From f080e2e25d05eb639cc4168d3c6905041f4dc564 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 30 Nov 2019 03:39:12 -0500 Subject: always enable clear filter button, made it so it also removes not flags removed "deselect filters" context menu, redundant disable not flag menu items without selection --- src/filterlist.cpp | 30 ++++++++++++++++++++++++------ src/filterlist.h | 3 ++- src/mainwindow.ui | 6 ------ 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/filterlist.cpp b/src/filterlist.cpp index 36cdacd0..66a9aed0 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -78,7 +78,7 @@ FilterList::FilterList(Ui::MainWindow* ui, CategoryFactory& factory) connect( ui->filtersClear, &QPushButton::clicked, - [&]{ clearSelection(); }); + [&]{ clear(); }); connect( ui->filtersAnd, &QCheckBox::toggled, @@ -241,20 +241,23 @@ void FilterList::onSelection() }); } - ui->filtersClear->setEnabled(!criteria.empty()); - emit criteriaChanged(criteria); } 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); }); + + QAction* set = menu.addAction(tr("Set inverted"), [&]{ toggleInverted(true); }); + QAction* unset = menu.addAction(tr("Unset inverted"), [&]{ toggleInverted(false); }); menu.addSeparator(); menu.addAction(tr("Edit Categories..."), [&]{ editCategories(); }); + if (ui->filters->selectedItems().empty()) { + set->setEnabled(false); + unset->setEnabled(false); + } + menu.exec(ui->filters->viewport()->mapToGlobal(pos)); } @@ -267,6 +270,21 @@ void FilterList::editCategories() } } +void FilterList::clear() +{ + const auto count = ui->filters->topLevelItemCount(); + for (int i=0; i(ui->filters->topLevelItem(i)); + if (!ci) { + continue; + } + + ci->setInverted(false); + } + + clearSelection(); +} + void FilterList::toggleInverted(bool b) { bool changed = false; diff --git a/src/filterlist.h b/src/filterlist.h index 1fd0942a..e98f81a9 100644 --- a/src/filterlist.h +++ b/src/filterlist.h @@ -32,8 +32,9 @@ private: void onSelection(); void onCriteriaChanged(); - void editCategories(); + void clear(); void toggleInverted(bool b); + void editCategories(); QTreeWidgetItem* addCriteriaItem( QTreeWidgetItem *root, const QString &name, int categoryID, diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 6c35d239..5206d797 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -114,9 +114,6 @@ - - false - 0 @@ -132,9 +129,6 @@ Clear - - true - -- cgit v1.3.1