1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-02-20 09:40:49 +01:00

Some more Mapsforge micro-optimizations

This commit is contained in:
Martin Tůma 2023-04-23 11:01:18 +02:00
parent 2232e47821
commit 6c91060cbb
2 changed files with 18 additions and 13 deletions

View File

@ -108,8 +108,6 @@ bool Style::Rule::match(int zoom, bool closed,
{ {
Closed cl = closed ? YesClosed : NoClosed; Closed cl = closed ? YesClosed : NoClosed;
if (_type && WayType != _type)
return false;
if (!_zooms.contains(zoom)) if (!_zooms.contains(zoom))
return false; return false;
if (_closed && cl != _closed) if (_closed && cl != _closed)
@ -124,8 +122,6 @@ bool Style::Rule::match(int zoom, bool closed,
bool Style::Rule::match(int zoom, const QVector<MapData::Tag> &tags) const bool Style::Rule::match(int zoom, const QVector<MapData::Tag> &tags) const
{ {
if (_type && NodeType != _type)
return false;
if (!_zooms.contains(zoom)) if (!_zooms.contains(zoom))
return false; return false;
@ -177,7 +173,8 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
if (!file.isNull()) if (!file.isNull())
ri._fillImage = image(file, width, height, ratio); ri._fillImage = image(file, width, height, ratio);
_paths.append(ri); if (ri.rule()._type == Rule::AnyType || ri.rule()._type == Rule::WayType)
_paths.append(ri);
reader.skipCurrentElement(); reader.skipCurrentElement();
} }
@ -232,7 +229,8 @@ void Style::line(QXmlStreamReader &reader, const Rule &rule)
ri._curve = true; ri._curve = true;
} }
_paths.append(ri); if (ri.rule()._type == Rule::AnyType || ri.rule()._type == Rule::WayType)
_paths.append(ri);
reader.skipCurrentElement(); reader.skipCurrentElement();
} }
@ -275,7 +273,8 @@ void Style::circle(QXmlStreamReader &reader, const Rule &rule)
? QPen(QBrush(strokeColor), strokeWidth) : Qt::NoPen; ? QPen(QBrush(strokeColor), strokeWidth) : Qt::NoPen;
ri._brush = fillColor.isValid() ? QBrush(fillColor) : Qt::NoBrush; ri._brush = fillColor.isValid() ? QBrush(fillColor) : Qt::NoBrush;
_circles.append(ri); if (ri.rule()._type == Rule::AnyType || ri.rule()._type == Rule::NodeType)
_circles.append(ri);
reader.skipCurrentElement(); reader.skipCurrentElement();
} }
@ -370,6 +369,10 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
if (attr.hasAttribute("src")) if (attr.hasAttribute("src"))
file = resourcePath(attr.value("src").toString(), dir); file = resourcePath(attr.value("src").toString(), dir);
else {
reader.raiseError("missing src value");
return;
}
if (attr.hasAttribute("symbol-height")) { if (attr.hasAttribute("symbol-height")) {
height = attr.value("symbol-height").toInt(&ok); height = attr.value("symbol-height").toInt(&ok);
if (!ok || height < 0) { if (!ok || height < 0) {
@ -392,8 +395,7 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
} }
} }
if (!file.isNull()) ri._img = image(file, width, height, ratio);
ri._img = image(file, width, height, ratio);
_symbols.append(ri); _symbols.append(ri);
@ -639,7 +641,7 @@ QList<const Style::Symbol*> Style::areaSymbols(int zoom) const
for (int i = 0; i < _symbols.size(); i++) { for (int i = 0; i < _symbols.size(); i++) {
const Symbol &symbol = _symbols.at(i); const Symbol &symbol = _symbols.at(i);
const Rule & rule = symbol.rule(); const Rule &rule = symbol.rule();
if (rule._zooms.contains(zoom) && (rule._type == Rule::AnyType if (rule._zooms.contains(zoom) && (rule._type == Rule::AnyType
|| rule._type == Rule::WayType)) || rule._type == Rule::WayType))
list.append(&symbol); list.append(&symbol);

View File

@ -74,10 +74,13 @@ public:
private: private:
bool keyMatches(const QVector<MapData::Tag> &tags) const bool keyMatches(const QVector<MapData::Tag> &tags) const
{ {
for (int i = 0; i < _keys.size(); i++) for (int i = 0; i < _keys.size(); i++) {
for (int j = 0; j < tags.size(); j++) for (int j = 0; j < tags.size(); j++) {
if (!_keys.at(i) || _keys.at(i) == tags.at(j).key) unsigned key = _keys.at(i);
if (!key || key == tags.at(j).key)
return true; return true;
}
}
return false; return false;
} }