1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +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,44 +147,47 @@ void GUI::createMapActions()
_mapsActionGroup = new QActionGroup(this);
_mapsActionGroup->setExclusive(true);
for (int i = 0; i < _ml->maps().count(); i++) {
QAction *a = new QAction(_ml->maps().at(i)->name(), this);
a->setMenuRole(QAction::NoRole);
a->setCheckable(true);
a->setActionGroup(_mapsActionGroup);
_mapsSignalMapper->setMapping(a, i);
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
_mapActions.append(a);
}
for (int i = 0; i < _ml->maps().count(); i++)
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->setCheckable(true);
a->setActionGroup(_mapsActionGroup);
_mapActions.append(a);
_mapsSignalMapper->setMapping(a, _mapActions.size() - 1);
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
return a;
}
void GUI::createPOIFilesActions()
{
_poiFilesSignalMapper = new QSignalMapper(this);
for (int i = 0; i < _poi->files().count(); i++)
createPOIFileAction(i);
createPOIFileAction(_poi->files().at(i));
connect(_poiFilesSignalMapper, SIGNAL(mapped(int)), this,
SLOT(poiFileChecked(int)));
}
QAction *GUI::createPOIFileAction(int index)
QAction *GUI::createPOIFileAction(const QString &fileName)
{
QAction *a = new QAction(QFileInfo(_poi->files().at(index)).fileName(),
this);
QAction *a = new QAction(QFileInfo(fileName).fileName(), this);
a->setMenuRole(QAction::NoRole);
a->setCheckable(true);
_poiFilesSignalMapper->setMapping(a, index);
connect(a, SIGNAL(triggered()), _poiFilesSignalMapper, SLOT(map()));
_poiFilesActions.append(a);
_poiFilesSignalMapper->setMapping(a, _poiFilesActions.size() - 1);
connect(a, SIGNAL(triggered()), _poiFilesSignalMapper, SLOT(map()));
return a;
}
@ -838,7 +841,15 @@ bool GUI::openPOIFile(const QString &fileName)
if (fileName.isEmpty() || _poi->files().contains(fileName))
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"
+ fileName + "\n\n" + _poi->errorString();
if (_poi->errorLine())
@ -846,14 +857,6 @@ bool GUI::openPOIFile(const QString &fileName)
QMessageBox::critical(this, APP_NAME, error);
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;
if (_ml->loadFile(fileName)) {
QAction *a = new QAction(_ml->maps().last()->name(), this);
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);
QAction *a = createMapAction(_ml->maps().last());
_mapMenu->insertAction(_mapsEnd, a);
_showMapAction->setEnabled(true);
_clearMapCacheAction->setEnabled(true);
_mapActions.last()->trigger();
a->trigger();
return true;
} else {
QString error = tr("Error loading map:") + "\n\n"

View File

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

View File

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