summaryrefslogtreecommitdiff
path: root/examples/declarative/tutorials/extending
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/tutorials/extending')
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/app.qml18
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro4
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/main.cpp4
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp81
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/piechart.h (renamed from examples/declarative/tutorials/extending/chapter1-basics/musician.h)21
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/app.qml24
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro4
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/main.cpp4
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp87
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/piechart.h (renamed from examples/declarative/tutorials/extending/chapter3-bindings/musician.h)26
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/app.qml42
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro4
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/main.cpp4
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp89
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/piechart.h84
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml18
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro8
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp56
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp8
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter2-methods/musician.cpp)30
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h (renamed from examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h)20
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp68
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h (renamed from examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h)21
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/app.qml70
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro7
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp (renamed from examples/declarative/tutorials/extending/chapter1-basics/musician.cpp)34
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp)32
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h (renamed from examples/declarative/tutorials/extending/chapter2-methods/musician.h)34
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp88
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h76
-rw-r--r--examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp56
-rw-r--r--examples/declarative/tutorials/extending/chapter5-plugins/instrument.h61
-rw-r--r--examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp67
-rw-r--r--examples/declarative/tutorials/extending/chapter5-plugins/qmldir1
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/app.qml (renamed from examples/declarative/tutorials/extending/chapter5-plugins/app.qml)29
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro (renamed from examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro)12
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp)14
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h)6
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp)24
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/piechart.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musician.h)21
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp88
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h74
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/qmldir1
-rw-r--r--examples/declarative/tutorials/extending/extending.pro3
44 files changed, 1060 insertions, 463 deletions
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/app.qml b/examples/declarative/tutorials/extending/chapter1-basics/app.qml
index 9af155cdc1..ada088d6d9 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/app.qml
+++ b/examples/declarative/tutorials/extending/chapter1-basics/app.qml
@@ -38,21 +38,23 @@
**
****************************************************************************/
//![0]
-import Music 1.0
+import Charts 1.0
import Qt 4.7
-Rectangle {
+Item {
width: 300; height: 200
- Musician {
- id: aMusician
- name: "Reddy the Rocker"
- instrument: "Guitar"
+ PieChart {
+ id: aPieChart
+ anchors.centerIn: parent
+ width: 100; height: 100
+ name: "A simple pie chart"
+ color: "red"
}
Text {
- anchors.fill: parent
- text: aMusician.name + " plays the " + aMusician.instrument
+ anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
+ text: aPieChart.name
}
}
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro b/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro
index bd05ebe2cc..0f0416718c 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro
+++ b/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro
@@ -1,5 +1,5 @@
QT += declarative
-HEADERS += musician.h
-SOURCES += musician.cpp \
+HEADERS += piechart.h
+SOURCES += piechart.cpp \
main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/main.cpp b/examples/declarative/tutorials/extending/chapter1-basics/main.cpp
index 8ef6965ea8..a5dbab32d2 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/main.cpp
+++ b/examples/declarative/tutorials/extending/chapter1-basics/main.cpp
@@ -38,7 +38,7 @@
**
****************************************************************************/
//![0]
-#include "musician.h"
+#include "piechart.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- qmlRegisterType<Musician>("Music", 1, 0, "Musician");
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("app.qml"));
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp b/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp
new file mode 100644
index 0000000000..3b9ef7160a
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "piechart.h"
+#include <QPainter>
+
+//![0]
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+//![0]
+
+QString PieChart::name() const
+{
+ return m_name;
+}
+
+void PieChart::setName(const QString &name)
+{
+ m_name = name;
+}
+
+QColor PieChart::color() const
+{
+ return m_color;
+}
+
+void PieChart::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+//![1]
+void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), 90 * 16, 290 * 16);
+}
+//![1]
+
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/musician.h b/examples/declarative/tutorials/extending/chapter1-basics/piechart.h
index f9a0537502..aae7b26dd3 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/musician.h
+++ b/examples/declarative/tutorials/extending/chapter1-basics/piechart.h
@@ -37,30 +37,33 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
//![0]
-#include <QObject>
+#include <QDeclarativeItem>
+#include <QColor>
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(QString instrument READ instrument WRITE setInstrument)
+ Q_PROPERTY(QColor color READ color WRITE setColor)
public:
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
- QString instrument() const;
- void setInstrument(const QString &instrument);
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
QString m_name;
- QString m_instrument;
+ QColor m_color;
};
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/app.qml b/examples/declarative/tutorials/extending/chapter2-methods/app.qml
index 02d33c2f1b..0b55f7c02a 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/app.qml
+++ b/examples/declarative/tutorials/extending/chapter2-methods/app.qml
@@ -38,23 +38,29 @@
**
****************************************************************************/
//![0]
-import Music 1.0
+import Charts 1.0
import Qt 4.7
-Rectangle {
- width: 200; height: 200
+Item {
+ width: 300; height: 200
- Musician {
- id: aMusician
- name: "Reddy the Rocker"
- instrument: "Guitar"
+ PieChart {
+ id: aPieChart
+ anchors.centerIn: parent
+ width: 100; height: 100
+ color: "red"
- onPerformanceEnded: console.log("The performance has now ended")
+ onChartCleared: console.log("The chart has been cleared")
}
MouseArea {
anchors.fill: parent
- onClicked: aMusician.perform()
+ onClicked: aPieChart.clearChart()
+ }
+
+ Text {
+ anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
+ text: "Click anywhere to clear the chart"
}
}
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro b/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro
index bd05ebe2cc..0f0416718c 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro
+++ b/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro
@@ -1,5 +1,5 @@
QT += declarative
-HEADERS += musician.h
-SOURCES += musician.cpp \
+HEADERS += piechart.h
+SOURCES += piechart.cpp \
main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/main.cpp b/examples/declarative/tutorials/extending/chapter2-methods/main.cpp
index 8ef6965ea8..a5dbab32d2 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/main.cpp
+++ b/examples/declarative/tutorials/extending/chapter2-methods/main.cpp
@@ -38,7 +38,7 @@
**
****************************************************************************/
//![0]
-#include "musician.h"
+#include "piechart.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- qmlRegisterType<Musician>("Music", 1, 0, "Musician");
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("app.qml"));
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp b/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp
new file mode 100644
index 0000000000..11ff7c8bff
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "piechart.h"
+#include <QPainter>
+#include <QDebug>
+
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QString PieChart::name() const
+{
+ return m_name;
+}
+
+void PieChart::setName(const QString &name)
+{
+ m_name = name;
+}
+
+QColor PieChart::color() const
+{
+ return m_color;
+}
+
+void PieChart::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), 90 * 16, 290 * 16);
+}
+
+//![0]
+void PieChart::clearChart()
+{
+ setColor(QColor(Qt::transparent));
+ update();
+
+ emit chartCleared();
+}
+//![0]
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/musician.h b/examples/declarative/tutorials/extending/chapter2-methods/piechart.h
index 0b0addb997..246fd9f929 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/musician.h
+++ b/examples/declarative/tutorials/extending/chapter2-methods/piechart.h
@@ -37,42 +37,44 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
-#include <QObject>
+#include <QDeclarativeItem>
+#include <QColor>
//![0]
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
//![0]
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(QString instrument READ instrument WRITE setInstrument)
+ Q_PROPERTY(QColor color READ color WRITE setColor)
//![1]
- Q_PROPERTY(QString instrument READ instrument WRITE setInstrument NOTIFY instrumentChanged)
public:
//![1]
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
- QString instrument() const;
- void setInstrument(const QString &instrument);
+ QColor color() const;
+ void setColor(const QColor &color);
- Q_INVOKABLE void perform();
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
//![2]
+ Q_INVOKABLE void clearChart();
+
signals:
- void instrumentChanged();
+ void chartCleared();
//![2]
private:
QString m_name;
- QString m_instrument;
+ QColor m_color;
//![3]
};
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/app.qml b/examples/declarative/tutorials/extending/chapter3-bindings/app.qml
index 8bf6ecfaf6..2ff6ae1965 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/app.qml
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/app.qml
@@ -38,35 +38,37 @@
**
****************************************************************************/
//![0]
-import Music 1.0
+import Charts 1.0
import Qt 4.7
-Rectangle {
- width: 200; height: 200
+Item {
+ width: 300; height: 200
- Musician {
- id: reddy
- name: "Reddy the Rocker"
- instrument: "Guitar"
- }
+ Row {
+ anchors.centerIn: parent
+ spacing: 20
+
+ PieChart {
+ id: chartA
+ width: 100; height: 100
+ color: "red"
+ }
- Musician {
- id: craig
- name: "Craig the Copycat"
- instrument: reddy.instrument
+ PieChart {
+ id: chartB
+ width: 100; height: 100
+ color: chartA.color
+ }
}
MouseArea {
anchors.fill: parent
- onClicked: {
- reddy.perform()
- craig.perform()
-
- reddy.instrument = "Drums"
+ onClicked: { chartA.color = "blue" }
+ }
- reddy.perform()
- craig.perform()
- }
+ Text {
+ anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
+ text: "Click anywhere to change the chart color"
}
}
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro b/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro
index bd05ebe2cc..0f0416718c 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro
@@ -1,5 +1,5 @@
QT += declarative
-HEADERS += musician.h
-SOURCES += musician.cpp \
+HEADERS += piechart.h
+SOURCES += piechart.cpp \
main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp b/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp
index 8ef6965ea8..a5dbab32d2 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp
@@ -38,7 +38,7 @@
**
****************************************************************************/
//![0]
-#include "musician.h"
+#include "piechart.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- qmlRegisterType<Musician>("Music", 1, 0, "Musician");
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("app.qml"));
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp
new file mode 100644
index 0000000000..85a9762994
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "piechart.h"
+#include <QPainter>
+#include <QDebug>
+
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QString PieChart::name() const
+{
+ return m_name;
+}
+
+void PieChart::setName(const QString &name)
+{
+ m_name = name;
+}
+
+QColor PieChart::color() const
+{
+ return m_color;
+}
+
+//![0]
+void PieChart::setColor(const QColor &color)
+{
+ if (color != m_color) {
+ m_color = color;
+ update(); // repaint with the new color
+ emit colorChanged();
+ }
+}
+//![0]
+
+void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), 90 * 16, 290 * 16);
+}
+
+void PieChart::clearChart()
+{
+ setColor(QColor(Qt::transparent));
+ update();
+}
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h
new file mode 100644
index 0000000000..164cebb65e
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PIECHART_H
+#define PIECHART_H
+
+#include <QDeclarativeItem>
+#include <QColor>
+
+//![0]
+class PieChart : public QDeclarativeItem
+{
+//![0]
+ Q_OBJECT
+ Q_PROPERTY(QString name READ name WRITE setName)
+
+//![1]
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+public:
+//![1]
+
+ PieChart(QDeclarativeItem *parent = 0);
+
+ QString name() const;
+ void setName(const QString &name);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+ Q_INVOKABLE void clearChart();
+
+//![2]
+signals:
+ void colorChanged();
+//![2]
+
+private:
+ QString m_name;
+ QColor m_color;
+
+//![3]
+};
+//![3]
+
+#endif
+
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml
index d76f80120f..fcd38068c5 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml
@@ -38,17 +38,23 @@
**
****************************************************************************/
//![0]
-import Music 1.0
+import Charts 1.0
import Qt 4.7
Item {
+ width: 300; height: 200
- Musician {
- id: reddy
- name: "Reddy the Rocker"
- instrument: Instrument { type: "Guitar" }
+ PieChart {
+ id: chart
+ anchors.centerIn: parent
+ width: 100; height: 100
+
+ pieSlice: PieSlice {
+ anchors.fill: parent
+ color: "red"
+ }
}
- Component.onCompleted: console.log("Reddy plays the " + reddy.instrument.type)
+ Component.onCompleted: console.log("The pie is colored " + chart.pieSlice.color)
}
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro
index aea07a0ef5..c3f5402aea 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro
@@ -1,7 +1,7 @@
QT += declarative
-HEADERS += musician.h \
- instrument.h
-SOURCES += musician.cpp \
- instrument.cpp \
+HEADERS += piechart.h \
+ pieslice.h
+SOURCES += piechart.cpp \
+ pieslice.cpp \
main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp
deleted file mode 100644
index 9ca96f6386..0000000000
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "instrument.h"
-
-Instrument::Instrument(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString Instrument::type() const
-{
- return m_type;
-}
-
-void Instrument::setType(const QString &type)
-{
- m_type = type;
-}
-
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp
index d94cb036cb..fd518a255a 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp
@@ -37,8 +37,8 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
-#include "instrument.h"
+#include "piechart.h"
+#include "pieslice.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
@@ -50,10 +50,10 @@ int main(int argc, char *argv[])
//![0]
QApplication app(argc, argv);
- qmlRegisterType<Musician>("Music", 1, 0, "Musician");
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
//![1]
- qmlRegisterType<Instrument>("Music", 1, 0, "Instrument");
+ qmlRegisterType<PieSlice>("Charts", 1, 0, "PieSlice");
//![1]
QDeclarativeView view;
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/musician.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp
index 0ce0022251..70988542d3 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/musician.cpp
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp
@@ -37,38 +37,36 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
-#include <QDebug>
+#include "piechart.h"
+#include "pieslice.h"
-Musician::Musician(QObject *parent)
- : QObject(parent)
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
{
+ // this doesn't need to disable QGraphicsItem::ItemHasNoContents
+ // anymore since the drawing is now done in PieSlice
}
-QString Musician::name() const
+QString PieChart::name() const
{
return m_name;
}
-void Musician::setName(const QString &name)
+void PieChart::setName(const QString &name)
{
m_name = name;
}
-QString Musician::instrument() const
+PieSlice *PieChart::pieSlice() const
{
- return m_instrument;
-}
-
-void Musician::setInstrument(const QString &instrument)
-{
- m_instrument = instrument;
+ return m_pieSlice;
}
//![0]
-void Musician::perform()
+void PieChart::setPieSlice(PieSlice *pieSlice)
{
- qWarning() << m_name << "is playing the" << m_instrument;
- emit performanceEnded();
+ m_pieSlice = pieSlice;
+ pieSlice->setParentItem(this);
}
//![0]
+
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h
index 8f67f61cc0..448ca7b67b 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h
@@ -37,18 +37,18 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
-#include <QObject>
+#include <QDeclarativeItem>
-class Instrument;
+class PieSlice;
//![0]
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
Q_OBJECT
- Q_PROPERTY(Instrument* instrument READ instrument WRITE setInstrument)
+ Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice)
//![0]
Q_PROPERTY(QString name READ name WRITE setName)
@@ -56,19 +56,19 @@ class Musician : public QObject
public:
//![1]
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
//![2]
- Instrument *instrument() const;
- void setInstrument(Instrument *instrument);
+ PieSlice *pieSlice() const;
+ void setPieSlice(PieSlice *pieSlice);
//![2]
private:
QString m_name;
- Instrument *m_instrument;
+ PieSlice *m_pieSlice;
//![3]
};
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp
new file mode 100644
index 0000000000..7a420fd285
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "pieslice.h"
+
+#include <QPainter>
+
+PieSlice::PieSlice(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QColor PieSlice::color() const
+{
+ return m_color;
+}
+
+void PieSlice::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), 90 * 16, 290 * 16);
+}
+
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h
index 9971207f0f..085a9b8fe6 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h
@@ -37,25 +37,28 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef INSTRUMENT_H
-#define INSTRUMENT_H
+#ifndef PIESLICE_H
+#define PIESLICE_H
-#include <QObject>
+#include <QDeclarativeItem>
+#include <QColor>
//![0]
-class Instrument : public QObject
+class PieSlice : public QDeclarativeItem
{
Q_OBJECT
- Q_PROPERTY(QString type READ type WRITE setType)
+ Q_PROPERTY(QColor color READ color WRITE setColor)
public:
- Instrument(QObject *parent = 0);
+ PieSlice(QDeclarativeItem *parent = 0);
- QString type() const;
- void setType(const QString &type);
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
- QString m_type;
+ QColor m_color;
};
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml b/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml
new file mode 100644
index 0000000000..f759bc90e5
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+//![0]
+import Charts 1.0
+import Qt 4.7
+
+Item {
+ width: 300; height: 200
+
+ PieChart {
+ anchors.centerIn: parent
+ width: 100; height: 100
+
+ slices: [
+ PieSlice {
+ anchors.fill: parent
+ color: "red"
+ fromAngle: 0; angleSpan: 110
+ },
+ PieSlice {
+ anchors.fill: parent
+ color: "black"
+ fromAngle: 110; angleSpan: 50
+ },
+ PieSlice {
+ anchors.fill: parent
+ color: "blue"
+ fromAngle: 160; angleSpan: 100
+ }
+ ]
+ }
+}
+//![0]
diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro b/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro
new file mode 100644
index 0000000000..c3f5402aea
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro
@@ -0,0 +1,7 @@
+QT += declarative
+
+HEADERS += piechart.h \
+ pieslice.h
+SOURCES += piechart.cpp \
+ pieslice.cpp \
+ main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/musician.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp
index 6c42f310b9..f73c49fd24 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/musician.cpp
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp
@@ -37,30 +37,22 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
+#include "piechart.h"
+#include "pieslice.h"
-Musician::Musician(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString Musician::name() const
-{
- return m_name;
-}
+#include <qdeclarative.h>
+#include <QDeclarativeView>
+#include <QApplication>
-void Musician::setName(const QString &name)
+int main(int argc, char *argv[])
{
- m_name = name;
-}
+ QApplication app(argc, argv);
-QString Musician::instrument() const
-{
- return m_instrument;
-}
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
+ qmlRegisterType<PieSlice>("Charts", 1, 0, "PieSlice");
-void Musician::setInstrument(const QString &instrument)
-{
- m_instrument = instrument;
+ QDeclarativeView view;
+ view.setSource(QUrl::fromLocalFile("app.qml"));
+ view.show();
+ return app.exec();
}
-
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp
index 5f9ead4bfe..2515b64280 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp
@@ -37,40 +37,36 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
-#include <QDebug>
+#include "piechart.h"
+#include "pieslice.h"
-Musician::Musician(QObject *parent)
- : QObject(parent)
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
{
}
-QString Musician::name() const
+QString PieChart::name() const
{
return m_name;
}
-void Musician::setName(const QString &name)
+void PieChart::setName(const QString &name)
{
m_name = name;
}
-QString Musician::instrument() const
+//![0]
+QDeclarativeListProperty<PieSlice> PieChart::slices()
{
- return m_instrument;
+ return QDeclarativeListProperty<PieSlice>(this, 0, &PieChart::append_slice);
}
-//![0]
-void Musician::setInstrument(const QString &instrument)
+void PieChart::append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice)
{
- if (instrument != m_instrument) {
- m_instrument = instrument;
- emit instrumentChanged();
+ PieChart *chart = qobject_cast<PieChart *>(list->object);
+ if (chart) {
+ slice->setParentItem(chart);
+ chart->m_slices.append(slice);
}
}
//![0]
-
-void Musician::perform()
-{
- qWarning() << m_name << "is playing the" << m_instrument;
-}
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/musician.h b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h
index 86849ba237..44242513c0 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/musician.h
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h
@@ -37,45 +37,39 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
-#include <QObject>
+#include <QDeclarativeItem>
+
+class PieSlice;
//![0]
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
-//![0]
Q_OBJECT
+ Q_PROPERTY(QDeclarativeListProperty<PieSlice> slices READ slices)
+//![0]
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(QString instrument READ instrument WRITE setInstrument)
//![1]
public:
//![1]
-
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
- QString instrument() const;
- void setInstrument(const QString &instrument);
-
-//![2]
- Q_INVOKABLE void perform();
-
-signals:
- void performanceEnded();
//![2]
+ QDeclarativeListProperty<PieSlice> slices();
private:
- QString m_name;
- QString m_instrument;
+ static void append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice);
-//![3]
+ QString m_name;
+ QList<PieSlice *> m_slices;
};
-//![3]
+//![2]
#endif
diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp
new file mode 100644
index 0000000000..65120f53e3
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "pieslice.h"
+
+#include <QPainter>
+
+PieSlice::PieSlice(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QColor PieSlice::color() const
+{
+ return m_color;
+}
+
+void PieSlice::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+int PieSlice::fromAngle() const
+{
+ return m_fromAngle;
+}
+
+void PieSlice::setFromAngle(int angle)
+{
+ m_fromAngle = angle;
+}
+
+int PieSlice::angleSpan() const
+{
+ return m_angleSpan;
+}
+
+void PieSlice::setAngleSpan(int angle)
+{
+ m_angleSpan = angle;
+}
+
+void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), m_fromAngle * 16, m_angleSpan * 16);
+}
+
diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h
new file mode 100644
index 0000000000..7cd0c7474d
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PIESLICE_H
+#define PIESLICE_H
+
+#include <QDeclarativeItem>
+#include <QColor>
+
+//![0]
+class PieSlice : public QDeclarativeItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor)
+ Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle)
+ Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan)
+//![0]
+
+public:
+ PieSlice(QDeclarativeItem *parent = 0);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ int fromAngle() const;
+ void setFromAngle(int angle);
+
+ int angleSpan() const;
+ void setAngleSpan(int span);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+private:
+ QColor m_color;
+ int m_fromAngle;
+ int m_angleSpan;
+};
+
+#endif
+
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp
deleted file mode 100644
index 9ca96f6386..0000000000
--- a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "instrument.h"
-
-Instrument::Instrument(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString Instrument::type() const
-{
- return m_type;
-}
-
-void Instrument::setType(const QString &type)
-{
- m_type = type;
-}
-
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h b/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h
deleted file mode 100644
index ce1e7ce808..0000000000
--- a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef INSTRUMENT_H
-#define INSTRUMENT_H
-
-#include <QObject>
-
-class Instrument : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString type READ type WRITE setType)
-
-public:
- Instrument(QObject *parent = 0);
-
- QString type() const;
- void setType(const QString &type);
-
-private:
- QString m_type;
-};
-
-#endif
-
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp
deleted file mode 100644
index e62efb197d..0000000000
--- a/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "musician.h"
-#include "instrument.h"
-
-Musician::Musician(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString Musician::name() const
-{
- return m_name;
-}
-
-void Musician::setName(const QString &name)
-{
- m_name = name;
-}
-
-Instrument *Musician::instrument() const
-{
- return m_instrument;
-}
-
-void Musician::setInstrument(Instrument *instrument)
-{
- m_instrument = instrument;
-}
-
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/qmldir b/examples/declarative/tutorials/extending/chapter5-plugins/qmldir
deleted file mode 100644
index c3afd6b054..0000000000
--- a/examples/declarative/tutorials/extending/chapter5-plugins/qmldir
+++ /dev/null
@@ -1 +0,0 @@
-plugin chapter5-plugins lib
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml b/examples/declarative/tutorials/extending/chapter6-plugins/app.qml
index 9c050b873c..38ceefa356 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/app.qml
@@ -37,17 +37,32 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
import Qt 4.7
Item {
+ width: 300; height: 200
- Musician {
- id: reddy
- name: "Reddy the Rocker"
- instrument: Instrument { type: "Guitar" }
- }
+ PieChart {
+ anchors.centerIn: parent
+ width: 100; height: 100
- Component.onCompleted: console.log("Reddy plays the " + reddy.instrument.type)
+ slices: [
+ PieSlice {
+ anchors.fill: parent
+ color: "red"
+ fromAngle: 0; angleSpan: 110
+ },
+ PieSlice {
+ anchors.fill: parent
+ color: "black"
+ fromAngle: 110; angleSpan: 50
+ },
+ PieSlice {
+ anchors.fill: parent
+ color: "blue"
+ fromAngle: 160; angleSpan: 100
+ }
+ ]
+ }
}
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro
index 483da8fc9a..1ffbf29925 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro
@@ -6,13 +6,13 @@ DESTDIR = lib
OBJECTS_DIR = tmp
MOC_DIR = tmp
-HEADERS += musician.h \
- instrument.h \
- musicplugin.h
+HEADERS += piechart.h \
+ pieslice.h \
+ chartsplugin.h
-SOURCES += musician.cpp \
- instrument.cpp \
- musicplugin.cpp
+SOURCES += piechart.cpp \
+ pieslice.cpp \
+ chartsplugin.cpp
symbian {
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp
index 76acf0144d..5aa2a4bcbe 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp
@@ -37,18 +37,18 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musicplugin.h"
+#include "chartsplugin.h"
//![0]
-#include "musician.h"
-#include "instrument.h"
+#include "piechart.h"
+#include "pieslice.h"
#include <QtDeclarative/qdeclarative.h>
-void MusicPlugin::registerTypes(const char *uri)
+void ChartsPlugin::registerTypes(const char *uri)
{
- qmlRegisterType<Musician>(uri, 1, 0, "Musician");
- qmlRegisterType<Instrument>(uri, 1, 0, "Instrument");
+ qmlRegisterType<PieChart>(uri, 1, 0, "PieChart");
+ qmlRegisterType<PieSlice>(uri, 1, 0, "PieSlice");
}
-Q_EXPORT_PLUGIN2(musicplugin, MusicPlugin);
+Q_EXPORT_PLUGIN2(chartsplugin, ChartsPlugin);
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h
index d6a5392431..797d1e7a85 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h
@@ -37,13 +37,13 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICPLUGIN_H
-#define MUSICPLUGIN_H
+#ifndef CHARTSPLUGIN_H
+#define CHARTSPLUGIN_H
//![0]
#include <QtDeclarative/QDeclarativeExtensionPlugin>
-class MusicPlugin : public QDeclarativeExtensionPlugin
+class ChartsPlugin : public QDeclarativeExtensionPlugin
{
Q_OBJECT
public:
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp
index e62efb197d..4e6ee5c698 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp
@@ -37,31 +37,35 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
-#include "instrument.h"
+#include "piechart.h"
+#include "pieslice.h"
-Musician::Musician(QObject *parent)
- : QObject(parent)
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
{
}
-QString Musician::name() const
+QString PieChart::name() const
{
return m_name;
}
-void Musician::setName(const QString &name)
+void PieChart::setName(const QString &name)
{
m_name = name;
}
-Instrument *Musician::instrument() const
+QDeclarativeListProperty<PieSlice> PieChart::slices()
{
- return m_instrument;
+ return QDeclarativeListProperty<PieSlice>(this, 0, &PieChart::append_slice);
}
-void Musician::setInstrument(Instrument *instrument)
+void PieChart::append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice)
{
- m_instrument = instrument;
+ PieChart *chart = qobject_cast<PieChart *>(list->object);
+ if (chart) {
+ slice->setParentItem(chart);
+ chart->m_slices.append(slice);
+ }
}
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musician.h b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h
index b92063131c..d6e443993a 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/musician.h
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h
@@ -37,31 +37,32 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
-#include <QObject>
+#include <QDeclarativeItem>
-class Instrument;
+class PieSlice;
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
Q_OBJECT
+ Q_PROPERTY(QDeclarativeListProperty<PieSlice> slices READ slices)
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(Instrument* instrument READ instrument WRITE setInstrument)
public:
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
- Instrument *instrument() const;
- void setInstrument(Instrument *instrument);
+ QDeclarativeListProperty<PieSlice> slices();
private:
+ static void append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice);
+
QString m_name;
- Instrument *m_instrument;
+ QList<PieSlice *> m_slices;
};
#endif
diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp
new file mode 100644
index 0000000000..65120f53e3
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "pieslice.h"
+
+#include <QPainter>
+
+PieSlice::PieSlice(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QColor PieSlice::color() const
+{
+ return m_color;
+}
+
+void PieSlice::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+int PieSlice::fromAngle() const
+{
+ return m_fromAngle;
+}
+
+void PieSlice::setFromAngle(int angle)
+{
+ m_fromAngle = angle;
+}
+
+int PieSlice::angleSpan() const
+{
+ return m_angleSpan;
+}
+
+void PieSlice::setAngleSpan(int angle)
+{
+ m_angleSpan = angle;
+}
+
+void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), m_fromAngle * 16, m_angleSpan * 16);
+}
+
diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h
new file mode 100644
index 0000000000..a3afd25d60
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PIESLICE_H
+#define PIESLICE_H
+
+#include <QDeclarativeItem>
+#include <QColor>
+
+class PieSlice : public QDeclarativeItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor)
+ Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle)
+ Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan)
+
+public:
+ PieSlice(QDeclarativeItem *parent = 0);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ int fromAngle() const;
+ void setFromAngle(int angle);
+
+ int angleSpan() const;
+ void setAngleSpan(int span);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+private:
+ QColor m_color;
+ int m_fromAngle;
+ int m_angleSpan;
+};
+
+#endif
+
diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/qmldir b/examples/declarative/tutorials/extending/chapter6-plugins/qmldir
new file mode 100644
index 0000000000..a83bf85ddb
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/qmldir
@@ -0,0 +1 @@
+plugin chapter6-plugins lib
diff --git a/examples/declarative/tutorials/extending/extending.pro b/examples/declarative/tutorials/extending/extending.pro
index 0c86fed2d1..967473fda0 100644
--- a/examples/declarative/tutorials/extending/extending.pro
+++ b/examples/declarative/tutorials/extending/extending.pro
@@ -5,5 +5,6 @@ SUBDIRS += \
chapter2-methods \
chapter3-bindings \
chapter4-customPropertyTypes \
- chapter5-plugins
+ chapter5-listproperties \
+ chapter6-plugins