summaryrefslogtreecommitdiffstats
path: root/examples/declarative/extending/binding
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-02-22 04:56:49 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-02-22 05:53:27 (GMT)
commit33eb76f050b45718d87926a8ff7afc89d6201c16 (patch)
tree935ddc2337b3891aab1ad7edcb06a62aabf14668 /examples/declarative/extending/binding
parent5f63321e3fe2b436d469d2722dc464ea4c7830c4 (diff)
downloadQt-33eb76f050b45718d87926a8ff7afc89d6201c16.zip
Qt-33eb76f050b45718d87926a8ff7afc89d6201c16.tar.gz
Qt-33eb76f050b45718d87926a8ff7afc89d6201c16.tar.bz2
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).
Diffstat (limited to 'examples/declarative/extending/binding')
-rw-r--r--examples/declarative/extending/binding/birthdayparty.cpp14
-rw-r--r--examples/declarative/extending/binding/birthdayparty.h8
-rw-r--r--examples/declarative/extending/binding/main.cpp4
3 files changed, 19 insertions, 7 deletions
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<Person *> *BirthdayParty::guests()
+QmlListProperty<Person> BirthdayParty::guests()
{
- return &m_guests;
+ return QmlListProperty<Person>(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<Person *> *guests READ guests)
+Q_PROPERTY(QmlListProperty<Person> 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<Person *> *guests();
+ QmlListProperty<Person> 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<Person *> m_guests;
+ QList<Person *> 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 =