From cfe06a8132615af57c3beb6f2d5991cc2bf0979c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 31 Oct 2016 13:13:03 +0100 Subject: [PATCH] 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 Reviewed-by: Christian Stenger Reviewed-by: Ulf Hermann --- src/libs/timeline/qml/TimeDisplay.qml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/libs/timeline/qml/TimeDisplay.qml b/src/libs/timeline/qml/TimeDisplay.qml index e85f905bb12..599024e6f6c 100644 --- a/src/libs/timeline/qml/TimeDisplay.qml +++ b/src/libs/timeline/qml/TimeDisplay.qml @@ -82,12 +82,12 @@ Item { } Item { - x: Math.floor(firstBlock * timeDisplay.pixelsPerBlock - timeDisplay.offsetX) + x: -(timeDisplay.offsetX % timeDisplay.pixelsPerBlock) y: 0 id: row property int firstBlock: timeDisplay.offsetX / timeDisplay.pixelsPerBlock - property int offset: firstBlock % repeater.model + property int offset: repeater.model - (firstBlock % repeater.model); Repeater { id: repeater @@ -98,19 +98,16 @@ Item { // Changing the text in text nodes is expensive. We minimize the number of changes // by rotating the nodes during scrolling. - property int stableIndex: row.offset > index ? repeater.model - row.offset + index : - index - row.offset + property int stableIndex: (index + row.offset) % repeater.model + height: timeDisplay.height y: 0 x: width * stableIndex width: timeDisplay.pixelsPerBlock - // Manually control this. We don't want it to happen when firstBlock - // changes before stableIndex changes. - onStableIndexChanged: block = row.firstBlock + stableIndex - property int block: -1 - property double blockStartTime: block * timeDisplay.timePerBlock + - timeDisplay.alignedWindowStart + property double blockStartTime: (row.firstBlock + stableIndex) + * timeDisplay.timePerBlock + + timeDisplay.alignedWindowStart TimelineText { id: timeLabel