summaryrefslogtreecommitdiffstats
path: root/qt-gui.cpp
diff options
context:
space:
mode:
authorGravatar Grace Karanja <gracie.karanja89@gmail.com>2015-07-22 19:09:49 +0300
committerGravatar Grace Karanja <gracie.karanja89@gmail.com>2015-07-22 19:09:49 +0300
commitb0df506a8c30760d9efb07097ed5a4d9a008bf2b (patch)
tree089be546964380d2b7a55dfcd95616c29e347f46 /qt-gui.cpp
parentab44c789939fc4472dfc8106b9cb5f709cbe7e1c (diff)
downloadsubsurface-b0df506a8c30760d9efb07097ed5a4d9a008bf2b.tar.gz
QML UI: Sort dives by date
Sort the dives by date, with the latest one appearing before the others. Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com>
Diffstat (limited to 'qt-gui.cpp')
-rw-r--r--qt-gui.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/qt-gui.cpp b/qt-gui.cpp
index fac743a43..a4997a6fe 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -17,6 +17,7 @@
#include <QQuickWindow>
#include <QQmlApplicationEngine>
#include <QQmlContext>
+#include <QSortFilterProxyModel>
#include "qt-mobile/qmlmanager.h"
#include "qt-models/divelistmodel.h"
#include "qt-mobile/qmlprofile.h"
@@ -44,8 +45,13 @@ void run_ui()
qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
QQmlApplicationEngine engine;
DiveListModel diveListModel;
+ QSortFilterProxyModel *sortModel = new QSortFilterProxyModel(0);
+ sortModel->setSourceModel(&diveListModel);
+ sortModel->setDynamicSortFilter(true);
+ sortModel->setSortRole(DiveListModel::DiveDateRole);
+ sortModel->sort(0, Qt::DescendingOrder);
QQmlContext *ctxt = engine.rootContext();
- ctxt->setContextProperty("diveModel", &diveListModel);
+ ctxt->setContextProperty("diveModel", sortModel);
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
qqWindowObject = engine.rootObjects().value(0);
if (!qqWindowObject) {