From 449782a8923d9d5f8f7e90d6e4ba84f47d2077ce Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Sun, 26 Aug 2018 23:46:46 +0300 Subject: 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 --- desktop-widgets/divelistview.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'desktop-widgets') 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(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); } -- cgit v1.2.3-70-g09d2