##// END OF EJS Templates
Added declarative model for bar series
Tero Ahola -
r1162:e5feb9c12a84
parent child
Show More
@@ -23,6 +23,7 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 anchors.fill: parent
25 anchors.fill: parent
26 property int __explodedIndex: -1
26
27
27 ChartView {
28 ChartView {
28 id: chart
29 id: chart
@@ -36,9 +37,12 Rectangle {
36 animationOptions: ChartView.SeriesAnimations
37 animationOptions: ChartView.SeriesAnimations
37
38
38 PieSeries {
39 PieSeries {
40 id: pieSeries
39 model: PieModel {
41 model: PieModel {
40 id: pieModel
42 id: pieModel
41 PieSlice { label: "Volkswagen"; value: 13.5 }
43 // TODO: initializing properties does not work at the moment, see DeclarativePieModel::append
44 // TODO: explode range, color, border color, border thickness, font, ..
45 PieSlice { exploded: true; label: "Volkswagen"; value: 13.5 }
42 PieSlice { label: "Toyota"; value: 10.9 }
46 PieSlice { label: "Toyota"; value: 10.9 }
43 PieSlice { label: "Ford"; value: 8.6 }
47 PieSlice { label: "Ford"; value: 8.6 }
44 PieSlice { label: "Skoda"; value: 8.2 }
48 PieSlice { label: "Skoda"; value: 8.2 }
@@ -47,6 +51,23 Rectangle {
47 }
51 }
48 }
52 }
49
53
54 Timer {
55 repeat: true
56 interval: 2000
57 running: true
58 onTriggered: {
59 changeSliceExploded(__explodedIndex);
60 __explodedIndex = (__explodedIndex + 1) % pieModel.count;
61 changeSliceExploded(__explodedIndex);
62 }
63 }
64
65 function changeSliceExploded(index) {
66 if (index >= 0 && index < pieModel.count) {
67 pieSeries.slice(index).exploded = !pieSeries.slice(index).exploded;
68 }
69 }
70
50 Rectangle {
71 Rectangle {
51 id: button
72 id: button
52 anchors.bottom: parent.bottom
73 anchors.bottom: parent.bottom
@@ -74,6 +95,7 Rectangle {
74 // TODO: this should also be doable by redefining the range inside the model
95 // TODO: this should also be doable by redefining the range inside the model
75 button.state = "";
96 button.state = "";
76 pieModel.removeRow(pieModel.count - 1);
97 pieModel.removeRow(pieModel.count - 1);
98 // TODO: removeAll("label") ?
77 }
99 }
78 }
100 }
79 }
101 }
@@ -89,9 +111,14 Rectangle {
89 // // column3 not used by pie series
111 // // column3 not used by pie series
90 // PieSeries {
112 // PieSeries {
91 // model: chartModel
113 // model: chartModel
92 // mappings: [ {"column1":"label"}, {"column2":"value"} ]
114 // modelMapping: PieMapping {
115 // labels: 0 // undefined by default
116 // values: 1 // undefined by default
117 // first: 0 // 0 by default
118 // count: 10 // "Undefined" by default
119 // orientation: PieMapping.Vertical // Vertical by default
120 // }
93 // }
121 // }
94
95
122
96 // TODO: show how to use data from a list model in a chart view
123 // TODO: show how to use data from a list model in a chart view
97 // i.e. copy the data into a chart model
124 // i.e. copy the data into a chart model
@@ -49,6 +49,19 Rectangle {
49 }
49 }
50 }
50 }
51
51
52 // TODO: optional implementation with generic ChartModel
53 // AreaSeries {
54 // model: chartModel
55 // modelMapping: XyMapping {
56 // xValues: 0 // undefined by default
57 // yValues: 1 // undefined by default
58 // first: 0 // 0 by default
59 // count: 10 // "Undefined" by default
60 // orientation: XyMapping.Vertical // Vertical by default
61 // }
62 // }
63
64
52 XYModel {
65 XYModel {
53 id: zerosModel
66 id: zerosModel
54 XyPoint { x: 0; y: 0 }
67 XyPoint { x: 0; y: 0 }
@@ -29,10 +29,50 Rectangle {
29 anchors.fill: parent
29 anchors.fill: parent
30 theme: ChartView.ChartThemeLight
30 theme: ChartView.ChartThemeLight
31 legend: ChartView.LegendBottom
31 legend: ChartView.LegendBottom
32 // axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"]
33 axisX.max: 10
32
34
33 BarSeries {
35 BarSeries {
34 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
36 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
35 // data implementation missing
37 model: barModel
36 }
38 }
39
40
41 // // TODO: optional syntax with ChartModel base model API
42 // BarSeries {
43 // model: chartModel
44 // modelMapping: BarSeriesMapping {
45 // // Giving "undefined" x mapping value means that the indexes are used as x-values
46 // setIndexes: [BarSeriesMapping.Undefined, 0,
47 // BarSeriesMapping.Undefined, 1,
48 // BarSeriesMapping.Undefined, 2] // defaults to []
49 //// setValues: [
50 //// BarSetMapping {x: BarSetMapping.Undefined; y: 0},
51 //// BarSetMapping {x: BarSetMapping.Undefined; y: 1},
52 //// BarSetMapping {x: BarSetMapping.Undefined; y: 2}
53 //// ]
54 // orientation: BarSeriesMapping.Vertical // defaults to Vertical
55 // startIndex: 0 // defaults to 0
56 // count: BarSeriesMapping.Undefined // defaults to "Undefined"
57 // }
58 // }
59 }
60
61 // ChartModel {
62 // id: chartModel
63 // }
64
65 BarModel {
66 id: barModel
67 BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] }
68 BarSet { name: "Bub"; values: [5, 1, 2, 4, 1, 7] }
69 BarSet { name: "Bib"; values: [3, 5, 8, 13, 5, 8] }
37 }
70 }
71
72 // TODO
73 // Component.onCompleted: {
74 // bobBars.append(1.2);
75 // bobBars.append(1.5);
76 // bobBars.append([1.5, 1.4, 1.9]);
77 // }
38 }
78 }
@@ -20,60 +20,76
20
20
21 #include "declarativebarseries.h"
21 #include "declarativebarseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include <QBarSet>
24 #include "qbarseries.h"
25 #include "qbarset.h"
26
24
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
26
29 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
27 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
30 QDeclarativeItem(parent)
28 QBarSet("", parent)
31 {
29 {
32 setFlag(QGraphicsItem::ItemHasNoContents, false);
33 }
30 }
34
31
35 void DeclarativeBarSeries::componentComplete()
32 QVariantList DeclarativeBarSet::values()
36 {
33 {
34 QVariantList values;
35 for (int i(0); i < count(); i++)
36 values.append(QVariant(at(i)));
37 return values;
37 }
38 }
38
39
39 void DeclarativeBarSeries::setBarCategories(QStringList categories)
40 void DeclarativeBarSet::setValues(QVariantList values)
40 {
41 {
41 m_categories = categories;
42 while (count())
43 remove(count() - 1);
42
44
43 if (m_series) {
45 for (int i(0); i < values.count(); i++) {
44 delete m_series;
46 if (values.at(i).canConvert(QVariant::Double))
45 m_series = 0;
47 append(values[i].toDouble());
48 }
46 }
49 }
47
50
48 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
51 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
49 if (declarativeChart) {
52 QBarSeries(parent)
50 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
53 {
51 Q_ASSERT(chart);
54 }
52
53 // m_series = new QBarSeries(m_categories);
54 m_series = new QBarSeries();
55 m_series->setCategories(m_categories);
56
55
57 // TODO: use data from model
56 void DeclarativeBarSeries::classBegin()
58 QBarSet *set0 = new QBarSet("Bub");
57 {
59 QBarSet *set1 = new QBarSet("Bob");
58 }
60 QBarSet *set2 = new QBarSet("Guybrush");
61
59
62 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
60 void DeclarativeBarSeries::componentComplete()
63 *set1 << 5 << 1 << 2 << 4 << 1 << 7;
61 {
64 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
62 if (model())
63 setModelMapping(0, 1, 1, Qt::Vertical);
64 }
65
65
66 m_series->appendBarSet(set0);
66 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeBarModel *model)
67 m_series->appendBarSet(set1);
67 {
68 m_series->appendBarSet(set2);
68 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
69 bool value(false);
70 if (m) {
71 value = setModel(m);
72 //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
73 setModelMapping(0, 1, 1, Qt::Vertical);
74 } else {
75 qWarning("DeclarativeBarSeries: Illegal model");
76 }
77 return value;
78 }
69
79
70 chart->addSeries(m_series);
80 DeclarativeBarModel *DeclarativeBarSeries::declarativeModel()
81 {
82 return qobject_cast<DeclarativeBarModel *>(model());
71 }
83 }
84
85 void DeclarativeBarSeries::setBarCategories(QStringList categories)
86 {
87 setCategories(categories);
72 }
88 }
73
89
74 QStringList DeclarativeBarSeries::barCategories()
90 QStringList DeclarativeBarSeries::barCategories()
75 {
91 {
76 return m_categories;
92 return categories();
77 }
93 }
78
94
79 #include "moc_declarativebarseries.cpp"
95 #include "moc_declarativebarseries.cpp"
@@ -22,25 +22,45
22 #define DECLARATIVEBARSERIES_H
22 #define DECLARATIVEBARSERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "declarativemodel.h"
25 #include <QDeclarativeItem>
26 #include <QDeclarativeItem>
27 #include <QDeclarativeParserStatus>
28 #include <QBarSeries>
26
29
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
31
29 class QChart;
32 class QChart;
30 class QBarSeries;
33 class QBarSeries;
31
34
32 class DeclarativeBarSeries : public QDeclarativeItem
35 class DeclarativeBarSet : public QBarSet
33 {
36 {
34 Q_OBJECT
37 Q_OBJECT
38 Q_PROPERTY(QVariantList values READ values WRITE setValues)
39 Q_PROPERTY(QString name READ name WRITE setName)
40
41 public:
42 explicit DeclarativeBarSet(QObject *parent = 0);
43 QVariantList values();
44 void setValues(QVariantList values);
45 };
46
47 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus
48 {
49 Q_OBJECT
50 Q_INTERFACES(QDeclarativeParserStatus)
51 Q_PROPERTY(DeclarativeBarModel *model READ declarativeModel WRITE setDeclarativeModel)
35 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
52 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
36
53
37 public:
54 public:
38 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
55 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
39
56
40 public: // from QDeclarativeParserStatus
57 public: // from QDeclarativeParserStatus
58 void classBegin();
41 void componentComplete();
59 void componentComplete();
42
60
43 public:
61 public:
62 bool setDeclarativeModel(DeclarativeBarModel *model);
63 DeclarativeBarModel *declarativeModel();
44 void setBarCategories(QStringList categories);
64 void setBarCategories(QStringList categories);
45 QStringList barCategories();
65 QStringList barCategories();
46
66
@@ -49,9 +69,6 Q_SIGNALS:
49 public Q_SLOTS:
69 public Q_SLOTS:
50
70
51 public:
71 public:
52 QChart *m_chart;
53 QBarSeries *m_series;
54 QStringList m_categories;
55 };
72 };
56
73
57 QTCOMMERCIALCHART_END_NAMESPACE
74 QTCOMMERCIALCHART_END_NAMESPACE
@@ -24,10 +24,54
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 ////////////// Table model (base) ///////////////////
28
29 DeclarativeTableModel::DeclarativeTableModel(QObject *parent) :
30 ChartTableModel(parent)
31 {
32 }
33
34 void DeclarativeTableModel::classBegin()
35 {
36 }
37
38 void DeclarativeTableModel::componentComplete()
39 {
40 foreach (QObject *child, children())
41 appendToModel(child);
42 }
43
44 QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren()
45 {
46 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild);
47 }
48
49 void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list,
50 QObject *child)
51 {
52 // childs are added in componentComplete instead
53 Q_UNUSED(list)
54 Q_UNUSED(child)
55 }
56
57 void DeclarativeTableModel::appendToModel(QObject *object)
58 {
59 if (qobject_cast<DeclarativeBarModel *>(this)) {
60 DeclarativeBarModel *model = qobject_cast<DeclarativeBarModel *>(this);
61 model->append(qobject_cast<QBarSet *>(object));
62 } else if (qobject_cast<DeclarativePieModel *>(this)) {
63 DeclarativePieModel *model = qobject_cast<DeclarativePieModel *>(this);
64 model->append(qobject_cast<QPieSlice *>(object));
65 } else if (qobject_cast<DeclarativeXyModel *>(this)) {
66 DeclarativeXyModel *model = qobject_cast<DeclarativeXyModel *>(this);
67 model->append(qobject_cast<DeclarativeXyPoint *>(object));
68 }
69 }
70
27 ////////////// XY model ///////////////////////
71 ////////////// XY model ///////////////////////
28
72
29 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
73 DeclarativeXyModel::DeclarativeXyModel(QObject *parent) :
30 ChartTableModel(parent)
74 DeclarativeTableModel(parent)
31 {
75 {
32 }
76 }
33
77
@@ -67,25 +111,10 void DeclarativeXyModel::append(QVariantList points)
67 }
111 }
68 }
112 }
69
113
70 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeXyModel::points()
71 {
72 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXyModel::appendPoint);
73 }
74
75 void DeclarativeXyModel::appendPoint(QDeclarativeListProperty<DeclarativeXyPoint> *list,
76 DeclarativeXyPoint *point)
77 {
78 DeclarativeXyModel *model = qobject_cast<DeclarativeXyModel *>(list->object);
79 if (model)
80 model->append(point);
81 else
82 qWarning() << "Illegal point item";
83 }
84
85 ////////////// Pie model ///////////////////////
114 ////////////// Pie model ///////////////////////
86
115
87 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
116 DeclarativePieModel::DeclarativePieModel(QObject *parent) :
88 ChartTableModel(parent)
117 DeclarativeTableModel(parent)
89 {
118 {
90 }
119 }
91
120
@@ -109,6 +138,10 void DeclarativePieModel::append(QVariantList slices)
109 if (ok) {
138 if (ok) {
110 QPieSlice *slice = new QPieSlice(value, label);
139 QPieSlice *slice = new QPieSlice(value, label);
111 append(slice);
140 append(slice);
141 // TODO: how to copy the properties to the newly added slice?
142 // (DeclarativePieModel::append only copies the label and value to the model)
143 // QPieSlice *addedSlice = append(slice);
144 // addedSlice->setExploded(slice->isExploded());
112 } else {
145 } else {
113 qWarning() << "Illegal slice item";
146 qWarning() << "Illegal slice item";
114 }
147 }
@@ -118,19 +151,25 void DeclarativePieModel::append(QVariantList slices)
118 }
151 }
119 }
152 }
120
153
121 QDeclarativeListProperty<QPieSlice> DeclarativePieModel::slices()
154 ////////////// Bar model ///////////////////////
155
156 DeclarativeBarModel::DeclarativeBarModel(QObject *parent) :
157 DeclarativeTableModel(parent)
122 {
158 {
123 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieModel::appendSlice);
124 }
159 }
125
160
126 void DeclarativePieModel::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
161 void DeclarativeBarModel::append(QBarSet* barSet)
127 QPieSlice *slice)
128 {
162 {
129 DeclarativePieModel *pieModel = qobject_cast<DeclarativePieModel *>(list->object);
163 insertColumn(columnCount());
130 if (pieModel)
164 for (int i(0); i < barSet->count(); i++) {
131 pieModel->append(slice);
165 if (rowCount() < (i + 1))
132 else
166 insertRow(rowCount());
133 qWarning() << "Illegal slice item";
167 setData(createIndex(i, columnCount() - 1), barSet->at(i));
168 // insertRow(rowCount());
169 // setData(createIndex(rowCount() - 1, 0), );
170 // setData(createIndex(rowCount() - 1, 1), barSet->at(i));
171 }
172 // TODO: setModelMapping(0, 1, columnCount(), Qt::Vertical);
134 }
173 }
135
174
136 #include "moc_declarativemodel.cpp"
175 #include "moc_declarativemodel.cpp"
@@ -23,46 +23,70
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "declarativexypoint.h"
25 #include "declarativexypoint.h"
26 #include "qpieslice.h"
26 #include <QPieSlice>
27 #include "../src/charttablemodel.h" // TODO
27 #include "../src/charttablemodel.h" // TODO
28 #include <QBarSet>
28 #include <QDeclarativeListProperty>
29 #include <QDeclarativeListProperty>
29 #include <QVariant>
30 #include <QVariant>
31 #include <QDeclarativeParserStatus>
30
32
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
34
33 class DeclarativeXyModel : public ChartTableModel
35 class DeclarativeTableModel : public ChartTableModel, public QDeclarativeParserStatus
36 {
37 Q_OBJECT
38 Q_INTERFACES(QDeclarativeParserStatus)
39 Q_PROPERTY(QDeclarativeListProperty<QObject> modelChildren READ modelChildren)
40 Q_CLASSINFO("DefaultProperty", "modelChildren")
41
42 public:
43 explicit DeclarativeTableModel(QObject *parent = 0);
44 QDeclarativeListProperty<QObject> modelChildren();
45
46 public: // from QDeclarativeParserStatus
47 void classBegin();
48 void componentComplete();
49
50 public Q_SLOTS:
51 static void appendModelChild(QDeclarativeListProperty<QObject> *list,
52 QObject *element);
53 private:
54 void appendToModel(QObject *object);
55 };
56
57 class DeclarativeXyModel : public DeclarativeTableModel
34 {
58 {
35 Q_OBJECT
59 Q_OBJECT
36 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
37 Q_CLASSINFO("DefaultProperty", "points")
38
60
39 public:
61 public:
40 explicit DeclarativeXyModel(QObject *parent = 0);
62 explicit DeclarativeXyModel(QObject *parent = 0);
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42
63
43 public Q_SLOTS:
64 public Q_SLOTS:
44 void append(DeclarativeXyPoint* point);
65 void append(DeclarativeXyPoint* point);
45 void append(QVariantList points);
66 void append(QVariantList points);
46 static void appendPoint(QDeclarativeListProperty<DeclarativeXyPoint> *list,
47 DeclarativeXyPoint *element);
48 };
67 };
49
68
50
69 class DeclarativePieModel : public DeclarativeTableModel
51 class DeclarativePieModel : public ChartTableModel
52 {
70 {
53 Q_OBJECT
71 Q_OBJECT
54 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices)
55 Q_CLASSINFO("DefaultProperty", "slices")
56
72
57 public:
73 public:
58 explicit DeclarativePieModel(QObject *parent = 0);
74 explicit DeclarativePieModel(QObject *parent = 0);
59 QDeclarativeListProperty<QPieSlice> slices();
60
75
61 public Q_SLOTS:
76 public Q_SLOTS:
62 void append(QPieSlice* slice);
77 void append(QPieSlice* slice);
63 void append(QVariantList slices);
78 void append(QVariantList slices);
64 static void appendSlice(QDeclarativeListProperty<QPieSlice> *list,
79 };
65 QPieSlice *element);
80
81 class DeclarativeBarModel : public DeclarativeTableModel
82 {
83 Q_OBJECT
84
85 public:
86 explicit DeclarativeBarModel(QObject *parent = 0);
87
88 public Q_SLOTS:
89 void append(QBarSet* barSet);
66 };
90 };
67
91
68 QTCOMMERCIALCHART_END_NAMESPACE
92 QTCOMMERCIALCHART_END_NAMESPACE
@@ -30,6 +30,15 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
30 {
30 {
31 }
31 }
32
32
33 QPieSlice *DeclarativePieSeries::slice(int index)
34 {
35 QList<QPieSlice*> sliceList = slices();
36 if (index < sliceList.count())
37 return sliceList[index];
38
39 return 0;
40 }
41
33 bool DeclarativePieSeries::setPieModel(DeclarativePieModel *model)
42 bool DeclarativePieSeries::setPieModel(DeclarativePieModel *model)
34 {
43 {
35 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
44 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
@@ -41,6 +41,9 class DeclarativePieSeries : public QPieSeries
41 public:
41 public:
42 explicit DeclarativePieSeries(QObject *parent = 0);
42 explicit DeclarativePieSeries(QObject *parent = 0);
43
43
44 public:
45 Q_INVOKABLE QPieSlice *slice(int index);
46
44 public Q_SLOTS:
47 public Q_SLOTS:
45
48
46 public:
49 public:
@@ -40,7 +40,7 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeXyModel *model)
40 if (m) {
40 if (m) {
41 // All the inherited objects must be of type QXYSeries, so it is safe to cast
41 // All the inherited objects must be of type QXYSeries, so it is safe to cast
42 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
42 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
43 series->setModel(m);
43 value = series->setModel(m);
44 series->setModelMapping(0, 1, Qt::Vertical);
44 series->setModelMapping(0, 1, Qt::Vertical);
45 } else {
45 } else {
46 qWarning("DeclarativeXySeries: Illegal model");
46 qWarning("DeclarativeXySeries: Illegal model");
@@ -30,7 +30,6
30 #include "declarativescatterseries.h"
30 #include "declarativescatterseries.h"
31 #include "declarativebarseries.h"
31 #include "declarativebarseries.h"
32 #include "declarativepieseries.h"
32 #include "declarativepieseries.h"
33 //#include "declarativepiemodel.h"
34
33
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
35
@@ -54,9 +53,10 public:
54 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
53 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
55 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
54 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
56 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
55 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
57 // TODO: a declarative model for each type
58 qmlRegisterType<DeclarativePieModel>(uri, 1, 0, "PieModel");
56 qmlRegisterType<DeclarativePieModel>(uri, 1, 0, "PieModel");
59 qmlRegisterType<DeclarativeXyModel>(uri, 1, 0, "XYModel");
57 qmlRegisterType<DeclarativeXyModel>(uri, 1, 0, "XYModel");
58 qmlRegisterType<DeclarativeBarModel>(uri, 1, 0, "BarModel");
59 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
60 }
60 }
61 };
61 };
62
62
@@ -137,6 +137,9 void QBarSet::replace(const int index, const qreal value)
137 */
137 */
138 qreal QBarSet::at(const int index) const
138 qreal QBarSet::at(const int index) const
139 {
139 {
140 if (index < 0 || index >= d_ptr->m_values.count())
141 return 0.0;
142
140 return d_ptr->m_values.at(index);
143 return d_ptr->m_values.at(index);
141 }
144 }
142
145
@@ -32,6 +32,7 class QBarSetPrivate;
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(QString name READ name WRITE setName)
35
36
36 public:
37 public:
37 explicit QBarSet(const QString name, QObject *parent = 0);
38 explicit QBarSet(const QString name, QObject *parent = 0);
@@ -64,16 +64,15 QVariant ChartTableModel::headerData (int section, Qt::Orientation orientation,
64 if (role != Qt::DisplayRole)
64 if (role != Qt::DisplayRole)
65 return QVariant();
65 return QVariant();
66
66
67 if (orientation == Qt::Horizontal)
67 if (orientation == Qt::Horizontal) {
68 {
69 if (section%2 == 0)
68 if (section % 2 == 0)
70 return "x";
69 return "x";
71 else
70 else
72 return "y";
71 return "y";
73 }
72 } else {
74 else
75 return QString("%1").arg(section + 1);
73 return QString("%1").arg(section + 1);
76 }
74 }
75 }
77
76
78 QVariant ChartTableModel::data(const QModelIndex &index, int role) const
77 QVariant ChartTableModel::data(const QModelIndex &index, int role) const
79 {
78 {
@@ -33,8 +33,9 class PieSliceData;
33 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
33 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY changed)
36 Q_PROPERTY(QString label READ label WRITE setLabel)
37 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed)
37 Q_PROPERTY(qreal value READ value WRITE setValue)
38 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded)
38
39
39 public:
40 public:
40 explicit QPieSlice(QObject *parent = 0);
41 explicit QPieSlice(QObject *parent = 0);
General Comments 0
You need to be logged in to leave comments. Login now