Optimizations

This commit is contained in:
Martin Tůma 2018-10-31 00:47:23 +01:00
parent d0e958501f
commit b064c4bbfa

View File

@ -196,25 +196,32 @@ QPen Style::Layer::Paint::pen(Type type, int zoom) const
{ {
QPen pen(Qt::NoPen); QPen pen(Qt::NoPen);
qreal width; qreal width;
QColor color;
switch (type) { switch (type) {
case Line: case Line:
width = _lineWidth.value(zoom); width = _lineWidth.value(zoom);
if (_lineColor.value(zoom).isValid() && width > 0) { color = _lineColor.value(zoom);
pen = QPen(_lineColor.value(zoom), width); if (color.isValid() && width > 0) {
pen = QPen(color, width);
if (!_lineDasharray.isEmpty()) if (!_lineDasharray.isEmpty())
pen.setDashPattern(_lineDasharray); pen.setDashPattern(_lineDasharray);
} }
break; break;
case Fill: case Fill:
if (_fillOutlineColor.value(zoom).isValid()) color = _fillOutlineColor.value(zoom);
pen = QPen(_fillOutlineColor.value(zoom)); if (color.isValid())
else if (_fillColor.value(zoom).isValid()) pen = QPen(color);
pen = QPen(_fillColor.value(zoom)); else {
color = _fillColor.value(zoom);
if (color.isValid())
pen = QPen(color);
}
break; break;
case Symbol: case Symbol:
if (_textColor.value(zoom).isValid()) color = _textColor.value(zoom);
pen = QPen(_textColor.value(zoom)); if (color.isValid())
pen = QPen(color);
break; break;
default: default:
break; break;
@ -225,13 +232,15 @@ QPen Style::Layer::Paint::pen(Type type, int zoom) const
QBrush Style::Layer::Paint::brush(Type type, int zoom) const QBrush Style::Layer::Paint::brush(Type type, int zoom) const
{ {
QColor color;
switch (type) { switch (type) {
case Fill: case Fill:
return _fillColor.value(zoom).isValid() color = _fillColor.value(zoom);
? QBrush(_fillColor.value(zoom)) : QBrush(Qt::NoBrush); return color.isValid() ? QBrush(color) : QBrush(Qt::NoBrush);
case Background: case Background:
return _backgroundColor.value(zoom).isValid() color = _backgroundColor.value(zoom);
? QBrush(_backgroundColor.value(zoom)) : QBrush(Qt::NoBrush); return color.isValid() ? QBrush(color) : QBrush(Qt::NoBrush);
default: default:
return QBrush(Qt::NoBrush); return QBrush(Qt::NoBrush);
} }
@ -360,26 +369,26 @@ bool Style::Layer::match(int zoom, const QVariantMap &tags) const
return false; return false;
} }
if (_type == Line && _paint.pen(_type, zoom).style() == Qt::NoPen)
return false;
if (_type == Fill && _paint.brush(_type, zoom) == Qt::NoBrush)
return false;
return _filter.match(tags); return _filter.match(tags);
} }
void Style::Layer::drawPath(int zoom, const QPainterPath &path, void Style::Layer::drawPath(int zoom, const QPainterPath &path,
Tile &tile) const Tile &tile) const
{ {
QPainter &p = tile.painter();
QPen pen(_paint.pen(_type, zoom)); QPen pen(_paint.pen(_type, zoom));
if (_type == Line && pen.style() == Qt::NoPen)
return;
QBrush brush(_paint.brush(_type, zoom));
if (_type == Fill && brush.style() == Qt::NoBrush)
return;
pen.setJoinStyle(_layout.lineJoin()); pen.setJoinStyle(_layout.lineJoin());
pen.setCapStyle(_layout.lineCap()); pen.setCapStyle(_layout.lineCap());
QPainter &p = tile.painter();
p.setRenderHint(QPainter::Antialiasing, _paint.antialias(_type)); p.setRenderHint(QPainter::Antialiasing, _paint.antialias(_type));
p.setPen(pen); p.setPen(pen);
p.setBrush(_paint.brush(_type, zoom)); p.setBrush(brush);
p.setOpacity(_paint.opacity(_type, zoom)); p.setOpacity(_paint.opacity(_type, zoom));
p.drawPath(path); p.drawPath(path);
} }