summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/divelistview.cpp11
-rw-r--r--qt-ui/divelistview.h3
2 files changed, 9 insertions, 5 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index e64ad217b..a78e48777 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -22,7 +22,7 @@
#include <QFileDialog>
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false),
- currentHeaderClicked(-1), searchBox(new QLineEdit(this))
+ sortColumn(0), currentOrder(Qt::DescendingOrder), searchBox(new QLineEdit(this))
{
setUniformRowHeights(true);
setItemDelegateForColumn(DiveTripModel::RATING, new StarWidgetsDelegate());
@@ -107,6 +107,7 @@ bool DiveListView::eventFilter(QObject* , QEvent* event)
// index. TRIP_ROLE vs DIVE_ROLE?
void DiveListView::headerClicked(int i)
{
+ sortColumn = i;
QItemSelection oldSelection = selectionModel()->selection();
QList<struct dive*> currentSelectedDives;
DiveTripModel::Layout newLayout;
@@ -127,11 +128,13 @@ void DiveListView::headerClicked(int i)
/* No layout change? Just re-sort, and scroll to first selection, making sure all selections are expanded */
if (currentLayout == newLayout) {
- sortByColumn(i);
+ currentOrder = (currentOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder;
+ sortByColumn(i, currentOrder);
} else {
// clear the model, repopulate with new indexes.
reload(newLayout, false);
- sortByColumn(i, Qt::DescendingOrder);
+ currentOrder = Qt::DescendingOrder;
+ sortByColumn(i, currentOrder);
}
// repopulate the selections.
@@ -163,7 +166,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
if(!forceSort)
return;
- sortByColumn(0, Qt::DescendingOrder);
+ sortByColumn(sortColumn, currentOrder);
if (amount_selected && selected_dive >= 0) {
selectDive(current_dive, true);
} else {
diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h
index c1222abdf..384ece9a3 100644
--- a/qt-ui/divelistview.h
+++ b/qt-ui/divelistview.h
@@ -48,7 +48,8 @@ signals:
private:
bool mouseClickSelection;
- int currentHeaderClicked;
+ int sortColumn;
+ Qt::SortOrder currentOrder;
DiveTripModel::Layout currentLayout;
QLineEdit *searchBox;
QModelIndex contextMenuIndex;