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>
This commit is contained in:
Grace Karanja 2015-07-22 19:09:49 +03:00
parent ab44c78993
commit b0df506a8c

View file

@ -17,6 +17,7 @@
#include <QQuickWindow> #include <QQuickWindow>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQmlContext> #include <QQmlContext>
#include <QSortFilterProxyModel>
#include "qt-mobile/qmlmanager.h" #include "qt-mobile/qmlmanager.h"
#include "qt-models/divelistmodel.h" #include "qt-models/divelistmodel.h"
#include "qt-mobile/qmlprofile.h" #include "qt-mobile/qmlprofile.h"
@ -44,8 +45,13 @@ void run_ui()
qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile"); qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
DiveListModel diveListModel; 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(); QQmlContext *ctxt = engine.rootContext();
ctxt->setContextProperty("diveModel", &diveListModel); ctxt->setContextProperty("diveModel", sortModel);
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
qqWindowObject = engine.rootObjects().value(0); qqWindowObject = engine.rootObjects().value(0);
if (!qqWindowObject) { if (!qqWindowObject) {