From a41e0bd0529a327f2d25b6e011bacf8fefae8962 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Mon, 8 Feb 2021 10:48:35 -0700 Subject: [PATCH 1/2] cleanup filterwidgets. clang-tidy modernize-use-override clang-tidy modernize-use-equals-default clang-tidy readability-inconsistent-declaration-parameter-name manual fix for clang-tidy readability-named-parameter rule of zero implemented for FilterWidget class by using QSharedPointers. rule of five implemented for FilterOption class by deleting copy and move special member functions. use c++17 std::clamp. --- gui/filterwidgets.cc | 117 ++++++++++++++++++++++--------------------- gui/filterwidgets.h | 89 +++++++++++++++++++------------- 2 files changed, 114 insertions(+), 92 deletions(-) diff --git a/gui/filterwidgets.cc b/gui/filterwidgets.cc index adf57dfe3..5e52cd1a0 100644 --- a/gui/filterwidgets.cc +++ b/gui/filterwidgets.cc @@ -22,6 +22,11 @@ #include "filterwidgets.h" +#include // for QChar +#include // for QCheckBox +#include // for QLabel +#include // for QRadioButton + //------------------------------------------------------------------------ TrackWidget::TrackWidget(QWidget* parent, TrackFilterData& tfd): FilterWidget(parent), tfd(tfd) @@ -63,35 +68,35 @@ TrackWidget::TrackWidget(QWidget* parent, TrackFilterData& tfd): FilterWidget(pa ui.stopEdit->setDisplayFormat("dd MMM yyyy hh:mm:ss AP"); // Collect the data fields. - fopts << new BoolFilterOption(tfd.title, ui.titleCheck); - fopts << new BoolFilterOption(tfd.move, ui.moveCheck); - fopts << new BoolFilterOption(tfd.TZ, ui.TZCheck); - fopts << new BoolFilterOption(tfd.start, ui.startCheck); - fopts << new BoolFilterOption(tfd.stop, ui.stopCheck); - fopts << new BoolFilterOption(tfd.pack, ui.packCheck); - fopts << new BoolFilterOption(tfd.merge, ui.mergeCheck); - fopts << new BoolFilterOption(tfd.splitByDate, ui.splitDateCheck); - fopts << new BoolFilterOption(tfd.splitByTime, ui.splitTimeCheck); - fopts << new BoolFilterOption(tfd.splitByDistance, ui.splitDistanceCheck); - fopts << new BoolFilterOption(tfd.GPSFixes, ui.GPSFixesCheck); - fopts << new BoolFilterOption(tfd.course, ui.courseCheck); - fopts << new BoolFilterOption(tfd.speed, ui.speedCheck); - - fopts << new IntSpinFilterOption(tfd.weeks, ui.weeksSpin, ui.weeksSpin->minimum(), ui.weeksSpin->maximum()); - fopts << new IntSpinFilterOption(tfd.days, ui.daysSpin, ui.daysSpin->minimum(), ui.daysSpin->maximum()); - fopts << new IntSpinFilterOption(tfd.hours, ui.hoursSpin, ui.hoursSpin->minimum(), ui.hoursSpin->maximum()); - fopts << new IntSpinFilterOption(tfd.mins, ui.minsSpin, ui.minsSpin->minimum(), ui.minsSpin->maximum()); - fopts << new IntSpinFilterOption(tfd.secs, ui.secsSpin, ui.secsSpin->minimum(), ui.secsSpin->maximum()); - fopts << new IntSpinFilterOption(tfd.splitTime, ui.splitTimeSpin, 0, 1000); - fopts << new IntSpinFilterOption(tfd.splitDist, ui.splitDistSpin, 0, 5280); - - fopts << new DateTimeFilterOption(tfd.startTime, ui.startEdit); - fopts << new DateTimeFilterOption(tfd.stopTime, ui.stopEdit); - - fopts << new StringFilterOption(tfd.titleString, ui.titleText); - fopts << new ComboFilterOption(tfd.GPSFixesVal, ui.GPSFixesCombo); - fopts << new ComboFilterOption(tfd.splitTimeUnit, ui.splitTimeCombo); - fopts << new ComboFilterOption(tfd.splitDistUnit, ui.splitDistCombo); + fopts << QSharedPointer(new BoolFilterOption(tfd.title, ui.titleCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.move, ui.moveCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.TZ, ui.TZCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.start, ui.startCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.stop, ui.stopCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.pack, ui.packCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.merge, ui.mergeCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.splitByDate, ui.splitDateCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.splitByTime, ui.splitTimeCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.splitByDistance, ui.splitDistanceCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.GPSFixes, ui.GPSFixesCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.course, ui.courseCheck)); + fopts << QSharedPointer(new BoolFilterOption(tfd.speed, ui.speedCheck)); + + fopts << QSharedPointer(new IntSpinFilterOption(tfd.weeks, ui.weeksSpin, ui.weeksSpin->minimum(), ui.weeksSpin->maximum())); + fopts << QSharedPointer(new IntSpinFilterOption(tfd.days, ui.daysSpin, ui.daysSpin->minimum(), ui.daysSpin->maximum())); + fopts << QSharedPointer(new IntSpinFilterOption(tfd.hours, ui.hoursSpin, ui.hoursSpin->minimum(), ui.hoursSpin->maximum())); + fopts << QSharedPointer(new IntSpinFilterOption(tfd.mins, ui.minsSpin, ui.minsSpin->minimum(), ui.minsSpin->maximum())); + fopts << QSharedPointer(new IntSpinFilterOption(tfd.secs, ui.secsSpin, ui.secsSpin->minimum(), ui.secsSpin->maximum())); + fopts << QSharedPointer(new IntSpinFilterOption(tfd.splitTime, ui.splitTimeSpin, 0, 1000)); + fopts << QSharedPointer(new IntSpinFilterOption(tfd.splitDist, ui.splitDistSpin, 0, 5280)); + + fopts << QSharedPointer(new DateTimeFilterOption(tfd.startTime, ui.startEdit)); + fopts << QSharedPointer(new DateTimeFilterOption(tfd.stopTime, ui.stopEdit)); + + fopts << QSharedPointer(new StringFilterOption(tfd.titleString, ui.titleText)); + fopts << QSharedPointer(new ComboFilterOption(tfd.GPSFixesVal, ui.GPSFixesCombo)); + fopts << QSharedPointer(new ComboFilterOption(tfd.splitTimeUnit, ui.splitTimeCombo)); + fopts << QSharedPointer(new ComboFilterOption(tfd.splitDistUnit, ui.splitDistCombo)); setWidgetValues(); checkChecks(); } @@ -171,17 +176,17 @@ WayPtsWidget::WayPtsWidget(QWidget* parent, WayPtsFilterData& wfd): FilterWidget QList() << ui.latLabel << ui.latText << ui.longLabel << ui.longText << ui.radiusUnitCombo << ui.radiusText); - fopts << new BoolFilterOption(wfd.duplicates, ui.duplicatesCheck); - fopts << new BoolFilterOption(wfd.shortNames, ui.shortNamesCheck); - fopts << new BoolFilterOption(wfd.locations, ui.locationsCheck); - fopts << new BoolFilterOption(wfd.position, ui.positionCheck); - fopts << new BoolFilterOption(wfd.radius, ui.radiusCheck); - fopts << new DoubleFilterOption(wfd.positionVal, ui.positionText, 0.0, 1.0E308); - fopts << new DoubleFilterOption(wfd.radiusVal, ui.radiusText, 0.0, 1.0E308); - fopts << new DoubleFilterOption(wfd.longVal, ui.longText, -180, 180, 7, 'f'); - fopts << new DoubleFilterOption(wfd.latVal, ui.latText, -90, 90, 7, 'f'); - fopts << new ComboFilterOption(wfd.positionUnit, ui.positionUnitCombo); - fopts << new ComboFilterOption(wfd.radiusUnit, ui.radiusUnitCombo); + fopts << QSharedPointer(new BoolFilterOption(wfd.duplicates, ui.duplicatesCheck)); + fopts << QSharedPointer(new BoolFilterOption(wfd.shortNames, ui.shortNamesCheck)); + fopts << QSharedPointer(new BoolFilterOption(wfd.locations, ui.locationsCheck)); + fopts << QSharedPointer(new BoolFilterOption(wfd.position, ui.positionCheck)); + fopts << QSharedPointer(new BoolFilterOption(wfd.radius, ui.radiusCheck)); + fopts << QSharedPointer(new DoubleFilterOption(wfd.positionVal, ui.positionText, 0.0, 1.0E308)); + fopts << QSharedPointer(new DoubleFilterOption(wfd.radiusVal, ui.radiusText, 0.0, 1.0E308)); + fopts << QSharedPointer(new DoubleFilterOption(wfd.longVal, ui.longText, -180, 180, 7, 'f')); + fopts << QSharedPointer(new DoubleFilterOption(wfd.latVal, ui.latText, -90, 90, 7, 'f')); + fopts << QSharedPointer(new ComboFilterOption(wfd.positionUnit, ui.positionUnitCombo)); + fopts << QSharedPointer(new ComboFilterOption(wfd.radiusUnit, ui.radiusUnitCombo)); connect(ui.shortNamesCheck, &QAbstractButton::clicked, this, &WayPtsWidget::shortNamesCkX); connect(ui.locationsCheck, &QAbstractButton::clicked, this, &WayPtsWidget::locationsCkX); @@ -211,9 +216,9 @@ RtTrkWidget::RtTrkWidget(QWidget* parent, RtTrkFilterData& rfd): FilterWidget(pa addCheckEnabler(ui.simplifyCheck, QList() << ui.limitToLabel << ui.limitToSpin << ui.pointLabel); - fopts << new BoolFilterOption(rfd.simplify_, ui.simplifyCheck); - fopts << new BoolFilterOption(rfd.reverse_, ui.reverseCheck); - fopts << new IntSpinFilterOption(rfd.limitTo_, ui.limitToSpin, 1, 5000); + fopts << QSharedPointer(new BoolFilterOption(rfd.simplify_, ui.simplifyCheck)); + fopts << QSharedPointer(new BoolFilterOption(rfd.reverse_, ui.reverseCheck)); + fopts << QSharedPointer(new IntSpinFilterOption(rfd.limitTo_, ui.limitToSpin, 1, 5000)); setWidgetValues(); checkChecks(); } @@ -235,19 +240,19 @@ MiscFltWidget::MiscFltWidget(QWidget* parent, MiscFltFilterData& mfd): FilterWid addCheckEnabler(ui.sortRteCheck, ui.sortRteBy); addCheckEnabler(ui.sortTrkCheck, ui.sortTrkBy); - fopts << new BoolFilterOption(mfd.transform_, ui.transformCheck); - fopts << new BoolFilterOption(mfd.swap_, ui.swapCheck); - fopts << new BoolFilterOption(mfd.del_, ui.deleteCheck); - fopts << new BoolFilterOption(mfd.nukeTracks_, ui.nukeTracks); - fopts << new BoolFilterOption(mfd.nukeRoutes_, ui.nukeRoutes); - fopts << new BoolFilterOption(mfd.nukeWaypoints_, ui.nukeWaypoints); - fopts << new BoolFilterOption(mfd.sortWpt_, ui.sortWptCheck); - fopts << new BoolFilterOption(mfd.sortRte_, ui.sortRteCheck); - fopts << new BoolFilterOption(mfd.sortTrk_, ui.sortTrkCheck); - fopts << new ComboFilterOption(mfd.transformVal_, ui.transformCombo); - fopts << new ComboFilterOption(mfd.sortWptBy_, ui.sortWptBy); - fopts << new ComboFilterOption(mfd.sortRteBy_, ui.sortRteBy); - fopts << new ComboFilterOption(mfd.sortTrkBy_, ui.sortTrkBy); + fopts << QSharedPointer(new BoolFilterOption(mfd.transform_, ui.transformCheck)); + fopts << QSharedPointer(new BoolFilterOption(mfd.swap_, ui.swapCheck)); + fopts << QSharedPointer(new BoolFilterOption(mfd.del_, ui.deleteCheck)); + fopts << QSharedPointer(new BoolFilterOption(mfd.nukeTracks_, ui.nukeTracks)); + fopts << QSharedPointer(new BoolFilterOption(mfd.nukeRoutes_, ui.nukeRoutes)); + fopts << QSharedPointer(new BoolFilterOption(mfd.nukeWaypoints_, ui.nukeWaypoints)); + fopts << QSharedPointer(new BoolFilterOption(mfd.sortWpt_, ui.sortWptCheck)); + fopts << QSharedPointer(new BoolFilterOption(mfd.sortRte_, ui.sortRteCheck)); + fopts << QSharedPointer(new BoolFilterOption(mfd.sortTrk_, ui.sortTrkCheck)); + fopts << QSharedPointer(new ComboFilterOption(mfd.transformVal_, ui.transformCombo)); + fopts << QSharedPointer(new ComboFilterOption(mfd.sortWptBy_, ui.sortWptBy)); + fopts << QSharedPointer(new ComboFilterOption(mfd.sortRteBy_, ui.sortRteBy)); + fopts << QSharedPointer(new ComboFilterOption(mfd.sortTrkBy_, ui.sortTrkBy)); setWidgetValues(); checkChecks(); diff --git a/gui/filterwidgets.h b/gui/filterwidgets.h index 088ca0ae8..54cf0f4d8 100644 --- a/gui/filterwidgets.h +++ b/gui/filterwidgets.h @@ -23,15 +23,28 @@ #ifndef FILTERWIDGETS_H #define FILTERWIDGETS_H +#include // for QDateTime +#include // for QList +#include // for QObject +#include // for QSharedPointer +#include // for QString +#include // for QDoubleValidator +#include // for QAbstractButton +#include // for QComboBox +#include // for QDateTimeEdit +#include // for QLineEdit +#include // for QSpinBox +#include // for QWidget + +#include // for clamp + +#include "filterdata.h" // for MiscFltFilterData, RtTrkFilterData, TrackFilterData, WayPtsFilterData +#include "ui_miscfltui.h" // for Ui_MiscFltWidget +#include "ui_rttrkui.h" // for Ui_RtTrkWidget +#include "ui_trackui.h" // for Ui_TrackWidget +#include "ui_wayptsui.h" // for Ui_WayPtsWidget -#include "ui_trackui.h" -#include "ui_wayptsui.h" -#include "ui_rttrkui.h" -#include "ui_miscfltui.h" -#include "filterdata.h" -class CheckEnabler; -class FilterOption; //------------------------------------------------------------------------ class CheckEnabler: public QObject { @@ -93,8 +106,13 @@ public slots: class FilterOption { public: - FilterOption() {} - virtual ~FilterOption() {} + FilterOption() = default; + FilterOption(const FilterOption&) = delete; + FilterOption& operator=(const FilterOption&) = delete; + FilterOption(FilterOption&&) = delete; + FilterOption& operator=(FilterOption&&) = delete; + virtual ~FilterOption() = default; + virtual void setWidgetValue() = 0; virtual void getWidgetValue() = 0; }; @@ -106,11 +124,12 @@ class BoolFilterOption: public FilterOption BoolFilterOption(bool& b, QAbstractButton* ck): b(b), checkBox(ck) { } - void setWidgetValue() + + void setWidgetValue() override { checkBox->setChecked(b); } - void getWidgetValue() + void getWidgetValue() override { b = checkBox->isChecked(); } @@ -128,11 +147,12 @@ class IntSpinFilterOption: public FilterOption { sb->setRange(bottom, top); } - void setWidgetValue() + + void setWidgetValue() override { spinBox->setValue(val); } - void getWidgetValue() + void getWidgetValue() override { val = spinBox->value(); } @@ -149,11 +169,12 @@ class StringFilterOption: public FilterOption StringFilterOption(QString& val, QLineEdit* le): val(val), lineEdit(le) { } - void setWidgetValue() + + void setWidgetValue() override { lineEdit->setText(val); } - void getWidgetValue() + void getWidgetValue() override { val = lineEdit->text(); } @@ -177,21 +198,21 @@ class DoubleFilterOption: public FilterOption { le->setValidator(new QDoubleValidator(minVal, maxVal, decimals, le)); } - void setWidgetValue() + + void setWidgetValue() override { lineEdit->setText(QString("%1").arg(val, 0, format, decimals)); } - void getWidgetValue() + void getWidgetValue() override { - val = lineEdit->text().toDouble(); - val = qMin(val, maxVal); - val = qMax(val, minVal); + val = std::clamp(lineEdit->text().toDouble(), minVal, maxVal); } private: double& val; QLineEdit* lineEdit; - double minVal, maxVal; + double minVal; + double maxVal; int decimals; char format; }; @@ -203,11 +224,12 @@ class DateTimeFilterOption: public FilterOption DateTimeFilterOption(QDateTime& val, QDateTimeEdit* w): val(val), w(w) { } - void setWidgetValue() + + void setWidgetValue() override { w->setDateTime(val); } - void getWidgetValue() + void getWidgetValue() override { val = w->dateTime(); } @@ -224,11 +246,12 @@ class ComboFilterOption: public FilterOption ComboFilterOption(int& val, QComboBox* w): val(val), w(w) { } - void setWidgetValue() + + void setWidgetValue() override { w->setCurrentIndex(val); } - void getWidgetValue() + void getWidgetValue() override { val = w->currentIndex(); } @@ -244,12 +267,6 @@ class FilterWidget: public QWidget { public: FilterWidget(QWidget* parent) : QWidget(parent) {} - ~FilterWidget() - { - for (int i=0; i fopts; - QList enbls; + QList> fopts; + QList enbls; }; //------------------------------------------------------------------------ @@ -291,7 +308,7 @@ class TrackWidget: public FilterWidget public: TrackWidget(QWidget* parent, TrackFilterData& tf); - virtual void checkChecks() + void checkChecks() override { otherCheckX(); FilterWidget::checkChecks(); @@ -331,7 +348,7 @@ class RtTrkWidget: public FilterWidget { Q_OBJECT public: - RtTrkWidget(QWidget* parent, RtTrkFilterData& wf); + RtTrkWidget(QWidget* parent, RtTrkFilterData& rfd); private: Ui_RtTrkWidget ui; @@ -342,7 +359,7 @@ class MiscFltWidget: public FilterWidget { Q_OBJECT public: - MiscFltWidget(QWidget*, MiscFltFilterData&); + MiscFltWidget(QWidget* parent, MiscFltFilterData& mfd); private: Ui_MiscFltWidget ui; From 13ca7f0908aa958fc274733bde4119a283277e85 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Mon, 8 Feb 2021 13:17:10 -0700 Subject: [PATCH 2/2] declare TrackWidget final to quiet clang-analyzer-optin.cplusplus.VirtualCall We don't intend to inhereit from this class anyway. --- gui/filterwidgets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gui/filterwidgets.h b/gui/filterwidgets.h index 54cf0f4d8..207f28843 100644 --- a/gui/filterwidgets.h +++ b/gui/filterwidgets.h @@ -302,7 +302,9 @@ class FilterWidget: public QWidget //------------------------------------------------------------------------ -class TrackWidget: public FilterWidget +// quiet clang-analyzer-optin.cplusplus.VirtualCall warnings by declaring +// TrackWidget final. We don't intend to inhereit from this class anyway. +class TrackWidget final: public FilterWidget { Q_OBJECT public: