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.