aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-01-14 21:52:09 +0100
committerLiang Qi <liang.qi@qt.io>2017-01-14 22:17:32 +0100
commit60300fda463ae0f31c1e66ca253a2a976a88ee20 (patch)
treeb2264433418280ccbb7ed173892456fce4fab43a /src/imports
parentdb462cce86dba0be80239d4aaaea668ef173af3d (diff)
parent0e3380f9c6ab6e3ea7398caccf5aa84f1575f1cd (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts: .qmake.conf Change-Id: I9d87ed86e95b5901a86cc3aa65d7ac39b0b708c2
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/layouts/qquicklayout.cpp26
-rw-r--r--src/imports/layouts/qquicklayout_p.h2
-rw-r--r--src/imports/layouts/qquicklinearlayout.cpp6
3 files changed, 29 insertions, 5 deletions
diff --git a/src/imports/layouts/qquicklayout.cpp b/src/imports/layouts/qquicklayout.cpp
index 3786d21727..fd2ff4a73e 100644
--- a/src/imports/layouts/qquicklayout.cpp
+++ b/src/imports/layouts/qquicklayout.cpp
@@ -762,9 +762,11 @@ bool QQuickLayout::shouldIgnoreItem(QQuickItem *child, QQuickLayoutAttached *&in
void QQuickLayout::itemChange(ItemChange change, const ItemChangeData &value)
{
if (change == ItemChildAddedChange) {
+ Q_D(QQuickLayout);
QQuickItem *item = value.item;
qmlobject_connect(item, QQuickItem, SIGNAL(baselineOffsetChanged(qreal)), this, QQuickLayout, SLOT(invalidateSenderItem()));
QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed | QQuickItemPrivate::Visibility);
+ d->m_hasItemChangeListeners = true;
if (isReady())
updateLayoutItems();
} else if (change == ItemChildRemovedChange) {
@@ -802,6 +804,30 @@ bool QQuickLayout::isReady() const
return d_func()->m_isReady;
}
+/*!
+ * \brief QQuickLayout::deactivateRecur
+ * \internal
+ *
+ * Call this from the dtor of the top-level layout.
+ * Otherwise, it will trigger lots of unneeded item change listeners (itemVisibleChanged()) for all its descendants
+ * that will have its impact thrown away.
+ */
+void QQuickLayout::deactivateRecur()
+{
+ if (d_func()->m_hasItemChangeListeners) {
+ for (int i = 0; i < itemCount(); ++i) {
+ QQuickItem *item = itemAt(i);
+ // When deleting a layout with children, there is no reason for the children to inform the layout that their
+ // e.g. visibility got changed. The layout already knows that all its children will eventually become invisible, so
+ // we therefore remove its change listener.
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed | QQuickItemPrivate::Visibility);
+ if (QQuickLayout *layout = qobject_cast<QQuickLayout*>(item))
+ layout->deactivateRecur();
+ }
+ d_func()->m_hasItemChangeListeners = false;
+ }
+}
+
void QQuickLayout::itemSiblingOrderChanged(QQuickItem *item)
{
Q_UNUSED(item);
diff --git a/src/imports/layouts/qquicklayout_p.h b/src/imports/layouts/qquicklayout_p.h
index eece6f8658..113498eb2b 100644
--- a/src/imports/layouts/qquicklayout_p.h
+++ b/src/imports/layouts/qquicklayout_p.h
@@ -95,6 +95,7 @@ public:
void itemChange(ItemChange change, const ItemChangeData &value) Q_DECL_OVERRIDE;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
bool isReady() const;
+ void deactivateRecur();
/* QQuickItemChangeListener */
@@ -134,6 +135,7 @@ public:
protected:
unsigned m_isReady : 1;
unsigned m_disableRearrange : 1;
+ unsigned m_hasItemChangeListeners : 1; // if false, we don't need to remove its item change listeners...
mutable QSet<QQuickItem *> m_ignoredItems;
};
diff --git a/src/imports/layouts/qquicklinearlayout.cpp b/src/imports/layouts/qquicklinearlayout.cpp
index 13fdd496c2..50b3eed87e 100644
--- a/src/imports/layouts/qquicklinearlayout.cpp
+++ b/src/imports/layouts/qquicklinearlayout.cpp
@@ -305,11 +305,7 @@ QQuickGridLayoutBase::~QQuickGridLayoutBase()
// Remove item listeners so we do not act on signalling unnecessarily
// (there is no point, as the layout will be torn down anyway).
- for (int i = 0; i < itemCount(); ++i) {
- QQuickItem *item = itemAt(i);
- QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed | QQuickItemPrivate::Visibility);
- }
-
+ deactivateRecur();
delete d->styleInfo;
}