summaryrefslogtreecommitdiffstats
path: root/examples/declarative/extending/attached
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-02-04 04:56:50 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-02-04 04:56:50 (GMT)
commit7fec7ff568659c3816ce26d2d82d59dd372f1166 (patch)
treec2546e401f13ba5c55e3311744d83fa68e46f165 /examples/declarative/extending/attached
parent5783f98ce5e243afbbd4c6a68c80d2dd959520e0 (diff)
parentf7dfce110c96ef33200abf2dd93b86d3853095e5 (diff)
downloadQt-7fec7ff568659c3816ce26d2d82d59dd372f1166.zip
Qt-7fec7ff568659c3816ce26d2d82d59dd372f1166.tar.gz
Qt-7fec7ff568659c3816ce26d2d82d59dd372f1166.tar.bz2
Merge branch 'kinetic-declarativeui' of git://git-nokia.trolltech.com.au/qtsoftware/qt/kinetic
Conflicts: src/xmlpatterns/type/qprimitives_p.h tools/linguist/lupdate/main.cpp
Diffstat (limited to 'examples/declarative/extending/attached')
-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
8 files changed, 533 insertions, 0 deletions
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