From 5bd744a8ed4f490313c82262e28c34e325aeb856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 20 May 2020 21:00:36 +0200 Subject: [PATCH] Added time zone settings --- gpxsee.pro | 6 ++-- src/GUI/gui.cpp | 33 ++++++++++++++---- src/GUI/gui.h | 6 ++-- src/GUI/mapview.cpp | 49 +++++++++------------------ src/GUI/mapview.h | 4 +-- src/GUI/optionsdialog.cpp | 70 +++++++++++++++++++++++++++++++++++---- src/GUI/optionsdialog.h | 16 +++++++-- src/GUI/pathitem.cpp | 16 +++------ src/GUI/pathitem.h | 18 ++++++++-- src/GUI/routeitem.cpp | 23 ------------- src/GUI/routeitem.h | 3 -- src/GUI/settings.h | 1 + src/GUI/timezoneinfo.h | 69 ++++++++++++++++++++++++++++++++++++++ src/GUI/trackitem.cpp | 8 ++++- src/GUI/waypointitem.cpp | 23 +++++++------ src/GUI/waypointitem.h | 19 +++++++++-- src/common/config.h | 4 +++ src/main.cpp | 6 ++++ 18 files changed, 266 insertions(+), 108 deletions(-) create mode 100644 src/GUI/timezoneinfo.h diff --git a/gpxsee.pro b/gpxsee.pro index 7dd7f39b..321dde77 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -14,8 +14,7 @@ greaterThan(QT_MAJOR_VERSION, 4) { QT += widgets QT += printsupport } -lessThan(QT_MAJOR_VERSION, 5) {QT += opengl} -equals(QT_MAJOR_VERSION, 5) : lessThan(QT_MINOR_VERSION, 4) {QT += opengl} +lessThan(QT_VERSION, 5.4.0) {QT += opengl} INCLUDEPATH += ./src HEADERS += src/common/config.h \ @@ -348,6 +347,9 @@ greaterThan(QT_MAJOR_VERSION, 4) { HEADERS += src/data/geojsonparser.h SOURCES += src/data/geojsonparser.cpp } +greaterThan(QT_VERSION, 5.1.0) { + HEADERS += src/GUI/timezoneinfo.h +} DEFINES += APP_VERSION=\\\"$$VERSION\\\" \ QT_NO_DEPRECATED_WARNINGS diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index 07d3e482..5592ebe6 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -248,7 +248,7 @@ void GUI::createActions() _reloadFileAction->setMenuRole(QAction::NoRole); _reloadFileAction->setShortcut(RELOAD_SHORTCUT); _reloadFileAction->setActionGroup(_fileActionGroup); - connect(_reloadFileAction, SIGNAL(triggered()), this, SLOT(reloadFile())); + connect(_reloadFileAction, SIGNAL(triggered()), this, SLOT(reloadFiles())); addAction(_reloadFileAction); _statisticsAction = new QAction(tr("Statistics..."), this); _statisticsAction->setMenuRole(QAction::NoRole); @@ -791,7 +791,12 @@ bool GUI::loadFile(const QString &fileName) _trackDistance += track.distance(); _time += track.time(); _movingTime += track.movingTime(); - const QDate &date = track.date().date(); +#ifdef ENABLE_TIMEZONES + const QDateTime date = track.date().toTimeZone( + _options.timeZone.zone()); +#else // ENABLE_TIMEZONES + const QDateTime &date = track.date(); +#endif // ENABLE_TIMEZONES if (_dateRange.first.isNull() || _dateRange.first > date) _dateRange.first = date; if (_dateRange.second.isNull() || _dateRange.second < date) @@ -990,9 +995,16 @@ void GUI::openOptions() _mapView->setDevicePixelRatio(devicePixelRatioF(), options.hidpiMap ? devicePixelRatioF() : 1.0); #endif // ENABLE_HIDPI +#ifdef ENABLE_TIMEZONES + if (options.timeZone != _options.timeZone) { + _mapView->setTimeZone(options.timeZone.zone()); + _dateRange.first = _dateRange.first.toTimeZone(options.timeZone.zone()); + _dateRange.second = _dateRange.second.toTimeZone(options.timeZone.zone()); + } +#endif // ENABLE_TIMEZONES if (reload) - reloadFile(); + reloadFiles(); _options = options; } @@ -1185,7 +1197,7 @@ void GUI::plot(QPrinter *printer) } } -void GUI::reloadFile() +void GUI::reloadFiles() { _trackCount = 0; _routeCount = 0; @@ -1195,7 +1207,7 @@ void GUI::reloadFile() _routeDistance = 0; _time = 0; _movingTime = 0; - _dateRange = DateRange(QDate(), QDate()); + _dateRange = DateTimeRange(QDateTime(), QDateTime()); _pathName = QString(); for (int i = 0; i < _tabs.count(); i++) @@ -1229,7 +1241,7 @@ void GUI::closeFiles() _routeDistance = 0; _time = 0; _movingTime = 0; - _dateRange = DateRange(QDate(), QDate()); + _dateRange = DateTimeRange(QDateTime(), QDateTime()); _pathName = QString(); _sliderPos = 0; @@ -1867,6 +1879,9 @@ void GUI::writeSettings() if (_options.showSecondarySpeed != SHOW_SECONDARY_SPEED_DEFAULT) settings.setValue(SHOW_SECONDARY_SPEED_SETTING, _options.showSecondarySpeed); + if (_options.timeZone != TimeZoneInfo()) + settings.setValue(TIME_ZONE_SETTING, QVariant::fromValue( + _options.timeZone)); if (_options.poiRadius != POI_RADIUS_DEFAULT) settings.setValue(POI_RADIUS_SETTING, _options.poiRadius); if (_options.useOpenGL != USE_OPENGL_DEFAULT) @@ -2139,6 +2154,9 @@ void GUI::readSettings() _options.showSecondarySpeed = settings.value( SHOW_SECONDARY_SPEED_SETTING, SHOW_SECONDARY_SPEED_DEFAULT).toBool(); +#ifdef ENABLE_TIMEZONES + _options.timeZone = settings.value(TIME_ZONE_SETTING).value(); +#endif // ENABLE_TIMEZONES _options.automaticPause = settings.value(AUTOMATIC_PAUSE_SETTING, AUTOMATIC_PAUSE_DEFAULT).toBool(); _options.pauseInterval = settings.value(PAUSE_INTERVAL_SETTING, @@ -2203,6 +2221,9 @@ void GUI::readSettings() _options.hidpiMap ? devicePixelRatioF() : 1.0); #endif // ENABLE_HIDPI _mapView->setProjection(_options.projection); +#ifdef ENABLE_TIMEZONES + _mapView->setTimeZone(_options.timeZone.zone()); +#endif // ENABLE_TIMEZONES for (int i = 0; i < _tabs.count(); i++) { _tabs.at(i)->setPalette(_options.palette); diff --git a/src/GUI/gui.h b/src/GUI/gui.h index 95c2ab68..5faa0834 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -48,7 +48,7 @@ private slots: void exportFile(); void openFile(); void closeAll(); - void reloadFile(); + void reloadFiles(); void statistics(); void openPOIFile(); void closePOIFiles(); @@ -92,7 +92,7 @@ private slots: void mapInitialized(); private: - typedef QPair DateRange; + typedef QPair DateTimeRange; void loadPOIs(); void closeFiles(); @@ -220,7 +220,7 @@ private: int _trackCount, _routeCount, _areaCount, _waypointCount; qreal _trackDistance, _routeDistance; qreal _time, _movingTime; - DateRange _dateRange; + DateTimeRange _dateRange; QString _pathName; qreal _sliderPos; diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index b2150b7e..46d308c3 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -59,8 +59,6 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent) _poi = poi; connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI())); - _units = Metric; - _coordinatesFormat = DecimalDegrees; _mapOpacity = 1.0; _backgroundColor = Qt::white; _markerColor = Qt::red; @@ -122,7 +120,6 @@ PathItem *MapView::addTrack(const Track &track) ti->setColor(_palette.nextColor()); ti->setWidth(_trackWidth); ti->setStyle(_trackStyle); - ti->setUnits(_units); ti->setVisible(_showTracks); ti->setDigitalZoom(_digitalZoom); ti->setMarkerColor(_markerColor); @@ -149,8 +146,6 @@ PathItem *MapView::addRoute(const Route &route) ri->setColor(_palette.nextColor()); ri->setWidth(_routeWidth); ri->setStyle(_routeStyle); - ri->setUnits(_units); - ri->setCoordinatesFormat(_coordinatesFormat); ri->setVisible(_showRoutes); ri->showWaypoints(_showRouteWaypoints); ri->showWaypointLabels(_showWaypointLabels); @@ -200,7 +195,6 @@ void MapView::addWaypoints(const QVector &waypoints) wi->setSize(_waypointSize); wi->setColor(_waypointColor); wi->showLabel(_showWaypointLabels); - wi->setToolTipFormat(_units, _coordinatesFormat); wi->setVisible(_showWaypoints); wi->setDigitalZoom(_digitalZoom); _scene->addItem(wi); @@ -401,7 +395,6 @@ void MapView::addPOI(const QList &waypoints) pi->showLabel(_showPOILabels); pi->setVisible(_showPOI); pi->setDigitalZoom(_digitalZoom); - pi->setToolTipFormat(_units, _coordinatesFormat); _scene->addItem(pi); _pois.insert(SearchPointer(&(pi->waypoint())), pi); @@ -410,42 +403,32 @@ void MapView::addPOI(const QList &waypoints) void MapView::setUnits(Units units) { - if (_units == units) - return; - - _units = units; - - _mapScale->setUnits(_units); + WaypointItem::setUnits(units); + PathItem::setUnits(units); for (int i = 0; i < _tracks.count(); i++) - _tracks[i]->setUnits(_units); + _tracks[i]->updateTicks(); for (int i = 0; i < _routes.count(); i++) - _routes[i]->setUnits(_units); - for (int i = 0; i < _waypoints.size(); i++) - _waypoints.at(i)->setToolTipFormat(_units, _coordinatesFormat); + _routes[i]->updateTicks(); - for (POIHash::const_iterator it = _pois.constBegin(); - it != _pois.constEnd(); it++) - it.value()->setToolTipFormat(_units, _coordinatesFormat); + _mapScale->setUnits(units); } void MapView::setCoordinatesFormat(CoordinatesFormat format) { - if (_coordinatesFormat == format) - return; + WaypointItem::setCoordinatesFormat(format); - _coordinatesFormat = format; + _coordinates->setFormat(format); +} - _coordinates->setFormat(_coordinatesFormat); - - for (int i = 0; i < _waypoints.count(); i++) - _waypoints.at(i)->setToolTipFormat(_units, _coordinatesFormat); - for (int i = 0; i < _routes.count(); i++) - _routes[i]->setCoordinatesFormat(_coordinatesFormat); - - for (POIHash::const_iterator it = _pois.constBegin(); - it != _pois.constEnd(); it++) - it.value()->setToolTipFormat(_units, _coordinatesFormat); +void MapView::setTimeZone(const QTimeZone &zone) +{ +#ifdef ENABLE_TIMEZONES + WaypointItem::setTimeZone(zone); + PathItem::setTimeZone(zone); +#else // ENABLE_TIMEZONES + Q_UNUSED(zone); +#endif // ENABLE_TIMEZONES } void MapView::clearMapCache() diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index c0800f0f..fb57e091 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -31,6 +31,7 @@ class GraphItem; class AreaItem; class Area; class GraphicsScene; +class QTimeZone; class MapView : public QGraphicsView { @@ -83,6 +84,7 @@ public slots: void showTicks(bool show); void clearMapCache(); void setCoordinatesFormat(CoordinatesFormat format); + void setTimeZone(const QTimeZone &zone); void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio); void setProjection(int id); @@ -137,8 +139,6 @@ private: POI *_poi; Palette _palette; - Units _units; - CoordinatesFormat _coordinatesFormat; qreal _mapOpacity; Projection _projection; diff --git a/src/GUI/optionsdialog.cpp b/src/GUI/optionsdialog.cpp index 10732440..0ade8aba 100644 --- a/src/GUI/optionsdialog.cpp +++ b/src/GUI/optionsdialog.cpp @@ -167,11 +167,8 @@ QWidget *OptionsDialog::createAppearancePage() // Palette & antialiasing _baseColor = new ColorBox(); _baseColor->setColor(_options->palette.color()); - _colorOffset = new QDoubleSpinBox(); - _colorOffset->setMinimum(0); - _colorOffset->setMaximum(1.0); - _colorOffset->setSingleStep(0.01); - _colorOffset->setValue(_options->palette.shift()); + _colorOffset = new PercentSlider(); + _colorOffset->setValue(_options->palette.shift() * 100); QFormLayout *paletteLayout = new QFormLayout(); paletteLayout->addRow(tr("Base color:"), _baseColor); paletteLayout->addRow(tr("Palette shift:"), _colorOffset); @@ -419,6 +416,29 @@ QWidget *OptionsDialog::createDataPage() _showSecondaryElevation = new QCheckBox(tr("Show secondary elevation")); _showSecondaryElevation->setChecked(_options->showSecondaryElevation); +#ifdef ENABLE_TIMEZONES + _utcZone = new QRadioButton(tr("UTC")); + _systemZone = new QRadioButton(tr("System")); + _customZone = new QRadioButton(tr("Custom")); + if (_options->timeZone.type() == TimeZoneInfo::UTC) + _utcZone->setChecked(true); + else if (_options->timeZone.type() == TimeZoneInfo::System) + _systemZone->setChecked(true); + else + _customZone->setChecked(true); + _timeZone = new QComboBox(); + _timeZone->setEnabled(_customZone->isChecked()); + QList zones = QTimeZone::availableTimeZoneIds(); + for (int i = 0; i < zones.size(); i++) + _timeZone->addItem(zones.at(i)); + _timeZone->setCurrentText(_options->timeZone.customZone().id()); + connect(_customZone, SIGNAL(toggled(bool)), _timeZone, + SLOT(setEnabled(bool))); + QHBoxLayout *customZoneLayout = new QHBoxLayout(); + customZoneLayout->addSpacing(20); + customZoneLayout->addWidget(_timeZone); +#endif // ENABLE_TIMEZONES + QWidget *sourceTab = new QWidget(); QVBoxLayout *sourceTabLayout = new QVBoxLayout(); @@ -439,14 +459,32 @@ QWidget *OptionsDialog::createDataPage() elevationOptions->addWidget(_dataDEMElevation); elevationOptions->addWidget(_showSecondaryElevation); +#ifdef ENABLE_TIMEZONES + QButtonGroup *zoneGroup = new QButtonGroup(this); + timeZoneGroup->addButton(_utcZone); + timeZoneGroup->addButton(_systemZone); + timeZoneGroup->addButton(_customZone); + QVBoxLayout *zoneOptions = new QVBoxLayout(); + zoneOptions->addWidget(_utcZone); + zoneOptions->addWidget(_systemZone); + zoneOptions->addWidget(_customZone); + zoneOptions->addItem(customZoneLayout); +#endif // ENABLE_TIMEZONES + QFormLayout *formLayout = new QFormLayout(); formLayout->addRow(tr("Speed:"), speedOptions); formLayout->addRow(tr("Elevation:"), elevationOptions); +#ifdef ENABLE_TIMEZONES + formLayout->addRow(tr("Time zone:"), zoneOptions); +#endif // ENABLE_TIMEZONES sourceTabLayout->addLayout(formLayout); #else // Q_OS_MAC QFormLayout *speedLayout = new QFormLayout(); QFormLayout *elevationLayout = new QFormLayout(); +#ifdef ENABLE_TIMEZONES + QFormLayout *timeZoneLayout = new QFormLayout(); +#endif // ENABLE_TIMEZONES speedLayout->addWidget(_computedSpeed); speedLayout->addWidget(_reportedSpeed); @@ -462,8 +500,21 @@ QWidget *OptionsDialog::createDataPage() QGroupBox *elevationBox = new QGroupBox(tr("Elevation")); elevationBox->setLayout(elevationLayout); +#ifdef ENABLE_TIMEZONES + timeZoneLayout->addWidget(_utcZone); + timeZoneLayout->addWidget(_systemZone); + timeZoneLayout->addWidget(_customZone); + timeZoneLayout->addItem(customZoneLayout); + + QGroupBox *timeZoneBox = new QGroupBox(tr("Time zone")); + timeZoneBox->setLayout(timeZoneLayout); +#endif // ENABLE_TIMEZONES + sourceTabLayout->addWidget(speedBox); sourceTabLayout->addWidget(elevationBox); +#ifdef ENABLE_TIMEZONES + sourceTabLayout->addWidget(timeZoneBox); +#endif // ENABLE_TIMEZONES #endif // Q_OS_MAC sourceTabLayout->addStretch(); sourceTab->setLayout(sourceTabLayout); @@ -677,7 +728,7 @@ OptionsDialog::OptionsDialog(Options *options, QWidget *parent) void OptionsDialog::accept() { _options->palette.setColor(_baseColor->color()); - _options->palette.setShift(_colorOffset->value()); + _options->palette.setShift(_colorOffset->value() / 100.0); _options->mapOpacity = _mapOpacity->value(); _options->backgroundColor = _backgroundColor->color(); _options->trackWidth = _trackWidth->value(); @@ -722,6 +773,13 @@ void OptionsDialog::accept() _options->dataUseDEM = _dataDEMElevation->isChecked(); _options->showSecondaryElevation = _showSecondaryElevation->isChecked(); _options->showSecondarySpeed = _showSecondarySpeed->isChecked(); +#ifdef ENABLE_TIMEZONES + _options->timeZone.setType(_utcZone->isChecked() + ? TimeZoneInfo::UTC : _systemZone->isChecked() + ? TimeZoneInfo::System : TimeZoneInfo::Custom); + _options->timeZone.setCustomZone(QTimeZone(_timeZone->currentText() + .toLatin1())); +#endif // ENABLE_TIMEZONES qreal poiRadius = (_options->units == Imperial) ? _poiRadius->value() * MIINM : (_options->units == Nautical) diff --git a/src/GUI/optionsdialog.h b/src/GUI/optionsdialog.h index 417cac8c..cfcd8319 100644 --- a/src/GUI/optionsdialog.h +++ b/src/GUI/optionsdialog.h @@ -5,6 +5,9 @@ #include "common/config.h" #include "palette.h" #include "units.h" +#ifdef ENABLE_TIMEZONES +#include "timezoneinfo.h" +#endif // ENABLE_TIMEZONES class ColorBox; class StyleComboBox; @@ -17,6 +20,7 @@ class QRadioButton; class PercentSlider; class LimitedComboBox; + struct Options { // Appearance Palette palette; @@ -56,6 +60,9 @@ struct Options { bool dataUseDEM; bool showSecondaryElevation; bool showSecondarySpeed; +#ifdef ENABLE_TIMEZONES + TimeZoneInfo timeZone; +#endif // ENABLE_TIMEZONES // POI int poiRadius; // System @@ -103,7 +110,7 @@ private: // Appearance ColorBox *_baseColor; - QDoubleSpinBox *_colorOffset; + PercentSlider *_colorOffset; PercentSlider *_mapOpacity; ColorBox *_backgroundColor; QSpinBox *_trackWidth; @@ -134,7 +141,6 @@ private: OddSpinBox *_cadenceFilter; OddSpinBox *_powerFilter; QCheckBox *_outlierEliminate; - QRadioButton *_automaticPause; QRadioButton *_manualPause; QDoubleSpinBox *_pauseSpeed; @@ -145,6 +151,12 @@ private: QRadioButton *_dataDEMElevation; QCheckBox *_showSecondaryElevation; QCheckBox *_showSecondarySpeed; +#ifdef ENABLE_TIMEZONES + QRadioButton *_utcZone; + QRadioButton *_systemZone; + QRadioButton *_customZone; + QComboBox *_timeZone; +#endif // ENABLE_TIMEZONES // POI QDoubleSpinBox *_poiRadius; // System diff --git a/src/GUI/pathitem.cpp b/src/GUI/pathitem.cpp index 31df4209..1249077f 100644 --- a/src/GUI/pathitem.cpp +++ b/src/GUI/pathitem.cpp @@ -21,12 +21,16 @@ static inline unsigned segments(qreal distance) return ceil(distance / GEOGRAPHICAL_MILE); } +Units PathItem::_units = Metric; +#ifdef ENABLE_TIMEZONES +QTimeZone PathItem::_timeZone = QTimeZone::utc(); +#endif // ENABLE_TIMEZONES + PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent) : GraphicsItem(parent), _path(path), _map(map) { Q_ASSERT(_path.isValid()); - _units = Metric; _digitalZoom = 0; _width = 3; QBrush brush(Qt::SolidPattern); @@ -352,16 +356,6 @@ void PathItem::showTicks(bool show) updateTicks(); } -void PathItem::setUnits(Units units) -{ - if (_units == units) - return; - - prepareGeometryChange(); - _units = units; - updateTicks(); -} - void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); diff --git a/src/GUI/pathitem.h b/src/GUI/pathitem.h index a364f1b2..f142a8fc 100644 --- a/src/GUI/pathitem.h +++ b/src/GUI/pathitem.h @@ -1,8 +1,12 @@ #ifndef PATHITEM_H #define PATHITEM_H +#include "common/config.h" #include #include +#ifdef ENABLE_TIMEZONES +#include +#endif // ENABLE_TIMEZONES #include "data/path.h" #include "markeritem.h" #include "units.h" @@ -28,7 +32,6 @@ public: void setMap(Map *map); - void setUnits(Units units); void setColor(const QColor &color); void setWidth(qreal width); void setStyle(Qt::PenStyle style); @@ -37,6 +40,13 @@ public: void showMarker(bool show); void showTicks(bool show); + void updateTicks(); + + static void setUnits(Units units) {_units = units;} +#ifdef ENABLE_TIMEZONES + static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;} +#endif // ENABLE_TIMEZONES + public slots: void moveMarker(qreal distance); void hover(bool hover); @@ -49,7 +59,10 @@ protected: void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); - Units _units; + static Units _units; +#ifdef ENABLE_TIMEZONES + static QTimeZone _timeZone; +#endif // ENABLE_TIMEZONES private: const PathSegment *segment(qreal x) const; @@ -60,7 +73,6 @@ private: qreal xInM() const; unsigned tickSize() const; - void updateTicks(); Path _path; Map *_map; diff --git a/src/GUI/routeitem.cpp b/src/GUI/routeitem.cpp index 0f83b3ab..a18e4da2 100644 --- a/src/GUI/routeitem.cpp +++ b/src/GUI/routeitem.cpp @@ -47,7 +47,6 @@ RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent) _desc = route.description(); _comment = route.comment(); _links = route.links(); - _coordinatesFormat = DecimalDegrees; } void RouteItem::setMap(Map *map) @@ -58,28 +57,6 @@ void RouteItem::setMap(Map *map) PathItem::setMap(map); } -void RouteItem::setUnits(Units u) -{ - if (_units == u) - return; - - for (int i = 0; i < _waypoints.count(); i++) - _waypoints[i]->setToolTipFormat(u, _coordinatesFormat); - - PathItem::setUnits(u); -} - -void RouteItem::setCoordinatesFormat(CoordinatesFormat format) -{ - if (_coordinatesFormat == format) - return; - - _coordinatesFormat = format; - - for (int i = 0; i < _waypoints.count(); i++) - _waypoints[i]->setToolTipFormat(_units, _coordinatesFormat); -} - void RouteItem::showWaypoints(bool show) { for (int i = 0; i < _waypoints.count(); i++) diff --git a/src/GUI/routeitem.h b/src/GUI/routeitem.h index 8295201f..e6b20285 100644 --- a/src/GUI/routeitem.h +++ b/src/GUI/routeitem.h @@ -19,8 +19,6 @@ public: void setMap(Map *map); - void setUnits(Units u); - void setCoordinatesFormat(CoordinatesFormat format); void showWaypoints(bool show); void showWaypointLabels(bool show); @@ -31,7 +29,6 @@ private: QString _desc; QString _comment; QVector _links; - CoordinatesFormat _coordinatesFormat; QVector _waypoints; }; diff --git a/src/GUI/settings.h b/src/GUI/settings.h index afb09594..6211c5c1 100644 --- a/src/GUI/settings.h +++ b/src/GUI/settings.h @@ -149,6 +149,7 @@ #define SHOW_SECONDARY_ELEVATION_DEFAULT false #define SHOW_SECONDARY_SPEED_SETTING "showSecondarySpeed" #define SHOW_SECONDARY_SPEED_DEFAULT false +#define TIME_ZONE_SETTING "timeZone" #define POI_RADIUS_SETTING "poiRadius" #define POI_RADIUS_DEFAULT (int)(IMPERIAL_UNITS() ? MIINM : KMINM) #define USE_OPENGL_SETTING "useOpenGL" diff --git a/src/GUI/timezoneinfo.h b/src/GUI/timezoneinfo.h new file mode 100644 index 00000000..62f2708a --- /dev/null +++ b/src/GUI/timezoneinfo.h @@ -0,0 +1,69 @@ +#ifndef TIMEZONEINFO_H +#define TIMEZONEINFO_H + +#include +#include + +class TimeZoneInfo +{ +public: + enum Type { + UTC, + System, + Custom + }; + + TimeZoneInfo() : _type(UTC), _customZone(QTimeZone::systemTimeZone()) {} + + Type type() const {return _type;} + const QTimeZone &customZone() const {return _customZone;} + QTimeZone zone() const + { + if (_type == UTC) + return QTimeZone::utc(); + else if (_type == System) + return QTimeZone::systemTimeZone(); + else + return _customZone; + } + + void setType(Type type) {_type = type;} + void setCustomZone(const QTimeZone &zone) {_customZone = zone;} + + bool operator==(const TimeZoneInfo &other) const + { + if (_type == UTC || _type == System) + return _type == other._type; + else + return (other._type == Custom && _customZone == other._customZone); + } + bool operator!=(const TimeZoneInfo &other) {return !(*this == other);} + +private: + friend QDataStream& operator<<(QDataStream &out, const TimeZoneInfo &info); + friend QDataStream& operator>>(QDataStream &in, TimeZoneInfo &info); + + Type _type; + QTimeZone _customZone; +}; + +Q_DECLARE_METATYPE(TimeZoneInfo) + +inline QDataStream &operator<<(QDataStream &out, const TimeZoneInfo &info) +{ + out << static_cast(info._type) << info._customZone; + return out; +} + +inline QDataStream &operator>>(QDataStream &in, TimeZoneInfo &info) +{ + int t; + + in >> t; + info._type = static_cast(t); + in >> info._customZone; + + return in; +} + +#endif // TIMEZONEINFO_H diff --git a/src/GUI/trackitem.cpp b/src/GUI/trackitem.cpp index b4629fd9..32f85c23 100644 --- a/src/GUI/trackitem.cpp +++ b/src/GUI/trackitem.cpp @@ -22,7 +22,13 @@ QString TrackItem::info() const if (_movingTime > 0) tt.insert(tr("Moving time"), Format::timeSpan(_movingTime)); if (!_date.isNull()) - tt.insert(tr("Date"), _date.toString(Qt::SystemLocaleShortDate)); + tt.insert(tr("Date"), +#ifdef ENABLE_TIMEZONES + _date.toTimeZone(_timeZone) +#else // ENABLE_TIMEZONES + _date +#endif // ENABLE_TIMEZONES + .toString(Qt::SystemLocaleShortDate)); if (!_links.isEmpty()) { QString links; for (int i = 0; i < _links.size(); i++) { diff --git a/src/GUI/waypointitem.cpp b/src/GUI/waypointitem.cpp index 3e93de96..94b0a5ed 100644 --- a/src/GUI/waypointitem.cpp +++ b/src/GUI/waypointitem.cpp @@ -13,6 +13,13 @@ #define FS(size) \ ((int)((qreal)size * 1.41)) + +Units WaypointItem::_units = Metric; +CoordinatesFormat WaypointItem::_format = DecimalDegrees; +#ifdef ENABLE_TIMEZONES +QTimeZone WaypointItem::_timeZone = QTimeZone::utc(); +#endif // ENABLE_TIMEZONES + QString WaypointItem::info() const { ToolTip tt; @@ -30,7 +37,12 @@ QString WaypointItem::info() const } if (_waypoint.timestamp().isValid()) tt.insert(qApp->translate("WaypointItem", "Date"), - _waypoint.timestamp().toString(Qt::SystemLocaleShortDate)); +#ifdef ENABLE_TIMEZONES + _waypoint.timestamp().toTimeZone(_timeZone) +#else // ENABLE_TIMEZONES + _waypoint.timestamp() +#endif // ENABLE_TIMEZONES + .toString(Qt::SystemLocaleShortDate)); if (!_waypoint.description().isEmpty()) tt.insert(qApp->translate("WaypointItem", "Description"), _waypoint.description()); @@ -78,9 +90,6 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map, _font.setPixelSize(FS(_size)); _font.setFamily(FONT_FAMILY); - _units = Metric; - _format = DecimalDegrees; - updateCache(); setPos(map->ll2xy(waypoint.coordinates())); @@ -151,12 +160,6 @@ void WaypointItem::setColor(const QColor &color) update(); } -void WaypointItem::setToolTipFormat(Units units, CoordinatesFormat format) -{ - _units = units; - _format = format; -} - void WaypointItem::showLabel(bool show) { if (_showLabel == show) diff --git a/src/GUI/waypointitem.h b/src/GUI/waypointitem.h index 9646553b..9de99a26 100644 --- a/src/GUI/waypointitem.h +++ b/src/GUI/waypointitem.h @@ -1,9 +1,13 @@ #ifndef WAYPOINTITEM_H #define WAYPOINTITEM_H +#include "common/config.h" #include #include #include +#ifdef ENABLE_TIMEZONES +#include +#endif // ENABLE_TIMEZONES #include "data/waypoint.h" #include "map/map.h" #include "units.h" @@ -23,7 +27,6 @@ public: void setColor(const QColor &color); void showLabel(bool show); void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));} - void setToolTipFormat(Units units, CoordinatesFormat format); QPainterPath shape() const {return _shape;} QRectF boundingRect() const {return _shape.boundingRect();} @@ -32,6 +35,13 @@ public: QString info() const; + static void setUnits(Units units) {_units = units;} + static void setCoordinatesFormat(CoordinatesFormat format) + {_format = format;} +#ifdef ENABLE_TIMEZONES + static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;} +#endif // ENABLE_TIMEZONES + protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); @@ -48,8 +58,11 @@ private: QFont _font; QRect _labelBB; - Units _units; - CoordinatesFormat _format; + static Units _units; + static CoordinatesFormat _format; +#ifdef ENABLE_TIMEZONES + static QTimeZone _timeZone; +#endif // ENABLE_TIMEZONES }; #endif // WAYPOINTITEM_H diff --git a/src/common/config.h b/src/common/config.h index f206c782..50c4f8b1 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -18,4 +18,8 @@ #define ENABLE_GEOJSON #endif // QT >= 5.0 +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) +#define ENABLE_TIMEZONES +#endif // QT >= 5.2 + #endif /* CONFIG_H */ diff --git a/src/main.cpp b/src/main.cpp index 14878bac..f237199d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,7 @@ #include "common/config.h" +#ifdef ENABLE_TIMEZONES +#include "GUI/timezoneinfo.h" +#endif // ENABLE_TIMEZONES #include "GUI/app.h" int main(int argc, char *argv[]) @@ -7,6 +10,9 @@ int main(int argc, char *argv[]) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif // ENABLE_HIDPI +#ifdef ENABLE_TIMEZONES + qRegisterMetaTypeStreamOperators("TimeZoneInfo"); +#endif // ENABLE_TIMEZONES App app(argc, argv); return app.run();