aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates/qquickcontainer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates/qquickcontainer.cpp')
-rw-r--r--src/quicktemplates/qquickcontainer.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/quicktemplates/qquickcontainer.cpp b/src/quicktemplates/qquickcontainer.cpp
index b696b1812c..9d48f3b3a1 100644
--- a/src/quicktemplates/qquickcontainer.cpp
+++ b/src/quicktemplates/qquickcontainer.cpp
@@ -5,6 +5,7 @@
#include "qquickcontainer_p_p.h"
#include <QtQuick/private/qquickflickable_p.h>
+#include <QtQuick/private/qquickitemview_p.h>
QT_BEGIN_NAMESPACE
@@ -210,6 +211,7 @@ void QQuickContainerPrivate::insertItem(int index, QQuickItem *item)
updatingCurrent = true;
item->setParentItem(effectiveContentItem(q->contentItem()));
+ maybeCullItem(item);
QQuickItemPrivate::get(item)->addItemChangeListener(this, changeTypes);
contentModel->insert(index, item);
@@ -309,6 +311,38 @@ void QQuickContainerPrivate::reorderItems()
}
}
+void QQuickContainerPrivate::maybeCullItem(QQuickItem *item)
+{
+ if (QQuickItemPrivate::get(item)->isTransparentForPositioner())
+ return;
+
+ // Items like Repeater don't control the visibility of the items they create,
+ // so we can't expected them to uncull items added dynamically. As mentioned
+ // below, Repeater _does_ uncull items added to it, but unlike e.g. ListView,
+ // it shouldn't care if its size becomes zero and so it shouldn't manage
+ // the culled state of items in the same way.
+ if (!qobject_cast<QQuickItemView *>(contentItem))
+ return;
+
+ // Only cull items if the contentItem has a zero size; otherwise let the
+ // contentItem manage it.
+ const bool hasZeroSize = qFuzzyIsNull(width) && qFuzzyIsNull(height);
+ if (!hasZeroSize)
+ return;
+
+ QQuickItemPrivate::get(item)->setCulled(true);
+}
+
+void QQuickContainerPrivate::maybeCullItems()
+{
+ if (!contentItem)
+ return;
+
+ const QList<QQuickItem *> childItems = effectiveContentItem(contentItem)->childItems();
+ for (auto &childItem : childItems)
+ maybeCullItem(childItem);
+}
+
void QQuickContainerPrivate::_q_currentIndexChanged()
{
Q_Q(QQuickContainer);
@@ -808,6 +842,7 @@ void QQuickContainer::componentComplete()
Q_D(QQuickContainer);
QQuickControl::componentComplete();
d->reorderItems();
+ d->maybeCullItems();
}
void QQuickContainer::itemChange(ItemChange change, const ItemChangeData &data)