mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Add select-all, deselect-all and invert-selection options to filters
To every filter list add a menu button that allows selection of all, selection of none or inversion of selection. Implements #435. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
668635e98e
commit
7451517e4a
4 changed files with 33 additions and 0 deletions
|
@ -51,6 +51,16 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="selectionButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="popupMode">
|
||||||
|
<enum>QToolButton::InstantPopup</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -513,6 +513,12 @@ FilterBase::FilterBase(FilterModelBase *model_, QWidget *parent)
|
||||||
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);
|
||||||
|
|
||||||
|
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)
|
void FilterBase::showEvent(QShowEvent *event)
|
||||||
|
|
|
@ -100,6 +100,21 @@ void FilterModelBase::clearFilter()
|
||||||
emit dataChanged(createIndex(0,0), createIndex(rowCount()-1, 0));
|
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)
|
SuitsFilterModel::SuitsFilterModel(QObject *parent) : FilterModelBase(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ class FilterModelBase : public QStringListModel {
|
||||||
public:
|
public:
|
||||||
virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0;
|
virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0;
|
||||||
void clearFilter();
|
void clearFilter();
|
||||||
|
void selectAll();
|
||||||
|
void invertSelection();
|
||||||
std::vector<char> checkState;
|
std::vector<char> checkState;
|
||||||
bool anyChecked;
|
bool anyChecked;
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue