From 531eb256f1cc405160f299a43135b84f0fdfcc9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sat, 21 Jul 2018 16:13:18 +0200 Subject: [PATCH] Added statistics window --- gpxsee.pro | 3 +- src/GUI/graphview.h | 3 +- src/GUI/gui.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++-- src/GUI/gui.h | 2 ++ src/GUI/infoitem.cpp | 12 ++++---- src/GUI/infoitem.h | 14 ++------- src/GUI/keys.h | 1 + src/GUI/kv.h | 21 +++++++++++++ 8 files changed, 105 insertions(+), 21 deletions(-) create mode 100644 src/GUI/kv.h diff --git a/gpxsee.pro b/gpxsee.pro index b56c992f..cb368522 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -132,7 +132,8 @@ HEADERS += src/config.h \ src/map/geocentric.h \ src/map/mercator.h \ src/map/jnxmap.h \ - src/map/krovak.h + src/map/krovak.h \ + src/GUI/kv.h SOURCES += src/main.cpp \ src/common/coordinates.cpp \ src/common/rectc.cpp \ diff --git a/src/GUI/graphview.h b/src/GUI/graphview.h index 032c51cc..7f2f9877 100644 --- a/src/GUI/graphview.h +++ b/src/GUI/graphview.h @@ -7,12 +7,12 @@ #include "data/graph.h" #include "palette.h" #include "units.h" +#include "infoitem.h" class AxisItem; class SliderItem; class SliderInfoItem; -class InfoItem; class GraphItem; class PathItem; class GridItem; @@ -27,6 +27,7 @@ public: ~GraphView(); bool isEmpty() const {return _graphs.isEmpty();} + const QList &info() const {return _info->info();} void clear(); void plot(QPainter *painter, const QRectF &target, qreal scale); diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index e621061f..c81ad1fc 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -238,6 +238,10 @@ void GUI::createActions() _reloadFileAction->setActionGroup(_fileActionGroup); connect(_reloadFileAction, SIGNAL(triggered()), this, SLOT(reloadFile())); addAction(_reloadFileAction); + _statisticsAction = new QAction(tr("Statistics..."), this); + _statisticsAction->setShortcut(STATISTICS_SHORTCUT); + _statisticsAction->setActionGroup(_fileActionGroup); + connect(_statisticsAction, SIGNAL(triggered()), this, SLOT(statistics())); // POI actions _openPOIAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)), @@ -432,8 +436,9 @@ void GUI::createMenus() fileMenu->addAction(_printFileAction); fileMenu->addAction(_exportFileAction); fileMenu->addSeparator(); - fileMenu->addAction(_reloadFileAction); + fileMenu->addAction(_statisticsAction); fileMenu->addSeparator(); + fileMenu->addAction(_reloadFileAction); fileMenu->addAction(_closeFileAction); #ifndef Q_OS_MAC fileMenu->addSeparator(); @@ -908,6 +913,67 @@ void GUI::exportFile() plot(&printer); } +void GUI::statistics() +{ + QString text = ""; + + if (_showTracksAction->isChecked() && _trackCount > 1) + text.append(""); + if (_showRoutesAction->isChecked() && _routeCount > 1) + text.append(""); + if (_showWaypointsAction->isChecked() && _waypointCount > 1) + text.append(""); + + if (_dateRange.first.isValid()) { + if (_dateRange.first == _dateRange.second) { + QString format = QLocale::system().dateFormat(QLocale::LongFormat); + text.append(""); + } else { + QString format = QLocale::system().dateFormat(QLocale::ShortFormat); + text.append(""); + } + } + + if (distance() > 0) + text.append(""); + if (time() > 0) { + text.append(""); + text.append(""); + } + + for (int i = 0; i < _tabs.count(); i++) { + const GraphTab *tab = _tabs.at(i); + if (tab->isEmpty()) + continue; + + text.append(""); + for (int j = 0; j < tab->info().size(); j++) { + const KV &kv = tab->info().at(j); + text.append(""); + } + } + + text.append("
" + tr("Tracks") + ":" + + QString::number(_trackCount) + "
" + tr("Routes") + ":" + + QString::number(_routeCount) + "
" + tr("Waypoints") + ":" + + QString::number(_waypointCount) + "
" + tr("Date") + ":" + + _dateRange.first.toString(format) + "
" + tr("Date") + ":" + + QString("%1 - %2").arg(_dateRange.first.toString(format), + _dateRange.second.toString(format)) + "
" + tr("Distance") + ":" + + Format::distance(distance(), units()) + "
" + tr("Time") + ":" + + Format::timeSpan(time()) + "
" + tr("Moving time") + ":" + + Format::timeSpan(movingTime()) + "
" + tab->label() + "
" + kv.key() + ":" + kv.value() + + "
"); + + + QMessageBox msgBox(this); + msgBox.setWindowTitle(tr("Statistics")); + msgBox.setText("

