summaryrefslogtreecommitdiffstats
path: root/examples/declarative/extending
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/extending')
-rw-r--r--examples/declarative/extending/adding/adding.pro11
-rw-r--r--examples/declarative/extending/adding/adding.qrc5
-rw-r--r--examples/declarative/extending/adding/example.qml8
-rw-r--r--examples/declarative/extending/adding/main.cpp62
-rw-r--r--examples/declarative/extending/adding/person.cpp70
-rw-r--r--examples/declarative/extending/adding/person.h67
-rw-r--r--examples/declarative/extending/attached/attached.pro13
-rw-r--r--examples/declarative/extending/attached/attached.qrc5
-rw-r--r--examples/declarative/extending/attached/birthdayparty.cpp85
-rw-r--r--examples/declarative/extending/attached/birthdayparty.h87
-rw-r--r--examples/declarative/extending/attached/example.qml29
-rw-r--r--examples/declarative/extending/attached/main.cpp84
-rw-r--r--examples/declarative/extending/attached/person.cpp123
-rw-r--r--examples/declarative/extending/attached/person.h107
-rw-r--r--examples/declarative/extending/binding/binding.pro15
-rw-r--r--examples/declarative/extending/binding/binding.qrc5
-rw-r--r--examples/declarative/extending/binding/birthdayparty.cpp106
-rw-r--r--examples/declarative/extending/binding/birthdayparty.h103
-rw-r--r--examples/declarative/extending/binding/example.qml37
-rw-r--r--examples/declarative/extending/binding/happybirthday.cpp87
-rw-r--r--examples/declarative/extending/binding/happybirthday.h76
-rw-r--r--examples/declarative/extending/binding/main.cpp85
-rw-r--r--examples/declarative/extending/binding/person.cpp143
-rw-r--r--examples/declarative/extending/binding/person.h115
-rw-r--r--examples/declarative/extending/coercion/birthdayparty.cpp63
-rw-r--r--examples/declarative/extending/coercion/birthdayparty.h69
-rw-r--r--examples/declarative/extending/coercion/coercion.pro13
-rw-r--r--examples/declarative/extending/coercion/coercion.qrc5
-rw-r--r--examples/declarative/extending/coercion/example.qml15
-rw-r--r--examples/declarative/extending/coercion/main.cpp70
-rw-r--r--examples/declarative/extending/coercion/person.cpp86
-rw-r--r--examples/declarative/extending/coercion/person.h81
-rw-r--r--examples/declarative/extending/default/birthdayparty.cpp63
-rw-r--r--examples/declarative/extending/default/birthdayparty.h70
-rw-r--r--examples/declarative/extending/default/default.pro13
-rw-r--r--examples/declarative/extending/default/default.qrc5
-rw-r--r--examples/declarative/extending/default/example.qml14
-rw-r--r--examples/declarative/extending/default/main.cpp70
-rw-r--r--examples/declarative/extending/default/person.cpp82
-rw-r--r--examples/declarative/extending/default/person.h79
-rw-r--r--examples/declarative/extending/extended/example.qml7
-rw-r--r--examples/declarative/extending/extended/extended.pro11
-rw-r--r--examples/declarative/extending/extended/extended.qrc5
-rw-r--r--examples/declarative/extending/extended/lineedit.cpp106
-rw-r--r--examples/declarative/extending/extended/lineedit.h74
-rw-r--r--examples/declarative/extending/extended/main.cpp62
-rw-r--r--examples/declarative/extending/grouped/birthdayparty.cpp63
-rw-r--r--examples/declarative/extending/grouped/birthdayparty.h68
-rw-r--r--examples/declarative/extending/grouped/example.qml33
-rw-r--r--examples/declarative/extending/grouped/grouped.pro13
-rw-r--r--examples/declarative/extending/grouped/grouped.qrc5
-rw-r--r--examples/declarative/extending/grouped/main.cpp80
-rw-r--r--examples/declarative/extending/grouped/person.cpp123
-rw-r--r--examples/declarative/extending/grouped/person.h109
-rw-r--r--examples/declarative/extending/properties/birthdayparty.cpp65
-rw-r--r--examples/declarative/extending/properties/birthdayparty.h75
-rw-r--r--examples/declarative/extending/properties/example.qml15
-rw-r--r--examples/declarative/extending/properties/main.cpp66
-rw-r--r--examples/declarative/extending/properties/person.cpp68
-rw-r--r--examples/declarative/extending/properties/person.h65
-rw-r--r--examples/declarative/extending/properties/properties.pro13
-rw-r--r--examples/declarative/extending/properties/properties.qrc5
-rw-r--r--examples/declarative/extending/signal/birthdayparty.cpp91
-rw-r--r--examples/declarative/extending/signal/birthdayparty.h94
-rw-r--r--examples/declarative/extending/signal/example.qml32
-rw-r--r--examples/declarative/extending/signal/main.cpp85
-rw-r--r--examples/declarative/extending/signal/person.cpp123
-rw-r--r--examples/declarative/extending/signal/person.h107
-rw-r--r--examples/declarative/extending/signal/signal.pro13
-rw-r--r--examples/declarative/extending/signal/signal.qrc5
-rw-r--r--examples/declarative/extending/valuesource/birthdayparty.cpp101
-rw-r--r--examples/declarative/extending/valuesource/birthdayparty.h99
-rw-r--r--examples/declarative/extending/valuesource/example.qml36
-rw-r--r--examples/declarative/extending/valuesource/happybirthday.cpp82
-rw-r--r--examples/declarative/extending/valuesource/happybirthday.h79
-rw-r--r--examples/declarative/extending/valuesource/main.cpp85
-rw-r--r--examples/declarative/extending/valuesource/person.cpp123
-rw-r--r--examples/declarative/extending/valuesource/person.h107
-rw-r--r--examples/declarative/extending/valuesource/valuesource.pro15
-rw-r--r--examples/declarative/extending/valuesource/valuesource.qrc5
80 files changed, 4739 insertions, 0 deletions
diff --git a/examples/declarative/extending/adding/adding.pro b/examples/declarative/extending/adding/adding.pro
new file mode 100644
index 0000000..c02a35f
--- /dev/null
+++ b/examples/declarative/extending/adding/adding.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = adding
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp
+HEADERS += person.h
+RESOURCES += adding.qrc
diff --git a/examples/declarative/extending/adding/adding.qrc b/examples/declarative/extending/adding/adding.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/adding/adding.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/adding/example.qml b/examples/declarative/extending/adding/example.qml
new file mode 100644
index 0000000..c608f94
--- /dev/null
+++ b/examples/declarative/extending/adding/example.qml
@@ -0,0 +1,8 @@
+import People 1.0
+
+// ![0]
+Person {
+ name: "Bob Jones"
+ shoeSize: 12
+}
+// ![0]
diff --git a/examples/declarative/extending/adding/main.cpp b/examples/declarative/extending/adding/main.cpp
new file mode 100644
index 0000000..82e4946
--- /dev/null
+++ b/examples/declarative/extending/adding/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** 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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ Person *person = qobject_cast<Person *>(component.create());
+ if (person) {
+ qWarning() << "The person's name is" << person->name();
+ qWarning() << "They wear a" << person->shoeSize() << "sized shoe";
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return 0;
+}
diff --git a/examples/declarative/extending/adding/person.cpp b/examples/declarative/extending/adding/person.cpp
new file mode 100644
index 0000000..832bcdc
--- /dev/null
+++ b/examples/declarative/extending/adding/person.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+// ![0]
+Person::Person(QObject *parent)
+: QObject(parent), m_shoeSize(0)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ m_name = n;
+}
+
+int Person::shoeSize() const
+{
+ return m_shoeSize;
+}
+
+void Person::setShoeSize(int s)
+{
+ m_shoeSize = s;
+}
+
+QML_DEFINE_TYPE(People, 1,0, Person, Person);
+// ![0]
diff --git a/examples/declarative/extending/adding/person.h b/examples/declarative/extending/adding/person.h
new file mode 100644
index 0000000..1a01586
--- /dev/null
+++ b/examples/declarative/extending/adding/person.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+// ![0]
+#include <qml.h>
+
+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);
+
+ QString name() const;
+ void setName(const QString &);
+
+ int shoeSize() const;
+ void setShoeSize(int);
+private:
+ QString m_name;
+ int m_shoeSize;
+};
+QML_DECLARE_TYPE(Person);
+// ![0]
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/attached/attached.pro b/examples/declarative/extending/attached/attached.pro
new file mode 100644
index 0000000..b0f3fea
--- /dev/null
+++ b/examples/declarative/extending/attached/attached.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+TARGET = attached
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp \
+ birthdayparty.cpp
+HEADERS += person.h \
+ birthdayparty.h
+RESOURCES += attached.qrc
diff --git a/examples/declarative/extending/attached/attached.qrc b/examples/declarative/extending/attached/attached.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/attached/attached.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/attached/birthdayparty.cpp b/examples/declarative/extending/attached/birthdayparty.cpp
new file mode 100644
index 0000000..c1f0fe8
--- /dev/null
+++ b/examples/declarative/extending/attached/birthdayparty.cpp
@@ -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 examples 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 "birthdayparty.h"
+
+BirthdayPartyAttached::BirthdayPartyAttached(QObject *object)
+: QObject(object)
+{
+}
+
+QDate BirthdayPartyAttached::rsvp() const
+{
+ return m_rsvp;
+}
+
+void BirthdayPartyAttached::setRsvp(const QDate &d)
+{
+ m_rsvp = d;
+}
+
+QML_DEFINE_NOCREATE_TYPE(BirthdayPartyAttached);
+
+BirthdayParty::BirthdayParty(QObject *parent)
+: QObject(parent), m_celebrant(0)
+{
+}
+
+Person *BirthdayParty::celebrant() const
+{
+ return m_celebrant;
+}
+
+void BirthdayParty::setCelebrant(Person *c)
+{
+ m_celebrant = c;
+}
+
+QmlList<Person *> *BirthdayParty::guests()
+{
+ return &m_guests;
+}
+
+BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
+{
+ return new BirthdayPartyAttached(object);
+}
+
+QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty);
diff --git a/examples/declarative/extending/attached/birthdayparty.h b/examples/declarative/extending/attached/birthdayparty.h
new file mode 100644
index 0000000..ffebe5f
--- /dev/null
+++ b/examples/declarative/extending/attached/birthdayparty.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** 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 examples 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 BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include <QObject>
+#include <QDate>
+#include <qml.h>
+#include "person.h"
+
+class BirthdayPartyAttached : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp)
+public:
+ BirthdayPartyAttached(QObject *object);
+
+ QDate rsvp() const;
+ void setRsvp(const QDate &);
+
+private:
+ QDate m_rsvp;
+};
+QML_DECLARE_TYPE(BirthdayPartyAttached)
+
+class BirthdayParty : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant)
+Q_PROPERTY(QmlList<Person *> *guests READ guests)
+Q_CLASSINFO("DefaultProperty", "guests")
+public:
+ BirthdayParty(QObject *parent = 0);
+
+ Person *celebrant() const;
+ void setCelebrant(Person *);
+
+ QmlList<Person *> *guests();
+
+ static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
+private:
+ Person *m_celebrant;
+ QmlConcreteList<Person *> m_guests;
+};
+
+QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPE(BirthdayParty)
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/declarative/extending/attached/example.qml b/examples/declarative/extending/attached/example.qml
new file mode 100644
index 0000000..952eb93
--- /dev/null
+++ b/examples/declarative/extending/attached/example.qml
@@ -0,0 +1,29 @@
+import People 1.0
+
+BirthdayParty {
+ celebrant: Boy {
+ name: "Bob Jones"
+ shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
+ }
+
+ // ![1]
+ Boy {
+ name: "Joan Hodges"
+ BirthdayParty.rsvp: "2009-07-06"
+ shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
+ }
+ // ![1]
+ Boy {
+ name: "Jack Smith"
+ shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 }
+ }
+ Girl {
+ name: "Anne Brown"
+ BirthdayParty.rsvp: "2009-07-01"
+ shoe.size: 7
+ shoe.color: "red"
+ shoe.brand: "Marc Jacobs"
+ shoe.price: 699.99
+ }
+}
+
diff --git a/examples/declarative/extending/attached/main.cpp b/examples/declarative/extending/attached/main.cpp
new file mode 100644
index 0000000..d99bfd3
--- /dev/null
+++ b/examples/declarative/extending/attached/main.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** 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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "birthdayparty.h"
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
+
+ if (party && party->celebrant()) {
+ qWarning() << party->celebrant()->name() << "is having a birthday!";
+
+ if (qobject_cast<Boy *>(party->celebrant()))
+ qWarning() << "He is inviting:";
+ else
+ qWarning() << "She is inviting:";
+
+ for (int ii = 0; ii < party->guests()->count(); ++ii) {
+ Person *guest = party->guests()->at(ii);
+
+ QDate rsvpDate;
+ QObject *attached =
+ qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
+ if (attached)
+ rsvpDate = attached->property("rsvp").toDate();
+
+ if (rsvpDate.isNull())
+ qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd";
+ else
+ qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString());
+ }
+
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return 0;
+}
diff --git a/examples/declarative/extending/attached/person.cpp b/examples/declarative/extending/attached/person.cpp
new file mode 100644
index 0000000..8105ee7
--- /dev/null
+++ b/examples/declarative/extending/attached/person.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+ShoeDescription::ShoeDescription(QObject *parent)
+: QObject(parent), m_size(0), m_price(0)
+{
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int s)
+{
+ m_size = s;
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &c)
+{
+ m_color = c;
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &b)
+{
+ m_brand = b;
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal p)
+{
+ m_price = p;
+}
+QML_DEFINE_NOCREATE_TYPE(ShoeDescription);
+
+Person::Person(QObject *parent)
+: QObject(parent)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ m_name = n;
+}
+
+ShoeDescription *Person::shoe()
+{
+ return &m_shoe;
+}
+
+QML_DEFINE_NOCREATE_TYPE(Person);
+
+Boy::Boy(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Boy, Boy);
+
+Girl::Girl(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Girl, Girl);
diff --git a/examples/declarative/extending/attached/person.h b/examples/declarative/extending/attached/person.h
new file mode 100644
index 0000000..c5b7727
--- /dev/null
+++ b/examples/declarative/extending/attached/person.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+#include <QColor>
+#include <qml.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)
+public:
+ ShoeDescription(QObject *parent = 0);
+
+ int size() const;
+ void setSize(int);
+
+ QColor color() const;
+ void setColor(const QColor &);
+
+ QString brand() const;
+ void setBrand(const QString &);
+
+ qreal price() const;
+ void setPrice(qreal);
+private:
+ int m_size;
+ QColor m_color;
+ QString m_brand;
+ qreal m_price;
+};
+QML_DECLARE_TYPE(ShoeDescription);
+
+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);
+
+ QString name() const;
+ void setName(const QString &);
+
+ ShoeDescription *shoe();
+private:
+ QString m_name;
+ ShoeDescription m_shoe;
+};
+QML_DECLARE_TYPE(Person);
+
+class Boy : public Person {
+Q_OBJECT
+public:
+ Boy(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Boy);
+
+class Girl : public Person {
+Q_OBJECT
+public:
+ Girl(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Girl);
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/binding/binding.pro b/examples/declarative/extending/binding/binding.pro
new file mode 100644
index 0000000..8298565
--- /dev/null
+++ b/examples/declarative/extending/binding/binding.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+TARGET = binding
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp \
+ birthdayparty.cpp \
+ happybirthday.cpp
+HEADERS += person.h \
+ birthdayparty.h \
+ happybirthday.h
+RESOURCES += binding.qrc
diff --git a/examples/declarative/extending/binding/binding.qrc b/examples/declarative/extending/binding/binding.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/binding/binding.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/binding/birthdayparty.cpp b/examples/declarative/extending/binding/birthdayparty.cpp
new file mode 100644
index 0000000..13d6bc8
--- /dev/null
+++ b/examples/declarative/extending/binding/birthdayparty.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** 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 examples 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 "birthdayparty.h"
+
+BirthdayPartyAttached::BirthdayPartyAttached(QObject *object)
+: QObject(object)
+{
+}
+
+QDate BirthdayPartyAttached::rsvp() const
+{
+ return m_rsvp;
+}
+
+void BirthdayPartyAttached::setRsvp(const QDate &d)
+{
+ if (d != m_rsvp) {
+ m_rsvp = d;
+ emit rsvpChanged();
+ }
+}
+
+QML_DEFINE_NOCREATE_TYPE(BirthdayPartyAttached);
+
+BirthdayParty::BirthdayParty(QObject *parent)
+: QObject(parent), m_celebrant(0)
+{
+}
+
+Person *BirthdayParty::celebrant() const
+{
+ return m_celebrant;
+}
+
+void BirthdayParty::setCelebrant(Person *c)
+{
+ if (c == m_celebrant) return;
+ m_celebrant = c;
+ emit celebrantChanged();
+}
+
+QmlList<Person *> *BirthdayParty::guests()
+{
+ return &m_guests;
+}
+
+void BirthdayParty::startParty()
+{
+ QTime time = QTime::currentTime();
+ emit partyStarted(time);
+}
+
+QString BirthdayParty::speaker() const
+{
+ return QString();
+}
+
+void BirthdayParty::setSpeaker(const QString &speak)
+{
+ qWarning() << qPrintable(speak);
+}
+
+BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
+{
+ return new BirthdayPartyAttached(object);
+}
+
+QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty);
diff --git a/examples/declarative/extending/binding/birthdayparty.h b/examples/declarative/extending/binding/birthdayparty.h
new file mode 100644
index 0000000..7fde54e
--- /dev/null
+++ b/examples/declarative/extending/binding/birthdayparty.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** 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 examples 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 BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include <QObject>
+#include <QDate>
+#include <QDebug>
+#include <qml.h>
+#include "person.h"
+
+class BirthdayPartyAttached : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged)
+public:
+ BirthdayPartyAttached(QObject *object);
+
+ QDate rsvp() const;
+ void setRsvp(const QDate &);
+
+signals:
+ void rsvpChanged();
+
+private:
+ QDate m_rsvp;
+};
+QML_DECLARE_TYPE(BirthdayPartyAttached)
+
+class BirthdayParty : public QObject
+{
+Q_OBJECT
+// ![0]
+Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant NOTIFY celebrantChanged)
+// ![0]
+Q_PROPERTY(QmlList<Person *> *guests READ guests)
+Q_PROPERTY(QString speaker READ speaker WRITE setSpeaker)
+Q_CLASSINFO("DefaultProperty", "guests")
+public:
+ BirthdayParty(QObject *parent = 0);
+
+ Person *celebrant() const;
+ void setCelebrant(Person *);
+
+ QmlList<Person *> *guests();
+
+ QString speaker() const;
+ void setSpeaker(const QString &);
+
+ static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
+
+ void startParty();
+signals:
+ void partyStarted(const QTime &time);
+ void celebrantChanged();
+
+private:
+ Person *m_celebrant;
+ QmlConcreteList<Person *> m_guests;
+};
+
+QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPE(BirthdayParty)
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/declarative/extending/binding/example.qml b/examples/declarative/extending/binding/example.qml
new file mode 100644
index 0000000..b66bc86
--- /dev/null
+++ b/examples/declarative/extending/binding/example.qml
@@ -0,0 +1,37 @@
+import People 1.0
+
+// ![0]
+BirthdayParty {
+ id: theParty
+
+ speaker: HappyBirthday { name: theParty.celebrant.name }
+
+ celebrant: Boy {
+ name: "Bob Jones"
+ shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
+ }
+// ![0]
+ onPartyStarted: console.log("This party started rockin' at " + time);
+
+
+ Boy {
+ name: "Joan Hodges"
+ BirthdayParty.rsvp: "2009-07-06"
+ shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
+ }
+ Boy {
+ name: "Jack Smith"
+ shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 }
+ }
+ Girl {
+ name: "Anne Brown"
+ BirthdayParty.rsvp: "2009-07-01"
+ shoe.size: 7
+ shoe.color: "red"
+ shoe.brand: "Marc Jacobs"
+ shoe.price: 699.99
+ }
+
+// ![1]
+}
+// ![1]
diff --git a/examples/declarative/extending/binding/happybirthday.cpp b/examples/declarative/extending/binding/happybirthday.cpp
new file mode 100644
index 0000000..9ce5a3d
--- /dev/null
+++ b/examples/declarative/extending/binding/happybirthday.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** 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 examples 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 "happybirthday.h"
+#include <QTimer>
+
+HappyBirthday::HappyBirthday(QObject *parent)
+: QObject(parent), m_line(-1)
+{
+ setName(QString());
+ QTimer *timer = new QTimer(this);
+ QObject::connect(timer, SIGNAL(timeout()), this, SLOT(advance()));
+ timer->start(1000);
+}
+
+void HappyBirthday::setTarget(const QmlMetaProperty &p)
+{
+ m_target = p;
+}
+
+QString HappyBirthday::name() const
+{
+ return m_name;
+}
+
+void HappyBirthday::setName(const QString &name)
+{
+ if (m_name == name)
+ return;
+
+ m_name = name;
+
+ m_lyrics.clear();
+ m_lyrics << "Happy birthday to you,";
+ m_lyrics << "Happy birthday to you,";
+ m_lyrics << "Happy birthday dear " + m_name + ",";
+ m_lyrics << "Happy birthday to you!";
+ m_lyrics << "";
+
+ emit nameChanged();
+}
+
+void HappyBirthday::advance()
+{
+ m_line = (m_line + 1) % m_lyrics.count();
+
+ m_target.write(m_lyrics.at(m_line));
+}
+
+QML_DEFINE_TYPE(People, 1,0, HappyBirthday, HappyBirthday);
diff --git a/examples/declarative/extending/binding/happybirthday.h b/examples/declarative/extending/binding/happybirthday.h
new file mode 100644
index 0000000..5a492c7
--- /dev/null
+++ b/examples/declarative/extending/binding/happybirthday.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** 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 examples 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 HAPPYBIRTHDAY_H
+#define HAPPYBIRTHDAY_H
+
+#include <QmlPropertyValueSource>
+#include <QmlMetaProperty>
+#include <qml.h>
+
+#include <QStringList>
+
+class HappyBirthday : public QObject, public QmlPropertyValueSource
+{
+Q_OBJECT
+Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+public:
+ HappyBirthday(QObject *parent = 0);
+
+ virtual void setTarget(const QmlMetaProperty &);
+
+ QString name() const;
+ void setName(const QString &);
+
+private slots:
+ void advance();
+
+signals:
+ void nameChanged();
+private:
+ int m_line;
+ QStringList m_lyrics;
+ QmlMetaProperty m_target;
+ QString m_name;
+};
+QML_DECLARE_TYPE(HappyBirthday);
+
+#endif // HAPPYBIRTHDAY_H
+
diff --git a/examples/declarative/extending/binding/main.cpp b/examples/declarative/extending/binding/main.cpp
new file mode 100644
index 0000000..c4090c4
--- /dev/null
+++ b/examples/declarative/extending/binding/main.cpp
@@ -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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "birthdayparty.h"
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
+
+ if (party && party->celebrant()) {
+ qWarning() << party->celebrant()->name() << "is having a birthday!";
+
+ if (qobject_cast<Boy *>(party->celebrant()))
+ qWarning() << "He is inviting:";
+ else
+ qWarning() << "She is inviting:";
+
+ for (int ii = 0; ii < party->guests()->count(); ++ii) {
+ Person *guest = party->guests()->at(ii);
+
+ QDate rsvpDate;
+ QObject *attached =
+ qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
+ if (attached)
+ rsvpDate = attached->property("rsvp").toDate();
+
+ if (rsvpDate.isNull())
+ qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd";
+ else
+ qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString());
+ }
+
+ party->startParty();
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return app.exec();
+}
diff --git a/examples/declarative/extending/binding/person.cpp b/examples/declarative/extending/binding/person.cpp
new file mode 100644
index 0000000..6ad62e9
--- /dev/null
+++ b/examples/declarative/extending/binding/person.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+ShoeDescription::ShoeDescription(QObject *parent)
+: QObject(parent), m_size(0), m_price(0)
+{
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int s)
+{
+ if (m_size == s)
+ return;
+
+ m_size = s;
+ emit shoeChanged();
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &c)
+{
+ if (m_color == c)
+ return;
+
+ m_color = c;
+ emit shoeChanged();
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &b)
+{
+ if (m_brand == b)
+ return;
+
+ m_brand = b;
+ emit shoeChanged();
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal p)
+{
+ if (m_price == p)
+ return;
+
+ m_price = p;
+ emit shoeChanged();
+}
+QML_DEFINE_NOCREATE_TYPE(ShoeDescription);
+
+Person::Person(QObject *parent)
+: QObject(parent)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ if (m_name == n)
+ return;
+
+ m_name = n;
+ emit nameChanged();
+}
+
+ShoeDescription *Person::shoe()
+{
+ return &m_shoe;
+}
+
+QML_DEFINE_NOCREATE_TYPE(Person);
+
+Boy::Boy(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Boy, Boy);
+
+Girl::Girl(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Girl, Girl);
diff --git a/examples/declarative/extending/binding/person.h b/examples/declarative/extending/binding/person.h
new file mode 100644
index 0000000..ad77d69
--- /dev/null
+++ b/examples/declarative/extending/binding/person.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+#include <QColor>
+#include <qml.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)
+public:
+ ShoeDescription(QObject *parent = 0);
+
+ int size() const;
+ void setSize(int);
+
+ QColor color() const;
+ void setColor(const QColor &);
+
+ QString brand() const;
+ void setBrand(const QString &);
+
+ qreal price() const;
+ void setPrice(qreal);
+signals:
+ void shoeChanged();
+
+private:
+ int m_size;
+ QColor m_color;
+ QString m_brand;
+ qreal m_price;
+};
+QML_DECLARE_TYPE(ShoeDescription);
+
+class Person : public QObject {
+Q_OBJECT
+Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+// ![0]
+Q_PROPERTY(ShoeDescription *shoe READ shoe CONSTANT);
+// ![0]
+public:
+ Person(QObject *parent = 0);
+
+ QString name() const;
+ void setName(const QString &);
+
+ ShoeDescription *shoe();
+signals:
+ void nameChanged();
+
+private:
+ QString m_name;
+ ShoeDescription m_shoe;
+};
+QML_DECLARE_TYPE(Person);
+
+class Boy : public Person {
+Q_OBJECT
+public:
+ Boy(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Boy);
+
+class Girl : public Person {
+Q_OBJECT
+public:
+ Girl(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Girl);
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/coercion/birthdayparty.cpp b/examples/declarative/extending/coercion/birthdayparty.cpp
new file mode 100644
index 0000000..f3e0846
--- /dev/null
+++ b/examples/declarative/extending/coercion/birthdayparty.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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 examples 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 "birthdayparty.h"
+
+BirthdayParty::BirthdayParty(QObject *parent)
+: QObject(parent), m_celebrant(0)
+{
+}
+
+Person *BirthdayParty::celebrant() const
+{
+ return m_celebrant;
+}
+
+void BirthdayParty::setCelebrant(Person *c)
+{
+ m_celebrant = c;
+}
+
+QmlList<Person *> *BirthdayParty::guests()
+{
+ return &m_guests;
+}
+
+QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty);
diff --git a/examples/declarative/extending/coercion/birthdayparty.h b/examples/declarative/extending/coercion/birthdayparty.h
new file mode 100644
index 0000000..810cee3
--- /dev/null
+++ b/examples/declarative/extending/coercion/birthdayparty.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** 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 examples 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 BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include <QObject>
+#include <qml.h>
+#include "person.h"
+
+class BirthdayParty : public QObject
+{
+Q_OBJECT
+// ![0]
+Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant)
+Q_PROPERTY(QmlList<Person *> *guests READ guests)
+// ![0]
+public:
+ BirthdayParty(QObject *parent = 0);
+
+ Person *celebrant() const;
+ void setCelebrant(Person *);
+
+ QmlList<Person *> *guests();
+
+private:
+ Person *m_celebrant;
+ QmlConcreteList<Person *> m_guests;
+};
+QML_DECLARE_TYPE(BirthdayParty);
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/declarative/extending/coercion/coercion.pro b/examples/declarative/extending/coercion/coercion.pro
new file mode 100644
index 0000000..136b210
--- /dev/null
+++ b/examples/declarative/extending/coercion/coercion.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+TARGET = coercion
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp \
+ birthdayparty.cpp
+HEADERS += person.h \
+ birthdayparty.h
+RESOURCES += coercion.qrc
diff --git a/examples/declarative/extending/coercion/coercion.qrc b/examples/declarative/extending/coercion/coercion.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/coercion/coercion.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/coercion/example.qml b/examples/declarative/extending/coercion/example.qml
new file mode 100644
index 0000000..64d26b0
--- /dev/null
+++ b/examples/declarative/extending/coercion/example.qml
@@ -0,0 +1,15 @@
+import People 1.0
+
+// ![0]
+BirthdayParty {
+ celebrant: Boy {
+ name: "Bob Jones"
+ shoeSize: 12
+ }
+ guests: [
+ Boy { name: "Joan Hodges" },
+ Boy { name: "Jack Smith" },
+ Girl { name: "Anne Brown" }
+ ]
+}
+// ![0]
diff --git a/examples/declarative/extending/coercion/main.cpp b/examples/declarative/extending/coercion/main.cpp
new file mode 100644
index 0000000..1ad6d26
--- /dev/null
+++ b/examples/declarative/extending/coercion/main.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "birthdayparty.h"
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
+
+ if (party && party->celebrant()) {
+ qWarning() << party->celebrant()->name() << "is having a birthday!";
+
+ if (qobject_cast<Boy *>(party->celebrant()))
+ qWarning() << "He is inviting:";
+ else
+ qWarning() << "She is inviting:";
+ for (int ii = 0; ii < party->guests()->count(); ++ii)
+ qWarning() << " " << party->guests()->at(ii)->name();
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return 0;
+}
diff --git a/examples/declarative/extending/coercion/person.cpp b/examples/declarative/extending/coercion/person.cpp
new file mode 100644
index 0000000..a897d8d
--- /dev/null
+++ b/examples/declarative/extending/coercion/person.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+Person::Person(QObject *parent)
+: QObject(parent), m_shoeSize(0)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ m_name = n;
+}
+
+int Person::shoeSize() const
+{
+ return m_shoeSize;
+}
+
+void Person::setShoeSize(int s)
+{
+ m_shoeSize = s;
+}
+
+// ![0]
+QML_DEFINE_NOCREATE_TYPE(Person);
+// ![0]
+
+// ![1]
+Boy::Boy(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Boy, Boy);
+
+Girl::Girl(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Girl, Girl);
+// ![1]
diff --git a/examples/declarative/extending/coercion/person.h b/examples/declarative/extending/coercion/person.h
new file mode 100644
index 0000000..7cfd3d6
--- /dev/null
+++ b/examples/declarative/extending/coercion/person.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+#include <qml.h>
+
+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);
+
+ QString name() const;
+ void setName(const QString &);
+
+ int shoeSize() const;
+ void setShoeSize(int);
+private:
+ QString m_name;
+ int m_shoeSize;
+};
+QML_DECLARE_TYPE(Person);
+
+// ![0]
+class Boy : public Person {
+Q_OBJECT
+public:
+ Boy(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Boy);
+
+class Girl : public Person {
+Q_OBJECT
+public:
+ Girl(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Girl);
+// ![0]
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/default/birthdayparty.cpp b/examples/declarative/extending/default/birthdayparty.cpp
new file mode 100644
index 0000000..f3e0846
--- /dev/null
+++ b/examples/declarative/extending/default/birthdayparty.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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 examples 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 "birthdayparty.h"
+
+BirthdayParty::BirthdayParty(QObject *parent)
+: QObject(parent), m_celebrant(0)
+{
+}
+
+Person *BirthdayParty::celebrant() const
+{
+ return m_celebrant;
+}
+
+void BirthdayParty::setCelebrant(Person *c)
+{
+ m_celebrant = c;
+}
+
+QmlList<Person *> *BirthdayParty::guests()
+{
+ return &m_guests;
+}
+
+QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty);
diff --git a/examples/declarative/extending/default/birthdayparty.h b/examples/declarative/extending/default/birthdayparty.h
new file mode 100644
index 0000000..cafe4c7
--- /dev/null
+++ b/examples/declarative/extending/default/birthdayparty.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 examples 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 BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include <QObject>
+#include <qml.h>
+#include "person.h"
+
+// ![0]
+class BirthdayParty : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant)
+Q_PROPERTY(QmlList<Person *> *guests READ guests)
+Q_CLASSINFO("DefaultProperty", "guests")
+public:
+ BirthdayParty(QObject *parent = 0);
+
+ Person *celebrant() const;
+ void setCelebrant(Person *);
+
+ QmlList<Person *> *guests();
+
+private:
+ Person *m_celebrant;
+ QmlConcreteList<Person *> m_guests;
+};
+// ![0]
+QML_DECLARE_TYPE(BirthdayParty);
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/declarative/extending/default/default.pro b/examples/declarative/extending/default/default.pro
new file mode 100644
index 0000000..0d5d45c
--- /dev/null
+++ b/examples/declarative/extending/default/default.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+TARGET = default
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp \
+ birthdayparty.cpp
+HEADERS += person.h \
+ birthdayparty.h
+RESOURCES += default.qrc
diff --git a/examples/declarative/extending/default/default.qrc b/examples/declarative/extending/default/default.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/default/default.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/default/example.qml b/examples/declarative/extending/default/example.qml
new file mode 100644
index 0000000..58035f9
--- /dev/null
+++ b/examples/declarative/extending/default/example.qml
@@ -0,0 +1,14 @@
+import People 1.0
+
+// ![0]
+BirthdayParty {
+ celebrant: Boy {
+ name: "Bob Jones"
+ shoeSize: 12
+ }
+
+ Boy { name: "Joan Hodges" }
+ Boy { name: "Jack Smith" }
+ Girl { name: "Anne Brown" }
+}
+// ![0]
diff --git a/examples/declarative/extending/default/main.cpp b/examples/declarative/extending/default/main.cpp
new file mode 100644
index 0000000..1ad6d26
--- /dev/null
+++ b/examples/declarative/extending/default/main.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "birthdayparty.h"
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
+
+ if (party && party->celebrant()) {
+ qWarning() << party->celebrant()->name() << "is having a birthday!";
+
+ if (qobject_cast<Boy *>(party->celebrant()))
+ qWarning() << "He is inviting:";
+ else
+ qWarning() << "She is inviting:";
+ for (int ii = 0; ii < party->guests()->count(); ++ii)
+ qWarning() << " " << party->guests()->at(ii)->name();
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return 0;
+}
diff --git a/examples/declarative/extending/default/person.cpp b/examples/declarative/extending/default/person.cpp
new file mode 100644
index 0000000..a5eafc4
--- /dev/null
+++ b/examples/declarative/extending/default/person.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+Person::Person(QObject *parent)
+: QObject(parent), m_shoeSize(0)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ m_name = n;
+}
+
+int Person::shoeSize() const
+{
+ return m_shoeSize;
+}
+
+void Person::setShoeSize(int s)
+{
+ m_shoeSize = s;
+}
+
+QML_DEFINE_NOCREATE_TYPE(Person);
+
+Boy::Boy(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Boy, Boy);
+
+Girl::Girl(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Girl, Girl);
diff --git a/examples/declarative/extending/default/person.h b/examples/declarative/extending/default/person.h
new file mode 100644
index 0000000..6fd9232
--- /dev/null
+++ b/examples/declarative/extending/default/person.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+#include <qml.h>
+
+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);
+
+ QString name() const;
+ void setName(const QString &);
+
+ int shoeSize() const;
+ void setShoeSize(int);
+private:
+ QString m_name;
+ int m_shoeSize;
+};
+QML_DECLARE_TYPE(Person);
+
+class Boy : public Person {
+Q_OBJECT
+public:
+ Boy(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Boy);
+
+class Girl : public Person {
+Q_OBJECT
+public:
+ Girl(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Girl);
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/extended/example.qml b/examples/declarative/extending/extended/example.qml
new file mode 100644
index 0000000..985ce20
--- /dev/null
+++ b/examples/declarative/extending/extended/example.qml
@@ -0,0 +1,7 @@
+import People 1.0
+
+// ![0]
+QLineEdit {
+ leftMargin: 20
+}
+// ![0]
diff --git a/examples/declarative/extending/extended/extended.pro b/examples/declarative/extending/extended/extended.pro
new file mode 100644
index 0000000..1182226
--- /dev/null
+++ b/examples/declarative/extending/extended/extended.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = extended
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ lineedit.cpp
+HEADERS += lineedit.h
+RESOURCES += extended.qrc
diff --git a/examples/declarative/extending/extended/extended.qrc b/examples/declarative/extending/extended/extended.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/extended/extended.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/extended/lineedit.cpp b/examples/declarative/extending/extended/lineedit.cpp
new file mode 100644
index 0000000..8a31004
--- /dev/null
+++ b/examples/declarative/extending/extended/lineedit.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** 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 examples 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 "lineedit.h"
+#include <qml.h>
+
+LineEditExtension::LineEditExtension(QObject *object)
+: QObject(object), m_lineedit(static_cast<QLineEdit *>(object))
+{
+}
+
+int LineEditExtension::leftMargin() const
+{
+ int l, r, t, b;
+ m_lineedit->getTextMargins(&l, &t, &r, &b);
+ return l;
+}
+
+void LineEditExtension::setLeftMargin(int m)
+{
+ int l, r, t, b;
+ m_lineedit->getTextMargins(&l, &t, &r, &b);
+ m_lineedit->setTextMargins(m, t, r, b);
+}
+
+int LineEditExtension::rightMargin() const
+{
+ int l, r, t, b;
+ m_lineedit->getTextMargins(&l, &t, &r, &b);
+ return r;
+}
+
+void LineEditExtension::setRightMargin(int m)
+{
+ int l, r, t, b;
+ m_lineedit->getTextMargins(&l, &t, &r, &b);
+ m_lineedit->setTextMargins(l, t, m, b);
+}
+
+int LineEditExtension::topMargin() const
+{
+ int l, r, t, b;
+ m_lineedit->getTextMargins(&l, &t, &r, &b);
+ return t;
+}
+
+void LineEditExtension::setTopMargin(int m)
+{
+ int l, r, t, b;
+ m_lineedit->getTextMargins(&l, &t, &r, &b);
+ m_lineedit->setTextMargins(l, m, r, b);
+}
+
+int LineEditExtension::bottomMargin() const
+{
+ int l, r, t, b;
+ m_lineedit->getTextMargins(&l, &t, &r, &b);
+ return b;
+}
+
+void LineEditExtension::setBottomMargin(int m)
+{
+ int l, r, t, b;
+ m_lineedit->getTextMargins(&l, &t, &r, &b);
+ m_lineedit->setTextMargins(l, t, r, m);
+}
+
+QML_DECLARE_TYPE(QLineEdit);
+QML_DEFINE_EXTENDED_TYPE(People, 1,0, QLineEdit, QLineEdit, LineEditExtension);
diff --git a/examples/declarative/extending/extended/lineedit.h b/examples/declarative/extending/extended/lineedit.h
new file mode 100644
index 0000000..3f03ba1
--- /dev/null
+++ b/examples/declarative/extending/extended/lineedit.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** 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 examples 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 LINEEDIT_H
+#define LINEEDIT_H
+
+#include <QLineEdit>
+
+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);
+public:
+ LineEditExtension(QObject *);
+
+ int leftMargin() const;
+ void setLeftMargin(int);
+
+ int rightMargin() const;
+ void setRightMargin(int);
+
+ int topMargin() const;
+ void setTopMargin(int);
+
+ int bottomMargin() const;
+ void setBottomMargin(int);
+signals:
+ void marginsChanged();
+
+private:
+ QLineEdit *m_lineedit;
+};
+
+#endif // LINEEDIT_H
diff --git a/examples/declarative/extending/extended/main.cpp b/examples/declarative/extending/extended/main.cpp
new file mode 100644
index 0000000..c956ebc
--- /dev/null
+++ b/examples/declarative/extending/extended/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** 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 examples 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 <QApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include <QLineEdit>
+
+int main(int argc, char ** argv)
+{
+ QApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ QLineEdit *edit = qobject_cast<QLineEdit *>(component.create());
+
+ if (edit) {
+ edit->show();
+ return app.exec();
+ } else {
+ qWarning() << "An error occured";
+ return 0;
+ }
+}
diff --git a/examples/declarative/extending/grouped/birthdayparty.cpp b/examples/declarative/extending/grouped/birthdayparty.cpp
new file mode 100644
index 0000000..f3e0846
--- /dev/null
+++ b/examples/declarative/extending/grouped/birthdayparty.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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 examples 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 "birthdayparty.h"
+
+BirthdayParty::BirthdayParty(QObject *parent)
+: QObject(parent), m_celebrant(0)
+{
+}
+
+Person *BirthdayParty::celebrant() const
+{
+ return m_celebrant;
+}
+
+void BirthdayParty::setCelebrant(Person *c)
+{
+ m_celebrant = c;
+}
+
+QmlList<Person *> *BirthdayParty::guests()
+{
+ return &m_guests;
+}
+
+QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty);
diff --git a/examples/declarative/extending/grouped/birthdayparty.h b/examples/declarative/extending/grouped/birthdayparty.h
new file mode 100644
index 0000000..ba8a68d
--- /dev/null
+++ b/examples/declarative/extending/grouped/birthdayparty.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** 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 examples 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 BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include <QObject>
+#include <qml.h>
+#include "person.h"
+
+class BirthdayParty : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant)
+Q_PROPERTY(QmlList<Person *> *guests READ guests)
+Q_CLASSINFO("DefaultProperty", "guests")
+public:
+ BirthdayParty(QObject *parent = 0);
+
+ Person *celebrant() const;
+ void setCelebrant(Person *);
+
+ QmlList<Person *> *guests();
+
+private:
+ Person *m_celebrant;
+ QmlConcreteList<Person *> m_guests;
+};
+QML_DECLARE_TYPE(BirthdayParty);
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/declarative/extending/grouped/example.qml b/examples/declarative/extending/grouped/example.qml
new file mode 100644
index 0000000..55912ed
--- /dev/null
+++ b/examples/declarative/extending/grouped/example.qml
@@ -0,0 +1,33 @@
+import People 1.0
+
+// ![0]
+BirthdayParty {
+ celebrant: Boy {
+ name: "Bob Jones"
+ shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
+ }
+
+ Boy {
+ name: "Joan Hodges"
+ shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
+ }
+ // ![1]
+ Boy {
+ name: "Jack Smith"
+ shoe {
+ size: 8
+ color: "blue"
+ brand: "Puma"
+ price: 19.95
+ }
+ }
+ // ![1]
+ Girl {
+ name: "Anne Brown"
+ shoe.size: 7
+ shoe.color: "red"
+ shoe.brand: "Marc Jacobs"
+ shoe.price: 699.99
+ }
+}
+// ![0]
diff --git a/examples/declarative/extending/grouped/grouped.pro b/examples/declarative/extending/grouped/grouped.pro
new file mode 100644
index 0000000..8fde8e8
--- /dev/null
+++ b/examples/declarative/extending/grouped/grouped.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+TARGET = grouped
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp \
+ birthdayparty.cpp
+HEADERS += person.h \
+ birthdayparty.h
+RESOURCES += grouped.qrc
diff --git a/examples/declarative/extending/grouped/grouped.qrc b/examples/declarative/extending/grouped/grouped.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/grouped/grouped.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/grouped/main.cpp b/examples/declarative/extending/grouped/main.cpp
new file mode 100644
index 0000000..baf5349
--- /dev/null
+++ b/examples/declarative/extending/grouped/main.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** 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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "birthdayparty.h"
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
+
+ if (party && party->celebrant()) {
+ qWarning() << party->celebrant()->name() << "is having a birthday!";
+
+ if (qobject_cast<Boy *>(party->celebrant()))
+ qWarning() << "He is inviting:";
+ else
+ qWarning() << "She is inviting:";
+
+ Person *bestShoe = 0;
+ for (int ii = 0; ii < party->guests()->count(); ++ii) {
+ Person *guest = party->guests()->at(ii);
+ qWarning() << " " << guest->name();
+
+ if (!bestShoe || bestShoe->shoe()->price() < guest->shoe()->price())
+ bestShoe = guest;
+ }
+ if (bestShoe)
+ qWarning() << bestShoe->name() << "is wearing the best shoes!";
+
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return 0;
+}
diff --git a/examples/declarative/extending/grouped/person.cpp b/examples/declarative/extending/grouped/person.cpp
new file mode 100644
index 0000000..8105ee7
--- /dev/null
+++ b/examples/declarative/extending/grouped/person.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+ShoeDescription::ShoeDescription(QObject *parent)
+: QObject(parent), m_size(0), m_price(0)
+{
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int s)
+{
+ m_size = s;
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &c)
+{
+ m_color = c;
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &b)
+{
+ m_brand = b;
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal p)
+{
+ m_price = p;
+}
+QML_DEFINE_NOCREATE_TYPE(ShoeDescription);
+
+Person::Person(QObject *parent)
+: QObject(parent)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ m_name = n;
+}
+
+ShoeDescription *Person::shoe()
+{
+ return &m_shoe;
+}
+
+QML_DEFINE_NOCREATE_TYPE(Person);
+
+Boy::Boy(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Boy, Boy);
+
+Girl::Girl(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Girl, Girl);
diff --git a/examples/declarative/extending/grouped/person.h b/examples/declarative/extending/grouped/person.h
new file mode 100644
index 0000000..5cd3e8f
--- /dev/null
+++ b/examples/declarative/extending/grouped/person.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+#include <QColor>
+#include <qml.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)
+public:
+ ShoeDescription(QObject *parent = 0);
+
+ int size() const;
+ void setSize(int);
+
+ QColor color() const;
+ void setColor(const QColor &);
+
+ QString brand() const;
+ void setBrand(const QString &);
+
+ qreal price() const;
+ void setPrice(qreal);
+private:
+ int m_size;
+ QColor m_color;
+ QString m_brand;
+ qreal m_price;
+};
+QML_DECLARE_TYPE(ShoeDescription);
+
+class Person : public QObject {
+Q_OBJECT
+Q_PROPERTY(QString name READ name WRITE setName)
+// ![1]
+Q_PROPERTY(ShoeDescription *shoe READ shoe);
+// ![1]
+public:
+ Person(QObject *parent = 0);
+
+ QString name() const;
+ void setName(const QString &);
+
+ ShoeDescription *shoe();
+private:
+ QString m_name;
+ ShoeDescription m_shoe;
+};
+QML_DECLARE_TYPE(Person);
+
+class Boy : public Person {
+Q_OBJECT
+public:
+ Boy(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Boy);
+
+class Girl : public Person {
+Q_OBJECT
+public:
+ Girl(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Girl);
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/properties/birthdayparty.cpp b/examples/declarative/extending/properties/birthdayparty.cpp
new file mode 100644
index 0000000..b98a691
--- /dev/null
+++ b/examples/declarative/extending/properties/birthdayparty.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 examples 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 "birthdayparty.h"
+
+BirthdayParty::BirthdayParty(QObject *parent)
+: QObject(parent), m_celebrant(0)
+{
+}
+
+// ![0]
+Person *BirthdayParty::celebrant() const
+{
+ return m_celebrant;
+}
+
+void BirthdayParty::setCelebrant(Person *c)
+{
+ m_celebrant = c;
+}
+
+QmlList<Person *> *BirthdayParty::guests()
+{
+ return &m_guests;
+}
+// ![0]
+
+QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty);
diff --git a/examples/declarative/extending/properties/birthdayparty.h b/examples/declarative/extending/properties/birthdayparty.h
new file mode 100644
index 0000000..7bc3c3f
--- /dev/null
+++ b/examples/declarative/extending/properties/birthdayparty.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** 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 examples 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 BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include <QObject>
+#include <qml.h>
+#include "person.h"
+
+// ![0]
+class BirthdayParty : public QObject
+{
+Q_OBJECT
+// ![0]
+// ![1]
+Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant)
+// ![1]
+// ![2]
+Q_PROPERTY(QmlList<Person *> *guests READ guests)
+// ![2]
+// ![3]
+public:
+ BirthdayParty(QObject *parent = 0);
+
+ Person *celebrant() const;
+ void setCelebrant(Person *);
+
+ QmlList<Person *> *guests();
+
+private:
+ Person *m_celebrant;
+ QmlConcreteList<Person *> m_guests;
+};
+QML_DECLARE_TYPE(BirthdayParty);
+// ![3]
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/declarative/extending/properties/example.qml b/examples/declarative/extending/properties/example.qml
new file mode 100644
index 0000000..9594a84
--- /dev/null
+++ b/examples/declarative/extending/properties/example.qml
@@ -0,0 +1,15 @@
+import People 1.0
+
+// ![0]
+BirthdayParty {
+ celebrant: Person {
+ name: "Bob Jones"
+ shoeSize: 12
+ }
+ guests: [
+ Person { name: "Joan Hodges" },
+ Person { name: "Jack Smith" },
+ Person { name: "Anne Brown" }
+ ]
+}
+// ![0]
diff --git a/examples/declarative/extending/properties/main.cpp b/examples/declarative/extending/properties/main.cpp
new file mode 100644
index 0000000..590628e
--- /dev/null
+++ b/examples/declarative/extending/properties/main.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** 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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "birthdayparty.h"
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
+
+ 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();
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return 0;
+}
diff --git a/examples/declarative/extending/properties/person.cpp b/examples/declarative/extending/properties/person.cpp
new file mode 100644
index 0000000..b41d0b6
--- /dev/null
+++ b/examples/declarative/extending/properties/person.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+Person::Person(QObject *parent)
+: QObject(parent), m_shoeSize(0)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ m_name = n;
+}
+
+int Person::shoeSize() const
+{
+ return m_shoeSize;
+}
+
+void Person::setShoeSize(int s)
+{
+ m_shoeSize = s;
+}
+
+QML_DEFINE_TYPE(People, 1,0, Person, Person);
diff --git a/examples/declarative/extending/properties/person.h b/examples/declarative/extending/properties/person.h
new file mode 100644
index 0000000..1c69f5a
--- /dev/null
+++ b/examples/declarative/extending/properties/person.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+#include <qml.h>
+
+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);
+
+ QString name() const;
+ void setName(const QString &);
+
+ int shoeSize() const;
+ void setShoeSize(int);
+private:
+ QString m_name;
+ int m_shoeSize;
+};
+QML_DECLARE_TYPE(Person);
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/properties/properties.pro b/examples/declarative/extending/properties/properties.pro
new file mode 100644
index 0000000..6355644
--- /dev/null
+++ b/examples/declarative/extending/properties/properties.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+TARGET = properties
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp \
+ birthdayparty.cpp
+HEADERS += person.h \
+ birthdayparty.h
+RESOURCES += properties.qrc
diff --git a/examples/declarative/extending/properties/properties.qrc b/examples/declarative/extending/properties/properties.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/properties/properties.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/signal/birthdayparty.cpp b/examples/declarative/extending/signal/birthdayparty.cpp
new file mode 100644
index 0000000..178ce0e
--- /dev/null
+++ b/examples/declarative/extending/signal/birthdayparty.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** 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 examples 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 "birthdayparty.h"
+
+BirthdayPartyAttached::BirthdayPartyAttached(QObject *object)
+: QObject(object)
+{
+}
+
+QDate BirthdayPartyAttached::rsvp() const
+{
+ return m_rsvp;
+}
+
+void BirthdayPartyAttached::setRsvp(const QDate &d)
+{
+ m_rsvp = d;
+}
+
+QML_DEFINE_NOCREATE_TYPE(BirthdayPartyAttached);
+
+BirthdayParty::BirthdayParty(QObject *parent)
+: QObject(parent), m_celebrant(0)
+{
+}
+
+Person *BirthdayParty::celebrant() const
+{
+ return m_celebrant;
+}
+
+void BirthdayParty::setCelebrant(Person *c)
+{
+ m_celebrant = c;
+}
+
+QmlList<Person *> *BirthdayParty::guests()
+{
+ return &m_guests;
+}
+
+void BirthdayParty::startParty()
+{
+ QTime time = QTime::currentTime();
+ emit partyStarted(time);
+}
+
+BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
+{
+ return new BirthdayPartyAttached(object);
+}
+
+QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty);
diff --git a/examples/declarative/extending/signal/birthdayparty.h b/examples/declarative/extending/signal/birthdayparty.h
new file mode 100644
index 0000000..56a809e
--- /dev/null
+++ b/examples/declarative/extending/signal/birthdayparty.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** 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 examples 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 BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include <QObject>
+#include <QDate>
+#include <qml.h>
+#include "person.h"
+
+class BirthdayPartyAttached : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp)
+public:
+ BirthdayPartyAttached(QObject *object);
+
+ QDate rsvp() const;
+ void setRsvp(const QDate &);
+
+private:
+ QDate m_rsvp;
+};
+QML_DECLARE_TYPE(BirthdayPartyAttached)
+
+class BirthdayParty : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant)
+Q_PROPERTY(QmlList<Person *> *guests READ guests)
+Q_CLASSINFO("DefaultProperty", "guests")
+public:
+ BirthdayParty(QObject *parent = 0);
+
+ Person *celebrant() const;
+ void setCelebrant(Person *);
+
+ QmlList<Person *> *guests();
+
+ static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
+
+ void startParty();
+// ![0]
+signals:
+ void partyStarted(const QTime &time);
+// ![0]
+
+private:
+ Person *m_celebrant;
+ QmlConcreteList<Person *> m_guests;
+};
+
+QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPE(BirthdayParty)
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/declarative/extending/signal/example.qml b/examples/declarative/extending/signal/example.qml
new file mode 100644
index 0000000..c7d4792
--- /dev/null
+++ b/examples/declarative/extending/signal/example.qml
@@ -0,0 +1,32 @@
+import People 1.0
+
+// ![0]
+BirthdayParty {
+ onPartyStarted: console.log("This party started rockin' at " + time);
+// ![0]
+
+ celebrant: Boy {
+ name: "Bob Jones"
+ shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
+ }
+
+ Boy {
+ name: "Joan Hodges"
+ BirthdayParty.rsvp: "2009-07-06"
+ shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
+ }
+ Boy {
+ name: "Jack Smith"
+ shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 }
+ }
+ Girl {
+ name: "Anne Brown"
+ BirthdayParty.rsvp: "2009-07-01"
+ shoe.size: 7
+ shoe.color: "red"
+ shoe.brand: "Marc Jacobs"
+ shoe.price: 699.99
+ }
+// ![1]
+}
+// ![1]
diff --git a/examples/declarative/extending/signal/main.cpp b/examples/declarative/extending/signal/main.cpp
new file mode 100644
index 0000000..d4e32a1
--- /dev/null
+++ b/examples/declarative/extending/signal/main.cpp
@@ -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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "birthdayparty.h"
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
+
+ if (party && party->celebrant()) {
+ qWarning() << party->celebrant()->name() << "is having a birthday!";
+
+ if (qobject_cast<Boy *>(party->celebrant()))
+ qWarning() << "He is inviting:";
+ else
+ qWarning() << "She is inviting:";
+
+ for (int ii = 0; ii < party->guests()->count(); ++ii) {
+ Person *guest = party->guests()->at(ii);
+
+ QDate rsvpDate;
+ QObject *attached =
+ qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
+ if (attached)
+ rsvpDate = attached->property("rsvp").toDate();
+
+ if (rsvpDate.isNull())
+ qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd";
+ else
+ qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString());
+ }
+
+ party->startParty();
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return 0;
+}
diff --git a/examples/declarative/extending/signal/person.cpp b/examples/declarative/extending/signal/person.cpp
new file mode 100644
index 0000000..8105ee7
--- /dev/null
+++ b/examples/declarative/extending/signal/person.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+ShoeDescription::ShoeDescription(QObject *parent)
+: QObject(parent), m_size(0), m_price(0)
+{
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int s)
+{
+ m_size = s;
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &c)
+{
+ m_color = c;
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &b)
+{
+ m_brand = b;
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal p)
+{
+ m_price = p;
+}
+QML_DEFINE_NOCREATE_TYPE(ShoeDescription);
+
+Person::Person(QObject *parent)
+: QObject(parent)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ m_name = n;
+}
+
+ShoeDescription *Person::shoe()
+{
+ return &m_shoe;
+}
+
+QML_DEFINE_NOCREATE_TYPE(Person);
+
+Boy::Boy(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Boy, Boy);
+
+Girl::Girl(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Girl, Girl);
diff --git a/examples/declarative/extending/signal/person.h b/examples/declarative/extending/signal/person.h
new file mode 100644
index 0000000..c5b7727
--- /dev/null
+++ b/examples/declarative/extending/signal/person.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+#include <QColor>
+#include <qml.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)
+public:
+ ShoeDescription(QObject *parent = 0);
+
+ int size() const;
+ void setSize(int);
+
+ QColor color() const;
+ void setColor(const QColor &);
+
+ QString brand() const;
+ void setBrand(const QString &);
+
+ qreal price() const;
+ void setPrice(qreal);
+private:
+ int m_size;
+ QColor m_color;
+ QString m_brand;
+ qreal m_price;
+};
+QML_DECLARE_TYPE(ShoeDescription);
+
+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);
+
+ QString name() const;
+ void setName(const QString &);
+
+ ShoeDescription *shoe();
+private:
+ QString m_name;
+ ShoeDescription m_shoe;
+};
+QML_DECLARE_TYPE(Person);
+
+class Boy : public Person {
+Q_OBJECT
+public:
+ Boy(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Boy);
+
+class Girl : public Person {
+Q_OBJECT
+public:
+ Girl(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Girl);
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/signal/signal.pro b/examples/declarative/extending/signal/signal.pro
new file mode 100644
index 0000000..30e413f
--- /dev/null
+++ b/examples/declarative/extending/signal/signal.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+TARGET = signal
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp \
+ birthdayparty.cpp
+HEADERS += person.h \
+ birthdayparty.h
+RESOURCES += signal.qrc
diff --git a/examples/declarative/extending/signal/signal.qrc b/examples/declarative/extending/signal/signal.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/signal/signal.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>
diff --git a/examples/declarative/extending/valuesource/birthdayparty.cpp b/examples/declarative/extending/valuesource/birthdayparty.cpp
new file mode 100644
index 0000000..b0472d0
--- /dev/null
+++ b/examples/declarative/extending/valuesource/birthdayparty.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** 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 examples 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 "birthdayparty.h"
+
+BirthdayPartyAttached::BirthdayPartyAttached(QObject *object)
+: QObject(object)
+{
+}
+
+QDate BirthdayPartyAttached::rsvp() const
+{
+ return m_rsvp;
+}
+
+void BirthdayPartyAttached::setRsvp(const QDate &d)
+{
+ m_rsvp = d;
+}
+
+QML_DEFINE_NOCREATE_TYPE(BirthdayPartyAttached);
+
+BirthdayParty::BirthdayParty(QObject *parent)
+: QObject(parent), m_celebrant(0)
+{
+}
+
+Person *BirthdayParty::celebrant() const
+{
+ return m_celebrant;
+}
+
+void BirthdayParty::setCelebrant(Person *c)
+{
+ m_celebrant = c;
+}
+
+QmlList<Person *> *BirthdayParty::guests()
+{
+ return &m_guests;
+}
+
+void BirthdayParty::startParty()
+{
+ QTime time = QTime::currentTime();
+ emit partyStarted(time);
+}
+
+QString BirthdayParty::speaker() const
+{
+ return QString();
+}
+
+void BirthdayParty::setSpeaker(const QString &speak)
+{
+ qWarning() << qPrintable(speak);
+}
+
+BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
+{
+ return new BirthdayPartyAttached(object);
+}
+
+QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty);
diff --git a/examples/declarative/extending/valuesource/birthdayparty.h b/examples/declarative/extending/valuesource/birthdayparty.h
new file mode 100644
index 0000000..11e1fdf
--- /dev/null
+++ b/examples/declarative/extending/valuesource/birthdayparty.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** 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 examples 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 BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include <QObject>
+#include <QDate>
+#include <QDebug>
+#include <qml.h>
+#include "person.h"
+
+class BirthdayPartyAttached : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp)
+public:
+ BirthdayPartyAttached(QObject *object);
+
+ QDate rsvp() const;
+ void setRsvp(const QDate &);
+
+private:
+ QDate m_rsvp;
+};
+QML_DECLARE_TYPE(BirthdayPartyAttached)
+
+class BirthdayParty : public QObject
+{
+Q_OBJECT
+Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant)
+Q_PROPERTY(QmlList<Person *> *guests READ guests)
+// ![0]
+Q_PROPERTY(QString speaker READ speaker WRITE setSpeaker)
+// ![0]
+Q_CLASSINFO("DefaultProperty", "guests")
+public:
+ BirthdayParty(QObject *parent = 0);
+
+ Person *celebrant() const;
+ void setCelebrant(Person *);
+
+ QmlList<Person *> *guests();
+
+ QString speaker() const;
+ void setSpeaker(const QString &);
+
+ static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
+
+ void startParty();
+signals:
+ void partyStarted(const QTime &time);
+
+private:
+ Person *m_celebrant;
+ QmlConcreteList<Person *> m_guests;
+};
+
+QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPE(BirthdayParty)
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/declarative/extending/valuesource/example.qml b/examples/declarative/extending/valuesource/example.qml
new file mode 100644
index 0000000..7cdf8c0
--- /dev/null
+++ b/examples/declarative/extending/valuesource/example.qml
@@ -0,0 +1,36 @@
+import People 1.0
+
+// ![0]
+BirthdayParty {
+ speaker: HappyBirthday { name: "Bob Jones" }
+// ![0]
+
+ onPartyStarted: console.log("This party started rockin' at " + time);
+
+
+ celebrant: Boy {
+ name: "Bob Jones"
+ shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
+ }
+
+ Boy {
+ name: "Joan Hodges"
+ BirthdayParty.rsvp: "2009-07-06"
+ shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
+ }
+ Boy {
+ name: "Jack Smith"
+ shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 }
+ }
+ Girl {
+ name: "Anne Brown"
+ BirthdayParty.rsvp: "2009-07-01"
+ shoe.size: 7
+ shoe.color: "red"
+ shoe.brand: "Marc Jacobs"
+ shoe.price: 699.99
+ }
+
+// ![1]
+}
+// ![1]
diff --git a/examples/declarative/extending/valuesource/happybirthday.cpp b/examples/declarative/extending/valuesource/happybirthday.cpp
new file mode 100644
index 0000000..b453944
--- /dev/null
+++ b/examples/declarative/extending/valuesource/happybirthday.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** 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 examples 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 "happybirthday.h"
+#include <QTimer>
+
+HappyBirthday::HappyBirthday(QObject *parent)
+: QObject(parent), m_line(-1)
+{
+ setName(QString());
+ QTimer *timer = new QTimer(this);
+ QObject::connect(timer, SIGNAL(timeout()), this, SLOT(advance()));
+ timer->start(1000);
+}
+
+void HappyBirthday::setTarget(const QmlMetaProperty &p)
+{
+ m_target = p;
+}
+
+QString HappyBirthday::name() const
+{
+ return m_name;
+}
+
+void HappyBirthday::setName(const QString &name)
+{
+ m_name = name;
+
+ m_lyrics.clear();
+ m_lyrics << "Happy birthday to you,";
+ m_lyrics << "Happy birthday to you,";
+ m_lyrics << "Happy birthday dear " + m_name + ",";
+ m_lyrics << "Happy birthday to you!";
+ m_lyrics << "";
+}
+
+void HappyBirthday::advance()
+{
+ m_line = (m_line + 1) % m_lyrics.count();
+
+ m_target.write(m_lyrics.at(m_line));
+}
+
+QML_DEFINE_TYPE(People, 1,0, HappyBirthday, HappyBirthday);
diff --git a/examples/declarative/extending/valuesource/happybirthday.h b/examples/declarative/extending/valuesource/happybirthday.h
new file mode 100644
index 0000000..4e8e87c
--- /dev/null
+++ b/examples/declarative/extending/valuesource/happybirthday.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** 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 examples 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 HAPPYBIRTHDAY_H
+#define HAPPYBIRTHDAY_H
+
+#include <QmlPropertyValueSource>
+#include <qml.h>
+
+#include <QStringList>
+
+// ![0]
+class HappyBirthday : public QObject, public QmlPropertyValueSource
+{
+Q_OBJECT
+// ![0]
+Q_PROPERTY(QString name READ name WRITE setName)
+// ![1]
+public:
+ HappyBirthday(QObject *parent = 0);
+
+ virtual void setTarget(const QmlMetaProperty &);
+// ![1]
+
+ QString name() const;
+ void setName(const QString &);
+
+private slots:
+ void advance();
+
+private:
+ int m_line;
+ QStringList m_lyrics;
+ QmlMetaProperty m_target;
+ QString m_name;
+// ![2]
+};
+// ![2]
+QML_DECLARE_TYPE(HappyBirthday);
+
+#endif // HAPPYBIRTHDAY_H
+
diff --git a/examples/declarative/extending/valuesource/main.cpp b/examples/declarative/extending/valuesource/main.cpp
new file mode 100644
index 0000000..c4090c4
--- /dev/null
+++ b/examples/declarative/extending/valuesource/main.cpp
@@ -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 examples 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 <QCoreApplication>
+#include <QmlEngine>
+#include <QmlComponent>
+#include <QDebug>
+#include "birthdayparty.h"
+#include "person.h"
+
+int main(int argc, char ** argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QmlEngine engine;
+ QmlComponent component(&engine, ":example.qml");
+ BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
+
+ if (party && party->celebrant()) {
+ qWarning() << party->celebrant()->name() << "is having a birthday!";
+
+ if (qobject_cast<Boy *>(party->celebrant()))
+ qWarning() << "He is inviting:";
+ else
+ qWarning() << "She is inviting:";
+
+ for (int ii = 0; ii < party->guests()->count(); ++ii) {
+ Person *guest = party->guests()->at(ii);
+
+ QDate rsvpDate;
+ QObject *attached =
+ qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
+ if (attached)
+ rsvpDate = attached->property("rsvp").toDate();
+
+ if (rsvpDate.isNull())
+ qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd";
+ else
+ qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString());
+ }
+
+ party->startParty();
+ } else {
+ qWarning() << "An error occured";
+ }
+
+ return app.exec();
+}
diff --git a/examples/declarative/extending/valuesource/person.cpp b/examples/declarative/extending/valuesource/person.cpp
new file mode 100644
index 0000000..8105ee7
--- /dev/null
+++ b/examples/declarative/extending/valuesource/person.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** 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 examples 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 "person.h"
+
+ShoeDescription::ShoeDescription(QObject *parent)
+: QObject(parent), m_size(0), m_price(0)
+{
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int s)
+{
+ m_size = s;
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &c)
+{
+ m_color = c;
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &b)
+{
+ m_brand = b;
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal p)
+{
+ m_price = p;
+}
+QML_DEFINE_NOCREATE_TYPE(ShoeDescription);
+
+Person::Person(QObject *parent)
+: QObject(parent)
+{
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &n)
+{
+ m_name = n;
+}
+
+ShoeDescription *Person::shoe()
+{
+ return &m_shoe;
+}
+
+QML_DEFINE_NOCREATE_TYPE(Person);
+
+Boy::Boy(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Boy, Boy);
+
+Girl::Girl(QObject * parent)
+: Person(parent)
+{
+}
+
+QML_DEFINE_TYPE(People, 1,0, Girl, Girl);
diff --git a/examples/declarative/extending/valuesource/person.h b/examples/declarative/extending/valuesource/person.h
new file mode 100644
index 0000000..c5b7727
--- /dev/null
+++ b/examples/declarative/extending/valuesource/person.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** 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 examples 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 PERSON_H
+#define PERSON_H
+
+#include <QObject>
+#include <QColor>
+#include <qml.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)
+public:
+ ShoeDescription(QObject *parent = 0);
+
+ int size() const;
+ void setSize(int);
+
+ QColor color() const;
+ void setColor(const QColor &);
+
+ QString brand() const;
+ void setBrand(const QString &);
+
+ qreal price() const;
+ void setPrice(qreal);
+private:
+ int m_size;
+ QColor m_color;
+ QString m_brand;
+ qreal m_price;
+};
+QML_DECLARE_TYPE(ShoeDescription);
+
+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);
+
+ QString name() const;
+ void setName(const QString &);
+
+ ShoeDescription *shoe();
+private:
+ QString m_name;
+ ShoeDescription m_shoe;
+};
+QML_DECLARE_TYPE(Person);
+
+class Boy : public Person {
+Q_OBJECT
+public:
+ Boy(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Boy);
+
+class Girl : public Person {
+Q_OBJECT
+public:
+ Girl(QObject * parent = 0);
+};
+QML_DECLARE_TYPE(Girl);
+
+#endif // PERSON_H
diff --git a/examples/declarative/extending/valuesource/valuesource.pro b/examples/declarative/extending/valuesource/valuesource.pro
new file mode 100644
index 0000000..9e54448
--- /dev/null
+++ b/examples/declarative/extending/valuesource/valuesource.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+TARGET = valuesource
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += declarative
+
+# Input
+SOURCES += main.cpp \
+ person.cpp \
+ birthdayparty.cpp \
+ happybirthday.cpp
+HEADERS += person.h \
+ birthdayparty.h \
+ happybirthday.h
+RESOURCES += valuesource.qrc
diff --git a/examples/declarative/extending/valuesource/valuesource.qrc b/examples/declarative/extending/valuesource/valuesource.qrc
new file mode 100644
index 0000000..e2fa01d
--- /dev/null
+++ b/examples/declarative/extending/valuesource/valuesource.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>example.qml</file>
+</qresource>
+</RCC>