diff options
Diffstat (limited to 'examples/declarative/extending/binding')
-rw-r--r-- | examples/declarative/extending/binding/binding.pro | 4 | ||||
-rw-r--r-- | examples/declarative/extending/binding/birthdayparty.cpp | 18 | ||||
-rw-r--r-- | examples/declarative/extending/binding/birthdayparty.h | 26 | ||||
-rw-r--r-- | examples/declarative/extending/binding/example.qml | 6 | ||||
-rw-r--r-- | examples/declarative/extending/binding/happybirthdaysong.cpp (renamed from examples/declarative/extending/binding/happybirthday.cpp) | 12 | ||||
-rw-r--r-- | examples/declarative/extending/binding/happybirthdaysong.h (renamed from examples/declarative/extending/binding/happybirthday.h) | 17 | ||||
-rw-r--r-- | examples/declarative/extending/binding/main.cpp | 10 | ||||
-rw-r--r-- | examples/declarative/extending/binding/person.h | 33 |
8 files changed, 64 insertions, 62 deletions
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); }; |