mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Extended POI file control possibilities
This commit is contained in:
parent
209f58412a
commit
f05e6ce29f
63
src/gui.cpp
63
src/gui.cpp
@ -8,6 +8,12 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QSignalMapper>
|
#include <QSignalMapper>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QToolBar>
|
||||||
|
#include <QTabWidget>
|
||||||
|
#include <QActionGroup>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QLabel>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "icons.h"
|
#include "icons.h"
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
@ -110,6 +116,25 @@ void GUI::createMapActions()
|
|||||||
_currentMap = _maps.at(0);
|
_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()
|
void GUI::createActions()
|
||||||
{
|
{
|
||||||
// Action Groups
|
// Action Groups
|
||||||
@ -166,11 +191,15 @@ void GUI::createActions()
|
|||||||
_openPOIAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
|
_openPOIAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
|
||||||
tr("Load POI file"), this);
|
tr("Load POI file"), this);
|
||||||
connect(_openPOIAction, SIGNAL(triggered()), this, SLOT(openPOIFile()));
|
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)),
|
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
|
||||||
tr("Show POIs"), this);
|
tr("Show POIs"), this);
|
||||||
_showPOIAction->setCheckable(true);
|
_showPOIAction->setCheckable(true);
|
||||||
_showPOIAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
|
_showPOIAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
|
||||||
connect(_showPOIAction, SIGNAL(triggered(bool)), this, SLOT(showPOI(bool)));
|
connect(_showPOIAction, SIGNAL(triggered(bool)), this, SLOT(showPOI(bool)));
|
||||||
|
createPOIFilesActions();
|
||||||
|
|
||||||
// Map actions
|
// Map actions
|
||||||
_showMapAction = new QAction(QIcon(QPixmap(SHOW_MAP_ICON)), tr("Show map"),
|
_showMapAction = new QAction(QIcon(QPixmap(SHOW_MAP_ICON)), tr("Show map"),
|
||||||
@ -250,7 +279,12 @@ void GUI::createMenus()
|
|||||||
_mapMenu->addAction(_showMapAction);
|
_mapMenu->addAction(_showMapAction);
|
||||||
|
|
||||||
_poiMenu = menuBar()->addMenu(tr("POI"));
|
_poiMenu = menuBar()->addMenu(tr("POI"));
|
||||||
|
_poiFilesMenu = _poiMenu->addMenu(tr("POI files"));
|
||||||
|
_poiFilesMenu->addActions(_poiFilesActions);
|
||||||
|
_poiMenu->addSeparator();
|
||||||
_poiMenu->addAction(_openPOIAction);
|
_poiMenu->addAction(_openPOIAction);
|
||||||
|
_poiMenu->addAction(_closePOIAction);
|
||||||
|
_poiMenu->addSeparator();
|
||||||
_poiMenu->addAction(_showPOIAction);
|
_poiMenu->addAction(_showPOIAction);
|
||||||
|
|
||||||
_settingsMenu = menuBar()->addMenu(tr("Settings"));
|
_settingsMenu = menuBar()->addMenu(tr("Settings"));
|
||||||
@ -477,10 +511,31 @@ void GUI::openPOIFile()
|
|||||||
} else {
|
} else {
|
||||||
_showPOIAction->setChecked(true);
|
_showPOIAction->setChecked(true);
|
||||||
_track->loadPOI(_poi);
|
_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()
|
void GUI::saveAs()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, "Export to PDF",
|
QString fileName = QFileDialog::getSaveFileName(this, "Export to PDF",
|
||||||
@ -654,6 +709,14 @@ void GUI::mapChanged(int index)
|
|||||||
_track->setMap(_currentMap);
|
_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)
|
void GUI::graphChanged(int index)
|
||||||
{
|
{
|
||||||
if (_trackGraphs->widget(index) == _elevationGraph)
|
if (_trackGraphs->widget(index) == _elevationGraph)
|
||||||
|
25
src/gui.h
25
src/gui.h
@ -2,16 +2,17 @@
|
|||||||
#define GUI_H
|
#define GUI_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMenu>
|
#include <QString>
|
||||||
#include <QToolBar>
|
#include <QList>
|
||||||
#include <QTabWidget>
|
|
||||||
#include <QGraphicsView>
|
|
||||||
#include <QActionGroup>
|
|
||||||
#include <QAction>
|
|
||||||
#include <QLabel>
|
|
||||||
#include "poi.h"
|
#include "poi.h"
|
||||||
|
|
||||||
|
class QMenu;
|
||||||
|
class QToolBar;
|
||||||
|
class QTabWidget;
|
||||||
|
class QActionGroup;
|
||||||
|
class QAction;
|
||||||
|
class QLabel;
|
||||||
|
class QSignalMapper;
|
||||||
class FileBrowser;
|
class FileBrowser;
|
||||||
class ElevationGraph;
|
class ElevationGraph;
|
||||||
class SpeedGraph;
|
class SpeedGraph;
|
||||||
@ -37,6 +38,7 @@ private slots:
|
|||||||
void closeFile();
|
void closeFile();
|
||||||
void reloadFile();
|
void reloadFile();
|
||||||
void openPOIFile();
|
void openPOIFile();
|
||||||
|
void closePOIFiles();
|
||||||
void showPOI(bool checked);
|
void showPOI(bool checked);
|
||||||
void showMap(bool checked);
|
void showMap(bool checked);
|
||||||
void showGraphs(bool checked);
|
void showGraphs(bool checked);
|
||||||
@ -44,6 +46,7 @@ private slots:
|
|||||||
|
|
||||||
void mapChanged(int);
|
void mapChanged(int);
|
||||||
void graphChanged(int);
|
void graphChanged(int);
|
||||||
|
void poiFileChecked(int);
|
||||||
|
|
||||||
void next();
|
void next();
|
||||||
void prev();
|
void prev();
|
||||||
@ -57,6 +60,7 @@ private:
|
|||||||
void loadFiles();
|
void loadFiles();
|
||||||
|
|
||||||
void createMapActions();
|
void createMapActions();
|
||||||
|
void createPOIFilesActions();
|
||||||
void createActions();
|
void createActions();
|
||||||
void createMenus();
|
void createMenus();
|
||||||
void createToolBars();
|
void createToolBars();
|
||||||
@ -77,6 +81,7 @@ private:
|
|||||||
QMenu *_mapMenu;
|
QMenu *_mapMenu;
|
||||||
QMenu *_settingsMenu;
|
QMenu *_settingsMenu;
|
||||||
QMenu *_unitsMenu;
|
QMenu *_unitsMenu;
|
||||||
|
QMenu *_poiFilesMenu;
|
||||||
|
|
||||||
QToolBar *_fileToolBar;
|
QToolBar *_fileToolBar;
|
||||||
QToolBar *_showToolBar;
|
QToolBar *_showToolBar;
|
||||||
@ -96,6 +101,7 @@ private:
|
|||||||
QAction *_closeFileAction;
|
QAction *_closeFileAction;
|
||||||
QAction *_reloadFileAction;
|
QAction *_reloadFileAction;
|
||||||
QAction *_openPOIAction;
|
QAction *_openPOIAction;
|
||||||
|
QAction *_closePOIAction;
|
||||||
QAction *_showPOIAction;
|
QAction *_showPOIAction;
|
||||||
QAction *_showMapAction;
|
QAction *_showMapAction;
|
||||||
QAction *_showGraphsAction;
|
QAction *_showGraphsAction;
|
||||||
@ -107,6 +113,9 @@ private:
|
|||||||
QAction *_metricUnitsAction;
|
QAction *_metricUnitsAction;
|
||||||
QAction *_imperialUnitsAction;
|
QAction *_imperialUnitsAction;
|
||||||
QList<QAction*> _mapActions;
|
QList<QAction*> _mapActions;
|
||||||
|
QList<QAction*> _poiFilesActions;
|
||||||
|
|
||||||
|
QSignalMapper *_poiFilesSM;
|
||||||
|
|
||||||
QLabel *_fileNameLabel;
|
QLabel *_fileNameLabel;
|
||||||
QLabel *_distanceLabel;
|
QLabel *_distanceLabel;
|
||||||
|
48
src/poi.cpp
48
src/poi.cpp
@ -39,21 +39,28 @@ bool POI::loadFile(const QString &fileName)
|
|||||||
bool POI::loadGPXFile(const QString &fileName)
|
bool POI::loadGPXFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
GPX gpx;
|
GPX gpx;
|
||||||
int cnt = _data.size();
|
FileIndex index;
|
||||||
|
|
||||||
|
index.enabled = true;
|
||||||
|
index.start = _data.size();
|
||||||
|
|
||||||
if (gpx.loadFile(fileName)) {
|
if (gpx.loadFile(fileName)) {
|
||||||
for (int i = 0; i < gpx.waypoints().size(); i++)
|
for (int i = 0; i < gpx.waypoints().size(); i++)
|
||||||
_data.append(Waypoint(
|
_data.append(Waypoint(
|
||||||
ll2mercator(gpx.waypoints().at(i).coordinates()),
|
ll2mercator(gpx.waypoints().at(i).coordinates()),
|
||||||
gpx.waypoints().at(i).description()));
|
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];
|
qreal c[2];
|
||||||
c[0] = _data.at(i).coordinates().x();
|
c[0] = _data.at(i).coordinates().x();
|
||||||
c[1] = _data.at(i).coordinates().y();
|
c[1] = _data.at(i).coordinates().y();
|
||||||
_tree.Insert(c, c, i);
|
_tree.Insert(c, c, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_files.append(fileName);
|
||||||
|
_indexes.append(index);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
_error = gpx.errorString();
|
_error = gpx.errorString();
|
||||||
@ -66,8 +73,12 @@ bool POI::loadGPXFile(const QString &fileName)
|
|||||||
bool POI::loadCSVFile(const QString &fileName)
|
bool POI::loadCSVFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
|
FileIndex index;
|
||||||
bool ret;
|
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)) {
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
_error = qPrintable(file.errorString());
|
_error = qPrintable(file.errorString());
|
||||||
@ -101,14 +112,18 @@ bool POI::loadCSVFile(const QString &fileName)
|
|||||||
QString::fromUtf8(ba.data(), ba.size())));
|
QString::fromUtf8(ba.data(), ba.size())));
|
||||||
ln++;
|
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];
|
qreal c[2];
|
||||||
c[0] = _data.at(i).coordinates().x();
|
c[0] = _data.at(i).coordinates().x();
|
||||||
c[1] = _data.at(i).coordinates().y();
|
c[1] = _data.at(i).coordinates().y();
|
||||||
_tree.Insert(c, c, i);
|
_tree.Insert(c, c, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_files.append(fileName);
|
||||||
|
_indexes.append(index);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +158,33 @@ QVector<Waypoint> POI::points(const QVector<QPointF> &path, qreal radius) const
|
|||||||
return ret;
|
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()
|
void POI::clear()
|
||||||
{
|
{
|
||||||
_tree.RemoveAll();
|
_tree.RemoveAll();
|
||||||
_data.clear();
|
_data.clear();
|
||||||
|
_files.clear();
|
||||||
|
_indexes.clear();
|
||||||
}
|
}
|
||||||
|
11
src/poi.h
11
src/poi.h
@ -4,6 +4,7 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
#include "waypoint.h"
|
#include "waypoint.h"
|
||||||
#include "rtree.h"
|
#include "rtree.h"
|
||||||
|
|
||||||
@ -18,17 +19,25 @@ public:
|
|||||||
|
|
||||||
QVector<Waypoint> points(const QVector<QPointF> &path,
|
QVector<Waypoint> points(const QVector<QPointF> &path,
|
||||||
qreal radius = 0.01) const;
|
qreal radius = 0.01) const;
|
||||||
|
const QStringList &files() const {return _files;}
|
||||||
|
void enableFile(const QString &fileName, bool enable);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef RTree<size_t, qreal, 2> POITree;
|
typedef RTree<size_t, qreal, 2> POITree;
|
||||||
|
typedef struct {
|
||||||
|
int start;
|
||||||
|
int end;
|
||||||
|
bool enabled;
|
||||||
|
} FileIndex;
|
||||||
|
|
||||||
bool loadCSVFile(const QString &fileName);
|
bool loadCSVFile(const QString &fileName);
|
||||||
bool loadGPXFile(const QString &fileName);
|
bool loadGPXFile(const QString &fileName);
|
||||||
|
|
||||||
POITree _tree;
|
POITree _tree;
|
||||||
QVector<Waypoint> _data;
|
QVector<Waypoint> _data;
|
||||||
|
QStringList _files;
|
||||||
|
QList<FileIndex> _indexes;
|
||||||
|
|
||||||
QString _error;
|
QString _error;
|
||||||
int _errorLine;
|
int _errorLine;
|
||||||
|
Loading…
Reference in New Issue
Block a user