diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-07-14 13:18:42 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-07-14 14:19:35 +0000 |
commit | d6c8721476607f22896785baa547a7551015f164 (patch) | |
tree | 1e08687e65ac3184e74c0289309abc09452ed47a | |
parent | f7250ca1822f08963f4d9cef6d79a9cfaaddef0d (diff) |
Fix QQuickControlPrivate::getContentItem() overrides
When no content item is explicitly assigned, container type of controls
(Page, Pane, Popup...) create a default content item on demand. Notice
that the content item is created from within the contentItem() getter,
so it must not emit contentItemChanged() to avoid binding loops.
QQuickControl::setContentItem_helper() was introduced in 1eaebd0 to
mitigate basically the same problem with QQuickScrollView, which has
its own special lazy creation of a Flickable content item.
Now, the problem is that the other container controls are not executing
setContentItem_helper(), because they have already assigned contentItem
and therefore it returns right away. Fix the issue by returning the new
content item without assigning it to let setContentItem_helper() do its
job. The issue was spotted while debugging QTBUG-61434.
Change-Id: Id6f84748ec08bbdfd3bd934dda627e2619af7d2a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickpage.cpp | 8 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpane.cpp | 8 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpopup.cpp | 2 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpopupitem.cpp | 2 |
4 files changed, 8 insertions, 12 deletions
diff --git a/src/quicktemplates2/qquickpage.cpp b/src/quicktemplates2/qquickpage.cpp index 40d47cda..ecc5a9c9 100644 --- a/src/quicktemplates2/qquickpage.cpp +++ b/src/quicktemplates2/qquickpage.cpp @@ -107,7 +107,7 @@ QQuickItem *QQuickPagePrivate::getContentItem() { Q_Q(QQuickPage); if (!contentItem) - contentItem = new QQuickItem(q); + return new QQuickItem(q); return contentItem; } @@ -298,8 +298,7 @@ void QQuickPage::setContentHeight(qreal height) */ QQmlListProperty<QObject> QQuickPage::contentData() { - Q_D(QQuickPage); - return QQmlListProperty<QObject>(d->getContentItem(), nullptr, + return QQmlListProperty<QObject>(contentItem(), nullptr, QQuickItemPrivate::data_append, QQuickItemPrivate::data_count, QQuickItemPrivate::data_at, @@ -321,8 +320,7 @@ QQmlListProperty<QObject> QQuickPage::contentData() */ QQmlListProperty<QQuickItem> QQuickPage::contentChildren() { - Q_D(QQuickPage); - return QQmlListProperty<QQuickItem>(d->getContentItem(), nullptr, + return QQmlListProperty<QQuickItem>(contentItem(), nullptr, QQuickItemPrivate::children_append, QQuickItemPrivate::children_count, QQuickItemPrivate::children_at, diff --git a/src/quicktemplates2/qquickpane.cpp b/src/quicktemplates2/qquickpane.cpp index efa85e0c..b89131c4 100644 --- a/src/quicktemplates2/qquickpane.cpp +++ b/src/quicktemplates2/qquickpane.cpp @@ -114,7 +114,7 @@ QQuickItem *QQuickPanePrivate::getContentItem() { Q_Q(QQuickPane); if (!contentItem) - contentItem = new QQuickItem(q); + return new QQuickItem(q); return contentItem; } @@ -206,8 +206,7 @@ void QQuickPane::setContentHeight(qreal height) */ QQmlListProperty<QObject> QQuickPane::contentData() { - Q_D(QQuickPane); - return QQmlListProperty<QObject>(d->getContentItem(), nullptr, + return QQmlListProperty<QObject>(contentItem(), nullptr, QQuickItemPrivate::data_append, QQuickItemPrivate::data_count, QQuickItemPrivate::data_at, @@ -229,8 +228,7 @@ QQmlListProperty<QObject> QQuickPane::contentData() */ QQmlListProperty<QQuickItem> QQuickPane::contentChildren() { - Q_D(QQuickPane); - return QQmlListProperty<QQuickItem>(d->getContentItem(), nullptr, + return QQmlListProperty<QQuickItem>(contentItem(), nullptr, QQuickItemPrivate::children_append, QQuickItemPrivate::children_count, QQuickItemPrivate::children_at, diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index c457b347..ce4072e5 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -261,6 +261,7 @@ void QQuickPopupPrivate::init() popupItem->setVisible(false); q->setParentItem(qobject_cast<QQuickItem *>(parent)); QObject::connect(popupItem, &QQuickControl::paddingChanged, q, &QQuickPopup::paddingChanged); + QObject::connect(popupItem, &QQuickControl::contentItemChanged, q, &QQuickPopup::contentItemChanged); positioner = new QQuickPopupPositioner(q); } @@ -2027,7 +2028,6 @@ void QQuickPopup::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) { Q_UNUSED(newItem); Q_UNUSED(oldItem); - emit contentItemChanged(); } void QQuickPopup::fontChange(const QFont &newFont, const QFont &oldFont) diff --git a/src/quicktemplates2/qquickpopupitem.cpp b/src/quicktemplates2/qquickpopupitem.cpp index 952c2db6..6f9d7697 100644 --- a/src/quicktemplates2/qquickpopupitem.cpp +++ b/src/quicktemplates2/qquickpopupitem.cpp @@ -96,7 +96,7 @@ QQuickItem *QQuickPopupItemPrivate::getContentItem() { Q_Q(QQuickPopupItem); if (!contentItem) - contentItem = new QQuickItem(q); + return new QQuickItem(q); return contentItem; } |