##// END OF EJS Templates
Cleaning up ChartModel impl before moving it into a demo app
Tero Ahola -
r1190:f9f8ff23359b
parent child
Show More
@@ -50,11 +50,11 Rectangle {
50 // // For dynamic data you can use the ChartModel API.
50 // // For dynamic data you can use the ChartModel API.
51 // ChartModel {
51 // ChartModel {
52 // id: chartModel
52 // id: chartModel
53 // ChartModelRow { values: ["Volkswagen", 13.5] }
53 // ChartModelElement { values: ["Volkswagen", 13.5] }
54 // ChartModelRow { values: ["Toyota", 10.9] }
54 // ChartModelElement { values: ["Toyota", 10.9] }
55 // ChartModelRow { values: ["Ford", 8.6] }
55 // ChartModelElement { values: ["Ford", 8.6] }
56 // ChartModelRow { values: ["Skoda", 8.2] }
56 // ChartModelElement { values: ["Skoda", 8.2] }
57 // ChartModelRow { values: ["Volvo", 6.8] }
57 // ChartModelElement { values: ["Volvo", 6.8] }
58 // }
58 // }
59 // // In this case you need to define how the data maps to pie slices with the ModelMapper API of the pie series.
59 // // In this case you need to define how the data maps to pie slices with the ModelMapper API of the pie series.
60 // PieSeries {
60 // PieSeries {
@@ -50,13 +50,13 Rectangle {
50
50
51 ChartModel {
51 ChartModel {
52 id: chartModel
52 id: chartModel
53 ChartModelRow { values: [0.0, 0.0, 0.3] }
53 ChartModelElement { values: [0.0, 0.0, 0.3] }
54 ChartModelRow { values: [1.1, 2.1, 3.2] }
54 ChartModelElement { values: [1.1, 2.1, 3.2] }
55 ChartModelRow { values: [1.9, 3.3, 2.4] }
55 ChartModelElement { values: [1.9, 3.3, 2.4] }
56 ChartModelRow { values: [2.1, 2.1, 2.1] }
56 ChartModelElement { values: [2.1, 2.1, 2.1] }
57 ChartModelRow { values: [2.9, 4.9, 2.6] }
57 ChartModelElement { values: [2.9, 4.9, 2.6] }
58 ChartModelRow { values: [3.4, 3.0, 2.3] }
58 ChartModelElement { values: [3.4, 3.0, 2.3] }
59 ChartModelRow { values: [4.1, 3.3, 3.1] }
59 ChartModelElement { values: [4.1, 3.3, 3.1] }
60 }
60 }
61
61
62 }
62 }
@@ -62,17 +62,17 Rectangle {
62
62
63 ChartModel {
63 ChartModel {
64 id: chartModel
64 id: chartModel
65 ChartModelRow { values: [0, 0, 1, 1, 0] }
65 ChartModelElement { values: [0, 0, 1, 1, 0] }
66 ChartModelRow { values: [1, 0, 1, 1, 0] }
66 ChartModelElement { values: [1, 0, 1, 1, 0] }
67 ChartModelRow { values: [2, 0, 1, 3, 0] }
67 ChartModelElement { values: [2, 0, 1, 3, 0] }
68 ChartModelRow { values: [3, 0, 1, 3, 0] }
68 ChartModelElement { values: [3, 0, 1, 3, 0] }
69 ChartModelRow { values: [4, 0, 1, 2, 0] }
69 ChartModelElement { values: [4, 0, 1, 2, 0] }
70 ChartModelRow { values: [5, 0, 0, 0, 0] }
70 ChartModelElement { values: [5, 0, 0, 0, 0] }
71 ChartModelRow { values: [6, 0, 1, 2, 1] }
71 ChartModelElement { values: [6, 0, 1, 2, 1] }
72 ChartModelRow { values: [7, 0, 1, 1, 0] }
72 ChartModelElement { values: [7, 0, 1, 1, 0] }
73 ChartModelRow { values: [8, 0, 4, 2, 0] }
73 ChartModelElement { values: [8, 0, 4, 2, 0] }
74 ChartModelRow { values: [9, 0, 3, 1, 0] }
74 ChartModelElement { values: [9, 0, 3, 1, 0] }
75 ChartModelRow { values: [10, 0, 2, 3, 0] }
75 ChartModelElement { values: [10, 0, 2, 3, 0] }
76 ChartModelRow { values: [11, 0, 1, 3, 1] }
76 ChartModelElement { values: [11, 0, 1, 3, 1] }
77 }
77 }
78 }
78 }
@@ -37,7 +37,6 Rectangle {
37 model: barModel
37 model: barModel
38 }
38 }
39
39
40
41 // // TODO: optional syntax with ChartModel base model API
40 // // TODO: optional syntax with ChartModel base model API
42 // BarSeries {
41 // BarSeries {
43 // model: chartModel
42 // model: chartModel
@@ -65,8 +64,8 Rectangle {
65 BarModel {
64 BarModel {
66 id: barModel
65 id: barModel
67 BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] }
66 BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] }
68 BarSet { name: "Bub"; values: [5, 1, 2, 4, 1, 7] }
67 BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] }
69 BarSet { name: "Bib"; values: [3, 5, 8, 13, 5, 8] }
68 BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] }
70 }
69 }
71
70
72 // TODO
71 // TODO
@@ -27,17 +27,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 ////////////// Table model row ///////////////////
28 ////////////// Table model row ///////////////////
29
29
30 DeclarativeTableModelRow::DeclarativeTableModelRow(QObject *parent)
30 DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent)
31 : QObject(parent)
31 : QObject(parent)
32 {
32 {
33 }
33 }
34
34
35 QVariantList DeclarativeTableModelRow::values()
35 QVariantList DeclarativeTableModelElement::values()
36 {
36 {
37 return m_values;
37 return m_values;
38 }
38 }
39
39
40 void DeclarativeTableModelRow::setValues(QVariantList values)
40 void DeclarativeTableModelElement::setValues(QVariantList values)
41 {
41 {
42 m_values = values;
42 m_values = values;
43 }
43 }
@@ -56,8 +56,8 void DeclarativeTableModel::classBegin()
56 void DeclarativeTableModel::componentComplete()
56 void DeclarativeTableModel::componentComplete()
57 {
57 {
58 foreach (QObject *child, children()) {
58 foreach (QObject *child, children()) {
59 if (qobject_cast<DeclarativeTableModelRow *>(child)) {
59 if (qobject_cast<DeclarativeTableModelElement *>(child)) {
60 append(qobject_cast<DeclarativeTableModelRow *>(child)->values());
60 append(qobject_cast<DeclarativeTableModelElement *>(child)->values());
61 }
61 }
62 }
62 }
63 }
63 }
@@ -99,49 +99,13 void DeclarativeTableModel::append(QVariantList values)
99
99
100 void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point)
100 void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point)
101 {
101 {
102 qDebug() << "DeclarativeTableModel::appendPoint:" << point;
102 // qDebug() << "DeclarativeTableModel::appendPoint:" << point;
103 QVariantList values;
103 QVariantList values;
104 values.insert(mapper->mapX(), point->x());
104 values.insert(mapper->mapX(), point->x());
105 values.insert(mapper->mapY(), point->y());
105 values.insert(mapper->mapY(), point->y());
106 append(values);
106 append(values);
107 }
107 }
108
108
109 //void DeclarativeTableModel::appendPoints(QVariantList points)
110 //{
111 // qreal x = 0.0;
112 // for (int i(0); i < points.count(); i++) {
113 // if (i % 2) {
114 // bool ok(false);
115 // qreal y = points.at(i).toReal(&ok);
116 // if (ok) {
117 // DeclarativeXyPoint *point= new DeclarativeXyPoint();
118 // point->setX(x);
119 // point->setY(y);
120 // appendPoint(point);
121 // } else {
122 // qWarning() << "Illegal y value";
123 // }
124 // } else {
125 // bool ok(false);
126 // x = points.at(i).toReal(&ok);
127 // if (!ok) {
128 // qWarning() << "Illegal x value";
129 // }
130 // }
131 // }
132 //}
133
134 //void DeclarativeTableModel::appendPoint(DeclarativeXyPoint* point)
135 //{
136 //// qDebug() << "DeclarativeTableModel::append:" << point->x() << " " << point->y();
137 // insertRow(rowCount());
138 // QModelIndex xModelIndex = createIndex(rowCount() - 1, 0);
139 // QModelIndex yModelIndex = createIndex(rowCount() - 1, 1);
140 // setData(xModelIndex, point->x());
141 // setData(yModelIndex, point->y());
142 // dataChanged(xModelIndex, yModelIndex);
143 //}
144
145 ////////////// Bar model ///////////////////////
109 ////////////// Bar model ///////////////////////
146
110
147 DeclarativeBarModel::DeclarativeBarModel(QObject *parent) :
111 DeclarativeBarModel::DeclarativeBarModel(QObject *parent) :
@@ -33,13 +33,13
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 class DeclarativeTableModelRow : public QObject
36 class DeclarativeTableModelElement : public QObject
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 Q_PROPERTY(QVariantList values READ values WRITE setValues)
39 Q_PROPERTY(QVariantList values READ values WRITE setValues)
40
40
41 public:
41 public:
42 explicit DeclarativeTableModelRow(QObject *parent = 0);
42 explicit DeclarativeTableModelElement(QObject *parent = 0);
43 QVariantList values();
43 QVariantList values();
44 void setValues(QVariantList values);
44 void setValues(QVariantList values);
45 private:
45 private:
@@ -57,7 +57,7 public:
57 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
57 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
58 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
58 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
59 qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel");
59 qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel");
60 qmlRegisterType<DeclarativeTableModelRow>(uri, 1, 0, "ChartModelRow");
60 qmlRegisterType<DeclarativeTableModelElement>(uri, 1, 0, "ChartModelElement");
61 //qmlRegisterType<DeclarativePieMapping>(uri, 1, 0, "PieMapping");
61 //qmlRegisterType<DeclarativePieMapping>(uri, 1, 0, "PieMapping");
62 //qmlRegisterType<QPieModelMapper>(uri, 1, 0, "PieModelMapper");
62 //qmlRegisterType<QPieModelMapper>(uri, 1, 0, "PieModelMapper");
63 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
63 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
General Comments 0
You need to be logged in to leave comments. Login now