aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-27 17:30:22 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-28 15:10:57 +0000
commitf634554d30d867e54886ea4391e1a5f340deab36 (patch)
tree30a2a5e4e5b3cc24da1ca4d38092941104528508 /desktop-widgets
parent7f2026ded8645910ad1ad9c61cb1eea20ea276b6 (diff)
downloadsubsurface-f634554d30d867e54886ea4391e1a5f340deab36.tar.gz
Dive list: switch to a default sort order on column-header click
On desktop, clicking on a column header sorts the dive-list. This has the interesting property that every click reverses the sort order (unless changing from list to tree-mode). The much more common idiom seems to be to define a default sort order for each column and switch to that when changing sort-column. Switch order after clicking the same column again. Implement this more common behavior. For now, sort # and date in descending, all other columns in ascending order. While doing this, use the proper enum (NR) for setting the default sort-column instead of its integer representation (0). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/divelistview.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index d2685caa2..9d77fb7b7 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -26,7 +26,7 @@
#include "core/metrics.h"
#include "core/subsurface-qt/DiveListNotifier.h"
-DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), sortColumn(0),
+DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), sortColumn(DiveTripModel::NR),
currentOrder(Qt::DescendingOrder), dontEmitDiveChangedSignal(false), selectionSaved(false),
initialColumnWidths(DiveTripModel::COLUMNS, 50) // Set up with default length 50
{
@@ -472,7 +472,14 @@ void DiveListView::headerClicked(int i)
unselectDives();
/* No layout change? Just re-sort, and scroll to first selection, making sure all selections are expanded */
if (currentLayout == newLayout) {
- currentOrder = (currentOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder;
+ // If this is the same column as before, change sort order. Otherwise, choose a default
+ // sort order (descending for NR and DATE, ascending elsewise).
+ if (sortColumn == i)
+ currentOrder = (currentOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder;
+ else if (i == DiveTripModel::NR || i == DiveTripModel::DATE)
+ currentOrder = Qt::DescendingOrder;
+ else
+ currentOrder = Qt::AscendingOrder;
sortByColumn(i, currentOrder);
} else {
// clear the model, repopulate with new indexes.