diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-08-26 23:46:46 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-08-26 23:08:24 -0700 |
commit | 449782a8923d9d5f8f7e90d6e4ba84f47d2077ce (patch) | |
tree | 0fbd5ae0cb626964aea93cc22493e520dea0bc6a /desktop-widgets | |
parent | 5204af58da3ad56ec05a31e561ee43bb1443e866 (diff) | |
download | subsurface-449782a8923d9d5f8f7e90d6e4ba84f47d2077ce.tar.gz |
divelistview: always show at least one column
Currently it is possible to hide all columns by unchecking them
in the context menu that appears by right clicking the header
of the divelist. But once all are hidden the header disappears.
This can cause a situation where the user cannot show any
columns and the only fix for that is to edit the application
configuration.
To avoid this sutuation prevent the last column from being hidden.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index a6268413f..a6f1531af 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -501,13 +501,30 @@ void DiveListView::toggleColumnVisibilityByIndex() QAction *action = qobject_cast<QAction *>(sender()); if (!action) return; + const int idx = action->property("index").toInt(); + + // Count the number of visible columns. + int totalVisible = 0, lastVisibleIdx = -1; + for (int i = 0; i < model()->columnCount(); i++) { + if (isColumnHidden(i)) + continue; + totalVisible++; + lastVisibleIdx = i; + } + // If there is only one visible column and we are performing an action on it, + // don't hide the column and revert the action back to checked == true. + // This keeps one column visible at all times. + if (totalVisible == 1 && idx == lastVisibleIdx) { + action->setChecked(true); + return; + } QSettings s; s.beginGroup("DiveListColumnState"); s.setValue(action->property("settingName").toString(), action->isChecked()); s.endGroup(); s.sync(); - setColumnHidden(action->property("index").toInt(), !action->isChecked()); + setColumnHidden(idx, !action->isChecked()); setColumnWidth(lastVisibleColumn(), 10); } |