Timeline: Drop manual control of scale updates

The assumption that the scale entries only have to be updated when
their stable index changes was wrong. The repeater can shuffle around,
stash and restore items at will. It might restore some item at the
same position, but the timestamp it refers to might have changed. Thus,
the value being displayed was wrong until the timeline got scrolled.

By using a proper binding we avoid this. In turn the blockStartTime
might get re-evaluated twice for a single update to row.firstBlock.
That would be bad as we would constantly re-render all the texts.
Experiments show that the current implementation of the QML engine
happens to order the bindings in a way where this doesn't happen and
we cannot get better than this without huge overhead.

Also, we simplify some of the expressions involved.

Change-Id: I93848f89bdbefd28c3dbf30f13551c9476dabd37
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Ulf Hermann
2016-10-31 13:13:03 +01:00
parent 9050f19046
commit cfe06a8132

View File

@@ -82,12 +82,12 @@ Item {
} }
Item { Item {
x: Math.floor(firstBlock * timeDisplay.pixelsPerBlock - timeDisplay.offsetX) x: -(timeDisplay.offsetX % timeDisplay.pixelsPerBlock)
y: 0 y: 0
id: row id: row
property int firstBlock: timeDisplay.offsetX / timeDisplay.pixelsPerBlock property int firstBlock: timeDisplay.offsetX / timeDisplay.pixelsPerBlock
property int offset: firstBlock % repeater.model property int offset: repeater.model - (firstBlock % repeater.model);
Repeater { Repeater {
id: repeater id: repeater
@@ -98,19 +98,16 @@ Item {
// Changing the text in text nodes is expensive. We minimize the number of changes // Changing the text in text nodes is expensive. We minimize the number of changes
// by rotating the nodes during scrolling. // by rotating the nodes during scrolling.
property int stableIndex: row.offset > index ? repeater.model - row.offset + index : property int stableIndex: (index + row.offset) % repeater.model
index - row.offset
height: timeDisplay.height height: timeDisplay.height
y: 0 y: 0
x: width * stableIndex x: width * stableIndex
width: timeDisplay.pixelsPerBlock width: timeDisplay.pixelsPerBlock
// Manually control this. We don't want it to happen when firstBlock property double blockStartTime: (row.firstBlock + stableIndex)
// changes before stableIndex changes. * timeDisplay.timePerBlock
onStableIndexChanged: block = row.firstBlock + stableIndex + timeDisplay.alignedWindowStart
property int block: -1
property double blockStartTime: block * timeDisplay.timePerBlock +
timeDisplay.alignedWindowStart
TimelineText { TimelineText {
id: timeLabel id: timeLabel