From cca6e8e3bd80824ff5aa3e17995a5b46ad48be28 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 3 Jul 2017 13:14:57 +0200 Subject: Tumbler: fix regression with currentIndex and currentItem 2c4b2d48 made Tumbler's wrap property follow its count by default, but did so using updatePolish() to account for the use case where a items are appended to the model in a for loop, as is done in TumblerDatePicker.qml in Tumbler's auto tests. This (appending items one at a time in a for loop) is not a good idea, but it should work. The problem with the solution is that the delay means that the use cases mentioned in the referenced bug report were broken. This patch removes the delay. The recursion guards are necessary due to the complex nature of TumblerView (and its non-standard use of the Qt Quick views), as they prevent a memory leak in QQuickListView::createHighlight() from being introuduced. We now call deleteLater() to ensure we do not interfere with the views' internal operations, and hence we also perform a few extra operations at the same time as insurance (although it appears that simply unparenting the internal view from QQuickTumblerView is enough to get the tests to pass). Task-number: QTBUG-61374 Change-Id: Ifef9e99522ea183b282ac862f346beaed12d0c09 Reviewed-by: J-P Nurmi --- src/quicktemplates2/qquicktumbler.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/quicktemplates2/qquicktumbler.cpp') diff --git a/src/quicktemplates2/qquicktumbler.cpp b/src/quicktemplates2/qquicktumbler.cpp index 5cdd140d..80ab71ea 100644 --- a/src/quicktemplates2/qquicktumbler.cpp +++ b/src/quicktemplates2/qquicktumbler.cpp @@ -97,7 +97,8 @@ QQuickTumblerPrivate::QQuickTumblerPrivate() currentIndex(-1), pendingCurrentIndex(-1), ignoreCurrentIndexChanges(false), - count(0) + count(0), + ignoreSignals(false) { } @@ -163,6 +164,9 @@ QQuickTumblerPrivate *QQuickTumblerPrivate::get(QQuickTumbler *tumbler) void QQuickTumblerPrivate::_q_updateItemHeights() { + if (ignoreSignals) + return; + // Can't use our own private padding members here, as the padding property might be set, // which doesn't affect them, only their getters. Q_Q(const QQuickTumbler); @@ -174,6 +178,9 @@ void QQuickTumblerPrivate::_q_updateItemHeights() void QQuickTumblerPrivate::_q_updateItemWidths() { + if (ignoreSignals) + return; + Q_Q(const QQuickTumbler); const qreal availableWidth = q->availableWidth(); const auto items = viewContentItemChildItems(); @@ -195,6 +202,8 @@ void QQuickTumblerPrivate::_q_onViewCurrentIndexChanged() void QQuickTumblerPrivate::_q_onViewCountChanged() { Q_Q(QQuickTumbler); + if (ignoreSignals) + return; setCount(view->property("count").toInt()); @@ -336,7 +345,9 @@ void QQuickTumbler::setCurrentIndex(int currentIndex) couldSet = true; } else { d->ignoreCurrentIndexChanges = true; + d->ignoreSignals = true; d->view->setProperty("currentIndex", currentIndex); + d->ignoreSignals = false; d->ignoreCurrentIndexChanges = false; couldSet = d->view->property("currentIndex").toInt() == currentIndex; -- cgit v1.2.3