diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-07-15 05:29:20 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-07-15 05:41:07 (GMT) |
commit | 7d0b62158471d46db9902ce0d0d7b7244c743cce (patch) | |
tree | 8fc9d4d9ba0df2842d0974a1929c9e63754a89b7 /examples | |
parent | fb8869e00da635be7660d845d4cb631d230bed6e (diff) | |
download | Qt-7d0b62158471d46db9902ce0d0d7b7244c743cce.zip Qt-7d0b62158471d46db9902ce0d0d7b7244c743cce.tar.gz Qt-7d0b62158471d46db9902ce0d0d7b7244c743cce.tar.bz2 |
Add chapter on creating list property types
Diffstat (limited to 'examples')
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/qmldir | 1 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/app.qml (renamed from examples/declarative/tutorials/extending/chapter5-plugins/app.qml) | 25 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro (renamed from examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro) | 0 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp (renamed from examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp) | 0 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h) | 0 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp) | 13 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/piechart.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/piechart.h) | 9 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp (renamed from examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp) | 23 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h) | 12 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter6-plugins/qmldir | 1 |
10 files changed, 64 insertions, 20 deletions
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/qmldir b/examples/declarative/tutorials/extending/chapter5-plugins/qmldir deleted file mode 100644 index c3afd6b..0000000 --- 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 b06e399..38ceefa 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml +++ b/examples/declarative/tutorials/extending/chapter6-plugins/app.qml @@ -37,23 +37,32 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - import Qt 4.7 Item { width: 300; height: 200 PieChart { - id: chart anchors.centerIn: parent width: 100; height: 100 - pieSlice: PieSlice { - anchors.fill: parent - color: "red" - } + 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 + } + ] } - - Component.onCompleted: console.log("The pie is colored " + chart.pieSlice.color) } diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro index 1ffbf29..1ffbf29 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro +++ b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp index 5aa2a4b..5aa2a4b 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp +++ b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h index 797d1e7..797d1e7 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h +++ b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp index 2d7acf7..4e6ee5c 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp +++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp @@ -55,14 +55,17 @@ void PieChart::setName(const QString &name) m_name = name; } -PieSlice *PieChart::pieSlice() const +QDeclarativeListProperty<PieSlice> PieChart::slices() { - return m_pieSlice; + return QDeclarativeListProperty<PieSlice>(this, 0, &PieChart::append_slice); } -void PieChart::setPieSlice(PieSlice *pieSlice) +void PieChart::append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice) { - m_pieSlice = pieSlice; - m_pieSlice->setParentItem(this); + 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/piechart.h b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h index a8b5b6e..d6e4439 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h +++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h @@ -47,8 +47,8 @@ class PieSlice; class PieChart : public QDeclarativeItem { Q_OBJECT + Q_PROPERTY(QDeclarativeListProperty<PieSlice> slices READ slices) Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) public: PieChart(QDeclarativeItem *parent = 0); @@ -56,12 +56,13 @@ public: QString name() const; void setName(const QString &name); - PieSlice *pieSlice() const; - void setPieSlice(PieSlice *pieSlice); + QDeclarativeListProperty<PieSlice> slices(); private: + static void append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice); + QString m_name; - PieSlice *m_pieSlice; + QList<PieSlice *> m_slices; }; #endif diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp index a312da3..65120f5 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp +++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp @@ -58,10 +58,31 @@ 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(), 90 * 16, 290 * 16); + painter->drawPie(boundingRect(), m_fromAngle * 16, m_angleSpan * 16); } + diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h index 6774731..a3afd25 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h +++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h @@ -47,17 +47,27 @@ 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 &QColor); + 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 0000000..a83bf85 --- /dev/null +++ b/examples/declarative/tutorials/extending/chapter6-plugins/qmldir @@ -0,0 +1 @@ +plugin chapter6-plugins lib |