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