" + tr("Statistics") + "

"); + msgBox.setInformativeText(text); + msgBox.exec(); +} + void GUI::plot(QPrinter *printer) { QPainter p(printer); @@ -925,7 +991,7 @@ void GUI::plot(QPrinter *printer) info.insert(tr("Tracks"), QString::number(_trackCount)); if (_showRoutesAction->isChecked() && _routeCount > 1) info.insert(tr("Routes"), QString::number(_routeCount)); - if (_showWaypointsAction->isChecked() && _waypointCount > 2) + if (_showWaypointsAction->isChecked() && _waypointCount > 1) info.insert(tr("Waypoints"), QString::number(_waypointCount)); } diff --git a/src/GUI/gui.h b/src/GUI/gui.h index 981dd259..92a4f77d 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -47,6 +47,7 @@ private slots: void openFile(); void closeAll(); void reloadFile(); + void statistics(); void openPOIFile(); void closePOIFiles(); void showGraphs(bool show); @@ -150,6 +151,7 @@ private: QAction *_openFileAction; QAction *_closeFileAction; QAction *_reloadFileAction; + QAction *_statisticsAction; QAction *_openPOIAction; QAction *_closePOIAction; QAction *_showPOIAction; diff --git a/src/GUI/infoitem.cpp b/src/GUI/infoitem.cpp index 0a204bea..9de666bd 100644 --- a/src/GUI/infoitem.cpp +++ b/src/GUI/infoitem.cpp @@ -22,8 +22,8 @@ void InfoItem::updateBoundingRect() for (QList::const_iterator i = _list.constBegin(); i != _list.constEnd(); i++) { - width += fm.width(i->key + ": "); - width += fm.width(i->value) + ((i == _list.constEnd() - 1) + width += fm.width(i->key() + ": "); + width += fm.width(i->value()) + ((i == _list.constEnd() - 1) ? 0 : PADDING); } @@ -43,10 +43,10 @@ void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, for (QList::const_iterator i = _list.constBegin(); i != _list.constEnd(); i++) { - painter->drawText(width, fm.height() - fm.descent(), i->key + ": "); - width += fm.width(i->key + ": "); - painter->drawText(width, fm.height() - fm.descent(), i->value); - width += fm.width(i->value) + ((i == _list.constEnd() - 1) + painter->drawText(width, fm.height() - fm.descent(), i->key() + ": "); + width += fm.width(i->key() + ": "); + painter->drawText(width, fm.height() - fm.descent(), i->value()); + width += fm.width(i->value()) + ((i == _list.constEnd() - 1) ? 0 : PADDING); if (i != _list.constEnd() - 1) { painter->save(); diff --git a/src/GUI/infoitem.h b/src/GUI/infoitem.h index 48a9662a..e64f3842 100644 --- a/src/GUI/infoitem.h +++ b/src/GUI/infoitem.h @@ -3,6 +3,7 @@ #include #include +#include "kv.h" class InfoItem : public QGraphicsItem { @@ -13,6 +14,8 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + const QList &info() const {return _list;} + void insert(const QString &key, const QString &value); void clear(); bool isEmpty() {return _list.isEmpty();} @@ -20,17 +23,6 @@ public: private: void updateBoundingRect(); - class KV { - public: - QString key; - QString value; - - KV(const QString &k, const QString &v) - {key = k; value = v;} - bool operator==(const KV &other) const - {return this->key == other.key;} - }; - QList _list; QRectF _boundingRect; QFont _font; diff --git a/src/GUI/keys.h b/src/GUI/keys.h index 9d87baa8..b05631c8 100644 --- a/src/GUI/keys.h +++ b/src/GUI/keys.h @@ -24,6 +24,7 @@ #define NEXT_MAP_SHORTCUT QKeySequence(QKeySequence::Forward) #define PREV_MAP_SHORTCUT QKeySequence(QKeySequence::Back) #define SHOW_GRAPHS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_G) +#define STATISTICS_SHORTCUT QKeySequence(Qt::CTRL + Qt::Key_S) #ifdef Q_OS_MAC #define FULLSCREEN_SHORTCUT QKeySequence(Qt::META + Qt::CTRL + Qt::Key_F) diff --git a/src/GUI/kv.h b/src/GUI/kv.h new file mode 100644 index 00000000..b9c65f41 --- /dev/null +++ b/src/GUI/kv.h @@ -0,0 +1,21 @@ +#ifndef KV_H +#define KV_H + +#include + +class KV { +public: + KV(const QString &key, const QString &value) : _key(key), _value(value) {} + + const QString &key() const {return _key;} + const QString &value() const {return _value;} + + bool operator==(const KV &other) const + {return this->key() == other.key();} + +private: + QString _key; + QString _value; +}; + +#endif // KV_H