mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Check for duplicit map loads
This commit is contained in:
parent
4bad086152
commit
e76e7b71ed
@ -777,7 +777,7 @@ void GUI::openFile()
|
|||||||
bool GUI::openFile(const QString &fileName, bool silent)
|
bool GUI::openFile(const QString &fileName, bool silent)
|
||||||
{
|
{
|
||||||
if (_files.contains(fileName))
|
if (_files.contains(fileName))
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
if (!loadFile(fileName, silent))
|
if (!loadFile(fileName, silent))
|
||||||
return false;
|
return false;
|
||||||
@ -891,7 +891,7 @@ void GUI::openPOIFile()
|
|||||||
bool GUI::openPOIFile(const QString &fileName)
|
bool GUI::openPOIFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (_poi->files().contains(fileName))
|
if (_poi->files().contains(fileName))
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
if (_poi->loadFile(fileName)) {
|
if (_poi->loadFile(fileName)) {
|
||||||
_mapView->showPOI(true);
|
_mapView->showPOI(true);
|
||||||
@ -1449,6 +1449,18 @@ void GUI::loadMap()
|
|||||||
lastReady->trigger();
|
lastReady->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MapAction *findMapAction(const QList<QAction*> &mapActions,
|
||||||
|
const Map *map)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < mapActions.count(); i++) {
|
||||||
|
const Map *m = mapActions.at(i)->data().value<Map*>();
|
||||||
|
if (map->path() == m->path())
|
||||||
|
return static_cast<MapAction*>(mapActions.at(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool GUI::loadMap(const QString &fileName, MapAction *&action, bool silent)
|
bool GUI::loadMap(const QString &fileName, MapAction *&action, bool silent)
|
||||||
{
|
{
|
||||||
QString error;
|
QString error;
|
||||||
@ -1461,16 +1473,26 @@ bool GUI::loadMap(const QString &fileName, MapAction *&action, bool silent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MapAction *lastReady = 0;
|
MapAction *lastReady = 0;
|
||||||
|
QList<QAction*> mapActions(_mapsActionGroup->actions());
|
||||||
|
|
||||||
for (int i = 0; i < maps.size(); i++) {
|
for (int i = 0; i < maps.size(); i++) {
|
||||||
Map *map = maps.at(i);
|
Map *map = maps.at(i);
|
||||||
MapAction *a = createMapAction(map);
|
MapAction *a;
|
||||||
_mapMenu->insertAction(_mapsEnd, a);
|
|
||||||
if (map->isReady()) {
|
if (!(a = findMapAction(mapActions, map))) {
|
||||||
lastReady = a;
|
a = createMapAction(map);
|
||||||
_showMapAction->setEnabled(true);
|
_mapMenu->insertAction(_mapsEnd, a);
|
||||||
_clearMapCacheAction->setEnabled(true);
|
if (map->isReady()) {
|
||||||
} else
|
lastReady = a;
|
||||||
connect(a, SIGNAL(loaded()), this, SLOT(mapLoaded()));
|
_showMapAction->setEnabled(true);
|
||||||
|
_clearMapCacheAction->setEnabled(true);
|
||||||
|
} else
|
||||||
|
connect(a, SIGNAL(loaded()), this, SLOT(mapLoaded()));
|
||||||
|
} else {
|
||||||
|
map = a->data().value<Map*>();
|
||||||
|
if (map->isReady())
|
||||||
|
lastReady = a;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
action = lastReady;
|
action = lastReady;
|
||||||
@ -1510,23 +1532,32 @@ void GUI::loadMapDir()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<MapItem*> items(_mapView->loadMaps(maps));
|
QList<MapItem*> items(_mapView->loadMaps(maps));
|
||||||
|
QList<QAction*> mapActions(_mapsActionGroup->actions());
|
||||||
|
|
||||||
QFileInfo fi(dir);
|
QFileInfo fi(dir);
|
||||||
QMenu *menu = new QMenu(fi.fileName());
|
QMenu *menu = new QMenu(fi.fileName());
|
||||||
menu->setStyleSheet("QMenu { menu-scrollable: 1; }");
|
|
||||||
_mapMenu->insertMenu(_mapsEnd, menu);
|
|
||||||
|
|
||||||
for (int i = 0; i < maps.size(); i++) {
|
for (int i = 0; i < maps.size(); i++) {
|
||||||
Map *map = maps.at(i);
|
Map *map = maps.at(i);
|
||||||
MapAction *a = createMapAction(map);
|
|
||||||
menu->addAction(a);
|
|
||||||
if (map->isReady()) {
|
|
||||||
_showMapAction->setEnabled(true);
|
|
||||||
_clearMapCacheAction->setEnabled(true);
|
|
||||||
} else
|
|
||||||
connect(a, SIGNAL(loaded()), this, SLOT(mapLoaded()));
|
|
||||||
|
|
||||||
connect(items.at(i), SIGNAL(triggered()), a, SLOT(trigger()));
|
if (!findMapAction(mapActions, map)) {
|
||||||
|
MapAction *a = createMapAction(map);
|
||||||
|
menu->addAction(a);
|
||||||
|
if (map->isReady()) {
|
||||||
|
_showMapAction->setEnabled(true);
|
||||||
|
_clearMapCacheAction->setEnabled(true);
|
||||||
|
} else
|
||||||
|
connect(a, SIGNAL(loaded()), this, SLOT(mapLoaded()));
|
||||||
|
|
||||||
|
connect(items.at(i), SIGNAL(triggered()), a, SLOT(trigger()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menu->isEmpty())
|
||||||
|
delete menu;
|
||||||
|
else {
|
||||||
|
menu->setStyleSheet("QMenu { menu-scrollable: 1; }");
|
||||||
|
_mapMenu->insertMenu(_mapsEnd, menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
_mapDir = fi.absolutePath();
|
_mapDir = fi.absolutePath();
|
||||||
@ -2470,7 +2501,7 @@ void GUI::readSettings()
|
|||||||
|
|
||||||
QAction *GUI::mapAction(const QString &name)
|
QAction *GUI::mapAction(const QString &name)
|
||||||
{
|
{
|
||||||
QList<QAction *> maps = _mapsActionGroup->actions();
|
QList<QAction *> maps(_mapsActionGroup->actions());
|
||||||
|
|
||||||
// Last map
|
// Last map
|
||||||
for (int i = 0; i < maps.count(); i++) {
|
for (int i = 0; i < maps.count(); i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user