From 50f483663cda72494fadffcb181a7bf54c6cf1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 20 Sep 2020 22:18:35 +0200 Subject: [PATCH] Added configurable segments usage --- src/GUI/gui.cpp | 6 ++++++ src/GUI/optionsdialog.cpp | 9 +++++++++ src/GUI/optionsdialog.h | 2 ++ src/GUI/settings.h | 2 ++ src/data/track.cpp | 12 ++++++++++-- src/data/track.h | 8 ++++---- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index c0c5a16f..29b5e47e 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -970,6 +970,7 @@ void GUI::openOptions() SET_TRACK_OPTION(dataUseDEM, useDEM); SET_TRACK_OPTION(showSecondaryElevation, showSecondaryElevation); SET_TRACK_OPTION(showSecondarySpeed, showSecondarySpeed); + SET_TRACK_OPTION(useSegments, useSegments); SET_ROUTE_OPTION(dataUseDEM, useDEM); SET_ROUTE_OPTION(showSecondaryElevation, showSecondaryElevation); @@ -1884,6 +1885,8 @@ void GUI::writeSettings() settings.setValue(TIME_ZONE_SETTING, QVariant::fromValue( _options.timeZone)); #endif // ENABLE_TIMEZONES + if (_options.useSegments != USE_SEGMENTS_DEFAULT) + settings.setValue(USE_SEGMENTS_SETTING, _options.useSegments); if (_options.poiRadius != POI_RADIUS_DEFAULT) settings.setValue(POI_RADIUS_SETTING, _options.poiRadius); if (_options.useOpenGL != USE_OPENGL_DEFAULT) @@ -2159,6 +2162,8 @@ void GUI::readSettings() #ifdef ENABLE_TIMEZONES _options.timeZone = settings.value(TIME_ZONE_SETTING).value(); #endif // ENABLE_TIMEZONES + _options.useSegments = settings.value(USE_SEGMENTS_SETTING, + USE_SEGMENTS_DEFAULT).toBool(); _options.automaticPause = settings.value(AUTOMATIC_PAUSE_SETTING, AUTOMATIC_PAUSE_DEFAULT).toBool(); _options.pauseInterval = settings.value(PAUSE_INTERVAL_SETTING, @@ -2250,6 +2255,7 @@ void GUI::readSettings() Track::useDEM(_options.dataUseDEM); Track::showSecondaryElevation(_options.showSecondaryElevation); Track::showSecondarySpeed(_options.showSecondarySpeed); + Track::useSegments(_options.useSegments); Route::useDEM(_options.dataUseDEM); Route::showSecondaryElevation(_options.showSecondaryElevation); Waypoint::useDEM(_options.dataUseDEM); diff --git a/src/GUI/optionsdialog.cpp b/src/GUI/optionsdialog.cpp index 54f363fe..69ace537 100644 --- a/src/GUI/optionsdialog.cpp +++ b/src/GUI/optionsdialog.cpp @@ -439,6 +439,9 @@ QWidget *OptionsDialog::createDataPage() customZoneLayout->addWidget(_timeZone); #endif // ENABLE_TIMEZONES + _useSegments = new QCheckBox(tr("Use segments")); + _useSegments->setChecked(_options->useSegments); + QWidget *sourceTab = new QWidget(); QVBoxLayout *sourceTabLayout = new QVBoxLayout(); @@ -477,6 +480,7 @@ QWidget *OptionsDialog::createDataPage() #ifdef ENABLE_TIMEZONES formLayout->addRow(tr("Time zone:"), zoneOptions); #endif // ENABLE_TIMEZONES + formLayout->addRow(_useSegments); sourceTabLayout->addLayout(formLayout); #else // Q_OS_MAC @@ -485,6 +489,7 @@ QWidget *OptionsDialog::createDataPage() #ifdef ENABLE_TIMEZONES QFormLayout *timeZoneLayout = new QFormLayout(); #endif // ENABLE_TIMEZONES + QFormLayout *segmentsLayout = new QFormLayout(); speedLayout->addWidget(_computedSpeed); speedLayout->addWidget(_reportedSpeed); @@ -510,11 +515,14 @@ QWidget *OptionsDialog::createDataPage() timeZoneBox->setLayout(timeZoneLayout); #endif // ENABLE_TIMEZONES + segmentsLayout->addWidget(_useSegments); + sourceTabLayout->addWidget(speedBox); sourceTabLayout->addWidget(elevationBox); #ifdef ENABLE_TIMEZONES sourceTabLayout->addWidget(timeZoneBox); #endif // ENABLE_TIMEZONES + sourceTabLayout->addLayout(segmentsLayout); #endif // Q_OS_MAC sourceTabLayout->addStretch(); sourceTab->setLayout(sourceTabLayout); @@ -780,6 +788,7 @@ void OptionsDialog::accept() _options->timeZone.setCustomZone(QTimeZone(_timeZone->currentText() .toLatin1())); #endif // ENABLE_TIMEZONES + _options->useSegments = _useSegments->isChecked(); qreal poiRadius = (_options->units == Imperial) ? _poiRadius->value() * MIINM : (_options->units == Nautical) diff --git a/src/GUI/optionsdialog.h b/src/GUI/optionsdialog.h index cfcd8319..a2284d31 100644 --- a/src/GUI/optionsdialog.h +++ b/src/GUI/optionsdialog.h @@ -63,6 +63,7 @@ struct Options { #ifdef ENABLE_TIMEZONES TimeZoneInfo timeZone; #endif // ENABLE_TIMEZONES + bool useSegments; // POI int poiRadius; // System @@ -157,6 +158,7 @@ private: QRadioButton *_customZone; QComboBox *_timeZone; #endif // ENABLE_TIMEZONES + QCheckBox *_useSegments; // POI QDoubleSpinBox *_poiRadius; // System diff --git a/src/GUI/settings.h b/src/GUI/settings.h index 6211c5c1..9c38ac22 100644 --- a/src/GUI/settings.h +++ b/src/GUI/settings.h @@ -150,6 +150,8 @@ #define SHOW_SECONDARY_SPEED_SETTING "showSecondarySpeed" #define SHOW_SECONDARY_SPEED_DEFAULT false #define TIME_ZONE_SETTING "timeZone" +#define USE_SEGMENTS_SETTING "useSegments" +#define USE_SEGMENTS_DEFAULT true #define POI_RADIUS_SETTING "poiRadius" #define POI_RADIUS_DEFAULT (int)(IMPERIAL_UNITS() ? MIINM : KMINM) #define USE_OPENGL_SETTING "useOpenGL" diff --git a/src/data/track.cpp b/src/data/track.cpp index 9d38022d..b93e1cb5 100644 --- a/src/data/track.cpp +++ b/src/data/track.cpp @@ -17,7 +17,7 @@ bool Track::_useReportedSpeed = false; bool Track::_useDEM = false; bool Track::_show2ndElevation = false; bool Track::_show2ndSpeed = false; - +bool Track::_useSegments = true; static qreal avg(const QVector &v) { @@ -88,10 +88,18 @@ static GraphSegment filter(const GraphSegment &g, int window) } -Track::Track(const TrackData &data) : _data(data), _pause(0) +Track::Track(const TrackData &data) : _pause(0) { qreal ds, dt; + if (_useSegments) + _data = data; + else { + _data.append(SegmentData()); + for (int i = 0; i < data.size(); i++) + _data[0].append(data.at(i)); + } + for (int i = 0; i < _data.size(); i++) { const SegmentData &sd = _data.at(i); _segments.append(Segment()); diff --git a/src/data/track.h b/src/data/track.h index 03c926e6..e022e057 100644 --- a/src/data/track.h +++ b/src/data/track.h @@ -49,10 +49,9 @@ public: {_outlierEliminate = eliminate;} static void useReportedSpeed(bool use) {_useReportedSpeed = use;} static void useDEM(bool use) {_useDEM = use;} - static void showSecondaryElevation(bool show) - {_show2ndElevation = show;} - static void showSecondarySpeed(bool show) - {_show2ndSpeed = show;} + static void showSecondaryElevation(bool show) {_show2ndElevation = show;} + static void showSecondarySpeed(bool show) {_show2ndSpeed = show;} + static void useSegments(bool use) {_useSegments = use;} private: struct Segment { @@ -87,6 +86,7 @@ private: static bool _useDEM; static bool _show2ndElevation; static bool _show2ndSpeed; + static bool _useSegments; }; #endif // TRACK_H