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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-11-22 22:10:38 +01:00 committed by Dirk Hohndel
parent a863386cd4
commit 68414531ad
5 changed files with 67 additions and 51 deletions

View file

@ -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