mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-07 12:05:14 +01:00
Some more Mapsforge microoptimizations + code cleanup
This commit is contained in:
parent
b64065e076
commit
1d589e25d8
@ -200,6 +200,11 @@ QPainterPath RasterTile::painterPath(const Polygon &polygon, bool curve) const
|
|||||||
{
|
{
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
|
|
||||||
|
int size = 0;
|
||||||
|
for (int i = 0; i < polygon.size(); i++)
|
||||||
|
size += polygon.at(i).size();
|
||||||
|
path.reserve(size);
|
||||||
|
|
||||||
for (int i = 0; i < polygon.size(); i++) {
|
for (int i = 0; i < polygon.size(); i++) {
|
||||||
const QVector<Coordinates> &subpath = polygon.at(i);
|
const QVector<Coordinates> &subpath = polygon.at(i);
|
||||||
|
|
||||||
|
@ -138,12 +138,13 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
|||||||
PathRender ri(rule, _paths.size() + _circles.size());
|
PathRender ri(rule, _paths.size() + _circles.size());
|
||||||
const QXmlStreamAttributes &attr = reader.attributes();
|
const QXmlStreamAttributes &attr = reader.attributes();
|
||||||
QString file;
|
QString file;
|
||||||
|
QColor fillColor;
|
||||||
int height = 0, width = 0;
|
int height = 0, width = 0;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
ri._area = true;
|
ri._area = true;
|
||||||
if (attr.hasAttribute("fill"))
|
if (attr.hasAttribute("fill"))
|
||||||
ri._fillColor = QColor(attr.value("fill").toString());
|
fillColor = QColor(attr.value("fill").toString());
|
||||||
if (attr.hasAttribute("stroke"))
|
if (attr.hasAttribute("stroke"))
|
||||||
ri._strokeColor = QColor(attr.value("stroke").toString());
|
ri._strokeColor = QColor(attr.value("stroke").toString());
|
||||||
if (attr.hasAttribute("stroke-width")) {
|
if (attr.hasAttribute("stroke-width")) {
|
||||||
@ -171,7 +172,9 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!file.isNull())
|
if (!file.isNull())
|
||||||
ri._fillImage = image(file, width, height, ratio);
|
ri._brush = QBrush(image(file, width, height, ratio));
|
||||||
|
else if (fillColor.isValid())
|
||||||
|
ri._brush = QBrush(fillColor);
|
||||||
|
|
||||||
if (ri.rule()._type == Rule::AnyType || ri.rule()._type == Rule::WayType)
|
if (ri.rule()._type == Rule::AnyType || ri.rule()._type == Rule::WayType)
|
||||||
_paths.append(ri);
|
_paths.append(ri);
|
||||||
@ -652,10 +655,9 @@ QList<const Style::Symbol*> Style::areaSymbols(int zoom) const
|
|||||||
|
|
||||||
QPen Style::PathRender::pen(int zoom) const
|
QPen Style::PathRender::pen(int zoom) const
|
||||||
{
|
{
|
||||||
qreal width = (zoom >= 12)
|
|
||||||
? pow(1.5, zoom - 12) * _strokeWidth : _strokeWidth;
|
|
||||||
|
|
||||||
if (_strokeColor.isValid()) {
|
if (_strokeColor.isValid()) {
|
||||||
|
qreal width = (zoom >= 12)
|
||||||
|
? pow(1.5, zoom - 12) * _strokeWidth : _strokeWidth;
|
||||||
QPen p(QBrush(_strokeColor), width, Qt::SolidLine, _strokeCap,
|
QPen p(QBrush(_strokeColor), width, Qt::SolidLine, _strokeCap,
|
||||||
_strokeJoin);
|
_strokeJoin);
|
||||||
if (!_strokeDasharray.isEmpty()) {
|
if (!_strokeDasharray.isEmpty()) {
|
||||||
@ -669,16 +671,6 @@ QPen Style::PathRender::pen(int zoom) const
|
|||||||
return Qt::NoPen;
|
return Qt::NoPen;
|
||||||
}
|
}
|
||||||
|
|
||||||
QBrush Style::PathRender::brush() const
|
|
||||||
{
|
|
||||||
if (!_fillImage.isNull())
|
|
||||||
return QBrush(_fillImage);
|
|
||||||
else if (_fillColor.isValid())
|
|
||||||
return QBrush(_fillColor);
|
|
||||||
else
|
|
||||||
return Qt::NoBrush;
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal Style::CircleRender::radius(int zoom) const
|
qreal Style::CircleRender::radius(int zoom) const
|
||||||
{
|
{
|
||||||
return (_scale && zoom >= 12) ? pow(1.5, zoom - 12) * _radius : _radius;
|
return (_scale && zoom >= 12) ? pow(1.5, zoom - 12) * _radius : _radius;
|
||||||
|
@ -11,17 +11,6 @@ class QXmlStreamReader;
|
|||||||
|
|
||||||
namespace Mapsforge {
|
namespace Mapsforge {
|
||||||
|
|
||||||
inline bool wcmp(const QByteArray &b1, const QByteArray &b2)
|
|
||||||
{
|
|
||||||
int len = b1.length();
|
|
||||||
|
|
||||||
if (!len)
|
|
||||||
return true;
|
|
||||||
if (len != b2.length())
|
|
||||||
return false;
|
|
||||||
return !memcmp(b1.constData(), b2.constData(), len);
|
|
||||||
}
|
|
||||||
|
|
||||||
class Style
|
class Style
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -87,10 +76,13 @@ public:
|
|||||||
|
|
||||||
bool valueMatches(const QVector<MapData::Tag> &tags) const
|
bool valueMatches(const QVector<MapData::Tag> &tags) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _vals.size(); i++)
|
for (int i = 0; i < _vals.size(); i++) {
|
||||||
for (int j = 0; j < tags.size(); j++)
|
for (int j = 0; j < tags.size(); j++) {
|
||||||
if (wcmp(_vals.at(i), tags.at(j).value))
|
const QByteArray &ba = _vals.at(i);
|
||||||
|
if (!ba.size() || ba == tags.at(j).value)
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -148,7 +140,7 @@ public:
|
|||||||
|
|
||||||
int zOrder() const {return _zOrder;}
|
int zOrder() const {return _zOrder;}
|
||||||
QPen pen(int zoom) const;
|
QPen pen(int zoom) const;
|
||||||
QBrush brush() const;
|
const QBrush &brush() const {return _brush;}
|
||||||
bool area() const {return _area;}
|
bool area() const {return _area;}
|
||||||
bool curve() const {return _curve;}
|
bool curve() const {return _curve;}
|
||||||
|
|
||||||
@ -156,12 +148,12 @@ public:
|
|||||||
friend class Style;
|
friend class Style;
|
||||||
|
|
||||||
int _zOrder;
|
int _zOrder;
|
||||||
QColor _fillColor, _strokeColor;
|
QColor _strokeColor;
|
||||||
qreal _strokeWidth;
|
qreal _strokeWidth;
|
||||||
QVector<qreal> _strokeDasharray;
|
QVector<qreal> _strokeDasharray;
|
||||||
Qt::PenCapStyle _strokeCap;
|
Qt::PenCapStyle _strokeCap;
|
||||||
Qt::PenJoinStyle _strokeJoin;
|
Qt::PenJoinStyle _strokeJoin;
|
||||||
QImage _fillImage;
|
QBrush _brush;
|
||||||
bool _area, _curve;
|
bool _area, _curve;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user