mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-31 09:05:14 +01:00
Code cleanup
This commit is contained in:
parent
25838ad02d
commit
84dc58da71
@ -44,20 +44,12 @@ static QPointF centroid(const QPainterPath &polygon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const QByteArray *label(const QByteArray &key,
|
static const QByteArray *label(const QByteArray &key,
|
||||||
const QVector<MapData::Tag> &tags, bool *limit = 0)
|
const QVector<MapData::Tag> &tags)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < tags.size(); i++) {
|
for (int i = 0; i < tags.size(); i++) {
|
||||||
const MapData::Tag &tag = tags.at(i);
|
const MapData::Tag &tag = tags.at(i);
|
||||||
|
if (tag.key == key)
|
||||||
if (tag.key == key) {
|
return tag.value.isEmpty() ? 0 : &tag.value;
|
||||||
if (tag.value.isEmpty())
|
|
||||||
return 0;
|
|
||||||
else {
|
|
||||||
if (limit)
|
|
||||||
*limit = (tag.key == "ref");
|
|
||||||
return &tag.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -78,14 +70,14 @@ void RasterTile::processPointLabels(QList<TextItem*> &textItems)
|
|||||||
|
|
||||||
for (int i = 0; i < _points.size(); i++) {
|
for (int i = 0; i < _points.size(); i++) {
|
||||||
MapData::Point &point = _points[i];
|
MapData::Point &point = _points[i];
|
||||||
const QByteArray *l = 0;
|
const QByteArray *lbl = 0;
|
||||||
const Style::TextRender *ti = 0;
|
const Style::TextRender *ti = 0;
|
||||||
const Style::Symbol *si = 0;
|
const Style::Symbol *si = 0;
|
||||||
|
|
||||||
for (int j = 0; j < labels.size(); j++) {
|
for (int j = 0; j < labels.size(); j++) {
|
||||||
const Style::TextRender *ri = labels.at(j);
|
const Style::TextRender *ri = labels.at(j);
|
||||||
if (ri->rule().match(point.tags)) {
|
if (ri->rule().match(point.tags)) {
|
||||||
if ((l = label(ri->key(), point.tags))) {
|
if ((lbl = label(ri->key(), point.tags))) {
|
||||||
ti = ri;
|
ti = ri;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -109,7 +101,7 @@ void RasterTile::processPointLabels(QList<TextItem*> &textItems)
|
|||||||
const QColor *hColor = ti ? haloColor(ti) : 0;
|
const QColor *hColor = ti ? haloColor(ti) : 0;
|
||||||
|
|
||||||
PointItem *item = new PointItem(ll2xy(point.coordinates).toPoint(),
|
PointItem *item = new PointItem(ll2xy(point.coordinates).toPoint(),
|
||||||
l ? new QString(*l) : 0, font, img, color, hColor);
|
lbl ? new QString(*lbl) : 0, font, img, color, hColor);
|
||||||
if (item->isValid() && !item->collides(textItems))
|
if (item->isValid() && !item->collides(textItems))
|
||||||
textItems.append(item);
|
textItems.append(item);
|
||||||
else
|
else
|
||||||
@ -135,9 +127,9 @@ void RasterTile::processAreaLabels(QList<TextItem*> &textItems,
|
|||||||
for (int j = 0; j < labels.size(); j++) {
|
for (int j = 0; j < labels.size(); j++) {
|
||||||
const Style::TextRender *ri = labels.at(j);
|
const Style::TextRender *ri = labels.at(j);
|
||||||
if (ri->rule().match(path.path->closed, path.path->tags)) {
|
if (ri->rule().match(path.path->closed, path.path->tags)) {
|
||||||
const QByteArray *l;
|
const QByteArray *lbl;
|
||||||
if ((l = label(ri->key(), path.path->tags))) {
|
if ((lbl = label(ri->key(), path.path->tags))) {
|
||||||
path.label = *l;
|
path.label = *lbl;
|
||||||
ti = ri;
|
ti = ri;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -178,31 +170,30 @@ void RasterTile::processLineLabels(QList<TextItem*> &textItems,
|
|||||||
const Style &s = style(_ratio);
|
const Style &s = style(_ratio);
|
||||||
QList<const Style::TextRender*> instructions(s.pathLabels(_zoom));
|
QList<const Style::TextRender*> instructions(s.pathLabels(_zoom));
|
||||||
QSet<QByteArray> set;
|
QSet<QByteArray> set;
|
||||||
bool limit;
|
|
||||||
|
|
||||||
for (int i = 0; i < instructions.size(); i++) {
|
for (int i = 0; i < instructions.size(); i++) {
|
||||||
const Style::TextRender *ri = instructions.at(i);
|
const Style::TextRender *ri = instructions.at(i);
|
||||||
|
|
||||||
for (int i = 0; i < renderPaths.size(); i++) {
|
for (int i = 0; i < renderPaths.size(); i++) {
|
||||||
RenderPath &path = renderPaths[i];
|
RenderPath &path = renderPaths[i];
|
||||||
const QByteArray *l = label(ri->key(), path.path->tags,
|
const QByteArray *lbl = label(ri->key(), path.path->tags);
|
||||||
&limit);
|
|
||||||
|
|
||||||
if (!l)
|
if (!lbl)
|
||||||
continue;
|
continue;
|
||||||
if (!ri->rule().match(path.path->closed, path.path->tags))
|
if (!ri->rule().match(path.path->closed, path.path->tags))
|
||||||
continue;
|
continue;
|
||||||
if (limit && set.contains(*l))
|
bool limit = (ri->key() == "ref");
|
||||||
|
if (limit && set.contains(*lbl))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
path.label = *l;
|
path.label = *lbl;
|
||||||
|
|
||||||
TextPathItem *item = new TextPathItem(path.pp, &path.label, _rect,
|
TextPathItem *item = new TextPathItem(path.pp, &path.label, _rect,
|
||||||
&ri->font(), &ri->fillColor(), haloColor(ri));
|
&ri->font(), &ri->fillColor(), haloColor(ri));
|
||||||
if (item->isValid() && !item->collides(textItems)) {
|
if (item->isValid() && !item->collides(textItems)) {
|
||||||
textItems.append(item);
|
textItems.append(item);
|
||||||
if (limit)
|
if (limit)
|
||||||
set.insert(*l);
|
set.insert(*lbl);
|
||||||
} else
|
} else
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user