From 142c8b218b1f9a4a3e217023531feedd7cf9713e Mon Sep 17 00:00:00 2001 From: Sebastian Kügler Date: Tue, 12 Jan 2016 03:01:15 +0100 Subject: Fix bugs in edit drawer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - As the list may get reset on save, the dive_id effectively changes since currentItem isn't updated. So after editing, we end up with a different currentItem than visible. This is very unintuitive, but has to do with the model resetting. It would result in the edit view not showing the current dive when opened the second time. Let's make sure that out currentItem is always the visible one before we're filling the data into the edit page. - Close the drawer when we're navigating away from the dive item, for example when hitting the back button. Signed-off-by: Sebastian Kügler --- qt-mobile/qml/DiveDetails.qml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/qt-mobile/qml/DiveDetails.qml b/qt-mobile/qml/DiveDetails.qml index 1285d185a..cae8aab0c 100644 --- a/qt-mobile/qml/DiveDetails.qml +++ b/qt-mobile/qml/DiveDetails.qml @@ -10,6 +10,7 @@ MobileComponents.Page { id: page objectName: "DiveList" property alias currentIndex: diveListView.currentIndex + mainAction: Action { iconName: editDrawer.opened ? "dialog-cancel" : "document-edit" onTriggered: { @@ -17,6 +18,10 @@ MobileComponents.Page { editDrawer.close(); return; } + // After saving, the list may be shuffled, so first of all make sure that + // the listview's currentIndex is the visible item + // This makes sure that we always edit the currently visible item + diveListView.currentIndex = diveListView.indexAt(diveListView.contentX+1, 1); detailsEdit.dive_id = diveListView.currentItem.modelData.dive.id detailsEdit.number = diveListView.currentItem.modelData.dive.number detailsEdit.dateText = diveListView.currentItem.modelData.dive.date @@ -48,7 +53,7 @@ MobileComponents.Page { currentIndex: -1 boundsBehavior: Flickable.StopAtBounds maximumFlickVelocity: parent.width/4 - cacheBuffer: parent.width/2 + //cacheBuffer: parent.width/2 orientation: ListView.Horizontal focus: true clip: true @@ -80,6 +85,14 @@ MobileComponents.Page { id: detailsEdit implicitHeight: page.height - MobileComponents.Units.gridUnit*3 } + // Close the editDrawer when the pageStack navigates away, for example going + // back to the listview after the Back button was pressed + Connections { + target: rootItem.pageStack + onCurrentPageChanged: { + editDrawer.close(); + } + } } } -- cgit v1.2.3-70-g09d2