From 6d0a453f41d304239285d64b06612c36922be701 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 25 Nov 2019 16:10:04 +0100 Subject: Use the extended QQmlListProperty interface in a few places Task-number: QTBUG-79263 Change-Id: If518f644b5b9eddbacfb1cb16fbb557127ffcfb2 Reviewed-by: Simon Hausmann Reviewed-by: Shawn Rutledge --- .../referenceexamples/attached/birthdayparty.cpp | 2 +- .../referenceexamples/binding/birthdayparty.cpp | 2 +- .../referenceexamples/coercion/birthdayparty.cpp | 2 +- .../referenceexamples/default/birthdayparty.cpp | 2 +- .../referenceexamples/grouped/birthdayparty.cpp | 2 +- .../referenceexamples/methods/birthdayparty.cpp | 2 +- .../referenceexamples/properties/birthdayparty.cpp | 24 ++++++++++++- .../referenceexamples/properties/birthdayparty.h | 4 +++ .../qml/referenceexamples/signal/birthdayparty.cpp | 2 +- .../valuesource/birthdayparty.cpp | 2 +- .../chapter5-listproperties/piechart.cpp | 3 +- .../chapter6-plugins/import/piechart.cpp | 3 +- src/imports/labsmodels/qqmldelegatecomponent.cpp | 24 ++++++++++++- src/imports/labsmodels/qqmldelegatecomponent_p.h | 2 ++ src/imports/labsmodels/qqmltablemodel.cpp | 17 +++++++++- src/imports/labsmodels/qqmltablemodel_p.h | 2 ++ src/particles/qquickimageparticle.cpp | 4 ++- src/particles/qquickparticlegroup.cpp | 13 +++++--- src/qml/qml/qqmlvmemetaobject.cpp | 17 +++++++++- src/qmlmodels/qqmldelegatemodel.cpp | 2 +- src/qmlmodels/qqmlobjectmodel.cpp | 39 +++++++++++++++++----- src/qmlmodels/qquickpackage.cpp | 19 ++++++++--- src/quick/items/qquickspriteengine_p.h | 12 +++++++ src/quick/items/qquickspritesequence.cpp | 4 ++- src/quick/items/qquickwindow.cpp | 25 +++++++++++--- src/quick/items/qquickwindow_p.h | 2 ++ src/quick/util/qquickstate.cpp | 10 ++++-- src/quick/util/qquickstate_p_p.h | 17 ++++++++++ src/quick/util/qquickstategroup.cpp | 36 +++++++++++++++++--- 29 files changed, 250 insertions(+), 45 deletions(-) diff --git a/examples/qml/referenceexamples/attached/birthdayparty.cpp b/examples/qml/referenceexamples/attached/birthdayparty.cpp index da0cb800fc..888aafbc18 100644 --- a/examples/qml/referenceexamples/attached/birthdayparty.cpp +++ b/examples/qml/referenceexamples/attached/birthdayparty.cpp @@ -81,7 +81,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/binding/birthdayparty.cpp b/examples/qml/referenceexamples/binding/birthdayparty.cpp index 866c1f6968..cfedf84be0 100644 --- a/examples/qml/referenceexamples/binding/birthdayparty.cpp +++ b/examples/qml/referenceexamples/binding/birthdayparty.cpp @@ -87,7 +87,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty BirthdayParty::guests() { - return QQmlListProperty(this, m_guests); + return QQmlListProperty(this, &m_guests); } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/coercion/birthdayparty.cpp b/examples/qml/referenceexamples/coercion/birthdayparty.cpp index 1bae55076c..81db8ab1b8 100644 --- a/examples/qml/referenceexamples/coercion/birthdayparty.cpp +++ b/examples/qml/referenceexamples/coercion/birthdayparty.cpp @@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/default/birthdayparty.cpp b/examples/qml/referenceexamples/default/birthdayparty.cpp index 1bae55076c..81db8ab1b8 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.cpp +++ b/examples/qml/referenceexamples/default/birthdayparty.cpp @@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.cpp b/examples/qml/referenceexamples/grouped/birthdayparty.cpp index 1bae55076c..81db8ab1b8 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.cpp +++ b/examples/qml/referenceexamples/grouped/birthdayparty.cpp @@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/methods/birthdayparty.cpp b/examples/qml/referenceexamples/methods/birthdayparty.cpp index 7e750e4f4b..4b30d31aeb 100644 --- a/examples/qml/referenceexamples/methods/birthdayparty.cpp +++ b/examples/qml/referenceexamples/methods/birthdayparty.cpp @@ -67,7 +67,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/properties/birthdayparty.cpp b/examples/qml/referenceexamples/properties/birthdayparty.cpp index 9abb08dbd9..fe6abab3f5 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.cpp +++ b/examples/qml/referenceexamples/properties/birthdayparty.cpp @@ -71,7 +71,9 @@ QQmlListProperty BirthdayParty::guests() &BirthdayParty::appendGuest, &BirthdayParty::guestCount, &BirthdayParty::guest, - &BirthdayParty::clearGuests}; + &BirthdayParty::clearGuests, + &BirthdayParty::replaceGuest, + &BirthdayParty::removeLastGuest}; } void BirthdayParty::appendGuest(Person* p) { @@ -93,6 +95,16 @@ void BirthdayParty::clearGuests() { m_guests.clear(); } +void BirthdayParty::replaceGuest(int index, Person *p) +{ + m_guests[index] = p; +} + +void BirthdayParty::removeLastGuest() +{ + m_guests.removeLast(); +} + // ![0] void BirthdayParty::appendGuest(QQmlListProperty* list, Person* p) { @@ -103,6 +115,16 @@ void BirthdayParty::clearGuests(QQmlListProperty* list) { reinterpret_cast< BirthdayParty* >(list->data)->clearGuests(); } +void BirthdayParty::replaceGuest(QQmlListProperty *list, int i, Person *p) +{ + reinterpret_cast< BirthdayParty* >(list->data)->replaceGuest(i, p); +} + +void BirthdayParty::removeLastGuest(QQmlListProperty *list) +{ + reinterpret_cast< BirthdayParty* >(list->data)->removeLastGuest(); +} + Person* BirthdayParty::guest(QQmlListProperty* list, int i) { return reinterpret_cast< BirthdayParty* >(list->data)->guest(i); } diff --git a/examples/qml/referenceexamples/properties/birthdayparty.h b/examples/qml/referenceexamples/properties/birthdayparty.h index fb8b63a79d..a5704972cc 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.h +++ b/examples/qml/referenceexamples/properties/birthdayparty.h @@ -79,12 +79,16 @@ public: int guestCount() const; Person *guest(int) const; void clearGuests(); + void replaceGuest(int, Person*); + void removeLastGuest(); private: static void appendGuest(QQmlListProperty*, Person*); static int guestCount(QQmlListProperty*); static Person* guest(QQmlListProperty*, int); static void clearGuests(QQmlListProperty*); + static void replaceGuest(QQmlListProperty*, int, Person*); + static void removeLastGuest(QQmlListProperty*); Person *m_host; QVector m_guests; diff --git a/examples/qml/referenceexamples/signal/birthdayparty.cpp b/examples/qml/referenceexamples/signal/birthdayparty.cpp index 9d34cdf146..405c8af940 100644 --- a/examples/qml/referenceexamples/signal/birthdayparty.cpp +++ b/examples/qml/referenceexamples/signal/birthdayparty.cpp @@ -82,7 +82,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.cpp b/examples/qml/referenceexamples/valuesource/birthdayparty.cpp index 68d5767e8d..6a5e67aa0d 100644 --- a/examples/qml/referenceexamples/valuesource/birthdayparty.cpp +++ b/examples/qml/referenceexamples/valuesource/birthdayparty.cpp @@ -82,7 +82,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.cpp b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.cpp index ac680bb9c9..a8e14db542 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.cpp +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.cpp @@ -68,7 +68,8 @@ void PieChart::setName(const QString &name) //![0] QQmlListProperty PieChart::slices() { - return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, nullptr, nullptr); + return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, + nullptr, nullptr, nullptr, nullptr); } void PieChart::append_slice(QQmlListProperty *list, PieSlice *slice) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp index 1c712c887a..536c0e16ae 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp @@ -67,7 +67,8 @@ void PieChart::setName(const QString &name) QQmlListProperty PieChart::slices() { - return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, nullptr, nullptr); + return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, + nullptr, nullptr, nullptr, nullptr); } void PieChart::append_slice(QQmlListProperty *list, PieSlice *slice) diff --git a/src/imports/labsmodels/qqmldelegatecomponent.cpp b/src/imports/labsmodels/qqmldelegatecomponent.cpp index aaf3fea5da..b8eb8049b3 100644 --- a/src/imports/labsmodels/qqmldelegatecomponent.cpp +++ b/src/imports/labsmodels/qqmldelegatecomponent.cpp @@ -250,7 +250,9 @@ QQmlListProperty QQmlDelegateChooser::choices() QQmlDelegateChooser::choices_append, QQmlDelegateChooser::choices_count, QQmlDelegateChooser::choices_at, - QQmlDelegateChooser::choices_clear); + QQmlDelegateChooser::choices_clear, + QQmlDelegateChooser::choices_replace, + QQmlDelegateChooser::choices_removeLast); } void QQmlDelegateChooser::choices_append(QQmlListProperty *prop, QQmlDelegateChoice *choice) @@ -282,6 +284,26 @@ void QQmlDelegateChooser::choices_clear(QQmlListProperty *pr q->delegateChanged(); } +void QQmlDelegateChooser::choices_replace(QQmlListProperty *prop, int index, + QQmlDelegateChoice *choice) +{ + QQmlDelegateChooser *q = static_cast(prop->object); + disconnect(q->m_choices[index], &QQmlDelegateChoice::changed, + q, &QQmlAbstractDelegateComponent::delegateChanged); + q->m_choices[index] = choice; + connect(choice, &QQmlDelegateChoice::changed, q, + &QQmlAbstractDelegateComponent::delegateChanged); + q->delegateChanged(); +} + +void QQmlDelegateChooser::choices_removeLast(QQmlListProperty *prop) +{ + QQmlDelegateChooser *q = static_cast(prop->object); + disconnect(q->m_choices.takeLast(), &QQmlDelegateChoice::changed, + q, &QQmlAbstractDelegateComponent::delegateChanged); + q->delegateChanged(); +} + QQmlComponent *QQmlDelegateChooser::delegate(QQmlAdaptorModel *adaptorModel, int row, int column) const { QVariant v; diff --git a/src/imports/labsmodels/qqmldelegatecomponent_p.h b/src/imports/labsmodels/qqmldelegatecomponent_p.h index 4c39dc0d0a..8473831b1d 100644 --- a/src/imports/labsmodels/qqmldelegatecomponent_p.h +++ b/src/imports/labsmodels/qqmldelegatecomponent_p.h @@ -116,6 +116,8 @@ public: static int choices_count(QQmlListProperty *); static QQmlDelegateChoice *choices_at(QQmlListProperty *, int); static void choices_clear(QQmlListProperty *); + static void choices_replace(QQmlListProperty *, int, QQmlDelegateChoice *); + static void choices_removeLast(QQmlListProperty *); QQmlComponent *delegate(QQmlAdaptorModel *adaptorModel, int row, int column = -1) const override; diff --git a/src/imports/labsmodels/qqmltablemodel.cpp b/src/imports/labsmodels/qqmltablemodel.cpp index b6468d760f..6ba2cecf19 100644 --- a/src/imports/labsmodels/qqmltablemodel.cpp +++ b/src/imports/labsmodels/qqmltablemodel.cpp @@ -644,7 +644,9 @@ QQmlListProperty QQmlTableModel::columns() &QQmlTableModel::columns_append, &QQmlTableModel::columns_count, &QQmlTableModel::columns_at, - &QQmlTableModel::columns_clear); + &QQmlTableModel::columns_clear, + &QQmlTableModel::columns_replace, + &QQmlTableModel::columns_removeLast); } void QQmlTableModel::columns_append(QQmlListProperty *property, @@ -674,6 +676,19 @@ void QQmlTableModel::columns_clear(QQmlListProperty *prope return model->mColumns.clear(); } +void QQmlTableModel::columns_replace(QQmlListProperty *property, int index, QQmlTableModelColumn *value) +{ + QQmlTableModel *model = static_cast(property->object); + if (QQmlTableModelColumn *column = qobject_cast(value)) + return model->mColumns.replace(index, column); +} + +void QQmlTableModel::columns_removeLast(QQmlListProperty *property) +{ + QQmlTableModel *model = static_cast(property->object); + model->mColumns.removeLast(); +} + /*! \qmlmethod QModelIndex TableModel::index(int row, int column) diff --git a/src/imports/labsmodels/qqmltablemodel_p.h b/src/imports/labsmodels/qqmltablemodel_p.h index d6e982d19a..75e2768849 100644 --- a/src/imports/labsmodels/qqmltablemodel_p.h +++ b/src/imports/labsmodels/qqmltablemodel_p.h @@ -96,6 +96,8 @@ public: static int columns_count(QQmlListProperty *property); static QQmlTableModelColumn *columns_at(QQmlListProperty *property, int index); static void columns_clear(QQmlListProperty *property); + static void columns_replace(QQmlListProperty *property, int index, QQmlTableModelColumn *value); + static void columns_removeLast(QQmlListProperty *property); QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp index c6fe2f516d..4d67691771 100644 --- a/src/particles/qquickimageparticle.cpp +++ b/src/particles/qquickimageparticle.cpp @@ -1143,7 +1143,9 @@ QQuickImageParticle::~QQuickImageParticle() QQmlListProperty QQuickImageParticle::sprites() { - return QQmlListProperty(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear); + return QQmlListProperty(this, &m_sprites, + spriteAppend, spriteCount, spriteAt, + spriteClear, spriteReplace, spriteRemoveLast); } void QQuickImageParticle::sceneGraphInvalidated() diff --git a/src/particles/qquickparticlegroup.cpp b/src/particles/qquickparticlegroup.cpp index 052fda6eff..902c23331d 100644 --- a/src/particles/qquickparticlegroup.cpp +++ b/src/particles/qquickparticlegroup.cpp @@ -106,10 +106,15 @@ void delayedRedirect(QQmlListProperty *prop, QObject *value) QQmlListProperty QQuickParticleGroup::particleChildren() { QQuickParticleSystem* system = qobject_cast(parent()); - if (system) - return QQmlListProperty(this, nullptr, &QQuickParticleSystem::statePropertyRedirect, nullptr, nullptr, nullptr); - else - return QQmlListProperty(this, nullptr, &delayedRedirect, nullptr, nullptr, nullptr); + if (system) { + return QQmlListProperty(this, nullptr, + &QQuickParticleSystem::statePropertyRedirect, nullptr, + nullptr, nullptr, nullptr, nullptr); + } else { + return QQmlListProperty(this, nullptr, + &delayedRedirect, nullptr, nullptr, + nullptr, nullptr, nullptr); + } } void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg) diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index c20bc24a49..de23e929e2 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -136,6 +136,20 @@ static void list_clear(QQmlListProperty *prop) resolved.activateSignal(); } +static void list_replace(QQmlListProperty *prop, int index, QObject *o) +{ + const ResolvedList resolved(prop); + resolved.list()->replace(index, o); + resolved.activateSignal(); +} + +static void list_removeLast(QQmlListProperty *prop) +{ + const ResolvedList resolved(prop); + resolved.list()->removeLast(); + resolved.activateSignal(); +} + QQmlVMEVariantQObjectPtr::QQmlVMEVariantQObjectPtr() : QQmlGuard(nullptr), m_target(nullptr), m_index(-1) { @@ -737,7 +751,8 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * *static_cast *>(a[0]) = QQmlListProperty( object, reinterpret_cast(quintptr(id)), - list_append, list_count, list_at, list_clear); + list_append, list_count, list_at, + list_clear, list_replace, list_removeLast); } else { *reinterpret_cast(a[0]) = readPropertyAsQObject(id); } diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index ee407538f1..c32caafaa6 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -731,7 +731,7 @@ QQmlListProperty QQmlDelegateModel::groups() QQmlDelegateModelPrivate::group_append, QQmlDelegateModelPrivate::group_count, QQmlDelegateModelPrivate::group_at, - nullptr); + nullptr, nullptr, nullptr); } /*! diff --git a/src/qmlmodels/qqmlobjectmodel.cpp b/src/qmlmodels/qqmlobjectmodel.cpp index 01e91e98dd..d89ea702fa 100644 --- a/src/qmlmodels/qqmlobjectmodel.cpp +++ b/src/qmlmodels/qqmlobjectmodel.cpp @@ -91,6 +91,15 @@ public: static_cast(prop->data)->clear(); } + static void children_replace(QQmlListProperty *prop, int index, QObject *item) { + static_cast(prop->data)->replace(index, item); + } + + static void children_removeLast(QQmlListProperty *prop) { + auto data = static_cast(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,19 @@ public: emit q->childrenChanged(); } + 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); + 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) { @@ -138,6 +160,7 @@ 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); @@ -153,9 +176,6 @@ public: } void clear() { - Q_Q(QQmlObjectModel); - for (const Item &child : qAsConst(children)) - emit q->destroyingItem(child.item); remove(0, children.count()); } @@ -226,12 +246,13 @@ QQmlObjectModel::QQmlObjectModel(QObject *parent) QQmlListProperty QQmlObjectModel::children() { Q_D(QQmlObjectModel); - return QQmlListProperty(this, - d, - d->children_append, - d->children_count, - d->children_at, - d->children_clear); + return QQmlListProperty(this, d, + QQmlObjectModelPrivate::children_append, + QQmlObjectModelPrivate::children_count, + QQmlObjectModelPrivate::children_at, + QQmlObjectModelPrivate::children_clear, + QQmlObjectModelPrivate::children_replace, + QQmlObjectModelPrivate::children_removeLast); } /*! diff --git a/src/qmlmodels/qquickpackage.cpp b/src/qmlmodels/qquickpackage.cpp index 567381e5ab..42e7d0e09f 100644 --- a/src/qmlmodels/qquickpackage.cpp +++ b/src/qmlmodels/qquickpackage.cpp @@ -115,6 +115,14 @@ public: QList *list = static_cast *>(prop->data); return list->count(); } + static void data_replace(QQmlListProperty *prop, int index, QObject *o) { + QList *list = static_cast *>(prop->data); + list->replace(index, DataGuard(o, list)); + } + static void data_removeLast(QQmlListProperty *prop) { + QList *list = static_cast *>(prop->data); + list->removeLast(); + } }; QHash QQuickPackageAttached::attached; @@ -152,10 +160,13 @@ QQuickPackage::~QQuickPackage() QQmlListProperty QQuickPackage::data() { Q_D(QQuickPackage); - return QQmlListProperty(this, &d->dataList, QQuickPackagePrivate::data_append, - QQuickPackagePrivate::data_count, - QQuickPackagePrivate::data_at, - QQuickPackagePrivate::data_clear); + return QQmlListProperty(this, &d->dataList, + QQuickPackagePrivate::data_append, + QQuickPackagePrivate::data_count, + QQuickPackagePrivate::data_at, + QQuickPackagePrivate::data_clear, + QQuickPackagePrivate::data_replace, + QQuickPackagePrivate::data_removeLast); } bool QQuickPackage::hasPart(const QString &name) diff --git a/src/quick/items/qquickspriteengine_p.h b/src/quick/items/qquickspriteengine_p.h index d76055c831..5ad33389de 100644 --- a/src/quick/items/qquickspriteengine_p.h +++ b/src/quick/items/qquickspriteengine_p.h @@ -330,6 +330,18 @@ inline int spriteCount(QQmlListProperty *p) return reinterpret_cast *>(p->data)->count(); } +inline void spriteReplace(QQmlListProperty *p, int idx, QQuickSprite *s) +{ + reinterpret_cast *>(p->data)->replace(idx, s); + p->object->metaObject()->invokeMethod(p->object, "createEngine"); +} + +inline void spriteRemoveLast(QQmlListProperty *p) +{ + reinterpret_cast *>(p->data)->removeLast(); + p->object->metaObject()->invokeMethod(p->object, "createEngine"); +} + QT_END_NAMESPACE #endif // QQUICKSPRITEENGINE_P_H diff --git a/src/quick/items/qquickspritesequence.cpp b/src/quick/items/qquickspritesequence.cpp index eb4b5335e7..c29938a1bb 100644 --- a/src/quick/items/qquickspritesequence.cpp +++ b/src/quick/items/qquickspritesequence.cpp @@ -162,7 +162,9 @@ void QQuickSpriteSequence::setInterpolate(bool arg) QQmlListProperty QQuickSpriteSequence::sprites() { Q_D(QQuickSpriteSequence); - return QQmlListProperty(this, &d->m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear); + return QQmlListProperty(this, &d->m_sprites, + spriteAppend, spriteCount, spriteAt, + spriteClear, spriteReplace, spriteRemoveLast); } bool QQuickSpriteSequence::running() const diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 9ab3f2d8c2..6c63b83511 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -682,10 +682,13 @@ void QQuickWindow::handleApplicationStateChanged(Qt::ApplicationState state) QQmlListProperty QQuickWindowPrivate::data() { - return QQmlListProperty(q_func(), nullptr, QQuickWindowPrivate::data_append, - QQuickWindowPrivate::data_count, - QQuickWindowPrivate::data_at, - QQuickWindowPrivate::data_clear); + return QQmlListProperty(q_func(), nullptr, + QQuickWindowPrivate::data_append, + QQuickWindowPrivate::data_count, + QQuickWindowPrivate::data_at, + QQuickWindowPrivate::data_clear, + QQuickWindowPrivate::data_replace, + QQuickWindowPrivate::data_removeLast); } static QMouseEvent *touchToMouseEvent(QEvent::Type type, const QTouchEvent::TouchPoint &p, QTouchEvent *event, QQuickItem *item, bool transformNeeded = true) @@ -3257,6 +3260,20 @@ void QQuickWindowPrivate::data_clear(QQmlListProperty *property) itemProperty.clear(&itemProperty); } +void QQuickWindowPrivate::data_replace(QQmlListProperty *property, int i, QObject *o) +{ + QQuickWindow *win = static_cast(property->object); + QQmlListProperty itemProperty = QQuickItemPrivate::get(win->contentItem())->data(); + itemProperty.replace(&itemProperty, i, o); +} + +void QQuickWindowPrivate::data_removeLast(QQmlListProperty *property) +{ + QQuickWindow *win = static_cast(property->object); + QQmlListProperty itemProperty = QQuickItemPrivate::get(win->contentItem())->data(); + itemProperty.removeLast(&itemProperty); +} + bool QQuickWindowPrivate::isRenderable() const { Q_Q(const QQuickWindow); diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index 6e6dc7a400..86bdaf6396 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -299,6 +299,8 @@ public: static int data_count(QQmlListProperty *); static QObject *data_at(QQmlListProperty *, int); static void data_clear(QQmlListProperty *); + static void data_replace(QQmlListProperty *, int, QObject *); + static void data_removeLast(QQmlListProperty *); static void contextCreationFailureMessage(const QSurfaceFormat &format, QString *translatedMessage, diff --git a/src/quick/util/qquickstate.cpp b/src/quick/util/qquickstate.cpp index c106528f45..71ab1f4d62 100644 --- a/src/quick/util/qquickstate.cpp +++ b/src/quick/util/qquickstate.cpp @@ -267,9 +267,13 @@ void QQuickState::setExtends(const QString &extends) QQmlListProperty QQuickState::changes() { Q_D(QQuickState); - return QQmlListProperty(this, &d->operations, QQuickStatePrivate::operations_append, - QQuickStatePrivate::operations_count, QQuickStatePrivate::operations_at, - QQuickStatePrivate::operations_clear); + return QQmlListProperty(this, &d->operations, + QQuickStatePrivate::operations_append, + QQuickStatePrivate::operations_count, + QQuickStatePrivate::operations_at, + QQuickStatePrivate::operations_clear, + QQuickStatePrivate::operations_replace, + QQuickStatePrivate::operations_removeLast); } int QQuickState::operationCount() const diff --git a/src/quick/util/qquickstate_p_p.h b/src/quick/util/qquickstate_p_p.h index 2fa5321165..ae4ed291b5 100644 --- a/src/quick/util/qquickstate_p_p.h +++ b/src/quick/util/qquickstate_p_p.h @@ -244,6 +244,23 @@ public: QList *list = static_cast *>(prop->data); return list->at(index); } + static void operations_replace(QQmlListProperty *prop, int index, + QQuickStateOperation *op) { + QList *list = static_cast *>(prop->data); + auto &guard = list->at(index); + if (guard.object() == op) { + op->setState(qobject_cast(prop->object)); + } else { + list->at(index)->setState(nullptr); + op->setState(qobject_cast(prop->object)); + list->replace(index, OperationGuard(op, list)); + } + } + static void operations_removeLast(QQmlListProperty *prop) { + QList *list = static_cast *>(prop->data); + list->last()->setState(nullptr); + list->removeLast(); + } QQuickTransitionManager transitionManager; diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp index 46e7d62fc1..2109aafc10 100644 --- a/src/quick/util/qquickstategroup.cpp +++ b/src/quick/util/qquickstategroup.cpp @@ -70,6 +70,8 @@ public: static int count_state(QQmlListProperty *list); static QQuickState *at_state(QQmlListProperty *list, int index); static void clear_states(QQmlListProperty *list); + static void replace_states(QQmlListProperty *list, int index, QQuickState *state); + static void removeLast_states(QQmlListProperty *list); static void append_transition(QQmlListProperty *list, QQuickTransition *state); static int count_transitions(QQmlListProperty *list); @@ -163,10 +165,13 @@ QList QQuickStateGroup::states() const QQmlListProperty QQuickStateGroup::statesProperty() { Q_D(QQuickStateGroup); - return QQmlListProperty(this, &d->states, &QQuickStateGroupPrivate::append_state, - &QQuickStateGroupPrivate::count_state, - &QQuickStateGroupPrivate::at_state, - &QQuickStateGroupPrivate::clear_states); + return QQmlListProperty(this, &d->states, + &QQuickStateGroupPrivate::append_state, + &QQuickStateGroupPrivate::count_state, + &QQuickStateGroupPrivate::at_state, + &QQuickStateGroupPrivate::clear_states, + &QQuickStateGroupPrivate::replace_states, + &QQuickStateGroupPrivate::removeLast_states); } void QQuickStateGroupPrivate::append_state(QQmlListProperty *list, QQuickState *state) @@ -201,6 +206,29 @@ void QQuickStateGroupPrivate::clear_states(QQmlListProperty *list) _this->d_func()->states.clear(); } +void QQuickStateGroupPrivate::replace_states(QQmlListProperty *list, int index, QQuickState *state) +{ + auto *self = qobject_cast(list->object); + auto *d = self->d_func(); + auto *oldState = d->states.at(index); + if (oldState != state) { + oldState->setStateGroup(nullptr); + state->setStateGroup(self); + d->states.replace(index, state); + if (d->currentState == oldState->name()) + d->setCurrentStateInternal(state->name(), true); + } +} + +void QQuickStateGroupPrivate::removeLast_states(QQmlListProperty *list) +{ + auto *d = qobject_cast(list->object)->d_func(); + if (d->currentState == d->states.last()->name()) + d->setCurrentStateInternal(d->states.length() > 1 ? d->states.first()->name() : QString(), true); + d->states.last()->setStateGroup(nullptr); + d->states.removeLast(); +} + /*! \qmlproperty list QtQuick::StateGroup::transitions This property holds a list of transitions defined by the state group. -- cgit v1.2.3