mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 22:03:23 +00:00
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>
This commit is contained in:
parent
603e43f46e
commit
1a4e7ad0dd
2 changed files with 32 additions and 98 deletions
|
@ -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.setupUi(this);
|
||||||
ui.label->setText(tr("Tags: "));
|
|
||||||
#if QT_VERSION >= 0x050200
|
#if QT_VERSION >= 0x050200
|
||||||
ui.filterInternalList->setClearButtonEnabled(true);
|
ui.filterInternalList->setClearButtonEnabled(true);
|
||||||
#endif
|
#endif
|
||||||
QSortFilterProxyModel *filter = new QSortFilterProxyModel();
|
QSortFilterProxyModel *filter = new QSortFilterProxyModel();
|
||||||
filter->setSourceModel(TagFilterModel::instance());
|
filter->setSourceModel(model);
|
||||||
filter->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
filter->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString)));
|
connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString)));
|
||||||
ui.filterList->setModel(filter);
|
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);
|
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);
|
QWidget::hideEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
BuddyFilter::BuddyFilter(QWidget *parent) : QWidget(parent)
|
TagFilter::TagFilter(QWidget *parent) : FilterBase(TagFilterModel::instance(), parent)
|
||||||
|
{
|
||||||
|
ui.label->setText(tr("Tags: "));
|
||||||
|
}
|
||||||
|
|
||||||
|
BuddyFilter::BuddyFilter(QWidget *parent) : FilterBase(BuddyFilterModel::instance(), parent)
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
|
||||||
ui.label->setText(tr("Person: "));
|
ui.label->setText(tr("Person: "));
|
||||||
ui.label->setToolTip(tr("Searches for buddies and divemasters"));
|
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)
|
LocationFilter::LocationFilter(QWidget *parent) : FilterBase(LocationFilterModel::instance(), parent)
|
||||||
{
|
{
|
||||||
MultiFilterSortModel::instance()->addFilterModel(BuddyFilterModel::instance());
|
|
||||||
QWidget::showEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuddyFilter::hideEvent(QHideEvent *event)
|
|
||||||
{
|
|
||||||
MultiFilterSortModel::instance()->removeFilterModel(BuddyFilterModel::instance());
|
|
||||||
QWidget::hideEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationFilter::LocationFilter(QWidget *parent) : QWidget(parent)
|
|
||||||
{
|
|
||||||
ui.setupUi(this);
|
|
||||||
ui.label->setText(tr("Location: "));
|
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: "));
|
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)
|
MultiFilter::MultiFilter(QWidget *parent) : QWidget(parent)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
class MinMaxAvgWidgetPrivate;
|
class MinMaxAvgWidgetPrivate;
|
||||||
class QAbstractButton;
|
class QAbstractButton;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class FilterModelBase;
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
@ -165,49 +166,39 @@ public:
|
||||||
Ui::FilterWidget2 ui;
|
Ui::FilterWidget2 ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TagFilter : public QWidget {
|
class FilterBase : public QWidget {
|
||||||
Q_OBJECT
|
protected:
|
||||||
public:
|
FilterBase(FilterModelBase *model, QWidget *parent = 0);
|
||||||
TagFilter(QWidget *parent = 0);
|
FilterModelBase *model;
|
||||||
|
Ui::FilterWidget ui;
|
||||||
virtual void showEvent(QShowEvent *);
|
virtual void showEvent(QShowEvent *);
|
||||||
virtual void hideEvent(QHideEvent *);
|
virtual void hideEvent(QHideEvent *);
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::FilterWidget ui;
|
|
||||||
friend class MultiFilter;
|
friend class MultiFilter;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BuddyFilter : public QWidget {
|
class TagFilter : public FilterBase {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
TagFilter(QWidget *parent = 0);
|
||||||
|
friend class MultiFilter;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BuddyFilter : public FilterBase {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
BuddyFilter(QWidget *parent = 0);
|
BuddyFilter(QWidget *parent = 0);
|
||||||
virtual void showEvent(QShowEvent *);
|
|
||||||
virtual void hideEvent(QHideEvent *);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::FilterWidget ui;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SuitFilter : public QWidget {
|
class SuitFilter : public FilterBase {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SuitFilter(QWidget *parent = 0);
|
SuitFilter(QWidget *parent = 0);
|
||||||
virtual void showEvent(QShowEvent *);
|
|
||||||
virtual void hideEvent(QHideEvent *);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::FilterWidget ui;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class LocationFilter : public QWidget {
|
class LocationFilter : public FilterBase {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LocationFilter(QWidget *parent = 0);
|
LocationFilter(QWidget *parent = 0);
|
||||||
virtual void showEvent(QShowEvent *);
|
|
||||||
virtual void hideEvent(QHideEvent *);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::FilterWidget ui;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextHyperlinkEventFilter : public QObject {
|
class TextHyperlinkEventFilter : public QObject {
|
||||||
|
|
Loading…
Add table
Reference in a new issue