From 33eb76f050b45718d87926a8ff7afc89d6201c16 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 22 Feb 2010 14:56:49 +1000 Subject: Replace QmlList* and QList* support with a single QmlListProperty type As a value type QmlListProperty doesn't consume any memory in the object. It also has a companion QmlListReference class that is part of the public API for C++ developers to interact with that also manages memory issues that existed with previous solutions (if the containing QObject was destroyed it left a dangling pointer). --- doc/src/declarative/extending-examples.qdoc | 14 +- doc/src/declarative/extending.qdoc | 2 +- doc/src/declarative/qmlmodels.qdoc | 2 +- .../extending/attached/birthdayparty.cpp | 14 +- .../declarative/extending/attached/birthdayparty.h | 8 +- examples/declarative/extending/attached/main.cpp | 4 +- .../extending/binding/birthdayparty.cpp | 14 +- .../declarative/extending/binding/birthdayparty.h | 8 +- examples/declarative/extending/binding/main.cpp | 4 +- .../extending/coercion/birthdayparty.cpp | 14 +- .../declarative/extending/coercion/birthdayparty.h | 8 +- examples/declarative/extending/coercion/main.cpp | 5 +- .../extending/default/birthdayparty.cpp | 14 +- .../declarative/extending/default/birthdayparty.h | 8 +- examples/declarative/extending/default/main.cpp | 5 +- .../extending/grouped/birthdayparty.cpp | 14 +- .../declarative/extending/grouped/birthdayparty.h | 8 +- examples/declarative/extending/grouped/main.cpp | 4 +- .../extending/properties/birthdayparty.cpp | 14 +- .../extending/properties/birthdayparty.h | 8 +- examples/declarative/extending/properties/main.cpp | 4 +- .../declarative/extending/signal/birthdayparty.cpp | 14 +- .../declarative/extending/signal/birthdayparty.h | 8 +- examples/declarative/extending/signal/main.cpp | 4 +- .../extending/valuesource/birthdayparty.cpp | 14 +- .../extending/valuesource/birthdayparty.h | 9 +- .../declarative/extending/valuesource/main.cpp | 4 +- examples/declarative/objectlistmodel/main.cpp | 2 +- .../graphicsitems/qmlgraphicsflickable.cpp | 41 +- .../graphicsitems/qmlgraphicsflickable_p.h | 8 +- .../graphicsitems/qmlgraphicsflickable_p_p.h | 10 +- .../graphicsitems/qmlgraphicsflipable.cpp | 4 +- src/declarative/graphicsitems/qmlgraphicsitem.cpp | 188 +++----- src/declarative/graphicsitems/qmlgraphicsitem.h | 24 +- src/declarative/graphicsitems/qmlgraphicsitem_p.h | 45 +- src/declarative/graphicsitems/qmlgraphicspath.cpp | 4 +- src/declarative/graphicsitems/qmlgraphicspath_p.h | 4 +- .../graphicsitems/qmlgraphicsrectangle_p.h | 4 +- .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 37 +- .../graphicsitems/qmlgraphicsvisualitemmodel_p.h | 4 +- .../graphicsitems/qmlgraphicswebview.cpp | 24 +- .../graphicsitems/qmlgraphicswebview_p.h | 4 +- src/declarative/qml/qml.h | 6 +- src/declarative/qml/qml.pri | 5 +- src/declarative/qml/qmlbinding.cpp | 2 - src/declarative/qml/qmlcompiler.cpp | 103 ++-- src/declarative/qml/qmlcontext.cpp | 25 + src/declarative/qml/qmlcontext.h | 4 +- src/declarative/qml/qmlcontext_p.h | 3 + src/declarative/qml/qmlcontextscriptclass.cpp | 9 +- src/declarative/qml/qmldom.cpp | 1 - src/declarative/qml/qmlengine.cpp | 37 +- src/declarative/qml/qmlengine_p.h | 6 +- src/declarative/qml/qmlenginedebug.cpp | 10 +- src/declarative/qml/qmlexpression.cpp | 2 - src/declarative/qml/qmlinstruction.cpp | 6 - src/declarative/qml/qmlinstruction_p.h | 2 - src/declarative/qml/qmllist.cpp | 312 ++++++++++++ src/declarative/qml/qmllist.h | 140 +++--- src/declarative/qml/qmllist_p.h | 85 ++++ src/declarative/qml/qmllistscriptclass.cpp | 72 +-- src/declarative/qml/qmllistscriptclass_p.h | 5 +- src/declarative/qml/qmlmetaproperty.cpp | 92 ++-- src/declarative/qml/qmlmetaproperty.h | 1 - src/declarative/qml/qmlmetatype.cpp | 181 +------ src/declarative/qml/qmlmetatype.h | 56 +-- src/declarative/qml/qmlobjectscriptclass.cpp | 4 +- src/declarative/qml/qmlprivate.h | 177 +------ src/declarative/qml/qmlpropertycache.cpp | 2 - src/declarative/qml/qmlpropertycache_p.h | 1 - src/declarative/qml/qmlvme.cpp | 60 +-- src/declarative/qml/qmlvmemetaobject.cpp | 36 +- src/declarative/qml/qmlvmemetaobject_p.h | 31 +- src/declarative/util/qmlanimation.cpp | 42 +- src/declarative/util/qmlanimation_p.h | 20 +- src/declarative/util/qmlanimation_p_p.h | 36 +- src/declarative/util/qmllistaccessor.cpp | 134 +----- src/declarative/util/qmllistaccessor_p.h | 7 +- src/declarative/util/qmlpackage.cpp | 40 +- src/declarative/util/qmlpackage_p.h | 4 +- src/declarative/util/qmlstate.cpp | 20 +- src/declarative/util/qmlstate_p.h | 7 +- src/declarative/util/qmlstate_p_p.h | 33 +- src/declarative/util/qmlstategroup.cpp | 53 ++- src/declarative/util/qmlstategroup_p.h | 8 +- src/declarative/util/qmltransition.cpp | 30 +- src/declarative/util/qmltransition_p.h | 4 +- src/declarative/util/qmlxmllistmodel.cpp | 77 ++- src/declarative/util/qmlxmllistmodel_p.h | 4 +- src/declarative/widgets/graphicslayouts.cpp | 4 +- src/declarative/widgets/graphicslayouts_p.h | 83 ++-- src/declarative/widgets/graphicswidgets.cpp | 72 +-- tests/auto/declarative/declarative.pro | 1 - .../qmlecmascript/data/listProperties.qml | 21 +- tests/auto/declarative/qmlecmascript/testtypes.h | 11 +- .../qmlecmascript/tst_qmlecmascript.cpp | 13 +- .../tst_qmlgraphicspathview.cpp | 14 +- .../tst_qmlgraphicsrepeater.cpp | 8 +- .../qmlinstruction/tst_qmlinstruction.cpp | 42 +- .../qmllanguage/data/interfaceQmlList.qml | 7 - .../qmllanguage/data/listAssignment.1.errors.txt | 1 - .../qmllanguage/data/listAssignment.1.qml | 4 - tests/auto/declarative/qmllanguage/testtypes.h | 21 +- .../declarative/qmllanguage/tst_qmllanguage.cpp | 47 +- tests/auto/declarative/qmllist/data/MyType.qml | 5 + .../auto/declarative/qmllist/data/engineTypes.qml | 9 + .../declarative/qmllist/data/variantToList.qml | 10 + tests/auto/declarative/qmllist/tst_qmllist.cpp | 528 ++++++++++++++++++++- .../qmllistaccessor/qmllistaccessor.pro | 5 - .../qmllistaccessor/tst_qmllistaccessor.cpp | 452 ------------------ .../qmlmetaproperty/tst_qmlmetaproperty.cpp | 35 +- .../declarative/qmlmetatype/tst_qmlmetatype.cpp | 81 +--- tests/auto/declarative/qmlstates/tst_qmlstates.cpp | 48 +- 113 files changed, 1931 insertions(+), 2218 deletions(-) create mode 100644 src/declarative/qml/qmllist.cpp create mode 100644 src/declarative/qml/qmllist_p.h delete mode 100644 tests/auto/declarative/qmllanguage/data/interfaceQmlList.qml delete mode 100644 tests/auto/declarative/qmllanguage/data/listAssignment.1.errors.txt delete mode 100644 tests/auto/declarative/qmllanguage/data/listAssignment.1.qml create mode 100644 tests/auto/declarative/qmllist/data/MyType.qml create mode 100644 tests/auto/declarative/qmllist/data/engineTypes.qml create mode 100644 tests/auto/declarative/qmllist/data/variantToList.qml delete mode 100644 tests/auto/declarative/qmllistaccessor/qmllistaccessor.pro delete mode 100644 tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp diff --git a/doc/src/declarative/extending-examples.qdoc b/doc/src/declarative/extending-examples.qdoc index e92fa04..cce3e08 100644 --- a/doc/src/declarative/extending-examples.qdoc +++ b/doc/src/declarative/extending-examples.qdoc @@ -105,15 +105,15 @@ The BirthdayParty class is declared like this: \snippet examples/declarative/extending/properties/birthdayparty.h 3 The class contains a member to store the celebrant object, and also a -QmlConcreteList member. +QList member. In QML, the type of a list properties - and the guests property is a list of -people - are all of type QmlList*. QmlList is an abstract list interface -that allows a developer to react to QML accessing and modifying the contents of -the list. This is useful for implementing "virtual lists" or other advanced -scenarios, but can't be used directly for the common case of just wanting a -regular list of things. For this a concrete implementation, QmlConcreteList, is -provided and that is used here. +people - are all of type QmlListProperty. QmlListProperty is simple value +type that contains a set of function pointers. QML calls these function +pointers whenever it needs to read from, write to or otherwise interact with +the list. In addition to concrete lists like the people list used in this +example, the use of QmlListProperty allows for "virtual lists" and other advanced +scenarios. \section2 Define the BirthdayParty diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index c75c22e..1307ea9 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -169,7 +169,7 @@ for assignment to appropriately typed properties. The guests property is a list of \c Person objects. Properties that are lists of objects or Qt interfaces are also declared with the Q_PROPERTY() macro, just -like other properties. List properties must have the type \c {QmlList*}. +like other properties. List properties must have the type \c {QmlListProperty}. As with object properties, the type \a T must be registered with QML. The guest property declaration looks like this: diff --git a/doc/src/declarative/qmlmodels.qdoc b/doc/src/declarative/qmlmodels.qdoc index c898c07..39119e5 100644 --- a/doc/src/declarative/qmlmodels.qdoc +++ b/doc/src/declarative/qmlmodels.qdoc @@ -258,7 +258,7 @@ dataList.append(new DataObject("Item 3", "blue")); dataList.append(new DataObject("Item 4", "yellow")); QmlContext *ctxt = view.rootContext(); -ctxt->setContextProperty("myModel", QVariant::fromValue(&dataList)); +ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); \endcode The properties of the object may then be accessed in the delegate: diff --git a/examples/declarative/extending/attached/birthdayparty.cpp b/examples/declarative/extending/attached/birthdayparty.cpp index 9dc13de..ffdda57 100644 --- a/examples/declarative/extending/attached/birthdayparty.cpp +++ b/examples/declarative/extending/attached/birthdayparty.cpp @@ -72,9 +72,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList *BirthdayParty::guests() +QmlListProperty BirthdayParty::guests() { - return &m_guests; + return QmlListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) diff --git a/examples/declarative/extending/attached/birthdayparty.h b/examples/declarative/extending/attached/birthdayparty.h index bd8952b..9ba0f8b 100644 --- a/examples/declarative/extending/attached/birthdayparty.h +++ b/examples/declarative/extending/attached/birthdayparty.h @@ -65,7 +65,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList *guests READ guests) +Q_PROPERTY(QmlListProperty guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); @@ -73,12 +73,14 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList *guests(); + QmlListProperty guests(); + int guestCount() const; + Person *guest(int) const; static BirthdayPartyAttached *qmlAttachedProperties(QObject *); private: Person *m_celebrant; - QmlConcreteList m_guests; + QList m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/attached/main.cpp b/examples/declarative/extending/attached/main.cpp index 2ec783f..27a9287 100644 --- a/examples/declarative/extending/attached/main.cpp +++ b/examples/declarative/extending/attached/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char ** argv) else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); QDate rsvpDate; QObject *attached = diff --git a/examples/declarative/extending/binding/birthdayparty.cpp b/examples/declarative/extending/binding/birthdayparty.cpp index 8a409af..62b9c7b 100644 --- a/examples/declarative/extending/binding/birthdayparty.cpp +++ b/examples/declarative/extending/binding/birthdayparty.cpp @@ -77,9 +77,19 @@ void BirthdayParty::setCelebrant(Person *c) emit celebrantChanged(); } -QmlList *BirthdayParty::guests() +QmlListProperty BirthdayParty::guests() { - return &m_guests; + return QmlListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } void BirthdayParty::startParty() diff --git a/examples/declarative/extending/binding/birthdayparty.h b/examples/declarative/extending/binding/birthdayparty.h index 5651c65..8bdb76a 100644 --- a/examples/declarative/extending/binding/birthdayparty.h +++ b/examples/declarative/extending/binding/birthdayparty.h @@ -71,7 +71,7 @@ Q_OBJECT // ![0] Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant NOTIFY celebrantChanged) // ![0] -Q_PROPERTY(QmlList *guests READ guests) +Q_PROPERTY(QmlListProperty guests READ guests) Q_PROPERTY(QString speaker READ speaker WRITE setSpeaker) Q_CLASSINFO("DefaultProperty", "guests") public: @@ -80,7 +80,9 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList *guests(); + QmlListProperty guests(); + int guestCount() const; + Person *guest(int) const; QString speaker() const; void setSpeaker(const QString &); @@ -94,7 +96,7 @@ signals: private: Person *m_celebrant; - QmlConcreteList m_guests; + QList m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/binding/main.cpp b/examples/declarative/extending/binding/main.cpp index 4ad9929..ba38e82 100644 --- a/examples/declarative/extending/binding/main.cpp +++ b/examples/declarative/extending/binding/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char ** argv) else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); QDate rsvpDate; QObject *attached = diff --git a/examples/declarative/extending/coercion/birthdayparty.cpp b/examples/declarative/extending/coercion/birthdayparty.cpp index 014d307..15a4ca9 100644 --- a/examples/declarative/extending/coercion/birthdayparty.cpp +++ b/examples/declarative/extending/coercion/birthdayparty.cpp @@ -55,9 +55,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList *BirthdayParty::guests() +QmlListProperty BirthdayParty::guests() { - return &m_guests; + return QmlListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty); diff --git a/examples/declarative/extending/coercion/birthdayparty.h b/examples/declarative/extending/coercion/birthdayparty.h index 8563ec3..5a9eb08 100644 --- a/examples/declarative/extending/coercion/birthdayparty.h +++ b/examples/declarative/extending/coercion/birthdayparty.h @@ -50,7 +50,7 @@ class BirthdayParty : public QObject Q_OBJECT // ![0] Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList *guests READ guests) +Q_PROPERTY(QmlListProperty guests READ guests) // ![0] public: BirthdayParty(QObject *parent = 0); @@ -58,11 +58,13 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList *guests(); + QmlListProperty guests(); + int guestCount() const; + Person *guest(int) const; private: Person *m_celebrant; - QmlConcreteList m_guests; + QList m_guests; }; QML_DECLARE_TYPE(BirthdayParty); diff --git a/examples/declarative/extending/coercion/main.cpp b/examples/declarative/extending/coercion/main.cpp index c6cc847..ccbee83 100644 --- a/examples/declarative/extending/coercion/main.cpp +++ b/examples/declarative/extending/coercion/main.cpp @@ -60,8 +60,9 @@ int main(int argc, char ** argv) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) - qWarning() << " " << party->guests()->at(ii)->name(); + + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); } else { qWarning() << "An error occured"; } diff --git a/examples/declarative/extending/default/birthdayparty.cpp b/examples/declarative/extending/default/birthdayparty.cpp index 014d307..15a4ca9 100644 --- a/examples/declarative/extending/default/birthdayparty.cpp +++ b/examples/declarative/extending/default/birthdayparty.cpp @@ -55,9 +55,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList *BirthdayParty::guests() +QmlListProperty BirthdayParty::guests() { - return &m_guests; + return QmlListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty); diff --git a/examples/declarative/extending/default/birthdayparty.h b/examples/declarative/extending/default/birthdayparty.h index 869b32c..f25f8c2 100644 --- a/examples/declarative/extending/default/birthdayparty.h +++ b/examples/declarative/extending/default/birthdayparty.h @@ -50,7 +50,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList *guests READ guests) +Q_PROPERTY(QmlListProperty guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); @@ -58,11 +58,13 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList *guests(); + QmlListProperty guests(); + int guestCount() const; + Person *guest(int) const; private: Person *m_celebrant; - QmlConcreteList m_guests; + QList m_guests; }; // ![0] QML_DECLARE_TYPE(BirthdayParty); diff --git a/examples/declarative/extending/default/main.cpp b/examples/declarative/extending/default/main.cpp index c6cc847..ccbee83 100644 --- a/examples/declarative/extending/default/main.cpp +++ b/examples/declarative/extending/default/main.cpp @@ -60,8 +60,9 @@ int main(int argc, char ** argv) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) - qWarning() << " " << party->guests()->at(ii)->name(); + + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); } else { qWarning() << "An error occured"; } diff --git a/examples/declarative/extending/grouped/birthdayparty.cpp b/examples/declarative/extending/grouped/birthdayparty.cpp index 014d307..15a4ca9 100644 --- a/examples/declarative/extending/grouped/birthdayparty.cpp +++ b/examples/declarative/extending/grouped/birthdayparty.cpp @@ -55,9 +55,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList *BirthdayParty::guests() +QmlListProperty BirthdayParty::guests() { - return &m_guests; + return QmlListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty); diff --git a/examples/declarative/extending/grouped/birthdayparty.h b/examples/declarative/extending/grouped/birthdayparty.h index 3f4a3a6..fd0d955 100644 --- a/examples/declarative/extending/grouped/birthdayparty.h +++ b/examples/declarative/extending/grouped/birthdayparty.h @@ -49,7 +49,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList *guests READ guests) +Q_PROPERTY(QmlListProperty guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); @@ -57,11 +57,13 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList *guests(); + QmlListProperty guests(); + int guestCount() const; + Person *guest(int) const; private: Person *m_celebrant; - QmlConcreteList m_guests; + QList m_guests; }; QML_DECLARE_TYPE(BirthdayParty); diff --git a/examples/declarative/extending/grouped/main.cpp b/examples/declarative/extending/grouped/main.cpp index 23ba8bf..79aaab5 100644 --- a/examples/declarative/extending/grouped/main.cpp +++ b/examples/declarative/extending/grouped/main.cpp @@ -62,8 +62,8 @@ int main(int argc, char ** argv) qWarning() << "She is inviting:"; Person *bestShoe = 0; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); qWarning() << " " << guest->name(); if (!bestShoe || bestShoe->shoe()->price() < guest->shoe()->price()) diff --git a/examples/declarative/extending/properties/birthdayparty.cpp b/examples/declarative/extending/properties/birthdayparty.cpp index 332b090..23e6e58 100644 --- a/examples/declarative/extending/properties/birthdayparty.cpp +++ b/examples/declarative/extending/properties/birthdayparty.cpp @@ -56,9 +56,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList *BirthdayParty::guests() +QmlListProperty BirthdayParty::guests() { - return &m_guests; + return QmlListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } // ![0] diff --git a/examples/declarative/extending/properties/birthdayparty.h b/examples/declarative/extending/properties/birthdayparty.h index ceefd5b..e5d316c 100644 --- a/examples/declarative/extending/properties/birthdayparty.h +++ b/examples/declarative/extending/properties/birthdayparty.h @@ -54,7 +54,7 @@ Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) // ![1] // ![2] -Q_PROPERTY(QmlList *guests READ guests) +Q_PROPERTY(QmlListProperty guests READ guests) // ![2] // ![3] public: @@ -63,11 +63,13 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList *guests(); + QmlListProperty guests(); + int guestCount() const; + Person *guest(int) const; private: Person *m_celebrant; - QmlConcreteList m_guests; + QList m_guests; }; QML_DECLARE_TYPE(BirthdayParty); // ![3] diff --git a/examples/declarative/extending/properties/main.cpp b/examples/declarative/extending/properties/main.cpp index 229e59a..97d7905 100644 --- a/examples/declarative/extending/properties/main.cpp +++ b/examples/declarative/extending/properties/main.cpp @@ -56,8 +56,8 @@ int main(int argc, char ** argv) if (party && party->celebrant()) { qWarning() << party->celebrant()->name() << "is having a birthday!"; qWarning() << "They are inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) - qWarning() << " " << party->guests()->at(ii)->name(); + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); } else { qWarning() << "An error occured"; } diff --git a/examples/declarative/extending/signal/birthdayparty.cpp b/examples/declarative/extending/signal/birthdayparty.cpp index 88c5459..d8686f0 100644 --- a/examples/declarative/extending/signal/birthdayparty.cpp +++ b/examples/declarative/extending/signal/birthdayparty.cpp @@ -72,9 +72,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList *BirthdayParty::guests() +QmlListProperty BirthdayParty::guests() { - return &m_guests; + return QmlListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } void BirthdayParty::startParty() diff --git a/examples/declarative/extending/signal/birthdayparty.h b/examples/declarative/extending/signal/birthdayparty.h index 8ce5d7b..30ed43b 100644 --- a/examples/declarative/extending/signal/birthdayparty.h +++ b/examples/declarative/extending/signal/birthdayparty.h @@ -65,7 +65,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList *guests READ guests) +Q_PROPERTY(QmlListProperty guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); @@ -73,7 +73,9 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList *guests(); + QmlListProperty guests(); + int guestCount() const; + Person *guest(int) const; static BirthdayPartyAttached *qmlAttachedProperties(QObject *); @@ -85,7 +87,7 @@ signals: private: Person *m_celebrant; - QmlConcreteList m_guests; + QList m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/signal/main.cpp b/examples/declarative/extending/signal/main.cpp index 4e981c5..eb3bb4b 100644 --- a/examples/declarative/extending/signal/main.cpp +++ b/examples/declarative/extending/signal/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char ** argv) else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); QDate rsvpDate; QObject *attached = diff --git a/examples/declarative/extending/valuesource/birthdayparty.cpp b/examples/declarative/extending/valuesource/birthdayparty.cpp index b483f68..a5b3fab 100644 --- a/examples/declarative/extending/valuesource/birthdayparty.cpp +++ b/examples/declarative/extending/valuesource/birthdayparty.cpp @@ -72,9 +72,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList *BirthdayParty::guests() +QmlListProperty BirthdayParty::guests() { - return &m_guests; + return QmlListProperty(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } void BirthdayParty::startParty() diff --git a/examples/declarative/extending/valuesource/birthdayparty.h b/examples/declarative/extending/valuesource/birthdayparty.h index e7ca461..b5a0522 100644 --- a/examples/declarative/extending/valuesource/birthdayparty.h +++ b/examples/declarative/extending/valuesource/birthdayparty.h @@ -66,7 +66,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList *guests READ guests) +Q_PROPERTY(QmlListProperty guests READ guests) // ![0] Q_PROPERTY(QString speaker READ speaker WRITE setSpeaker) // ![0] @@ -77,7 +77,10 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList *guests(); + QmlListProperty guests(); + int guestCount() const; + Person *guest(int) const; + QString speaker() const; void setSpeaker(const QString &); @@ -90,7 +93,7 @@ signals: private: Person *m_celebrant; - QmlConcreteList m_guests; + QList m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/valuesource/main.cpp b/examples/declarative/extending/valuesource/main.cpp index 4ad9929..ba38e82 100644 --- a/examples/declarative/extending/valuesource/main.cpp +++ b/examples/declarative/extending/valuesource/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char ** argv) else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); QDate rsvpDate; QObject *attached = diff --git a/examples/declarative/objectlistmodel/main.cpp b/examples/declarative/objectlistmodel/main.cpp index 5eb6b7d..9e38bea 100644 --- a/examples/declarative/objectlistmodel/main.cpp +++ b/examples/declarative/objectlistmodel/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char ** argv) dataList.append(new DataObject("Item 4", "yellow")); QmlContext *ctxt = view.rootContext(); - ctxt->setContextProperty("myModel", QVariant::fromValue(&dataList)); + ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); view.execute(); view.show(); diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index bfee8d4..e92fea4 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -945,51 +945,22 @@ void QmlGraphicsFlickable::cancelFlick() movementEnding(); } -void QmlGraphicsFlickablePrivate::data_removeAt(int) +void QmlGraphicsFlickablePrivate::data_append(QmlListProperty *prop, QObject *o) { - // ### -} - -int QmlGraphicsFlickablePrivate::data_count() const -{ - // ### - return 0; -} - -void QmlGraphicsFlickablePrivate::data_append(QObject *o) -{ - Q_Q(QmlGraphicsFlickable); QmlGraphicsItem *i = qobject_cast(o); if (i) - viewport->fxChildren()->append(i); + i->setParentItem(static_cast(prop->data)->viewport); else - o->setParent(q); + o->setParent(prop->object); } -void QmlGraphicsFlickablePrivate::data_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsFlickablePrivate::data_at(int) const -{ - // ### - return 0; -} - -void QmlGraphicsFlickablePrivate::data_clear() -{ - // ### -} - - -QmlList *QmlGraphicsFlickable::flickableData() +QmlListProperty QmlGraphicsFlickable::flickableData() { Q_D(QmlGraphicsFlickable); - return &d->data; + return QmlListProperty(this, (void *)d, QmlGraphicsFlickablePrivate::data_append); } -QmlList *QmlGraphicsFlickable::flickableChildren() +QmlListProperty QmlGraphicsFlickable::flickableChildren() { Q_D(QmlGraphicsFlickable); return d->viewport->fxChildren(); diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable_p.h b/src/declarative/graphicsitems/qmlgraphicsflickable_p.h index 373815b..580d01e 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsflickable_p.h @@ -82,8 +82,8 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem Q_PROPERTY(QmlGraphicsFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) - Q_PROPERTY(QmlList* flickableData READ flickableData) - Q_PROPERTY(QmlList* flickableChildren READ flickableChildren) + Q_PROPERTY(QmlListProperty flickableData READ flickableData) + Q_PROPERTY(QmlListProperty flickableChildren READ flickableChildren) Q_CLASSINFO("DefaultProperty", "flickableData") Q_ENUMS(FlickDirection) @@ -92,8 +92,8 @@ public: QmlGraphicsFlickable(QmlGraphicsItem *parent=0); ~QmlGraphicsFlickable(); - QmlList *flickableData(); - QmlList *flickableChildren(); + QmlListProperty flickableData(); + QmlListProperty flickableChildren(); bool overShoot() const; void setOverShoot(bool); diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h b/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h index a76ee8a..e58cc0c 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h @@ -149,15 +149,7 @@ public: void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *); // flickableData property - void data_removeAt(int); - int data_count() const; - void data_append(QObject *); - void data_insert(int, QObject *); - QObject *data_at(int) const; - void data_clear(); - - friend class QmlGraphicsFlickableVisibleArea; - QML_DECLARE_LIST_PROXY(QmlGraphicsFlickablePrivate, QObject *, data) + static void data_append(QmlListProperty *, QObject *); }; class QmlGraphicsFlickableVisibleArea : public QObject diff --git a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp index f5abc18..5bab868 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflipable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflipable.cpp @@ -149,7 +149,7 @@ void QmlGraphicsFlipable::setFront(QmlGraphicsItem *front) return; } d->front = front; - fxChildren()->append(d->front); + d->front->setParentItem(this); if (Back == d->current) d->front->setOpacity(0.); } @@ -168,7 +168,7 @@ void QmlGraphicsFlipable::setBack(QmlGraphicsItem *back) return; } d->back = back; - fxChildren()->append(d->back); + d->back->setParentItem(this); if (Front == d->current) d->back->setOpacity(0.); } diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 22beb12..2e68264 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -892,7 +892,6 @@ void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event) parameter provides information about the event. */ - const QmlGraphicsKeysAttached::SigMap QmlGraphicsKeysAttached::sigMap[] = { { Qt::Key_Left, "leftPressed" }, { Qt::Key_Right, "rightPressed" }, @@ -1420,154 +1419,95 @@ QmlGraphicsAnchors *QmlGraphicsItem::anchors() return d->anchors(); } -void QmlGraphicsItemPrivate::data_removeAt(int) -{ - // ### -} - -int QmlGraphicsItemPrivate::data_count() const +void QmlGraphicsItemPrivate::data_append(QmlListProperty *prop, QObject *o) { - // ### - return 0; -} - -void QmlGraphicsItemPrivate::data_append(QObject *o) -{ - Q_Q(QmlGraphicsItem); QmlGraphicsItem *i = qobject_cast(o); - if (i) - q->fxChildren()->append(i); + if (i) + i->setParentItem(static_cast(prop->object)); else - resources_append(o); -} - -void QmlGraphicsItemPrivate::data_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsItemPrivate::data_at(int) const -{ - // ### - return 0; + o->setParent(static_cast(prop->object)); } -void QmlGraphicsItemPrivate::data_clear() +QObject *QmlGraphicsItemPrivate::resources_at(QmlListProperty *prop, int index) { - // ### -} - -void QmlGraphicsItemPrivate::resources_removeAt(int) -{ - // ### -} - -int QmlGraphicsItemPrivate::resources_count() const -{ - Q_Q(const QmlGraphicsItem); - return q->children().count(); -} - -void QmlGraphicsItemPrivate::resources_append(QObject *o) -{ - Q_Q(QmlGraphicsItem); - o->setParent(q); -} - -void QmlGraphicsItemPrivate::resources_insert(int, QObject *) -{ - // ### -} - -QObject *QmlGraphicsItemPrivate::resources_at(int idx) const -{ - Q_Q(const QmlGraphicsItem); - QObjectList children = q->children(); - if (idx < children.count()) - return children.at(idx); + QObjectList children = prop->object->children(); + if (index < children.count()) + return children.at(index); else return 0; } -void QmlGraphicsItemPrivate::resources_clear() +void QmlGraphicsItemPrivate::resources_append(QmlListProperty *prop, QObject *o) { - // ### + o->setParent(prop->object); } -void QmlGraphicsItemPrivate::children_removeAt(int) +int QmlGraphicsItemPrivate::resources_count(QmlListProperty *prop) { - // ### + return prop->object->children().count(); } -int QmlGraphicsItemPrivate::children_count() const +QmlGraphicsItem *QmlGraphicsItemPrivate::children_at(QmlListProperty *prop, int index) { - Q_Q(const QmlGraphicsItem); - return q->childItems().count(); -} + QList children = static_cast(prop->object)->childItems(); -void QmlGraphicsItemPrivate::children_append(QmlGraphicsItem *i) -{ - Q_Q(QmlGraphicsItem); - i->setParentItem(q); -} - -void QmlGraphicsItemPrivate::children_insert(int, QmlGraphicsItem *) -{ - // ### -} - -QmlGraphicsItem *QmlGraphicsItemPrivate::children_at(int idx) const -{ - Q_Q(const QmlGraphicsItem); - QList children = q->childItems(); - if (idx < children.count()) - return qobject_cast(children.at(idx)); + if (index < children.count()) + return qobject_cast(children.at(index)); else return 0; } -void QmlGraphicsItemPrivate::children_clear() +void QmlGraphicsItemPrivate::children_append(QmlListProperty *prop, QmlGraphicsItem *i) { - // ### -} - - -void QmlGraphicsItemPrivate::transform_removeAt(int i) -{ - if (!transformData) - return; - transformData->graphicsTransforms.removeAt(i); - dirtySceneTransform = 1; + if (i) + i->setParentItem(static_cast(prop->object)); } -int QmlGraphicsItemPrivate::transform_count() const +int QmlGraphicsItemPrivate::children_count(QmlListProperty *prop) { - return transformData ? transformData->graphicsTransforms.size() : 0; + return static_cast(prop->object)->childItems().count(); } -void QmlGraphicsItemPrivate::transform_append(QGraphicsTransform *item) +int QmlGraphicsItemPrivate::transform_count(QmlListProperty *list) { - appendGraphicsTransform(item); + QGraphicsObject *object = qobject_cast(list->object); + if (object) { + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object); + return d->transformData ? d->transformData->graphicsTransforms.size() : 0; + } else { + return 0; + } } -void QmlGraphicsItemPrivate::transform_insert(int, QGraphicsTransform *) +void QmlGraphicsItemPrivate::transform_append(QmlListProperty *list, QGraphicsTransform *item) { - // ### + QGraphicsObject *object = qobject_cast(list->object); + if (object) + QGraphicsItemPrivate::get(object)->appendGraphicsTransform(item); } -QGraphicsTransform *QmlGraphicsItemPrivate::transform_at(int idx) const +QGraphicsTransform *QmlGraphicsItemPrivate::transform_at(QmlListProperty *list, int idx) { - if (!transformData) + QGraphicsObject *object = qobject_cast(list->object); + if (object) { + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object); + if (!d->transformData) + return 0; + return d->transformData->graphicsTransforms.at(idx); + } else { return 0; - return transformData->graphicsTransforms.at(idx); + } } -void QmlGraphicsItemPrivate::transform_clear() +void QmlGraphicsItemPrivate::transform_clear(QmlListProperty *list) { - if (!transformData) - return; - Q_Q(QmlGraphicsItem); - q->setTransformations(QList()); + QGraphicsObject *object = qobject_cast(list->object); + if (object) { + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(object); + if (!d->transformData) + return; + object->setTransformations(QList()); + } } /*! @@ -1610,10 +1550,9 @@ void QmlGraphicsItemPrivate::transform_clear() */ /*! \internal */ -QmlList *QmlGraphicsItem::data() +QmlListProperty QmlGraphicsItem::data() { - Q_D(QmlGraphicsItem); - return &d->data; + return QmlListProperty(this, 0, QmlGraphicsItemPrivate::data_append); } /*! @@ -2215,17 +2154,19 @@ void QmlGraphicsItem::focusChanged(bool flag) } /*! \internal */ -QmlList *QmlGraphicsItem::fxChildren() +QmlListProperty QmlGraphicsItem::fxChildren() { - Q_D(QmlGraphicsItem); - return &(d->children); + return QmlListProperty(this, 0, QmlGraphicsItemPrivate::children_append, + QmlGraphicsItemPrivate::children_count, + QmlGraphicsItemPrivate::children_at); } /*! \internal */ -QmlList *QmlGraphicsItem::resources() +QmlListProperty QmlGraphicsItem::resources() { - Q_D(QmlGraphicsItem); - return &(d->resources); + return QmlListProperty(this, 0, QmlGraphicsItemPrivate::resources_append, + QmlGraphicsItemPrivate::resources_count, + QmlGraphicsItemPrivate::resources_at); } /*! @@ -2250,7 +2191,7 @@ QmlList *QmlGraphicsItem::resources() \internal */ /*! \internal */ -QmlList* QmlGraphicsItem::states() +QmlListProperty QmlGraphicsItem::states() { Q_D(QmlGraphicsItem); return d->states()->statesProperty(); @@ -2279,7 +2220,7 @@ QmlList* QmlGraphicsItem::states() */ /*! \internal */ -QmlList* QmlGraphicsItem::transitions() +QmlListProperty QmlGraphicsItem::transitions() { Q_D(QmlGraphicsItem); return d->states()->transitionsProperty(); @@ -2387,10 +2328,11 @@ void QmlGraphicsItem::setState(const QString &state) */ /*! \internal */ -QmlList* QmlGraphicsItem::transform() +QmlListProperty QmlGraphicsItem::transform() { Q_D(QmlGraphicsItem); - return &(d->transform); + return QmlListProperty(this, 0, d->transform_append, d->transform_count, + d->transform_at, d->transform_clear); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.h b/src/declarative/graphicsitems/qmlgraphicsitem.h index e1cf035..891fc88 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem.h @@ -70,11 +70,11 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlP Q_INTERFACES(QmlParserStatus) Q_PROPERTY(QmlGraphicsItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) - Q_PROPERTY(QmlList *data READ data DESIGNABLE false) - Q_PROPERTY(QmlList* children READ fxChildren DESIGNABLE false NOTIFY childrenChanged) - Q_PROPERTY(QmlList* resources READ resources DESIGNABLE false) - Q_PROPERTY(QmlList* states READ states DESIGNABLE false) - Q_PROPERTY(QmlList* transitions READ transitions DESIGNABLE false) + Q_PROPERTY(QmlListProperty data READ data DESIGNABLE false) + Q_PROPERTY(QmlListProperty children READ fxChildren DESIGNABLE false NOTIFY childrenChanged) + Q_PROPERTY(QmlListProperty resources READ resources DESIGNABLE false) + Q_PROPERTY(QmlListProperty states READ states DESIGNABLE false) + Q_PROPERTY(QmlListProperty transitions READ transitions DESIGNABLE false) Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL) Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL) @@ -91,7 +91,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlP Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged) // ### move to QGI/QGO, NOTIFY Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) - Q_PROPERTY(QmlList* transform READ transform DESIGNABLE false FINAL) + Q_PROPERTY(QmlListProperty transform READ transform DESIGNABLE false FINAL) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged) Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect) @@ -112,9 +112,9 @@ public: void setParentItem(QmlGraphicsItem *parent); void setParent(QmlGraphicsItem *parent) { setParentItem(parent); } - QmlList *data(); - QmlList *fxChildren(); - QmlList *resources(); + QmlListProperty data(); + QmlListProperty fxChildren(); + QmlListProperty resources(); QmlGraphicsAnchors *anchors(); QRectF childrenRect(); @@ -122,8 +122,8 @@ public: bool clip() const; void setClip(bool); - QmlList* states(); - QmlList* transitions(); + QmlListProperty states(); + QmlListProperty transitions(); QString state() const; void setState(const QString &); @@ -131,7 +131,7 @@ public: qreal baselineOffset() const; void setBaselineOffset(qreal); - QmlList *transform(); + QmlListProperty transform(); qreal width() const; void setWidth(qreal); diff --git a/src/declarative/graphicsitems/qmlgraphicsitem_p.h b/src/declarative/graphicsitems/qmlgraphicsitem_p.h index 7662a3b..4860b83 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem_p.h @@ -137,40 +137,23 @@ public: QString _id; // data property - void data_removeAt(int); - int data_count() const; - void data_append(QObject *); - void data_insert(int, QObject *); - QObject *data_at(int) const; - void data_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, data) + static void data_append(QmlListProperty *, QObject *); // resources property - void resources_removeAt(int); - int resources_count() const; - void resources_append(QObject *); - void resources_insert(int, QObject *); - QObject *resources_at(int) const; - void resources_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QObject *, resources) + static QObject *resources_at(QmlListProperty *, int); + static void resources_append(QmlListProperty *, QObject *); + static int resources_count(QmlListProperty *); // children property - void children_removeAt(int); - int children_count() const; - void children_append(QmlGraphicsItem *); - void children_insert(int, QmlGraphicsItem *); - QmlGraphicsItem *children_at(int) const; - void children_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QmlGraphicsItem *, children) + static QmlGraphicsItem *children_at(QmlListProperty *, int); + static void children_append(QmlListProperty *, QmlGraphicsItem *); + static int children_count(QmlListProperty *); // transform property - void transform_removeAt(int); - int transform_count() const; - void transform_append(QGraphicsTransform *); - void transform_insert(int, QGraphicsTransform *); - QGraphicsTransform *transform_at(int) const; - void transform_clear(); - QML_DECLARE_LIST_PROXY(QmlGraphicsItemPrivate, QGraphicsTransform *, transform) + static int transform_count(QmlListProperty *list); + static void transform_append(QmlListProperty *list, QGraphicsTransform *); + static QGraphicsTransform *transform_at(QmlListProperty *list, int); + static void transform_clear(QmlListProperty *list); QmlGraphicsAnchors *anchors() { if (!_anchors) { @@ -381,7 +364,7 @@ class QmlGraphicsKeysAttached : public QObject, public QmlGraphicsItemKeyFilter Q_DECLARE_PRIVATE(QmlGraphicsKeysAttached) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QList *forwardTo READ forwardTo) + Q_PROPERTY(QmlListProperty forwardTo READ forwardTo) public: QmlGraphicsKeysAttached(QObject *parent=0); @@ -396,9 +379,9 @@ public: } } - QList *forwardTo() { + QmlListProperty forwardTo() { Q_D(QmlGraphicsKeysAttached); - return &d->targets; + return QmlListProperty(this, d->targets); } virtual void componentComplete(); diff --git a/src/declarative/graphicsitems/qmlgraphicspath.cpp b/src/declarative/graphicsitems/qmlgraphicspath.cpp index 7916bd3..4e4459d 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspath.cpp @@ -155,10 +155,10 @@ bool QmlGraphicsPath::isClosed() const \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 2 */ -QList* QmlGraphicsPath::pathElements() +QmlListProperty QmlGraphicsPath::pathElements() { Q_D(QmlGraphicsPath); - return &(d->_pathElements); + return QmlListProperty(this, d->_pathElements); } void QmlGraphicsPath::interpolate(int idx, const QString &name, qreal value) diff --git a/src/declarative/graphicsitems/qmlgraphicspath_p.h b/src/declarative/graphicsitems/qmlgraphicspath_p.h index 51b7262..7ba5bbc 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspath_p.h @@ -189,7 +189,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserSta Q_OBJECT Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QList* pathElements READ pathElements) + Q_PROPERTY(QmlListProperty pathElements READ pathElements) Q_PROPERTY(qreal startX READ startX WRITE setStartX) Q_PROPERTY(qreal startY READ startY WRITE setStartY) Q_PROPERTY(bool closed READ isClosed NOTIFY changed) @@ -199,7 +199,7 @@ public: QmlGraphicsPath(QObject *parent=0); ~QmlGraphicsPath(); - QList* pathElements(); + QmlListProperty pathElements(); qreal startX() const; void setStartX(qreal x); diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h index c566027..66552f6 100644 --- a/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h @@ -107,14 +107,14 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject { Q_OBJECT - Q_PROPERTY(QList *stops READ stops) + Q_PROPERTY(QmlListProperty stops READ stops) Q_CLASSINFO("DefaultProperty", "stops") public: QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} ~QmlGraphicsGradient() { delete m_gradient; } - QList *stops() { return &m_stops; } + QmlListProperty stops() { return QmlListProperty(this, m_stops); } const QGradient *gradient() const; diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 4ced2c3..b96f399 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -71,16 +71,14 @@ class QmlGraphicsVisualItemModelPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlGraphicsVisualItemModel) public: - QmlGraphicsVisualItemModelPrivate() : QObjectPrivate(), children(this) {} + QmlGraphicsVisualItemModelPrivate() : QObjectPrivate() {} - struct ItemList : public QmlConcreteList - { - ItemList(QmlGraphicsVisualItemModelPrivate *m) : QmlConcreteList(), model(m) {} - - void append(QmlGraphicsItem *item); - - QmlGraphicsVisualItemModelPrivate *model; - }; + static void children_append(QmlListProperty *prop, QmlGraphicsItem *item) { + item->QObject::setParent(prop->object); + static_cast(prop->data)->children.append(item); + static_cast(prop->data)->itemAppended(); + static_cast(prop->data)->emitChildrenChanged(); + } void itemAppended() { Q_Q(QmlGraphicsVisualItemModel); @@ -94,7 +92,8 @@ public: Q_Q(QmlGraphicsVisualItemModel); emit q->childrenChanged(); } - ItemList children; + + QList children; }; @@ -132,10 +131,10 @@ QmlGraphicsVisualItemModel::QmlGraphicsVisualItemModel() { } -QmlList *QmlGraphicsVisualItemModel::children() +QmlListProperty QmlGraphicsVisualItemModel::children() { Q_D(QmlGraphicsVisualItemModel); - return &(d->children); + return QmlListProperty(this, d, QmlGraphicsVisualItemModelPrivate::children_append); } /*! @@ -200,15 +199,6 @@ int QmlGraphicsVisualItemModel::indexOf(QmlGraphicsItem *item, QObject *) const return d->children.indexOf(item); } -void QmlGraphicsVisualItemModelPrivate::ItemList::append(QmlGraphicsItem *item) -{ - QmlConcreteList::append(item); - item->QObject::setParent(model->q_ptr); - model->itemAppended(); - - model->emitChildrenChanged(); -} - QmlGraphicsVisualItemModelAttached *QmlGraphicsVisualItemModel::qmlAttachedProperties(QObject *obj) { return QmlGraphicsVisualItemModelAttached::properties(obj); @@ -422,8 +412,7 @@ int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, c QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { - if (model->m_listAccessor->type() == QmlListAccessor::QmlList - || model->m_listAccessor->type() == QmlListAccessor::QListPtr) { + if (model->m_listAccessor->type() == QmlListAccessor::ListProperty) { model->ensureRoles(); QObject *object = model->m_listAccessor->at(data->m_index).value(); if (object && object->property(name).isValid()) @@ -685,7 +674,7 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) } d->m_listAccessor = new QmlListAccessor; d->m_listAccessor->setList(model, d->m_context?d->m_context->engine():qmlEngine(this)); - if (d->m_listAccessor->type() != QmlListAccessor::QmlList && d->m_listAccessor->type() != QmlListAccessor::QListPtr) + if (d->m_listAccessor->type() != QmlListAccessor::ListProperty) d->m_metaDataCacheable = true; if (d->m_delegate && d->modelCount()) { emit itemsInserted(0, d->modelCount()); diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h index c0ea499..49f9b27 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h @@ -109,7 +109,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsVisualItemModel : public QmlGraphicsVisual Q_OBJECT Q_DECLARE_PRIVATE(QmlGraphicsVisualItemModel) - Q_PROPERTY(QmlList* children READ children NOTIFY childrenChanged DESIGNABLE false) + Q_PROPERTY(QmlListProperty children READ children NOTIFY childrenChanged DESIGNABLE false) Q_CLASSINFO("DefaultProperty", "children") public: @@ -126,7 +126,7 @@ public: virtual int indexOf(QmlGraphicsItem *item, QObject *objectContext) const; - QmlList *children(); + QmlListProperty children(); static QmlGraphicsVisualItemModelAttached *qmlAttachedProperties(QObject *obj); diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index 515f896..0c21f75 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -77,7 +77,6 @@ public: progress(1.0), status(QmlGraphicsWebView::Null), pending(PendingNone), newWindowComponent(0), newWindowParent(0), pressTime(400), - windowObjects(this), rendering(true) { } @@ -101,19 +100,14 @@ public: QPoint pressPoint; int pressTime; // milliseconds before it's a "hold" + + static void windowObjects_append(QmlListProperty *prop, QObject *o) { + static_cast(prop->data)->windowObjects.append(o); + static_cast(prop->data)->updateWindowObjects(); + } + void updateWindowObjects(); - class WindowObjectList : public QmlConcreteList - { - public: - WindowObjectList(QmlGraphicsWebViewPrivate *p) - : priv(p) {} - virtual void append(QObject *v) { - QmlConcreteList::append(v); - priv->updateWindowObjects(); - } - private: - QmlGraphicsWebViewPrivate *priv; - } windowObjects; + QObjectList windowObjects; bool rendering; }; @@ -451,10 +445,10 @@ void QmlGraphicsWebView::paintPage(const QRect& r) If Javascript is not enabled for this page, then this property does nothing. */ -QmlList *QmlGraphicsWebView::javaScriptWindowObjects() +QmlListProperty QmlGraphicsWebView::javaScriptWindowObjects() { Q_D(QmlGraphicsWebView); - return &d->windowObjects; + return QmlListProperty(this, d, &QmlGraphicsWebViewPrivate::windowObjects_append); } QmlGraphicsWebViewAttached *QmlGraphicsWebView::qmlAttachedProperties(QObject *o) diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h index 1822ddb..30ba0e4 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h @@ -114,7 +114,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem Q_PROPERTY(QmlGraphicsWebSettings* settings READ settingsObject CONSTANT) - Q_PROPERTY(QmlList* javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) + Q_PROPERTY(QmlListProperty javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) Q_PROPERTY(QmlComponent* newWindowComponent READ newWindowComponent WRITE setNewWindowComponent) Q_PROPERTY(QmlGraphicsItem* newWindowParent READ newWindowParent WRITE setNewWindowParent) @@ -174,7 +174,7 @@ public: bool renderingEnabled() const; void setRenderingEnabled(bool); - QmlList *javaScriptWindowObjects(); + QmlListProperty javaScriptWindowObjects(); static QmlGraphicsWebViewAttached *qmlAttachedProperties(QObject *); diff --git a/src/declarative/qml/qml.h b/src/declarative/qml/qml.h index e5e7c59..7972305 100644 --- a/src/declarative/qml/qml.h +++ b/src/declarative/qml/qml.h @@ -59,12 +59,10 @@ QT_MODULE(Declarative) #define QML_DECLARE_TYPE(TYPE) \ Q_DECLARE_METATYPE(TYPE *) \ - Q_DECLARE_METATYPE(QList *) \ - Q_DECLARE_METATYPE(QmlList *) + Q_DECLARE_METATYPE(QmlListProperty) #define QML_DECLARE_TYPE_HASMETATYPE(TYPE) \ - Q_DECLARE_METATYPE(QList *) \ - Q_DECLARE_METATYPE(QmlList *) + Q_DECLARE_METATYPE(QmlListProperty) #define QML_DECLARE_INTERFACE(INTERFACE) \ QML_DECLARE_TYPE(INTERFACE) diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index a8df61e..2313c37 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -51,7 +51,9 @@ SOURCES += \ $$PWD/qmllistscriptclass.cpp \ $$PWD/qmlworkerscript.cpp \ $$PWD/qmlimageprovider.cpp \ - $$PWD/qmlnetworkaccessmanagerfactory.cpp + $$PWD/qmlnetworkaccessmanagerfactory.cpp \ + $$PWD/qmllist.cpp + HEADERS += \ $$PWD/qmlparser_p.h \ $$PWD/qmlglobal_p.h \ @@ -91,6 +93,7 @@ HEADERS += \ $$PWD/qmlcompositetypedata_p.h \ $$PWD/qmlcompositetypemanager_p.h \ $$PWD/qmllist.h \ + $$PWD/qmllist_p.h \ $$PWD/qmldeclarativedata_p.h \ $$PWD/qmlerror.h \ $$PWD/qmlscriptparser_p.h \ diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index 0dbe63b..feadd0f 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -54,8 +54,6 @@ #include #include -Q_DECLARE_METATYPE(QList); - QT_BEGIN_NAMESPACE QML_DEFINE_NOCREATE_TYPE(QmlBinding); diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 2b1081e..bbae201 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1495,8 +1495,7 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, COMPILE_CHECK(buildGroupedProperty(prop, obj, ctxt)); - } else if (QmlEnginePrivate::get(engine)->isQmlList(prop->type) || - QmlMetaType::isList(prop->type)) { + } else if (QmlEnginePrivate::get(engine)->isList(prop->type)) { COMPILE_CHECK(buildListProperty(prop, obj, ctxt)); @@ -1552,8 +1551,7 @@ QmlCompiler::buildPropertyInNamespace(QmlEnginePrivate::ImportedNamespace *ns, void QmlCompiler::genValueProperty(QmlParser::Property *prop, QmlParser::Object *obj) { - if (QmlEnginePrivate::get(engine)->isQmlList(prop->type) || - QmlMetaType::isList(prop->type)) { + if (QmlEnginePrivate::get(engine)->isList(prop->type)) { genListProperty(prop, obj); } else { genPropertyAssignment(prop, obj); @@ -1563,22 +1561,10 @@ void QmlCompiler::genValueProperty(QmlParser::Property *prop, void QmlCompiler::genListProperty(QmlParser::Property *prop, QmlParser::Object *obj) { - QmlInstruction::Type fetchType; - QmlInstruction::Type storeType; - int listType; - - if (QmlEnginePrivate::get(engine)->isQmlList(prop->type)) { - fetchType = QmlInstruction::FetchQmlList; - storeType = QmlInstruction::StoreObjectQmlList; - listType = QmlEnginePrivate::get(engine)->qmlListType(prop->type); - } else { - fetchType = QmlInstruction::FetchQList; - storeType = QmlInstruction::StoreObjectQList; - listType = QmlMetaType::listType(prop->type); - } + int listType = QmlEnginePrivate::get(engine)->listType(prop->type); QmlInstruction fetch; - fetch.type = fetchType; + fetch.type = QmlInstruction::FetchQList; fetch.line = prop->location.start.line; fetch.fetchQmlList.property = prop->index; bool listTypeIsInterface = QmlMetaType::isInterface(listType); @@ -1598,7 +1584,7 @@ void QmlCompiler::genListProperty(QmlParser::Property *prop, output->bytecode << assign; } else { QmlInstruction store; - store.type = storeType; + store.type = QmlInstruction::StoreObjectQList; store.line = prop->location.start.line; output->bytecode << store; } @@ -1895,67 +1881,40 @@ bool QmlCompiler::buildListProperty(QmlParser::Property *prop, QmlParser::Object *obj, const BindingContext &ctxt) { - Q_ASSERT(QmlMetaType::isList(prop->type) || - QmlEnginePrivate::get(engine)->isQmlList(prop->type)); + Q_ASSERT(QmlEnginePrivate::get(engine)->isList(prop->type)); int t = prop->type; obj->addValueProperty(prop); - if (QmlEnginePrivate::get(engine)->isQmlList(t)) { - int listType = QmlEnginePrivate::get(engine)->qmlListType(t); - bool listTypeIsInterface = QmlMetaType::isInterface(listType); - - for (int ii = 0; ii < prop->values.count(); ++ii) { - Value *v = prop->values.at(ii); - if (v->object) { - v->type = Value::CreatedObject; - COMPILE_CHECK(buildObject(v->object, ctxt)); - - // We check object coercian here. We check interface assignment - // at runtime. - if (!listTypeIsInterface) { - if (!canCoerce(listType, v->object)) { - COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign object to list")); - } - } + int listType = QmlEnginePrivate::get(engine)->listType(t); + bool listTypeIsInterface = QmlMetaType::isInterface(listType); - } else { - COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign primitives to lists")); - } - } + bool assignedBinding = false; + for (int ii = 0; ii < prop->values.count(); ++ii) { + Value *v = prop->values.at(ii); + if (v->object) { + v->type = Value::CreatedObject; + COMPILE_CHECK(buildObject(v->object, ctxt)); - } else { - int listType = QmlMetaType::listType(t); - bool listTypeIsInterface = QmlMetaType::isInterface(listType); - - bool assignedBinding = false; - for (int ii = 0; ii < prop->values.count(); ++ii) { - Value *v = prop->values.at(ii); - if (v->object) { - v->type = Value::CreatedObject; - COMPILE_CHECK(buildObject(v->object, ctxt)); - - // We check object coercian here. We check interface assignment - // at runtime. - if (!listTypeIsInterface) { - if (!canCoerce(listType, v->object)) { - COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign object to list")); - } + // We check object coercian here. We check interface assignment + // at runtime. + if (!listTypeIsInterface) { + if (!canCoerce(listType, v->object)) { + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign object to list")); } + } - } else if (v->value.isScript()) { - if (assignedBinding) - COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Can only assign one binding to lists")); + } else if (v->value.isScript()) { + if (assignedBinding) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Can only assign one binding to lists")); - assignedBinding = true; - COMPILE_CHECK(buildBinding(v, prop, ctxt)); - v->type = Value::PropertyBinding; - } else { - COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign primitives to lists")); - } + assignedBinding = true; + COMPILE_CHECK(buildBinding(v, prop, ctxt)); + v->type = Value::PropertyBinding; + } else { + COMPILE_EXCEPTION(v, QCoreApplication::translate("QmlCompiler","Cannot assign primitives to lists")); } - } return true; @@ -2335,10 +2294,10 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) propertyType = QMetaType::QObjectStar; } else { readonly = true; - type = "QmlList<"; + type = "QmlListProperty<"; type.append(customTypeName); - type.append("*>*"); - propertyType = qMetaTypeId* >(); + type.append(">"); + propertyType = qMetaTypeId >(); } } break; diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 303af42..56038cf 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -544,5 +544,30 @@ QUrl QmlContext::baseUrl() const return QUrl(); } +int QmlContextPrivate::context_count(QmlListProperty *prop) +{ + QmlContext *context = static_cast(prop->object); + QmlContextPrivate *d = QmlContextPrivate::get(context); + int contextProperty = (int)(intptr_t)prop->data; + + if (d->propertyValues.at(contextProperty).userType() != qMetaTypeId >()) { + return 0; + } else { + return ((const QList *)d->propertyValues.at(contextProperty).constData())->count(); + } +} + +QObject *QmlContextPrivate::context_at(QmlListProperty *prop, int index) +{ + QmlContext *context = static_cast(prop->object); + QmlContextPrivate *d = QmlContextPrivate::get(context); + int contextProperty = (int)(intptr_t)prop->data; + + if (d->propertyValues.at(contextProperty).userType() != qMetaTypeId >()) { + return 0; + } else { + return ((const QList *)d->propertyValues.at(contextProperty).constData())->at(index); + } +} QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcontext.h b/src/declarative/qml/qmlcontext.h index 21b1a1e..e96ed84 100644 --- a/src/declarative/qml/qmlcontext.h +++ b/src/declarative/qml/qmlcontext.h @@ -45,6 +45,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -97,9 +98,10 @@ private: QmlContext(QmlContext *parent, QObject *objParent, bool); QmlContext(QmlEngine *, bool); }; - QT_END_NAMESPACE +Q_DECLARE_METATYPE(QList); + QT_END_HEADER #endif // QMLCONTEXT_H diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index bd4f5d5..965eeed 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -152,6 +152,9 @@ public: // Only used for debugging QList > instances; + + static int context_count(QmlListProperty *); + static QObject *context_at(QmlListProperty *, int); }; QmlContextPrivate::IdNotifier::IdNotifier() diff --git a/src/declarative/qml/qmlcontextscriptclass.cpp b/src/declarative/qml/qmlcontextscriptclass.cpp index be3bbc3..4c71903 100644 --- a/src/declarative/qml/qmlcontextscriptclass.cpp +++ b/src/declarative/qml/qmlcontextscriptclass.cpp @@ -44,6 +44,7 @@ #include "qmlengine_p.h" #include "qmlcontext_p.h" #include "qmltypenamescriptclass_p.h" +#include "qmllistscriptclass_p.h" #include "qmlguard_p.h" QT_BEGIN_NAMESPACE @@ -227,8 +228,12 @@ QmlContextScriptClass::property(Object *object, const Identifier &name) if (lastPropertyIndex < cp->idValueCount) { rv = ep->objectClass->newQObject(cp->idValues[lastPropertyIndex].data()); } else { - QVariant value = cp->propertyValues.at(lastPropertyIndex); - rv = ep->scriptValueFromVariant(value); + const QVariant &value = cp->propertyValues.at(lastPropertyIndex); + if (value.userType() == qMetaTypeId >()) { + rv = ep->listClass->newList(QmlListProperty(bindContext, (void*)lastPropertyIndex, 0, QmlContextPrivate::context_count, QmlContextPrivate::context_at), qMetaTypeId >()); + } else { + rv = ep->scriptValueFromVariant(value); + } } ep->capturedProperties << diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index 01061ee..c75a299 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -1346,7 +1346,6 @@ QmlDomValue::Type QmlDomValue::type() const { if (d->property) if (QmlMetaType::isList(d->property->type) || - QmlMetaType::isQmlList(d->property->type) || (d->property && d->property->values.count() > 1)) return List; diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index cf26f58..97d8250 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -66,6 +66,7 @@ #include "qmlscriptclass_p.h" #include "qmlnetworkaccessmanagerfactory.h" #include "qmlimageprovider.h" +#include "qmllist_p.h" #include @@ -107,7 +108,6 @@ #endif Q_DECLARE_METATYPE(QmlMetaProperty) -Q_DECLARE_METATYPE(QList); QT_BEGIN_NAMESPACE @@ -1170,6 +1170,15 @@ QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine) QScriptValue QmlEnginePrivate::scriptValueFromVariant(const QVariant &val) { + if (val.userType() == qMetaTypeId()) { + QmlListReferencePrivate *p = QmlListReferencePrivate::get((QmlListReference*)val.constData()); + if (p->object) { + return listClass->newList(p->property, p->propertyType); + } else { + return scriptEngine.nullValue(); + } + } + bool objOk; QObject *obj = QmlMetaType::toQObject(val, &objOk); if (objOk) { @@ -1667,7 +1676,7 @@ void QmlEnginePrivate::registerCompositeType(QmlCompiledData *data) QByteArray name = data->root->className(); QByteArray ptr = name + '*'; - QByteArray lst = "QmlList<" + ptr + ">*"; + QByteArray lst = "QmlListProperty<" + name + ">"; int ptr_type = QMetaType::registerType(ptr.constData(), voidptr_destructor, voidptr_constructor); @@ -1679,9 +1688,18 @@ void QmlEnginePrivate::registerCompositeType(QmlCompiledData *data) data->addref(); } -bool QmlEnginePrivate::isQmlList(int t) const +bool QmlEnginePrivate::isList(int t) const { - return m_qmlLists.contains(t) || QmlMetaType::isQmlList(t); + return m_qmlLists.contains(t) || QmlMetaType::isList(t); +} + +int QmlEnginePrivate::listType(int t) const +{ + QHash::ConstIterator iter = m_qmlLists.find(t); + if (iter != m_qmlLists.end()) + return *iter; + else + return QmlMetaType::listType(t); } bool QmlEnginePrivate::isQObject(int t) @@ -1700,21 +1718,12 @@ QObject *QmlEnginePrivate::toQObject(const QVariant &v, bool *ok) const } } -int QmlEnginePrivate::qmlListType(int t) const -{ - QHash::ConstIterator iter = m_qmlLists.find(t); - if (iter != m_qmlLists.end()) - return *iter; - else - return QmlMetaType::qmlListType(t); -} - QmlMetaType::TypeCategory QmlEnginePrivate::typeCategory(int t) const { if (m_compositeTypes.contains(t)) return QmlMetaType::Object; else if (m_qmlLists.contains(t)) - return QmlMetaType::QmlList; + return QmlMetaType::List; else return QmlMetaType::typeCategory(t); } diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 7ec6dd6..3fe7991 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -274,11 +274,12 @@ public: void registerCompositeType(QmlCompiledData *); - bool isQmlList(int) const; + bool isQObject(int); QObject *toQObject(const QVariant &, bool *ok = 0) const; - int qmlListType(int) const; QmlMetaType::TypeCategory typeCategory(int) const; + bool isList(int) const; + int listType(int) const; const QMetaObject *rawMetaObjectForType(int) const; const QMetaObject *metaObjectForType(int) const; QHash m_qmlLists; @@ -322,7 +323,6 @@ public: QmlContext *getContext(QScriptContext *); }; - QT_END_NAMESPACE #endif // QMLENGINE_P_H diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp index d3caa95..654157c 100644 --- a/src/declarative/qml/qmlenginedebug.cpp +++ b/src/declarative/qml/qmlenginedebug.cpp @@ -119,8 +119,7 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx) rv.type = QmlObjectProperty::Basic; } else if (QmlMetaType::isQObject(prop.userType())) { rv.type = QmlObjectProperty::Object; - } else if (QmlMetaType::isList(prop.userType()) || - QmlMetaType::isQmlList(prop.userType())) { + } else if (QmlMetaType::isList(prop.userType())) { rv.type = QmlObjectProperty::List; } @@ -133,14 +132,15 @@ QVariant QmlEngineDebugServer::valueContents(const QVariant &value) const if (QVariant::Type(userType) < QVariant::UserType) return value; - - if (QmlMetaType::isList(userType) || QmlMetaType::isQmlList(userType)) { + /* + if (QmlMetaType::isList(userType)) { int count = QmlMetaType::listCount(value); QVariantList contents; for (int i=0; iobjectName(); diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index d428377..8f0c945 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -52,8 +52,6 @@ #include -Q_DECLARE_METATYPE(QList); - QT_BEGIN_NAMESPACE bool QmlDelayedError::addError(QmlEnginePrivate *e) diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp index de01bfe..e37ade7 100644 --- a/src/declarative/qml/qmlinstruction.cpp +++ b/src/declarative/qml/qmlinstruction.cpp @@ -171,9 +171,6 @@ void QmlCompiledData::dump(QmlInstruction *instr, int idx) case QmlInstruction::BeginObject: qWarning().nospace() << idx << "\t\t" << line << "\t" << "BEGIN\t\t\t" << instr->begin.castValue; break; - case QmlInstruction::StoreObjectQmlList: - qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_OBJECT_QMLLIST"; - break; case QmlInstruction::StoreObjectQList: qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_OBJECT_QLIST"; break; @@ -183,9 +180,6 @@ void QmlCompiledData::dump(QmlInstruction *instr, int idx) case QmlInstruction::FetchAttached: qWarning().nospace() << idx << "\t\t" << line << "\t" << "FETCH_ATTACHED\t\t" << instr->fetchAttached.id; break; - case QmlInstruction::FetchQmlList: - qWarning().nospace() << idx << "\t\t" << line << "\t" << "FETCH_QMLLIST\t\t" << instr->fetchQmlList.property << "\t" << instr->fetchQmlList.type; - break; case QmlInstruction::FetchQList: qWarning().nospace() << idx << "\t\t" << line << "\t" << "FETCH_QLIST\t\t" << instr->fetch.property; break; diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h index 5613888..ea785b6 100644 --- a/src/declarative/qml/qmlinstruction_p.h +++ b/src/declarative/qml/qmlinstruction_p.h @@ -134,12 +134,10 @@ public: BeginObject, /* begin */ - StoreObjectQmlList, /* NA */ StoreObjectQList, /* NA */ AssignObjectList, /* NA */ FetchAttached, /* fetchAttached */ - FetchQmlList, /* fetchQmlList */ FetchQList, /* fetch */ FetchObject, /* fetch */ FetchValueType, /* fetchValue */ diff --git a/src/declarative/qml/qmllist.cpp b/src/declarative/qml/qmllist.cpp new file mode 100644 index 0000000..4cd2120 --- /dev/null +++ b/src/declarative/qml/qmllist.cpp @@ -0,0 +1,312 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmllist.h" +#include "qmllist_p.h" +#include "qmlengine_p.h" +#include "qmlmetaproperty_p.h" + +QT_BEGIN_NAMESPACE + +QmlListReferencePrivate::QmlListReferencePrivate() +: propertyType(-1), refCount(1) +{ +} + +QmlListReference QmlListReferencePrivate::init(const QmlListProperty &prop, int propType, QmlEngine *engine) +{ + QmlListReference rv; + + if (!prop.object) return rv; + + QmlEnginePrivate *p = engine?QmlEnginePrivate::get(engine):0; + + int listType = p?p->listType(propType):QmlMetaType::listType(propType); + if (listType == -1) return rv; + + rv.d = new QmlListReferencePrivate; + rv.d->object = prop.object; + rv.d->elementType = p?p->rawMetaObjectForType(listType):QmlMetaType::qmlType(listType)->baseMetaObject(); + rv.d->property = prop; + rv.d->propertyType = propType; + + return rv; +} + +void QmlListReferencePrivate::addref() +{ + Q_ASSERT(refCount > 0); + ++refCount; +} + +void QmlListReferencePrivate::release() +{ + Q_ASSERT(refCount > 0); + --refCount; + if (!refCount) + delete this; +} + +QmlListReference::QmlListReference() +: d(0) +{ +} + +QmlListReference::QmlListReference(QObject *o, const char *property, QmlEngine *engine) +: d(0) +{ + if (!o || !property) return; + + QmlPropertyCache::Data local; + QmlPropertyCache::Data *data = QmlPropertyCache::property(engine, o, QLatin1String(property), local); + + if (!data || !(data->flags & QmlPropertyCache::Data::IsQList)) return; + + QmlEnginePrivate *p = engine?QmlEnginePrivate::get(engine):0; + + int listType = p?p->listType(data->propType):QmlMetaType::listType(data->propType); + if (listType == -1) return; + + d = new QmlListReferencePrivate; + d->object = o; + d->elementType = p?p->rawMetaObjectForType(listType):QmlMetaType::qmlType(listType)->baseMetaObject(); + d->propertyType = data->propType; + + void *args[] = { &d->property, 0 }; + QMetaObject::metacall(o, QMetaObject::ReadProperty, data->coreIndex, args); +} + +QmlListReference::QmlListReference(const QmlListReference &o) +: d(o.d) +{ + if (d) d->addref(); +} + +QmlListReference &QmlListReference::operator=(const QmlListReference &o) +{ + if (o.d) o.d->addref(); + if (d) d->release(); + d = o.d; + return *this; +} + +QmlListReference::~QmlListReference() +{ + if (d) d->release(); +} + +bool QmlListReference::isValid() const +{ + return d && d->object; +} + +QObject *QmlListReference::object() const +{ + if (isValid()) return d->object; + else return 0; +} + +const QMetaObject *QmlListReference::listElementType() const +{ + if (isValid()) return d->elementType; + else return 0; +} + +bool QmlListReference::canAppend() const +{ + return (isValid() && d->property.append); +} + +bool QmlListReference::canAt() const +{ + return (isValid() && d->property.at); +} + +bool QmlListReference::canClear() const +{ + return (isValid() && d->property.clear); +} + +bool QmlListReference::canCount() const +{ + return (isValid() && d->property.count); +} + +bool QmlListReference::append(QObject *o) const +{ + if (!canAppend()) return false; + + if (o && !QmlMetaPropertyPrivate::canConvert(o->metaObject(), d->elementType)) + return false; + + d->property.append(&d->property, o); + + return true; +} + +QObject *QmlListReference::at(int index) const +{ + if (!canAt()) return 0; + + return d->property.at(&d->property, index); +} + +bool QmlListReference::clear() const +{ + if (!canClear()) return false; + + d->property.clear(&d->property); + + return true; +} + +int QmlListReference::count() const +{ + if (!canCount()) return 0; + + return d->property.count(&d->property); +} + +/*! +\class QmlListProperty +\brief The QmlListProperty class allows applications to explose list-like +properties to QML. + +QML has many list properties, where more than one object value can be assigned. +The use of a list property from QML looks like this: + +\code +FruitBasket { + fruit: [ + Apple {}, + Orange{}, + Banana {} + ] +} +\endcode + +The QmlListProperty encapsulates a group of function pointers that represet the +set of actions QML can perform on the list - adding items, retrieving items and +clearing the list. In the future, additional operations may be supported. All +list properties must implement the append operation, but the rest are optional. + +To provide a list property, a C++ class must implement the operation callbacks, +and then return an appropriate QmlListProperty value from the property getter. +List properties should have no setter. In the example above, the Q_PROPERTY() +declarative will look like this: + +\code +Q_PROPERTY(QmlListProperty fruit READ fruit); +\endcode + +QML list properties are typesafe - in this case \c {Fruit} is a QObject type that +\c {Apple}, \c {Orange} and \c {Banana} all derive from. +*/ + +/*! +\fn QmlListProperty::QmlListProperty() +\internal +*/ + +/*! +\fn QmlListProperty::QmlListProperty(QObject *object, QList &list) + +Convenience constructor for making a QmlListProperty value from an existing +QList \a list. The \a list reference must remain valid for as long as \a object +exists. \a object must be provided. + +Generally this constructor should not be used in production code, as a +writable QList violates QML's memory management rules. However, this constructor +can very useful while prototyping. +*/ + +/*! +\fn QmlListProperty::QmlListProperty(QObject *object, void *data, AppendFunction append, + CountFunction count = 0, AtFunction at = 0, + ClearFunction clear = 0) + +Construct a QmlListProperty from a set of operation functions. An opaque \a data handle +may be passed which can be accessed from within the operation functions. The list property +remains valid while \a object exists. + +The \a append operation is compulsory and must be provided, while the \a count, \a at and +\a clear methods are optional. +*/ + +/*! +\typedef QmlListProperty::AppendFunction + +Synonym for \c {void (*)(QmlListProperty *property, T *value)}. + +Append the \a value to the list \a property. +*/ + +/*! +\typedef QmlListProperty::CountFunction + +Synonym for \c {int (*)(QmlListProperty *property)}. + +Return the number of elements in the list \a property. +*/ + +/*! +\fn bool QmlListProperty::operator==(const QmlListProperty &other) const + +Returns true if this QmlListProperty is equal to \a other, otherwise false. +*/ + +/*! +\typedef QmlListProperty::AtFunction + +Synonym for \c {T *(*)(QmlListProperty *property, int index)}. + +Return the element at position \a index in the list \a property. +*/ + +/*! +\typedef QmlListProperty::ClearFunction + +Synonym for \c {void (*)(QmlListProperty *property)}. + +Clear the list \a property. +*/ + +QT_END_NAMESPACE diff --git a/src/declarative/qml/qmllist.h b/src/declarative/qml/qmllist.h index 261145d..cedc35b 100644 --- a/src/declarative/qml/qmllist.h +++ b/src/declarative/qml/qmllist.h @@ -51,73 +51,89 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) template -class QmlList : private QmlPrivate::ListInterface -{ -public: - virtual void append(T) = 0; - virtual void insert(int, T) = 0; - virtual void removeAt(int) = 0; - virtual T at(int) const = 0; - virtual int count() const = 0; - virtual void clear() = 0; - QmlList &operator<<(T t) { append(t); return *this; } - -protected: - virtual int type() const { return qMetaTypeId(); } - virtual void append(void *d) { const T &v = *(T *)d; append(v); } - virtual void insert(int i, void *d) { const T &v = *(T *)d; insert(i, v); } - virtual void at(int i, void *p) const { const T &v = at(i); *((T*)p) = v; } +struct QmlListProperty { + typedef void (*AppendFunction)(QmlListProperty *, T*); + typedef int (*CountFunction)(QmlListProperty *); + typedef T *(*AtFunction)(QmlListProperty *, int); + typedef void (*ClearFunction)(QmlListProperty *); + + QmlListProperty() + : object(0), data(0), append(0), count(0), at(0), clear(0), dummy1(0), dummy2(0) {} + QmlListProperty(QObject *o, QList &list) + : object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at), + clear(qlist_clear), dummy1(0), dummy2(0) {} + QmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c = 0, AtFunction t = 0, + ClearFunction r = 0) + : object(o), data(d), append(a), count(c), at(t), clear(r), dummy1(0), dummy2(0) {} + + bool operator==(const QmlListProperty &o) const { + return object == o.object && + data == o.data && + append == o.append && + count == o.count && + at == o.at && + clear == o.clear; + } + + QObject *object; + void *data; + + AppendFunction append; + + CountFunction count; + AtFunction at; + + ClearFunction clear; + + void *dummy1; + void *dummy2; + +private: + static void qlist_append(QmlListProperty *p, T *v) { + ((QList *)p->data)->append(v); + } + static int qlist_count(QmlListProperty *p) { + return ((QList *)p->data)->count(); + } + static T *qlist_at(QmlListProperty *p, int idx) { + return ((QList *)p->data)->at(idx); + } + static void qlist_clear(QmlListProperty *p) { + return ((QList *)p->data)->clear(); + } }; -template -class QmlConcreteList : public QList, public QmlList +class QmlEngine; +class QmlListReferencePrivate; +class Q_DECLARATIVE_EXPORT QmlListReference { public: - virtual void append(T v) { QList::append(v); } - virtual void insert(int i, T v) { QList::insert(i, v); } - virtual void clear() { QList::clear(); } - virtual T at(int i) const { return QList::at(i); } - virtual void removeAt(int i) { QList::removeAt(i); } - virtual int count() const { return QList::count(); } -}; + QmlListReference(); + QmlListReference(QObject *, const char *property, QmlEngine * = 0); + QmlListReference(const QmlListReference &); + QmlListReference &operator=(const QmlListReference &); + ~QmlListReference(); + + bool isValid() const; -#define QML_DECLARE_LIST_PROXY(ClassName, ListType, ListName) \ -class Qml_ProxyList_ ##ListName : public QmlList \ -{ \ - public: \ - virtual void removeAt(int idx) \ - { \ - ClassName *p = (ClassName *)((char *)this + ((char *)(ClassName *)(0x10000000) - (char *)&((ClassName *)(0x10000000))->ListName)); \ - p->ListName ## _removeAt(idx); \ - } \ - virtual int count() const \ - { \ - ClassName *p = (ClassName *)((char *)this + ((char *)(ClassName *)(0x10000000) - (char *)&((ClassName *)(0x10000000))->ListName)); \ - return p->ListName ## _count(); \ - } \ - virtual void append(ListType v) \ - { \ - ClassName *p = (ClassName *)((char *)this + ((char *)(ClassName *)(0x10000000) - (char *)&((ClassName *)(0x10000000))->ListName)); \ - p->ListName ## _append(v); \ - } \ - virtual void insert(int idx, ListType v) \ - { \ - ClassName *p = (ClassName *)((char *)this + ((char *)(ClassName *)(0x10000000) - (char *)&((ClassName *)(0x10000000))->ListName)); \ - p->ListName ## _insert(idx, v); \ - } \ - virtual ListType at(int idx) const \ - { \ - ClassName *p = (ClassName *)((char *)this + ((char *)(ClassName *)(0x10000000) - (char *)&((ClassName *)(0x10000000))->ListName)); \ - return p->ListName ## _at(idx); \ - } \ - virtual void clear() \ - { \ - ClassName *p = (ClassName *)((char *)this + ((char *)(ClassName *)(0x10000000) - (char *)&((ClassName *)(0x10000000))->ListName)); \ - p->ListName ## _clear(); \ - } \ -}; \ -friend class Qml_ProxyList_ ##ListName ; \ -Qml_ProxyList_##ListName ListName; + QObject *object() const; + const QMetaObject *listElementType() const; + + bool canAppend() const; + bool canAt() const; + bool canClear() const; + bool canCount() const; + + bool append(QObject *) const; + QObject *at(int) const; + bool clear() const; + int count() const; + +private: + friend class QmlListReferencePrivate; + QmlListReferencePrivate* d; +}; +Q_DECLARE_METATYPE(QmlListReference); QT_END_NAMESPACE diff --git a/src/declarative/qml/qmllist_p.h b/src/declarative/qml/qmllist_p.h new file mode 100644 index 0000000..4660e47 --- /dev/null +++ b/src/declarative/qml/qmllist_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLLIST_P_H +#define QMLLIST_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmllist.h" +#include "qmlguard_p.h" + +QT_BEGIN_NAMESPACE + +class QmlListReferencePrivate +{ +public: + QmlListReferencePrivate(); + + static QmlListReference init(const QmlListProperty &, int, QmlEngine *); + + QmlGuard object; + const QMetaObject *elementType; + QmlListProperty property; + int propertyType; + + void addref(); + void release(); + int refCount; + + static inline QmlListReferencePrivate *get(QmlListReference *ref) { + return ref->d; + } +}; + + +QT_END_NAMESPACE + +#endif // QMLLIST_P_H diff --git a/src/declarative/qml/qmllistscriptclass.cpp b/src/declarative/qml/qmllistscriptclass.cpp index d74a9b0..bb29763 100644 --- a/src/declarative/qml/qmllistscriptclass.cpp +++ b/src/declarative/qml/qmllistscriptclass.cpp @@ -43,13 +43,13 @@ #include "qmlengine_p.h" #include "qmlguard_p.h" +#include "qmllist_p.h" QT_BEGIN_NAMESPACE struct ListData : public QScriptDeclarativeClass::Object { QmlGuard object; - int propertyIdx; - QmlListScriptClass::ListCategory type; + QmlListProperty property; int propertyType; }; @@ -66,7 +66,7 @@ QmlListScriptClass::~QmlListScriptClass() { } -QScriptValue QmlListScriptClass::newList(QObject *object, int propId, ListCategory type, int propType) +QScriptValue QmlListScriptClass::newList(QObject *object, int propId, int propType) { QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); @@ -75,8 +75,20 @@ QScriptValue QmlListScriptClass::newList(QObject *object, int propId, ListCatego ListData *data = new ListData; data->object = object; - data->propertyIdx = propId; - data->type = type; + data->propertyType = propType; + void *args[] = { &data->property, 0 }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args); + + return newObject(scriptEngine, this, data); +} + +QScriptValue QmlListScriptClass::newList(const QmlListProperty &prop, int propType) +{ + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + + ListData *data = new ListData; + data->object = prop.object; + data->property = prop; data->propertyType = propType; return newObject(scriptEngine, this, data); @@ -111,39 +123,14 @@ QmlListScriptClass::ScriptValue QmlListScriptClass::property(Object *obj, const if (!data->object) return Value(); - void *list = 0; - void *args[] = { &list, 0 }; - QMetaObject::metacall(data->object, QMetaObject::ReadProperty, - data->propertyIdx, args); + quint32 count = data->property.count?data->property.count(&data->property):0; - if (!list) + if (name == m_lengthId.identifier) + return Value(scriptEngine, count); + else if (lastIndex < count && data->property.at) + return Value(scriptEngine, enginePriv->objectClass->newQObject(data->property.at(&data->property, lastIndex))); + else return Value(); - - if (data->type == QListPtr) { - const QList &qlist = *((QList*)list); - - quint32 count = qlist.count(); - - if (name == m_lengthId.identifier) - return Value(scriptEngine, count); - else if (lastIndex < count) - return Value(scriptEngine, enginePriv->objectClass->newQObject(qlist.at(lastIndex))); - else - return Value(); - - } else { - Q_ASSERT(data->type == QmlListPtr); - const QmlList &qmllist = *((QmlList*)list); - - quint32 count = qmllist.count(); - - if (name == m_lengthId.identifier) - return Value(scriptEngine, count); - else if (lastIndex < count) - return Value(scriptEngine, enginePriv->objectClass->newQObject(qmllist.at(lastIndex))); - else - return Value(); - } } QVariant QmlListScriptClass::toVariant(Object *obj, bool *ok) @@ -155,18 +142,7 @@ QVariant QmlListScriptClass::toVariant(Object *obj, bool *ok) return QVariant(); } - void *list = 0; - void *args[] = { &list, 0 }; - QMetaObject::metacall(data->object, QMetaObject::ReadProperty, - data->propertyIdx, args); - - if (!list) { - if (ok) *ok = false; - return QVariant(); - } - - if (ok) *ok = true; - return QVariant(data->propertyType, &list); + return QVariant::fromValue(QmlListReferencePrivate::init(data->property, data->propertyType, engine)); } QT_END_NAMESPACE diff --git a/src/declarative/qml/qmllistscriptclass_p.h b/src/declarative/qml/qmllistscriptclass_p.h index 92cf17f..07b09c3 100644 --- a/src/declarative/qml/qmllistscriptclass_p.h +++ b/src/declarative/qml/qmllistscriptclass_p.h @@ -54,6 +54,7 @@ // #include +#include "qmllist.h" QT_BEGIN_NAMESPACE @@ -64,8 +65,8 @@ public: QmlListScriptClass(QmlEngine *); ~QmlListScriptClass(); - enum ListCategory { QListPtr, QmlListPtr }; - QScriptValue newList(QObject *, int, ListCategory, int); + QScriptValue newList(QObject *, int, int); + QScriptValue newList(const QmlListProperty &, int); protected: virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index d7d4a07..7c273dc 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -52,16 +52,13 @@ #include "qmlengine_p.h" #include "qmldeclarativedata_p.h" #include "qmlstringconverters_p.h" - -#include +#include "qmllist_p.h" #include #include #include -Q_DECLARE_METATYPE(QList); - QT_BEGIN_NAMESPACE /*! @@ -213,7 +210,6 @@ QmlMetaProperty::QmlMetaProperty(const QmlMetaProperty &other) \value InvalidProperty The property is invalid. \value Bindable The property is a QmlBinding. \value List The property is a QList pointer - \value QmlList The property is a QmlList pointer \value Object The property is a QObject derived type pointer \value Normal The property is none of the above. */ @@ -257,8 +253,6 @@ QmlMetaPropertyPrivate::propertyCategory() const return QmlMetaProperty::Bindable; else if (core.flags & QmlPropertyCache::Data::IsQObjectDerived) return QmlMetaProperty::Object; - else if (core.flags & QmlPropertyCache::Data::IsQmlList) - return QmlMetaProperty::QmlList; else if (core.flags & QmlPropertyCache::Data::IsQList) return QmlMetaProperty::List; else @@ -401,7 +395,7 @@ bool QmlMetaProperty::isWritable() const if (!d->object) return false; - if (category == List || category == QmlList) + if (category == List) return true; else if (type() & SignalProperty) return false; @@ -703,6 +697,13 @@ QVariant QmlMetaPropertyPrivate::readValueProperty() if (!ep) delete valueType; return rv; + } else if(core.flags & QmlPropertyCache::Data::IsQList) { + + QmlListProperty prop; + void *args[] = { &prop, 0 }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args); + return QVariant::fromValue(QmlListReferencePrivate::init(prop, core.propType, context?context->engine():0)); + } else { return object->metaObject()->property(core.coreIndex).read(object.data()); @@ -813,9 +814,7 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data int t = property.propType; int vt = value.userType(); - QmlEnginePrivate *enginePriv = 0; - if (context && context->engine()) - enginePriv = QmlEnginePrivate::get(context->engine()); + QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(context); if (t == QVariant::Url) { @@ -880,55 +879,40 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data } else if (property.flags & QmlPropertyCache::Data::IsQList) { - int listType = QmlMetaType::listType(t); - QMetaProperty prop = object->metaObject()->property(property.coreIndex); - - if (value.userType() == qMetaTypeId >()) { - const QList &list = - qvariant_cast >(value); - QVariant listVar = prop.read(object); - QmlMetaType::clear(listVar); - for (int ii = 0; ii < list.count(); ++ii) { - QVariant v = QmlMetaType::qmlType(listType)->fromObject(list.at(ii)); - QmlMetaType::append(listVar, v); - } - - } else if (vt == listType || - value.userType() == listType) { - QVariant listVar = prop.read(object); - QmlMetaType::append(listVar, value); + const QMetaObject *listType = 0; + if (enginePriv) { + listType = enginePriv->rawMetaObjectForType(enginePriv->listType(property.propType)); + } else { + QmlType *type = QmlMetaType::qmlType(QmlMetaType::listType(property.propType)); + if (!type) return false; + listType = type->baseMetaObject(); } + if (!listType) return false; - } else if (property.flags & QmlPropertyCache::Data::IsQmlList) { + QmlListProperty prop; + void *args[] = { &prop, 0 }; + QMetaObject::metacall(object, QMetaObject::ReadProperty, coreIdx, args); - // XXX - optimize! - QMetaProperty prop = object->metaObject()->property(property.coreIndex); - QVariant list = prop.read(object); - QmlPrivate::ListInterface *li = - *(QmlPrivate::ListInterface **)list.constData(); - - int type = li->type(); - - if (QObject *obj = QmlMetaType::toQObject(value)) { - const QMetaObject *mo = rawMetaObjectForType(enginePriv, type); - - const QMetaObject *objMo = obj->metaObject(); - bool found = false; - while(!found && objMo) { - if (equal(objMo, mo)) - found = true; - else - objMo = objMo->superClass(); - } + if (!prop.clear) return false; - if (!found) - return false; + prop.clear(&prop); + + if (value.userType() == qMetaTypeId >()) { + const QList &list = qvariant_cast >(value); - // NOTE: This assumes a cast to QObject does not alter - // the object pointer - void *d = (void *)&obj; - li->append(d); + for (int ii = 0; ii < list.count(); ++ii) { + QObject *o = list.at(ii); + if (!canConvert(o->metaObject(), listType)) + o = 0; + prop.append(&prop, (void *)o); + } + } else { + QObject *o = enginePriv?enginePriv->toQObject(value):QmlMetaType::toQObject(value); + if (!canConvert(o->metaObject(), listType)) + o = 0; + prop.append(&prop, (void *)o); } + } else { Q_ASSERT(vt != t); diff --git a/src/declarative/qml/qmlmetaproperty.h b/src/declarative/qml/qmlmetaproperty.h index 723fc50..82266c8 100644 --- a/src/declarative/qml/qmlmetaproperty.h +++ b/src/declarative/qml/qmlmetaproperty.h @@ -68,7 +68,6 @@ public: InvalidProperty, Bindable, List, - QmlList, //XXX Object, Normal }; diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index b94a815..6db70d4 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -100,7 +100,6 @@ struct QmlMetaTypeData QBitArray objects; QBitArray interfaces; - QBitArray qmllists; QBitArray lists; }; Q_GLOBAL_STATIC(QmlMetaTypeData, metaTypeData) @@ -124,8 +123,8 @@ public: QByteArray m_name; int m_version_maj; int m_version_min; - int m_typeId; int m_listId; int m_qmlListId; - QmlPrivate::Func m_opFunc; + int m_typeId; int m_listId; + QObject *(*m_newFunc)(); const QMetaObject *m_baseMetaObject; QmlAttachedPropertiesFunc m_attachedPropertiesFunc; const QMetaObject *m_attachedPropertiesType; @@ -141,32 +140,30 @@ public: }; QmlTypePrivate::QmlTypePrivate() -: m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), m_qmlListId(0), - m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0), +: m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), + m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0), m_parserStatusCast(-1), m_propertyValueSourceCast(-1), m_propertyValueInterceptorCast(-1), m_extFunc(0), m_extMetaObject(0), m_index(-1), m_customParser(0), m_isSetup(false) { } -QmlType::QmlType(int type, int listType, int qmlListType, - QmlPrivate::Func opFunc, const char *iid, int index) +QmlType::QmlType(int type, int listType, const char *iid, int index) : d(new QmlTypePrivate) { d->m_isInterface = true; d->m_iid = iid; d->m_typeId = type; d->m_listId = listType; - d->m_qmlListId = qmlListType; - d->m_opFunc = opFunc; + d->m_newFunc = 0; d->m_index = index; d->m_isSetup = true; d->m_version_maj = 0; d->m_version_min = 0; } -QmlType::QmlType(int type, int listType, int qmlListType, - QmlPrivate::Func opFunc, const char *qmlName, +QmlType::QmlType(int type, int listType, + QObject *(*newFunc)(), const char *qmlName, int version_maj, int version_min, const QMetaObject *metaObject, QmlAttachedPropertiesFunc attachedPropertiesFunc, @@ -182,8 +179,7 @@ QmlType::QmlType(int type, int listType, int qmlListType, d->m_version_min = version_min; d->m_typeId = type; d->m_listId = listType; - d->m_qmlListId = qmlListType; - d->m_opFunc = opFunc; + d->m_newFunc = newFunc; d->m_baseMetaObject = metaObject; d->m_attachedPropertiesFunc = attachedPropertiesFunc; d->m_attachedPropertiesType = attachedType; @@ -283,10 +279,7 @@ QObject *QmlType::create() const { d->init(); - QVariant v; - QObject *rv = 0; - d->m_opFunc(QmlPrivate::Create, 0, v, v, (void **)&rv); - + QObject *rv = d->m_newFunc(); if (rv && !d->m_metaObjects.isEmpty()) (void *)new QmlProxyMetaObject(rv, &d->m_metaObjects); @@ -313,39 +306,6 @@ int QmlType::qListTypeId() const return d->m_listId; } -int QmlType::qmlListTypeId() const -{ - return d->m_qmlListId; -} - -void QmlType::listClear(const QVariant &list) -{ - Q_ASSERT(list.userType() == qListTypeId()); - QVariant arg; - d->m_opFunc(QmlPrivate::Clear, 0, list, arg, 0); -} - -void QmlType::listAppend(const QVariant &list, const QVariant &item) -{ - Q_ASSERT(list.userType() == qListTypeId()); - d->m_opFunc(QmlPrivate::Append, 0, list, item, 0); -} - -QVariant QmlType::listAt(const QVariant &list, int idx) -{ - Q_ASSERT(list.userType() == qListTypeId()); - QVariant rv; - void *ptr = (void *)&rv; - d->m_opFunc(QmlPrivate::Value, idx, list, QVariant(), &ptr); - return rv; -} - -int QmlType::listCount(const QVariant &list) -{ - Q_ASSERT(list.userType() == qListTypeId()); - return d->m_opFunc(QmlPrivate::Length, 0, list, QVariant(), 0); -} - const QMetaObject *QmlType::metaObject() const { d->init(); @@ -387,15 +347,6 @@ int QmlType::propertyValueInterceptorCast() const return d->m_propertyValueInterceptorCast; } -QVariant QmlType::fromObject(QObject *obj) const -{ - QVariant rv; - QVariant *v_ptr = &rv; - QVariant vobj = QVariant::fromValue(obj); - d->m_opFunc(QmlPrivate::FromObject, 0, QVariant(), vobj, (void **)&v_ptr); - return rv; -} - const char *QmlType::interfaceIId() const { return d->m_iid; @@ -407,7 +358,6 @@ int QmlType::index() const } int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id, - QmlPrivate::Func listFunction, const char *iid) { QWriteLocker lock(metaTypeDataLock()); @@ -415,31 +365,26 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id, int index = data->types.count(); - QmlType *type = new QmlType(id.typeId, id.listId, id.qmlListId, - listFunction, iid, index); + QmlType *type = new QmlType(id.typeId, id.listId, iid, index); data->types.append(type); data->idToType.insert(type->typeId(), type); data->idToType.insert(type->qListTypeId(), type); - data->idToType.insert(type->qmlListTypeId(), type); // XXX No insertMulti, so no multi-version interfaces? if (!type->qmlTypeName().isEmpty()) data->nameToType.insert(type->qmlTypeName(), type); - if (data->interfaces.size() < id.typeId) + if (data->interfaces.size() <= id.typeId) data->interfaces.resize(id.typeId + 16); - if (data->qmllists.size() < id.qmlListId) - data->qmllists.resize(id.qmlListId + 16); - if (data->lists.size() < id.listId) + if (data->lists.size() <= id.listId) data->lists.resize(id.listId + 16); data->interfaces.setBit(id.typeId, true); - data->qmllists.setBit(id.qmlListId, true); data->lists.setBit(id.listId, true); return index; } -int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func, +int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QObject *(*func)(), const char *uri, int version_maj, int version_min, const char *cname, const QMetaObject *mo, QmlAttachedPropertiesFunc attach, const QMetaObject *attachMo, int pStatus, int object, int valueSource, int valueInterceptor, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser) @@ -464,14 +409,13 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun name += '/'; name += cname; - QmlType *type = new QmlType(id.typeId, id.listId, id.qmlListId, + QmlType *type = new QmlType(id.typeId, id.listId, func, name, version_maj, version_min, mo, attach, attachMo, pStatus, valueSource, valueInterceptor, extFunc, extmo, index, parser); data->types.append(type); data->idToType.insert(type->typeId(), type); data->idToType.insert(type->qListTypeId(), type); - data->idToType.insert(type->qmlListTypeId(), type); if (!type->qmlTypeName().isEmpty()) data->nameToType.insertMulti(type->qmlTypeName(), type); @@ -480,12 +424,9 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun if (data->objects.size() <= id.typeId) data->objects.resize(id.typeId + 16); - if (data->qmllists.size() <= id.qmlListId) - data->qmllists.resize(id.qmlListId + 16); if (data->lists.size() <= id.listId) data->lists.resize(id.listId + 16); data->objects.setBit(id.typeId, true); - data->qmllists.setBit(id.qmlListId, true); data->lists.setBit(id.listId, true); return index; @@ -527,51 +468,6 @@ int QmlMetaType::listType(int id) return 0; } -/* - Returns the item type for a qml list of type \a id. - */ -int QmlMetaType::qmlListType(int id) -{ - QReadLocker lock(metaTypeDataLock()); - QmlMetaTypeData *data = metaTypeData(); - QmlType *type = data->idToType.value(id); - if (type && type->qmlListTypeId() == id) - return type->typeId(); - else - return 0; -} - -bool QmlMetaType::clear(const QVariant &list) -{ - int userType = list.userType(); - QReadLocker lock(metaTypeDataLock()); - QmlMetaTypeData *data = metaTypeData(); - QmlType *type = data->idToType.value(userType); - lock.unlock(); - if (type && type->qListTypeId() == userType) { - type->listClear(list); - return true; - } else { - return false; - } -} - -bool QmlMetaType::append(const QVariant &list, const QVariant &item) -{ - int userType = list.userType(); - QReadLocker lock(metaTypeDataLock()); - QmlMetaTypeData *data = metaTypeData(); - QmlType *type = data->idToType.value(userType); - lock.unlock(); - if (type && type->qListTypeId() == userType && - item.userType() == type->typeId()) { - type->listAppend(list, item); - return true; - } else { - return false; - } -} - int QmlMetaType::attachedPropertiesFuncId(const QMetaObject *mo) { QReadLocker lock(metaTypeDataLock()); @@ -656,8 +552,6 @@ QmlMetaType::TypeCategory QmlMetaType::typeCategory(int userType) QmlMetaTypeData *data = metaTypeData(); if (userType < data->objects.size() && data->objects.testBit(userType)) return Object; - else if (userType < data->qmllists.size() && data->qmllists.testBit(userType)) - return QmlList; else if (userType < data->lists.size() && data->lists.testBit(userType)) return List; else @@ -683,13 +577,6 @@ const char *QmlMetaType::interfaceIId(int userType) return 0; } -bool QmlMetaType::isQmlList(int userType) -{ - QReadLocker lock(metaTypeDataLock()); - QmlMetaTypeData *data = metaTypeData(); - return userType >= 0 && userType < data->qmllists.size() && data->qmllists.testBit(userType); -} - bool QmlMetaType::isList(int userType) { QReadLocker lock(metaTypeDataLock()); @@ -697,44 +584,6 @@ bool QmlMetaType::isList(int userType) return userType >= 0 && userType < data->lists.size() && data->lists.testBit(userType); } -bool QmlMetaType::isList(const QVariant &v) -{ - return (v.type() == QVariant::UserType && isList(v.userType())); -} - -int QmlMetaType::listCount(const QVariant &v) -{ - int userType = v.userType(); - - QReadLocker lock(metaTypeDataLock()); - QmlMetaTypeData *data = metaTypeData(); - QmlType *type = data->idToType.value(userType); - lock.unlock(); - - if (type && type->qListTypeId() == userType) - return type->listCount(v); - else - return 0; -} - -QVariant QmlMetaType::listAt(const QVariant &v, int idx) -{ - if (idx < 0) - return QVariant(); - - int userType = v.userType(); - - QReadLocker lock(metaTypeDataLock()); - QmlMetaTypeData *data = metaTypeData(); - QmlType *type = data->idToType.value(userType); - lock.unlock(); - - if (type && type->qListTypeId() == userType) - return type->listAt(v, idx); - else - return QVariant(); -} - /*! A custom string convertor allows you to specify a function pointer that returns a variant of \a type. For example, if you have written your own icon diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h index 3d082f8..98d04c1 100644 --- a/src/declarative/qml/qmlmetatype.h +++ b/src/declarative/qml/qmlmetatype.h @@ -46,6 +46,7 @@ #include "qmlparserstatus.h" #include "qmlpropertyvaluesource.h" #include "qmlpropertyvalueinterceptor.h" +#include "qmllist.h" #include #include @@ -62,8 +63,8 @@ class QmlCustomParser; class Q_DECLARATIVE_EXPORT QmlMetaType { public: - static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, int vmaj, int vmin, const char *qmlName, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, int valueSource, int valueInterceptor, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *); - static int registerInterface(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *); + static int registerType(const QmlPrivate::MetaTypeIds &, QObject *(*)(), const char *, int vmaj, int vmin, const char *qmlName, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, int valueSource, int valueInterceptor, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *); + static int registerInterface(const QmlPrivate::MetaTypeIds &, const char *); static bool copy(int type, void *data, const void *copy = 0); @@ -83,22 +84,15 @@ public: static QObject *toQObject(const QVariant &, bool *ok = 0); static int listType(int); - static bool clear(const QVariant &); - static bool append(const QVariant &, const QVariant &); static int attachedPropertiesFuncId(const QMetaObject *); static QmlAttachedPropertiesFunc attachedPropertiesFuncById(int); - enum TypeCategory { Unknown, Object, List, QmlList }; + enum TypeCategory { Unknown, Object, List }; static TypeCategory typeCategory(int); static bool isInterface(int); static const char *interfaceIId(int); static bool isList(int); - static bool isList(const QVariant &); - static bool isQmlList(int); - static int qmlListType(int); - static int listCount(const QVariant &); - static QVariant listAt(const QVariant &, int); typedef QVariant (*StringConverter)(const QString &); static void registerCustomStringConverter(int, StringConverter); @@ -123,12 +117,6 @@ public: bool isInterface() const; int typeId() const; int qListTypeId() const; - int qmlListTypeId() const; - - void listClear(const QVariant &); - void listAppend(const QVariant &, const QVariant &); - QVariant listAt(const QVariant &, int); - int listCount(const QVariant &); const QMetaObject *metaObject() const; const QMetaObject *baseMetaObject() const; @@ -147,8 +135,8 @@ private: friend class QmlMetaType; friend class QmlTypePrivate; friend struct QmlMetaTypeData; - QmlType(int, int, int, QmlPrivate::Func, const char *, int); - QmlType(int, int, int, QmlPrivate::Func, const char *, int, int, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, int, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *); + QmlType(int, int, const char *, int); + QmlType(int, int, QObject *(*)(), const char *, int, int, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, int, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *); ~QmlType(); QmlTypePrivate *d; @@ -160,11 +148,10 @@ int qmlRegisterType(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), }; - return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op, 0, 0, 0, 0, + return QmlMetaType::registerType(ids, 0, 0, 0, 0, 0, &T::staticMetaObject, QmlPrivate::attachedPropertiesFunc(), QmlPrivate::attachedPropertiesMetaObject(), @@ -181,11 +168,10 @@ int qmlRegisterType(const char *uri, int version_maj, int version_min, const cha QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), }; - return QmlMetaType::registerType(ids, QmlPrivate::list_op, + return QmlMetaType::registerType(ids, QmlPrivate::create, uri, version_maj, version_min, qmlName, &T::staticMetaObject, QmlPrivate::attachedPropertiesFunc(), @@ -203,8 +189,7 @@ int qmlRegisterExtendedType(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), }; QmlAttachedPropertiesFunc attached = @@ -216,7 +201,7 @@ int qmlRegisterExtendedType(const char *typeName) attachedMo = QmlPrivate::attachedPropertiesMetaObject(); } - return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op, 0, 0, 0, 0, + return QmlMetaType::registerType(ids, 0, 0, 0, 0, 0, &T::staticMetaObject, attached, attachedMo, QmlPrivate::StaticCastSelector::cast(), QmlPrivate::StaticCastSelector::cast(), @@ -231,8 +216,7 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min, c QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), }; QmlAttachedPropertiesFunc attached = @@ -244,7 +228,7 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min, c attachedMo = QmlPrivate::attachedPropertiesMetaObject(); } - return QmlMetaType::registerType(ids, QmlPrivate::list_op, + return QmlMetaType::registerType(ids, QmlPrivate::create, uri, version_maj, version_min, qmlName, &T::staticMetaObject, attached, attachedMo, @@ -262,13 +246,10 @@ int qmlRegisterInterface(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), }; - return QmlMetaType::registerInterface(ids, - QmlPrivate::list_interface_op, - qobject_interface_iid()); + return QmlMetaType::registerInterface(ids, qobject_interface_iid()); } template @@ -277,11 +258,10 @@ int qmlRegisterCustomType(const char *uri, int version_maj, int version_min, con QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), }; - return QmlMetaType::registerType(ids, QmlPrivate::list_op, + return QmlMetaType::registerType(ids, QmlPrivate::create, uri, version_maj, version_min, qmlName, &T::staticMetaObject, QmlPrivate::attachedPropertiesFunc(), diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp index 76d1837..15ece1d 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -239,9 +239,7 @@ QmlObjectScriptClass::property(QObject *obj, const Identifier &name) } if (lastData->flags & QmlPropertyCache::Data::IsQList) { - return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, QmlListScriptClass::QListPtr, lastData->propType)); - } else if (lastData->flags & QmlPropertyCache::Data::IsQmlList) { - return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, QmlListScriptClass::QmlListPtr, lastData->propType)); + return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, lastData->propType)); } else if (lastData->flags & QmlPropertyCache::Data::IsQObjectDerived) { QObject *rv = 0; void *args[] = { &rv, 0 }; diff --git a/src/declarative/qml/qmlprivate.h b/src/declarative/qml/qmlprivate.h index e087788..e5ea07f 100644 --- a/src/declarative/qml/qmlprivate.h +++ b/src/declarative/qml/qmlprivate.h @@ -72,39 +72,8 @@ public: namespace QmlPrivate { - class ListInterface - { - public: - virtual ~ListInterface() {} - virtual int type() const = 0; - virtual void append(void *) = 0; - virtual void insert(int, void *) = 0; - virtual void removeAt(int) = 0; - virtual void at(int, void *) const = 0; - virtual int count() const = 0; - virtual void clear() = 0; - }; - - enum ListOp { Append, Set, Insert, Prepend, Length, FromObject, - Object, Create, Value, Clear }; - template - int list_op(ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out); - - template - int list_nocreate_op(ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out); - - template - int list_interface_op(ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out); + QObject *create() { return new T; } template struct StaticCastSelectorClass @@ -201,9 +170,7 @@ namespace QmlPrivate struct MetaTypeIds { int typeId; int listId; - int qmlListId; }; - typedef int (*Func)(QmlPrivate::ListOp, int, const QVariant &, const QVariant &, void **); typedef QObject *(*CreateFunc)(QObject *); template @@ -237,148 +204,6 @@ namespace QmlPrivate }; } -template -int QmlPrivate::list_op(QmlPrivate::ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out) -{ - if (op == QmlPrivate::Create) { - QObject *obj = static_cast(new T); - *((QObject **)out) = obj; - return 0; - } - QList *list = vlist.value *>(); - switch(op) { - case QmlPrivate::Append: - list->append(value.value()); - break; - case QmlPrivate::Set: - (*list)[val] = value.value(); - break; - case QmlPrivate::Insert: - list->insert(val, value.value()); - break; - case QmlPrivate::Prepend: - list->prepend(value.value()); - break; - case QmlPrivate::Length: - return list->count(); - break; - case QmlPrivate::Clear: - list->clear(); - return 0; - break; - case QmlPrivate::Create: - break; - case QmlPrivate::Object: - *out = static_cast(value.value()); - break; - case QmlPrivate::FromObject: - { - QObject *fromObj = value.value(); - T *me = qobject_cast(fromObj); - if (me) { - *((QVariant *)*out) = QVariant::fromValue(me); - } - } - break; - case QmlPrivate::Value: - if (list->count() <= val) *((QVariant *)*out) = QVariant(); - else *((QVariant *)*out) = QVariant::fromValue(list->at(val)); - break; - } - return 0; -} - -template -int QmlPrivate::list_nocreate_op(QmlPrivate::ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out) -{ - QList *list = vlist.value *>(); - switch(op) { - case QmlPrivate::Append: - list->append(value.value()); - break; - case QmlPrivate::Set: - (*list)[val] = value.value(); - break; - case QmlPrivate::Insert: - list->insert(val, value.value()); - break; - case QmlPrivate::Prepend: - list->prepend(value.value()); - break; - case QmlPrivate::Length: - return list->count(); - break; - case QmlPrivate::Clear: - list->clear(); - return 0; - break; - case QmlPrivate::Create: - break; - case QmlPrivate::Object: - *out = static_cast(value.value()); - break; - case QmlPrivate::FromObject: - { - QObject *fromObj = value.value(); - T *me = qobject_cast(fromObj); - if (me) { - *((QVariant *)*out) = QVariant::fromValue(me); - } - } - break; - case QmlPrivate::Value: - *((QVariant *)*out) = QVariant::fromValue(list->at(val)); - break; - } - return 0; -} - -template -int QmlPrivate::list_interface_op(QmlPrivate::ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out) -{ - QList *list = vlist.value *>(); - switch(op) { - case QmlPrivate::Append: - list->append(value.value()); - break; - case QmlPrivate::Set: - (*list)[val] = value.value(); - break; - case QmlPrivate::Insert: - list->insert(val, value.value()); - break; - case QmlPrivate::Prepend: - list->prepend(value.value()); - break; - case QmlPrivate::Length: - return list->count(); - break; - case QmlPrivate::Clear: - list->clear(); - return 0; - break; - case QmlPrivate::Create: - break; - case QmlPrivate::Object: - break; - case QmlPrivate::FromObject: - break; - case QmlPrivate::Value: - *((QVariant *)*out) = QVariant::fromValue(list->at(val)); - break; - } - return 0; -} - QT_END_NAMESPACE QT_END_HEADER diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index e567fd2..a3e655b 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -77,8 +77,6 @@ void QmlPropertyCache::Data::load(const QMetaProperty &p, QmlEngine *engine) flags |= Data::IsQObjectDerived; else if (cat == QmlMetaType::List) flags |= Data::IsQList; - else if (cat == QmlMetaType::QmlList) - flags |= Data::IsQmlList; } } diff --git a/src/declarative/qml/qmlpropertycache_p.h b/src/declarative/qml/qmlpropertycache_p.h index 34b648d..18eea80 100644 --- a/src/declarative/qml/qmlpropertycache_p.h +++ b/src/declarative/qml/qmlpropertycache_p.h @@ -86,7 +86,6 @@ public: IsFunction = 0x00000008, IsQObjectDerived = 0x00000010, IsEnumType = 0x00000020, - IsQmlList = 0x00000040, IsQList = 0x00000080, IsQmlBinding = 0x00000100, IsQScriptValue = 0x00000200, diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 39de062..8655809 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -91,15 +91,13 @@ QmlVME::QmlVME() struct ListInstance { - ListInstance() {} - ListInstance(QList *q, int t) - : type(t), qListInterface(q), qmlListInterface(0) {} - ListInstance(QmlPrivate::ListInterface *q, int t) - : type(t), qListInterface(0), qmlListInterface(q) {} + ListInstance() + : type(0) {} + ListInstance(int t) + : type(t) {} int type; - QList *qListInterface; - QmlPrivate::ListInterface *qmlListInterface; + QmlListProperty qListProperty; }; QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledData *comp, @@ -654,22 +652,12 @@ QObject *QmlVME::run(QmlVMEStack &stack, QmlContext *ctxt, } break; - case QmlInstruction::StoreObjectQmlList: - { - QObject *assign = stack.pop(); - const ListInstance &list = qliststack.top(); - - void *d = (void *)&assign; - list.qmlListInterface->append(d); - } - break; - case QmlInstruction::StoreObjectQList: { QObject *assign = stack.pop(); const ListInstance &list = qliststack.top(); - list.qListInterface->append((void *)assign); + list.qListProperty.append((QmlListProperty*)&list.qListProperty, assign); } break; @@ -690,12 +678,7 @@ QObject *QmlVME::run(QmlVMEStack &stack, QmlContext *ctxt, VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign object to list")); - if (list.qmlListInterface) { - void *d = (void *)&ptr; - list.qmlListInterface->append(d); - } else { - list.qListInterface->append(ptr); - } + list.qListProperty.append((QmlListProperty*)&list.qListProperty, ptr); } break; @@ -750,39 +733,16 @@ QObject *QmlVME::run(QmlVMEStack &stack, QmlContext *ctxt, } break; - case QmlInstruction::FetchQmlList: - { - QObject *target = stack.top(); - - void *a[1]; - // We know that QmlList<*> can be converted to - // QmlPrivate::ListInterface - QmlPrivate::ListInterface *list = 0; - a[0] = &list; - QMetaObject::metacall(target, QMetaObject::ReadProperty, - instr.fetchQmlList.property, a); - if (!list) - VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign to null list")); - - qliststack.push(ListInstance(list, instr.fetchQmlList.type)); - } - break; - case QmlInstruction::FetchQList: { QObject *target = stack.top(); + qliststack.push(ListInstance(instr.fetchQmlList.type)); + void *a[1]; - // We know that QList* can be converted to - // QList* - QList *list = 0; - a[0] = &list; + a[0] = (void *)&(qliststack.top().qListProperty); QMetaObject::metacall(target, QMetaObject::ReadProperty, instr.fetchQmlList.property, a); - if (!list) - VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign to null list")); - - qliststack.push(ListInstance(list, instr.fetchQmlList.type)); } break; diff --git a/src/declarative/qml/qmlvmemetaobject.cpp b/src/declarative/qml/qmlvmemetaobject.cpp index 3858138..4886680 100644 --- a/src/declarative/qml/qmlvmemetaobject.cpp +++ b/src/declarative/qml/qmlvmemetaobject.cpp @@ -77,13 +77,14 @@ QmlVMEMetaObject::QmlVMEMetaObject(QObject *obj, data = new QVariant[metaData->propertyCount]; aConnected.resize(metaData->aliasCount); - int list_type = qMetaTypeId* >(); + int list_type = qMetaTypeId >(); // ### Optimize for (int ii = 0; ii < metaData->propertyCount; ++ii) { int t = (metaData->propertyData() + ii)->propertyType; if (t == list_type) { - listProperties.append(new List(this, ii)); - data[ii] = QVariant::fromValue((QmlList*)listProperties.last()); + listProperties.append(new List(methodOffset + ii)); + data[ii] = QVariant::fromValue(QmlListProperty(obj, listProperties.last(), list_append, + list_count, list_at, list_clear)); } else if (t != -1) { data[ii] = QVariant((QVariant::Type)t); } @@ -182,8 +183,9 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) default: break; } - if (t == qMetaTypeId* >()) { - *reinterpret_cast **>(a[0]) = data[id].value*>(); + if (t == qMetaTypeId >()) { + *reinterpret_cast *>(a[0]) = + data[id].value >(); } } else if (c == QMetaObject::WriteProperty) { @@ -318,6 +320,30 @@ void QmlVMEMetaObject::listChanged(int id) activate(object, methodOffset + id, 0); } +void QmlVMEMetaObject::list_append(QmlListProperty *prop, QObject *o) +{ + List *list = static_cast(prop->data); + list->append(o); + QMetaObject::activate(prop->object, list->notifyIndex, 0); +} + +int QmlVMEMetaObject::list_count(QmlListProperty *prop) +{ + return static_cast(prop->data)->count(); +} + +QObject *QmlVMEMetaObject::list_at(QmlListProperty *prop, int index) +{ + return static_cast(prop->data)->at(index); +} + +void QmlVMEMetaObject::list_clear(QmlListProperty *prop) +{ + List *list = static_cast(prop->data); + list->clear(); + QMetaObject::activate(prop->object, list->notifyIndex, 0); +} + void QmlVMEMetaObject::registerInterceptor(int index, int valueIndex, QmlPropertyValueInterceptor *interceptor) { if (aInterceptors.isEmpty()) diff --git a/src/declarative/qml/qmlvmemetaobject_p.h b/src/declarative/qml/qmlvmemetaobject_p.h index 7fa46fd..3eb776e 100644 --- a/src/declarative/qml/qmlvmemetaobject_p.h +++ b/src/declarative/qml/qmlvmemetaobject_p.h @@ -138,33 +138,18 @@ private: QAbstractDynamicMetaObject *parent; void listChanged(int); - class List : public QmlConcreteList + class List : public QList { public: - List(QmlVMEMetaObject *p, int propIdx) - : parent(p), parentProperty(propIdx) { } - - virtual void append(QObject *v) { - QmlConcreteList::append(v); - parent->listChanged(parentProperty); - } - virtual void insert(int i, QObject *v) { - QmlConcreteList::insert(i, v); - parent->listChanged(parentProperty); - } - virtual void clear() { - QmlConcreteList::clear(); - parent->listChanged(parentProperty); - } - virtual void removeAt(int i) { - QmlConcreteList::removeAt(i); - parent->listChanged(parentProperty); - } - private: - QmlVMEMetaObject *parent; - int parentProperty; + List(int lpi) : notifyIndex(lpi) {} + int notifyIndex; }; QList listProperties; + + static void list_append(QmlListProperty *, QObject *); + static int list_count(QmlListProperty *); + static QObject *list_at(QmlListProperty *, int); + static void list_clear(QmlListProperty *); }; QT_END_NAMESPACE diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index d7ddfce..c044f97 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -937,10 +937,10 @@ void QmlPropertyAction::setProperties(const QString &p) emit propertiesChanged(p); } -QList *QmlPropertyAction::targets() +QmlListProperty QmlPropertyAction::targets() { Q_D(QmlPropertyAction); - return &d->targets; + return QmlListProperty(this, d->targets); } /*! @@ -948,10 +948,10 @@ QList *QmlPropertyAction::targets() This property holds the objects not to be affected by this animation. \sa targets */ -QList *QmlPropertyAction::exclude() +QmlListProperty QmlPropertyAction::exclude() { Q_D(QmlPropertyAction); - return &d->exclude; + return QmlListProperty(this, d->exclude); } /*! @@ -1577,14 +1577,36 @@ QmlAnimationGroup::QmlAnimationGroup(QObject *parent) { } +void QmlAnimationGroupPrivate::append_animation(QmlListProperty *list, QmlAbstractAnimation *a) +{ + QmlAnimationGroup *q = qobject_cast(list->object); + if (q) { + q->d_func()->animations.append(a); + a->setGroup(q); + } +} + +void QmlAnimationGroupPrivate::clear_animation(QmlListProperty *list) +{ + QmlAnimationGroup *q = qobject_cast(list->object); + if (q) { + for (int i = 0; i < q->d_func()->animations.count(); ++i) + q->d_func()->animations.at(i)->setGroup(0); + q->d_func()->animations.clear(); + } +} + QmlAnimationGroup::~QmlAnimationGroup() { } -QmlList *QmlAnimationGroup::animations() +QmlListProperty QmlAnimationGroup::animations() { Q_D(QmlAnimationGroup); - return &d->animations; + QmlListProperty list(this, d->animations); + list.append = &QmlAnimationGroupPrivate::append_animation; + list.clear = &QmlAnimationGroupPrivate::clear_animation; + return list; } /*! @@ -2226,10 +2248,10 @@ void QmlPropertyAnimation::setProperties(const QString &prop) \sa exclude */ -QList *QmlPropertyAnimation::targets() +QmlListProperty QmlPropertyAnimation::targets() { Q_D(QmlPropertyAnimation); - return &d->targets; + return QmlListProperty(this, d->targets); } /*! @@ -2237,10 +2259,10 @@ QList *QmlPropertyAnimation::targets() This property holds the items not to be affected by this animation. \sa targets */ -QList *QmlPropertyAnimation::exclude() +QmlListProperty QmlPropertyAnimation::exclude() { Q_D(QmlPropertyAnimation); - return &d->exclude; + return QmlListProperty(this, d->exclude); } QAbstractAnimation *QmlPropertyAnimation::qtAnimation() diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 50eb577..623ad8d 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -190,8 +190,8 @@ class QmlPropertyAction : public QmlAbstractAnimation Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList* targets READ targets) - Q_PROPERTY(QList* exclude READ exclude) + Q_PROPERTY(QmlListProperty targets READ targets) + Q_PROPERTY(QmlListProperty exclude READ exclude) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) public: @@ -207,8 +207,8 @@ public: QString properties() const; void setProperties(const QString &); - QList *targets(); - QList *exclude(); + QmlListProperty targets(); + QmlListProperty exclude(); QVariant value() const; void setValue(const QVariant &); @@ -265,8 +265,8 @@ class Q_AUTOTEST_EXPORT QmlPropertyAnimation : public QmlAbstractAnimation Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList* targets READ targets) - Q_PROPERTY(QList* exclude READ exclude) + Q_PROPERTY(QmlListProperty targets READ targets) + Q_PROPERTY(QmlListProperty exclude READ exclude) public: QmlPropertyAnimation(QObject *parent=0); @@ -293,8 +293,8 @@ public: QString properties() const; void setProperties(const QString &); - QList *targets(); - QList *exclude(); + QmlListProperty targets(); + QmlListProperty exclude(); protected: QmlPropertyAnimation(QmlPropertyAnimationPrivate &dd, QObject *parent); @@ -404,13 +404,13 @@ class QmlAnimationGroup : public QmlAbstractAnimation Q_DECLARE_PRIVATE(QmlAnimationGroup) Q_CLASSINFO("DefaultProperty", "animations") - Q_PROPERTY(QmlList *animations READ animations) + Q_PROPERTY(QmlListProperty animations READ animations) public: QmlAnimationGroup(QObject *parent); virtual ~QmlAnimationGroup(); - QmlList* animations(); + QmlListProperty animations(); friend class QmlAbstractAnimation; }; diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index b2ce297..056ce82 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -304,37 +304,13 @@ class QmlAnimationGroupPrivate : public QmlAbstractAnimationPrivate Q_DECLARE_PUBLIC(QmlAnimationGroup) public: QmlAnimationGroupPrivate() - : QmlAbstractAnimationPrivate(), animations(this), ag(0) {} + : QmlAbstractAnimationPrivate(), ag(0) {} - struct AnimationList : public QmlConcreteList - { - AnimationList(QmlAnimationGroupPrivate *p) - : anim(p) {} - virtual void append(QmlAbstractAnimation *a) { - QmlConcreteList::append(a); - a->setGroup(anim->q_func()); - } - virtual void clear() - { - for (int i = 0; i < count(); ++i) - at(i)->setGroup(0); - QmlConcreteList::clear(); - } - virtual void removeAt(int i) - { - at(i)->setGroup(0); - QmlConcreteList::removeAt(i); - } - virtual void insert(int i, QmlAbstractAnimation *a) - { - QmlConcreteList::insert(i, a); - a->setGroup(anim->q_func()); - } - - QmlAnimationGroupPrivate *anim; - }; - - AnimationList animations; + static void append_animation(QmlListProperty *list, QmlAbstractAnimation *role); + static void clear_animation(QmlListProperty *list); + static void removeAt_animation(QmlListProperty *list, int i); + static void insert_animation(QmlListProperty *list, int i, QmlAbstractAnimation *role); + QList animations; QAnimationGroup *ag; }; diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index c1b9247..abdb626 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -84,11 +84,8 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) QObject *data = enginePrivate?enginePrivate->toQObject(v):QmlMetaType::toQObject(v); d = QVariant::fromValue(data); m_type = Instance; - } else if ((!enginePrivate && QmlMetaType::isQmlList(d.userType())) || - (enginePrivate && enginePrivate->isQmlList(d.userType()))) { - m_type = QmlList; - } else if (QmlMetaType::isList(d.userType())) { - m_type = QListPtr; + } else if (d.userType() == qMetaTypeId()) { + m_type = ListProperty; } else { m_type = Instance; } @@ -101,16 +98,8 @@ int QmlListAccessor::count() const return qvariant_cast(d).count(); case VariantList: return qvariant_cast(d).count(); - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - return li->count(); - } - case QListPtr: - { - QList *li = *(QList **)d.constData(); - return li->count(); - } + case ListProperty: + return ((QmlListReference *)d.constData())->count(); case Instance: return 1; case Integer: @@ -129,19 +118,8 @@ QVariant QmlListAccessor::at(int idx) const return QVariant::fromValue(qvariant_cast(d).at(idx)); case VariantList: return qvariant_cast(d).at(idx); - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - void *ptr[1]; - li->at(idx, ptr); - return QVariant::fromValue((QObject*)ptr[0]); - } - case QListPtr: - { - QList *li = *(QList **)d.constData(); - void *ptr = li->at(idx); - return QVariant::fromValue((QObject*)ptr); - } + case ListProperty: + return QVariant::fromValue(((QmlListReference *)d.constData())->at(idx)); case Instance: return d; case Integer: @@ -152,106 +130,6 @@ QVariant QmlListAccessor::at(int idx) const } } -bool QmlListAccessor::append(const QVariant &value) -{ - switch(m_type) { - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->append(const_cast(value.constData())); //XXX Typesafety - return true; - } - case QListPtr: - { - QList *li = *(QList **)d.constData(); - li->append(*reinterpret_cast(const_cast(value.constData()))); //XXX Typesafety - return true; - } - case StringList: - case VariantList: - case Invalid: - case Instance: - case Integer: - default: - return false; - } -} - -bool QmlListAccessor::insert(int index, const QVariant &value) -{ - switch(m_type) { - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->insert(index, const_cast(value.constData())); //XXX Typesafety - return true; - } - case QListPtr: - { - QList *li = *(QList**)d.constData(); - li->insert(index, *reinterpret_cast(const_cast(value.constData()))); //XXX Typesafety - return true; - } - case StringList: - case VariantList: - case Invalid: - case Instance: - case Integer: - default: - return false; - } -} - -bool QmlListAccessor::removeAt(int index) -{ - switch(m_type) { - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->removeAt(index); - return true; - } - case QListPtr: - { - QList *li = *(QList**)d.constData(); - li->removeAt(index); - return true; - } - case StringList: - case VariantList: - case Invalid: - case Instance: - case Integer: - default: - return false; - } -} - -bool QmlListAccessor::clear() -{ - switch(m_type) { - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->clear(); - return true; - } - case QListPtr: - { - QList *li = *(QList**)d.constData(); - li->clear(); - return true; - } - case StringList: - case VariantList: - case Invalid: - case Instance: - case Integer: - default: - return false; - } -} - bool QmlListAccessor::isValid() const { return m_type != Invalid; diff --git a/src/declarative/util/qmllistaccessor_p.h b/src/declarative/util/qmllistaccessor_p.h index 8a0b06c..611eebb 100644 --- a/src/declarative/util/qmllistaccessor_p.h +++ b/src/declarative/util/qmllistaccessor_p.h @@ -65,12 +65,7 @@ public: int count() const; QVariant at(int) const; - bool append(const QVariant &); - bool insert(int, const QVariant &); - bool removeAt(int); - bool clear(); - - enum Type { Invalid, StringList, VariantList, QmlList, QListPtr, Instance, Integer }; + enum Type { Invalid, StringList, VariantList, ListProperty, Instance, Integer }; Type type() const { return m_type; } private: diff --git a/src/declarative/util/qmlpackage.cpp b/src/declarative/util/qmlpackage.cpp index 115f2fd..82f776f 100644 --- a/src/declarative/util/qmlpackage.cpp +++ b/src/declarative/util/qmlpackage.cpp @@ -51,28 +51,33 @@ class QmlPackagePrivate : public QObjectPrivate public: QmlPackagePrivate() {} - class DataList; struct DataGuard : public QmlGuard { - DataGuard(QObject *obj, DataList *l) : list(l) { (QmlGuard&)*this = obj; } - DataList *list; + DataGuard(QObject *obj, QList *l) : list(l) { (QmlGuard&)*this = obj; } + QList *list; void objectDestroyed(QObject *) { // we assume priv will always be destroyed after objectDestroyed calls list->removeOne(*this); } }; - class DataList : public QList, public QmlList - { - public: - virtual void append(QObject* v) { QList::append(DataGuard(v, this)); } - virtual void insert(int i, QObject* v) { QList::insert(i, DataGuard(v, this)); } - virtual void clear() { QList::clear(); } - virtual QObject* at(int i) const { return QList::at(i); } - virtual void removeAt(int i) { QList::removeAt(i); } - virtual int count() const { return QList::count(); } - }; - DataList dataList; + QList dataList; + static void data_append(QmlListProperty *prop, QObject *o) { + QList *list = static_cast *>(prop->data); + list->append(DataGuard(o, list)); + } + static void data_clear(QmlListProperty *prop) { + QList *list = static_cast *>(prop->data); + list->clear(); + } + static QObject *data_at(QmlListProperty *prop, int index) { + QList *list = static_cast *>(prop->data); + return list->at(index); + } + static int data_count(QmlListProperty *prop) { + QList *list = static_cast *>(prop->data); + return list->count(); + } }; class QmlPackageAttached : public QObject @@ -128,10 +133,13 @@ QmlPackage::~QmlPackage() } } -QmlList *QmlPackage::data() +QmlListProperty QmlPackage::data() { Q_D(QmlPackage); - return &d->dataList; + return QmlListProperty(this, &d->dataList, QmlPackagePrivate::data_append, + QmlPackagePrivate::data_count, + QmlPackagePrivate::data_at, + QmlPackagePrivate::data_clear); } bool QmlPackage::hasPart(const QString &name) diff --git a/src/declarative/util/qmlpackage_p.h b/src/declarative/util/qmlpackage_p.h index 2538bb9..29b6bbe 100644 --- a/src/declarative/util/qmlpackage_p.h +++ b/src/declarative/util/qmlpackage_p.h @@ -64,13 +64,13 @@ class QmlPackage : public QObject Q_DECLARE_PRIVATE(QmlPackage) Q_CLASSINFO("DefaultProperty", "data") - Q_PROPERTY(QmlList *data READ data SCRIPTABLE false) + Q_PROPERTY(QmlListProperty data READ data SCRIPTABLE false) public: QmlPackage(QObject *parent=0); virtual ~QmlPackage(); - QmlList *data(); + QmlListProperty data(); QObject *part(const QString & = QString()); bool hasPart(const QString &); diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index 7ecbd79..4462b1f 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -242,16 +242,30 @@ void QmlState::setExtends(const QString &extends) extends another state, then the changes are applied against the state being extended. */ -QmlList *QmlState::changes() +QmlListProperty QmlState::changes() { Q_D(QmlState); - return &d->operations; + return QmlListProperty(this, &d->operations, QmlStatePrivate::operations_append, + QmlStatePrivate::operations_count, QmlStatePrivate::operations_at, + QmlStatePrivate::operations_clear); +} + +int QmlState::operationCount() const +{ + Q_D(const QmlState); + return d->operations.count(); +} + +QmlStateOperation *QmlState::operationAt(int index) const +{ + Q_D(const QmlState); + return d->operations.at(index); } QmlState &QmlState::operator<<(QmlStateOperation *op) { Q_D(QmlState); - d->operations.append(op); + d->operations.append(QmlStatePrivate::OperationGuard(op, &d->operations)); return *this; } diff --git a/src/declarative/util/qmlstate_p.h b/src/declarative/util/qmlstate_p.h index 785a175..2c92387 100644 --- a/src/declarative/util/qmlstate_p.h +++ b/src/declarative/util/qmlstate_p.h @@ -131,7 +131,7 @@ class Q_DECLARATIVE_EXPORT QmlState : public QObject Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QmlBinding *when READ when WRITE setWhen) Q_PROPERTY(QString extend READ extends WRITE setExtends) - Q_PROPERTY(QmlList* changes READ changes) + Q_PROPERTY(QmlListProperty changes READ changes) Q_CLASSINFO("DefaultProperty", "changes") Q_CLASSINFO("DeferredPropertyNames", "changes") @@ -151,7 +151,10 @@ public: QString extends() const; void setExtends(const QString &); - QmlList *changes(); + QmlListProperty changes(); + int operationCount() const; + QmlStateOperation *operationAt(int) const; + QmlState &operator<<(QmlStateOperation *); void apply(QmlStateGroup *, QmlTransition *, QmlState *revert); diff --git a/src/declarative/util/qmlstate_p_p.h b/src/declarative/util/qmlstate_p_p.h index c389846..d138e4e 100644 --- a/src/declarative/util/qmlstate_p_p.h +++ b/src/declarative/util/qmlstate_p_p.h @@ -107,28 +107,33 @@ public: QString name; QmlBinding *when; - class OperationList; struct OperationGuard : public QmlGuard { - OperationGuard(QObject *obj, OperationList *l) : list(l) { (QmlGuard&)*this = obj; } - OperationList *list; + OperationGuard(QObject *obj, QList *l) : list(l) { (QmlGuard&)*this = obj; } + QList *list; void objectDestroyed(QmlStateOperation *) { // we assume priv will always be destroyed after objectDestroyed calls list->removeOne(*this); } }; + QList operations; - class OperationList : public QList, public QmlList - { - public: - virtual void append(QmlStateOperation* v) { QList::append(OperationGuard(v, this)); } - virtual void insert(int i, QmlStateOperation* v) { QList::insert(i, OperationGuard(v, this)); } - virtual void clear() { QList::clear(); } - virtual QmlStateOperation* at(int i) const { return QList::at(i); } - virtual void removeAt(int i) { QList::removeAt(i); } - virtual int count() const { return QList::count(); } - }; - OperationList operations; + static void operations_append(QmlListProperty *prop, QmlStateOperation *op) { + QList *list = static_cast *>(prop->data); + list->append(OperationGuard(op, list)); + } + static void operations_clear(QmlListProperty *prop) { + QList *list = static_cast *>(prop->data); + list->clear(); + } + static int operations_count(QmlListProperty *prop) { + QList *list = static_cast *>(prop->data); + return list->count(); + } + static QmlStateOperation *operations_at(QmlListProperty *prop, int index) { + QList *list = static_cast *>(prop->data); + return list->at(index); + } QmlTransitionManager transitionManager; diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp index d289e17..4ad77c8 100644 --- a/src/declarative/util/qmlstategroup.cpp +++ b/src/declarative/util/qmlstategroup.cpp @@ -60,26 +60,19 @@ class QmlStateGroupPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlStateGroup) public: QmlStateGroupPrivate(QmlStateGroup *p) - : nullState(0), states(p), componentComplete(true), + : nullState(0), componentComplete(true), ignoreTrans(false), applyingState(false) {} QString currentState; QmlState *nullState; - struct StateList : public QmlConcreteList - { - StateList(QmlStateGroup *g) - :group(g) {} - void append(QmlState *s) { - QmlConcreteList::append(s); - if (s) s->setStateGroup(group); - } - private: - QmlStateGroup *group; - }; - StateList states; + static void append_state(QmlListProperty *list, QmlState *state); + static int count_state(QmlListProperty *list); + static QmlState *at_state(QmlListProperty *list, int index); + + QList states; + QList transitions; - QmlConcreteList transitions; bool componentComplete; bool ignoreTrans; bool applyingState; @@ -151,10 +144,34 @@ QList QmlStateGroup::states() const \sa {qmlstate}{States} */ -QmlList* QmlStateGroup::statesProperty() +QmlListProperty QmlStateGroup::statesProperty() { Q_D(QmlStateGroup); - return &(d->states); + return QmlListProperty(this, &d->states, &QmlStateGroupPrivate::append_state, + &QmlStateGroupPrivate::count_state, + &QmlStateGroupPrivate::at_state); +} + +void QmlStateGroupPrivate::append_state(QmlListProperty *list, QmlState *state) +{ + QmlStateGroup *_this = static_cast(list->object); + if (state) { + _this->d_func()->states.append(state); + state->setStateGroup(_this); + } + +} + +int QmlStateGroupPrivate::count_state(QmlListProperty *list) +{ + QmlStateGroup *_this = static_cast(list->object); + return _this->d_func()->states.count(); +} + +QmlState *QmlStateGroupPrivate::at_state(QmlListProperty *list, int index) +{ + QmlStateGroup *_this = static_cast(list->object); + return _this->d_func()->states.at(index); } /*! @@ -173,10 +190,10 @@ QmlList* QmlStateGroup::statesProperty() \sa {state-transitions}{Transitions} */ -QmlList* QmlStateGroup::transitionsProperty() +QmlListProperty QmlStateGroup::transitionsProperty() { Q_D(QmlStateGroup); - return &(d->transitions); + return QmlListProperty(this, d->transitions); } /*! diff --git a/src/declarative/util/qmlstategroup_p.h b/src/declarative/util/qmlstategroup_p.h index 48b9c66..d39ca03 100644 --- a/src/declarative/util/qmlstategroup_p.h +++ b/src/declarative/util/qmlstategroup_p.h @@ -58,8 +58,8 @@ class Q_DECLARATIVE_EXPORT QmlStateGroup : public QObject, public QmlParserStatu Q_DECLARE_PRIVATE(QmlStateGroup) Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(QmlList* states READ statesProperty DESIGNABLE false) - Q_PROPERTY(QmlList* transitions READ transitionsProperty DESIGNABLE false) + Q_PROPERTY(QmlListProperty states READ statesProperty DESIGNABLE false) + Q_PROPERTY(QmlListProperty transitions READ transitionsProperty DESIGNABLE false) public: QmlStateGroup(QObject * = 0); @@ -68,10 +68,10 @@ public: QString state() const; void setState(const QString &); - QmlList* statesProperty(); + QmlListProperty statesProperty(); QList states() const; - QmlList* transitionsProperty(); + QmlListProperty transitionsProperty(); QmlState *findState(const QString &name) const; diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp index e4e53d6..e90fc20 100644 --- a/src/declarative/util/qmltransition.cpp +++ b/src/declarative/util/qmltransition.cpp @@ -82,10 +82,10 @@ class QmlTransitionPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlTransition) public: - QmlTransitionPrivate() : fromState(QLatin1String("*")), toState(QLatin1String("*")) - , reversed(false), reversible(false), endState(0) + QmlTransitionPrivate() + : fromState(QLatin1String("*")), toState(QLatin1String("*")), + reversed(false), reversible(false), endState(0) { - animations.parent = this; group.trans = this; } @@ -100,23 +100,15 @@ public: { endState->complete(); } - - class AnimationList : public QmlConcreteList - { - public: - AnimationList() : parent(0) {} - virtual void append(QmlAbstractAnimation *a); - virtual void clear() { QmlConcreteList::clear(); } //### - - QmlTransitionPrivate *parent; - }; - AnimationList animations; + static void append_animation(QmlListProperty *list, QmlAbstractAnimation *a); + QList animations; }; -void QmlTransitionPrivate::AnimationList::append(QmlAbstractAnimation *a) +void QmlTransitionPrivate::append_animation(QmlListProperty *list, QmlAbstractAnimation *a) { - QmlConcreteList::append(a); - parent->group.addAnimation(a->qtAnimation()); + QmlTransition *q = static_cast(list->object); + q->d_func()->animations.append(a); + q->d_func()->group.addAnimation(a->qtAnimation()); a->setDisableUserControl(); } @@ -245,10 +237,10 @@ void QmlTransition::setToState(const QString &t) and assign that to animations the animations property. \default */ -QmlList* QmlTransition::animations() +QmlListProperty QmlTransition::animations() { Q_D(QmlTransition); - return &d->animations; + return QmlListProperty(this, &d->animations, QmlTransitionPrivate::append_animation); } QT_END_NAMESPACE diff --git a/src/declarative/util/qmltransition_p.h b/src/declarative/util/qmltransition_p.h index 5a989bc..ea02a33 100644 --- a/src/declarative/util/qmltransition_p.h +++ b/src/declarative/util/qmltransition_p.h @@ -65,7 +65,7 @@ class Q_DECLARATIVE_EXPORT QmlTransition : public QObject Q_PROPERTY(QString from READ fromState WRITE setFromState) Q_PROPERTY(QString to READ toState WRITE setToState) Q_PROPERTY(bool reversible READ reversible WRITE setReversible) - Q_PROPERTY(QmlList* animations READ animations) + Q_PROPERTY(QmlListProperty animations READ animations) Q_CLASSINFO("DefaultProperty", "animations") Q_CLASSINFO("DeferredPropertyNames", "animations") @@ -82,7 +82,7 @@ public: bool reversible() const; void setReversible(bool); - QmlList* animations(); + QmlListProperty animations(); void prepare(QmlStateOperation::ActionList &actions, QList &after, diff --git a/src/declarative/util/qmlxmllistmodel.cpp b/src/declarative/util/qmlxmllistmodel.cpp index 0e939bf..e631cd9 100644 --- a/src/declarative/util/qmlxmllistmodel.cpp +++ b/src/declarative/util/qmlxmllistmodel.cpp @@ -130,19 +130,6 @@ QML_DECLARE_TYPE(QmlXmlListModelRole) QT_BEGIN_NAMESPACE -class QmlXmlListModelPrivate; -struct QmlXmlRoleList : public QmlConcreteList -{ - QmlXmlRoleList(QmlXmlListModelPrivate *p) - : model(p) {} - virtual void append(QmlXmlListModelRole *role); - virtual void clear(); - virtual void removeAt(int i); - virtual void insert(int i, QmlXmlListModelRole *role); - - QmlXmlListModelPrivate *model; -}; - class QmlXmlQuery : public QThread { Q_OBJECT @@ -164,7 +151,7 @@ public: m_abort = true; } - int doQuery(QString query, QString namespaces, QByteArray data, QmlXmlRoleList *roleObjects) { + int doQuery(QString query, QString namespaces, QByteArray data, QList *roleObjects) { QMutexLocker locker(&m_mutex); m_modelData.clear(); m_size = 0; @@ -229,7 +216,7 @@ private: QString m_prefix; int m_size; int m_queryId; - const QmlXmlRoleList *m_roleObjects; + const QList *m_roleObjects; QList > m_modelData; }; @@ -347,7 +334,7 @@ public: QmlXmlListModelPrivate() : isComponentComplete(true), size(-1), highestRole(Qt::UserRole) , reply(0), status(QmlXmlListModel::Null), progress(0.0) - , queryId(-1), roleObjects(this) {} + , queryId(-1), roleObjects() {} bool isComponentComplete; QUrl src; @@ -363,42 +350,39 @@ public: qreal progress; QmlXmlQuery qmlXmlQuery; int queryId; - QmlXmlRoleList roleObjects; + QList roleObjects; + static void append_role(QmlListProperty *list, QmlXmlListModelRole *role); + static void clear_role(QmlListProperty *list); + static void removeAt_role(QmlListProperty *list, int i); + static void insert_role(QmlListProperty *list, int i, QmlXmlListModelRole *role); QList > data; }; -void QmlXmlRoleList::append(QmlXmlListModelRole *role) +void QmlXmlListModelPrivate::append_role(QmlListProperty *list, QmlXmlListModelRole *role) { - insert(size(), role); + QmlXmlListModel *_this = qobject_cast(list->object); + if (_this) { + int i = _this->d_func()->roleObjects.count(); + _this->d_func()->roleObjects.append(role); + if (_this->d_func()->roleNames.contains(role->name())) { + qmlInfo(role) << QObject::tr("\"%1\" duplicates a previous role name and will be disabled.").arg(role->name()); + return; + } + _this->d_func()->roles.insert(i, _this->d_func()->highestRole); + _this->d_func()->roleNames.insert(i, role->name()); + ++_this->d_func()->highestRole; + } } -//### clear, removeAt, and insert need to invalidate any cached data (in data table) as well +//### clear needs to invalidate any cached data (in data table) as well // (and the model should emit the appropriate signals) -void QmlXmlRoleList::clear() -{ - model->roles.clear(); - model->roleNames.clear(); - QmlConcreteList::clear(); -} - -void QmlXmlRoleList::removeAt(int i) +void QmlXmlListModelPrivate::clear_role(QmlListProperty *list) { - model->roles.removeAt(i); - model->roleNames.removeAt(i); - QmlConcreteList::removeAt(i); -} - -void QmlXmlRoleList::insert(int i, QmlXmlListModelRole *role) -{ - QmlConcreteList::insert(i, role); - if (model->roleNames.contains(role->name())) { - qmlInfo(role) << QCoreApplication::translate("QmlXmlRoleList", "\"%1\" duplicates a previous role name and will be disabled.").arg(role->name()); - return; - } - model->roles.insert(i, model->highestRole); - model->roleNames.insert(i, role->name()); - ++model->highestRole; + QmlXmlListModel *_this = static_cast(list->object); + _this->d_func()->roles.clear(); + _this->d_func()->roleNames.clear(); + _this->d_func()->roleObjects.clear(); } /*! @@ -446,10 +430,13 @@ QmlXmlListModel::~QmlXmlListModel() The roles to make available for this model. */ -QmlList *QmlXmlListModel::roleObjects() +QmlListProperty QmlXmlListModel::roleObjects() { Q_D(QmlXmlListModel); - return &d->roleObjects; + QmlListProperty list(this, d->roleObjects); + list.append = &QmlXmlListModelPrivate::append_role; + list.clear = &QmlXmlListModelPrivate::clear_role; + return list; } QHash QmlXmlListModel::data(int index, const QList &roles) const diff --git a/src/declarative/util/qmlxmllistmodel_p.h b/src/declarative/util/qmlxmllistmodel_p.h index 51d942d..a6627e2 100644 --- a/src/declarative/util/qmlxmllistmodel_p.h +++ b/src/declarative/util/qmlxmllistmodel_p.h @@ -70,7 +70,7 @@ class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public Q_PROPERTY(QString xml READ xml WRITE setXml) Q_PROPERTY(QString query READ query WRITE setQuery) Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) - Q_PROPERTY(QmlList *roles READ roleObjects) + Q_PROPERTY(QmlListProperty roles READ roleObjects) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_CLASSINFO("DefaultProperty", "roles") @@ -84,7 +84,7 @@ public: virtual QList roles() const; virtual QString toString(int role) const; - QmlList *roleObjects(); + QmlListProperty roleObjects(); QUrl source() const; void setSource(const QUrl&); diff --git a/src/declarative/widgets/graphicslayouts.cpp b/src/declarative/widgets/graphicslayouts.cpp index a8b5f70..62e941a 100644 --- a/src/declarative/widgets/graphicslayouts.cpp +++ b/src/declarative/widgets/graphicslayouts.cpp @@ -109,7 +109,7 @@ QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, cons QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) -: QObject(parent), _children(this) +: QObject(parent) { } @@ -246,7 +246,7 @@ private: QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) -: QObject(parent), _children(this) +: QObject(parent) { } diff --git a/src/declarative/widgets/graphicslayouts_p.h b/src/declarative/widgets/graphicslayouts_p.h index 030be90..3076af1 100644 --- a/src/declarative/widgets/graphicslayouts_p.h +++ b/src/declarative/widgets/graphicslayouts_p.h @@ -69,7 +69,7 @@ class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout Q_OBJECT Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - Q_PROPERTY(QmlList *children READ children) + Q_PROPERTY(QmlListProperty children READ children) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) Q_CLASSINFO("DefaultProperty", "children") @@ -77,7 +77,7 @@ public: QGraphicsLinearLayoutObject(QObject * = 0); ~QGraphicsLinearLayoutObject(); - QmlList *children() { return &_children; } + QmlListProperty children() { return QmlListProperty(this, 0, children_append, children_count, children_at, children_clear); } static LinearLayoutAttached *qmlAttachedProperties(QObject *); @@ -91,27 +91,21 @@ private: void insertLayoutItem(int, QGraphicsLayoutItem *); static QHash attachedProperties; - class ChildList : public QmlList - { - public: - ChildList(QGraphicsLinearLayoutObject *o) - : obj(o) {} - - virtual void append(QGraphicsLayoutItem *item) - { - insert(-1, item); - } - virtual void clear() { obj->clearChildren(); } - virtual int count() const { return obj->count(); } - virtual void removeAt(int i) { obj->removeAt(i); } - virtual QGraphicsLayoutItem *at(int i) const { return obj->itemAt(i); } - virtual void insert(int i, QGraphicsLayoutItem *item) { obj->insertLayoutItem(i, item); } - - private: - QGraphicsLinearLayoutObject *obj; - }; - - ChildList _children; + static void children_append(QmlListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->insertLayoutItem(-1, item); + } + + static void children_clear(QmlListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QmlListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QmlListProperty *prop, int index) { + return static_cast(prop->object)->itemAt(index); + } }; class GridLayoutAttached; @@ -120,7 +114,7 @@ class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout Q_OBJECT Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) - Q_PROPERTY(QmlList *children READ children) + Q_PROPERTY(QmlListProperty children READ children) Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) @@ -129,7 +123,7 @@ public: QGraphicsGridLayoutObject(QObject * = 0); ~QGraphicsGridLayoutObject(); - QmlList *children() { return &_children; } + QmlListProperty children() { return QmlListProperty(this, 0, children_append, children_count, children_at, children_clear); } qreal spacing() const; @@ -142,30 +136,21 @@ private: void addLayoutItem(QGraphicsLayoutItem *); static QHash attachedProperties; - class ChildList : public QmlList - { - public: - ChildList(QGraphicsGridLayoutObject *o) - : obj(o) {} - - virtual void append(QGraphicsLayoutItem *o) - { - obj->addLayoutItem(o); - } - virtual void clear() { obj->clearChildren(); } - virtual int count() const { return obj->count(); } - virtual void removeAt(int i) { obj->removeAt(i); } - virtual QGraphicsLayoutItem *at(int i) const { return obj->itemAt(i); } - //### GridLayout doesn't have an insert, so for now we treat it as an append. - // this is obviously potenitally dangerous -- perhaps should be a concrete - // list with no relation to layout index, etc at all. - virtual void insert(int, QGraphicsLayoutItem *item) { append(item); } - - private: - QGraphicsGridLayoutObject *obj; - }; - - ChildList _children; + static void children_append(QmlListProperty *prop, QGraphicsLayoutItem *item) { + static_cast(prop->object)->addLayoutItem(item); + } + + static void children_clear(QmlListProperty *prop) { + static_cast(prop->object)->clearChildren(); + } + + static int children_count(QmlListProperty *prop) { + return static_cast(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QmlListProperty *prop, int index) { + return static_cast(prop->object)->itemAt(index); + } }; QT_END_NAMESPACE diff --git a/src/declarative/widgets/graphicswidgets.cpp b/src/declarative/widgets/graphicswidgets.cpp index 5c7f093..bb4dc74 100644 --- a/src/declarative/widgets/graphicswidgets.cpp +++ b/src/declarative/widgets/graphicswidgets.cpp @@ -63,63 +63,31 @@ class QGraphicsSceneDeclarativeUI : public QObject { Q_OBJECT - Q_PROPERTY(QmlList *children READ children) + Q_PROPERTY(QmlListProperty children READ children) Q_CLASSINFO("DefaultProperty", "children") public: - QGraphicsSceneDeclarativeUI(QObject *other) : QObject(other), _children(other) {} + QGraphicsSceneDeclarativeUI(QObject *other) : QObject(other) {} - QmlList *children() { return &_children; } + QmlListProperty children() { return QmlListProperty(this->parent(), 0, children_append); } private: - class Children : public QmlConcreteList - { - public: - Children(QObject *scene) : q(scene) {} - virtual void append(QObject *o) - { - insert(-1, o); - } - virtual void clear() - { - for (int i = 0; i < count(); ++i) - if (QGraphicsObject *go = qobject_cast(at(i))) - static_cast(q)->removeItem(go); - QmlConcreteList::clear(); - } - virtual void removeAt(int i) - { - if (QGraphicsObject *go = qobject_cast(at(i))) - static_cast(q)->removeItem(go); - QmlConcreteList::removeAt(i); - } - virtual void insert(int i, QObject *o) - { - QmlConcreteList::insert(i, o); - if (QGraphicsObject *go = qobject_cast(o)) - static_cast(q)->addItem(go); - //else if (QWidget *w = qobject_cast(o)) - // static_cast(q)->addWidget(w); - } - private: - QObject *q; - }; - Children _children; + static void children_append(QmlListProperty *prop, QObject *o) { + if (QGraphicsObject *go = qobject_cast(o)) + static_cast(prop->object)->addItem(go); + } }; class QGraphicsWidgetDeclarativeUI : public QObject { Q_OBJECT - Q_PROPERTY(QmlList *data READ data) - Q_PROPERTY(QmlList *children READ children) + Q_PROPERTY(QmlListProperty children READ children) Q_PROPERTY(QGraphicsLayout *layout READ layout WRITE setLayout) Q_CLASSINFO("DefaultProperty", "children") public: - QGraphicsWidgetDeclarativeUI(QObject *other) : QObject(other), _widgets(this) {} - - QmlList *data() { return &_data; } + QGraphicsWidgetDeclarativeUI(QObject *other) : QObject(other) {} - QmlList *children() { return &_widgets; } + QmlListProperty children() { return QmlListProperty(this, 0, children_append); } QGraphicsLayout *layout() const { return static_cast(parent())->layout(); } void setLayout(QGraphicsLayout *lo) @@ -128,28 +96,14 @@ public: } private: - friend class WidgetList; void setItemParent(QGraphicsItem *wid) { wid->setParentItem(static_cast(parent())); } - class WidgetList : public QmlConcreteList - { - public: - WidgetList(QGraphicsWidgetDeclarativeUI *o) - : obj(o) {} - - virtual void append(QGraphicsItem *w) { QmlConcreteList::append(w); obj->setItemParent(w); } - virtual void clear() { QmlConcreteList::clear(); } //### - virtual void removeAt(int i) { QmlConcreteList::removeAt(i); } //### - virtual void insert(int i, QGraphicsItem *item) { QmlConcreteList::insert(i, item); obj->setItemParent(item); } - - private: - QGraphicsWidgetDeclarativeUI *obj; - }; - WidgetList _widgets; - QmlConcreteList _data; + static void children_append(QmlListProperty *prop, QGraphicsItem *i) { + static_cast(prop->object)->setItemParent(i); + } }; QML_DEFINE_EXTENDED_TYPE(Qt,4,6,QGraphicsView,QGraphicsView,QGraphicsViewDeclarativeUI) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 2c58f7c..9dc7230 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -40,7 +40,6 @@ SUBDIRS += \ qmlinstruction \ # Cover qmllanguage \ # Cover qmllist \ # Cover - qmllistaccessor \ # Cover qmllistmodel \ # Cover qmlmetaproperty \ # Cover qmlmetatype \ # Cover diff --git a/tests/auto/declarative/qmlecmascript/data/listProperties.qml b/tests/auto/declarative/qmlecmascript/data/listProperties.qml index cae1721..810f9b6 100644 --- a/tests/auto/declarative/qmlecmascript/data/listProperties.qml +++ b/tests/auto/declarative/qmlecmascript/data/listProperties.qml @@ -9,12 +9,6 @@ MyQmlObject { QtObject { property int a: 11 } ] - objectQmlListProperty: [ - QtObject { property int a: 10 }, - QtObject { property int a: 1 }, - QtObject { property int a: 39 } - ] - Script { function calcTest1() { var rv = 0; @@ -24,21 +18,10 @@ MyQmlObject { return rv; } - function calcTest2() { - var rv = 0; - for (var ii = 0; ii < root.objectQmlListProperty.length; ++ii) { - rv += root.objectQmlListProperty[ii].a; - } - return rv; - } } property int test1: calcTest1(); property int test2: root.objectListProperty.length - property int test3: calcTest2(); - property int test4: root.objectQmlListProperty.length - property bool test5: root.objectQmlListProperty[1] != undefined - property bool test6: root.objectQmlListProperty[100] == undefined - property bool test7: root.objectListProperty[1] != undefined - property bool test8: root.objectListProperty[100] == undefined + property bool test3: root.objectListProperty[1] != undefined + property bool test4: root.objectListProperty[100] == undefined } diff --git a/tests/auto/declarative/qmlecmascript/testtypes.h b/tests/auto/declarative/qmlecmascript/testtypes.h index 330664f..0af72cb 100644 --- a/tests/auto/declarative/qmlecmascript/testtypes.h +++ b/tests/auto/declarative/qmlecmascript/testtypes.h @@ -77,8 +77,7 @@ class MyQmlObject : public QObject Q_PROPERTY(int value READ value WRITE setValue) Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged) Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged) - Q_PROPERTY(QmlList *objectQmlListProperty READ objectQmlListProperty CONSTANT) - Q_PROPERTY(QList *objectListProperty READ objectListProperty CONSTANT) + Q_PROPERTY(QmlListProperty objectListProperty READ objectListProperty CONSTANT) Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty) public: @@ -107,8 +106,7 @@ public: emit objectChanged(); } - QmlList *objectQmlListProperty() { return &m_objectQmlList; } - QList *objectListProperty() { return &m_objectQList; } + QmlListProperty objectListProperty() { return QmlListProperty(this, m_objectQList); } bool methodCalled() const { return m_methodCalled; } bool methodIntCalled() const { return m_methodIntCalled; } @@ -150,7 +148,6 @@ private: QObject *m_object; QString m_string; - QmlConcreteList m_objectQmlList; QList m_objectQList; int m_value; int m_resetProperty; @@ -162,11 +159,11 @@ QML_DECLARE_TYPE(MyQmlObject); class MyQmlContainer : public QObject { Q_OBJECT - Q_PROPERTY(QList* children READ children CONSTANT) + Q_PROPERTY(QmlListProperty children READ children CONSTANT) public: MyQmlContainer() {} - QList *children() { return &m_children; } + QmlListProperty children() { return QmlListProperty(this, m_children); } private: QList m_children; diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index 0ef836f..b30ad1c 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -365,7 +365,6 @@ void tst_qmlecmascript::basicExpressions() QCOMPARE(expr.value(), result); } -Q_DECLARE_METATYPE(QList); void tst_qmlecmascript::arrayExpressions() { QObject obj1; @@ -985,12 +984,8 @@ void tst_qmlecmascript::listProperties() QCOMPARE(object->property("test1").toInt(), 21); QCOMPARE(object->property("test2").toInt(), 2); - QCOMPARE(object->property("test3").toInt(), 50); - QCOMPARE(object->property("test4").toInt(), 3); - QCOMPARE(object->property("test5").toBool(), true); - QCOMPARE(object->property("test6").toBool(), true); - QCOMPARE(object->property("test7").toBool(), true); - QCOMPARE(object->property("test8").toBool(), true); + QCOMPARE(object->property("test3").toBool(), true); + QCOMPARE(object->property("test4").toBool(), true); } void tst_qmlecmascript::exceptionClearsOnReeval() @@ -1612,7 +1607,9 @@ void tst_qmlecmascript::listToVariant() QObject *object = component.create(&context); QVERIFY(object != 0); - QCOMPARE(object->property("test"), QVariant::fromValue(container.children())); + QVariant v = object->property("test"); + QCOMPARE(v.userType(), qMetaTypeId()); + QVERIFY(qvariant_cast(v).object() == &container); delete object; } diff --git a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp index 072f740..b986a64 100644 --- a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp +++ b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp @@ -268,31 +268,31 @@ void tst_QmlGraphicsPathView::path() QCOMPARE(obj->startY(), 100.); QVERIFY(obj->path() != QPainterPath()); - QList *list = obj->pathElements(); - QCOMPARE(list->count(), 5); + QmlListReference list(obj, "pathElements"); + QCOMPARE(list.count(), 5); - QmlGraphicsPathAttribute* attr = qobject_cast(list->at(0)); + QmlGraphicsPathAttribute* attr = qobject_cast(list.at(0)); QVERIFY(attr != 0); QCOMPARE(attr->name(), QString("scale")); QCOMPARE(attr->value(), 1.0); - QmlGraphicsPathQuad* quad = qobject_cast(list->at(1)); + QmlGraphicsPathQuad* quad = qobject_cast(list.at(1)); QVERIFY(quad != 0); QCOMPARE(quad->x(), 120.); QCOMPARE(quad->y(), 25.); QCOMPARE(quad->controlX(), 260.); QCOMPARE(quad->controlY(), 75.); - QmlGraphicsPathPercent* perc = qobject_cast(list->at(2)); + QmlGraphicsPathPercent* perc = qobject_cast(list.at(2)); QVERIFY(perc != 0); QCOMPARE(perc->value(), 0.3); - QmlGraphicsPathLine* line = qobject_cast(list->at(3)); + QmlGraphicsPathLine* line = qobject_cast(list.at(3)); QVERIFY(line != 0); QCOMPARE(line->x(), 120.); QCOMPARE(line->y(), 100.); - QmlGraphicsPathCubic* cubic = qobject_cast(list->at(4)); + QmlGraphicsPathCubic* cubic = qobject_cast(list.at(4)); QVERIFY(cubic != 0); QCOMPARE(cubic->x(), 180.); QCOMPARE(cubic->y(), 0.); diff --git a/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp index 9e3a028..c971840 100644 --- a/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp +++ b/tests/auto/declarative/qmlgraphicsrepeater/tst_qmlgraphicsrepeater.cpp @@ -188,14 +188,14 @@ void tst_QmlGraphicsRepeater::objectList() { QmlView *canvas = createView(SRCDIR "/data/objlist.qml"); - QObjectList* data = new QObjectList; + QObjectList data; for(int i=0; i<100; i++){ - *data << new QObject(); - data->back()->setProperty("idx", i); + data << new QObject(); + data.back()->setProperty("idx", i); } QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testData", QVariant::fromValue(data)); + ctxt->setContextProperty("testData", QVariant::fromValue(data)); canvas->execute(); qApp->processEvents(); diff --git a/tests/auto/declarative/qmlinstruction/tst_qmlinstruction.cpp b/tests/auto/declarative/qmlinstruction/tst_qmlinstruction.cpp index 9c753ce..38d024a 100644 --- a/tests/auto/declarative/qmlinstruction/tst_qmlinstruction.cpp +++ b/tests/auto/declarative/qmlinstruction/tst_qmlinstruction.cpp @@ -421,13 +421,6 @@ void tst_qmlinstruction::dump() { QmlInstruction i; - i.line = 37; - i.type = QmlInstruction::StoreObjectQmlList; - data->bytecode << i; - } - - { - QmlInstruction i; i.line = 38; i.type = QmlInstruction::StoreObjectQList; data->bytecode << i; @@ -450,15 +443,6 @@ void tst_qmlinstruction::dump() { QmlInstruction i; - i.line = 41; - i.type = QmlInstruction::FetchQmlList; - i.fetchQmlList.property = 31; - i.fetchQmlList.type = 3; - data->bytecode << i; - } - - { - QmlInstruction i; i.line = 42; i.type = QmlInstruction::FetchQList; i.fetch.property = 32; @@ -569,20 +553,18 @@ void tst_qmlinstruction::dump() << "34\t\t34\tSTORE_VALUE_SOURCE\t29\t4" << "35\t\t35\tSTORE_VALUE_INTERCEPTOR\t30\t-4" << "36\t\t36\tBEGIN\t\t\t4" - << "37\t\t37\tSTORE_OBJECT_QMLLIST" - << "38\t\t38\tSTORE_OBJECT_QLIST" - << "39\t\t39\tASSIGN_OBJECT_LIST" - << "40\t\t40\tFETCH_ATTACHED\t\t23" - << "41\t\t41\tFETCH_QMLLIST\t\t31\t3" - << "42\t\t42\tFETCH_QLIST\t\t32" - << "43\t\t43\tFETCH\t\t\t33" - << "44\t\t44\tFETCH_VALUE\t\t34\t6" - << "45\t\t45\tPOP" - << "46\t\t46\tPOP_QLIST" - << "47\t\t47\tPOP_VALUE\t\t35\t8" - << "48\t\t48\tDEFER\t\t\t7" - << "49\t\tNA\tDEFER\t\t\t7" - << "50\t\t50\tXXX UNKOWN INSTRUCTION\t49" + << "37\t\t38\tSTORE_OBJECT_QLIST" + << "38\t\t39\tASSIGN_OBJECT_LIST" + << "39\t\t40\tFETCH_ATTACHED\t\t23" + << "40\t\t42\tFETCH_QLIST\t\t32" + << "41\t\t43\tFETCH\t\t\t33" + << "42\t\t44\tFETCH_VALUE\t\t34\t6" + << "43\t\t45\tPOP" + << "44\t\t46\tPOP_QLIST" + << "45\t\t47\tPOP_VALUE\t\t35\t8" + << "46\t\t48\tDEFER\t\t\t7" + << "47\t\tNA\tDEFER\t\t\t7" + << "48\t\t50\tXXX UNKOWN INSTRUCTION\t47" << "-------------------------------------------------------------------------------"; messages = QStringList(); diff --git a/tests/auto/declarative/qmllanguage/data/interfaceQmlList.qml b/tests/auto/declarative/qmllanguage/data/interfaceQmlList.qml deleted file mode 100644 index 8392bea..0000000 --- a/tests/auto/declarative/qmllanguage/data/interfaceQmlList.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Test 1.0 -MyContainer { - qmllistInterfaces: [ - MyQmlObject {}, - MyQmlObject {} - ] -} diff --git a/tests/auto/declarative/qmllanguage/data/listAssignment.1.errors.txt b/tests/auto/declarative/qmllanguage/data/listAssignment.1.errors.txt deleted file mode 100644 index d68d487..0000000 --- a/tests/auto/declarative/qmllanguage/data/listAssignment.1.errors.txt +++ /dev/null @@ -1 +0,0 @@ -3:24:Cannot assign primitives to lists diff --git a/tests/auto/declarative/qmllanguage/data/listAssignment.1.qml b/tests/auto/declarative/qmllanguage/data/listAssignment.1.qml deleted file mode 100644 index 4240425..0000000 --- a/tests/auto/declarative/qmllanguage/data/listAssignment.1.qml +++ /dev/null @@ -1,4 +0,0 @@ -import Test 1.0 -MyContainer { - qmllistInterfaces: 1 -} diff --git a/tests/auto/declarative/qmllanguage/testtypes.h b/tests/auto/declarative/qmllanguage/testtypes.h index 0dc957f..27b45e4 100644 --- a/tests/auto/declarative/qmllanguage/testtypes.h +++ b/tests/auto/declarative/qmllanguage/testtypes.h @@ -447,22 +447,19 @@ QML_DECLARE_TYPE(MyTypeObject); class MyContainer : public QObject { Q_OBJECT - Q_PROPERTY(QList* children READ children) - Q_PROPERTY(QList* qlistInterfaces READ qlistInterfaces) - Q_PROPERTY(QmlList* qmllistInterfaces READ qmllistInterfaces) + Q_PROPERTY(QmlListProperty children READ children) + Q_PROPERTY(QmlListProperty qlistInterfaces READ qlistInterfaces) Q_CLASSINFO("DefaultProperty", "children"); public: MyContainer() {} - QList *children() { return &m_children; } - QList *qlistInterfaces() { return &m_interfaces; } - QmlList *qmllistInterfaces() { return &m_qmlinterfaces; } - const QmlConcreteList &qmllistAccessor() const { return m_qmlinterfaces; } + QmlListProperty children() { return QmlListProperty(this, m_children); } + QList *getChildren() { return &m_children; } + QmlListProperty qlistInterfaces() { return QmlListProperty(this, m_interfaces); } + QList *getQListInterfaces() { return &m_interfaces; } -private: QList m_children; QList m_interfaces; - QmlConcreteList m_qmlinterfaces; }; QML_DECLARE_TYPE(MyContainer); @@ -534,12 +531,12 @@ namespace MyNamespace { class MySecondNamespacedType : public QObject { Q_OBJECT - Q_PROPERTY(QmlList *list READ list); + Q_PROPERTY(QmlListProperty list READ list); public: - QmlList *list() { return &m_list; } + QmlListProperty list() { return QmlListProperty(this, m_list); } private: - QmlConcreteList m_list; + QList m_list; }; } QML_DECLARE_TYPE(MyNamespace::MyNamespacedType); diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index c4636f3..4090e1d 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -76,7 +76,6 @@ private slots: void simpleObject(); void simpleContainer(); void interfaceProperty(); - void interfaceQmlList(); void interfaceQList(); void assignObjectToSignal(); void assignObjectToVariant(); @@ -233,7 +232,6 @@ void tst_qmllanguage::errors_data() QTest::newRow("readOnly.2") << "readOnly.2.qml" << "readOnly.2.errors.txt" << false; QTest::newRow("readOnly.3") << "readOnly.3.qml" << "readOnly.3.errors.txt" << false; - QTest::newRow("listAssignment.1") << "listAssignment.1.qml" << "listAssignment.1.errors.txt" << false; QTest::newRow("listAssignment.2") << "listAssignment.2.qml" << "listAssignment.2.errors.txt" << false; QTest::newRow("listAssignment.3") << "listAssignment.3.qml" << "listAssignment.3.errors.txt" << false; @@ -354,7 +352,7 @@ void tst_qmllanguage::simpleContainer() VERIFY_ERRORS(0); MyContainer *container= qobject_cast(component.create()); QVERIFY(container != 0); - QCOMPARE(container->children()->count(),2); + QCOMPARE(container->getChildren()->count(),2); } void tst_qmllanguage::interfaceProperty() @@ -367,26 +365,15 @@ void tst_qmllanguage::interfaceProperty() QVERIFY(object->interface()->id == 913); } -void tst_qmllanguage::interfaceQmlList() -{ - QmlComponent component(&engine, TEST_FILE("interfaceQmlList.qml")); - VERIFY_ERRORS(0); - MyContainer *container= qobject_cast(component.create()); - QVERIFY(container != 0); - QVERIFY(container->qmllistAccessor().count() == 2); - for(int ii = 0; ii < 2; ++ii) - QVERIFY(container->qmllistAccessor().at(ii)->id == 913); -} - void tst_qmllanguage::interfaceQList() { QmlComponent component(&engine, TEST_FILE("interfaceQList.qml")); VERIFY_ERRORS(0); MyContainer *container= qobject_cast(component.create()); QVERIFY(container != 0); - QVERIFY(container->qlistInterfaces()->count() == 2); + QVERIFY(container->getQListInterfaces()->count() == 2); for(int ii = 0; ii < 2; ++ii) - QVERIFY(container->qlistInterfaces()->at(ii)->id == 913); + QVERIFY(container->getQListInterfaces()->at(ii)->id == 913); } void tst_qmllanguage::assignObjectToSignal() @@ -425,8 +412,8 @@ void tst_qmllanguage::assignQmlComponent() VERIFY_ERRORS(0); MyContainer *object = qobject_cast(component.create()); QVERIFY(object != 0); - QVERIFY(object->children()->count() == 1); - QObject *child = object->children()->at(0); + QVERIFY(object->getChildren()->count() == 1); + QObject *child = object->getChildren()->at(0); QCOMPARE(child->property("x"), QVariant(10)); QCOMPARE(child->property("y"), QVariant(11)); } @@ -504,7 +491,7 @@ void tst_qmllanguage::rootAsQmlComponent() MyContainer *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->property("x"), QVariant(11)); - QCOMPARE(object->children()->count(), 2); + QCOMPARE(object->getChildren()->count(), 2); } // Tests that components can be specified inline @@ -514,8 +501,8 @@ void tst_qmllanguage::inlineQmlComponents() VERIFY_ERRORS(0); MyContainer *object = qobject_cast(component.create()); QVERIFY(object != 0); - QCOMPARE(object->children()->count(), 1); - QmlComponent *comp = qobject_cast(object->children()->at(0)); + QCOMPARE(object->getChildren()->count(), 1); + QmlComponent *comp = qobject_cast(object->getChildren()->at(0)); QVERIFY(comp != 0); MyQmlObject *compObject = qobject_cast(comp->create()); QVERIFY(compObject != 0); @@ -529,9 +516,9 @@ void tst_qmllanguage::idProperty() VERIFY_ERRORS(0); MyContainer *object = qobject_cast(component.create()); QVERIFY(object != 0); - QCOMPARE(object->children()->count(), 1); + QCOMPARE(object->getChildren()->count(), 1); MyTypeObject *child = - qobject_cast(object->children()->at(0)); + qobject_cast(object->getChildren()->at(0)); QVERIFY(child != 0); QCOMPARE(child->id(), QString("myObjectId")); QCOMPARE(object->property("object"), QVariant::fromValue((QObject *)child)); @@ -1034,13 +1021,13 @@ void tst_qmllanguage::defaultPropertyListOrder() MyContainer *container = qobject_cast(component.create()); QVERIFY(container != 0); - QCOMPARE(container->children()->count(), 6); - QCOMPARE(container->children()->at(0)->property("index"), QVariant(0)); - QCOMPARE(container->children()->at(1)->property("index"), QVariant(1)); - QCOMPARE(container->children()->at(2)->property("index"), QVariant(2)); - QCOMPARE(container->children()->at(3)->property("index"), QVariant(3)); - QCOMPARE(container->children()->at(4)->property("index"), QVariant(4)); - QCOMPARE(container->children()->at(5)->property("index"), QVariant(5)); + QCOMPARE(container->getChildren()->count(), 6); + QCOMPARE(container->getChildren()->at(0)->property("index"), QVariant(0)); + QCOMPARE(container->getChildren()->at(1)->property("index"), QVariant(1)); + QCOMPARE(container->getChildren()->at(2)->property("index"), QVariant(2)); + QCOMPARE(container->getChildren()->at(3)->property("index"), QVariant(3)); + QCOMPARE(container->getChildren()->at(4)->property("index"), QVariant(4)); + QCOMPARE(container->getChildren()->at(5)->property("index"), QVariant(5)); } void tst_qmllanguage::declaredPropertyValues() diff --git a/tests/auto/declarative/qmllist/data/MyType.qml b/tests/auto/declarative/qmllist/data/MyType.qml new file mode 100644 index 0000000..d08f35b --- /dev/null +++ b/tests/auto/declarative/qmllist/data/MyType.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +QtObject { + property int a +} diff --git a/tests/auto/declarative/qmllist/data/engineTypes.qml b/tests/auto/declarative/qmllist/data/engineTypes.qml new file mode 100644 index 0000000..670aee4 --- /dev/null +++ b/tests/auto/declarative/qmllist/data/engineTypes.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property list myList + + myList: [ MyType { a: 1 }, + MyType { a: 9 } ] + +} diff --git a/tests/auto/declarative/qmllist/data/variantToList.qml b/tests/auto/declarative/qmllist/data/variantToList.qml new file mode 100644 index 0000000..0c2d0aa --- /dev/null +++ b/tests/auto/declarative/qmllist/data/variantToList.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +QtObject { + property list myList; + myList: QtObject {} + + property var value: myList + property int test: value.length +} + diff --git a/tests/auto/declarative/qmllist/tst_qmllist.cpp b/tests/auto/declarative/qmllist/tst_qmllist.cpp index 4ffbbb8..76def1c 100644 --- a/tests/auto/declarative/qmllist/tst_qmllist.cpp +++ b/tests/auto/declarative/qmllist/tst_qmllist.cpp @@ -38,9 +38,27 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include +#include +#include +#include +#include +#include #include #include +#include + +inline QUrl TEST_FILE(const QString &filename) +{ + QFileInfo fileInfo(__FILE__); + return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename)); +} + +inline QUrl TEST_FILE(const char *filename) +{ + return TEST_FILE(QLatin1String(filename)); +} class tst_QmlList : public QObject { @@ -49,28 +67,506 @@ public: tst_QmlList() {} private slots: - void interface(); + void qmllistreference(); + void qmllistreference_invalid(); + void isValid(); + void object(); + void listElementType(); + void canAppend(); + void canAt(); + void canClear(); + void canCount(); + void append(); + void at(); + void clear(); + void count(); + void copy(); + void qmlmetaproperty(); + void engineTypes(); + void variantToList(); }; -void tst_QmlList::interface() +class TestType : public QObject +{ + Q_OBJECT + Q_PROPERTY(QmlListProperty data READ dataProperty); + Q_PROPERTY(int intProperty READ intProperty); + +public: + TestType() : property(this, data) {} + QmlListProperty dataProperty() { return property; } + int intProperty() const { return 10; } + + QList data; + QmlListProperty property; +}; +QML_DECLARE_TYPE(TestType); +QML_DEFINE_NOCREATE_TYPE(TestType); + +void tst_QmlList::qmllistreference() +{ + TestType tt; + + QmlListReference r(&tt, "data"); + QVERIFY(r.isValid() == true); + QCOMPARE(r.count(), 0); + + tt.data.append(&tt); + QCOMPARE(r.count(), 1); +} + +void tst_QmlList::qmllistreference_invalid() +{ + TestType tt; + + // Invalid + { + QmlListReference r; + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } + + // Non-property + { + QmlListReference r(&tt, "blah"); + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } + + // Non-list property + { + QmlListReference r(&tt, "intProperty"); + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } +} + +void tst_QmlList::isValid() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.isValid() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.isValid() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.isValid() == true); + delete tt; + QVERIFY(ref.isValid() == false); + } +} + +void tst_QmlList::object() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.object() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.object() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.object() == tt); + delete tt; + QVERIFY(ref.object() == 0); + } +} + +void tst_QmlList::listElementType() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.listElementType() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.listElementType() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.listElementType() == &TestType::staticMetaObject); + delete tt; + QVERIFY(ref.listElementType() == 0); + } +} + +void tst_QmlList::canAppend() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canAppend() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canAppend() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canAppend() == true); + delete tt; + QVERIFY(ref.canAppend() == false); + } + + { + TestType tt; + tt.property.append = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canAppend() == false); + } +} + +void tst_QmlList::canAt() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canAt() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canAt() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canAt() == true); + delete tt; + QVERIFY(ref.canAt() == false); + } + + { + TestType tt; + tt.property.at = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canAt() == false); + } +} + +void tst_QmlList::canClear() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canClear() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canClear() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canClear() == true); + delete tt; + QVERIFY(ref.canClear() == false); + } + + { + TestType tt; + tt.property.clear = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canClear() == false); + } +} + +void tst_QmlList::canCount() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canCount() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canCount() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canCount() == true); + delete tt; + QVERIFY(ref.canCount() == false); + } + + { + TestType tt; + tt.property.count = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canCount() == false); + } +} + +void tst_QmlList::append() +{ + TestType *tt = new TestType; + QObject object; + + { + QmlListReference ref; + QVERIFY(ref.append(tt) == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.append(tt) == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.append(tt) == true); + QVERIFY(tt->data.count() == 1); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(ref.append(&object) == false); + QVERIFY(tt->data.count() == 1); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(ref.append(0) == true); + QVERIFY(tt->data.count() == 2); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(tt->data.at(1) == 0); + delete tt; + QVERIFY(ref.append(0) == false); + } + + { + TestType tt; + tt.property.append = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.append(&tt) == false); + } +} + +void tst_QmlList::at() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.at(0) == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.at(0) == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.at(0) == tt); + QVERIFY(ref.at(1) == 0); + QVERIFY(ref.at(2) == tt); + delete tt; + QVERIFY(ref.at(0) == 0); + } + + { + TestType tt; + tt.data.append(&tt); + tt.property.at = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.at(0) == 0); + } +} + +void tst_QmlList::clear() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.clear() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.clear() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.clear() == true); + QVERIFY(tt->data.count() == 0); + delete tt; + QVERIFY(ref.clear() == false); + } + + { + TestType tt; + tt.property.clear = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.clear() == false); + } +} + +void tst_QmlList::count() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.count() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.count() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.count() == 3); + tt->data.removeAt(1); + QVERIFY(ref.count() == 2); + delete tt; + QVERIFY(ref.count() == 0); + } + + { + TestType tt; + tt.data.append(&tt); + tt.property.count = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.count() == 0); + } +} + +void tst_QmlList::copy() +{ + TestType tt; + tt.data.append(&tt); + tt.data.append(0); + tt.data.append(&tt); + + QmlListReference *r1 = new QmlListReference(&tt, "data"); + QVERIFY(r1->count() == 3); + + QmlListReference r2(*r1); + QmlListReference r3; + r3 = *r1; + + QVERIFY(r2.count() == 3); + QVERIFY(r3.count() == 3); + + delete r1; + + QVERIFY(r2.count() == 3); + QVERIFY(r3.count() == 3); + + tt.data.removeAt(2); + + QVERIFY(r2.count() == 2); + QVERIFY(r3.count() == 2); +} + +void tst_QmlList::qmlmetaproperty() +{ + TestType tt; + tt.data.append(&tt); + tt.data.append(0); + tt.data.append(&tt); + + QmlMetaProperty prop(&tt, QLatin1String("data")); + QVariant v = prop.read(); + QVERIFY(v.userType() == qMetaTypeId()); + QmlListReference ref = qvariant_cast(v); + QVERIFY(ref.count() == 3); + QVERIFY(ref.listElementType() == &TestType::staticMetaObject); +} + +void tst_QmlList::engineTypes() +{ + QmlEngine engine; + QmlComponent component(&engine, TEST_FILE("engineTypes.qml")); + + QObject *o = component.create(); + QVERIFY(o); + + QmlMetaProperty p1(o, QLatin1String("myList")); + QVERIFY(p1.propertyCategory() == QmlMetaProperty::Normal); + + QmlMetaProperty p2(o, QLatin1String("myList"), engine.rootContext()); + QVERIFY(p2.propertyCategory() == QmlMetaProperty::List); + QVariant v = p2.read(); + QVERIFY(v.userType() == qMetaTypeId()); + QmlListReference ref = qvariant_cast(v); + QVERIFY(ref.count() == 2); + QVERIFY(ref.listElementType()); + QVERIFY(ref.listElementType() != &QObject::staticMetaObject); + + delete o; +} + +void tst_QmlList::variantToList() { - QmlConcreteList list; - QObject *obj = new QObject; - obj->setObjectName("foo"); - list.append(obj); - QVERIFY(list.count() == 1); - QCOMPARE(list.at(0), obj); + QmlEngine engine; + QmlComponent component(&engine, TEST_FILE("variantToList.qml")); - QmlPrivate::ListInterface *li = (QmlPrivate::ListInterface*)&list; + QObject *o = component.create(); + QVERIFY(o); - void *ptr[1]; - li->at(0, ptr); - QVERIFY(li->count() == 1); - QCOMPARE(ptr[0], obj); + QVERIFY(o->property("value").userType() == qMetaTypeId()); + QCOMPARE(o->property("test").toInt(), 1); - li->removeAt(0); - QVERIFY(li->count() == 0); - QVERIFY(list.count() == 0); + delete o; } QTEST_MAIN(tst_QmlList) diff --git a/tests/auto/declarative/qmllistaccessor/qmllistaccessor.pro b/tests/auto/declarative/qmllistaccessor/qmllistaccessor.pro deleted file mode 100644 index ce2915e..0000000 --- a/tests/auto/declarative/qmllistaccessor/qmllistaccessor.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -macx:CONFIG -= app_bundle - -SOURCES += tst_qmllistaccessor.cpp diff --git a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp deleted file mode 100644 index 3efe847..0000000 --- a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp +++ /dev/null @@ -1,452 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include - -class tst_QmlListAccessor : public QObject -{ - Q_OBJECT -public: - tst_QmlListAccessor() {} - -private slots: - void invalid(); - void qmllist(); - void qlist(); - void qstringlist(); - void qvariantlist(); - void qobject(); - void instance(); - void integer(); -}; - -void tst_QmlListAccessor::invalid() -{ - QmlListAccessor accessor; - - QCOMPARE(accessor.list(), QVariant()); - QVERIFY(!accessor.isValid()); - QCOMPARE(accessor.type(), QmlListAccessor::Invalid); - - QCOMPARE(accessor.count(), 0); - QVERIFY(!accessor.append(QVariant(10))); - QVERIFY(!accessor.insert(0, QVariant(10))); - QVERIFY(!accessor.removeAt(0)); - QVERIFY(!accessor.clear()); - - accessor.setList(QVariant()); - - QCOMPARE(accessor.list(), QVariant()); - QVERIFY(!accessor.isValid()); - QCOMPARE(accessor.type(), QmlListAccessor::Invalid); - - QCOMPARE(accessor.count(), 0); - QVERIFY(!accessor.append(QVariant(10))); - QVERIFY(!accessor.insert(0, QVariant(10))); - QVERIFY(!accessor.removeAt(0)); - QVERIFY(!accessor.clear()); -} - -void tst_QmlListAccessor::qmllist() -{ - QmlConcreteList list; - QObject *obj = new QObject(this); - QObject *obj2 = new QObject(this); - QObject *obj3 = new QObject(this); - - list.append(obj); - QVERIFY(list.count() == 1); - QCOMPARE(list.at(0), obj); - - QmlListAccessor accessor; - accessor.setList(qVariantFromValue((QmlList*)&list)); - QCOMPARE(accessor.list(), qVariantFromValue((QmlList*)&list)); - - // type - QCOMPARE(accessor.type(), QmlListAccessor::QmlList); - - // isValid - QVERIFY(accessor.isValid()); - - // count - QCOMPARE(accessor.count(), 1); - - // at - QCOMPARE(qvariant_cast(accessor.at(0)), obj); - - // append - accessor.append(qVariantFromValue(obj2)); - QVERIFY(accessor.isValid()); - QCOMPARE(accessor.count(), 2); - QCOMPARE(qvariant_cast(accessor.at(1)), obj2); - QCOMPARE(list.count(), 2); - QCOMPARE(list.at(0), obj); - QCOMPARE(list.at(1), obj2); - - // insert - accessor.insert(1, qVariantFromValue(obj3)); - QVERIFY(accessor.isValid()); - QCOMPARE(accessor.count(), 3); - QCOMPARE(qvariant_cast(accessor.at(1)), obj3); - QCOMPARE(list.count(), 3); - QCOMPARE(list.at(0), obj); - QCOMPARE(list.at(1), obj3); - QCOMPARE(list.at(2), obj2); - - // removeAt - accessor.removeAt(1); - QVERIFY(accessor.isValid()); - QCOMPARE(accessor.count(), 2); - QCOMPARE(qvariant_cast(accessor.at(1)), obj2); - QCOMPARE(list.count(), 2); - QCOMPARE(list.at(0), obj); - QCOMPARE(list.at(1), obj2); - - // clear - accessor.clear(); - QVERIFY(accessor.isValid()); - QCOMPARE(accessor.count(), 0); - QCOMPARE(list.count(), 0); -} - -void tst_QmlListAccessor::qlist() -{ - QList list; - QObject *obj = new QObject(this); - QObject *obj2 = new QObject(this); - QObject *obj3 = new QObject(this); - - list.append(obj); - QVERIFY(list.count() == 1); - QCOMPARE(list.at(0), obj); - - QmlListAccessor accessor; - accessor.setList(qVariantFromValue((QList*)&list)); - QCOMPARE(accessor.list(), qVariantFromValue((QList*)&list)); - - // type - QCOMPARE(accessor.type(), QmlListAccessor::QListPtr); - - // isValid - QVERIFY(accessor.isValid()); - - // count - QCOMPARE(accessor.count(), 1); - - // at - QCOMPARE(qvariant_cast(accessor.at(0)), obj); - - // append - accessor.append(qVariantFromValue(obj2)); - QVERIFY(accessor.isValid()); - QCOMPARE(accessor.count(), 2); - QCOMPARE(qvariant_cast(accessor.at(1)), obj2); - QCOMPARE(list.count(), 2); - QCOMPARE(list.at(0), obj); - QCOMPARE(list.at(1), obj2); - - // insert - accessor.insert(1, qVariantFromValue(obj3)); - QVERIFY(accessor.isValid()); - QCOMPARE(accessor.count(), 3); - QCOMPARE(qvariant_cast(accessor.at(1)), obj3); - QCOMPARE(list.count(), 3); - QCOMPARE(list.at(0), obj); - QCOMPARE(list.at(1), obj3); - QCOMPARE(list.at(2), obj2); - - // removeAt - accessor.removeAt(1); - QVERIFY(accessor.isValid()); - QCOMPARE(accessor.count(), 2); - QCOMPARE(qvariant_cast(accessor.at(1)), obj2); - QCOMPARE(list.count(), 2); - QCOMPARE(list.at(0), obj); - QCOMPARE(list.at(1), obj2); - - // clear - accessor.clear(); - QVERIFY(accessor.isValid()); - QCOMPARE(accessor.count(), 0); - QCOMPARE(list.count(), 0); -} - -void tst_QmlListAccessor::qstringlist() -{ - QStringList list; - list.append(QLatin1String("Item1")); - list.append(QLatin1String("Item2")); - QVERIFY(list.count() == 2); - - QmlListAccessor accessor; - accessor.setList(list); - - // type - QCOMPARE(accessor.type(), QmlListAccessor::StringList); - - // isValid - QVERIFY(accessor.isValid()); - - // count - QVERIFY(accessor.count() == 2); - - // at - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); - - // append - QVERIFY(!accessor.append(QVariant("Item3"))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 2); - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); - - // insert - QVERIFY(!accessor.insert(1, QVariant("MiddleItem"))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 2); - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); - - // removeAt - QVERIFY(!accessor.removeAt(1)); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 2); - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); - - // clear - QVERIFY(!accessor.clear()); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 2); - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); -} - -void tst_QmlListAccessor::qvariantlist() -{ - QVariantList list; - list.append(QLatin1String("Item1")); - list.append(QLatin1String("Item2")); - QVERIFY(list.count() == 2); - - QmlListAccessor accessor; - accessor.setList(list); - - // type - QCOMPARE(accessor.type(), QmlListAccessor::VariantList); - - // isValid - QVERIFY(accessor.isValid()); - - // count - QVERIFY(accessor.count() == 2); - - // at - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); - - // append - QVERIFY(!accessor.append(QVariant("Item3"))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 2); - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); - - // insert - QVERIFY(!accessor.insert(1, QVariant("MiddleItem"))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 2); - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); - - // removeAt - QVERIFY(!accessor.removeAt(1)); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 2); - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); - - // clear - QVERIFY(!accessor.clear()); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 2); - QCOMPARE(qvariant_cast(accessor.at(0)), QLatin1String("Item1")); - QCOMPARE(qvariant_cast(accessor.at(1)), QLatin1String("Item2")); -} - -void tst_QmlListAccessor::qobject() -{ - QObject *obj = new QObject(this); - - QmlListAccessor accessor; - accessor.setList(qVariantFromValue(obj)); - - // type - QCOMPARE(accessor.type(), QmlListAccessor::Instance); - - // isValid - QVERIFY(accessor.isValid()); - - // count - QVERIFY(accessor.count() == 1); - - // at - QCOMPARE(accessor.at(0), qVariantFromValue(obj)); - - // append - QVERIFY(!accessor.append(qVariantFromValue((QObject *)0))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QCOMPARE(accessor.at(0), qVariantFromValue(obj)); - - // insert - QVERIFY(!accessor.insert(0, qVariantFromValue((QObject *)0))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QCOMPARE(accessor.at(0), qVariantFromValue(obj)); - - // removeAt - QVERIFY(!accessor.removeAt(0)); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QCOMPARE(accessor.at(0), qVariantFromValue(obj)); - - // clear - QVERIFY(!accessor.clear()); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QCOMPARE(accessor.at(0), qVariantFromValue(obj)); -} - -void tst_QmlListAccessor::instance() -{ - QRect r; - - QmlListAccessor accessor; - accessor.setList(r); - - // type - QCOMPARE(accessor.type(), QmlListAccessor::Instance); - - // isValid - QVERIFY(accessor.isValid()); - - // count - QVERIFY(accessor.count() == 1); - - // at - QCOMPARE(accessor.at(0), qVariantFromValue(r)); - - // append - QVERIFY(!accessor.append(qVariantFromValue(r))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QCOMPARE(accessor.at(0), qVariantFromValue(r)); - - // insert - QVERIFY(!accessor.insert(0, qVariantFromValue(r))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QCOMPARE(accessor.at(0), qVariantFromValue(r)); - - // removeAt - QVERIFY(!accessor.removeAt(0)); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QCOMPARE(accessor.at(0), qVariantFromValue(r)); - - // clear - QVERIFY(!accessor.clear()); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 1); - QCOMPARE(accessor.at(0), qVariantFromValue(r)); -} - -void tst_QmlListAccessor::integer() -{ - int r = 13; - - QmlListAccessor accessor; - accessor.setList(r); - - // type - QCOMPARE(accessor.type(), QmlListAccessor::Integer); - - // isValid - QVERIFY(accessor.isValid()); - - // count - QVERIFY(accessor.count() == 13); - - // at - QCOMPARE(accessor.at(4), qVariantFromValue(4)); - - // append - QVERIFY(!accessor.append(qVariantFromValue(r))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 13); - QCOMPARE(accessor.at(4), qVariantFromValue(4)); - - // insert - QVERIFY(!accessor.insert(0, qVariantFromValue(r))); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 13); - QCOMPARE(accessor.at(4), qVariantFromValue(4)); - - // removeAt - QVERIFY(!accessor.removeAt(0)); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 13); - QCOMPARE(accessor.at(4), qVariantFromValue(4)); - - // clear - QVERIFY(!accessor.clear()); - QVERIFY(accessor.isValid()); - QVERIFY(accessor.count() == 13); - QCOMPARE(accessor.at(4), qVariantFromValue(4)); -} - -QTEST_MAIN(tst_QmlListAccessor) - -#include "tst_qmllistaccessor.moc" diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index 91ff727..050cd3f 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -73,13 +73,11 @@ private: class MyContainer : public QObject { Q_OBJECT - Q_PROPERTY(QList* children READ children) - Q_PROPERTY(QmlList* qmlChildren READ qmlChildren) + Q_PROPERTY(QmlListProperty children READ children) public: MyContainer() {} - QList *children() { return &m_children; } - QmlConcreteList *qmlChildren() { return &m_qmlChildren; } + QmlListProperty children() { return QmlListProperty(this, m_children); } static MyAttached *qmlAttachedProperties(QObject *o) { return new MyAttached(o); @@ -87,7 +85,6 @@ public: private: QList m_children; - QmlConcreteList m_qmlChildren; }; QML_DECLARE_TYPE(MyContainer); @@ -118,7 +115,6 @@ private slots: // Functionality void writeObjectToList(); void writeListToList(); - void writeObjectToQmlList(); //writeToReadOnly(); @@ -1078,13 +1074,14 @@ void tst_qmlmetaproperty::writeObjectToList() containerComponent.setData("import Test 1.0\nMyContainer { children: MyQmlObject {} }", QUrl()); MyContainer *container = qobject_cast(containerComponent.create()); QVERIFY(container != 0); - QVERIFY(container->children()->size() == 1); + QmlListReference list(container, "children"); + QVERIFY(list.count() == 1); MyQmlObject *object = new MyQmlObject; QmlMetaProperty prop(container, "children"); prop.write(qVariantFromValue(object)); - QCOMPARE(container->children()->size(), 2); - QCOMPARE(container->children()->at(1), object); + QCOMPARE(list.count(), 1); + QCOMPARE(list.at(0), object); } Q_DECLARE_METATYPE(QList); @@ -1094,13 +1091,14 @@ void tst_qmlmetaproperty::writeListToList() containerComponent.setData("import Test 1.0\nMyContainer { children: MyQmlObject {} }", QUrl()); MyContainer *container = qobject_cast(containerComponent.create()); QVERIFY(container != 0); - QVERIFY(container->children()->size() == 1); + QmlListReference list(container, "children"); + QVERIFY(list.count() == 1); QList objList; objList << new MyQmlObject() << new MyQmlObject() << new MyQmlObject() << new MyQmlObject(); QmlMetaProperty prop(container, "children"); prop.write(qVariantFromValue(objList)); - QCOMPARE(container->children()->size(), 4); + QCOMPARE(list.count(), 4); //XXX need to try this with read/write prop (for read-only it correctly doesn't write) /*QList typedObjList; @@ -1109,21 +1107,6 @@ void tst_qmlmetaproperty::writeListToList() QCOMPARE(container->children()->size(), 1);*/ } -void tst_qmlmetaproperty::writeObjectToQmlList() -{ - QmlComponent containerComponent(&engine); - containerComponent.setData("import Test 1.0\nMyContainer { qmlChildren: MyQmlObject {} }", QUrl()); - MyContainer *container = qobject_cast(containerComponent.create()); - QVERIFY(container != 0); - QVERIFY(container->qmlChildren()->size() == 1); - - MyQmlObject *object = new MyQmlObject; - QmlMetaProperty prop(container, "qmlChildren"); - prop.write(qVariantFromValue(object)); - QCOMPARE(container->qmlChildren()->size(), 2); - QCOMPARE(container->qmlChildren()->at(1), object); -} - void tst_qmlmetaproperty::crashOnValueProperty() { QmlEngine *engine = new QmlEngine; diff --git a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp index 6d1887f..750ccf8 100644 --- a/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp +++ b/tests/auto/declarative/qmlmetatype/tst_qmlmetatype.cpp @@ -67,10 +67,6 @@ private slots: void qmlPropertyValueInterceptorCast(); void isList(); - void isQmlList(); - - void listCount(); - void listAt(); void defaultObject(); }; @@ -346,85 +342,12 @@ void tst_qmlmetatype::qmlPropertyValueInterceptorCast() void tst_qmlmetatype::isList() { - QCOMPARE(QmlMetaType::isList(QVariant()), false); QCOMPARE(QmlMetaType::isList(QVariant::Invalid), false); QCOMPARE(QmlMetaType::isList(QVariant::Int), false); - QCOMPARE(QmlMetaType::isList(QVariant(10)), false); - - QList list; - QmlConcreteList qmllist; - - QCOMPARE(QmlMetaType::isList(qMetaTypeId*>()), true); - QCOMPARE(QmlMetaType::isList(QVariant::fromValue(&list)), true); - QCOMPARE(QmlMetaType::isList(qMetaTypeId*>()), false); - QCOMPARE(QmlMetaType::isList(QVariant::fromValue((QmlList*)&qmllist)), false); -} -void tst_qmlmetatype::isQmlList() -{ - QCOMPARE(QmlMetaType::isQmlList(QVariant::Invalid), false); - QCOMPARE(QmlMetaType::isQmlList(QVariant::Int), false); - - QCOMPARE(QmlMetaType::isQmlList(qMetaTypeId*>()), false); - QCOMPARE(QmlMetaType::isQmlList(qMetaTypeId*>()), true); -} + QmlListProperty list; -void tst_qmlmetatype::listCount() -{ - QCOMPARE(QmlMetaType::listCount(QVariant()), 0); - QCOMPARE(QmlMetaType::listCount(QVariant(10)), 0); - - QList list; - QVariant listVar = QVariant::fromValue(&list); - QmlConcreteList qmllist; - QVariant qmllistVar = QVariant::fromValue((QmlList*)&qmllist); - - QCOMPARE(QmlMetaType::listCount(listVar), 0); - QCOMPARE(QmlMetaType::listCount(qmllistVar), 0); - - list.append(0); list.append(0); list.append(0); - qmllist.append(0); qmllist.append(0); qmllist.append(0); - - QCOMPARE(QmlMetaType::listCount(listVar), 3); - QCOMPARE(QmlMetaType::listCount(qmllistVar), 0); -} - -void tst_qmlmetatype::listAt() -{ - QCOMPARE(QmlMetaType::listAt(QVariant(), 0), QVariant()); - QCOMPARE(QmlMetaType::listAt(QVariant(10), 0), QVariant()); - QCOMPARE(QmlMetaType::listAt(QVariant(), 10), QVariant()); - QCOMPARE(QmlMetaType::listAt(QVariant(10), 10), QVariant()); - QCOMPARE(QmlMetaType::listAt(QVariant(), -10), QVariant()); - QCOMPARE(QmlMetaType::listAt(QVariant(10), -10), QVariant()); - - QList list; - QVariant listVar = QVariant::fromValue(&list); - QmlConcreteList qmllist; - QVariant qmllistVar = QVariant::fromValue((QmlList*)&qmllist); - - QCOMPARE(QmlMetaType::listAt(listVar, 0), QVariant()); - QCOMPARE(QmlMetaType::listAt(listVar, 2), QVariant()); - QCOMPARE(QmlMetaType::listAt(listVar, -1), QVariant()); - - QCOMPARE(QmlMetaType::listAt(qmllistVar, 0), QVariant()); - QCOMPARE(QmlMetaType::listAt(qmllistVar, 2), QVariant()); - QCOMPARE(QmlMetaType::listAt(qmllistVar, -1), QVariant()); - - TestType ttype; - QVariant ttypeVar = QVariant::fromValue(&ttype); - QVariant nullttypeVar = QVariant::fromValue((TestType *)0); - - list.append(0); list.append(&ttype); list.append(0); - qmllist.append(0); qmllist.append(&ttype); qmllist.append(0); - - QCOMPARE(QmlMetaType::listAt(listVar, 0), nullttypeVar); - QCOMPARE(QmlMetaType::listAt(listVar, 1), ttypeVar); - QCOMPARE(QmlMetaType::listAt(listVar, -1), QVariant()); - - QCOMPARE(QmlMetaType::listAt(qmllistVar, 0), QVariant()); - QCOMPARE(QmlMetaType::listAt(qmllistVar, 2), QVariant()); - QCOMPARE(QmlMetaType::listAt(qmllistVar, -1), QVariant()); + QCOMPARE(QmlMetaType::isList(qMetaTypeId >()), true); } void tst_qmlmetatype::defaultObject() diff --git a/tests/auto/declarative/qmlstates/tst_qmlstates.cpp b/tests/auto/declarative/qmlstates/tst_qmlstates.cpp index 81145a8..b910c85 100644 --- a/tests/auto/declarative/qmlstates/tst_qmlstates.cpp +++ b/tests/auto/declarative/qmlstates/tst_qmlstates.cpp @@ -407,8 +407,12 @@ void tst_qmlstates::parentChange() QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect != 0); - qmlExecuteDeferred(rect->states()->at(0)); - QmlParentChange *pChange = qobject_cast(rect->states()->at(0)->changes()->at(0)); + QmlListReference list(rect, "states"); + QmlState *state = qobject_cast(list.at(0)); + QVERIFY(state != 0); + + qmlExecuteDeferred(state); + QmlParentChange *pChange = qobject_cast(state->operationAt(0)); QVERIFY(pChange != 0); QmlGraphicsItem *nParent = qobject_cast(rect->findChild("NewParent")); QVERIFY(nParent != 0); @@ -510,8 +514,12 @@ void tst_qmlstates::anchorChanges() QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); QVERIFY(innerRect != 0); - qmlExecuteDeferred(rect->states()->at(0)); - QmlAnchorChanges *aChanges = qobject_cast(rect->states()->at(0)->changes()->at(0)); + QmlListReference list(rect, "states"); + QmlState *state = qobject_cast(list.at(0)); + QVERIFY(state != 0); + + qmlExecuteDeferred(state); + QmlAnchorChanges *aChanges = qobject_cast(state->operationAt(0)); QVERIFY(aChanges != 0); rect->setState("right"); @@ -565,8 +573,12 @@ void tst_qmlstates::anchorChanges3() QmlGraphicsItem *bottomGuideline = qobject_cast(rect->findChild("BottomGuideline")); QVERIFY(bottomGuideline != 0); - qmlExecuteDeferred(rect->states()->at(0)); - QmlAnchorChanges *aChanges = qobject_cast(rect->states()->at(0)->changes()->at(0)); + QmlListReference list(rect, "states"); + QmlState *state = qobject_cast(list.at(0)); + QVERIFY(state != 0); + + qmlExecuteDeferred(state); + QmlAnchorChanges *aChanges = qobject_cast(state->operationAt(0)); QVERIFY(aChanges != 0); rect->setState("reanchored"); @@ -611,8 +623,12 @@ void tst_qmlstates::anchorChanges4() QmlGraphicsItem *bottomGuideline = qobject_cast(rect->findChild("BottomGuideline")); QVERIFY(bottomGuideline != 0); - qmlExecuteDeferred(rect->states()->at(0)); - QmlAnchorChanges *aChanges = qobject_cast(rect->states()->at(0)->changes()->at(0)); + QmlListReference list(rect, "states"); + QmlState *state = qobject_cast(list.at(0)); + QVERIFY(state != 0); + + qmlExecuteDeferred(state); + QmlAnchorChanges *aChanges = qobject_cast(state->operationAt(0)); QVERIFY(aChanges != 0); rect->setState("reanchored"); @@ -642,8 +658,12 @@ void tst_qmlstates::anchorChanges5() QmlGraphicsItem *bottomGuideline = qobject_cast(rect->findChild("BottomGuideline")); QVERIFY(bottomGuideline != 0); - qmlExecuteDeferred(rect->states()->at(0)); - QmlAnchorChanges *aChanges = qobject_cast(rect->states()->at(0)->changes()->at(0)); + QmlListReference list(rect, "states"); + QmlState *state = qobject_cast(list.at(0)); + QVERIFY(state != 0); + + qmlExecuteDeferred(state); + QmlAnchorChanges *aChanges = qobject_cast(state->operationAt(0)); QVERIFY(aChanges != 0); rect->setState("reanchored"); @@ -700,7 +720,11 @@ void tst_qmlstates::explicitChanges() QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); QVERIFY(rect != 0); - qmlExecuteDeferred(rect->states()->at(0)); + QmlListReference list(rect, "states"); + QmlState *state = qobject_cast(list.at(0)); + QVERIFY(state != 0); + + qmlExecuteDeferred(state); QmlPropertyChanges *changes = qobject_cast(rect->findChild("changes")); QVERIFY(changes != 0); QVERIFY(changes->isExplicit()); @@ -802,7 +826,7 @@ void tst_qmlstates::deletingChange() QmlState *state = rect->findChild(); QVERIFY(state != 0); qmlExecuteDeferred(state); - QCOMPARE(state->changes()->count(), 1); + QCOMPARE(state->operationCount(), 1); rect->setState("blue"); QCOMPARE(rect->color(),QColor("red")); -- cgit v0.12