aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-04 20:24:16 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-05 07:55:53 -0800
commitda3ea59a25890b5992413e80c4260e4350129061 (patch)
treebdf64f4a2629e3c1b379ce8e725c581b2d49fc46
parent64a1a50e10c4ec8432de9d7cc08921b1b5b490a5 (diff)
downloadsubsurface-da3ea59a25890b5992413e80c4260e4350129061.tar.gz
Dive list: let sort arrows reflect sort order for NR and DATE
The old code always sorted by "ascending" by default. But because users typically want their new dives top, "ascending" was defined for NR and DATE, such that it is actually descending. Turn these around and intitialize these two fields as default-descending. This is possible using the Qt::InitialSortOrderRole role in DiveTripModel::headerData(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/mainwindow.cpp2
-rw-r--r--qt-models/divetripmodel.cpp11
2 files changed, 10 insertions, 3 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 33d954f8d..f5e63851c 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -705,7 +705,7 @@ void MainWindow::cleanUpEmpty()
mainTab->updateDiveInfo(true);
graphics->setEmptyState();
diveList->reload();
- diveList->setSortOrder(DiveTripModel::NR, Qt::AscendingOrder);
+ diveList->setSortOrder(DiveTripModel::NR, Qt::DescendingOrder);
MapWidget::instance()->reload();
if (!existing_filename)
setTitle();
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 7c86d6b73..3655ecab2 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -350,6 +350,9 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int
return dive_table_alignment(section);
case Qt::FontRole:
return defaultModelFont();
+ case Qt::InitialSortOrderRole:
+ // By default, sort NR and DATE descending, everything else ascending.
+ return section == NR || section == DATE ? Qt::DescendingOrder : Qt::AscendingOrder;
case Qt::DisplayRole:
switch (section) {
case NR:
@@ -1084,7 +1087,9 @@ bool DiveTripModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const
if (currentLayout != LIST) {
// In tree mode we don't support any sorting!
// Simply keep the original position.
- return i1.row() < i2.row();
+ // Note that the model is filled in reverse order, therefore
+ // ascending means sorting in descending order. TODO: fix.
+ return i1.row() > i2.row();
}
// We assume that i1.column() == i2.column().
@@ -1100,7 +1105,9 @@ bool DiveTripModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const
case NR:
case DATE:
default:
- return row1 < row2;
+ // Note that the model is filled in reverse order, therefore
+ // ascending means sorting in descending order. TODO: fix.
+ return row1 > row2;
case RATING:
return lessThanHelper(d1->rating - d2->rating, row_diff);
case DEPTH: