aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlmodels
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-02-10 16:32:56 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-02-10 18:19:57 +0100
commitdba4e7dae4c08ff08fbf1858e8bc5cc2b4cbb553 (patch)
tree8e7fb87851d85770b5fc66bd3fe056b684c3f47f /src/qmlmodels
parentc915ac23d9a460070ab4e4f8417df9db461c537c (diff)
Fix QQmlObjectModel::destroyingItem emission
The signal is used to tell the view that the item is definitely going away. For the "view" based QQmlObjectModel that is almost never really the case, except - oddly - for clear(). The view is typically a QQuickItemView, which casts the item to a QQuickItem and calls setParentItem(nullptr). That in turn is caught by QQuickContainer, which calls remove() on the QQmlObjectModel. That is why remove() can't emit destroyingItem(). Amends 6d0a453f41d304239285d64b06612c36922be701 Change-Id: I5d82def872550744b947b4b53447647327e03f67 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlmodels')
-rw-r--r--src/qmlmodels/qqmlobjectmodel.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/qmlmodels/qqmlobjectmodel.cpp b/src/qmlmodels/qqmlobjectmodel.cpp
index d89ea702fa..90469d06c2 100644
--- a/src/qmlmodels/qqmlobjectmodel.cpp
+++ b/src/qmlmodels/qqmlobjectmodel.cpp
@@ -117,7 +117,6 @@ public:
void replace(int index, QObject *item) {
Q_Q(QQmlObjectModel);
auto *attached = QQmlObjectModelAttached::properties(children.at(index).item);
- emit q->destroyingItem(attached);
attached->setIndex(-1);
children.replace(index, Item(item));
QQmlObjectModelAttached::properties(children.at(index).item)->setIndex(index);
@@ -160,7 +159,6 @@ public:
Q_Q(QQmlObjectModel);
for (int i = index; i < index + n; ++i) {
QQmlObjectModelAttached *attached = QQmlObjectModelAttached::properties(children.at(i).item);
- emit q->destroyingItem(attached);
attached->setIndex(-1);
}
children.erase(children.begin() + index, children.begin() + index + n);
@@ -176,6 +174,9 @@ public:
}
void clear() {
+ Q_Q(QQmlObjectModel);
+ for (const Item &child : qAsConst(children))
+ emit q->destroyingItem(child.item);
remove(0, children.count());
}