From 68414531adeb68f7ad01c98bbac4d4d950409f02 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 22 Nov 2018 22:10:38 +0100 Subject: Mobile: don't format trip heading for all dives QML's ListView uses the "section" property to test if items belong to the same section. Apparently, this must be a string and therefore we can't pass e.g. a dive-trip object. Therefore a specially formatted string was passed in, which was guaranteed to be unique (contained the dive-trip pointer value) and the fully formatted trip-title and short-date. The disadvantage of that approach is that the formatting is performed for every dive and not every trip. Perhaps not a problem now, but it makes it for example necessary to cache the number of filtered dives. To be more flexible, pass in only the pointer value formatted as hexadecimal string and provide a function to convert that string back to a trip-pointer (in the form of a QVariant, so that it can be passed to QML). Moreover provide two functions for formatting the title and the short-date. The three new functions are members of DiveListSortModel. This might not be the perfect place, but it is easy to reach from the DiveListView. Signed-off-by: Berthold Stoeger --- mobile-widgets/qml/DiveList.qml | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'mobile-widgets/qml') diff --git a/mobile-widgets/qml/DiveList.qml b/mobile-widgets/qml/DiveList.qml index f31a2ca8b..3d29a1ec4 100644 --- a/mobile-widgets/qml/DiveList.qml +++ b/mobile-widgets/qml/DiveList.qml @@ -58,7 +58,7 @@ Kirigami.ScrollablePage { states: [ State { name: "isHidden"; - when: dive.tripMeta !== activeTrip && ! diveOutsideTrip + when: dive.tripId !== activeTrip && ! diveOutsideTrip PropertyChanges { target: innerListItem height: 0 @@ -67,7 +67,7 @@ Kirigami.ScrollablePage { }, State { name: "isVisible"; - when: dive.tripMeta === activeTrip || diveOutsideTrip + when: dive.tripId === activeTrip || diveOutsideTrip PropertyChanges { target: innerListItem height: diveListEntry.height + Kirigami.Units.smallSpacing @@ -130,7 +130,7 @@ Kirigami.ScrollablePage { Item { Rectangle { id: leftBarDive - width: dive.tripMeta == "" ? 0 : Kirigami.Units.smallSpacing + width: dive.tripId == "" ? 0 : Kirigami.Units.smallSpacing height: diveListEntry.height * 0.8 color: subsurfaceTheme.lightPrimaryColor anchors { @@ -348,7 +348,10 @@ Kirigami.ScrollablePage { leftMargin: Kirigami.Units.smallSpacing } Controls.Label { - text: { section.replace(/.*\+\+/, "").replace(/::.*/, "").replace("@", "\n'") } + text: { + var trip = diveListView.model.tripIdToObject(section); + diveListView.model.tripShortDate(trip); + } color: subsurfaceTheme.primaryTextColor font.pointSize: subsurfaceTheme.smallPointSize lineHeightMode: Text.FixedHeight @@ -372,17 +375,8 @@ Kirigami.ScrollablePage { Controls.Label { id: sectionText text: { - // if the tripMeta (which we get as "section") ends in ::-- we know - // that there's no trip -- otherwise strip the meta information before - // the :: and show the trip location - var shownText - var endsWithDoubleDash = /::--$/; - if (endsWithDoubleDash.test(section) || section === "--") { - shownText = "" - } else { - shownText = section.replace(/.*::/, "") - } - shownText + var trip = diveListView.model.tripIdToObject(section); + diveListView.model.tripTitle(trip); } wrapMode: Text.WrapAtWordBoundaryOrAnywhere visible: text !== "" @@ -526,7 +520,7 @@ Kirigami.ScrollablePage { maximumFlickVelocity: parent.height * 5 bottomMargin: Kirigami.Units.iconSizes.medium + Kirigami.Units.gridUnit cacheBuffer: 40 // this will increase memory use, but should help with scrolling - section.property: "dive.tripMeta" + section.property: "dive.tripId" section.criteria: ViewSection.FullString section.delegate: tripHeading section.labelPositioning: ViewSection.CurrentLabelAtStart | ViewSection.InlineLabels -- cgit v1.2.3-70-g09d2