From b7e4b35cde1f1a6be01818eac94732186a1b99ab Mon Sep 17 00:00:00 2001 From: Grace Karanja Date: Tue, 9 Jun 2015 22:20:44 +0300 Subject: Add DiveListModel This model will be used to show the dives in QML. This commit adds the model, and the means to link it to QML. Signed-off-by: Grace Karanja Signed-off-by: Dirk Hohndel --- qt-mobile/main.qml | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ qt-mobile/qmlmanager.cpp | 15 ++++++++++++--- 2 files changed, 61 insertions(+), 3 deletions(-) (limited to 'qt-mobile') diff --git a/qt-mobile/main.qml b/qt-mobile/main.qml index c6ee4bb09..ab147a2b4 100644 --- a/qt-mobile/main.qml +++ b/qt-mobile/main.qml @@ -37,4 +37,53 @@ ApplicationWindow { } } } + + Rectangle { + width: parent.width; height: parent.height + anchors.fill: parent + + Component { + id: diveDelegate + Item { + id: wrapper + width: parent.width; height: 55 + Column { + Text { text: '#:' + diveNumber + "(" + location + ")" } + Text { text: date } + Text { text: duration + " " + depth } + } + MouseArea { anchors.fill: parent; onClicked: diveListView.currentIndex = index } + + states: State { + name: "Current" + when: wrapper.ListView.isCurrentItem + PropertyChanges { target: wrapper; x:20 } + } + transitions: Transition { + NumberAnimation { properties: "x"; duration: 200 } + } + } + } + + Component { + id: highlightBar + Rectangle { + width: parent.width; height: 50 + color: "#FFFF88" + y: diveListView.currentItem.y; + Behavior on y { SpringAnimation { spring: 2; damping: 0.1 } } + } + } + + ListView { + id: diveListView + width: parent.width; height: parent.height + anchors.fill: parent + model: diveModel + delegate: diveDelegate + focus: true + highlight: highlightBar + highlightFollowsCurrentItem: false + } + } } diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp index 6a770b256..0f8ccbe61 100644 --- a/qt-mobile/qmlmanager.cpp +++ b/qt-mobile/qmlmanager.cpp @@ -1,15 +1,15 @@ #include "qmlmanager.h" #include +#include "../qt-models/divelistmodel.h" + QMLManager::QMLManager() { - } QMLManager::~QMLManager() { - } QString QMLManager::filename() @@ -20,12 +20,21 @@ QString QMLManager::filename() void QMLManager::setFilename(const QString &f) { m_fileName = f; - emit filenameChanged(); loadFile(); + emit filenameChanged(); } void QMLManager::loadFile() { QUrl url(m_fileName); QString strippedFileName = url.toLocalFile(); + + parse_file(strippedFileName.toUtf8().data()); + + int i; + struct dive *d; + + for_each_dive(i, d) { + DiveListModel::instance()->addDive(d); + } } -- cgit v1.2.3-70-g09d2