aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/layouts/qquicklayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports/layouts/qquicklayout.cpp')
-rw-r--r--src/imports/layouts/qquicklayout.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/imports/layouts/qquicklayout.cpp b/src/imports/layouts/qquicklayout.cpp
index 3786d21727..55ee3b63c6 100644
--- a/src/imports/layouts/qquicklayout.cpp
+++ b/src/imports/layouts/qquicklayout.cpp
@@ -42,6 +42,7 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/private/qnumeric_p.h>
#include <QtCore/qmath.h>
+#include <QtQml/qqmlinfo.h>
#include <limits>
/*!
@@ -678,7 +679,7 @@ QQuickLayout *QQuickLayoutAttached::parentLayout() const
parentItem = parentItem->parentItem();
return qobject_cast<QQuickLayout *>(parentItem);
} else {
- qWarning("Layout must be attached to Item elements");
+ qmlWarning(parent()) << "Layout must be attached to Item elements";
}
return 0;
}
@@ -762,9 +763,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 +805,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);