1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-27 11:39:16 +02:00

A much better area Z-level algorithm

O(n^2) -> O(1)
This commit is contained in:
2022-01-27 00:26:28 +01:00
parent 1f0bd76f67
commit 0b3e54abf2
2 changed files with 3 additions and 21 deletions

View File

@ -34,20 +34,6 @@
#define COORDINATES_OFFSET SCALE_OFFSET
template<typename T>
static void updateZValues(T &items)
{
for (int i = 0; i < items.size(); i++) {
const QGraphicsItem *ai = items.at(i);
for (int j = 0; j < items.size(); j++) {
QGraphicsItem *aj = items[j];
if (aj->boundingRect().contains(ai->boundingRect()))
aj->setZValue(qMin(ai->zValue() - 1, aj->zValue()));
}
}
}
MapView::MapView(Map *map, POI *poi, QGeoPositionInfoSource *source,
QWidget *parent) : QGraphicsView(parent)
{
@ -226,6 +212,7 @@ void MapView::addArea(const Area &area)
ai->setOpacity(_areaOpacity);
ai->setDigitalZoom(_digitalZoom);
ai->setVisible(_showAreas);
ai->setZValue(-area.boundingRect().area());
_scene->addItem(ai);
_ar |= ai->bounds();
@ -266,6 +253,7 @@ MapItem *MapView::addMap(MapAction *map)
mi->setOpacity(_areaOpacity);
mi->setDigitalZoom(_digitalZoom);
mi->setVisible(_showAreas);
mi->setZValue(-mi->bounds().area());
_scene->addItem(mi);
_ar |= mi->bounds();
@ -299,9 +287,6 @@ QList<PathItem *> MapView::loadData(const Data &data)
else
updatePOIVisibility();
if (!data.areas().isEmpty())
updateZValues(_areas);
centerOn(contentCenter());
return paths;
@ -319,8 +304,6 @@ void MapView::loadMaps(const QList<MapAction *> &maps)
else
updatePOIVisibility();
updateZValues(_areas);
centerOn(contentCenter());
}
@ -336,8 +319,6 @@ void MapView::loadDEMs(const QList<Area> &dems)
else
updatePOIVisibility();
updateZValues(_areas);
centerOn(contentCenter());
}