##// END OF EJS Templates
Bar model mapper to Qml custom model demo
Tero Ahola -
r1313:a90564adf9b7
parent child
Show More
@@ -1,120 +1,128
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23 import QmlCustomModel 1.0
23 import QmlCustomModel 1.0
24
24
25 Rectangle {
25 Rectangle {
26 width: parent.width
26 width: parent.width
27 height: parent.height
27 height: parent.height
28
28
29 ChartView {
29 ChartView {
30 id: chart
30 id: chart
31 title: "Custom model example"
31 title: "Custom model example"
32 anchors.fill: parent
32 anchors.fill: parent
33 theme: ChartView.ChartThemeLight
33 theme: ChartView.ChartThemeLight
34 axisX.max: 20
34 axisX.max: 10
35 axisX.min: 0
35 axisY.max: 20
36 axisY.max: 20
37 axisY.min: 0
36
38
37 // For dynamic data we use a custom data model derived from QAbstractiItemModel
39 // For dynamic data we use a custom data model derived from QAbstractiItemModel
38 CustomModel {
40 CustomModel {
39 id: customModel
41 id: customModel
40 CustomModelElement { values: [0, "Manufacturer", 1, 2] }
42 CustomModelElement { values: [0, "Manufacturer", 1, 2] }
41 CustomModelElement { values: [1, "Volkswagen", 13.5, 12.5] }
43 CustomModelElement { values: [1, "Volkswagen", 13.5, 12.5] }
42 CustomModelElement { values: [2, "Toyota", 10.9, 9.9] }
44 CustomModelElement { values: [2, "Toyota", 10.9, 9.9] }
43 CustomModelElement { values: [3, "Ford", 8.6, 7.6] }
45 CustomModelElement { values: [3, "Ford", 8.6, 7.6] }
44 CustomModelElement { values: [4, "Skoda", 8.2, 7.2] }
46 CustomModelElement { values: [4, "Skoda", 8.2, 7.2] }
45 CustomModelElement { values: [5, "Volvo", 6.8, 5.8] }
47 CustomModelElement { values: [5, "Volvo", 6.8, 5.8] }
46 }
48 }
47
49
48 LineSeries {
50 LineSeries {
49 name: "Volkswagen"
51 name: "Volkswagen"
50 HXYModelMapper {
52 HXYModelMapper {
51 model: customModel
53 model: customModel
52 xRow: 0
54 xRow: 0
53 yRow: 1
55 yRow: 1
54 first: 2
56 first: 2
55 }
57 }
56 }
58 }
57
59
58 LineSeries {
60 LineSeries {
59 name: "Toyota"
61 name: "Toyota"
60 HXYModelMapper {
62 HXYModelMapper {
61 model: customModel
63 model: customModel
62 xRow: 0
64 xRow: 0
63 yRow: 2
65 yRow: 2
64 first: 2
66 first: 2
65 }
67 }
66 }
68 }
67
69
68 PieSeries {
70 PieSeries {
69 id: pieSeries
71 id: pieSeries
70 size: 0.4
72 size: 0.4
71 horizontalPosition: 0.2
73 horizontalPosition: 0.7
72 verticalPosition: 0.3
74 verticalPosition: 0.3
73 }
75 }
74
76
75 VPieModelMapper {
77 VPieModelMapper {
76 series: pieSeries
78 series: pieSeries
77 model: customModel
79 model: customModel
78 labelsColumn: 1
80 labelsColumn: 1
79 valuesColumn: 2
81 valuesColumn: 2
80 first: 1
82 first: 1
81 }
83 }
82
84
83 AreaSeries {
85 AreaSeries {
84 name: "Ford"
86 name: "Ford"
85 upperSeries: LineSeries {
87 upperSeries: LineSeries {
86 HXYModelMapper {
88 HXYModelMapper {
87 model: customModel
89 model: customModel
88 xRow: 0
90 xRow: 0
89 yRow: 3
91 yRow: 3
90 first: 2
92 first: 2
91 }
93 }
92 }
94 }
93 }
95 }
94
96
95 // BarSeries {
97 GroupedBarSeries {
96 // model: customModel
98 name: "Skoda and Volvo"
97 // modelMapper.first: 0
99 barCategories: [ "1", "2", "3", "4", "5", "6" ]
98 // }
100 HBarModelMapper {
101 model: customModel
102 firstBarSetRow: 4
103 lastBarSetRow: 5
104 first: 2
105 }
106 }
99 }
107 }
100
108
101
109
102 // TODO: you could also implement appending to your model, for example:
110 // TODO: you could also implement appending to your model, for example:
103 // pieSeries.model.append(["Others", 52.0]);
111 // pieSeries.model.append(["Others", 52.0]);
104
112
105 // TODO: show how to use data from a list model in a chart view
113 // TODO: show how to use data from a list model in a chart view
106 // i.e. copy the data into a custom model
114 // i.e. copy the data into a custom model
107 // ListModel {
115 // ListModel {
108 // id: listModel
116 // id: listModel
109 // ListElement {
117 // ListElement {
110 // label: "Volkswagen"
118 // label: "Volkswagen"
111 // value: 13.5
119 // value: 13.5
112 // }
120 // }
113 // ListElement {
121 // ListElement {
114 // label: "Toyota"
122 // label: "Toyota"
115 // value: 10.9
123 // value: 10.9
116 // }
124 // }
117 // // and so on...
125 // // and so on...
118 // }
126 // }
119
127
120 }
128 }
@@ -1,173 +1,201
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativebarseries.h"
21 #include "declarativebarseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include <QBarSet>
23 #include <QBarSet>
24 #include <QVBarModelMapper>
25 #include <QHBarModelMapper>
24
26
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
28
27 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
29 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
28 QBarSet("", parent)
30 QBarSet("", parent)
29 {
31 {
30 }
32 }
31
33
32 QVariantList DeclarativeBarSet::values()
34 QVariantList DeclarativeBarSet::values()
33 {
35 {
34 QVariantList values;
36 QVariantList values;
35 for (int i(0); i < count(); i++)
37 for (int i(0); i < count(); i++)
36 values.append(QVariant(at(i)));
38 values.append(QVariant(at(i)));
37 return values;
39 return values;
38 }
40 }
39
41
40 void DeclarativeBarSet::setValues(QVariantList values)
42 void DeclarativeBarSet::setValues(QVariantList values)
41 {
43 {
42 while (count())
44 while (count())
43 remove(count() - 1);
45 remove(count() - 1);
44
46
45 for (int i(0); i < values.count(); i++) {
47 for (int i(0); i < values.count(); i++) {
46 if (values.at(i).canConvert(QVariant::Double))
48 if (values.at(i).canConvert(QVariant::Double))
47 append(values[i].toDouble());
49 append(values[i].toDouble());
48 }
50 }
49 }
51 }
50
52
51 QColor DeclarativeBarSet::color()
53 QColor DeclarativeBarSet::color()
52 {
54 {
53 return brush().color();
55 return brush().color();
54 }
56 }
55
57
56 void DeclarativeBarSet::setColor(QColor color)
58 void DeclarativeBarSet::setColor(QColor color)
57 {
59 {
58 QBrush b = brush();
60 QBrush b = brush();
59 b.setColor(color);
61 b.setColor(color);
60 setBrush(b);
62 setBrush(b);
61 }
63 }
62
64
63 QColor DeclarativeBarSet::borderColor()
65 QColor DeclarativeBarSet::borderColor()
64 {
66 {
65 return pen().color();
67 return pen().color();
66 }
68 }
67
69
68 void DeclarativeBarSet::setBorderColor(QColor color)
70 void DeclarativeBarSet::setBorderColor(QColor color)
69 {
71 {
70 QPen p = pen();
72 QPen p = pen();
71 p.setColor(color);
73 p.setColor(color);
72 setPen(p);
74 setPen(p);
73 }
75 }
74
76
75 QColor DeclarativeBarSet::labelColor()
77 QColor DeclarativeBarSet::labelColor()
76 {
78 {
77 return labelBrush().color();
79 return labelBrush().color();
78 }
80 }
79
81
80 void DeclarativeBarSet::setLabelColor(QColor color)
82 void DeclarativeBarSet::setLabelColor(QColor color)
81 {
83 {
82 QBrush b = labelBrush();
84 QBrush b = labelBrush();
83 b.setColor(color);
85 b.setColor(color);
84 setLabelBrush(b);
86 setLabelBrush(b);
85 }
87 }
86
88
87 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
89 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
88 QBarSeries(parent)
90 QBarSeries(parent)
89 {
91 {
90 }
92 }
91
93
92 void DeclarativeBarSeries::classBegin()
94 void DeclarativeBarSeries::classBegin()
93 {
95 {
94 }
96 }
95
97
96 void DeclarativeBarSeries::componentComplete()
98 void DeclarativeBarSeries::componentComplete()
97 {
99 {
98 foreach(QObject *child, children()) {
100 foreach(QObject *child, children()) {
99 if (qobject_cast<DeclarativeBarSet *>(child)) {
101 if (qobject_cast<DeclarativeBarSet *>(child)) {
100 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
102 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
103 } else if(qobject_cast<QVBarModelMapper *>(child)) {
104 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
105 mapper->setSeries(this);
106 } else if(qobject_cast<QHBarModelMapper *>(child)) {
107 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
108 mapper->setSeries(this);
101 }
109 }
102 }
110 }
103 }
111 }
104
112
105 QDeclarativeListProperty<DeclarativeBarSet> DeclarativeBarSeries::initialBarSets()
113 QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren()
106 {
114 {
107 return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeBarSeries::appendInitialBarSets);
115 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
116 }
117
118 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
119 {
120 // Empty implementation; the children are parsed in componentComplete instead
121 Q_UNUSED(list);
122 Q_UNUSED(element);
108 }
123 }
109
124
110 void DeclarativeBarSeries::setBarCategories(QStringList categories)
125 void DeclarativeBarSeries::setBarCategories(QStringList categories)
111 {
126 {
112 setCategories(categories);
127 setCategories(categories);
113 }
128 }
114
129
115 QStringList DeclarativeBarSeries::barCategories()
130 QStringList DeclarativeBarSeries::barCategories()
116 {
131 {
117 return categories();
132 return categories();
118 }
133 }
119
134
120 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
135 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
121 {
136 {
122 QList<QBarSet*> setList = barSets();
137 QList<QBarSet*> setList = barSets();
123 if (index < setList.count())
138 if (index < setList.count())
124 return qobject_cast<DeclarativeBarSet *>(setList[index]);
139 return qobject_cast<DeclarativeBarSet *>(setList[index]);
125
140
126 return 0;
141 return 0;
127 }
142 }
128
143
129 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
144 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
130 QGroupedBarSeries(parent)
145 QGroupedBarSeries(parent)
131 {
146 {
132 }
147 }
133
148
134 void DeclarativeGroupedBarSeries::classBegin()
149 void DeclarativeGroupedBarSeries::classBegin()
135 {
150 {
136 }
151 }
137
152
138 void DeclarativeGroupedBarSeries::componentComplete()
153 void DeclarativeGroupedBarSeries::componentComplete()
139 {
154 {
140 foreach(QObject *child, children()) {
155 foreach(QObject *child, children()) {
141 if (qobject_cast<DeclarativeBarSet *>(child)) {
156 if (qobject_cast<DeclarativeBarSet *>(child)) {
142 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
157 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
158 } else if(qobject_cast<QVBarModelMapper *>(child)) {
159 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
160 mapper->setSeries(this);
161 } else if(qobject_cast<QHBarModelMapper *>(child)) {
162 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
163 mapper->setSeries(this);
143 }
164 }
144 }
165 }
145 }
166 }
146
167
147 QDeclarativeListProperty<DeclarativeBarSet> DeclarativeGroupedBarSeries::initialBarSets()
168 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
169 {
170 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
171 }
172
173 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
148 {
174 {
149 return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeGroupedBarSeries::appendInitialBarSets);
175 // Empty implementation; the children are parsed in componentComplete instead
176 Q_UNUSED(list);
177 Q_UNUSED(element);
150 }
178 }
151
179
152 void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories)
180 void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories)
153 {
181 {
154 setCategories(categories);
182 setCategories(categories);
155 }
183 }
156
184
157 QStringList DeclarativeGroupedBarSeries::barCategories()
185 QStringList DeclarativeGroupedBarSeries::barCategories()
158 {
186 {
159 return categories();
187 return categories();
160 }
188 }
161
189
162 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
190 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
163 {
191 {
164 QList<QBarSet*> setList = barSets();
192 QList<QBarSet*> setList = barSets();
165 if (index < setList.count())
193 if (index < setList.count())
166 return qobject_cast<DeclarativeBarSet *>(setList[index]);
194 return qobject_cast<DeclarativeBarSet *>(setList[index]);
167
195
168 return 0;
196 return 0;
169 }
197 }
170
198
171 #include "moc_declarativebarseries.cpp"
199 #include "moc_declarativebarseries.cpp"
172
200
173 QTCOMMERCIALCHART_END_NAMESPACE
201 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,110 +1,110
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVEBARSERIES_H
21 #ifndef DECLARATIVEBARSERIES_H
22 #define DECLARATIVEBARSERIES_H
22 #define DECLARATIVEBARSERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include <QDeclarativeItem>
25 #include <QDeclarativeItem>
26 #include <QDeclarativeParserStatus>
26 #include <QDeclarativeParserStatus>
27 #include <QGroupedBarSeries>
27 #include <QGroupedBarSeries>
28 #include <QBarSet>
28 #include <QBarSet>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class QChart;
32 class QChart;
33
33
34 class DeclarativeBarSet : public QBarSet
34 class DeclarativeBarSet : public QBarSet
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37 Q_PROPERTY(QVariantList values READ values WRITE setValues)
37 Q_PROPERTY(QVariantList values READ values WRITE setValues)
38 Q_PROPERTY(QColor color READ color WRITE setColor)
38 Q_PROPERTY(QColor color READ color WRITE setColor)
39 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
39 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
40 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
40 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
41
41
42 public:
42 public:
43 explicit DeclarativeBarSet(QObject *parent = 0);
43 explicit DeclarativeBarSet(QObject *parent = 0);
44 QVariantList values();
44 QVariantList values();
45 void setValues(QVariantList values);
45 void setValues(QVariantList values);
46 QColor color();
46 QColor color();
47 void setColor(QColor color);
47 void setColor(QColor color);
48 QColor borderColor();
48 QColor borderColor();
49 void setBorderColor(QColor color);
49 void setBorderColor(QColor color);
50 QColor labelColor();
50 QColor labelColor();
51 void setLabelColor(QColor color);
51 void setLabelColor(QColor color);
52
52
53 public: // From QBarSet
53 public: // From QBarSet
54 Q_INVOKABLE void append(qreal value) { QBarSet::append(value); }
54 Q_INVOKABLE void append(qreal value) { QBarSet::append(value); }
55 Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); }
55 Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); }
56 };
56 };
57
57
58 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus
58 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus
59 {
59 {
60 Q_OBJECT
60 Q_OBJECT
61 Q_INTERFACES(QDeclarativeParserStatus)
61 Q_INTERFACES(QDeclarativeParserStatus)
62 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
62 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
63 Q_PROPERTY(QDeclarativeListProperty<DeclarativeBarSet> initialBarSets READ initialBarSets)
63 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
64 Q_CLASSINFO("DefaultProperty", "initialBarSets")
64 Q_CLASSINFO("DefaultProperty", "seriesChildren")
65
65
66 public:
66 public:
67 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
67 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
68 QDeclarativeListProperty<DeclarativeBarSet> initialBarSets();
68 QDeclarativeListProperty<QObject> seriesChildren();
69
69
70 void setBarCategories(QStringList categories);
70 void setBarCategories(QStringList categories);
71 QStringList barCategories();
71 QStringList barCategories();
72
72
73 Q_INVOKABLE DeclarativeBarSet *at(int index);
73 Q_INVOKABLE DeclarativeBarSet *at(int index);
74
74
75 public: // from QDeclarativeParserStatus
75 public: // from QDeclarativeParserStatus
76 void classBegin();
76 void classBegin();
77 void componentComplete();
77 void componentComplete();
78
78
79 public Q_SLOTS:
79 public Q_SLOTS:
80 static void appendInitialBarSets(QDeclarativeListProperty<DeclarativeBarSet> * /*list*/, DeclarativeBarSet * /*element*/) {}
80 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
81 };
81 };
82
82
83 class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus
83 class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus
84 {
84 {
85 Q_OBJECT
85 Q_OBJECT
86 Q_INTERFACES(QDeclarativeParserStatus)
86 Q_INTERFACES(QDeclarativeParserStatus)
87 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
87 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
88 Q_PROPERTY(QDeclarativeListProperty<DeclarativeBarSet> initialBarSets READ initialBarSets)
88 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
89 Q_CLASSINFO("DefaultProperty", "initialBarSets")
89 Q_CLASSINFO("DefaultProperty", "seriesChildren")
90
90
91 public:
91 public:
92 explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0);
92 explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0);
93 QDeclarativeListProperty<DeclarativeBarSet> initialBarSets();
93 QDeclarativeListProperty<QObject> seriesChildren();
94
94
95 void setBarCategories(QStringList categories);
95 void setBarCategories(QStringList categories);
96 QStringList barCategories();
96 QStringList barCategories();
97
97
98 Q_INVOKABLE DeclarativeBarSet *at(int index);
98 Q_INVOKABLE DeclarativeBarSet *at(int index);
99
99
100 public: // from QDeclarativeParserStatus
100 public: // from QDeclarativeParserStatus
101 void classBegin();
101 void classBegin();
102 void componentComplete();
102 void componentComplete();
103
103
104 public Q_SLOTS:
104 public Q_SLOTS:
105 static void appendInitialBarSets(QDeclarativeListProperty<DeclarativeBarSet> * /*list*/, DeclarativeBarSet * /*element*/) {}
105 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
106 };
106 };
107
107
108 QTCOMMERCIALCHART_END_NAMESPACE
108 QTCOMMERCIALCHART_END_NAMESPACE
109
109
110 #endif // DECLARATIVEBARSERIES_H
110 #endif // DECLARATIVEBARSERIES_H
@@ -1,92 +1,98
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 #include <QtDeclarative/qdeclarative.h>
22 #include <QtDeclarative/qdeclarative.h>
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qaxiscategories.h"
24 #include "qaxiscategories.h"
25 #include "declarativechart.h"
25 #include "declarativechart.h"
26 #include "declarativexypoint.h"
26 #include "declarativexypoint.h"
27 #include "declarativelineseries.h"
27 #include "declarativelineseries.h"
28 #include "declarativesplineseries.h"
28 #include "declarativesplineseries.h"
29 #include "declarativeareaseries.h"
29 #include "declarativeareaseries.h"
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 <QVXYModelMapper>
33 #include <QVXYModelMapper>
34 #include <QHXYModelMapper>
34 #include <QHXYModelMapper>
35 #include <QHPieModelMapper>
35 #include <QHPieModelMapper>
36 #include <QVPieModelMapper>
36 #include <QVPieModelMapper>
37 #include <QHBarModelMapper>
38 #include <QVBarModelMapper>
37
39
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
41
40 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
42 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
41 {
43 {
42 Q_OBJECT
44 Q_OBJECT
43 public:
45 public:
44 virtual void registerTypes(const char *uri)
46 virtual void registerTypes(const char *uri)
45 {
47 {
46 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
48 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
47
49
48 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
50 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
49 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
51 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
50 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
52 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
51 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
53 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
52 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
54 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
53 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
55 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
54 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
56 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
55 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
57 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
56 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
58 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
57 qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice");
59 qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice");
58 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
60 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
59 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
61 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
60 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
62 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
61 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
63 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
62 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
64 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
65 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
66 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
63
67
64
68
65 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
69 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
66 QLatin1String("Trying to create uncreatable: QScatterSeries."));
70 QLatin1String("Trying to create uncreatable: QScatterSeries."));
67 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
71 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
68 QLatin1String("Trying to create uncreatable: QPieSeries."));
72 QLatin1String("Trying to create uncreatable: QPieSeries."));
69 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
73 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
70 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
74 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
71 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
75 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
72 QLatin1String("Trying to create uncreatable: XYModelMapper."));
76 QLatin1String("Trying to create uncreatable: XYModelMapper."));
73 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
77 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
74 QLatin1String("Trying to create uncreatable: PieModelMapper."));
78 QLatin1String("Trying to create uncreatable: PieModelMapper."));
79 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
80 QLatin1String("Trying to create uncreatable: BarModelMapper."));
75 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
81 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
76 QLatin1String("Trying to create uncreatable: AbstractSeries."));
82 QLatin1String("Trying to create uncreatable: AbstractSeries."));
77 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
83 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
78 QLatin1String("Trying to create uncreatable: Axis."));
84 QLatin1String("Trying to create uncreatable: Axis."));
79 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
85 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
80 QLatin1String("Trying to create uncreatable: PieModelMapper."));
86 QLatin1String("Trying to create uncreatable: PieModelMapper."));
81 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
87 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
82 QLatin1String("Trying to create uncreatable: XYModelMapper."));
88 QLatin1String("Trying to create uncreatable: XYModelMapper."));
83 }
89 }
84 };
90 };
85
91
86 #include "plugin.moc"
92 #include "plugin.moc"
87
93
88 QTCOMMERCIALCHART_END_NAMESPACE
94 QTCOMMERCIALCHART_END_NAMESPACE
89
95
90 QTCOMMERCIALCHART_USE_NAMESPACE
96 QTCOMMERCIALCHART_USE_NAMESPACE
91
97
92 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
98 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,30 +1,31
1 #ifndef QHBARMODELMAPPER_H
1 #ifndef QHBARMODELMAPPER_H
2 #define QHBARMODELMAPPER_H
2 #define QHBARMODELMAPPER_H
3
3
4 #include <QBarModelMapper>
4 #include <QBarModelMapper>
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper
8 class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper
9 {
9 {
10 Q_OBJECT
10 Q_OBJECT
11 Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow)
11 Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow)
12 Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow)
12 Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow)
13 Q_PROPERTY(int categoriesRow READ categoriesRow WRITE setCategoriesRow)
13
14
14 public:
15 public:
15 explicit QHBarModelMapper(QObject *parent = 0);
16 explicit QHBarModelMapper(QObject *parent = 0);
16
17
17 int firstBarSetRow() const;
18 int firstBarSetRow() const;
18 void setFirstBarSetRow(int firstBarSetRow);
19 void setFirstBarSetRow(int firstBarSetRow);
19
20
20 int lastBarSetRow() const;
21 int lastBarSetRow() const;
21 void setLastBarSetRow(int lastBarSetRow);
22 void setLastBarSetRow(int lastBarSetRow);
22
23
23 int categoriesRow() const;
24 int categoriesRow() const;
24 void setCategoriesRow(int categoriesRow);
25 void setCategoriesRow(int categoriesRow);
25
26
26 };
27 };
27
28
28 QTCOMMERCIALCHART_END_NAMESPACE
29 QTCOMMERCIALCHART_END_NAMESPACE
29
30
30 #endif // QHBARMODELMAPPER_H
31 #endif // QHBARMODELMAPPER_H
@@ -1,30 +1,31
1 #ifndef QVBARMODELMAPPER_H
1 #ifndef QVBARMODELMAPPER_H
2 #define QVBARMODELMAPPER_H
2 #define QVBARMODELMAPPER_H
3
3
4 #include <QBarModelMapper>
4 #include <QBarModelMapper>
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper
8 class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper
9 {
9 {
10 Q_OBJECT
10 Q_OBJECT
11 Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn)
11 Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn)
12 Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn)
12 Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn)
13 Q_PROPERTY(int categoriesColumn READ categoriesColumn WRITE setCategoriesColumn)
13
14
14 public:
15 public:
15 explicit QVBarModelMapper(QObject *parent = 0);
16 explicit QVBarModelMapper(QObject *parent = 0);
16
17
17 int firstBarSetColumn() const;
18 int firstBarSetColumn() const;
18 void setFirstBarSetColumn(int firstBarSetColumn);
19 void setFirstBarSetColumn(int firstBarSetColumn);
19
20
20 int lastBarSetColumn() const;
21 int lastBarSetColumn() const;
21 void setLastBarSetColumn(int lastBarSetColumn);
22 void setLastBarSetColumn(int lastBarSetColumn);
22
23
23 int categoriesColumn() const;
24 int categoriesColumn() const;
24 void setCategoriesColumn(int categoriesColumn);
25 void setCategoriesColumn(int categoriesColumn);
25
26
26 };
27 };
27
28
28 QTCOMMERCIALCHART_END_NAMESPACE
29 QTCOMMERCIALCHART_END_NAMESPACE
29
30
30 #endif // QVBARMODELMAPPER_H
31 #endif // QVBARMODELMAPPER_H
@@ -1,582 +1,582
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "tablewidget.h"
21 #include "tablewidget.h"
22 #include <QGridLayout>
22 #include <QGridLayout>
23 #include <QTableView>
23 #include <QTableView>
24 #include <QChart>
24 #include <QChart>
25 #include <QStyledItemDelegate>
25 #include <QStyledItemDelegate>
26 #include <QLineSeries>
26 #include <QLineSeries>
27 #include <QSplineSeries>
27 #include <QSplineSeries>
28 #include <QScatterSeries>
28 #include <QScatterSeries>
29 #include <QVXYModelMapper>
29 #include <QVXYModelMapper>
30 #include <QHXYModelMapper>
30 #include <QHXYModelMapper>
31 #include "customtablemodel.h"
31 #include "customtablemodel.h"
32 #include <QPieSeries>
32 #include <QPieSeries>
33 #include <QVPieModelMapper>
33 #include <QVPieModelMapper>
34 #include <QPieSlice>
34 #include <QPieSlice>
35 #include <QAreaSeries>
35 #include <QAreaSeries>
36 #include <QBarSeries>
36 #include <QBarSeries>
37 #include <QGroupedBarSeries>
37 #include <QGroupedBarSeries>
38 #include <QBarSet>
38 #include <QBarSet>
39 #include <QVBarModelMapper>
39 #include <QVBarModelMapper>
40 #include <QPushButton>
40 #include <QPushButton>
41 #include <QRadioButton>
41 #include <QRadioButton>
42 #include <QLabel>
42 #include <QLabel>
43 #include <QSpinBox>
43 #include <QSpinBox>
44 #include <QTime>
44 #include <QTime>
45 #include <QHeaderView>
45 #include <QHeaderView>
46
46
47 TableWidget::TableWidget(QWidget *parent)
47 TableWidget::TableWidget(QWidget *parent)
48 : QWidget(parent),
48 : QWidget(parent),
49 m_series(0),
49 m_series(0),
50 m_mapper(0),
50 m_mapper(0),
51 m_model(0),
51 m_model(0),
52 m_pieMapper(0),
52 m_pieMapper(0),
53 m_pieMapper2(0)
53 m_pieMapper2(0)
54 // specialPie(0)
54 // specialPie(0)
55 {
55 {
56 setGeometry(1900, 100, 1000, 600);
56 setGeometry(1900, 100, 1000, 600);
57 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
57 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
58 // create simple model for storing data
58 // create simple model for storing data
59 // user's table data model
59 // user's table data model
60 m_model = new CustomTableModel;
60 m_model = new CustomTableModel;
61 m_tableView = new QTableView;
61 m_tableView = new QTableView;
62 m_tableView->setModel(m_model);
62 m_tableView->setModel(m_model);
63 // m_tableView->setMinimumHeight(300);
63 // m_tableView->setMinimumHeight(300);
64 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
64 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
65 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
65 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
66
66
67 m_chart = new QChart;
67 m_chart = new QChart;
68 m_chart->legend()->setVisible(true);
68 m_chart->legend()->setVisible(true);
69 m_chart->setAnimationOptions(QChart::SeriesAnimations);
69 m_chart->setAnimationOptions(QChart::SeriesAnimations);
70 m_chartView = new QChartView(m_chart);
70 m_chartView = new QChartView(m_chart);
71 m_chartView->setRenderHint(QPainter::Antialiasing);
71 m_chartView->setRenderHint(QPainter::Antialiasing);
72 m_chartView->setMinimumSize(640, 480);
72 m_chartView->setMinimumSize(640, 480);
73
73
74 // add, remove data buttons
74 // add, remove data buttons
75 QPushButton* addRowAboveButton = new QPushButton("Add row above");
75 QPushButton* addRowAboveButton = new QPushButton("Add row above");
76 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
76 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
77
77
78 QPushButton* addRowBelowButton = new QPushButton("Add row below");
78 QPushButton* addRowBelowButton = new QPushButton("Add row below");
79 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
79 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
80
80
81 QPushButton* removeRowButton = new QPushButton("Remove row");
81 QPushButton* removeRowButton = new QPushButton("Remove row");
82 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
82 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
83
83
84 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
84 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
85 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
85 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
86
86
87 QPushButton* removeColumnButton = new QPushButton("Remove column");
87 QPushButton* removeColumnButton = new QPushButton("Remove column");
88 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
88 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
89
89
90 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
90 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
91 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
91 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
92
92
93 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
93 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
94 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
94 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
95
95
96 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
96 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
97 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
97 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
98
98
99 QPushButton* xyTestButton = new QPushButton("Append XY point");
99 QPushButton* xyTestButton = new QPushButton("Append XY point");
100 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
100 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
101
101
102
102
103 QLabel *spinBoxLabel = new QLabel("Rows affected:");
103 QLabel *spinBoxLabel = new QLabel("Rows affected:");
104
104
105 // spin box for setting number of affected items (add, remove)
105 // spin box for setting number of affected items (add, remove)
106 m_linesCountSpinBox = new QSpinBox;
106 m_linesCountSpinBox = new QSpinBox;
107 m_linesCountSpinBox->setRange(1, 10);
107 m_linesCountSpinBox->setRange(1, 10);
108 m_linesCountSpinBox->setValue(1);
108 m_linesCountSpinBox->setValue(1);
109
109
110 // buttons layout
110 // buttons layout
111 QVBoxLayout* buttonsLayout = new QVBoxLayout;
111 QVBoxLayout* buttonsLayout = new QVBoxLayout;
112 buttonsLayout->addWidget(spinBoxLabel);
112 buttonsLayout->addWidget(spinBoxLabel);
113 buttonsLayout->addWidget(m_linesCountSpinBox);
113 buttonsLayout->addWidget(m_linesCountSpinBox);
114 // buttonsLayout->addWidget(addRowAboveButton);
114 // buttonsLayout->addWidget(addRowAboveButton);
115 buttonsLayout->addWidget(addRowBelowButton);
115 buttonsLayout->addWidget(addRowBelowButton);
116 buttonsLayout->addWidget(removeRowButton);
116 buttonsLayout->addWidget(removeRowButton);
117 // buttonsLayout->addWidget(addColumnRightButton);
117 // buttonsLayout->addWidget(addColumnRightButton);
118 // buttonsLayout->addWidget(removeColumnButton);
118 // buttonsLayout->addWidget(removeColumnButton);
119 buttonsLayout->addWidget(specialPieButton);
119 buttonsLayout->addWidget(specialPieButton);
120 buttonsLayout->addWidget(specialPieButton2);
120 buttonsLayout->addWidget(specialPieButton2);
121 buttonsLayout->addWidget(specialPieButton3);
121 buttonsLayout->addWidget(specialPieButton3);
122 buttonsLayout->addWidget(xyTestButton);
122 buttonsLayout->addWidget(xyTestButton);
123 buttonsLayout->addStretch();
123 buttonsLayout->addStretch();
124
124
125 // chart type radio buttons
125 // chart type radio buttons
126 m_lineRadioButton = new QRadioButton("Line");
126 m_lineRadioButton = new QRadioButton("Line");
127 m_splineRadioButton = new QRadioButton("Spline");
127 m_splineRadioButton = new QRadioButton("Spline");
128 m_scatterRadioButton = new QRadioButton("Scatter");
128 m_scatterRadioButton = new QRadioButton("Scatter");
129 m_pieRadioButton = new QRadioButton("Pie");
129 m_pieRadioButton = new QRadioButton("Pie");
130 m_areaRadioButton = new QRadioButton("Area");
130 m_areaRadioButton = new QRadioButton("Area");
131 m_barRadioButton = new QRadioButton("Bar");
131 m_barRadioButton = new QRadioButton("Bar");
132
132
133 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
133 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
134 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
134 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
135 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
135 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
138 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
138 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
139 m_lineRadioButton->setChecked(true);
139 m_lineRadioButton->setChecked(true);
140
140
141 // radio buttons layout
141 // radio buttons layout
142 QVBoxLayout* radioLayout = new QVBoxLayout;
142 QVBoxLayout* radioLayout = new QVBoxLayout;
143 radioLayout->addWidget(m_lineRadioButton);
143 radioLayout->addWidget(m_lineRadioButton);
144 radioLayout->addWidget(m_splineRadioButton);
144 radioLayout->addWidget(m_splineRadioButton);
145 radioLayout->addWidget(m_scatterRadioButton);
145 radioLayout->addWidget(m_scatterRadioButton);
146 radioLayout->addWidget(m_pieRadioButton);
146 radioLayout->addWidget(m_pieRadioButton);
147 // radioLayout->addWidget(m_areaRadioButton);
147 // radioLayout->addWidget(m_areaRadioButton);
148 radioLayout->addWidget(m_barRadioButton);
148 radioLayout->addWidget(m_barRadioButton);
149 radioLayout->addStretch();
149 radioLayout->addStretch();
150
150
151 // create main layout
151 // create main layout
152 QGridLayout* mainLayout = new QGridLayout;
152 QGridLayout* mainLayout = new QGridLayout;
153 mainLayout->addLayout(buttonsLayout, 2, 0);
153 mainLayout->addLayout(buttonsLayout, 2, 0);
154 mainLayout->addLayout(radioLayout, 3, 0);
154 mainLayout->addLayout(radioLayout, 3, 0);
155 mainLayout->addWidget(m_tableView, 1, 0);
155 mainLayout->addWidget(m_tableView, 1, 0);
156 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
156 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
157 setLayout(mainLayout);
157 setLayout(mainLayout);
158 m_lineRadioButton->setFocus();
158 m_lineRadioButton->setFocus();
159 }
159 }
160
160
161 void TableWidget::addRowAbove()
161 void TableWidget::addRowAbove()
162 {
162 {
163 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
163 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
164
164
165 }
165 }
166
166
167 void TableWidget::addRowBelow()
167 void TableWidget::addRowBelow()
168 {
168 {
169 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
169 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
170
170
171 }
171 }
172
172
173 void TableWidget::removeRow()
173 void TableWidget::removeRow()
174 {
174 {
175 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
175 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
176 }
176 }
177
177
178 void TableWidget::addColumnRight()
178 void TableWidget::addColumnRight()
179 {
179 {
180 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
180 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
181 }
181 }
182
182
183 void TableWidget::removeColumn()
183 void TableWidget::removeColumn()
184 {
184 {
185 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
185 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
186 }
186 }
187
187
188 void TableWidget::updateChartType(bool toggle)
188 void TableWidget::updateChartType(bool toggle)
189 {
189 {
190 // this if is needed, so that the function is only called once.
190 // this if is needed, so that the function is only called once.
191 // For the radioButton that was enabled.
191 // For the radioButton that was enabled.
192 if (toggle) {
192 if (toggle) {
193 // specialPie = 0;
193 // specialPie = 0;
194 m_chart->removeAllSeries();
194 m_chart->removeAllSeries();
195 m_series = 0;
195 m_series = 0;
196 // m_chart->axisX()->setNiceNumbersEnabled(false);
196 // m_chart->axisX()->setNiceNumbersEnabled(false);
197 // m_chart->axisY()->setNiceNumbersEnabled(false);
197 // m_chart->axisY()->setNiceNumbersEnabled(false);
198 if (m_mapper) {
198 if (m_mapper) {
199 m_mapper->deleteLater();
199 m_mapper->deleteLater();
200 m_mapper = 0;
200 m_mapper = 0;
201 }
201 }
202
202
203 if (m_pieMapper) {
203 if (m_pieMapper) {
204 m_pieMapper->deleteLater();
204 m_pieMapper->deleteLater();
205 m_pieMapper = 0;
205 m_pieMapper = 0;
206 }
206 }
207
207
208 if (m_pieMapper2) {
208 if (m_pieMapper2) {
209 m_pieMapper2->deleteLater();
209 m_pieMapper2->deleteLater();
210 m_pieMapper2 = 0;
210 m_pieMapper2 = 0;
211 }
211 }
212
212
213 // if (m_series) {
213 // if (m_series) {
214 // delete m_series;
214 // delete m_series;
215 // m_series = 0;
215 // m_series = 0;
216 // }
216 // }
217
217
218 // renable axes of the chart (pie hides them)
218 // renable axes of the chart (pie hides them)
219 // x axis
219 // x axis
220 QAxis *axis = m_chart->axisX();
220 QAxis *axis = m_chart->axisX();
221 axis->setAxisVisible(true);
221 axis->setAxisVisible(true);
222 axis->setGridLineVisible(true);
222 axis->setGridLineVisible(true);
223 axis->setLabelsVisible(true);
223 axis->setLabelsVisible(true);
224
224
225 // y axis
225 // y axis
226 axis = m_chart->axisY();
226 axis = m_chart->axisY();
227 axis->setAxisVisible(true);
227 axis->setAxisVisible(true);
228 axis->setGridLineVisible(true);
228 axis->setGridLineVisible(true);
229 axis->setLabelsVisible(true);
229 axis->setLabelsVisible(true);
230
230
231 m_model->clearMapping();
231 m_model->clearMapping();
232
232
233 QString seriesColorHex = "#000000";
233 QString seriesColorHex = "#000000";
234 // QPen pen;
234 // QPen pen;
235 // pen.setWidth(2);
235 // pen.setWidth(2);
236
236
237 if (m_lineRadioButton->isChecked())
237 if (m_lineRadioButton->isChecked())
238 {
238 {
239 m_chart->setAnimationOptions(QChart::NoAnimation);
239 m_chart->setAnimationOptions(QChart::NoAnimation);
240
240
241 // series 1
241 // series 1
242 m_series = new QLineSeries;
242 m_series = new QLineSeries;
243
243
244 m_mapper = new QHXYModelMapper;
244 m_mapper = new QHXYModelMapper;
245 m_mapper->setModel(m_model);
245 m_mapper->setModel(m_model);
246 m_mapper->setSeries(m_series);
246 m_mapper->setSeries(m_series);
247 m_mapper->setXRow(0);
247 m_mapper->setXRow(0);
248 m_mapper->setYRow(1);
248 m_mapper->setYRow(1);
249 m_mapper->setFirst(3);
249 m_mapper->setFirst(3);
250 m_mapper->setCount(4);
250 m_mapper->setCount(4);
251
251
252 // m_mapper = new QVXYModelMapper;
252 // m_mapper = new QVXYModelMapper;
253 // m_mapper->setModel(m_model);
253 // m_mapper->setModel(m_model);
254 // m_mapper->setSeries(m_series);
254 // m_mapper->setSeries(m_series);
255 // m_mapper->setXColumn(0);
255 // m_mapper->setXColumn(0);
256 // m_mapper->setYColumn(1);
256 // m_mapper->setYColumn(1);
257 // m_mapper->setFirst(3);
257 // m_mapper->setFirst(3);
258 // m_mapper->setCount(4);
258 // m_mapper->setCount(4);
259
259
260 // m_series->setModelMapping(0,1, Qt::Vertical);
260 // m_series->setModelMapping(0,1, Qt::Vertical);
261 // m_series->setModelMappingRange(3, 4);
261 // m_series->setModelMappingRange(3, 4);
262 m_chart->addSeries(m_series);
262 m_chart->addSeries(m_series);
263 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
263 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
264 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
264 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
265
265
266 // // series 2
266 // // series 2
267 // m_series = new QLineSeries;
267 // m_series = new QLineSeries;
268 // m_series->setModel(m_model);
268 // m_series->setModel(m_model);
269
269
270 // mapper = new QXYModelMapper;
270 // mapper = new QXYModelMapper;
271 // mapper->setMapX(3);
271 // mapper->setMapX(3);
272 // mapper->setMapY(4);
272 // mapper->setMapY(4);
273 // // mapper->setFirst(3);
273 // // mapper->setFirst(3);
274 // // mapper->setCount(4);
274 // // mapper->setCount(4);
275 // m_series->setModelMapper(mapper);
275 // m_series->setModelMapper(mapper);
276 // // m_series->setModelMapping(2,3, Qt::Vertical);
276 // // m_series->setModelMapping(2,3, Qt::Vertical);
277 // m_chart->addSeries(m_series);
277 // m_chart->addSeries(m_series);
278 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
278 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
279 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
279 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
280
280
281 // // series 3
281 // // series 3
282 // m_series = new QLineSeries;
282 // m_series = new QLineSeries;
283 // m_series->setModel(m_model);
283 // m_series->setModel(m_model);
284
284
285 // mapper = new QXYModelMapper;
285 // mapper = new QXYModelMapper;
286 // mapper->setMapX(5);
286 // mapper->setMapX(5);
287 // mapper->setMapY(6);
287 // mapper->setMapY(6);
288 // mapper->setFirst(2);
288 // mapper->setFirst(2);
289 // mapper->setCount(-1);
289 // mapper->setCount(-1);
290 // m_series->setModelMapper(mapper);
290 // m_series->setModelMapper(mapper);
291 // // m_series->setModelMapping(4,5, Qt::Vertical);
291 // // m_series->setModelMapping(4,5, Qt::Vertical);
292 // // m_series->setModelMappingRange(2, -1);
292 // // m_series->setModelMappingRange(2, -1);
293 // m_chart->addSeries(m_series);
293 // m_chart->addSeries(m_series);
294 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
294 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
295 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
295 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
296 }
296 }
297 else if (m_splineRadioButton->isChecked())
297 else if (m_splineRadioButton->isChecked())
298 {
298 {
299 m_chart->setAnimationOptions(QChart::NoAnimation);
299 m_chart->setAnimationOptions(QChart::NoAnimation);
300
300
301 // series 1
301 // series 1
302 m_series = new QSplineSeries;
302 m_series = new QSplineSeries;
303 // m_series->setModel(m_model);
303 // m_series->setModel(m_model);
304
304
305 // m_mapper = new QVXYModelMapper;
305 // m_mapper = new QVXYModelMapper;
306 // m_mapper->setSeries(m_series);
306 // m_mapper->setSeries(m_series);
307 // m_mapper->setModel(m_model);
307 // m_mapper->setModel(m_model);
308 // m_mapper->setXColumn(0);
308 // m_mapper->setXColumn(0);
309 // m_mapper->setYColumn(1);
309 // m_mapper->setYColumn(1);
310 // m_mapper->setFirst(0);
310 // m_mapper->setFirst(0);
311 // m_mapper->setCount(-1);
311 // m_mapper->setCount(-1);
312
312
313 // m_series->setModelMapper(mapper);
313 // m_series->setModelMapper(mapper);
314
314
315 m_chart->addSeries(m_series);
315 m_chart->addSeries(m_series);
316 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
316 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
317 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
317 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
318
318
319 // // series 2
319 // // series 2
320 // m_series = new QSplineSeries;
320 // m_series = new QSplineSeries;
321 // m_series->setModel(m_model);
321 // m_series->setModel(m_model);
322
322
323 // mapper = new QXYModelMapper;
323 // mapper = new QXYModelMapper;
324 // mapper->setMapX(2);
324 // mapper->setMapX(2);
325 // mapper->setMapY(3);
325 // mapper->setMapY(3);
326 // mapper->setFirst(2);
326 // mapper->setFirst(2);
327 // mapper->setCount(4);
327 // mapper->setCount(4);
328
328
329 // m_series->setModelMapper(mapper);
329 // m_series->setModelMapper(mapper);
330
330
331 // m_chart->addSeries(m_series);
331 // m_chart->addSeries(m_series);
332 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
332 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
333 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
333 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
334
334
335 // // series 3
335 // // series 3
336 // m_series = new QSplineSeries;
336 // m_series = new QSplineSeries;
337 // m_series->setModel(m_model);
337 // m_series->setModel(m_model);
338
338
339 // mapper = new QXYModelMapper;
339 // mapper = new QXYModelMapper;
340 // mapper->setMapX(4);
340 // mapper->setMapX(4);
341 // mapper->setMapY(5);
341 // mapper->setMapY(5);
342 // mapper->setFirst(2);
342 // mapper->setFirst(2);
343 // mapper->setCount(-1);
343 // mapper->setCount(-1);
344
344
345 // m_series->setModelMapper(mapper);
345 // m_series->setModelMapper(mapper);
346
346
347 // m_chart->addSeries(m_series);
347 // m_chart->addSeries(m_series);
348 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
348 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
349 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
349 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
350 } else if (m_scatterRadioButton->isChecked())
350 } else if (m_scatterRadioButton->isChecked())
351 {
351 {
352 m_chart->setAnimationOptions(QChart::NoAnimation);
352 m_chart->setAnimationOptions(QChart::NoAnimation);
353
353
354 // series 1
354 // series 1
355 m_series = new QScatterSeries;
355 m_series = new QScatterSeries;
356
356
357 // m_mapper = new QVXYModelMapper;
357 // m_mapper = new QVXYModelMapper;
358 // m_mapper->setSeries(m_series);
358 // m_mapper->setSeries(m_series);
359 // m_mapper->setModel(m_model);
359 // m_mapper->setModel(m_model);
360 // m_mapper->setXColumn(0);
360 // m_mapper->setXColumn(0);
361 // m_mapper->setYColumn(1);
361 // m_mapper->setYColumn(1);
362 // m_mapper->setFirst(0);
362 // m_mapper->setFirst(0);
363 // m_mapper->setCount(-1);
363 // m_mapper->setCount(-1);
364
364
365 m_chart->addSeries(m_series);
365 m_chart->addSeries(m_series);
366 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
366 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
367 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
367 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
368
368
369 // // series 2
369 // // series 2
370 // m_series = new QScatterSeries;
370 // m_series = new QScatterSeries;
371 // m_series->setModel(m_model);
371 // m_series->setModel(m_model);
372 // m_series->setModelMapping(2,3, Qt::Vertical);
372 // m_series->setModelMapping(2,3, Qt::Vertical);
373 // // m_series->setModelMappingRange(1, 6);
373 // // m_series->setModelMappingRange(1, 6);
374 // // series->setModelMapping(2,3, Qt::Horizontal);
374 // // series->setModelMapping(2,3, Qt::Horizontal);
375 // m_chart->addSeries(m_series);
375 // m_chart->addSeries(m_series);
376
376
377 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
377 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
378 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
378 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
379
379
380 // // series 3
380 // // series 3
381 // m_series = new QScatterSeries;
381 // m_series = new QScatterSeries;
382 // m_series->setModel(m_model);
382 // m_series->setModel(m_model);
383 // m_series->setModelMapping(4,5, Qt::Vertical);
383 // m_series->setModelMapping(4,5, Qt::Vertical);
384 // // series->setModelMapping(4,5, Qt::Horizontal);
384 // // series->setModelMapping(4,5, Qt::Horizontal);
385 // m_chart->addSeries(m_series);
385 // m_chart->addSeries(m_series);
386 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
386 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
387 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
387 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
388 } else if (m_pieRadioButton->isChecked()) {
388 } else if (m_pieRadioButton->isChecked()) {
389 m_chart->setAnimationOptions(QChart::SeriesAnimations);
389 m_chart->setAnimationOptions(QChart::SeriesAnimations);
390
390
391 // pie 1
391 // pie 1
392 m_pieSeries = new QPieSeries;
392 m_pieSeries = new QPieSeries;
393
393
394 m_pieMapper = new QVPieModelMapper;
394 m_pieMapper = new QVPieModelMapper;
395 m_pieMapper->setValuesColumn(1);
395 m_pieMapper->setValuesColumn(1);
396 m_pieMapper->setLabelsColumn(7);
396 m_pieMapper->setLabelsColumn(7);
397 m_pieMapper->setSeries(m_pieSeries);
397 m_pieMapper->setSeries(m_pieSeries);
398 m_pieMapper->setModel(m_model);
398 m_pieMapper->setModel(m_model);
399 m_pieMapper->setFirst(2);
399 m_pieMapper->setFirst(2);
400 // m_pieMapper->setCount(5);
400 // m_pieMapper->setCount(5);
401 // pieSeries->setModelMapper(mapper);
401 // pieSeries->setModelMapper(mapper);
402
402
403 m_pieSeries->setLabelsVisible(true);
403 m_pieSeries->setLabelsVisible(true);
404 m_pieSeries->setPieSize(0.35);
404 m_pieSeries->setPieSize(0.35);
405 m_pieSeries->setHorizontalPosition(0.25);
405 m_pieSeries->setHorizontalPosition(0.25);
406 m_pieSeries->setVerticalPosition(0.35);
406 m_pieSeries->setVerticalPosition(0.35);
407
407
408 m_chart->addSeries(m_pieSeries);
408 m_chart->addSeries(m_pieSeries);
409 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
409 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
410 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
410 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
411
411
412
412
413 // pieSeries->slices().at(0)->setValue(400);
413 // pieSeries->slices().at(0)->setValue(400);
414 // pieSeries->slices().at(0)->setLabel(QString("36"));
414 // pieSeries->slices().at(0)->setLabel(QString("36"));
415
415
416 // pie 2
416 // pie 2
417 m_pieSeries2 = new QPieSeries;
417 m_pieSeries2 = new QPieSeries;
418
418
419 m_pieMapper2 = new QVPieModelMapper;
419 m_pieMapper2 = new QVPieModelMapper;
420 m_pieMapper2->setValuesColumn(0);
420 m_pieMapper2->setValuesColumn(0);
421 m_pieMapper2->setLabelsColumn(7);
421 m_pieMapper2->setLabelsColumn(7);
422 m_pieMapper2->setModel(m_model);
422 m_pieMapper2->setModel(m_model);
423 m_pieMapper2->setSeries(m_pieSeries2);
423 m_pieMapper2->setSeries(m_pieSeries2);
424 m_pieMapper2->setFirst(2);
424 m_pieMapper2->setFirst(2);
425
425
426 m_pieSeries2->setLabelsVisible(true);
426 m_pieSeries2->setLabelsVisible(true);
427 m_pieSeries2->setPieSize(0.35);
427 m_pieSeries2->setPieSize(0.35);
428 m_pieSeries2->setHorizontalPosition(0.75);
428 m_pieSeries2->setHorizontalPosition(0.75);
429 m_pieSeries2->setVerticalPosition(0.65);
429 m_pieSeries2->setVerticalPosition(0.65);
430 m_chart->addSeries(m_pieSeries2);
430 m_chart->addSeries(m_pieSeries2);
431 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
431 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
432 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
432 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
433
433
434 // // pie 3
434 // // pie 3
435 // pieSeries = new QPieSeries;
435 // pieSeries = new QPieSeries;
436 // pieSeries->setModel(m_model);
436 // pieSeries->setModel(m_model);
437 // pieSeries->setModelMapping(2,2, Qt::Vertical);
437 // pieSeries->setModelMapping(2,2, Qt::Vertical);
438 // pieSeries->setLabelsVisible(true);
438 // pieSeries->setLabelsVisible(true);
439 // pieSeries->setPieSize(0.35);
439 // pieSeries->setPieSize(0.35);
440 // pieSeries->setHorizontalPosition(0.5);
440 // pieSeries->setHorizontalPosition(0.5);
441 // pieSeries->setVerticalPosition(0.75);
441 // pieSeries->setVerticalPosition(0.75);
442 // m_chart->addSeries(pieSeries);
442 // m_chart->addSeries(pieSeries);
443 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
443 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
444 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
444 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
445
445
446 // // special pie
446 // // special pie
447 // specialPie = new QPieSeries;
447 // specialPie = new QPieSeries;
448 // specialPie->append(17, "1");
448 // specialPie->append(17, "1");
449 // specialPie->append(45, "2");
449 // specialPie->append(45, "2");
450 // specialPie->append(77, "3");
450 // specialPie->append(77, "3");
451 // specialPie->append(37, "4");
451 // specialPie->append(37, "4");
452 // specialPie->append(27, "5");
452 // specialPie->append(27, "5");
453 // specialPie->append(47, "6");
453 // specialPie->append(47, "6");
454 // specialPie->setPieSize(0.35);
454 // specialPie->setPieSize(0.35);
455 // specialPie->setHorizontalPosition(0.8);
455 // specialPie->setHorizontalPosition(0.8);
456 // specialPie->setVerticalPosition(0.75);
456 // specialPie->setVerticalPosition(0.75);
457 // specialPie->setLabelsVisible(true);
457 // specialPie->setLabelsVisible(true);
458 // m_chart->addSeries(specialPie);
458 // m_chart->addSeries(specialPie);
459 }
459 }
460 // else if (m_areaRadioButton->isChecked())
460 // else if (m_areaRadioButton->isChecked())
461 // {
461 // {
462 // m_chart->setAnimationOptions(QChart::NoAnimation);
462 // m_chart->setAnimationOptions(QChart::NoAnimation);
463
463
464 // QLineSeries* upperLineSeries = new QLineSeries;
464 // QLineSeries* upperLineSeries = new QLineSeries;
465 // upperLineSeries->setModel(m_model);
465 // upperLineSeries->setModel(m_model);
466 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
466 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
467 // // upperLineSeries->setModelMappingRange(1, 5);
467 // // upperLineSeries->setModelMappingRange(1, 5);
468 // QLineSeries* lowerLineSeries = new QLineSeries;
468 // QLineSeries* lowerLineSeries = new QLineSeries;
469 // lowerLineSeries->setModel(m_model);
469 // lowerLineSeries->setModel(m_model);
470 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
470 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
471 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
471 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
472 // m_chart->addSeries(areaSeries);
472 // m_chart->addSeries(areaSeries);
473 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
473 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
474 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
474 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
475 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
475 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
476 // }
476 // }
477 else if (m_barRadioButton->isChecked())
477 else if (m_barRadioButton->isChecked())
478 {
478 {
479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
480
480
481 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
481 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
482 // barSeries->setCategories(QStringList());
482 // barSeries->setCategories(QStringList());
483 // barSeries->setModel(m_model);
483 // barSeries->setModel(m_model);
484 // barSeries->setModelMappingRange(2, 5);
484 // barSeries->setModelMappingRange(2, 5);
485 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
485 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
486
486
487 int first = 3;
487 int first = 3;
488 // int count = 4;
488 // int count = 4;
489 QVBarModelMapper *mapper = new QVBarModelMapper;
489 QVBarModelMapper *mapper = new QVBarModelMapper;
490 mapper->setCategoriesSection(5);
490 mapper->setCategoriesSection(5);
491 mapper->setFirstBarSection(2);
491 mapper->setFirstBarSetSection(2);
492 mapper->setLastBarSection(4);
492 mapper->setLastBarSetSection(4);
493 mapper->setFirst(first);
493 mapper->setFirst(first);
494 // mapper->setCount(count);
494 // mapper->setCount(count);
495 mapper->setSeries(barSeries);
495 mapper->setSeries(barSeries);
496 mapper->setModel(m_model);
496 mapper->setModel(m_model);
497 // barSeries->setModelMapper(mapper);
497 // barSeries->setModelMapper(mapper);
498 m_chart->addSeries(barSeries);
498 m_chart->addSeries(barSeries);
499 QList<QBarSet*> barsets = barSeries->barSets();
499 QList<QBarSet*> barsets = barSeries->barSets();
500 for (int i = 0; i < barsets.count(); i++) {
500 for (int i = 0; i < barsets.count(); i++) {
501 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
501 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
502 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
502 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
503 }
503 }
504 }
504 }
505
505
506
506
507 if (!m_barRadioButton->isChecked()) {
507 if (!m_barRadioButton->isChecked()) {
508 m_chart->axisX()->setRange(0, 500);
508 m_chart->axisX()->setRange(0, 500);
509 m_chart->axisY()->setRange(0, 220);
509 m_chart->axisY()->setRange(0, 220);
510 }
510 }
511 m_chart->legend()->setVisible(true);
511 m_chart->legend()->setVisible(true);
512
512
513 // repaint table view colors
513 // repaint table view colors
514 m_tableView->repaint();
514 m_tableView->repaint();
515 m_tableView->setFocus();
515 m_tableView->setFocus();
516 }
516 }
517 }
517 }
518
518
519 void TableWidget::testPie()
519 void TableWidget::testPie()
520 {
520 {
521 // m_pieMapper->setCount(-1);
521 // m_pieMapper->setCount(-1);
522 QPieSlice *slice = new QPieSlice("Hehe", 145);
522 QPieSlice *slice = new QPieSlice("Hehe", 145);
523 slice->setLabelVisible();
523 slice->setLabelVisible();
524 m_pieSeries->append(slice);
524 m_pieSeries->append(slice);
525
525
526 slice = new QPieSlice("Hoho", 34);
526 slice = new QPieSlice("Hoho", 34);
527 slice->setLabelVisible();
527 slice->setLabelVisible();
528 m_pieSeries->append(slice);
528 m_pieSeries->append(slice);
529 // m_series->modelMapper()->setMapX(4);
529 // m_series->modelMapper()->setMapX(4);
530 // m_tableView->setColumnWidth(10, 250);
530 // m_tableView->setColumnWidth(10, 250);
531 // if (specialPie) {
531 // if (specialPie) {
532 // specialPie->remove(specialPie->slices().at(2));
532 // specialPie->remove(specialPie->slices().at(2));
533 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
533 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
534 // specialPie->append(4, "heloo");
534 // specialPie->append(4, "heloo");
535 // }
535 // }
536 }
536 }
537
537
538 void TableWidget::testPie2()
538 void TableWidget::testPie2()
539 {
539 {
540 QPieSlice *slice;
540 QPieSlice *slice;
541 if (m_pieSeries->count() > 0) {
541 if (m_pieSeries->count() > 0) {
542 slice = m_pieSeries->slices().last();
542 slice = m_pieSeries->slices().last();
543 m_pieSeries->remove(slice);
543 m_pieSeries->remove(slice);
544 }
544 }
545
545
546 if (m_pieSeries->count() > 0) {
546 if (m_pieSeries->count() > 0) {
547 slice = m_pieSeries->slices().first();
547 slice = m_pieSeries->slices().first();
548 m_pieSeries->remove(slice);
548 m_pieSeries->remove(slice);
549 }
549 }
550 }
550 }
551
551
552 void TableWidget::testPie3()
552 void TableWidget::testPie3()
553 {
553 {
554 QPieSlice *slice;
554 QPieSlice *slice;
555 if (m_pieSeries->count() > 0) {
555 if (m_pieSeries->count() > 0) {
556 slice = m_pieSeries->slices().last();
556 slice = m_pieSeries->slices().last();
557 slice->setLabel("Dalej");
557 slice->setLabel("Dalej");
558 slice->setValue(222);
558 slice->setValue(222);
559 }
559 }
560
560
561 if (m_pieSeries->count() > 0) {
561 if (m_pieSeries->count() > 0) {
562 slice = m_pieSeries->slices().first();
562 slice = m_pieSeries->slices().first();
563 slice->setLabel("Prawie");
563 slice->setLabel("Prawie");
564 slice->setValue(111);
564 slice->setValue(111);
565 }
565 }
566 }
566 }
567
567
568 void TableWidget::testXY()
568 void TableWidget::testXY()
569 {
569 {
570 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
570 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
571 // m_series->append(QPointF(150, 75));
571 // m_series->append(QPointF(150, 75));
572 // }
572 // }
573
573
574 if (m_series->count() > 0) {
574 if (m_series->count() > 0) {
575 m_series->remove(m_series->points().last());
575 m_series->remove(m_series->points().last());
576 }
576 }
577 }
577 }
578
578
579 TableWidget::~TableWidget()
579 TableWidget::~TableWidget()
580 {
580 {
581
581
582 }
582 }
General Comments 0
You need to be logged in to leave comments. Login now