Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup filterwidgets. #687

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 62 additions & 56 deletions gui/filterwidgets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include "filterwidgets.h"
#include <limits>

#include <QtCore/QChar> // for QChar
#include <QtWidgets/QCheckBox> // for QCheckBox
#include <QtWidgets/QLabel> // for QLabel
#include <QtWidgets/QRadioButton> // for QRadioButton


//------------------------------------------------------------------------
TrackWidget::TrackWidget(QWidget* parent, TrackFilterData& tfd): FilterWidget(parent), tfd(tfd)
Expand Down Expand Up @@ -64,35 +69,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<BoolFilterOption>(new BoolFilterOption(tfd.title, ui.titleCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.move, ui.moveCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.TZ, ui.TZCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.start, ui.startCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.stop, ui.stopCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.pack, ui.packCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.merge, ui.mergeCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.splitByDate, ui.splitDateCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.splitByTime, ui.splitTimeCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.splitByDistance, ui.splitDistanceCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.GPSFixes, ui.GPSFixesCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.course, ui.courseCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(tfd.speed, ui.speedCheck));

fopts << QSharedPointer<IntSpinFilterOption>(new IntSpinFilterOption(tfd.weeks, ui.weeksSpin, ui.weeksSpin->minimum(), ui.weeksSpin->maximum()));
fopts << QSharedPointer<IntSpinFilterOption>(new IntSpinFilterOption(tfd.days, ui.daysSpin, ui.daysSpin->minimum(), ui.daysSpin->maximum()));
fopts << QSharedPointer<IntSpinFilterOption>(new IntSpinFilterOption(tfd.hours, ui.hoursSpin, ui.hoursSpin->minimum(), ui.hoursSpin->maximum()));
fopts << QSharedPointer<IntSpinFilterOption>(new IntSpinFilterOption(tfd.mins, ui.minsSpin, ui.minsSpin->minimum(), ui.minsSpin->maximum()));
fopts << QSharedPointer<IntSpinFilterOption>(new IntSpinFilterOption(tfd.secs, ui.secsSpin, ui.secsSpin->minimum(), ui.secsSpin->maximum()));
fopts << QSharedPointer<IntSpinFilterOption>(new IntSpinFilterOption(tfd.splitTime, ui.splitTimeSpin, 0, 1000));
fopts << QSharedPointer<IntSpinFilterOption>(new IntSpinFilterOption(tfd.splitDist, ui.splitDistSpin, 0, 5280));

fopts << QSharedPointer<DateTimeFilterOption>(new DateTimeFilterOption(tfd.startTime, ui.startEdit));
fopts << QSharedPointer<DateTimeFilterOption>(new DateTimeFilterOption(tfd.stopTime, ui.stopEdit));

fopts << QSharedPointer<StringFilterOption>(new StringFilterOption(tfd.titleString, ui.titleText));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(tfd.GPSFixesVal, ui.GPSFixesCombo));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(tfd.splitTimeUnit, ui.splitTimeCombo));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(tfd.splitDistUnit, ui.splitDistCombo));
setWidgetValues();
checkChecks();
}
Expand Down Expand Up @@ -172,17 +177,17 @@ WayPtsWidget::WayPtsWidget(QWidget* parent, WayPtsFilterData& wfd): FilterWidget
QList<QWidget*>() << 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<BoolFilterOption>(new BoolFilterOption(wfd.duplicates, ui.duplicatesCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(wfd.shortNames, ui.shortNamesCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(wfd.locations, ui.locationsCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(wfd.position, ui.positionCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(wfd.radius, ui.radiusCheck));
fopts << QSharedPointer<DoubleFilterOption>(new DoubleFilterOption(wfd.positionVal, ui.positionText, 0.0, 1.0E308));
fopts << QSharedPointer<DoubleFilterOption>(new DoubleFilterOption(wfd.radiusVal, ui.radiusText, 0.0, 1.0E308));
fopts << QSharedPointer<DoubleFilterOption>(new DoubleFilterOption(wfd.longVal, ui.longText, -180, 180, 7, 'f'));
fopts << QSharedPointer<DoubleFilterOption>(new DoubleFilterOption(wfd.latVal, ui.latText, -90, 90, 7, 'f'));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(wfd.positionUnit, ui.positionUnitCombo));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(wfd.radiusUnit, ui.radiusUnitCombo));

connect(ui.shortNamesCheck, &QAbstractButton::clicked, this, &WayPtsWidget::shortNamesCkX);
connect(ui.locationsCheck, &QAbstractButton::clicked, this, &WayPtsWidget::locationsCkX);
Expand Down Expand Up @@ -212,9 +217,10 @@ RtTrkWidget::RtTrkWidget(QWidget* parent, RtTrkFilterData& rfd): FilterWidget(pa
addCheckEnabler(ui.simplifyCheck,
QList<QWidget*>() << 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, std::numeric_limits<int>::max());
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(rfd.simplify_, ui.simplifyCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(rfd.reverse_, ui.reverseCheck));
fopts << QSharedPointer<IntSpinFilterOption>(new IntSpinFilterOption(rfd.limitTo_, ui.limitToSpin, 1, std::numeric_limits<int>::max()));

setWidgetValues();
checkChecks();
}
Expand All @@ -236,19 +242,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<BoolFilterOption>(new BoolFilterOption(mfd.transform_, ui.transformCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(mfd.swap_, ui.swapCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(mfd.del_, ui.deleteCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(mfd.nukeTracks_, ui.nukeTracks));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(mfd.nukeRoutes_, ui.nukeRoutes));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(mfd.nukeWaypoints_, ui.nukeWaypoints));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(mfd.sortWpt_, ui.sortWptCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(mfd.sortRte_, ui.sortRteCheck));
fopts << QSharedPointer<BoolFilterOption>(new BoolFilterOption(mfd.sortTrk_, ui.sortTrkCheck));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(mfd.transformVal_, ui.transformCombo));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(mfd.sortWptBy_, ui.sortWptBy));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(mfd.sortRteBy_, ui.sortRteBy));
fopts << QSharedPointer<ComboFilterOption>(new ComboFilterOption(mfd.sortTrkBy_, ui.sortTrkBy));

