diff options
Diffstat (limited to 'src/qmlmodels/qqmlobjectmodel.cpp')
-rw-r--r-- | src/qmlmodels/qqmlobjectmodel.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/qmlmodels/qqmlobjectmodel.cpp b/src/qmlmodels/qqmlobjectmodel.cpp index 85e64cc2f9..dac868a0a2 100644 --- a/src/qmlmodels/qqmlobjectmodel.cpp +++ b/src/qmlmodels/qqmlobjectmodel.cpp @@ -91,6 +91,15 @@ public: static_cast<QQmlObjectModelPrivate *>(prop->data)->clear(); } + static void children_replace(QQmlListProperty<QObject> *prop, int index, QObject *item) { + static_cast<QQmlObjectModelPrivate *>(prop->data)->replace(index, item); + } + + static void children_removeLast(QQmlListProperty<QObject> *prop) { + auto data = static_cast<QQmlObjectModelPrivate *>(prop->data); + data->remove(data->children.count() - 1, 1); + } + void insert(int index, QObject *item) { Q_Q(QQmlObjectModel); children.insert(index, Item(item)); @@ -105,6 +114,18 @@ public: emit q->childrenChanged(); } + void replace(int index, QObject *item) { + Q_Q(QQmlObjectModel); + auto *attached = QQmlObjectModelAttached::properties(children.at(index).item); + attached->setIndex(-1); + children.replace(index, Item(item)); + QQmlObjectModelAttached::properties(children.at(index).item)->setIndex(index); + QQmlChangeSet changeSet; + changeSet.change(index, 1); + emit q->modelUpdated(changeSet, false); + emit q->childrenChanged(); + } + void move(int from, int to, int n) { Q_Q(QQmlObjectModel); if (from > to) { @@ -229,12 +250,13 @@ QQmlObjectModel::QQmlObjectModel(QObject *parent) QQmlListProperty<QObject> QQmlObjectModel::children() { Q_D(QQmlObjectModel); - return QQmlListProperty<QObject>(this, - d, - d->children_append, - d->children_count, - d->children_at, - d->children_clear); + return QQmlListProperty<QObject>(this, d, + QQmlObjectModelPrivate::children_append, + QQmlObjectModelPrivate::children_count, + QQmlObjectModelPrivate::children_at, + QQmlObjectModelPrivate::children_clear, + QQmlObjectModelPrivate::children_replace, + QQmlObjectModelPrivate::children_removeLast); } /*! |