From aff7b1c13f58d7478e4ed12227b6150101422ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 22 May 2017 23:41:01 +0200 Subject: [PATCH] Allow only odd window sizes for moving average filter --- gpxsee.pro | 6 ++++-- src/oddspinbox.cpp | 22 ++++++++++++++++++++++ src/oddspinbox.h | 15 +++++++++++++++ src/optionsdialog.cpp | 11 ++++++----- src/optionsdialog.h | 11 ++++++----- 5 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 src/oddspinbox.cpp create mode 100644 src/oddspinbox.h diff --git a/gpxsee.pro b/gpxsee.pro index ea3081b3..e094c499 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -93,7 +93,8 @@ HEADERS += src/config.h \ src/ozf.h \ src/datum.h \ src/maplist.h \ - src/albersequal.h + src/albersequal.h \ + src/oddspinbox.h SOURCES += src/main.cpp \ src/gui.cpp \ src/poi.cpp \ @@ -160,7 +161,8 @@ SOURCES += src/main.cpp \ src/ozf.cpp \ src/datum.cpp \ src/maplist.cpp \ - src/albersequal.cpp + src/albersequal.cpp \ + src/oddspinbox.cpp RESOURCES += gpxsee.qrc TRANSLATIONS = lang/gpxsee_cs.ts \ lang/gpxsee_sv.ts \ diff --git a/src/oddspinbox.cpp b/src/oddspinbox.cpp new file mode 100644 index 00000000..0365e47a --- /dev/null +++ b/src/oddspinbox.cpp @@ -0,0 +1,22 @@ +#include "oddspinbox.h" + +#include + +OddSpinBox::OddSpinBox(QWidget *parent) : QSpinBox(parent) +{ + setSingleStep(2); + setMinimum(1); +} + +QValidator::State OddSpinBox::validate(QString &text, int &pos) const +{ + Q_UNUSED(pos); + bool ok; + int val; + + val = text.toInt(&ok); + if (!ok || val < 0 || val % 2 == 0) + return QValidator::Invalid; + + return QValidator::Acceptable; +} diff --git a/src/oddspinbox.h b/src/oddspinbox.h new file mode 100644 index 00000000..fcf97c5b --- /dev/null +++ b/src/oddspinbox.h @@ -0,0 +1,15 @@ +#ifndef ODDSPINBOX_H +#define ODDSPINBOX_H + +#include + +class OddSpinBox : public QSpinBox +{ +public: + OddSpinBox(QWidget *parent = 0); + +protected: + QValidator::State validate(QString &text, int &pos) const; +}; + +#endif // ODDSPINBOX_H diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index 63238671..7bc5f694 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -14,6 +14,7 @@ #include "icons.h" #include "colorbox.h" #include "stylecombobox.h" +#include "oddspinbox.h" #include "optionsdialog.h" #define MENU_MARGIN 20 @@ -122,19 +123,19 @@ QWidget *OptionsDialog::createDataPage() { QString filterToolTip = tr("Moving average window size"); - _elevationFilter = new QSpinBox(); + _elevationFilter = new OddSpinBox(); _elevationFilter->setValue(_options->elevationFilter); _elevationFilter->setToolTip(filterToolTip); - _speedFilter = new QSpinBox(); + _speedFilter = new OddSpinBox(); _speedFilter->setValue(_options->speedFilter); _speedFilter->setToolTip(filterToolTip); - _heartRateFilter = new QSpinBox(); + _heartRateFilter = new OddSpinBox(); _heartRateFilter->setValue(_options->heartRateFilter); _heartRateFilter->setToolTip(filterToolTip); - _cadenceFilter = new QSpinBox(); + _cadenceFilter = new OddSpinBox(); _cadenceFilter->setValue(_options->cadenceFilter); _cadenceFilter->setToolTip(filterToolTip); - _powerFilter = new QSpinBox(); + _powerFilter = new OddSpinBox(); _powerFilter->setValue(_options->powerFilter); _powerFilter->setToolTip(filterToolTip); diff --git a/src/optionsdialog.h b/src/optionsdialog.h index ae65d73c..133225c4 100644 --- a/src/optionsdialog.h +++ b/src/optionsdialog.h @@ -7,6 +7,7 @@ class ColorBox; class StyleComboBox; +class OddSpinBox; class QSpinBox; class QDoubleSpinBox; class QComboBox; @@ -78,11 +79,11 @@ private: QSpinBox *_graphWidth; QCheckBox *_graphAA; // Data - QSpinBox *_elevationFilter; - QSpinBox *_speedFilter; - QSpinBox *_heartRateFilter; - QSpinBox *_cadenceFilter; - QSpinBox *_powerFilter; + OddSpinBox *_elevationFilter; + OddSpinBox *_speedFilter; + OddSpinBox *_heartRateFilter; + OddSpinBox *_cadenceFilter; + OddSpinBox *_powerFilter; QCheckBox *_outlierEliminate; QDoubleSpinBox *_pauseSpeed; QSpinBox *_pauseInterval;