From b0df506a8c30760d9efb07097ed5a4d9a008bf2b Mon Sep 17 00:00:00 2001 From: Grace Karanja Date: Wed, 22 Jul 2015 19:09:49 +0300 Subject: QML UI: Sort dives by date Sort the dives by date, with the latest one appearing before the others. Signed-off-by: Grace Karanja --- qt-gui.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'qt-gui.cpp') 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 #include #include +#include #include "qt-mobile/qmlmanager.h" #include "qt-models/divelistmodel.h" #include "qt-mobile/qmlprofile.h" @@ -44,8 +45,13 @@ void run_ui() qmlRegisterType("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) { -- cgit v1.2.3-70-g09d2