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>
This commit is contained in:
Berthold Stoeger 2018-10-27 17:30:22 +02:00 committed by Dirk Hohndel
parent 7f2026ded8
commit f634554d30

View file

@ -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.