Timeline: Improve performance of labels

a, We don't need our special synchronous reloader anymore because the
stock Loader does the same now.

b, Creating and removing the labels while scrolling only accounts for a
relatively small part of the total overhead. The most expensive part is
the offset calculation which has to be performed for each label on each
scroll movement. Move parts of that to the parent item.

c, Asynchronous loading of items in a repeater doesn't work because the
repeater will still wait until all the items are loaded. Thus, the
previous code would still load all the labels immediately when
expanding. Use the "active" property instead to load labels on demand.

d, The repeater initializes all the labels to y == 0 before moving them
into place. Make sure they aren't all initially active because of that.

Change-Id: I4d8b762899c4aa88173dacec668341f592ffe38c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2018-01-18 16:26:44 +01:00
parent fb0b5d9d9b
commit 5ad0fea83c
4 changed files with 8 additions and 44 deletions

View File

@@ -42,6 +42,7 @@ Item {
property int visualIndex
property int dragOffset
property Item draggerParent
property int contentBottom: draggerParent.contentY + draggerParent.height - dragOffset
signal dragStarted;
signal dragStopped;
@@ -101,12 +102,14 @@ Item {
visible: expanded
Repeater {
model: expanded ? labels.length : 0
SynchronousReloader {
Loader {
id: loader
asynchronous: dragOffset - draggerParent.contentY + y + txt.height >
draggerParent.height
active: expanded
// Initially y == 0 for all the items. Don't enable them until they have been moved
// into place.
property int offset: (index === 0 || y > 0) ? (y + txt.height)
: draggerParent.contentHeight
active: contentBottom > offset
width: labelContainer.width
height: column.parentModel ? column.parentModel.rowHeight(index + 1) : 0

View File

@@ -1,38 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
import QtQuick 2.0
Loader {
onAsynchronousChanged: {
if (!asynchronous && active && status !== Loader.Ready) {
// Trigger a synchronous reload to avoid glitches
var component = sourceComponent;
sourceComponent = undefined;
sourceComponent = component;
}
}
}

View File

@@ -71,7 +71,7 @@ Flickable {
}
model: modelProxy.models
delegate: SynchronousReloader {
delegate: Loader {
id: loader
asynchronous: y < categories.contentY + categories.height &&
y + height > categories.contentY

View File

@@ -27,7 +27,6 @@
<file>TimelineLabels.qml</file>
<file>TimelineContent.qml</file>
<file>RowLabel.qml</file>
<file>SynchronousReloader.qml</file>
<file>TimelineText.qml</file>
<file>ImageToolButton.qml</file>
<file>TimelineRulers.qml</file>