From 283ce23111c64232ddbd983691eb93e72d627943 Mon Sep 17 00:00:00 2001 From: David Szabo Date: Wed, 25 Jul 2018 14:39:42 +0200 Subject: [PATCH] Manage sets window: "Enable all/selected" button toggling never disabled (#3337) ## Related Ticket(s) - Fixes #3314 ## Short roundup of the initial problem When the view was sorted in the manage sets window, the "Enable/Disable All" buttons never toggled to "Enable/Disable selected" buttons, even when more sets were selected. ## What will change with this Pull Request? - Selected sets can be enabled/disabled in sorted view as well --- cockatrice/src/window_sets.cpp | 27 +++++++++++++-------------- cockatrice/src/window_sets.h | 1 + 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cockatrice/src/window_sets.cpp b/cockatrice/src/window_sets.cpp index b230a025..374b79b0 100644 --- a/cockatrice/src/window_sets.cpp +++ b/cockatrice/src/window_sets.cpp @@ -21,6 +21,8 @@ WndSets::WndSets(QWidget *parent) : QMainWindow(parent) { + setOrderIsSorted = false; + // left toolbar setsEditToolBar = new QToolBar; setsEditToolBar->setOrientation(Qt::Vertical); @@ -252,27 +254,24 @@ void WndSets::actDisableSortButtons(int index) { if (index != SORT_RESET) { view->setDragEnabled(false); - actToggleButtons(QItemSelection(), QItemSelection()); - disconnect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), - this, SLOT(actToggleButtons(const QItemSelection &, const QItemSelection &))); + setOrderIsSorted = true; } else { - actToggleButtons(view->selectionModel()->selection(), QItemSelection()); - connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, - SLOT(actToggleButtons(const QItemSelection &, const QItemSelection &))); - if (!view->selectionModel()->selection().empty()) { - view->scrollTo(view->selectionModel()->selectedRows().first()); - } + setOrderIsSorted = false; view->setDragEnabled(true); } + if (!view->selectionModel()->selection().empty()) { + view->scrollTo(view->selectionModel()->selectedRows().first()); + } + actToggleButtons(view->selectionModel()->selection(), QItemSelection()); } void WndSets::actToggleButtons(const QItemSelection &selected, const QItemSelection &) { - bool disabled = selected.empty(); - aTop->setDisabled(disabled); - aUp->setDisabled(disabled); - aDown->setDisabled(disabled); - aBottom->setDisabled(disabled); + bool emptySelection = selected.empty(); + aTop->setDisabled(emptySelection || setOrderIsSorted); + aUp->setDisabled(emptySelection || setOrderIsSorted); + aDown->setDisabled(emptySelection || setOrderIsSorted); + aBottom->setDisabled(emptySelection || setOrderIsSorted); int rows = view->selectionModel()->selectedRows().size(); rebuildMainLayout((rows > 1) ? SOME_SETS_SELECTED : NO_SETS_SELECTED); diff --git a/cockatrice/src/window_sets.h b/cockatrice/src/window_sets.h index 99a6f1a7..86632d7d 100644 --- a/cockatrice/src/window_sets.h +++ b/cockatrice/src/window_sets.h @@ -36,6 +36,7 @@ private: int sortIndex; Qt::SortOrder sortOrder; void rebuildMainLayout(int actionToTake); + bool setOrderIsSorted; enum { NO_SETS_SELECTED,