From f463c5494362a0fa75c581e59192e2640ec10f7e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 30 Nov 2019 03:02:11 -0500 Subject: added context menu items so set/unset inverted flag --- src/filterlist.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/filterlist.cpp') diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 31783c88..8f297af6 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -50,6 +50,11 @@ public: return m_checkbox->isChecked(); } + void setInverted(bool b) + { + m_checkbox->setChecked(b); + } + private: const int IDRole = Qt::UserRole; const int TypeRole = Qt::UserRole + 1; @@ -223,7 +228,7 @@ void FilterList::onSelection() const QModelIndexList indices = ui->filters->selectionModel()->selectedRows(); std::vector criteria; - for (auto* item: ui->filters->selectedItems()) { + for (auto* item : ui->filters->selectedItems()) { const auto* ci = dynamic_cast(item); if (!ci) { continue; @@ -242,8 +247,11 @@ void FilterList::onSelection() void FilterList::onContextMenu(const QPoint &pos) { QMenu menu; + menu.addAction(tr("Deselect filters"), [&]{ clearSelection(); }); + menu.addAction(tr("Set inverted"), [&]{ toggleInverted(true); }); + menu.addAction(tr("Unset inverted"), [&]{ toggleInverted(false); }); + menu.addSeparator(); menu.addAction(tr("Edit Categories..."), [&]{ editCategories(); }); - menu.addAction(tr("Deselect filter"), [&]{ clearSelection(); }); menu.exec(ui->filters->viewport()->mapToGlobal(pos)); } @@ -257,6 +265,27 @@ void FilterList::editCategories() } } +void FilterList::toggleInverted(bool b) +{ + bool changed = false; + + for (auto* item : ui->filters->selectedItems()) { + auto* ci = dynamic_cast(item); + if (!ci) { + continue; + } + + if (ci->inverse() != b) { + ci->setInverted(b); + changed = true; + } + } + + if (changed) { + onSelection(); + } +} + void FilterList::onCriteriaChanged() { const auto mode = ui->filtersAnd->isChecked() ? -- cgit v1.3.1