1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Extended POI file control possibilities

This commit is contained in:
Martin Tůma 2016-03-05 18:01:13 +01:00
parent 209f58412a
commit f05e6ce29f
4 changed files with 134 additions and 13 deletions

View File

@ -8,6 +8,12 @@
#include <QPainter>
#include <QKeyEvent>
#include <QSignalMapper>
#include <QMenu>
#include <QToolBar>
#include <QTabWidget>
#include <QActionGroup>
#include <QAction>
#include <QLabel>
#include "config.h"
#include "icons.h"
#include "keys.h"
@ -110,6 +116,25 @@ void GUI::createMapActions()
_currentMap = _maps.at(0);
}
void GUI::createPOIFilesActions()
{
_poiFilesSM = new QSignalMapper(this);
for (int i = 0; i < _poi.files().count(); i++) {
QAction *a = new QAction(QFileInfo(_poi.files().at(i)).fileName(),
this);
a->setCheckable(true);
a->setChecked(true);
_poiFilesSM->setMapping(a, i);
connect(a, SIGNAL(triggered()), _poiFilesSM, SLOT(map()));
_poiFilesActions.append(a);
}
connect(_poiFilesSM, SIGNAL(mapped(int)), this, SLOT(poiFileChecked(int)));
}
void GUI::createActions()
{
// Action Groups
@ -166,11 +191,15 @@ void GUI::createActions()
_openPOIAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
tr("Load POI file"), this);
connect(_openPOIAction, SIGNAL(triggered()), this, SLOT(openPOIFile()));
_closePOIAction = new QAction(QIcon(QPixmap(CLOSE_FILE_ICON)),
tr("Close POI files"), this);
connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles()));
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
tr("Show POIs"), this);
_showPOIAction->setCheckable(true);
_showPOIAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
connect(_showPOIAction, SIGNAL(triggered(bool)), this, SLOT(showPOI(bool)));
createPOIFilesActions();
// Map actions
_showMapAction = new QAction(QIcon(QPixmap(SHOW_MAP_ICON)), tr("Show map"),
@ -250,7 +279,12 @@ void GUI::createMenus()
_mapMenu->addAction(_showMapAction);
_poiMenu = menuBar()->addMenu(tr("POI"));
_poiFilesMenu = _poiMenu->addMenu(tr("POI files"));
_poiFilesMenu->addActions(_poiFilesActions);
_poiMenu->addSeparator();
_poiMenu->addAction(_openPOIAction);
_poiMenu->addAction(_closePOIAction);
_poiMenu->addSeparator();
_poiMenu->addAction(_showPOIAction);
_settingsMenu = menuBar()->addMenu(tr("Settings"));
@ -477,10 +511,31 @@ void GUI::openPOIFile()
} else {
_showPOIAction->setChecked(true);
_track->loadPOI(_poi);
QAction *a = new QAction(QFileInfo(fileName).fileName(), this);
a->setCheckable(true);
a->setChecked(true);
_poiFilesSM->setMapping(a, _poi.files().count() - 1);
connect(a, SIGNAL(triggered()), _poiFilesSM, SLOT(map()));
_poiFilesActions.append(a);
_poiFilesMenu->addAction(a);
}
}
}
void GUI::closePOIFiles()
{
_poiFilesMenu->clear();
for (int i = 0; i < _poiFilesActions.count(); i++)
delete _poiFilesActions[i];
_poiFilesActions.clear();
_track->clearPOI();
_poi.clear();
}
void GUI::saveAs()
{
QString fileName = QFileDialog::getSaveFileName(this, "Export to PDF",
@ -654,6 +709,14 @@ void GUI::mapChanged(int index)
_track->setMap(_currentMap);
}
void GUI::poiFileChecked(int index)
{
_poi.enableFile(_poi.files().at(index),
_poiFilesActions.at(index)->isChecked());
_track->clearPOI();
_track->loadPOI(_poi);
}
void GUI::graphChanged(int index)
{
if (_trackGraphs->widget(index) == _elevationGraph)

View File

@ -2,16 +2,17 @@
#define GUI_H
#include <QMainWindow>
#include <QMenu>
#include <QToolBar>
#include <QTabWidget>
#include <QGraphicsView>
#include <QActionGroup>
#include <QAction>
#include <QLabel>
#include <QString>
#include <QList>
#include "poi.h"
class QMenu;
class QToolBar;
class QTabWidget;
class QActionGroup;
class QAction;
class QLabel;
class QSignalMapper;
class FileBrowser;
class ElevationGraph;
class SpeedGraph;
@ -37,6 +38,7 @@ private slots:
void closeFile();
void reloadFile();
void openPOIFile();
void closePOIFiles();
void showPOI(bool checked);
void showMap(bool checked);
void showGraphs(bool checked);
@ -44,6 +46,7 @@ private slots:
void mapChanged(int);
void graphChanged(int);
void poiFileChecked(int);
void next();
void prev();
@ -57,6 +60,7 @@ private:
void loadFiles();
void createMapActions();
void createPOIFilesActions();
void createActions();
void createMenus();
void createToolBars();
@ -77,6 +81,7 @@ private:
QMenu *_mapMenu;
QMenu *_settingsMenu;
QMenu *_unitsMenu;
QMenu *_poiFilesMenu;
QToolBar *_fileToolBar;
QToolBar *_showToolBar;
@ -96,6 +101,7 @@ private:
QAction *_closeFileAction;
QAction *_reloadFileAction;
QAction *_openPOIAction;
QAction *_closePOIAction;
QAction *_showPOIAction;
QAction *_showMapAction;
QAction *_showGraphsAction;
@ -107,6 +113,9 @@ private:
QAction *_metricUnitsAction;
QAction *_imperialUnitsAction;
QList<QAction*> _mapActions;
QList<QAction*> _poiFilesActions;
QSignalMapper *_poiFilesSM;
QLabel *_fileNameLabel;
QLabel *_distanceLabel;

View File

@ -39,21 +39,28 @@ bool POI::loadFile(const QString &fileName)
bool POI::loadGPXFile(const QString &fileName)
{
GPX gpx;
int cnt = _data.size();
FileIndex index;
index.enabled = true;
index.start = _data.size();
if (gpx.loadFile(fileName)) {
for (int i = 0; i < gpx.waypoints().size(); i++)
_data.append(Waypoint(
ll2mercator(gpx.waypoints().at(i).coordinates()),
gpx.waypoints().at(i).description()));
index.end = _data.size() - 1;
for (int i = cnt; i < _data.size(); ++i) {
for (int i = index.start; i <= index.end; i++) {
qreal c[2];
c[0] = _data.at(i).coordinates().x();
c[1] = _data.at(i).coordinates().y();
_tree.Insert(c, c, i);
}
_files.append(fileName);
_indexes.append(index);
return true;
} else {
_error = gpx.errorString();
@ -66,8 +73,12 @@ bool POI::loadGPXFile(const QString &fileName)
bool POI::loadCSVFile(const QString &fileName)
{
QFile file(fileName);
FileIndex index;
bool ret;
int ln = 1, cnt = _data.size();
int ln = 1;
index.enabled = true;
index.start = _data.size();
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
@ -101,14 +112,18 @@ bool POI::loadCSVFile(const QString &fileName)
QString::fromUtf8(ba.data(), ba.size())));
ln++;
}
index.end = _data.size() - 1;
for (int i = cnt; i < _data.size(); ++i) {
for (int i = index.start; i <= index.end; i++) {
qreal c[2];
c[0] = _data.at(i).coordinates().x();
c[1] = _data.at(i).coordinates().y();
_tree.Insert(c, c, i);
}
_files.append(fileName);
_indexes.append(index);
return true;
}
@ -143,8 +158,33 @@ QVector<Waypoint> POI::points(const QVector<QPointF> &path, qreal radius) const
return ret;
}
void POI::enableFile(const QString &fileName, bool enable)
{
int i;
i = _files.indexOf(fileName);
Q_ASSERT(i >= 0);
_indexes[i].enabled = enable;
_tree.RemoveAll();
for (int i = 0; i < _indexes.count(); i++) {
FileIndex idx = _indexes.at(i);
if (!idx.enabled)
continue;
for (int j = idx.start; j <= idx.end; j++) {
qreal c[2];
c[0] = _data.at(j).coordinates().x();
c[1] = _data.at(j).coordinates().y();
_tree.Insert(c, c, j);
}
}
}
void POI::clear()
{
_tree.RemoveAll();
_data.clear();
_files.clear();
_indexes.clear();
}

View File

@ -4,6 +4,7 @@
#include <QVector>
#include <QPointF>
#include <QString>
#include <QStringList>
#include "waypoint.h"
#include "rtree.h"
@ -18,17 +19,25 @@ public:
QVector<Waypoint> points(const QVector<QPointF> &path,
qreal radius = 0.01) const;
const QStringList &files() const {return _files;}
void enableFile(const QString &fileName, bool enable);
void clear();
private:
typedef RTree<size_t, qreal, 2> POITree;
typedef struct {
int start;
int end;
bool enabled;
} FileIndex;
bool loadCSVFile(const QString &fileName);
bool loadGPXFile(const QString &fileName);
POITree _tree;
QVector<Waypoint> _data;
QStringList _files;
QList<FileIndex> _indexes;
QString _error;
int _errorLine;