From 7c5c38b154baeeb05d2c70a3c248cda41349133a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 16 Nov 2014 14:04:06 -0200 Subject: [PATCH] Addded a min / max layout for the filter, and a filter count But the filter count seems to be broken for some reason and I really don't know why. It seems to work for tags, but not for everything else. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/filtermodels.cpp | 15 ++++- qt-ui/filtermodels.h | 5 +- qt-ui/filterwidget.ui | 127 ++++++++++++++++++++++++++++++++++++++++ qt-ui/simplewidgets.cpp | 54 ++++++++--------- qt-ui/simplewidgets.h | 12 +++- subsurface.pro | 3 +- 6 files changed, 181 insertions(+), 35 deletions(-) create mode 100644 qt-ui/filterwidget.ui diff --git a/qt-ui/filtermodels.cpp b/qt-ui/filtermodels.cpp index 5b2553d96..6751a8cfe 100644 --- a/qt-ui/filtermodels.cpp +++ b/qt-ui/filtermodels.cpp @@ -379,7 +379,7 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s if (!model->doFilter(d, index0, sourceModel())) shouldShow = false; } - // if it's a dive, mark it accordingly + filter_dive(d, shouldShow); return shouldShow; } @@ -390,7 +390,11 @@ void MultiFilterSortModel::myInvalidate() struct dive *d; DiveListView *dlv = MainWindow::instance()->dive_list(); + divesDisplayed = 0; + divesFilteredOut = 0; + invalidate(); + // first make sure the trips are no longer shown as selected // (but without updating the selection state of the dives... this just cleans // up an oddity in the filter handling) @@ -412,6 +416,15 @@ void MultiFilterSortModel::myInvalidate() } dlv->selectDives(curSelectedDives); } + + for_each_dive (i,d) { + if (d->hidden_by_filter) + divesFilteredOut++; + else + divesDisplayed++; + } + + emit filterFinished(); } void MultiFilterSortModel::addFilterModel(MultiFilterInterface *model) diff --git a/qt-ui/filtermodels.h b/qt-ui/filtermodels.h index b8439bb81..c70264b3d 100644 --- a/qt-ui/filtermodels.h +++ b/qt-ui/filtermodels.h @@ -93,11 +93,14 @@ public: virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; void addFilterModel(MultiFilterInterface *model); void removeFilterModel(MultiFilterInterface *model); + int divesFilteredOut; + int divesDisplayed; public slots: void myInvalidate(); void clearFilter(); - +signals: + void filterFinished(); private: MultiFilterSortModel(QObject *parent = 0); QList models; diff --git a/qt-ui/filterwidget.ui b/qt-ui/filterwidget.ui new file mode 100644 index 000000000..4b5f9d9d4 --- /dev/null +++ b/qt-ui/filterwidget.ui @@ -0,0 +1,127 @@ + + + FilterWidget2 + + + + 0 + 0 + 594 + 362 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + :/plus:/plus + + + true + + + + + + + ... + + + + :/average:/average + + + true + + + + + + + ... + + + + :/flag:/flag + + + true + + + + + + + + + QFrame::NoFrame + + + true + + + + + 0 + 0 + 594 + 332 + + + + + + + + + + + + diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index 192682774..1020e0ec3 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -17,6 +17,7 @@ #include "display.h" #include "mainwindow.h" #include "helpers.h" +#include "ui_filterwidget.h" class MinMaxAvgWidgetPrivate { public: @@ -560,55 +561,50 @@ void SuitFilter::hideEvent(QHideEvent *event) QWidget::hideEvent(event); } -MultiFilter::MultiFilter(QWidget *parent) : QScrollArea(parent) +MultiFilter::MultiFilter(QWidget *parent) : QWidget(parent) { + ui = new Ui::FilterWidget2(); + ui->setupUi(this); + QWidget *expandedWidget = new QWidget(); QHBoxLayout *l = new QHBoxLayout(); - TagFilter *tagFilter = new TagFilter(); int minimumHeight = tagFilter->ui.filterInternalList->height() + - tagFilter->ui.verticalLayout->spacing() * tagFilter->ui.verticalLayout->count(); + tagFilter->ui.verticalLayout->spacing() * tagFilter->ui.verticalLayout->count(); QListView *dummyList = new QListView(); QStringListModel *dummy = new QStringListModel(QStringList() << "Dummy Text"); dummyList->setModel(dummy); - // Buttons to Clear/Minimize/Close - QToolBar *tb = new QToolBar(); - QToolButton *clearBtn = new QToolButton(); - clearBtn->setToolTip(tr("Reset the filters")); - clearBtn->setIcon(QIcon(":/trash")); - clearBtn->setAutoRaise(true); - QToolButton *closeBtn = new QToolButton(); - closeBtn->setToolTip(tr("Close this window and reset the filters")); - closeBtn->setIcon(QIcon(":/close")); - closeBtn->setAutoRaise(true); - QToolButton *minimize = new QToolButton(); - minimize->setToolTip(tr("Minimize this window")); - minimize->setIcon(QIcon(":/arrow_up")); - minimize->setAutoRaise(true); + connect(ui->close, SIGNAL(clicked(bool)), this, SLOT(closeFilter())); + connect(ui->clear, SIGNAL(clicked(bool)), MultiFilterSortModel::instance(), SLOT(clearFilter())); + connect(ui->maximize, SIGNAL(clicked(bool)), this, SLOT(adjustHeight())); - tb->setOrientation(Qt::Vertical); - tb->addWidget(clearBtn); - tb->addWidget(minimize); - tb->addWidget(closeBtn); - - connect(closeBtn, SIGNAL(clicked(bool)), this, SLOT(closeFilter())); - connect(clearBtn, SIGNAL(clicked(bool)), MultiFilterSortModel::instance(), SLOT(clearFilter())); - l->addWidget(tb); l->addWidget(tagFilter); l->addWidget(new BuddyFilter()); l->addWidget(new LocationFilter()); l->addWidget(new SuitFilter()); l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); - expandedWidget->setLayout(l); - setWidget(expandedWidget); - expandedWidget->resize(expandedWidget->width(), minimumHeight + dummyList->sizeHintForRow(0) * 5 ); - setMinimumHeight(expandedWidget->height() + 5); + ui->scrollArea->setWidget(expandedWidget); + expandedWidget->resize(expandedWidget->width(), minimumHeight + dummyList->sizeHintForRow(0) * 5 ); + ui->scrollArea->setMinimumHeight(expandedWidget->height() + 5); + + connect(MultiFilterSortModel::instance(), SIGNAL(filterFinished()), this, SLOT(filterFinished())); +} + +void MultiFilter::filterFinished() +{ + ui->filterText->setText(tr("Dives filtered out: ") + QString::number(MultiFilterSortModel::instance()->divesFilteredOut) + + tr("Dives being shown: ") + QString::number(MultiFilterSortModel::instance()->divesDisplayed)); +} + +void MultiFilter::adjustHeight() +{ + ui->scrollArea->setVisible(!ui->scrollArea->isVisible()); } void MultiFilter::closeFilter() diff --git a/qt-ui/simplewidgets.h b/qt-ui/simplewidgets.h index 68735451e..00992d6ec 100644 --- a/qt-ui/simplewidgets.h +++ b/qt-ui/simplewidgets.h @@ -130,15 +130,21 @@ private: struct dive_components *what; }; -class MultiFilter : public QScrollArea { +namespace Ui{ + class FilterWidget2; +}; + +class MultiFilter : public QWidget { Q_OBJECT public slots: void closeFilter(); + void adjustHeight(); + void filterFinished(); + public: MultiFilter(QWidget *parent); - QWidget *expandedWidget; - QWidget *minimizedWidget; + Ui::FilterWidget2 *ui; }; class TagFilter : public QWidget { diff --git a/subsurface.pro b/subsurface.pro index 94245fcec..182490e5b 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -232,7 +232,8 @@ FORMS = \ qt-ui/divecomponentselection.ui \ qt-ui/configuredivecomputerdialog.ui \ qt-ui/listfilter.ui \ - qt-ui/diveshareexportdialog.ui + qt-ui/diveshareexportdialog.ui \ + qt-ui/filterwidget.ui # Nether usermanual or printing is supported on android right now android: FORMS -= qt-ui/printoptions.ui