summaryrefslogtreecommitdiffstats
path: root/examples/declarative/extending/default
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/default
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/default')
-rw-r--r--examples/declarative/extending/default/birthdayparty.cpp14
-rw-r--r--examples/declarative/extending/default/birthdayparty.h8
-rw-r--r--examples/declarative/extending/default/main.cpp5
3 files changed, 20 insertions, 7 deletions
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<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);
}
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<Person *> *guests READ guests)
+Q_PROPERTY(QmlListProperty<Person> guests READ guests)
Q_CLASSINFO("DefaultProperty", "guests")
public:
BirthdayParty(QObject *parent = 0);
@@ -58,11 +58,13 @@ public:
Person *celebrant() const;
void setCelebrant(Person *);
- QmlList<Person *> *guests();
+ QmlListProperty<Person> guests();
+ int guestCount() const;
+ Person *guest(int) const;
private:
Person *m_celebrant;
- QmlConcreteList<Person *> m_guests;
+ QList<Person *> 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";
}