diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2017-12-23 14:17:23 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-24 08:24:11 -0800 |
commit | 1a4e7ad0dd29b9eeac2016933cb86bff260dadbb (patch) | |
tree | 92730f71f4d41207bb86fd81509fc7778f96108f /desktop-widgets/simplewidgets.cpp | |
parent | 603e43f46ece939e732df14c501844e7bd983211 (diff) | |
download | subsurface-1a4e7ad0dd29b9eeac2016933cb86bff260dadbb.tar.gz |
Factor out *Filter code into FilterBase base class
The TagFilter, BuddyFilter, SuitFilter and LocationFilter classes
all did essentially the same thing. Therefore, factor out common
code / objects into a base class FilterBase.
The new base class stores a pointer to the filter model. It was
felt that this is simpler than introducing virtual methods.
The only thing the *Filter classes now do is setting a label and
in one case a tooltip. Thus, in principle, they could be removed
completely, but let's keep them for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/simplewidgets.cpp')
-rw-r--r-- | desktop-widgets/simplewidgets.cpp | 87 |
1 files changed, 15 insertions, 72 deletions
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index fbc0a941d..addbda6af 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -500,109 +500,52 @@ void DiveComponentSelection::buttonClicked(QAbstractButton *button) } } -TagFilter::TagFilter(QWidget *parent) : QWidget(parent) +FilterBase::FilterBase(FilterModelBase *model_, QWidget *parent) + : QWidget(parent) + , model(model_) { ui.setupUi(this); - ui.label->setText(tr("Tags: ")); #if QT_VERSION >= 0x050200 ui.filterInternalList->setClearButtonEnabled(true); #endif QSortFilterProxyModel *filter = new QSortFilterProxyModel(); - filter->setSourceModel(TagFilterModel::instance()); + filter->setSourceModel(model); filter->setFilterCaseSensitivity(Qt::CaseInsensitive); connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString))); ui.filterList->setModel(filter); } -void TagFilter::showEvent(QShowEvent *event) +void FilterBase::showEvent(QShowEvent *event) { - MultiFilterSortModel::instance()->addFilterModel(TagFilterModel::instance()); + MultiFilterSortModel::instance()->addFilterModel(model); QWidget::showEvent(event); } -void TagFilter::hideEvent(QHideEvent *event) +void FilterBase::hideEvent(QHideEvent *event) { - MultiFilterSortModel::instance()->removeFilterModel(TagFilterModel::instance()); + MultiFilterSortModel::instance()->removeFilterModel(model); QWidget::hideEvent(event); } -BuddyFilter::BuddyFilter(QWidget *parent) : QWidget(parent) -{ - ui.setupUi(this); - ui.label->setText(tr("Person: ")); - ui.label->setToolTip(tr("Searches for buddies and divemasters")); -#if QT_VERSION >= 0x050200 - ui.filterInternalList->setClearButtonEnabled(true); -#endif - QSortFilterProxyModel *filter = new QSortFilterProxyModel(); - filter->setSourceModel(BuddyFilterModel::instance()); - filter->setFilterCaseSensitivity(Qt::CaseInsensitive); - connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString))); - ui.filterList->setModel(filter); -} - -void BuddyFilter::showEvent(QShowEvent *event) +TagFilter::TagFilter(QWidget *parent) : FilterBase(TagFilterModel::instance(), parent) { - MultiFilterSortModel::instance()->addFilterModel(BuddyFilterModel::instance()); - QWidget::showEvent(event); + ui.label->setText(tr("Tags: ")); } -void BuddyFilter::hideEvent(QHideEvent *event) +BuddyFilter::BuddyFilter(QWidget *parent) : FilterBase(BuddyFilterModel::instance(), parent) { - MultiFilterSortModel::instance()->removeFilterModel(BuddyFilterModel::instance()); - QWidget::hideEvent(event); + ui.label->setText(tr("Person: ")); + ui.label->setToolTip(tr("Searches for buddies and divemasters")); } -LocationFilter::LocationFilter(QWidget *parent) : QWidget(parent) +LocationFilter::LocationFilter(QWidget *parent) : FilterBase(LocationFilterModel::instance(), parent) { - ui.setupUi(this); ui.label->setText(tr("Location: ")); -#if QT_VERSION >= 0x050200 - ui.filterInternalList->setClearButtonEnabled(true); -#endif - QSortFilterProxyModel *filter = new QSortFilterProxyModel(); - filter->setSourceModel(LocationFilterModel::instance()); - filter->setFilterCaseSensitivity(Qt::CaseInsensitive); - connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString))); - ui.filterList->setModel(filter); } -void LocationFilter::showEvent(QShowEvent *event) +SuitFilter::SuitFilter(QWidget *parent) : FilterBase(SuitsFilterModel::instance(), parent) { - MultiFilterSortModel::instance()->addFilterModel(LocationFilterModel::instance()); - QWidget::showEvent(event); -} - -void LocationFilter::hideEvent(QHideEvent *event) -{ - MultiFilterSortModel::instance()->removeFilterModel(LocationFilterModel::instance()); - QWidget::hideEvent(event); -} - -SuitFilter::SuitFilter(QWidget *parent) : QWidget(parent) -{ - ui.setupUi(this); ui.label->setText(tr("Suits: ")); -#if QT_VERSION >= 0x050200 - ui.filterInternalList->setClearButtonEnabled(true); -#endif - QSortFilterProxyModel *filter = new QSortFilterProxyModel(); - filter->setSourceModel(SuitsFilterModel::instance()); - filter->setFilterCaseSensitivity(Qt::CaseInsensitive); - connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString))); - ui.filterList->setModel(filter); -} - -void SuitFilter::showEvent(QShowEvent *event) -{ - MultiFilterSortModel::instance()->addFilterModel(SuitsFilterModel::instance()); - QWidget::showEvent(event); -} - -void SuitFilter::hideEvent(QHideEvent *event) -{ - MultiFilterSortModel::instance()->removeFilterModel(SuitsFilterModel::instance()); - QWidget::hideEvent(event); } MultiFilter::MultiFilter(QWidget *parent) : QWidget(parent) |