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
This commit is contained in:
David Szabo 2018-07-25 14:39:42 +02:00 committed by tooomm
parent 451e1874a7
commit 283ce23111
2 changed files with 14 additions and 14 deletions

View file

@ -21,6 +21,8 @@
WndSets::WndSets(QWidget *parent) : QMainWindow(parent) WndSets::WndSets(QWidget *parent) : QMainWindow(parent)
{ {
setOrderIsSorted = false;
// left toolbar // left toolbar
setsEditToolBar = new QToolBar; setsEditToolBar = new QToolBar;
setsEditToolBar->setOrientation(Qt::Vertical); setsEditToolBar->setOrientation(Qt::Vertical);
@ -252,27 +254,24 @@ void WndSets::actDisableSortButtons(int index)
{ {
if (index != SORT_RESET) { if (index != SORT_RESET) {
view->setDragEnabled(false); view->setDragEnabled(false);
actToggleButtons(QItemSelection(), QItemSelection()); setOrderIsSorted = true;
disconnect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
this, SLOT(actToggleButtons(const QItemSelection &, const QItemSelection &)));
} else { } else {
actToggleButtons(view->selectionModel()->selection(), QItemSelection()); setOrderIsSorted = false;
connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, view->setDragEnabled(true);
SLOT(actToggleButtons(const QItemSelection &, const QItemSelection &))); }
if (!view->selectionModel()->selection().empty()) { if (!view->selectionModel()->selection().empty()) {
view->scrollTo(view->selectionModel()->selectedRows().first()); view->scrollTo(view->selectionModel()->selectedRows().first());
} }
view->setDragEnabled(true); actToggleButtons(view->selectionModel()->selection(), QItemSelection());
}
} }
void WndSets::actToggleButtons(const QItemSelection &selected, const QItemSelection &) void WndSets::actToggleButtons(const QItemSelection &selected, const QItemSelection &)
{ {
bool disabled = selected.empty(); bool emptySelection = selected.empty();
aTop->setDisabled(disabled); aTop->setDisabled(emptySelection || setOrderIsSorted);
aUp->setDisabled(disabled); aUp->setDisabled(emptySelection || setOrderIsSorted);
aDown->setDisabled(disabled); aDown->setDisabled(emptySelection || setOrderIsSorted);
aBottom->setDisabled(disabled); aBottom->setDisabled(emptySelection || setOrderIsSorted);
int rows = view->selectionModel()->selectedRows().size(); int rows = view->selectionModel()->selectedRows().size();
rebuildMainLayout((rows > 1) ? SOME_SETS_SELECTED : NO_SETS_SELECTED); rebuildMainLayout((rows > 1) ? SOME_SETS_SELECTED : NO_SETS_SELECTED);

View file

@ -36,6 +36,7 @@ private:
int sortIndex; int sortIndex;
Qt::SortOrder sortOrder; Qt::SortOrder sortOrder;
void rebuildMainLayout(int actionToTake); void rebuildMainLayout(int actionToTake);
bool setOrderIsSorted;
enum enum
{ {
NO_SETS_SELECTED, NO_SETS_SELECTED,