1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-27 08:54:23 +02:00

Fixed crashing async map loading

fixes #331
This commit is contained in:
2020-12-09 23:07:05 +01:00
parent 75b8b9eab0
commit 743a937f41
10 changed files with 179 additions and 117 deletions

View File

@ -18,6 +18,7 @@
#include "mapitem.h"
#include "keys.h"
#include "graphicsscene.h"
#include "mapaction.h"
#include "mapview.h"
@ -271,13 +272,19 @@ QList<PathItem *> MapView::loadData(const Data &data)
return paths;
}
QList<MapItem *> MapView::loadMaps(const QList<Map*> &maps)
void MapView::loadMaps(const QList<MapAction *> &maps)
{
QList<MapItem *> items;
int zoom = _map->zoom();
for (int i = 0; i < maps.size(); i++)
items.append(addMap(maps.at(i)));
for (int i = 0; i < maps.size(); i++) {
MapAction *a = maps.at(i);
Map *map = a->data().value<Map*>();
if (map->isReady()) {
MapItem *mi = addMap(map);
connect(mi, SIGNAL(triggered()), a, SLOT(trigger()));
} else
connect(a, SIGNAL(loaded()), this, SLOT(mapLoaded()));
}
if (fitMapZoom() != zoom)
rescale();
@ -287,8 +294,29 @@ QList<MapItem *> MapView::loadMaps(const QList<Map*> &maps)
updateZValues(_areas);
centerOn(contentCenter());
}
return items;
void MapView::mapLoaded()
{
MapAction *action = static_cast<MapAction*>(QObject::sender());
Map *map = action->data().value<Map*>();
if (!map->isValid())
return;
int zoom = _map->zoom();
MapItem *mi = addMap(map);
connect(mi, SIGNAL(triggered()), action, SLOT(trigger()));
if (fitMapZoom() != zoom)
rescale();
else
updatePOIVisibility();
updateZValues(_areas);
centerOn(contentCenter());
}
int MapView::fitMapZoom() const