setWidgetValues();
checkChecks();
Expand Down
93 changes: 56 additions & 37 deletions gui/filterwidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,28 @@
#ifndef FILTERWIDGETS_H
#define FILTERWIDGETS_H

#include <QtCore/QDateTime> // for QDateTime
#include <QtCore/QList> // for QList
#include <QtCore/QObject> // for QObject
#include <QtCore/QSharedPointer> // for QSharedPointer
#include <QtCore/QString> // for QString
#include <QtGui/QDoubleValidator> // for QDoubleValidator
#include <QtWidgets/QAbstractButton> // for QAbstractButton
#include <QtWidgets/QComboBox> // for QComboBox
#include <QtWidgets/QDateTimeEdit> // for QDateTimeEdit
#include <QtWidgets/QLineEdit> // for QLineEdit
#include <QtWidgets/QSpinBox> // for QSpinBox
#include <QtWidgets/QWidget> // for QWidget

#include <algorithm> // 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
{
Expand Down Expand Up @@ -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;
};
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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;
};
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -244,12 +267,6 @@ class FilterWidget: public QWidget
{
public:
FilterWidget(QWidget* parent) : QWidget(parent) {}
~FilterWidget()
{
for (int i=0; i<fopts.size(); i++) {
delete fopts[i];
}
}

void getWidgetValues()
{
Expand Down Expand Up @@ -279,19 +296,21 @@ class FilterWidget: public QWidget
}

protected:
QList <FilterOption*> fopts;
QList <CheckEnabler*> enbls;
QList<QSharedPointer<FilterOption>> fopts;
QList<CheckEnabler*> enbls;
};

//------------------------------------------------------------------------

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:
TrackWidget(QWidget* parent, TrackFilterData& tf);

virtual void checkChecks()
void checkChecks() override
{
otherCheckX();
FilterWidget::checkChecks();
Expand Down Expand Up @@ -331,7 +350,7 @@ class RtTrkWidget: public FilterWidget
{
Q_OBJECT
public:
RtTrkWidget(QWidget* parent, RtTrkFilterData& wf);
RtTrkWidget(QWidget* parent, RtTrkFilterData& rfd);

private:
Ui_RtTrkWidget ui;
Expand All @@ -342,7 +361,7 @@ class MiscFltWidget: public FilterWidget
{
Q_OBJECT
public:
MiscFltWidget(QWidget*, MiscFltFilterData&);
MiscFltWidget(QWidget* parent, MiscFltFilterData& mfd);

private:
Ui_MiscFltWidget ui;
Expand Down