summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/listfilter.ui10
-rw-r--r--desktop-widgets/simplewidgets.cpp6
-rw-r--r--qt-models/filtermodels.cpp15
-rw-r--r--qt-models/filtermodels.h2
4 files changed, 33 insertions, 0 deletions
diff --git a/desktop-widgets/listfilter.ui b/desktop-widgets/listfilter.ui
index 48d813d21..dcdcd932e 100644
--- a/desktop-widgets/listfilter.ui
+++ b/desktop-widgets/listfilter.ui
@@ -51,6 +51,16 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QToolButton" name="selectionButton">
+ <property name="text">
+ <string>...</string>
+ </property>
+ <property name="popupMode">
+ <enum>QToolButton::InstantPopup</enum>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item>
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp
index addbda6af..86ea1fbc0 100644
--- a/desktop-widgets/simplewidgets.cpp
+++ b/desktop-widgets/simplewidgets.cpp
@@ -513,6 +513,12 @@ FilterBase::FilterBase(FilterModelBase *model_, QWidget *parent)
filter->setFilterCaseSensitivity(Qt::CaseInsensitive);
connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString)));
ui.filterList->setModel(filter);
+
+ QMenu *menu = new QMenu(this);
+ menu->addAction(tr("Select All"), model, &FilterModelBase::selectAll);
+ menu->addAction(tr("Unselect All"), model, &FilterModelBase::clearFilter);
+ menu->addAction(tr("Invert Selection"), model, &FilterModelBase::invertSelection);
+ ui.selectionButton->setMenu(menu);
}
void FilterBase::showEvent(QShowEvent *event)
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 26759571a..0dece6f8f 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -100,6 +100,21 @@ void FilterModelBase::clearFilter()
emit dataChanged(createIndex(0,0), createIndex(rowCount()-1, 0));
}
+void FilterModelBase::selectAll()
+{
+ std::fill(checkState.begin(), checkState.end(), true);
+ anyChecked = true;
+ emit dataChanged(createIndex(0,0), createIndex(rowCount()-1, 0));
+}
+
+void FilterModelBase::invertSelection()
+{
+ for (char &b: checkState)
+ b = !b;
+ anyChecked = std::any_of(checkState.begin(), checkState.end(), [](char b){return !!b;});
+ emit dataChanged(createIndex(0,0), createIndex(rowCount()-1, 0));
+}
+
SuitsFilterModel::SuitsFilterModel(QObject *parent) : FilterModelBase(parent)
{
}
diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h
index d0c3a215a..9db5e5a97 100644
--- a/qt-models/filtermodels.h
+++ b/qt-models/filtermodels.h
@@ -11,6 +11,8 @@ class FilterModelBase : public QStringListModel {
public:
virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0;
void clearFilter();
+ void selectAll();
+ void invertSelection();
std::vector<char> checkState;
bool anyChecked;
protected: