diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-04-21 00:58:02 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-04-21 00:59:45 (GMT) |
commit | 61f3cb6e79fea0aed80df091013c2228f64955ec (patch) | |
tree | 916d4879a326739673f918fc340bc5a4c356bcb9 /examples/declarative/extending | |
parent | e11a5c4d1a1bb80ac03655227c833b560c7cad3c (diff) | |
download | Qt-61f3cb6e79fea0aed80df091013c2228f64955ec.zip Qt-61f3cb6e79fea0aed80df091013c2228f64955ec.tar.gz Qt-61f3cb6e79fea0aed80df091013c2228f64955ec.tar.bz2 |
Improve docs and examples for Extending QML in C++
Diffstat (limited to 'examples/declarative/extending')
50 files changed, 331 insertions, 310 deletions
diff --git a/examples/declarative/extending/adding/example.qml b/examples/declarative/extending/adding/example.qml index c608f94..dc891e7 100644 --- a/examples/declarative/extending/adding/example.qml +++ b/examples/declarative/extending/adding/example.qml @@ -1,6 +1,6 @@ +// ![0] import People 1.0 -// ![0] Person { name: "Bob Jones" shoeSize: 12 diff --git a/examples/declarative/extending/adding/main.cpp b/examples/declarative/extending/adding/main.cpp index b9e5aa3..7b33895 100644 --- a/examples/declarative/extending/adding/main.cpp +++ b/examples/declarative/extending/adding/main.cpp @@ -47,8 +47,9 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - +//![0] qmlRegisterType<Person>("People", 1,0, "Person"); +//![0] QDeclarativeEngine engine; QDeclarativeComponent component(&engine, ":example.qml"); diff --git a/examples/declarative/extending/adding/person.h b/examples/declarative/extending/adding/person.h index 7a9e0f0..d6de9a9 100644 --- a/examples/declarative/extending/adding/person.h +++ b/examples/declarative/extending/adding/person.h @@ -43,12 +43,11 @@ #include <QObject> // ![0] -#include <qdeclarative.h> - -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName) -Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) public: Person(QObject *parent = 0); @@ -57,6 +56,7 @@ public: int shoeSize() const; void setShoeSize(int); + private: QString m_name; int m_shoeSize; diff --git a/examples/declarative/extending/attached/birthdayparty.cpp b/examples/declarative/extending/attached/birthdayparty.cpp index d4f2675..7fa1748 100644 --- a/examples/declarative/extending/attached/birthdayparty.cpp +++ b/examples/declarative/extending/attached/birthdayparty.cpp @@ -56,18 +56,18 @@ void BirthdayPartyAttached::setRsvp(const QDate &d) } BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_celebrant(0) +: QObject(parent), m_host(0) { } -Person *BirthdayParty::celebrant() const +Person *BirthdayParty::host() const { - return m_celebrant; + return m_host; } -void BirthdayParty::setCelebrant(Person *c) +void BirthdayParty::setHost(Person *c) { - m_celebrant = c; + m_host = c; } QDeclarativeListProperty<Person> BirthdayParty::guests() diff --git a/examples/declarative/extending/attached/birthdayparty.h b/examples/declarative/extending/attached/birthdayparty.h index 7c45d21..1c66f8c 100644 --- a/examples/declarative/extending/attached/birthdayparty.h +++ b/examples/declarative/extending/attached/birthdayparty.h @@ -48,8 +48,8 @@ class BirthdayPartyAttached : public QObject { -Q_OBJECT -Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) + Q_OBJECT + Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) public: BirthdayPartyAttached(QObject *object); @@ -62,15 +62,15 @@ private: class BirthdayParty : public QObject { -Q_OBJECT -Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) -Q_CLASSINFO("DefaultProperty", "guests") + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); - Person *celebrant() const; - void setCelebrant(Person *); + Person *host() const; + void setHost(Person *); QDeclarativeListProperty<Person> guests(); int guestCount() const; @@ -78,7 +78,7 @@ public: static BirthdayPartyAttached *qmlAttachedProperties(QObject *); private: - Person *m_celebrant; + Person *m_host; QList<Person *> m_guests; }; diff --git a/examples/declarative/extending/attached/example.qml b/examples/declarative/extending/attached/example.qml index 952eb93..50f0a32 100644 --- a/examples/declarative/extending/attached/example.qml +++ b/examples/declarative/extending/attached/example.qml @@ -1,16 +1,17 @@ import People 1.0 BirthdayParty { - celebrant: Boy { + host: Boy { name: "Bob Jones" shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } } // ![1] Boy { - name: "Joan Hodges" - BirthdayParty.rsvp: "2009-07-06" + name: "Leo Hodges" shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } + + BirthdayParty.rsvp: "2009-07-06" } // ![1] Boy { @@ -19,11 +20,12 @@ BirthdayParty { } Girl { name: "Anne Brown" - BirthdayParty.rsvp: "2009-07-01" shoe.size: 7 shoe.color: "red" shoe.brand: "Marc Jacobs" shoe.price: 699.99 + + BirthdayParty.rsvp: "2009-07-01" } } diff --git a/examples/declarative/extending/attached/main.cpp b/examples/declarative/extending/attached/main.cpp index fd2d525..f1055ae 100644 --- a/examples/declarative/extending/attached/main.cpp +++ b/examples/declarative/extending/attached/main.cpp @@ -60,10 +60,10 @@ int main(int argc, char ** argv) QDeclarativeComponent component(&engine, ":example.qml"); BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); - if (party && party->celebrant()) { - qWarning() << party->celebrant()->name() << "is having a birthday!"; + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; - if (qobject_cast<Boy *>(party->celebrant())) + if (qobject_cast<Boy *>(party->host())) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; diff --git a/examples/declarative/extending/attached/person.h b/examples/declarative/extending/attached/person.h index 7a4b9c3..2f444c5 100644 --- a/examples/declarative/extending/attached/person.h +++ b/examples/declarative/extending/attached/person.h @@ -43,14 +43,14 @@ #include <QObject> #include <QColor> -#include <qdeclarative.h> -class ShoeDescription : public QObject { -Q_OBJECT -Q_PROPERTY(int size READ size WRITE setSize) -Q_PROPERTY(QColor color READ color WRITE setColor) -Q_PROPERTY(QString brand READ brand WRITE setBrand) -Q_PROPERTY(qreal price READ price WRITE setPrice) +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString brand READ brand WRITE setBrand) + Q_PROPERTY(qreal price READ price WRITE setPrice) public: ShoeDescription(QObject *parent = 0); @@ -72,10 +72,11 @@ private: qreal m_price; }; -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName) -Q_PROPERTY(ShoeDescription *shoe READ shoe) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(ShoeDescription *shoe READ shoe) public: Person(QObject *parent = 0); @@ -88,14 +89,16 @@ private: ShoeDescription m_shoe; }; -class Boy : public Person { -Q_OBJECT +class Boy : public Person +{ + Q_OBJECT public: Boy(QObject * parent = 0); }; -class Girl : public Person { -Q_OBJECT +class Girl : public Person +{ + Q_OBJECT public: Girl(QObject * parent = 0); }; diff --git a/examples/declarative/extending/binding/binding.pro b/examples/declarative/extending/binding/binding.pro index 903712e..896ce25 100644 --- a/examples/declarative/extending/binding/binding.pro +++ b/examples/declarative/extending/binding/binding.pro @@ -8,10 +8,10 @@ QT += declarative SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp \ - happybirthday.cpp + happybirthdaysong.cpp HEADERS += person.h \ birthdayparty.h \ - happybirthday.h + happybirthdaysong.h RESOURCES += binding.qrc target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/binding sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS binding.pro diff --git a/examples/declarative/extending/binding/birthdayparty.cpp b/examples/declarative/extending/binding/birthdayparty.cpp index e5be2b9..000bb1f 100644 --- a/examples/declarative/extending/binding/birthdayparty.cpp +++ b/examples/declarative/extending/binding/birthdayparty.cpp @@ -60,20 +60,20 @@ void BirthdayPartyAttached::setRsvp(const QDate &d) BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_celebrant(0) +: QObject(parent), m_host(0) { } -Person *BirthdayParty::celebrant() const +Person *BirthdayParty::host() const { - return m_celebrant; + return m_host; } -void BirthdayParty::setCelebrant(Person *c) +void BirthdayParty::setHost(Person *c) { - if (c == m_celebrant) return; - m_celebrant = c; - emit celebrantChanged(); + if (c == m_host) return; + m_host = c; + emit hostChanged(); } QDeclarativeListProperty<Person> BirthdayParty::guests() @@ -97,12 +97,12 @@ void BirthdayParty::startParty() emit partyStarted(time); } -QString BirthdayParty::speaker() const +QString BirthdayParty::announcement() const { return QString(); } -void BirthdayParty::setSpeaker(const QString &speak) +void BirthdayParty::setAnnouncement(const QString &speak) { qWarning() << qPrintable(speak); } diff --git a/examples/declarative/extending/binding/birthdayparty.h b/examples/declarative/extending/binding/birthdayparty.h index e2757bc..c3f033e 100644 --- a/examples/declarative/extending/binding/birthdayparty.h +++ b/examples/declarative/extending/binding/birthdayparty.h @@ -49,8 +49,8 @@ class BirthdayPartyAttached : public QObject { -Q_OBJECT -Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged) + Q_OBJECT + Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged) public: BirthdayPartyAttached(QObject *object); @@ -66,35 +66,35 @@ private: class BirthdayParty : public QObject { -Q_OBJECT + Q_OBJECT // ![0] -Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant NOTIFY celebrantChanged) + Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged) // ![0] -Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) -Q_PROPERTY(QString speaker READ speaker WRITE setSpeaker) -Q_CLASSINFO("DefaultProperty", "guests") + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement) + Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); - Person *celebrant() const; - void setCelebrant(Person *); + Person *host() const; + void setHost(Person *); QDeclarativeListProperty<Person> guests(); int guestCount() const; Person *guest(int) const; - QString speaker() const; - void setSpeaker(const QString &); + QString announcement() const; + void setAnnouncement(const QString &); static BirthdayPartyAttached *qmlAttachedProperties(QObject *); void startParty(); signals: void partyStarted(const QTime &time); - void celebrantChanged(); + void hostChanged(); private: - Person *m_celebrant; + Person *m_host; QList<Person *> m_guests; }; diff --git a/examples/declarative/extending/binding/example.qml b/examples/declarative/extending/binding/example.qml index b67049b..82eb3be 100644 --- a/examples/declarative/extending/binding/example.qml +++ b/examples/declarative/extending/binding/example.qml @@ -4,9 +4,9 @@ import People 1.0 BirthdayParty { id: theParty - HappyBirthday on speaker { name: theParty.celebrant.name } + HappyBirthdaySong on announcement { name: theParty.host.name } - celebrant: Boy { + host: Boy { name: "Bob Jones" shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } } @@ -15,7 +15,7 @@ BirthdayParty { Boy { - name: "Joan Hodges" + name: "Leo Hodges" BirthdayParty.rsvp: "2009-07-06" shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } } diff --git a/examples/declarative/extending/binding/happybirthday.cpp b/examples/declarative/extending/binding/happybirthdaysong.cpp index aa5f937..a40e7fb 100644 --- a/examples/declarative/extending/binding/happybirthday.cpp +++ b/examples/declarative/extending/binding/happybirthdaysong.cpp @@ -38,10 +38,10 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "happybirthday.h" +#include "happybirthdaysong.h" #include <QTimer> -HappyBirthday::HappyBirthday(QObject *parent) +HappyBirthdaySong::HappyBirthdaySong(QObject *parent) : QObject(parent), m_line(-1) { setName(QString()); @@ -50,17 +50,17 @@ HappyBirthday::HappyBirthday(QObject *parent) timer->start(1000); } -void HappyBirthday::setTarget(const QDeclarativeProperty &p) +void HappyBirthdaySong::setTarget(const QDeclarativeProperty &p) { m_target = p; } -QString HappyBirthday::name() const +QString HappyBirthdaySong::name() const { return m_name; } -void HappyBirthday::setName(const QString &name) +void HappyBirthdaySong::setName(const QString &name) { if (m_name == name) return; @@ -77,7 +77,7 @@ void HappyBirthday::setName(const QString &name) emit nameChanged(); } -void HappyBirthday::advance() +void HappyBirthdaySong::advance() { m_line = (m_line + 1) % m_lyrics.count(); diff --git a/examples/declarative/extending/binding/happybirthday.h b/examples/declarative/extending/binding/happybirthdaysong.h index 0e5a90a..e825b86 100644 --- a/examples/declarative/extending/binding/happybirthday.h +++ b/examples/declarative/extending/binding/happybirthdaysong.h @@ -38,22 +38,21 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#ifndef HAPPYBIRTHDAY_H -#define HAPPYBIRTHDAY_H +#ifndef HAPPYBIRTHDAYSONG_H +#define HAPPYBIRTHDAYSONG_H #include <QDeclarativePropertyValueSource> #include <QDeclarativeProperty> -#include <qdeclarative.h> #include <QStringList> -class HappyBirthday : public QObject, public QDeclarativePropertyValueSource +class HappyBirthdaySong : public QObject, public QDeclarativePropertyValueSource { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) -Q_INTERFACES(QDeclarativePropertyValueSource) + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_INTERFACES(QDeclarativePropertyValueSource) public: - HappyBirthday(QObject *parent = 0); + HappyBirthdaySong(QObject *parent = 0); virtual void setTarget(const QDeclarativeProperty &); @@ -72,5 +71,5 @@ private: QString m_name; }; -#endif // HAPPYBIRTHDAY_H +#endif // HAPPYBIRTHDAYSONG_H diff --git a/examples/declarative/extending/binding/main.cpp b/examples/declarative/extending/binding/main.cpp index ce6c50d..2495676 100644 --- a/examples/declarative/extending/binding/main.cpp +++ b/examples/declarative/extending/binding/main.cpp @@ -43,7 +43,7 @@ #include <QDeclarativeComponent> #include <QDebug> #include "birthdayparty.h" -#include "happybirthday.h" +#include "happybirthdaysong.h" #include "person.h" int main(int argc, char ** argv) @@ -51,7 +51,7 @@ int main(int argc, char ** argv) QCoreApplication app(argc, argv); qmlRegisterType<BirthdayPartyAttached>(); qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<HappyBirthday>("People", 1,0, "HappyBirthday"); + qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong"); qmlRegisterType<ShoeDescription>(); qmlRegisterType<Person>(); qmlRegisterType<Boy>("People", 1,0, "Boy"); @@ -61,10 +61,10 @@ int main(int argc, char ** argv) QDeclarativeComponent component(&engine, ":example.qml"); BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); - if (party && party->celebrant()) { - qWarning() << party->celebrant()->name() << "is having a birthday!"; + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; - if (qobject_cast<Boy *>(party->celebrant())) + if (qobject_cast<Boy *>(party->host())) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; diff --git a/examples/declarative/extending/binding/person.h b/examples/declarative/extending/binding/person.h index 0edfcdd..2a68da0 100644 --- a/examples/declarative/extending/binding/person.h +++ b/examples/declarative/extending/binding/person.h @@ -43,14 +43,14 @@ #include <QObject> #include <QColor> -#include <qdeclarative.h> -class ShoeDescription : public QObject { -Q_OBJECT -Q_PROPERTY(int size READ size WRITE setSize NOTIFY shoeChanged) -Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged) -Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged) -Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged) +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize NOTIFY shoeChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged) + Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged) + Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged) public: ShoeDescription(QObject *parent = 0); @@ -75,11 +75,12 @@ private: qreal m_price; }; -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) // ![0] -Q_PROPERTY(ShoeDescription *shoe READ shoe CONSTANT) + Q_PROPERTY(ShoeDescription *shoe READ shoe CONSTANT) // ![0] public: Person(QObject *parent = 0); @@ -96,14 +97,16 @@ private: ShoeDescription m_shoe; }; -class Boy : public Person { -Q_OBJECT +class Boy : public Person +{ + Q_OBJECT public: Boy(QObject * parent = 0); }; -class Girl : public Person { -Q_OBJECT +class Girl : public Person +{ + Q_OBJECT public: Girl(QObject * parent = 0); }; diff --git a/examples/declarative/extending/coercion/birthdayparty.cpp b/examples/declarative/extending/coercion/birthdayparty.cpp index 523a42d..4f415a3 100644 --- a/examples/declarative/extending/coercion/birthdayparty.cpp +++ b/examples/declarative/extending/coercion/birthdayparty.cpp @@ -41,18 +41,18 @@ #include "birthdayparty.h" BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_celebrant(0) +: QObject(parent), m_host(0) { } -Person *BirthdayParty::celebrant() const +Person *BirthdayParty::host() const { - return m_celebrant; + return m_host; } -void BirthdayParty::setCelebrant(Person *c) +void BirthdayParty::setHost(Person *c) { - m_celebrant = c; + m_host = c; } QDeclarativeListProperty<Person> BirthdayParty::guests() diff --git a/examples/declarative/extending/coercion/birthdayparty.h b/examples/declarative/extending/coercion/birthdayparty.h index a5d14f9..ee77e9a 100644 --- a/examples/declarative/extending/coercion/birthdayparty.h +++ b/examples/declarative/extending/coercion/birthdayparty.h @@ -42,28 +42,28 @@ #define BIRTHDAYPARTY_H #include <QObject> -#include <qdeclarative.h> +#include <QDeclarativeListProperty> #include "person.h" class BirthdayParty : public QObject { -Q_OBJECT + Q_OBJECT // ![0] -Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) // ![0] public: BirthdayParty(QObject *parent = 0); - Person *celebrant() const; - void setCelebrant(Person *); + Person *host() const; + void setHost(Person *); QDeclarativeListProperty<Person> guests(); int guestCount() const; Person *guest(int) const; private: - Person *m_celebrant; + Person *m_host; QList<Person *> m_guests; }; diff --git a/examples/declarative/extending/coercion/example.qml b/examples/declarative/extending/coercion/example.qml index 64d26b0..7b45950 100644 --- a/examples/declarative/extending/coercion/example.qml +++ b/examples/declarative/extending/coercion/example.qml @@ -2,12 +2,12 @@ import People 1.0 // ![0] BirthdayParty { - celebrant: Boy { + host: Boy { name: "Bob Jones" shoeSize: 12 } guests: [ - Boy { name: "Joan Hodges" }, + Boy { name: "Leo Hodges" }, Boy { name: "Jack Smith" }, Girl { name: "Anne Brown" } ] diff --git a/examples/declarative/extending/coercion/main.cpp b/examples/declarative/extending/coercion/main.cpp index 312aff9..2c7b545 100644 --- a/examples/declarative/extending/coercion/main.cpp +++ b/examples/declarative/extending/coercion/main.cpp @@ -60,10 +60,10 @@ int main(int argc, char ** argv) QDeclarativeComponent component(&engine, ":example.qml"); BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); - if (party && party->celebrant()) { - qWarning() << party->celebrant()->name() << "is having a birthday!"; + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; - if (qobject_cast<Boy *>(party->celebrant())) + if (qobject_cast<Boy *>(party->host())) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; diff --git a/examples/declarative/extending/coercion/person.h b/examples/declarative/extending/coercion/person.h index 861f135..1c95da7 100644 --- a/examples/declarative/extending/coercion/person.h +++ b/examples/declarative/extending/coercion/person.h @@ -42,12 +42,12 @@ #define PERSON_H #include <QObject> -#include <qdeclarative.h> -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName) -Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) public: Person(QObject *parent = 0); @@ -63,15 +63,17 @@ private: // ![0] -class Boy : public Person { -Q_OBJECT +class Boy : public Person +{ + Q_OBJECT public: Boy(QObject * parent = 0); }; -class Girl : public Person { -Q_OBJECT +class Girl : public Person +{ + Q_OBJECT public: Girl(QObject * parent = 0); }; diff --git a/examples/declarative/extending/default/birthdayparty.cpp b/examples/declarative/extending/default/birthdayparty.cpp index 523a42d..4f415a3 100644 --- a/examples/declarative/extending/default/birthdayparty.cpp +++ b/examples/declarative/extending/default/birthdayparty.cpp @@ -41,18 +41,18 @@ #include "birthdayparty.h" BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_celebrant(0) +: QObject(parent), m_host(0) { } -Person *BirthdayParty::celebrant() const +Person *BirthdayParty::host() const { - return m_celebrant; + return m_host; } -void BirthdayParty::setCelebrant(Person *c) +void BirthdayParty::setHost(Person *c) { - m_celebrant = c; + m_host = c; } QDeclarativeListProperty<Person> BirthdayParty::guests() diff --git a/examples/declarative/extending/default/birthdayparty.h b/examples/declarative/extending/default/birthdayparty.h index c0cb0a4..9741040 100644 --- a/examples/declarative/extending/default/birthdayparty.h +++ b/examples/declarative/extending/default/birthdayparty.h @@ -42,28 +42,28 @@ #define BIRTHDAYPARTY_H #include <QObject> -#include <qdeclarative.h> +#include <QDeclarativeListProperty> #include "person.h" // ![0] class BirthdayParty : public QObject { -Q_OBJECT -Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) -Q_CLASSINFO("DefaultProperty", "guests") + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); - Person *celebrant() const; - void setCelebrant(Person *); + Person *host() const; + void setHost(Person *); QDeclarativeListProperty<Person> guests(); int guestCount() const; Person *guest(int) const; private: - Person *m_celebrant; + Person *m_host; QList<Person *> m_guests; }; // ![0] diff --git a/examples/declarative/extending/default/example.qml b/examples/declarative/extending/default/example.qml index 58035f9..c0f3cbb 100644 --- a/examples/declarative/extending/default/example.qml +++ b/examples/declarative/extending/default/example.qml @@ -2,12 +2,12 @@ import People 1.0 // ![0] BirthdayParty { - celebrant: Boy { + host: Boy { name: "Bob Jones" shoeSize: 12 } - Boy { name: "Joan Hodges" } + Boy { name: "Leo Hodges" } Boy { name: "Jack Smith" } Girl { name: "Anne Brown" } } diff --git a/examples/declarative/extending/default/main.cpp b/examples/declarative/extending/default/main.cpp index 06282ad..2ffd180 100644 --- a/examples/declarative/extending/default/main.cpp +++ b/examples/declarative/extending/default/main.cpp @@ -58,10 +58,10 @@ int main(int argc, char ** argv) QDeclarativeComponent component(&engine, ":example.qml"); BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); - if (party && party->celebrant()) { - qWarning() << party->celebrant()->name() << "is having a birthday!"; + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; - if (qobject_cast<Boy *>(party->celebrant())) + if (qobject_cast<Boy *>(party->host())) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; diff --git a/examples/declarative/extending/default/person.h b/examples/declarative/extending/default/person.h index 832bf11..3e56860 100644 --- a/examples/declarative/extending/default/person.h +++ b/examples/declarative/extending/default/person.h @@ -42,12 +42,12 @@ #define PERSON_H #include <QObject> -#include <qdeclarative.h> -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName) -Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) public: Person(QObject *parent = 0); @@ -61,14 +61,16 @@ private: int m_shoeSize; }; -class Boy : public Person { -Q_OBJECT +class Boy : public Person +{ + Q_OBJECT public: Boy(QObject * parent = 0); }; -class Girl : public Person { -Q_OBJECT +class Girl : public Person +{ + Q_OBJECT public: Girl(QObject * parent = 0); }; diff --git a/examples/declarative/extending/extended/lineedit.h b/examples/declarative/extending/extended/lineedit.h index 9730b91..3a464b0 100644 --- a/examples/declarative/extending/extended/lineedit.h +++ b/examples/declarative/extending/extended/lineedit.h @@ -45,11 +45,11 @@ class LineEditExtension : public QObject { -Q_OBJECT -Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin NOTIFY marginsChanged) -Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin NOTIFY marginsChanged) -Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY marginsChanged) -Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY marginsChanged) + Q_OBJECT + Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin NOTIFY marginsChanged) + Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin NOTIFY marginsChanged) + Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY marginsChanged) + Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY marginsChanged) public: LineEditExtension(QObject *); diff --git a/examples/declarative/extending/grouped/birthdayparty.cpp b/examples/declarative/extending/grouped/birthdayparty.cpp index 523a42d..4f415a3 100644 --- a/examples/declarative/extending/grouped/birthdayparty.cpp +++ b/examples/declarative/extending/grouped/birthdayparty.cpp @@ -41,18 +41,18 @@ #include "birthdayparty.h" BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_celebrant(0) +: QObject(parent), m_host(0) { } -Person *BirthdayParty::celebrant() const +Person *BirthdayParty::host() const { - return m_celebrant; + return m_host; } -void BirthdayParty::setCelebrant(Person *c) +void BirthdayParty::setHost(Person *c) { - m_celebrant = c; + m_host = c; } QDeclarativeListProperty<Person> BirthdayParty::guests() diff --git a/examples/declarative/extending/grouped/birthdayparty.h b/examples/declarative/extending/grouped/birthdayparty.h index 4ac5602..31d21b2 100644 --- a/examples/declarative/extending/grouped/birthdayparty.h +++ b/examples/declarative/extending/grouped/birthdayparty.h @@ -42,27 +42,27 @@ #define BIRTHDAYPARTY_H #include <QObject> -#include <qdeclarative.h> +#include <QDeclarativeListProperty> #include "person.h" class BirthdayParty : public QObject { -Q_OBJECT -Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) -Q_CLASSINFO("DefaultProperty", "guests") + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); - Person *celebrant() const; - void setCelebrant(Person *); + Person *host() const; + void setHost(Person *); QDeclarativeListProperty<Person> guests(); int guestCount() const; Person *guest(int) const; private: - Person *m_celebrant; + Person *m_host; QList<Person *> m_guests; }; diff --git a/examples/declarative/extending/grouped/example.qml b/examples/declarative/extending/grouped/example.qml index 55912ed..91b7a06 100644 --- a/examples/declarative/extending/grouped/example.qml +++ b/examples/declarative/extending/grouped/example.qml @@ -2,13 +2,13 @@ import People 1.0 // ![0] BirthdayParty { - celebrant: Boy { + host: Boy { name: "Bob Jones" shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } } Boy { - name: "Joan Hodges" + name: "Leo Hodges" shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } } // ![1] diff --git a/examples/declarative/extending/grouped/main.cpp b/examples/declarative/extending/grouped/main.cpp index b383a8b..baf32cf 100644 --- a/examples/declarative/extending/grouped/main.cpp +++ b/examples/declarative/extending/grouped/main.cpp @@ -59,10 +59,10 @@ int main(int argc, char ** argv) QDeclarativeComponent component(&engine, ":example.qml"); BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); - if (party && party->celebrant()) { - qWarning() << party->celebrant()->name() << "is having a birthday!"; + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; - if (qobject_cast<Boy *>(party->celebrant())) + if (qobject_cast<Boy *>(party->host())) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; diff --git a/examples/declarative/extending/grouped/person.h b/examples/declarative/extending/grouped/person.h index 216c015..a031e69 100644 --- a/examples/declarative/extending/grouped/person.h +++ b/examples/declarative/extending/grouped/person.h @@ -43,14 +43,14 @@ #include <QObject> #include <QColor> -#include <qdeclarative.h> -class ShoeDescription : public QObject { -Q_OBJECT -Q_PROPERTY(int size READ size WRITE setSize) -Q_PROPERTY(QColor color READ color WRITE setColor) -Q_PROPERTY(QString brand READ brand WRITE setBrand) -Q_PROPERTY(qreal price READ price WRITE setPrice) +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString brand READ brand WRITE setBrand) + Q_PROPERTY(qreal price READ price WRITE setPrice) public: ShoeDescription(QObject *parent = 0); @@ -72,11 +72,12 @@ private: qreal m_price; }; -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) // ![1] -Q_PROPERTY(ShoeDescription *shoe READ shoe) + Q_PROPERTY(ShoeDescription *shoe READ shoe) // ![1] public: Person(QObject *parent = 0); @@ -90,14 +91,16 @@ private: ShoeDescription m_shoe; }; -class Boy : public Person { -Q_OBJECT +class Boy : public Person +{ + Q_OBJECT public: Boy(QObject * parent = 0); }; -class Girl : public Person { -Q_OBJECT +class Girl : public Person +{ + Q_OBJECT public: Girl(QObject * parent = 0); }; diff --git a/examples/declarative/extending/properties/birthdayparty.cpp b/examples/declarative/extending/properties/birthdayparty.cpp index 14fd6a3..27d17a1 100644 --- a/examples/declarative/extending/properties/birthdayparty.cpp +++ b/examples/declarative/extending/properties/birthdayparty.cpp @@ -41,19 +41,19 @@ #include "birthdayparty.h" BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_celebrant(0) +: QObject(parent), m_host(0) { } // ![0] -Person *BirthdayParty::celebrant() const +Person *BirthdayParty::host() const { - return m_celebrant; + return m_host; } -void BirthdayParty::setCelebrant(Person *c) +void BirthdayParty::setHost(Person *c) { - m_celebrant = c; + m_host = c; } QDeclarativeListProperty<Person> BirthdayParty::guests() diff --git a/examples/declarative/extending/properties/birthdayparty.h b/examples/declarative/extending/properties/birthdayparty.h index dd01562..39ce9ba 100644 --- a/examples/declarative/extending/properties/birthdayparty.h +++ b/examples/declarative/extending/properties/birthdayparty.h @@ -42,33 +42,33 @@ #define BIRTHDAYPARTY_H #include <QObject> -#include <qdeclarative.h> +#include <QDeclarativeListProperty> #include "person.h" // ![0] class BirthdayParty : public QObject { -Q_OBJECT + Q_OBJECT // ![0] // ![1] -Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) + Q_PROPERTY(Person *host READ host WRITE setHost) // ![1] // ![2] -Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) // ![2] // ![3] public: BirthdayParty(QObject *parent = 0); - Person *celebrant() const; - void setCelebrant(Person *); + Person *host() const; + void setHost(Person *); QDeclarativeListProperty<Person> guests(); int guestCount() const; Person *guest(int) const; private: - Person *m_celebrant; + Person *m_host; QList<Person *> m_guests; }; // ![3] diff --git a/examples/declarative/extending/properties/example.qml b/examples/declarative/extending/properties/example.qml index 9594a84..35abdd6 100644 --- a/examples/declarative/extending/properties/example.qml +++ b/examples/declarative/extending/properties/example.qml @@ -2,12 +2,12 @@ import People 1.0 // ![0] BirthdayParty { - celebrant: Person { + host: Person { name: "Bob Jones" shoeSize: 12 } guests: [ - Person { name: "Joan Hodges" }, + Person { name: "Leo Hodges" }, Person { name: "Jack Smith" }, Person { name: "Anne Brown" } ] diff --git a/examples/declarative/extending/properties/main.cpp b/examples/declarative/extending/properties/main.cpp index 350f8bd..85e9584 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) QDeclarativeComponent component(&engine, ":example.qml"); BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); - if (party && party->celebrant()) { - qWarning() << party->celebrant()->name() << "is having a birthday!"; + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; qWarning() << "They are inviting:"; for (int ii = 0; ii < party->guestCount(); ++ii) qWarning() << " " << party->guest(ii)->name(); diff --git a/examples/declarative/extending/properties/person.h b/examples/declarative/extending/properties/person.h index 7504d18..0029b09 100644 --- a/examples/declarative/extending/properties/person.h +++ b/examples/declarative/extending/properties/person.h @@ -42,12 +42,12 @@ #define PERSON_H #include <QObject> -#include <qdeclarative.h> -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName) -Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) public: Person(QObject *parent = 0); diff --git a/examples/declarative/extending/signal/birthdayparty.cpp b/examples/declarative/extending/signal/birthdayparty.cpp index 65ff530..740c8c9 100644 --- a/examples/declarative/extending/signal/birthdayparty.cpp +++ b/examples/declarative/extending/signal/birthdayparty.cpp @@ -57,18 +57,18 @@ void BirthdayPartyAttached::setRsvp(const QDate &d) BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_celebrant(0) +: QObject(parent), m_host(0) { } -Person *BirthdayParty::celebrant() const +Person *BirthdayParty::host() const { - return m_celebrant; + return m_host; } -void BirthdayParty::setCelebrant(Person *c) +void BirthdayParty::setHost(Person *c) { - m_celebrant = c; + m_host = c; } QDeclarativeListProperty<Person> BirthdayParty::guests() diff --git a/examples/declarative/extending/signal/birthdayparty.h b/examples/declarative/extending/signal/birthdayparty.h index a2b35cd..ae4dd39 100644 --- a/examples/declarative/extending/signal/birthdayparty.h +++ b/examples/declarative/extending/signal/birthdayparty.h @@ -48,8 +48,8 @@ class BirthdayPartyAttached : public QObject { -Q_OBJECT -Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) + Q_OBJECT + Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) public: BirthdayPartyAttached(QObject *object); @@ -62,15 +62,15 @@ private: class BirthdayParty : public QObject { -Q_OBJECT -Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) -Q_CLASSINFO("DefaultProperty", "guests") + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); - Person *celebrant() const; - void setCelebrant(Person *); + Person *host() const; + void setHost(Person *); QDeclarativeListProperty<Person> guests(); int guestCount() const; @@ -85,7 +85,7 @@ signals: // ![0] private: - Person *m_celebrant; + Person *m_host; QList<Person *> m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/signal/example.qml b/examples/declarative/extending/signal/example.qml index c7d4792..83d6a23 100644 --- a/examples/declarative/extending/signal/example.qml +++ b/examples/declarative/extending/signal/example.qml @@ -5,13 +5,13 @@ BirthdayParty { onPartyStarted: console.log("This party started rockin' at " + time); // ![0] - celebrant: Boy { + host: Boy { name: "Bob Jones" shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } } Boy { - name: "Joan Hodges" + name: "Leo Hodges" BirthdayParty.rsvp: "2009-07-06" shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } } diff --git a/examples/declarative/extending/signal/main.cpp b/examples/declarative/extending/signal/main.cpp index 1b23a46..453f688 100644 --- a/examples/declarative/extending/signal/main.cpp +++ b/examples/declarative/extending/signal/main.cpp @@ -60,10 +60,10 @@ int main(int argc, char ** argv) QDeclarativeComponent component(&engine, ":example.qml"); BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); - if (party && party->celebrant()) { - qWarning() << party->celebrant()->name() << "is having a birthday!"; + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; - if (qobject_cast<Boy *>(party->celebrant())) + if (qobject_cast<Boy *>(party->host())) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; diff --git a/examples/declarative/extending/signal/person.h b/examples/declarative/extending/signal/person.h index 7a4b9c3..2f444c5 100644 --- a/examples/declarative/extending/signal/person.h +++ b/examples/declarative/extending/signal/person.h @@ -43,14 +43,14 @@ #include <QObject> #include <QColor> -#include <qdeclarative.h> -class ShoeDescription : public QObject { -Q_OBJECT -Q_PROPERTY(int size READ size WRITE setSize) -Q_PROPERTY(QColor color READ color WRITE setColor) -Q_PROPERTY(QString brand READ brand WRITE setBrand) -Q_PROPERTY(qreal price READ price WRITE setPrice) +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString brand READ brand WRITE setBrand) + Q_PROPERTY(qreal price READ price WRITE setPrice) public: ShoeDescription(QObject *parent = 0); @@ -72,10 +72,11 @@ private: qreal m_price; }; -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName) -Q_PROPERTY(ShoeDescription *shoe READ shoe) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(ShoeDescription *shoe READ shoe) public: Person(QObject *parent = 0); @@ -88,14 +89,16 @@ private: ShoeDescription m_shoe; }; -class Boy : public Person { -Q_OBJECT +class Boy : public Person +{ + Q_OBJECT public: Boy(QObject * parent = 0); }; -class Girl : public Person { -Q_OBJECT +class Girl : public Person +{ + Q_OBJECT public: Girl(QObject * parent = 0); }; diff --git a/examples/declarative/extending/valuesource/birthdayparty.cpp b/examples/declarative/extending/valuesource/birthdayparty.cpp index 99d98be..b915f4f 100644 --- a/examples/declarative/extending/valuesource/birthdayparty.cpp +++ b/examples/declarative/extending/valuesource/birthdayparty.cpp @@ -57,18 +57,18 @@ void BirthdayPartyAttached::setRsvp(const QDate &d) BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_celebrant(0) +: QObject(parent), m_host(0) { } -Person *BirthdayParty::celebrant() const +Person *BirthdayParty::host() const { - return m_celebrant; + return m_host; } -void BirthdayParty::setCelebrant(Person *c) +void BirthdayParty::setHost(Person *c) { - m_celebrant = c; + m_host = c; } QDeclarativeListProperty<Person> BirthdayParty::guests() @@ -92,12 +92,12 @@ void BirthdayParty::startParty() emit partyStarted(time); } -QString BirthdayParty::speaker() const +QString BirthdayParty::announcement() const { return QString(); } -void BirthdayParty::setSpeaker(const QString &speak) +void BirthdayParty::setAnnouncement(const QString &speak) { qWarning() << qPrintable(speak); } diff --git a/examples/declarative/extending/valuesource/birthdayparty.h b/examples/declarative/extending/valuesource/birthdayparty.h index a9b3102..5f25781 100644 --- a/examples/declarative/extending/valuesource/birthdayparty.h +++ b/examples/declarative/extending/valuesource/birthdayparty.h @@ -49,8 +49,8 @@ class BirthdayPartyAttached : public QObject { -Q_OBJECT -Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) + Q_OBJECT + Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) public: BirthdayPartyAttached(QObject *object); @@ -63,26 +63,25 @@ private: class BirthdayParty : public QObject { -Q_OBJECT -Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost) + Q_PROPERTY(QDeclarativeListProperty<Person> guests READ guests) // ![0] -Q_PROPERTY(QString speaker READ speaker WRITE setSpeaker) + Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement) // ![0] -Q_CLASSINFO("DefaultProperty", "guests") + Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); - Person *celebrant() const; - void setCelebrant(Person *); + Person *host() const; + void setHost(Person *); QDeclarativeListProperty<Person> guests(); int guestCount() const; Person *guest(int) const; - - QString speaker() const; - void setSpeaker(const QString &); + QString announcement() const; + void setAnnouncement(const QString &); static BirthdayPartyAttached *qmlAttachedProperties(QObject *); @@ -91,7 +90,7 @@ signals: void partyStarted(const QTime &time); private: - Person *m_celebrant; + Person *m_host; QList<Person *> m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/valuesource/example.qml b/examples/declarative/extending/valuesource/example.qml index ed4d788..5b8c8af 100644 --- a/examples/declarative/extending/valuesource/example.qml +++ b/examples/declarative/extending/valuesource/example.qml @@ -2,19 +2,19 @@ import People 1.0 // ![0] BirthdayParty { - HappyBirthday on speaker { name: "Bob Jones" } + HappyBirthdaySong on announcement { name: "Bob Jones" } // ![0] onPartyStarted: console.log("This party started rockin' at " + time); - celebrant: Boy { + host: Boy { name: "Bob Jones" shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } } Boy { - name: "Joan Hodges" + name: "Leo Hodges" BirthdayParty.rsvp: "2009-07-06" shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } } diff --git a/examples/declarative/extending/valuesource/happybirthday.cpp b/examples/declarative/extending/valuesource/happybirthdaysong.cpp index 0dbbd6e..8ea5c2b 100644 --- a/examples/declarative/extending/valuesource/happybirthday.cpp +++ b/examples/declarative/extending/valuesource/happybirthdaysong.cpp @@ -38,10 +38,10 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "happybirthday.h" +#include "happybirthdaysong.h" #include <QTimer> -HappyBirthday::HappyBirthday(QObject *parent) +HappyBirthdaySong::HappyBirthdaySong(QObject *parent) : QObject(parent), m_line(-1) { setName(QString()); @@ -50,17 +50,17 @@ HappyBirthday::HappyBirthday(QObject *parent) timer->start(1000); } -void HappyBirthday::setTarget(const QDeclarativeProperty &p) +void HappyBirthdaySong::setTarget(const QDeclarativeProperty &p) { m_target = p; } -QString HappyBirthday::name() const +QString HappyBirthdaySong::name() const { return m_name; } -void HappyBirthday::setName(const QString &name) +void HappyBirthdaySong::setName(const QString &name) { m_name = name; @@ -72,7 +72,7 @@ void HappyBirthday::setName(const QString &name) m_lyrics << ""; } -void HappyBirthday::advance() +void HappyBirthdaySong::advance() { m_line = (m_line + 1) % m_lyrics.count(); diff --git a/examples/declarative/extending/valuesource/happybirthday.h b/examples/declarative/extending/valuesource/happybirthdaysong.h index 8548eb8..3d07909 100644 --- a/examples/declarative/extending/valuesource/happybirthday.h +++ b/examples/declarative/extending/valuesource/happybirthdaysong.h @@ -38,8 +38,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#ifndef HAPPYBIRTHDAY_H -#define HAPPYBIRTHDAY_H +#ifndef HAPPYBIRTHDAYSONG_H +#define HAPPYBIRTHDAYSONG_H #include <QDeclarativePropertyValueSource> #include <QDeclarativeProperty> @@ -48,14 +48,15 @@ #include <QStringList> // ![0] -class HappyBirthday : public QObject, public QDeclarativePropertyValueSource +class HappyBirthdaySong : public QObject, public QDeclarativePropertyValueSource { -Q_OBJECT + Q_OBJECT + Q_INTERFACES(QDeclarativePropertyValueSource) // ![0] -Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName) // ![1] public: - HappyBirthday(QObject *parent = 0); + HappyBirthdaySong(QObject *parent = 0); virtual void setTarget(const QDeclarativeProperty &); // ![1] @@ -75,5 +76,5 @@ private: }; // ![2] -#endif // HAPPYBIRTHDAY_H +#endif // HAPPYBIRTHDAYSONG_H diff --git a/examples/declarative/extending/valuesource/main.cpp b/examples/declarative/extending/valuesource/main.cpp index 2574917..00840ee 100644 --- a/examples/declarative/extending/valuesource/main.cpp +++ b/examples/declarative/extending/valuesource/main.cpp @@ -43,7 +43,7 @@ #include <QDeclarativeComponent> #include <QDebug> #include "birthdayparty.h" -#include "happybirthday.h" +#include "happybirthdaysong.h" #include "person.h" int main(int argc, char ** argv) @@ -52,7 +52,7 @@ int main(int argc, char ** argv) qmlRegisterType<BirthdayPartyAttached>(); qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<HappyBirthday>("People", 1,0, "HappyBirthday"); + qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong"); qmlRegisterType<ShoeDescription>(); qmlRegisterType<Person>(); qmlRegisterType<Boy>("People", 1,0, "Boy"); @@ -62,10 +62,10 @@ int main(int argc, char ** argv) QDeclarativeComponent component(&engine, ":example.qml"); BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create()); - if (party && party->celebrant()) { - qWarning() << party->celebrant()->name() << "is having a birthday!"; + if (party && party->host()) { + qWarning() << party->host()->name() << "is having a birthday!"; - if (qobject_cast<Boy *>(party->celebrant())) + if (qobject_cast<Boy *>(party->host())) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; diff --git a/examples/declarative/extending/valuesource/person.h b/examples/declarative/extending/valuesource/person.h index 7a4b9c3..2f444c5 100644 --- a/examples/declarative/extending/valuesource/person.h +++ b/examples/declarative/extending/valuesource/person.h @@ -43,14 +43,14 @@ #include <QObject> #include <QColor> -#include <qdeclarative.h> -class ShoeDescription : public QObject { -Q_OBJECT -Q_PROPERTY(int size READ size WRITE setSize) -Q_PROPERTY(QColor color READ color WRITE setColor) -Q_PROPERTY(QString brand READ brand WRITE setBrand) -Q_PROPERTY(qreal price READ price WRITE setPrice) +class ShoeDescription : public QObject +{ + Q_OBJECT + Q_PROPERTY(int size READ size WRITE setSize) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString brand READ brand WRITE setBrand) + Q_PROPERTY(qreal price READ price WRITE setPrice) public: ShoeDescription(QObject *parent = 0); @@ -72,10 +72,11 @@ private: qreal m_price; }; -class Person : public QObject { -Q_OBJECT -Q_PROPERTY(QString name READ name WRITE setName) -Q_PROPERTY(ShoeDescription *shoe READ shoe) +class Person : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(ShoeDescription *shoe READ shoe) public: Person(QObject *parent = 0); @@ -88,14 +89,16 @@ private: ShoeDescription m_shoe; }; -class Boy : public Person { -Q_OBJECT +class Boy : public Person +{ + Q_OBJECT public: Boy(QObject * parent = 0); }; -class Girl : public Person { -Q_OBJECT +class Girl : public Person +{ + Q_OBJECT public: Girl(QObject * parent = 0); }; diff --git a/examples/declarative/extending/valuesource/valuesource.pro b/examples/declarative/extending/valuesource/valuesource.pro index d3409b6..0626c98 100644 --- a/examples/declarative/extending/valuesource/valuesource.pro +++ b/examples/declarative/extending/valuesource/valuesource.pro @@ -8,10 +8,10 @@ QT += declarative SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp \ - happybirthday.cpp + happybirthdaysong.cpp HEADERS += person.h \ birthdayparty.h \ - happybirthday.h + happybirthdaysong.h RESOURCES += valuesource.qrc target.path = $$[QT_INSTALL_EXAMPLES]/declarative/extending/valuesource sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS valuesource.pro |