Optimization/code cleanup

This commit is contained in:
Martin Tůma 2018-11-29 23:01:06 +01:00
parent a023975b41
commit 37290e231a
2 changed files with 28 additions and 23 deletions

View File

@ -394,7 +394,8 @@ Style::Layer::Layer(const QJsonObject &json)
: _type(Unknown), _minZoom(-1), _maxZoom(-1) : _type(Unknown), _minZoom(-1), _maxZoom(-1)
{ {
// type // type
QString type = json["type"].toString(); QString type(json["type"].toString());
if (type == "fill") if (type == "fill")
_type = Fill; _type = Fill;
else if (type == "line") else if (type == "line")
@ -440,28 +441,33 @@ bool Style::Layer::match(int zoom, const QVariantHash &tags) const
void Style::Layer::setPathPainter(Tile &tile, const Sprites &sprites) const void Style::Layer::setPathPainter(Tile &tile, const Sprites &sprites) const
{ {
QPen pen(_paint.pen(_type, tile.zoom()));
QBrush brush(_paint.brush(_type, tile.zoom(), sprites));
pen.setJoinStyle(_layout.lineJoin(tile.zoom()));
pen.setCapStyle(_layout.lineCap(tile.zoom()));
QPainter &p = tile.painter(); QPainter &p = tile.painter();
p.setRenderHint(QPainter::Antialiasing, _paint.antialias(_type, tile.zoom())); int zoom = tile.zoom();
QPen pen(_paint.pen(_type, zoom));
pen.setJoinStyle(_layout.lineJoin(zoom));
pen.setCapStyle(_layout.lineCap(zoom));
QBrush brush(_paint.brush(_type, zoom, sprites));
p.setRenderHint(QPainter::Antialiasing, _paint.antialias(_type, zoom));
p.setPen(pen); p.setPen(pen);
p.setBrush(brush); p.setBrush(brush);
p.setOpacity(_paint.opacity(_type, tile.zoom())); p.setOpacity(_paint.opacity(_type, zoom));
} }
void Style::Layer::setTextProperties(Tile &tile) const void Style::Layer::setTextProperties(Tile &tile) const
{ {
tile.text().setMaxWidth(_layout.maxTextWidth(tile.zoom())); Text &t = tile.text();
tile.text().setMaxAngle(_layout.maxTextAngle(tile.zoom())); int zoom = tile.zoom();
tile.text().setAnchor(_layout.textAnchor(tile.zoom()));
tile.text().setPen(_paint.pen(_type, tile.zoom())); t.setMaxWidth(_layout.maxTextWidth(zoom));
tile.text().setFont(_layout.font(tile.zoom())); t.setMaxAngle(_layout.maxTextAngle(zoom));
tile.text().setSymbolPlacement(_layout.symbolPlacement(tile.zoom())); t.setAnchor(_layout.textAnchor(zoom));
tile.text().setRotationAlignment(_layout.textRotationAlignment(tile.zoom())); t.setPen(_paint.pen(_type, zoom));
t.setFont(_layout.font(zoom));
t.setSymbolPlacement(_layout.symbolPlacement(zoom));
t.setRotationAlignment(_layout.textRotationAlignment(zoom));
} }
void Style::Layer::addSymbol(Tile &tile, const QPainterPath &path, void Style::Layer::addSymbol(Tile &tile, const QPainterPath &path,

View File

@ -32,24 +32,23 @@ void Text::addLabel(const QString &text, const QImage &icon,
_maxWidth, _anchor, icon); _maxWidth, _anchor, icon);
else else
ti = new TextPathItem(text, path, _font, _maxAngle, _sceneRect); ti = new TextPathItem(text, path, _font, _maxAngle, _sceneRect);
if (!_sceneRect.contains(ti->boundingRect()))
ti->setVisible(false);
break; break;
case LineCenter: case LineCenter:
ti = new TextPointItem(text, path.pointAtPercent(0.5), _font, ti = new TextPointItem(text, path.pointAtPercent(0.5), _font,
_maxWidth, _anchor, icon); _maxWidth, _anchor, icon);
if (!_sceneRect.contains(ti->boundingRect()))
ti->setVisible(false);
break; break;
default: default:
ti = new TextPointItem(text, path.elementAt(0), _font, _maxWidth, ti = new TextPointItem(text, path.elementAt(0), _font, _maxWidth,
_anchor, icon); _anchor, icon);
if (_alignment == Viewport
&& !_sceneRect.contains(ti->boundingRect()))
ti->setVisible(false);
break; break;
} }
// Note: empty path == point geometry (single move)
if (!path.isEmpty() && !_sceneRect.contains(ti->boundingRect())) {
delete ti;
return;
}
ti->setPen(_pen); ti->setPen(_pen);
addItem(ti); addItem(ti);