1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2018-10-07 13:07:04 +02:00
parent 140e975524
commit 2f9751672e
3 changed files with 37 additions and 39 deletions

View File

@ -147,20 +147,25 @@ void GUI::createMapActions()
_mapsActionGroup = new QActionGroup(this); _mapsActionGroup = new QActionGroup(this);
_mapsActionGroup->setExclusive(true); _mapsActionGroup->setExclusive(true);
for (int i = 0; i < _ml->maps().count(); i++) { for (int i = 0; i < _ml->maps().count(); i++)
QAction *a = new QAction(_ml->maps().at(i)->name(), this); createMapAction(_ml->maps().at(i));
connect(_mapsSignalMapper, SIGNAL(mapped(int)), this,
SLOT(mapChanged(int)));
}
QAction *GUI::createMapAction(const Map *map)
{
QAction *a = new QAction(map->name(), this);
a->setMenuRole(QAction::NoRole); a->setMenuRole(QAction::NoRole);
a->setCheckable(true); a->setCheckable(true);
a->setActionGroup(_mapsActionGroup); a->setActionGroup(_mapsActionGroup);
_mapsSignalMapper->setMapping(a, i); _mapActions.append(a);
_mapsSignalMapper->setMapping(a, _mapActions.size() - 1);
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map())); connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
_mapActions.append(a); return a;
}
connect(_mapsSignalMapper, SIGNAL(mapped(int)), this,
SLOT(mapChanged(int)));
} }
void GUI::createPOIFilesActions() void GUI::createPOIFilesActions()
@ -168,23 +173,21 @@ void GUI::createPOIFilesActions()
_poiFilesSignalMapper = new QSignalMapper(this); _poiFilesSignalMapper = new QSignalMapper(this);
for (int i = 0; i < _poi->files().count(); i++) for (int i = 0; i < _poi->files().count(); i++)
createPOIFileAction(i); createPOIFileAction(_poi->files().at(i));
connect(_poiFilesSignalMapper, SIGNAL(mapped(int)), this, connect(_poiFilesSignalMapper, SIGNAL(mapped(int)), this,
SLOT(poiFileChecked(int))); SLOT(poiFileChecked(int)));
} }
QAction *GUI::createPOIFileAction(int index) QAction *GUI::createPOIFileAction(const QString &fileName)
{ {
QAction *a = new QAction(QFileInfo(_poi->files().at(index)).fileName(), QAction *a = new QAction(QFileInfo(fileName).fileName(), this);
this);
a->setMenuRole(QAction::NoRole); a->setMenuRole(QAction::NoRole);
a->setCheckable(true); a->setCheckable(true);
_poiFilesSignalMapper->setMapping(a, index);
connect(a, SIGNAL(triggered()), _poiFilesSignalMapper, SLOT(map()));
_poiFilesActions.append(a); _poiFilesActions.append(a);
_poiFilesSignalMapper->setMapping(a, _poiFilesActions.size() - 1);
connect(a, SIGNAL(triggered()), _poiFilesSignalMapper, SLOT(map()));
return a; return a;
} }
@ -838,7 +841,15 @@ bool GUI::openPOIFile(const QString &fileName)
if (fileName.isEmpty() || _poi->files().contains(fileName)) if (fileName.isEmpty() || _poi->files().contains(fileName))
return false; return false;
if (!_poi->loadFile(fileName)) { if (_poi->loadFile(fileName)) {
_mapView->showPOI(true);
_showPOIAction->setChecked(true);
QAction *action = createPOIFileAction(fileName);
action->setChecked(true);
_poiFilesMenu->addAction(action);
return true;
} else {
QString error = tr("Error loading POI file:") + "\n\n" QString error = tr("Error loading POI file:") + "\n\n"
+ fileName + "\n\n" + _poi->errorString(); + fileName + "\n\n" + _poi->errorString();
if (_poi->errorLine()) if (_poi->errorLine())
@ -846,14 +857,6 @@ bool GUI::openPOIFile(const QString &fileName)
QMessageBox::critical(this, APP_NAME, error); QMessageBox::critical(this, APP_NAME, error);
return false; return false;
} else {
_mapView->showPOI(true);
_showPOIAction->setChecked(true);
QAction *action = createPOIFileAction(_poi->files().indexOf(fileName));
action->setChecked(true);
_poiFilesMenu->addAction(action);
return true;
} }
} }
@ -1294,18 +1297,11 @@ bool GUI::loadMap(const QString &fileName)
return false; return false;
if (_ml->loadFile(fileName)) { if (_ml->loadFile(fileName)) {
QAction *a = new QAction(_ml->maps().last()->name(), this); QAction *a = createMapAction(_ml->maps().last());
a->setMenuRole(QAction::NoRole);
a->setCheckable(true);
a->setActionGroup(_mapsActionGroup);
_mapsSignalMapper->setMapping(a, _ml->maps().size() - 1);
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
_mapActions.append(a);
_mapMenu->insertAction(_mapsEnd, a); _mapMenu->insertAction(_mapsEnd, a);
_showMapAction->setEnabled(true); _showMapAction->setEnabled(true);
_clearMapCacheAction->setEnabled(true); _clearMapCacheAction->setEnabled(true);
_mapActions.last()->trigger(); a->trigger();
return true; return true;
} else { } else {
QString error = tr("Error loading map:") + "\n\n" QString error = tr("Error loading map:") + "\n\n"

View File

@ -96,7 +96,8 @@ private:
void closeFiles(); void closeFiles();
void plot(QPrinter *printer); void plot(QPrinter *printer);
QAction *createPOIFileAction(int index); QAction *createPOIFileAction(const QString &fileName);
QAction *createMapAction(const Map *map);
void createPOIFilesActions(); void createPOIFilesActions();
void createMapActions(); void createMapActions();
void createActions(); void createActions();

View File

@ -1,3 +1,4 @@
#include <QtCore>
#include "common/wgs84.h" #include "common/wgs84.h"
#include "osm.h" #include "osm.h"
@ -16,8 +17,8 @@ Coordinates OSM::m2ll(const QPointF &p)
QPoint OSM::mercator2tile(const QPointF &m, int zoom) QPoint OSM::mercator2tile(const QPointF &m, int zoom)
{ {
return QPoint((int)(floor((m.x() + 180.0) / 360.0 * (1<<zoom))), return QPoint(qFloor((m.x() + 180.0) / 360.0 * (1<<zoom)),
(int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * (1<<zoom)))); qFloor((1.0 - (m.y() / 180.0)) / 2.0 * (1<<zoom)));
} }
qreal OSM::zoom2scale(int zoom, int tileSize) qreal OSM::zoom2scale(int zoom, int tileSize)