@@ -1,9 +1,7 | |||
|
1 | 1 | include(compat.qdocconf) |
|
2 | 2 | include(macros.qdocconf) |
|
3 | 3 | include(qchart-html-template.qdocconf) |
|
4 | 4 | include(qchart-qch.qdocconf) |
|
5 | 5 | include(qcharts.qdocconf) |
|
6 | 6 | |
|
7 | outputdir = ../html | |
|
8 | imagedirs = ../images | |
|
9 | 7 | sourcedirs += ../src_qt4 |
@@ -1,9 +1,15 | |||
|
1 | 1 | include(macros.qdocconf) |
|
2 | 2 | include(qchart-html-template.qdocconf) |
|
3 | 3 | include(qchart-qch.qdocconf) |
|
4 | 4 | include(qcharts.qdocconf) |
|
5 | 5 | |
|
6 | 6 | defines = QDOC_QT5 |
|
7 | outputdir = ../html | |
|
8 | imagedirs = ../../images | |
|
7 | sourcedirs += ../../ | |
|
8 | ||
|
9 | #excludedirs for Windows and Linux | |
|
9 | 10 | excludedirs += ../src_qt4 |
|
11 | #excludefiles for Mac | |
|
12 | excludefiles += ../src_qt4/demos.qdoc \ | |
|
13 | ../src_qt4/examples.qdoc \ | |
|
14 | ../src_qt4/index.qdoc \ | |
|
15 | ../src_qt4/qml.qdoc |
@@ -1,40 +1,43 | |||
|
1 | 1 | project = Qt Charts |
|
2 | 2 | description = Library for creating charts |
|
3 | 3 | version = 1.3.1 |
|
4 | 4 | |
|
5 | 5 | sourcedirs = ../../src \ |
|
6 | 6 | ../../examples \ |
|
7 | 7 | ../src \ |
|
8 | 8 | ../qch \ |
|
9 | 9 | ../../plugins/declarative |
|
10 | 10 | headerdirs = ../../src \ |
|
11 | 11 | ../../examples \ |
|
12 | 12 | ../../plugins/declarative |
|
13 | 13 | exampledirs = ../../ \ |
|
14 | 14 | ../../src \ |
|
15 | 15 | ../../examples |
|
16 | 16 | |
|
17 | outputdir = ../html | |
|
18 | imagedirs = ../images | |
|
19 | ||
|
17 | 20 | sources.fileextensions = *.cpp *.qdoc *.mm *.qml *.qdocinc |
|
18 | 21 | headers.fileextensions = *.h *.ch *.h++ *.hh *.hpp *.hxx |
|
19 | 22 | examples.fileextensions = *.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml |
|
20 | 23 | examples.imageextensions = *.png *.jpeg *.jpg *.gif *.mng |
|
21 | 24 | |
|
22 | 25 | Cpp.ignoretokens = QTCOMMERCIALCHART_EXPORT \ |
|
23 | 26 | QTCOMMERCIALCHART_END_NAMESPACE \ |
|
24 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 28 | Cpp.ignoredirectives = Q_DECLARE_HANDLE \ |
|
26 | 29 | Q_DECLARE_INTERFACE \ |
|
27 | 30 | Q_DECLARE_METATYPE \ |
|
28 | 31 | Q_DECLARE_OPERATORS_FOR_FLAGS \ |
|
29 | 32 | Q_DECLARE_PRIVATE \ |
|
30 | 33 | Q_DECLARE_PUBLIC \ |
|
31 | 34 | Q_DECLARE_SHARED \ |
|
32 | 35 | Q_DECLARE_TR_FUNCTIONS \ |
|
33 | 36 | Q_DECLARE_TYPEINFO \ |
|
34 | 37 | Q_DISABLE_COPY \ |
|
35 | 38 | QT_FORWARD_DECLARE_CLASS \ |
|
36 | 39 | Q_DUMMY_COMPARISON_OPERATOR \ |
|
37 | 40 | Q_ENUMS \ |
|
38 | 41 | Q_FLAGS \ |
|
39 | 42 | Q_INTERFACES \ |
|
40 | 43 | __attribute__ |
@@ -1,339 +1,339 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "declarativeboxplotseries.h" |
|
23 | 23 | #include "qboxset.h" |
|
24 | 24 | #include "qvboxplotmodelmapper.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | #ifdef QDOC_QT5 |
|
29 | 29 | /*! |
|
30 | 30 | \qmltype BoxSet |
|
31 | 31 | \instantiates QBoxSet |
|
32 | 32 | \inqmlmodule QtCommercial.Chart |
|
33 | 33 | |
|
34 |
\include |
|
|
34 | \include doc/src/declarativeboxset.qdocinc | |
|
35 | 35 | */ |
|
36 | 36 | #else |
|
37 | 37 | /*! |
|
38 | 38 | \qmlclass BoxSet QBoxSet |
|
39 | 39 | |
|
40 | 40 | \include ../doc/src/declarativeboxset.qdocinc |
|
41 | 41 | */ |
|
42 | 42 | #endif |
|
43 | 43 | /*! |
|
44 | 44 | \qmlproperty string BoxSet::values |
|
45 | 45 | The values on the box-and-whiskers set. |
|
46 | 46 | */ |
|
47 | 47 | /*! |
|
48 | 48 | \qmlproperty string BoxSet::label |
|
49 | 49 | Defines the label of the box-and-whiskers set. |
|
50 | 50 | */ |
|
51 | 51 | /*! |
|
52 | 52 | \qmlproperty int BoxSet::count |
|
53 | 53 | The count of values on the box-and-whiskers set |
|
54 | 54 | */ |
|
55 | 55 | /*! |
|
56 | 56 | \qmlmethod void BoxSet::at(int index) |
|
57 | 57 | Returns the value at \a index position. |
|
58 | 58 | */ |
|
59 | 59 | /*! |
|
60 | 60 | \qmlmethod void BoxSet::append(qreal value) |
|
61 | 61 | Appends new value \a value to the end of set. |
|
62 | 62 | */ |
|
63 | 63 | /*! |
|
64 | 64 | \qmlmethod void BoxSet::clear() |
|
65 | 65 | Sets all values on the set to 0. |
|
66 | 66 | */ |
|
67 | 67 | /*! |
|
68 | 68 | \qmlmethod void BoxSet::setValue(int index, qreal value) |
|
69 | 69 | Sets a new \a value on the \a index position. |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | 72 | \qmlsignal BoxSet::onClicked() |
|
73 | 73 | This signal is emitted when the user clicks with a mouse on top of box-and-whiskers item. |
|
74 | 74 | */ |
|
75 | 75 | /*! |
|
76 | 76 | \qmlsignal BoxSet::onHovered(bool status) |
|
77 | 77 | The signal is emitted if mouse is hovered on top of box-and-whiskers item. |
|
78 | 78 | Parameter \a status is true, if mouse entered on top of the item, and false if mouse left from top of the item. |
|
79 | 79 | */ |
|
80 | 80 | /*! |
|
81 | 81 | \qmlsignal BoxSet::onPenChanged() |
|
82 | 82 | This signal is emitted when the pen of the box-and-whiskers item has changed. |
|
83 | 83 | */ |
|
84 | 84 | /*! |
|
85 | 85 | \qmlsignal BoxSet::onBrushChanged() |
|
86 | 86 | This signal is emitted when the brush of the box-and-whiskers item has changed. |
|
87 | 87 | */ |
|
88 | 88 | /*! |
|
89 | 89 | \qmlsignal BoxSet::onChangedValues() |
|
90 | 90 | This signal is emitted when multiple values have been changed on the box-and-whiskers item. |
|
91 | 91 | */ |
|
92 | 92 | /*! |
|
93 | 93 | \qmlsignal BoxSet::onChangedValue(int index) |
|
94 | 94 | This signal is emitted values the value in the box-and-whiskers item has been modified. |
|
95 | 95 | Parameter \a index indicates the position of the modified value. |
|
96 | 96 | */ |
|
97 | 97 | /*! |
|
98 | 98 | \qmlsignal BoxSet::onCleared() |
|
99 | 99 | This signal is emitted when all the values on the set are cleared to 0. |
|
100 | 100 | */ |
|
101 | 101 | |
|
102 | 102 | |
|
103 | 103 | #ifdef QDOC_QT5 |
|
104 | 104 | /*! |
|
105 | 105 | \qmltype BoxPlotSeries |
|
106 | 106 | \instantiates QBoxPlotSeries |
|
107 | 107 | \inqmlmodule QtCommercial.Chart |
|
108 | 108 | |
|
109 |
\include |
|
|
109 | \include doc/src/declarativeboxplotseries.qdocinc | |
|
110 | 110 | */ |
|
111 | 111 | #else |
|
112 | 112 | /*! |
|
113 | 113 | \qmlclass BoxPlotSeries QBoxPlotSeries |
|
114 | 114 | |
|
115 | 115 | \include ../doc/src/declarativeboxplotseries.qdocinc |
|
116 | 116 | */ |
|
117 | 117 | #endif |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | \qmlmethod BoxPlotSeries::append(string label, VariantList values) |
|
121 | 121 | Appends a new box-and-whiskers set with \a label and \a values to the series. |
|
122 | 122 | */ |
|
123 | 123 | /*! |
|
124 | 124 | \qmlmethod BoxPlotSeries::append(BoxSet box) |
|
125 | 125 | Appends the \a box to the series. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlmethod BoxPlotSeries::insert(int index, string label, VariantList values) |
|
129 | 129 | Inserts a new box-and-whiskers set with \a label and \a values at the \a index position. |
|
130 | 130 | */ |
|
131 | 131 | /*! |
|
132 | 132 | \qmlmethod BoxPlotSeries::remove(QBoxSet boxset) |
|
133 | 133 | Removes the \a boxset from the series. |
|
134 | 134 | */ |
|
135 | 135 | /*! |
|
136 | 136 | \qmlmethod BoxPlotSeries::clear() |
|
137 | 137 | Removes all boxsets from the series. Deletes removed sets. |
|
138 | 138 | */ |
|
139 | 139 | /*! |
|
140 | 140 | \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset); |
|
141 | 141 | Signal is emitted when the user clicks the \a boxset on the chart. |
|
142 | 142 | */ |
|
143 | 143 | /*! |
|
144 | 144 | \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset); |
|
145 | 145 | Signal is emitted when there is change in hover \a status over \a boxset. |
|
146 | 146 | */ |
|
147 | 147 | /*! |
|
148 | 148 | \qmlsignal BoxPlotSeries::onCountChanged(); |
|
149 | 149 | Signal is emitted when there is change in count of box-and-whiskers items in the series. |
|
150 | 150 | */ |
|
151 | 151 | /*! |
|
152 | 152 | \qmlsignal BoxPlotSeries::onBoxsetsAdded() |
|
153 | 153 | Signal is emitted when new box-and-whiskers sets are added to the series. |
|
154 | 154 | */ |
|
155 | 155 | /*! |
|
156 | 156 | \qmlsignal BoxPlotSeries::onBoxsetsRemoved() |
|
157 | 157 | Signal is emitted when new box-and-whiskers sets are removed from the series. |
|
158 | 158 | */ |
|
159 | 159 | /*! |
|
160 | 160 | \qmlproperty AbstractAxis BoxPlotSeries::axisX |
|
161 | 161 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for |
|
162 | 162 | the series. |
|
163 | 163 | \sa axisXTop |
|
164 | 164 | */ |
|
165 | 165 | /*! |
|
166 | 166 | \qmlproperty AbstractAxis BoxPlotSeries::axisY |
|
167 | 167 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
168 | 168 | the series. |
|
169 | 169 | \sa axisYRight |
|
170 | 170 | */ |
|
171 | 171 | /*! |
|
172 | 172 | \qmlproperty AbstractAxis BoxPlotSeries::axisXTop |
|
173 | 173 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
174 | 174 | axisXTop, but not both. |
|
175 | 175 | \sa axisX |
|
176 | 176 | */ |
|
177 | 177 | /*! |
|
178 | 178 | \qmlproperty AbstractAxis BoxPlotSeries::axisYRight |
|
179 | 179 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
180 | 180 | or axisYRight, but not both. |
|
181 | 181 | \sa axisY |
|
182 | 182 | */ |
|
183 | 183 | /*! |
|
184 | 184 | \qmlproperty bool BoxPlotSeries::boxOutlineVisible |
|
185 | 185 | This property configures the visibility of the middle box outline. |
|
186 | 186 | */ |
|
187 | 187 | /*! |
|
188 | 188 | \qmlproperty qreal BoxPlotSeries::boxWidth |
|
189 | 189 | This property configures the width of the box-and-whiskers item. The value signifies the relative |
|
190 | 190 | width of the box-and-whiskers item inside its own slot. The value can between 0.0 and 1.0. Negative values |
|
191 | 191 | are clamped to 0.0 and values over 1.0 are clamped to 1.0. |
|
192 | 192 | */ |
|
193 | 193 | /*! |
|
194 | 194 | \qmlproperty Pen BoxPlotSeries::pen |
|
195 | 195 | This property configures the pen of the box-and-whiskers items. |
|
196 | 196 | */ |
|
197 | 197 | /*! |
|
198 | 198 | \qmlproperty Brush BoxPlotSeries::brush |
|
199 | 199 | This property configures the brush of the box-and-whiskers items. |
|
200 | 200 | */ |
|
201 | 201 | /*! |
|
202 | 202 | \qmlsignal BoxPlotSeries::onBoxOutlineVisibilityChanged() |
|
203 | 203 | Signal is emitted when the middle box outline visibility is changed. |
|
204 | 204 | */ |
|
205 | 205 | /*! |
|
206 | 206 | \qmlsignal BoxPlotSeries::onBoxWidthChanged() |
|
207 | 207 | Signal is emitted when the width of the box-and-whiskers item is changed. |
|
208 | 208 | */ |
|
209 | 209 | /*! |
|
210 | 210 | \qmlsignal BoxPlotSeries::onPenChanged() |
|
211 | 211 | Signal is emitted when the pen for box-and-whiskers items has changed. |
|
212 | 212 | */ |
|
213 | 213 | /*! |
|
214 | 214 | \qmlsignal BoxPlotSeries::onBrushChanged() |
|
215 | 215 | Signal is emitted when the brush for box-and-whiskers items has changed. |
|
216 | 216 | */ |
|
217 | 217 | /*! |
|
218 | 218 | \qmlsignal BoxPlotSeries::onClicked(BoxSet boxset) |
|
219 | 219 | Signal is emitted when the user clicks the \a boxset on the chart. |
|
220 | 220 | */ |
|
221 | 221 | /*! |
|
222 | 222 | \qmlsignal BoxPlotSeries::onHovered(bool status, BoxSet boxset) |
|
223 | 223 | Signal is emitted when there is change in hover \a status over \a boxset. |
|
224 | 224 | */ |
|
225 | 225 | /*! |
|
226 | 226 | \qmlsignal BoxPlotSeries::onAxisXChanged(AbstractAxis axis) |
|
227 | 227 | Signal is emitted when there is change in X axis. |
|
228 | 228 | */ |
|
229 | 229 | /*! |
|
230 | 230 | \qmlsignal BoxPlotSeries::onAxisYChanged(AbstractAxis axis) |
|
231 | 231 | Signal is emitted when there is change in Y axis. |
|
232 | 232 | */ |
|
233 | 233 | /*! |
|
234 | 234 | \qmlsignal BoxPlotSeries::onAxisXTopChanged(AbstractAxis axis) |
|
235 | 235 | Signal is emitted when there is change in top X axis. |
|
236 | 236 | */ |
|
237 | 237 | /*! |
|
238 | 238 | \qmlsignal BoxPlotSeries::onAxisYRightChanged(AbstractAxis axis) |
|
239 | 239 | Signal is emitted when there is change in Y right axis. |
|
240 | 240 | */ |
|
241 | 241 | |
|
242 | 242 | |
|
243 | 243 | DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent) |
|
244 | 244 | : QBoxSet(label, parent) |
|
245 | 245 | { |
|
246 | 246 | connect(this, SIGNAL(valuesChanged()), this, SIGNAL(changedValues())); |
|
247 | 247 | connect(this, SIGNAL(valueChanged(int)), this, SIGNAL(changedValue(int))); |
|
248 | 248 | } |
|
249 | 249 | |
|
250 | 250 | QVariantList DeclarativeBoxSet::values() |
|
251 | 251 | { |
|
252 | 252 | QVariantList values; |
|
253 | 253 | for (int i(0); i < 5; i++) |
|
254 | 254 | values.append(QVariant(QBoxSet::at(i))); |
|
255 | 255 | return values; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | void DeclarativeBoxSet::setValues(QVariantList values) |
|
259 | 259 | { |
|
260 | 260 | for (int i(0); i < values.count(); i++) { |
|
261 | 261 | if (values.at(i).canConvert(QVariant::Double)) |
|
262 | 262 | QBoxSet::append(values[i].toDouble()); |
|
263 | 263 | } |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | 266 | // ===================================================== |
|
267 | 267 | |
|
268 | 268 | DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDECLARATIVE_ITEM *parent) : |
|
269 | 269 | QBoxPlotSeries(parent), |
|
270 | 270 | m_axes(new DeclarativeAxes(this)) |
|
271 | 271 | { |
|
272 | 272 | connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); |
|
273 | 273 | connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); |
|
274 | 274 | connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
|
275 | 275 | connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
|
276 | 276 | connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*))); |
|
277 | 277 | connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*))); |
|
278 | 278 | } |
|
279 | 279 | |
|
280 | 280 | void DeclarativeBoxPlotSeries::classBegin() |
|
281 | 281 | { |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | void DeclarativeBoxPlotSeries::componentComplete() |
|
285 | 285 | { |
|
286 | 286 | foreach (QObject *child, children()) { |
|
287 | 287 | if (qobject_cast<DeclarativeBoxSet *>(child)) { |
|
288 | 288 | QBoxPlotSeries::append(qobject_cast<DeclarativeBoxSet *>(child)); |
|
289 | 289 | } else if (qobject_cast<QVBoxPlotModelMapper *>(child)) { |
|
290 | 290 | QVBoxPlotModelMapper *mapper = qobject_cast<QVBoxPlotModelMapper *>(child); |
|
291 | 291 | mapper->setSeries(this); |
|
292 | 292 | } |
|
293 | 293 | } |
|
294 | 294 | } |
|
295 | 295 | |
|
296 | 296 | QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeBoxPlotSeries::seriesChildren() |
|
297 | 297 | { |
|
298 | 298 | return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS); |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | void DeclarativeBoxPlotSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> *list, QObject *element) |
|
302 | 302 | { |
|
303 | 303 | // Empty implementation; the children are parsed in componentComplete instead |
|
304 | 304 | Q_UNUSED(list); |
|
305 | 305 | Q_UNUSED(element); |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::at(int index) |
|
309 | 309 | { |
|
310 | 310 | QList<QBoxSet *> setList = boxSets(); |
|
311 | 311 | if (index >= 0 && index < setList.count()) |
|
312 | 312 | return qobject_cast<DeclarativeBoxSet *>(setList[index]); |
|
313 | 313 | |
|
314 | 314 | return 0; |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, const QString label, QVariantList values) |
|
318 | 318 | { |
|
319 | 319 | DeclarativeBoxSet *barset = new DeclarativeBoxSet(label, this); |
|
320 | 320 | barset->setValues(values); |
|
321 | 321 | if (QBoxPlotSeries::insert(index, barset)) |
|
322 | 322 | return barset; |
|
323 | 323 | delete barset; |
|
324 | 324 | return 0; |
|
325 | 325 | } |
|
326 | 326 | |
|
327 | 327 | void DeclarativeBoxPlotSeries::onHovered(bool status, QBoxSet *boxset) |
|
328 | 328 | { |
|
329 | 329 | emit hovered(status, qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | void DeclarativeBoxPlotSeries::onClicked(QBoxSet *boxset) |
|
333 | 333 | { |
|
334 | 334 | emit clicked(qobject_cast<DeclarativeBoxSet *>(boxset)); |
|
335 | 335 | } |
|
336 | 336 | |
|
337 | 337 | #include "moc_declarativeboxplotseries.cpp" |
|
338 | 338 | |
|
339 | 339 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,107 +1,107 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "declarativecategoryaxis.h" |
|
22 | 22 | #include <QDebug> |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | #ifdef QDOC_QT5 |
|
27 | 27 | /*! |
|
28 | 28 | \qmltype CategoryRange |
|
29 | 29 | \inqmlmodule QtCommercial.Chart |
|
30 | 30 | |
|
31 |
\include |
|
|
31 | \include doc/src/categoryrange.qdocinc | |
|
32 | 32 | */ |
|
33 | 33 | #else |
|
34 | 34 | /*! |
|
35 | 35 | \qmlclass CategoryRange |
|
36 | 36 | |
|
37 | 37 | \include ../doc/src/categoryrange.qdocinc |
|
38 | 38 | */ |
|
39 | 39 | #endif |
|
40 | 40 | |
|
41 | 41 | DeclarativeCategoryRange::DeclarativeCategoryRange(QObject *parent) : |
|
42 | 42 | QObject(parent), |
|
43 | 43 | m_endValue(0), |
|
44 | 44 | m_label(QString()) |
|
45 | 45 | { |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | DeclarativeCategoryAxis::DeclarativeCategoryAxis(QObject *parent) : |
|
49 | 49 | QCategoryAxis(parent) |
|
50 | 50 | { |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | void DeclarativeCategoryAxis::classBegin() |
|
54 | 54 | { |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | void DeclarativeCategoryAxis::componentComplete() |
|
58 | 58 | { |
|
59 | 59 | QList<QPair<QString, qreal> > ranges; |
|
60 | 60 | foreach (QObject *child, children()) { |
|
61 | 61 | if (qobject_cast<DeclarativeCategoryRange *>(child)) { |
|
62 | 62 | DeclarativeCategoryRange *range = qobject_cast<DeclarativeCategoryRange *>(child); |
|
63 | 63 | ranges.append(QPair<QString, qreal>(range->label(), range->endValue())); |
|
64 | 64 | } |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | // Sort and append the range objects according to end value |
|
68 | 68 | qSort(ranges.begin(), ranges.end(), endValueLessThan); |
|
69 | 69 | for (int i(0); i < ranges.count(); i++) |
|
70 | 70 | append(ranges.at(i).first, ranges.at(i).second); |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | bool DeclarativeCategoryAxis::endValueLessThan(const QPair<QString, qreal> &value1, const QPair<QString, qreal> &value2) |
|
74 | 74 | { |
|
75 | 75 | return value1.second < value2.second; |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeCategoryAxis::axisChildren() |
|
79 | 79 | { |
|
80 | 80 | return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeCategoryAxis::appendAxisChildren LIST_PROPERTY_PARAM_DEFAULTS); |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | void DeclarativeCategoryAxis::append(const QString &label, qreal categoryEndValue) |
|
84 | 84 | { |
|
85 | 85 | QCategoryAxis::append(label, categoryEndValue); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | void DeclarativeCategoryAxis::remove(const QString &label) |
|
89 | 89 | { |
|
90 | 90 | QCategoryAxis::remove(label); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | void DeclarativeCategoryAxis::replace(const QString &oldLabel, const QString &newLabel) |
|
94 | 94 | { |
|
95 | 95 | QCategoryAxis::replaceLabel(oldLabel, newLabel); |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void DeclarativeCategoryAxis::appendAxisChildren(QDECLARATIVE_LIST_PROPERTY<QObject> *list, QObject *element) |
|
99 | 99 | { |
|
100 | 100 | // Empty implementation; the children are parsed in componentComplete instead |
|
101 | 101 | Q_UNUSED(list) |
|
102 | 102 | Q_UNUSED(element) |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | #include "moc_declarativecategoryaxis.cpp" |
|
106 | 106 | |
|
107 | 107 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,1032 +1,1032 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "declarativechart.h" |
|
22 | 22 | #include <QPainter> |
|
23 | 23 | #include "declarativelineseries.h" |
|
24 | 24 | #include "declarativeareaseries.h" |
|
25 | 25 | #include "declarativebarseries.h" |
|
26 | 26 | #include "declarativepieseries.h" |
|
27 | 27 | #include "declarativesplineseries.h" |
|
28 | 28 | #include "declarativeboxplotseries.h" |
|
29 | 29 | #include "declarativescatterseries.h" |
|
30 | 30 | #include "qbarcategoryaxis.h" |
|
31 | 31 | #include "qvalueaxis.h" |
|
32 | 32 | #include "qlogvalueaxis.h" |
|
33 | 33 | #include "qcategoryaxis.h" |
|
34 | 34 | #include "qabstractseries_p.h" |
|
35 | 35 | #include "declarativemargins.h" |
|
36 | 36 | #include "chartdataset_p.h" |
|
37 | 37 | #include "declarativeaxes.h" |
|
38 | 38 | #include "qchart_p.h" |
|
39 | 39 | #include "qpolarchart.h" |
|
40 | 40 | |
|
41 | 41 | #ifndef QT_ON_ARM |
|
42 | 42 | #include "qdatetimeaxis.h" |
|
43 | 43 | #endif |
|
44 | 44 | |
|
45 | 45 | #ifdef CHARTS_FOR_QUICK2 |
|
46 | 46 | #include <QGraphicsSceneMouseEvent> |
|
47 | 47 | #include <QGraphicsSceneHoverEvent> |
|
48 | 48 | #include <QApplication> |
|
49 | 49 | #include <QTimer> |
|
50 | 50 | #include <QThread> |
|
51 | 51 | #endif |
|
52 | 52 | |
|
53 | 53 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
54 | 54 | |
|
55 | 55 | #ifdef QDOC_QT5 |
|
56 | 56 | /*! |
|
57 | 57 | \qmltype ChartView |
|
58 | 58 | \instantiates DeclarativeChart |
|
59 | 59 | \inqmlmodule QtCommercial.Chart |
|
60 | 60 | |
|
61 |
\include |
|
|
61 | \include doc/src/chartview.qdocinc | |
|
62 | 62 | */ |
|
63 | 63 | #else |
|
64 | 64 | /*! |
|
65 | 65 | \qmlclass ChartView DeclarativeChart |
|
66 | 66 | |
|
67 | 67 | \include ../doc/src/chartview.qdocinc |
|
68 | 68 | */ |
|
69 | 69 | #endif |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty Theme ChartView::theme |
|
73 | 73 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
74 | 74 | widths and chart background. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \qmlproperty Animation ChartView::animationOptions |
|
79 | 79 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
80 | 80 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty Font ChartView::titleFont |
|
85 | 85 | The title font of the chart. |
|
86 | 86 | |
|
87 | 87 | See the Qt documentation for more details of Font. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \qmlproperty string ChartView::title |
|
92 | 92 | The title of the chart, shown on top of the chart. |
|
93 | 93 | \sa ChartView::titleColor |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \qmlproperty color ChartView::titleColor |
|
98 | 98 | The color of the title text. |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \qmlproperty Legend ChartView::legend |
|
103 | 103 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
104 | 104 | */ |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | \qmlproperty int ChartView::count |
|
108 | 108 | The count of series added to the chart. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \qmlproperty color ChartView::backgroundColor |
|
113 | 113 | The color of the chart's background. By default background color is defined by chart theme. |
|
114 | 114 | \sa ChartView::theme |
|
115 | 115 | */ |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | 118 | \qmlproperty real ChartView::backgroundRoundness |
|
119 | 119 | The diameter of the rounding cirle at the corners of the chart background. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \qmlproperty color ChartView::plotAreaColor |
|
124 | 124 | The color of the background of the chart's plot area. By default plot area background uses chart's |
|
125 | 125 | background color. |
|
126 | 126 | \sa ChartView::backgroundColor |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \qmlproperty bool ChartView::dropShadowEnabled |
|
131 | 131 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \qmlproperty real ChartView::topMargin |
|
136 | 136 | Deprecated; use margins instead. |
|
137 | 137 | */ |
|
138 | 138 | |
|
139 | 139 | /*! |
|
140 | 140 | \qmlproperty real ChartView::bottomMargin |
|
141 | 141 | Deprecated; use margins instead. |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \qmlproperty real ChartView::leftMargin |
|
146 | 146 | Deprecated; use margins instead. |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \qmlproperty real ChartView::rightMargin |
|
151 | 151 | Deprecated; use margins instead. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | \qmlproperty Margins ChartView::minimumMargins |
|
156 | 156 | Deprecated; use margins instead. |
|
157 | 157 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
158 | 158 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
159 | 159 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
160 | 160 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
161 | 161 | given time, you can check ChartView::plotArea instead. |
|
162 | 162 | */ |
|
163 | 163 | |
|
164 | 164 | /*! |
|
165 | 165 | \qmlproperty rect ChartView::plotArea |
|
166 | 166 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
167 | 167 | margins. |
|
168 | 168 | \sa ChartView::minimumMargins |
|
169 | 169 | */ |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | \qmlproperty Margins ChartView::margins |
|
173 | 173 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
174 | 174 | area of ChartView is used for drawing title, axes and legend. |
|
175 | 175 | */ |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
179 | 179 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
180 | 180 | the count property of the chart. |
|
181 | 181 | */ |
|
182 | 182 | |
|
183 | 183 | /*! |
|
184 | 184 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
185 | 185 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
186 | 186 | */ |
|
187 | 187 | |
|
188 | 188 | /*! |
|
189 | 189 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
190 | 190 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
191 | 191 | optional axis \a axisY. For example: |
|
192 | 192 | \code |
|
193 | 193 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
194 | 194 | var myAxisX = chartView.axisX(lineSeries); |
|
195 | 195 | var myAxisY = chartView.axisY(lineSeries); |
|
196 | 196 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
197 | 197 | \endcode |
|
198 | 198 | */ |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
202 | 202 | Removes the \a series from the chart. The series object is also destroyed. |
|
203 | 203 | */ |
|
204 | 204 | |
|
205 | 205 | /*! |
|
206 | 206 | \qmlmethod ChartView::removeAllSeries() |
|
207 | 207 | Removes all series from the chart. All the series objects are also destroyed. |
|
208 | 208 | */ |
|
209 | 209 | |
|
210 | 210 | /*! |
|
211 | 211 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
212 | 212 | The x-axis of the series. |
|
213 | 213 | */ |
|
214 | 214 | |
|
215 | 215 | /*! |
|
216 | 216 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
217 | 217 | The y-axis of the series. |
|
218 | 218 | */ |
|
219 | 219 | |
|
220 | 220 | /*! |
|
221 | 221 | \qmlmethod ChartView::zoomY(real factor) |
|
222 | 222 | Zooms in by \a factor on the center of the chart. |
|
223 | 223 | */ |
|
224 | 224 | |
|
225 | 225 | /*! |
|
226 | 226 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
227 | 227 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
228 | 228 | */ |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | \qmlmethod ChartView::scrollRight(real pixels) |
|
232 | 232 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
233 | 233 | */ |
|
234 | 234 | |
|
235 | 235 | /*! |
|
236 | 236 | \qmlmethod ChartView::scrollUp(real pixels) |
|
237 | 237 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
238 | 238 | */ |
|
239 | 239 | |
|
240 | 240 | /*! |
|
241 | 241 | \qmlmethod ChartView::scrollDown(real pixels) |
|
242 | 242 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
243 | 243 | */ |
|
244 | 244 | |
|
245 | 245 | /*! |
|
246 | 246 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
247 | 247 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
248 | 248 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
249 | 249 | title. |
|
250 | 250 | */ |
|
251 | 251 | |
|
252 | 252 | /*! |
|
253 | 253 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
254 | 254 | The \a series has been added to the chart. |
|
255 | 255 | */ |
|
256 | 256 | |
|
257 | 257 | /*! |
|
258 | 258 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
259 | 259 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
260 | 260 | object after the signal handler has completed. |
|
261 | 261 | */ |
|
262 | 262 | |
|
263 | 263 | DeclarativeChart::DeclarativeChart(QDECLARATIVE_ITEM *parent) |
|
264 | 264 | : QDECLARATIVE_PAINTED_ITEM(parent) |
|
265 | 265 | { |
|
266 | 266 | initChart(QChart::ChartTypeCartesian); |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | DeclarativeChart::DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent) |
|
270 | 270 | : QDECLARATIVE_PAINTED_ITEM(parent) |
|
271 | 271 | { |
|
272 | 272 | initChart(type); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | void DeclarativeChart::initChart(QChart::ChartType type) |
|
276 | 276 | { |
|
277 | 277 | #ifdef CHARTS_FOR_QUICK2 |
|
278 | 278 | m_currentSceneImage = 0; |
|
279 | 279 | m_guiThreadId = QThread::currentThreadId(); |
|
280 | 280 | m_paintThreadId = 0; |
|
281 | 281 | m_updatePending = false; |
|
282 | 282 | |
|
283 | 283 | if (type == QChart::ChartTypePolar) |
|
284 | 284 | m_chart = new QPolarChart(); |
|
285 | 285 | else |
|
286 | 286 | m_chart = new QChart(); |
|
287 | 287 | |
|
288 | 288 | m_scene = new QGraphicsScene(this); |
|
289 | 289 | m_scene->addItem(m_chart); |
|
290 | 290 | |
|
291 | 291 | setAntialiasing(QQuickItem::antialiasing()); |
|
292 | 292 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>))); |
|
293 | 293 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
294 | 294 | |
|
295 | 295 | setAcceptedMouseButtons(Qt::AllButtons); |
|
296 | 296 | setAcceptHoverEvents(true); |
|
297 | 297 | #else |
|
298 | 298 | if (type == QChart::ChartTypePolar) |
|
299 | 299 | m_chart = new QPolarChart(this); |
|
300 | 300 | else |
|
301 | 301 | m_chart = new QChart(this); |
|
302 | 302 | |
|
303 | 303 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
304 | 304 | #endif |
|
305 | 305 | |
|
306 | 306 | m_margins = new DeclarativeMargins(this); |
|
307 | 307 | m_margins->setTop(m_chart->margins().top()); |
|
308 | 308 | m_margins->setLeft(m_chart->margins().left()); |
|
309 | 309 | m_margins->setRight(m_chart->margins().right()); |
|
310 | 310 | m_margins->setBottom(m_chart->margins().bottom()); |
|
311 | 311 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
312 | 312 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
313 | 313 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
314 | 314 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
315 | 315 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
316 | 316 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
317 | 317 | } |
|
318 | 318 | |
|
319 | 319 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) |
|
320 | 320 | { |
|
321 | 321 | emit seriesAdded(series); |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
325 | 325 | { |
|
326 | 326 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
327 | 327 | emit minimumMarginsChanged(); |
|
328 | 328 | emit plotAreaChanged(m_chart->plotArea()); |
|
329 | 329 | } |
|
330 | 330 | |
|
331 | 331 | DeclarativeChart::~DeclarativeChart() |
|
332 | 332 | { |
|
333 | 333 | delete m_chart; |
|
334 | 334 | #ifdef CHARTS_FOR_QUICK2 |
|
335 | 335 | m_sceneImageLock.lock(); |
|
336 | 336 | delete m_currentSceneImage; |
|
337 | 337 | m_currentSceneImage = 0; |
|
338 | 338 | m_sceneImageLock.unlock(); |
|
339 | 339 | #endif |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
343 | 343 | { |
|
344 | 344 | if (event->type() == QEvent::ChildAdded) { |
|
345 | 345 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
346 | 346 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
347 | 347 | } |
|
348 | 348 | } |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | void DeclarativeChart::componentComplete() |
|
352 | 352 | { |
|
353 | 353 | foreach (QObject *child, children()) { |
|
354 | 354 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
355 | 355 | // Add series to the chart |
|
356 | 356 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
357 | 357 | m_chart->addSeries(series); |
|
358 | 358 | |
|
359 | 359 | // Connect to axis changed signals (unless this is a pie series) |
|
360 | 360 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
361 | 361 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
362 | 362 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*))); |
|
363 | 363 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
364 | 364 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
365 | 365 | } |
|
366 | 366 | |
|
367 | 367 | initializeAxes(series); |
|
368 | 368 | } |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | QDECLARATIVE_ITEM::componentComplete(); |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
375 | 375 | { |
|
376 | 376 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
377 | 377 | if (axis && s) { |
|
378 | 378 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) |
|
379 | 379 | m_chart->setAxisX(axis, s); |
|
380 | 380 | if (!s->attachedAxes().contains(axis)) |
|
381 | 381 | s->attachAxis(axis); |
|
382 | 382 | } else { |
|
383 | 383 | qWarning() << "Trying to set axisX to null."; |
|
384 | 384 | } |
|
385 | 385 | } |
|
386 | 386 | |
|
387 | 387 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) |
|
388 | 388 | { |
|
389 | 389 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
390 | 390 | if (axis && s) { |
|
391 | 391 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) { |
|
392 | 392 | QList<QAbstractAxis *> oldAxes = m_chart->axes(Qt::Horizontal, s); |
|
393 | 393 | foreach (QAbstractAxis* a, oldAxes) { |
|
394 | 394 | m_chart->removeAxis(a); |
|
395 | 395 | delete a; |
|
396 | 396 | } |
|
397 | 397 | m_chart->addAxis(axis, Qt::AlignTop); |
|
398 | 398 | } |
|
399 | 399 | if (!s->attachedAxes().contains(axis)) |
|
400 | 400 | s->attachAxis(axis); |
|
401 | 401 | } else { |
|
402 | 402 | qWarning() << "Trying to set axisXTop to null."; |
|
403 | 403 | } |
|
404 | 404 | } |
|
405 | 405 | |
|
406 | 406 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
407 | 407 | { |
|
408 | 408 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
409 | 409 | if (axis && s) { |
|
410 | 410 | if (!m_chart->axes(Qt::Vertical).contains(axis)) |
|
411 | 411 | m_chart->setAxisY(axis, s); |
|
412 | 412 | if (!s->attachedAxes().contains(axis)) |
|
413 | 413 | s->attachAxis(axis); |
|
414 | 414 | } else { |
|
415 | 415 | qWarning() << "Trying to set axisY to null."; |
|
416 | 416 | } |
|
417 | 417 | } |
|
418 | 418 | |
|
419 | 419 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) |
|
420 | 420 | { |
|
421 | 421 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
422 | 422 | if (axis && s) { |
|
423 | 423 | if (!m_chart->axes(Qt::Vertical).contains(axis)) { |
|
424 | 424 | QList<QAbstractAxis *> oldAxes = m_chart->axes((Qt::Vertical), s); |
|
425 | 425 | foreach (QAbstractAxis* a, oldAxes) { |
|
426 | 426 | m_chart->removeAxis(a); |
|
427 | 427 | delete a; |
|
428 | 428 | } |
|
429 | 429 | m_chart->addAxis(axis, Qt::AlignRight); |
|
430 | 430 | } |
|
431 | 431 | if (!s->attachedAxes().contains(axis)) |
|
432 | 432 | s->attachAxis(axis); |
|
433 | 433 | } else { |
|
434 | 434 | qWarning() << "Trying to set axisYRight to null."; |
|
435 | 435 | } |
|
436 | 436 | } |
|
437 | 437 | |
|
438 | 438 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
439 | 439 | { |
|
440 | 440 | if (newGeometry.isValid()) { |
|
441 | 441 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
442 | 442 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
443 | 443 | } |
|
444 | 444 | } |
|
445 | 445 | QDECLARATIVE_ITEM::geometryChanged(newGeometry, oldGeometry); |
|
446 | 446 | |
|
447 | 447 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
448 | 448 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
449 | 449 | // to implement it here for the QML API purposes. |
|
450 | 450 | emit plotAreaChanged(m_chart->plotArea()); |
|
451 | 451 | } |
|
452 | 452 | |
|
453 | 453 | #ifdef CHARTS_FOR_QUICK2 |
|
454 | 454 | void DeclarativeChart::sceneChanged(QList<QRectF> region) |
|
455 | 455 | { |
|
456 | 456 | Q_UNUSED(region); |
|
457 | 457 | |
|
458 | 458 | if (m_guiThreadId == m_paintThreadId) { |
|
459 | 459 | // Rendering in gui thread, no need for shenannigans, just update |
|
460 | 460 | update(); |
|
461 | 461 | } else { |
|
462 | 462 | // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread |
|
463 | 463 | if (!m_updatePending) { |
|
464 | 464 | m_updatePending = true; |
|
465 | 465 | // Do async render to avoid some unnecessary renders. |
|
466 | 466 | QTimer::singleShot(0, this, SLOT(renderScene())); |
|
467 | 467 | } |
|
468 | 468 | } |
|
469 | 469 | } |
|
470 | 470 | |
|
471 | 471 | void DeclarativeChart::renderScene() |
|
472 | 472 | { |
|
473 | 473 | m_updatePending = false; |
|
474 | 474 | m_sceneImageLock.lock(); |
|
475 | 475 | delete m_currentSceneImage; |
|
476 | 476 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); |
|
477 | 477 | m_currentSceneImage->fill(Qt::transparent); |
|
478 | 478 | QPainter painter(m_currentSceneImage); |
|
479 | 479 | if (antialiasing()) |
|
480 | 480 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); |
|
481 | 481 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); |
|
482 | 482 | m_scene->render(&painter, renderRect, renderRect); |
|
483 | 483 | m_sceneImageLock.unlock(); |
|
484 | 484 | |
|
485 | 485 | update(); |
|
486 | 486 | } |
|
487 | 487 | |
|
488 | 488 | void DeclarativeChart::paint(QPainter *painter) |
|
489 | 489 | { |
|
490 | 490 | if (!m_paintThreadId) { |
|
491 | 491 | m_paintThreadId = QThread::currentThreadId(); |
|
492 | 492 | if (m_guiThreadId == m_paintThreadId) { |
|
493 | 493 | // No need for scene image in single threaded rendering, so delete |
|
494 | 494 | // the one that got made by default before the rendering type was |
|
495 | 495 | // detected. |
|
496 | 496 | delete m_currentSceneImage; |
|
497 | 497 | m_currentSceneImage = 0; |
|
498 | 498 | } |
|
499 | 499 | } |
|
500 | 500 | |
|
501 | 501 | if (m_guiThreadId == m_paintThreadId) { |
|
502 | 502 | QRectF renderRect(QPointF(0, 0), m_chart->size()); |
|
503 | 503 | m_scene->render(painter, renderRect, renderRect); |
|
504 | 504 | } else { |
|
505 | 505 | m_sceneImageLock.lock(); |
|
506 | 506 | if (m_currentSceneImage) { |
|
507 | 507 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); |
|
508 | 508 | QRect itemRect(QPoint(0, 0), QSize(width(), height())); |
|
509 | 509 | painter->drawImage(itemRect, *m_currentSceneImage, imageRect); |
|
510 | 510 | } |
|
511 | 511 | m_sceneImageLock.unlock(); |
|
512 | 512 | } |
|
513 | 513 | } |
|
514 | 514 | |
|
515 | 515 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
|
516 | 516 | { |
|
517 | 517 | m_mousePressScenePoint = event->pos(); |
|
518 | 518 | m_mousePressScreenPoint = event->globalPos(); |
|
519 | 519 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; |
|
520 | 520 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; |
|
521 | 521 | m_mousePressButton = event->button(); |
|
522 | 522 | m_mousePressButtons = event->buttons(); |
|
523 | 523 | |
|
524 | 524 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); |
|
525 | 525 | mouseEvent.setWidget(0); |
|
526 | 526 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
527 | 527 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
528 | 528 | mouseEvent.setScenePos(m_mousePressScenePoint); |
|
529 | 529 | mouseEvent.setScreenPos(m_mousePressScreenPoint); |
|
530 | 530 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
531 | 531 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
532 | 532 | mouseEvent.setButtons(m_mousePressButtons); |
|
533 | 533 | mouseEvent.setButton(m_mousePressButton); |
|
534 | 534 | mouseEvent.setModifiers(event->modifiers()); |
|
535 | 535 | mouseEvent.setAccepted(false); |
|
536 | 536 | |
|
537 | 537 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
538 | 538 | } |
|
539 | 539 | |
|
540 | 540 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) |
|
541 | 541 | { |
|
542 | 542 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); |
|
543 | 543 | mouseEvent.setWidget(0); |
|
544 | 544 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
545 | 545 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
546 | 546 | mouseEvent.setScenePos(event->pos()); |
|
547 | 547 | mouseEvent.setScreenPos(event->globalPos()); |
|
548 | 548 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
549 | 549 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
550 | 550 | mouseEvent.setButtons(event->buttons()); |
|
551 | 551 | mouseEvent.setButton(event->button()); |
|
552 | 552 | mouseEvent.setModifiers(event->modifiers()); |
|
553 | 553 | mouseEvent.setAccepted(false); |
|
554 | 554 | |
|
555 | 555 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
556 | 556 | |
|
557 | 557 | m_mousePressButtons = event->buttons(); |
|
558 | 558 | m_mousePressButton = Qt::NoButton; |
|
559 | 559 | } |
|
560 | 560 | |
|
561 | 561 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) |
|
562 | 562 | { |
|
563 | 563 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. |
|
564 | 564 | // QGraphicsScene generates hover events from mouse move events, so we don't need |
|
565 | 565 | // to pass hover events there. |
|
566 | 566 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
567 | 567 | mouseEvent.setWidget(0); |
|
568 | 568 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
569 | 569 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
570 | 570 | mouseEvent.setScenePos(event->pos()); |
|
571 | 571 | // Hover events do not have global pos in them, and the screen position doesn't seem to |
|
572 | 572 | // matter anyway in this use case, so just pass event pos instead of trying to |
|
573 | 573 | // calculate the real screen position. |
|
574 | 574 | mouseEvent.setScreenPos(event->pos()); |
|
575 | 575 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
576 | 576 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
577 | 577 | mouseEvent.setButtons(m_mousePressButtons); |
|
578 | 578 | mouseEvent.setButton(m_mousePressButton); |
|
579 | 579 | mouseEvent.setModifiers(event->modifiers()); |
|
580 | 580 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); |
|
581 | 581 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); |
|
582 | 582 | mouseEvent.setAccepted(false); |
|
583 | 583 | |
|
584 | 584 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
585 | 585 | } |
|
586 | 586 | |
|
587 | 587 | void DeclarativeChart::handleAntialiasingChanged(bool enable) |
|
588 | 588 | { |
|
589 | 589 | setAntialiasing(enable); |
|
590 | 590 | } |
|
591 | 591 | #endif |
|
592 | 592 | |
|
593 | 593 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
594 | 594 | { |
|
595 | 595 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
596 | 596 | if (chartTheme != m_chart->theme()) |
|
597 | 597 | m_chart->setTheme(chartTheme); |
|
598 | 598 | } |
|
599 | 599 | |
|
600 | 600 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
601 | 601 | { |
|
602 | 602 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
603 | 603 | } |
|
604 | 604 | |
|
605 | 605 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
606 | 606 | { |
|
607 | 607 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
608 | 608 | if (animationOptions != m_chart->animationOptions()) |
|
609 | 609 | m_chart->setAnimationOptions(animationOptions); |
|
610 | 610 | } |
|
611 | 611 | |
|
612 | 612 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
613 | 613 | { |
|
614 | 614 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
615 | 615 | return DeclarativeChart::AllAnimations; |
|
616 | 616 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
617 | 617 | return DeclarativeChart::GridAxisAnimations; |
|
618 | 618 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
619 | 619 | return DeclarativeChart::SeriesAnimations; |
|
620 | 620 | else |
|
621 | 621 | return DeclarativeChart::NoAnimation; |
|
622 | 622 | } |
|
623 | 623 | |
|
624 | 624 | void DeclarativeChart::setTitle(QString title) |
|
625 | 625 | { |
|
626 | 626 | if (title != m_chart->title()) |
|
627 | 627 | m_chart->setTitle(title); |
|
628 | 628 | } |
|
629 | 629 | QString DeclarativeChart::title() |
|
630 | 630 | { |
|
631 | 631 | return m_chart->title(); |
|
632 | 632 | } |
|
633 | 633 | |
|
634 | 634 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
635 | 635 | { |
|
636 | 636 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); |
|
637 | 637 | if (axes.count()) |
|
638 | 638 | return axes[0]; |
|
639 | 639 | return 0; |
|
640 | 640 | } |
|
641 | 641 | |
|
642 | 642 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
643 | 643 | { |
|
644 | 644 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); |
|
645 | 645 | if (axes.count()) |
|
646 | 646 | return axes[0]; |
|
647 | 647 | return 0; |
|
648 | 648 | } |
|
649 | 649 | |
|
650 | 650 | QLegend *DeclarativeChart::legend() |
|
651 | 651 | { |
|
652 | 652 | return m_chart->legend(); |
|
653 | 653 | } |
|
654 | 654 | |
|
655 | 655 | void DeclarativeChart::setTitleColor(QColor color) |
|
656 | 656 | { |
|
657 | 657 | QBrush b = m_chart->titleBrush(); |
|
658 | 658 | if (color != b.color()) { |
|
659 | 659 | b.setColor(color); |
|
660 | 660 | m_chart->setTitleBrush(b); |
|
661 | 661 | emit titleColorChanged(color); |
|
662 | 662 | } |
|
663 | 663 | } |
|
664 | 664 | |
|
665 | 665 | QFont DeclarativeChart::titleFont() const |
|
666 | 666 | { |
|
667 | 667 | return m_chart->titleFont(); |
|
668 | 668 | } |
|
669 | 669 | |
|
670 | 670 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
671 | 671 | { |
|
672 | 672 | m_chart->setTitleFont(font); |
|
673 | 673 | } |
|
674 | 674 | |
|
675 | 675 | QColor DeclarativeChart::titleColor() |
|
676 | 676 | { |
|
677 | 677 | return m_chart->titleBrush().color(); |
|
678 | 678 | } |
|
679 | 679 | |
|
680 | 680 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
681 | 681 | { |
|
682 | 682 | QBrush b = m_chart->backgroundBrush(); |
|
683 | 683 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
684 | 684 | b.setStyle(Qt::SolidPattern); |
|
685 | 685 | b.setColor(color); |
|
686 | 686 | m_chart->setBackgroundBrush(b); |
|
687 | 687 | emit backgroundColorChanged(); |
|
688 | 688 | } |
|
689 | 689 | } |
|
690 | 690 | |
|
691 | 691 | QColor DeclarativeChart::backgroundColor() |
|
692 | 692 | { |
|
693 | 693 | return m_chart->backgroundBrush().color(); |
|
694 | 694 | } |
|
695 | 695 | |
|
696 | 696 | void QtCommercialChart::DeclarativeChart::setPlotAreaColor(QColor color) |
|
697 | 697 | { |
|
698 | 698 | QBrush b = m_chart->plotAreaBackgroundBrush(); |
|
699 | 699 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
700 | 700 | b.setStyle(Qt::SolidPattern); |
|
701 | 701 | b.setColor(color); |
|
702 | 702 | m_chart->setPlotAreaBackgroundBrush(b); |
|
703 | 703 | m_chart->setPlotAreaBackgroundVisible(true); |
|
704 | 704 | emit plotAreaColorChanged(); |
|
705 | 705 | } |
|
706 | 706 | } |
|
707 | 707 | |
|
708 | 708 | QColor QtCommercialChart::DeclarativeChart::plotAreaColor() |
|
709 | 709 | { |
|
710 | 710 | return m_chart->plotAreaBackgroundBrush().color(); |
|
711 | 711 | } |
|
712 | 712 | |
|
713 | 713 | int DeclarativeChart::count() |
|
714 | 714 | { |
|
715 | 715 | return m_chart->series().count(); |
|
716 | 716 | } |
|
717 | 717 | |
|
718 | 718 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
719 | 719 | { |
|
720 | 720 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
721 | 721 | m_chart->setDropShadowEnabled(enabled); |
|
722 | 722 | dropShadowEnabledChanged(enabled); |
|
723 | 723 | } |
|
724 | 724 | } |
|
725 | 725 | |
|
726 | 726 | bool DeclarativeChart::dropShadowEnabled() |
|
727 | 727 | { |
|
728 | 728 | return m_chart->isDropShadowEnabled(); |
|
729 | 729 | } |
|
730 | 730 | |
|
731 | 731 | qreal DeclarativeChart::backgroundRoundness() const |
|
732 | 732 | { |
|
733 | 733 | return m_chart->backgroundRoundness(); |
|
734 | 734 | } |
|
735 | 735 | |
|
736 | 736 | void DeclarativeChart::setBackgroundRoundness(qreal diameter) |
|
737 | 737 | { |
|
738 | 738 | if (m_chart->backgroundRoundness() != diameter) { |
|
739 | 739 | m_chart->setBackgroundRoundness(diameter); |
|
740 | 740 | emit backgroundRoundnessChanged(diameter); |
|
741 | 741 | } |
|
742 | 742 | } |
|
743 | 743 | |
|
744 | 744 | qreal DeclarativeChart::topMargin() |
|
745 | 745 | { |
|
746 | 746 | qWarning() << "ChartView.topMargin is deprecated. Use margins instead."; |
|
747 | 747 | return m_chart->margins().top(); |
|
748 | 748 | } |
|
749 | 749 | |
|
750 | 750 | qreal DeclarativeChart::bottomMargin() |
|
751 | 751 | { |
|
752 | 752 | qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead."; |
|
753 | 753 | return m_chart->margins().bottom(); |
|
754 | 754 | } |
|
755 | 755 | |
|
756 | 756 | qreal DeclarativeChart::leftMargin() |
|
757 | 757 | { |
|
758 | 758 | qWarning() << "ChartView.leftMargin is deprecated. Use margins instead."; |
|
759 | 759 | return m_chart->margins().left(); |
|
760 | 760 | } |
|
761 | 761 | |
|
762 | 762 | qreal DeclarativeChart::rightMargin() |
|
763 | 763 | { |
|
764 | 764 | qWarning() << "ChartView.rightMargin is deprecated. Use margins instead."; |
|
765 | 765 | return m_chart->margins().right(); |
|
766 | 766 | } |
|
767 | 767 | |
|
768 | 768 | void DeclarativeChart::zoom(qreal factor) |
|
769 | 769 | { |
|
770 | 770 | m_chart->zoom(factor); |
|
771 | 771 | } |
|
772 | 772 | |
|
773 | 773 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
774 | 774 | { |
|
775 | 775 | m_chart->scroll(-pixels, 0); |
|
776 | 776 | } |
|
777 | 777 | |
|
778 | 778 | void DeclarativeChart::scrollRight(qreal pixels) |
|
779 | 779 | { |
|
780 | 780 | m_chart->scroll(pixels, 0); |
|
781 | 781 | } |
|
782 | 782 | |
|
783 | 783 | void DeclarativeChart::scrollUp(qreal pixels) |
|
784 | 784 | { |
|
785 | 785 | m_chart->scroll(0, pixels); |
|
786 | 786 | } |
|
787 | 787 | |
|
788 | 788 | void DeclarativeChart::scrollDown(qreal pixels) |
|
789 | 789 | { |
|
790 | 790 | m_chart->scroll(0, -pixels); |
|
791 | 791 | } |
|
792 | 792 | |
|
793 | 793 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> DeclarativeChart::axes() |
|
794 | 794 | { |
|
795 | 795 | return QDECLARATIVE_LIST_PROPERTY<QAbstractAxis>(this, 0, |
|
796 | 796 | &DeclarativeChart::axesAppendFunc, |
|
797 | 797 | &DeclarativeChart::axesCountFunc, |
|
798 | 798 | #ifdef CHARTS_FOR_QUICK2 |
|
799 | 799 | &DeclarativeChart::axesAtFunc, |
|
800 | 800 | &DeclarativeChart::axesClearFunc); |
|
801 | 801 | #else |
|
802 | 802 | &DeclarativeChart::axesAtFunc); |
|
803 | 803 | #endif |
|
804 | 804 | } |
|
805 | 805 | |
|
806 | 806 | void DeclarativeChart::axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element) |
|
807 | 807 | { |
|
808 | 808 | // Empty implementation |
|
809 | 809 | Q_UNUSED(list); |
|
810 | 810 | Q_UNUSED(element); |
|
811 | 811 | } |
|
812 | 812 | |
|
813 | 813 | int DeclarativeChart::axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) |
|
814 | 814 | { |
|
815 | 815 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
816 | 816 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
817 | 817 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); |
|
818 | 818 | } |
|
819 | 819 | return 0; |
|
820 | 820 | } |
|
821 | 821 | |
|
822 | 822 | QAbstractAxis *DeclarativeChart::axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index) |
|
823 | 823 | { |
|
824 | 824 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
825 | 825 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
826 | 826 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); |
|
827 | 827 | return axes.at(index); |
|
828 | 828 | } |
|
829 | 829 | return 0; |
|
830 | 830 | } |
|
831 | 831 | |
|
832 | 832 | void DeclarativeChart::axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) |
|
833 | 833 | { |
|
834 | 834 | // Empty implementation |
|
835 | 835 | Q_UNUSED(list); |
|
836 | 836 | } |
|
837 | 837 | |
|
838 | 838 | |
|
839 | 839 | QAbstractSeries *DeclarativeChart::series(int index) |
|
840 | 840 | { |
|
841 | 841 | if (index < m_chart->series().count()) { |
|
842 | 842 | return m_chart->series().at(index); |
|
843 | 843 | } |
|
844 | 844 | return 0; |
|
845 | 845 | } |
|
846 | 846 | |
|
847 | 847 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
848 | 848 | { |
|
849 | 849 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
850 | 850 | if (series->name() == seriesName) |
|
851 | 851 | return series; |
|
852 | 852 | } |
|
853 | 853 | return 0; |
|
854 | 854 | } |
|
855 | 855 | |
|
856 | 856 | QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
857 | 857 | { |
|
858 | 858 | QAbstractSeries *series = 0; |
|
859 | 859 | |
|
860 | 860 | switch (type) { |
|
861 | 861 | case DeclarativeChart::SeriesTypeLine: |
|
862 | 862 | series = new DeclarativeLineSeries(); |
|
863 | 863 | break; |
|
864 | 864 | case DeclarativeChart::SeriesTypeArea: { |
|
865 | 865 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
866 | 866 | area->setUpperSeries(new DeclarativeLineSeries()); |
|
867 | 867 | series = area; |
|
868 | 868 | break; |
|
869 | 869 | } |
|
870 | 870 | case DeclarativeChart::SeriesTypeStackedBar: |
|
871 | 871 | series = new DeclarativeStackedBarSeries(); |
|
872 | 872 | break; |
|
873 | 873 | case DeclarativeChart::SeriesTypePercentBar: |
|
874 | 874 | series = new DeclarativePercentBarSeries(); |
|
875 | 875 | break; |
|
876 | 876 | case DeclarativeChart::SeriesTypeBar: |
|
877 | 877 | series = new DeclarativeBarSeries(); |
|
878 | 878 | break; |
|
879 | 879 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
880 | 880 | series = new DeclarativeHorizontalBarSeries(); |
|
881 | 881 | break; |
|
882 | 882 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
883 | 883 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
884 | 884 | break; |
|
885 | 885 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
886 | 886 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
887 | 887 | break; |
|
888 | 888 | case DeclarativeChart::SeriesTypeBoxPlot: |
|
889 | 889 | series = new DeclarativeBoxPlotSeries(); |
|
890 | 890 | break; |
|
891 | 891 | case DeclarativeChart::SeriesTypePie: |
|
892 | 892 | series = new DeclarativePieSeries(); |
|
893 | 893 | break; |
|
894 | 894 | case DeclarativeChart::SeriesTypeScatter: |
|
895 | 895 | series = new DeclarativeScatterSeries(); |
|
896 | 896 | break; |
|
897 | 897 | case DeclarativeChart::SeriesTypeSpline: |
|
898 | 898 | series = new DeclarativeSplineSeries(); |
|
899 | 899 | break; |
|
900 | 900 | default: |
|
901 | 901 | qWarning() << "Illegal series type"; |
|
902 | 902 | } |
|
903 | 903 | |
|
904 | 904 | if (series) { |
|
905 | 905 | // Connect to axis changed signals (unless this is a pie series) |
|
906 | 906 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
907 | 907 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
908 | 908 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
909 | 909 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
910 | 910 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
911 | 911 | } |
|
912 | 912 | |
|
913 | 913 | series->setName(name); |
|
914 | 914 | m_chart->addSeries(series); |
|
915 | 915 | |
|
916 | 916 | if (axisX) |
|
917 | 917 | setAxisX(axisX, series); |
|
918 | 918 | if (axisY) |
|
919 | 919 | setAxisY(axisY, series); |
|
920 | 920 | |
|
921 | 921 | if (series->attachedAxes().count() < 2) |
|
922 | 922 | initializeAxes(series); |
|
923 | 923 | } |
|
924 | 924 | |
|
925 | 925 | return series; |
|
926 | 926 | } |
|
927 | 927 | |
|
928 | 928 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
929 | 929 | { |
|
930 | 930 | if (series) |
|
931 | 931 | m_chart->removeSeries(series); |
|
932 | 932 | else |
|
933 | 933 | qWarning("removeSeries: cannot remove null"); |
|
934 | 934 | } |
|
935 | 935 | |
|
936 | 936 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
937 | 937 | { |
|
938 | 938 | if (axis) |
|
939 | 939 | m_chart->setAxisX(axis, series); |
|
940 | 940 | } |
|
941 | 941 | |
|
942 | 942 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
943 | 943 | { |
|
944 | 944 | if (axis) |
|
945 | 945 | m_chart->setAxisY(axis, series); |
|
946 | 946 | } |
|
947 | 947 | |
|
948 | 948 | void DeclarativeChart::createDefaultAxes() |
|
949 | 949 | { |
|
950 | 950 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
951 | 951 | } |
|
952 | 952 | |
|
953 | 953 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) |
|
954 | 954 | { |
|
955 | 955 | if (!series) { |
|
956 | 956 | qWarning() << "No axis type defined for null series"; |
|
957 | 957 | return 0; |
|
958 | 958 | } |
|
959 | 959 | |
|
960 | 960 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { |
|
961 | 961 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) |
|
962 | 962 | return existingAxis; |
|
963 | 963 | } |
|
964 | 964 | |
|
965 | 965 | switch (series->d_ptr->defaultAxisType(orientation)) { |
|
966 | 966 | case QAbstractAxis::AxisTypeValue: |
|
967 | 967 | return new QValueAxis(this); |
|
968 | 968 | case QAbstractAxis::AxisTypeBarCategory: |
|
969 | 969 | return new QBarCategoryAxis(this); |
|
970 | 970 | case QAbstractAxis::AxisTypeCategory: |
|
971 | 971 | return new QCategoryAxis(this); |
|
972 | 972 | #ifndef QT_ON_ARM |
|
973 | 973 | case QAbstractAxis::AxisTypeDateTime: |
|
974 | 974 | return new QDateTimeAxis(this); |
|
975 | 975 | #endif |
|
976 | 976 | case QAbstractAxis::AxisTypeLogValue: |
|
977 | 977 | return new QLogValueAxis(this); |
|
978 | 978 | default: |
|
979 | 979 | // assume AxisTypeNoAxis |
|
980 | 980 | return 0; |
|
981 | 981 | } |
|
982 | 982 | } |
|
983 | 983 | |
|
984 | 984 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) |
|
985 | 985 | { |
|
986 | 986 | if (qobject_cast<DeclarativeLineSeries *>(series)) |
|
987 | 987 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); |
|
988 | 988 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) |
|
989 | 989 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); |
|
990 | 990 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) |
|
991 | 991 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); |
|
992 | 992 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) |
|
993 | 993 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); |
|
994 | 994 | else if (qobject_cast<DeclarativeBarSeries *>(series)) |
|
995 | 995 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); |
|
996 | 996 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) |
|
997 | 997 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); |
|
998 | 998 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) |
|
999 | 999 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); |
|
1000 | 1000 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) |
|
1001 | 1001 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); |
|
1002 | 1002 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) |
|
1003 | 1003 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); |
|
1004 | 1004 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) |
|
1005 | 1005 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); |
|
1006 | 1006 | else if (qobject_cast<DeclarativeBoxPlotSeries *>(series)) |
|
1007 | 1007 | doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes); |
|
1008 | 1008 | // else: do nothing |
|
1009 | 1009 | } |
|
1010 | 1010 | |
|
1011 | 1011 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) |
|
1012 | 1012 | { |
|
1013 | 1013 | // Initialize axis X |
|
1014 | 1014 | if (axes->axisX()) |
|
1015 | 1015 | axes->emitAxisXChanged(); |
|
1016 | 1016 | else if (axes->axisXTop()) |
|
1017 | 1017 | axes->emitAxisXTopChanged(); |
|
1018 | 1018 | else |
|
1019 | 1019 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); |
|
1020 | 1020 | |
|
1021 | 1021 | // Initialize axis Y |
|
1022 | 1022 | if (axes->axisY()) |
|
1023 | 1023 | axes->emitAxisYChanged(); |
|
1024 | 1024 | else if (axes->axisYRight()) |
|
1025 | 1025 | axes->emitAxisYRightChanged(); |
|
1026 | 1026 | else |
|
1027 | 1027 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); |
|
1028 | 1028 | } |
|
1029 | 1029 | |
|
1030 | 1030 | #include "moc_declarativechart.cpp" |
|
1031 | 1031 | |
|
1032 | 1032 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,121 +1,121 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "declarativemargins.h" |
|
22 | 22 | #include <QDataStream> |
|
23 | 23 | #include <QDebug> |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | #ifdef QDOC_QT5 |
|
28 | 28 | /*! |
|
29 | 29 | \qmltype Margins |
|
30 | 30 | \inqmlmodule QtCommercial.Chart |
|
31 | 31 | |
|
32 |
\include |
|
|
32 | \include doc/src/margins.qdocinc | |
|
33 | 33 | */ |
|
34 | 34 | #else |
|
35 | 35 | /*! |
|
36 | 36 | \qmlclass Margins |
|
37 | 37 | |
|
38 | 38 | \include ../doc/src/margins.qdocinc |
|
39 | 39 | */ |
|
40 | 40 | #endif |
|
41 | 41 | |
|
42 | 42 | /*! |
|
43 | 43 | \qmlproperty int Margins::top |
|
44 | 44 | The top margin. |
|
45 | 45 | */ |
|
46 | 46 | |
|
47 | 47 | /*! |
|
48 | 48 | \qmlproperty int Margins::bottom |
|
49 | 49 | The bottom margin. |
|
50 | 50 | */ |
|
51 | 51 | |
|
52 | 52 | /*! |
|
53 | 53 | \qmlproperty int Margins::left |
|
54 | 54 | The left margin. |
|
55 | 55 | */ |
|
56 | 56 | |
|
57 | 57 | /*! |
|
58 | 58 | \qmlproperty int Margins::right |
|
59 | 59 | The right margin. |
|
60 | 60 | */ |
|
61 | 61 | |
|
62 | 62 | DeclarativeMargins::DeclarativeMargins(QObject *parent) : |
|
63 | 63 | QObject(parent) |
|
64 | 64 | { |
|
65 | 65 | QMargins::setTop(0); |
|
66 | 66 | QMargins::setBottom(0); |
|
67 | 67 | QMargins::setLeft(0); |
|
68 | 68 | QMargins::setRight(0); |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | void DeclarativeMargins::setTop(int top) |
|
72 | 72 | { |
|
73 | 73 | if (top < 0) { |
|
74 | 74 | qWarning() << "Cannot set top margin to a negative value:" << top; |
|
75 | 75 | } else { |
|
76 | 76 | if (top != QMargins::top()) { |
|
77 | 77 | QMargins::setTop(top); |
|
78 | 78 | emit topChanged(QMargins::top(), QMargins::bottom(), QMargins::left(), QMargins::right()); |
|
79 | 79 | } |
|
80 | 80 | } |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | void DeclarativeMargins::setBottom(int bottom) |
|
84 | 84 | { |
|
85 | 85 | if (bottom < 0) { |
|
86 | 86 | qWarning() << "Cannot set bottom margin to a negative value:" << bottom; |
|
87 | 87 | } else { |
|
88 | 88 | if (bottom != QMargins::bottom()) { |
|
89 | 89 | QMargins::setBottom(bottom); |
|
90 | 90 | emit bottomChanged(QMargins::top(), QMargins::bottom(), QMargins::left(), QMargins::right()); |
|
91 | 91 | } |
|
92 | 92 | } |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | void DeclarativeMargins::setLeft(int left) |
|
96 | 96 | { |
|
97 | 97 | if (left < 0) { |
|
98 | 98 | qWarning() << "Cannot set left margin to a negative value:" << left; |
|
99 | 99 | } else { |
|
100 | 100 | if (left != QMargins::left()) { |
|
101 | 101 | QMargins::setLeft(left); |
|
102 | 102 | emit leftChanged(QMargins::top(), QMargins::bottom(), QMargins::left(), QMargins::right()); |
|
103 | 103 | } |
|
104 | 104 | } |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void DeclarativeMargins::setRight(int right) |
|
108 | 108 | { |
|
109 | 109 | if (right < 0) { |
|
110 | 110 | qWarning() << "Cannot set left margin to a negative value:" << right; |
|
111 | 111 | } else { |
|
112 | 112 | if (right != QMargins::right()) { |
|
113 | 113 | QMargins::setRight(right); |
|
114 | 114 | emit rightChanged(QMargins::top(), QMargins::bottom(), QMargins::left(), QMargins::right()); |
|
115 | 115 | } |
|
116 | 116 | } |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | #include "moc_declarativemargins.cpp" |
|
120 | 120 | |
|
121 | 121 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,53 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "declarativepolarchart.h" |
|
22 | 22 | #include "qchart.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | #ifdef QDOC_QT5 |
|
27 | 27 | /*! |
|
28 | 28 | \qmltype PolarChartView |
|
29 | 29 | \instantiates DeclarativePolarChart |
|
30 | 30 | \inqmlmodule QtCommercial.Chart |
|
31 | 31 | |
|
32 |
\include |
|
|
32 | \include doc/src/declarativepolarchart.qdocinc | |
|
33 | 33 | */ |
|
34 | 34 | #else |
|
35 | 35 | /*! |
|
36 | 36 | \qmlclass PolarChartView DeclarativePolarChart |
|
37 | 37 | |
|
38 | 38 | \include ../doc/src/declarativepolarchart.qdocinc |
|
39 | 39 | */ |
|
40 | 40 | #endif |
|
41 | 41 | |
|
42 | 42 | DeclarativePolarChart::DeclarativePolarChart(QDECLARATIVE_ITEM *parent) |
|
43 | 43 | : DeclarativeChart(QChart::ChartTypePolar, parent) |
|
44 | 44 | { |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | DeclarativePolarChart::~DeclarativePolarChart() |
|
48 | 48 | { |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | #include "moc_declarativepolarchart.cpp" |
|
52 | 52 | |
|
53 | 53 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,60 +1,60 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "declarativexypoint.h" |
|
22 | 22 | #include <QDataStream> |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | #ifdef QDOC_QT5 |
|
27 | 27 | /*! |
|
28 | 28 | \qmltype XYPoint |
|
29 | 29 | \inqmlmodule QtCommercial.Chart |
|
30 | 30 | |
|
31 |
\include |
|
|
31 | \include doc/src/declarativexypoint.qdocinc | |
|
32 | 32 | */ |
|
33 | 33 | #else |
|
34 | 34 | /*! |
|
35 | 35 | \qmlclass XYPoint QPointF |
|
36 | 36 | |
|
37 | 37 | \include ../doc/src/declarativexypoint.qdocinc |
|
38 | 38 | */ |
|
39 | 39 | #endif |
|
40 | 40 | |
|
41 | 41 | /*! |
|
42 | 42 | \qmlproperty real XYPoint::x |
|
43 | 43 | The x-coordinate of the point. |
|
44 | 44 | */ |
|
45 | 45 | |
|
46 | 46 | /*! |
|
47 | 47 | \qmlproperty real XYPoint::y |
|
48 | 48 | The y-coordinate of the point. |
|
49 | 49 | */ |
|
50 | 50 | |
|
51 | 51 | DeclarativeXYPoint::DeclarativeXYPoint(QObject *parent) : |
|
52 | 52 | QObject(parent) |
|
53 | 53 | { |
|
54 | 54 | setX(0.0); |
|
55 | 55 | setY(0.0); |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | #include "moc_declarativexypoint.cpp" |
|
59 | 59 | |
|
60 | 60 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,474 +1,474 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qareaseries.h" |
|
22 | 22 | #include "qareaseries_p.h" |
|
23 | 23 | #include "qlineseries.h" |
|
24 | 24 | #include "areachartitem_p.h" |
|
25 | 25 | #include "abstractdomain_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "qvalueaxis.h" |
|
29 | 29 | #include "qarealegendmarker.h" |
|
30 | 30 | #include "qchart_p.h" |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | /*! |
|
35 | 35 | \class QAreaSeries |
|
36 | 36 | \inmodule Qt Charts |
|
37 | 37 | \brief The QAreaSeries class is used for making area charts. |
|
38 | 38 | |
|
39 | 39 | \mainclass |
|
40 | 40 | |
|
41 | 41 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
42 | 42 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
43 | 43 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
44 | 44 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
45 | 45 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
46 | 46 | |
|
47 | 47 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
48 | 48 | \image examples_areachart.png |
|
49 | 49 | */ |
|
50 | 50 | #ifdef QDOC_QT5 |
|
51 | 51 | /*! |
|
52 | 52 | \qmltype AreaSeries |
|
53 | 53 | \instantiates QAreaSeries |
|
54 | 54 | \inqmlmodule QtCommercial.Chart |
|
55 | 55 | |
|
56 |
\include |
|
|
56 | \include doc/src/areaseries.qdocinc | |
|
57 | 57 | */ |
|
58 | 58 | #else |
|
59 | 59 | /*! |
|
60 | 60 | \qmlclass AreaSeries QAreaSeries |
|
61 | 61 | |
|
62 | 62 | \include ../doc/src/areaseries.qdocinc |
|
63 | 63 | */ |
|
64 | 64 | #endif |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \property QAreaSeries::upperSeries |
|
68 | 68 | \brief The upper one of the two line series used to define area series boundaries. |
|
69 | 69 | */ |
|
70 | 70 | /*! |
|
71 | 71 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
72 | 72 | The upper one of the two line series used to define area series boundaries. |
|
73 | 73 | */ |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \property QAreaSeries::lowerSeries |
|
77 | 77 | The lower one of the two line series used to define are series boundaries. Note if |
|
78 | 78 | QAreaSeries was constructed without a\ lowerSeries this is null. |
|
79 | 79 | */ |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
82 | 82 | The lower one of the two line series used to define are series boundaries. Note if |
|
83 | 83 | AreaSeries was constructed without a\ lowerSeries this is null. |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | 87 | \property QAreaSeries::color |
|
88 | 88 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
89 | 89 | \sa QAreaSeries::brush() |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty color AreaSeries::color |
|
93 | 93 | Fill (brush) color of the series. |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \property QAreaSeries::borderColor |
|
98 | 98 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
99 | 99 | \sa QAreaSeries::pen() |
|
100 | 100 | */ |
|
101 | 101 | /*! |
|
102 | 102 | \qmlproperty color AreaSeries::borderColor |
|
103 | 103 | Line (pen) color of the series. |
|
104 | 104 | */ |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | \qmlproperty real AreaSeries::borderWidth |
|
108 | 108 | The width of the border line. By default the width is 2.0. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \fn QPen QAreaSeries::pen() const |
|
113 | 113 | \brief Returns the pen used to draw line for this series. |
|
114 | 114 | \sa setPen() |
|
115 | 115 | */ |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | 118 | \fn QPen QAreaSeries::brush() const |
|
119 | 119 | \brief Returns the brush used to draw line for this series. |
|
120 | 120 | \sa setBrush() |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QAreaSeries::colorChanged(QColor color) |
|
125 | 125 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
129 | 129 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
134 | 134 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
135 | 135 | */ |
|
136 | 136 | /*! |
|
137 | 137 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
138 | 138 | Signal is emitted when the line (pen) color has changed to \a color. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
143 | 143 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
144 | 144 | */ |
|
145 | 145 | /*! |
|
146 | 146 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
147 | 147 | Signal is emitted when user clicks the \a point on area chart. |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \fn void QAreaSeries::hovered(const QPointF &point, bool state) |
|
152 | 152 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
153 | 153 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
154 | 154 | the series. |
|
155 | 155 | */ |
|
156 | 156 | /*! |
|
157 | 157 | \qmlsignal AreaSeries::onHovered(point point, bool state) |
|
158 | 158 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
159 | 159 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
160 | 160 | the series. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \fn void QAreaSeries::selected() |
|
165 | 165 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
166 | 166 | implemented by the user of QAreaSeries API. |
|
167 | 167 | */ |
|
168 | 168 | /*! |
|
169 | 169 | \qmlsignal AreaSeries::onSelected() |
|
170 | 170 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
171 | 171 | implemented by the user of AreaSeries API. |
|
172 | 172 | */ |
|
173 | 173 | |
|
174 | 174 | /*! |
|
175 | 175 | \fn void QAreaSeriesPrivate::updated() |
|
176 | 176 | \brief \internal |
|
177 | 177 | */ |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
181 | 181 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
182 | 182 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
183 | 183 | */ |
|
184 | 184 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
185 | 185 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) |
|
186 | 186 | { |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | /*! |
|
190 | 190 | Constructs area series object without upper or lower series with \a parent object. |
|
191 | 191 | */ |
|
192 | 192 | QAreaSeries::QAreaSeries(QObject *parent) |
|
193 | 193 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
194 | 194 | { |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | /*! |
|
198 | 198 | Destroys the object. |
|
199 | 199 | */ |
|
200 | 200 | QAreaSeries::~QAreaSeries() |
|
201 | 201 | { |
|
202 | 202 | Q_D(QAreaSeries); |
|
203 | 203 | if (d->m_chart) |
|
204 | 204 | d->m_chart->removeSeries(this); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | Returns QAbstractSeries::SeriesTypeArea. |
|
209 | 209 | */ |
|
210 | 210 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
211 | 211 | { |
|
212 | 212 | return QAbstractSeries::SeriesTypeArea; |
|
213 | 213 | } |
|
214 | 214 | |
|
215 | 215 | /*! |
|
216 | 216 | Sets the \a series that is to be used as the area chart upper series. |
|
217 | 217 | */ |
|
218 | 218 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
|
219 | 219 | { |
|
220 | 220 | Q_D(QAreaSeries); |
|
221 | 221 | if (d->m_upperSeries != series) |
|
222 | 222 | d->m_upperSeries = series; |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | QLineSeries *QAreaSeries::upperSeries() const |
|
226 | 226 | { |
|
227 | 227 | Q_D(const QAreaSeries); |
|
228 | 228 | return d->m_upperSeries; |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Sets the \a series that is to be used as the area chart lower series. |
|
233 | 233 | */ |
|
234 | 234 | void QAreaSeries::setLowerSeries(QLineSeries *series) |
|
235 | 235 | { |
|
236 | 236 | Q_D(QAreaSeries); |
|
237 | 237 | d->m_lowerSeries = series; |
|
238 | 238 | } |
|
239 | 239 | |
|
240 | 240 | QLineSeries *QAreaSeries::lowerSeries() const |
|
241 | 241 | { |
|
242 | 242 | Q_D(const QAreaSeries); |
|
243 | 243 | return d->m_lowerSeries; |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | /*! |
|
247 | 247 | Sets \a pen used for drawing area outline. |
|
248 | 248 | */ |
|
249 | 249 | void QAreaSeries::setPen(const QPen &pen) |
|
250 | 250 | { |
|
251 | 251 | Q_D(QAreaSeries); |
|
252 | 252 | if (d->m_pen != pen) { |
|
253 | 253 | d->m_pen = pen; |
|
254 | 254 | emit d->updated(); |
|
255 | 255 | } |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | QPen QAreaSeries::pen() const |
|
259 | 259 | { |
|
260 | 260 | Q_D(const QAreaSeries); |
|
261 | 261 | if (d->m_pen == QChartPrivate::defaultPen()) |
|
262 | 262 | return QPen(); |
|
263 | 263 | else |
|
264 | 264 | return d->m_pen; |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | /*! |
|
268 | 268 | Sets \a brush used for filling the area. |
|
269 | 269 | */ |
|
270 | 270 | void QAreaSeries::setBrush(const QBrush &brush) |
|
271 | 271 | { |
|
272 | 272 | Q_D(QAreaSeries); |
|
273 | 273 | if (d->m_brush != brush) { |
|
274 | 274 | bool emitColorChanged = brush.color() != d->m_brush.color(); |
|
275 | 275 | d->m_brush = brush; |
|
276 | 276 | emit d->updated(); |
|
277 | 277 | if (emitColorChanged) |
|
278 | 278 | emit colorChanged(brush.color()); |
|
279 | 279 | } |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | QBrush QAreaSeries::brush() const |
|
283 | 283 | { |
|
284 | 284 | Q_D(const QAreaSeries); |
|
285 | 285 | if (d->m_brush == QChartPrivate::defaultBrush()) |
|
286 | 286 | return QBrush(); |
|
287 | 287 | else |
|
288 | 288 | return d->m_brush; |
|
289 | 289 | } |
|
290 | 290 | |
|
291 | 291 | void QAreaSeries::setColor(const QColor &color) |
|
292 | 292 | { |
|
293 | 293 | QBrush b = brush(); |
|
294 | 294 | if (b == QBrush()) |
|
295 | 295 | b.setStyle(Qt::SolidPattern); |
|
296 | 296 | b.setColor(color); |
|
297 | 297 | setBrush(b); |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | QColor QAreaSeries::color() const |
|
301 | 301 | { |
|
302 | 302 | return brush().color(); |
|
303 | 303 | } |
|
304 | 304 | |
|
305 | 305 | void QAreaSeries::setBorderColor(const QColor &color) |
|
306 | 306 | { |
|
307 | 307 | QPen p = pen(); |
|
308 | 308 | if (p.color() != color) { |
|
309 | 309 | p.setColor(color); |
|
310 | 310 | setPen(p); |
|
311 | 311 | emit borderColorChanged(color); |
|
312 | 312 | } |
|
313 | 313 | } |
|
314 | 314 | |
|
315 | 315 | QColor QAreaSeries::borderColor() const |
|
316 | 316 | { |
|
317 | 317 | return pen().color(); |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | /*! |
|
321 | 321 | Sets if data points are \a visible and should be drawn on line. |
|
322 | 322 | */ |
|
323 | 323 | void QAreaSeries::setPointsVisible(bool visible) |
|
324 | 324 | { |
|
325 | 325 | Q_D(QAreaSeries); |
|
326 | 326 | if (d->m_pointsVisible != visible) { |
|
327 | 327 | d->m_pointsVisible = visible; |
|
328 | 328 | emit d->updated(); |
|
329 | 329 | } |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | /*! |
|
333 | 333 | Returns if the points are drawn for this series. |
|
334 | 334 | \sa setPointsVisible() |
|
335 | 335 | */ |
|
336 | 336 | bool QAreaSeries::pointsVisible() const |
|
337 | 337 | { |
|
338 | 338 | Q_D(const QAreaSeries); |
|
339 | 339 | return d->m_pointsVisible; |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
343 | 343 | |
|
344 | 344 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) |
|
345 | 345 | : QAbstractSeriesPrivate(q), |
|
346 | 346 | m_brush(QChartPrivate::defaultBrush()), |
|
347 | 347 | m_pen(QChartPrivate::defaultPen()), |
|
348 | 348 | m_upperSeries(upperSeries), |
|
349 | 349 | m_lowerSeries(lowerSeries), |
|
350 | 350 | m_pointsVisible(false) |
|
351 | 351 | { |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | void QAreaSeriesPrivate::initializeDomain() |
|
355 | 355 | { |
|
356 | 356 | Q_Q(QAreaSeries); |
|
357 | 357 | |
|
358 | 358 | qreal minX(domain()->minX()); |
|
359 | 359 | qreal minY(domain()->minY()); |
|
360 | 360 | qreal maxX(domain()->maxX()); |
|
361 | 361 | qreal maxY(domain()->maxY()); |
|
362 | 362 | |
|
363 | 363 | QLineSeries *upperSeries = q->upperSeries(); |
|
364 | 364 | QLineSeries *lowerSeries = q->lowerSeries(); |
|
365 | 365 | |
|
366 | 366 | if (upperSeries) { |
|
367 | 367 | const QList<QPointF>& points = upperSeries->points(); |
|
368 | 368 | |
|
369 | 369 | for (int i = 0; i < points.count(); i++) { |
|
370 | 370 | qreal x = points[i].x(); |
|
371 | 371 | qreal y = points[i].y(); |
|
372 | 372 | minX = qMin(minX, x); |
|
373 | 373 | minY = qMin(minY, y); |
|
374 | 374 | maxX = qMax(maxX, x); |
|
375 | 375 | maxY = qMax(maxY, y); |
|
376 | 376 | } |
|
377 | 377 | } |
|
378 | 378 | if (lowerSeries) { |
|
379 | 379 | |
|
380 | 380 | const QList<QPointF>& points = lowerSeries->points(); |
|
381 | 381 | |
|
382 | 382 | for (int i = 0; i < points.count(); i++) { |
|
383 | 383 | qreal x = points[i].x(); |
|
384 | 384 | qreal y = points[i].y(); |
|
385 | 385 | minX = qMin(minX, x); |
|
386 | 386 | minY = qMin(minY, y); |
|
387 | 387 | maxX = qMax(maxX, x); |
|
388 | 388 | maxY = qMax(maxY, y); |
|
389 | 389 | } |
|
390 | 390 | } |
|
391 | 391 | |
|
392 | 392 | domain()->setRange(minX, maxX, minY, maxY); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
396 | 396 | { |
|
397 | 397 | Q_Q(QAreaSeries); |
|
398 | 398 | AreaChartItem *area = new AreaChartItem(q,parent); |
|
399 | 399 | m_item.reset(area); |
|
400 | 400 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
401 | 401 | } |
|
402 | 402 | void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
403 | 403 | { |
|
404 | 404 | Q_Q(QAreaSeries); |
|
405 | 405 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); |
|
406 | 406 | |
|
407 | 407 | if (q->upperSeries() && area->upperLineItem()->animation()) |
|
408 | 408 | area->upperLineItem()->animation()->stopAndDestroyLater(); |
|
409 | 409 | if (q->lowerSeries() && area->lowerLineItem()->animation()) |
|
410 | 410 | area->lowerLineItem()->animation()->stopAndDestroyLater(); |
|
411 | 411 | |
|
412 | 412 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
413 | 413 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
414 | 414 | if (q->lowerSeries()) |
|
415 | 415 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
416 | 416 | } else { |
|
417 | 417 | if (q->upperSeries()) |
|
418 | 418 | area->upperLineItem()->setAnimation(0); |
|
419 | 419 | if (q->lowerSeries()) |
|
420 | 420 | area->lowerLineItem()->setAnimation(0); |
|
421 | 421 | } |
|
422 | 422 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
423 | 423 | } |
|
424 | 424 | |
|
425 | 425 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
426 | 426 | { |
|
427 | 427 | Q_Q(QAreaSeries); |
|
428 | 428 | QList<QLegendMarker*> list; |
|
429 | 429 | return list << new QAreaLegendMarker(q,legend); |
|
430 | 430 | } |
|
431 | 431 | |
|
432 | 432 | |
|
433 | 433 | void QAreaSeriesPrivate::initializeAxes() |
|
434 | 434 | { |
|
435 | 435 | |
|
436 | 436 | } |
|
437 | 437 | |
|
438 | 438 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
439 | 439 | { |
|
440 | 440 | Q_UNUSED(orientation); |
|
441 | 441 | return QAbstractAxis::AxisTypeValue; |
|
442 | 442 | } |
|
443 | 443 | |
|
444 | 444 | QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
445 | 445 | { |
|
446 | 446 | Q_UNUSED(orientation); |
|
447 | 447 | return new QValueAxis; |
|
448 | 448 | } |
|
449 | 449 | |
|
450 | 450 | void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
451 | 451 | { |
|
452 | 452 | Q_Q(QAreaSeries); |
|
453 | 453 | |
|
454 | 454 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
455 | 455 | const QList<QColor> colors = theme->seriesColors(); |
|
456 | 456 | |
|
457 | 457 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
458 | 458 | QPen pen; |
|
459 | 459 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); |
|
460 | 460 | pen.setWidthF(2); |
|
461 | 461 | q->setPen(pen); |
|
462 | 462 | } |
|
463 | 463 | |
|
464 | 464 | if (forced || QChartPrivate::defaultBrush() == m_brush) { |
|
465 | 465 | QBrush brush(colors.at(index % colors.size())); |
|
466 | 466 | q->setBrush(brush); |
|
467 | 467 | } |
|
468 | 468 | } |
|
469 | 469 | |
|
470 | 470 | |
|
471 | 471 | #include "moc_qareaseries.cpp" |
|
472 | 472 | #include "moc_qareaseries_p.cpp" |
|
473 | 473 | |
|
474 | 474 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,604 +1,604 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qbarcategoryaxis.h" |
|
22 | 22 | #include "qbarcategoryaxis_p.h" |
|
23 | 23 | #include "chartbarcategoryaxisx_p.h" |
|
24 | 24 | #include "chartbarcategoryaxisy_p.h" |
|
25 | 25 | #include "abstractdomain_p.h" |
|
26 | 26 | #include "qchart.h" |
|
27 | 27 | #include <qmath.h> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | /*! |
|
31 | 31 | \class QBarCategoryAxis |
|
32 | 32 | \inmodule Qt Charts |
|
33 | 33 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 | 36 | BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
37 | 37 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
38 | 38 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
39 | 39 | |
|
40 | 40 | Example code on how to use QBarCategoryAxis. |
|
41 | 41 | \code |
|
42 | 42 | QChartView *chartView = new QChartView; |
|
43 | 43 | QBarSeries *series = new QBarSeries; |
|
44 | 44 | // ... |
|
45 | 45 | chartView->chart()->addSeries(series); |
|
46 | 46 | chartView->chart()->createDefaultAxes(); |
|
47 | 47 | |
|
48 | 48 | QBarCategoryAxis *axisX = new QBarCategoryAxis; |
|
49 | 49 | QStringList categories; |
|
50 | 50 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
51 | 51 | axisX->append(categories); |
|
52 | 52 | axisX->setRange("Feb", "May"); |
|
53 | 53 | chartView->chart()->setAxisX(axisX, series); |
|
54 | 54 | \endcode |
|
55 | 55 | */ |
|
56 | 56 | |
|
57 | 57 | #ifdef QDOC_QT5 |
|
58 | 58 | /*! |
|
59 | 59 | \qmltype BarCategoryAxis |
|
60 | 60 | \instantiates QBarCategoryAxis |
|
61 | 61 | \inqmlmodule QtCommercial.Chart |
|
62 | 62 | |
|
63 |
\include |
|
|
63 | \include doc/src/barcategoryaxis.qdocinc | |
|
64 | 64 | */ |
|
65 | 65 | #else |
|
66 | 66 | /*! |
|
67 | 67 | \qmlclass BarCategoryAxis QBarCategoryAxis |
|
68 | 68 | |
|
69 | 69 | \include ../doc/src/barcategoryaxis.qdocinc |
|
70 | 70 | */ |
|
71 | 71 | #endif |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QBarCategoryAxis::categories |
|
75 | 75 | Defines the categories of axis |
|
76 | 76 | */ |
|
77 | 77 | /*! |
|
78 | 78 | \qmlproperty QStringList BarCategoryAxis::categories |
|
79 | 79 | Defines the categories of axis |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \property QBarCategoryAxis::min |
|
84 | 84 | Defines the minimum value on the axis. |
|
85 | 85 | */ |
|
86 | 86 | /*! |
|
87 | 87 | \qmlproperty string BarCategoryAxis::min |
|
88 | 88 | Defines the minimum value on the axis. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \property QBarCategoryAxis::max |
|
93 | 93 | Defines the maximum value on the axis. |
|
94 | 94 | */ |
|
95 | 95 | /*! |
|
96 | 96 | \qmlproperty string BarCategoryAxis::max |
|
97 | 97 | Defines the maximum value on the axis. |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \property QBarCategoryAxis::count |
|
102 | 102 | The count of categories. |
|
103 | 103 | */ |
|
104 | 104 | /*! |
|
105 | 105 | \qmlproperty int BarCategoryAxis::count |
|
106 | 106 | The count of categories. |
|
107 | 107 | */ |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | 110 | \fn void QBarCategoryAxis::categoriesChanged() |
|
111 | 111 | Axis emits signal when the categories of the axis have changed. |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | \fn void QBarCategoryAxis::minChanged(const QString &min) |
|
116 | 116 | Axis emits signal when \a min of axis has changed. |
|
117 | 117 | */ |
|
118 | 118 | /*! |
|
119 | 119 | \qmlsignal BarCategoryAxis::onMinChanged(const QString &min) |
|
120 | 120 | Axis emits signal when \a min of axis has changed. |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QBarCategoryAxis::maxChanged(const QString &max) |
|
125 | 125 | Axis emits signal when \a max of axis has changed. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max) |
|
129 | 129 | Axis emits signal when \a max of axis has changed. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QBarCategoryAxis::countChanged() |
|
134 | 134 | Axis emits signal when the count of categories has changed. |
|
135 | 135 | */ |
|
136 | 136 | /*! |
|
137 | 137 | \qmlsignal BarCategoryAxis::onCountChanged() |
|
138 | 138 | Axis emits signal when the count of categories has changed. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) |
|
143 | 143 | Axis emits signal when \a min or \a max of axis has changed. |
|
144 | 144 | */ |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | Constructs an axis object which is a child of \a parent. |
|
148 | 148 | */ |
|
149 | 149 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): |
|
150 | 150 | QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent) |
|
151 | 151 | { |
|
152 | 152 | } |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | Destroys the object |
|
156 | 156 | */ |
|
157 | 157 | QBarCategoryAxis::~QBarCategoryAxis() |
|
158 | 158 | { |
|
159 | 159 | Q_D(QBarCategoryAxis); |
|
160 | 160 | if (d->m_chart) |
|
161 | 161 | d->m_chart->removeAxis(this); |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | /*! |
|
165 | 165 | \internal |
|
166 | 166 | */ |
|
167 | 167 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent) |
|
168 | 168 | : QAbstractAxis(d, parent) |
|
169 | 169 | { |
|
170 | 170 | |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | Appends \a categories to axis. A maximum of the axis will be changed to last category in \a categories. |
|
175 | 175 | If there were no categories previously defined, minimum of axis will be also changed to first category in \a categories. |
|
176 | 176 | A category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. |
|
177 | 177 | */ |
|
178 | 178 | void QBarCategoryAxis::append(const QStringList &categories) |
|
179 | 179 | { |
|
180 | 180 | if (categories.isEmpty()) |
|
181 | 181 | return; |
|
182 | 182 | |
|
183 | 183 | Q_D(QBarCategoryAxis); |
|
184 | 184 | |
|
185 | 185 | int count = d->m_categories.count(); |
|
186 | 186 | |
|
187 | 187 | foreach(QString category, categories) { |
|
188 | 188 | if (!d->m_categories.contains(category) && !category.isNull()) { |
|
189 | 189 | d->m_categories.append(category); |
|
190 | 190 | } |
|
191 | 191 | } |
|
192 | 192 | |
|
193 | 193 | if (d->m_categories.count() == count) |
|
194 | 194 | return; |
|
195 | 195 | |
|
196 | 196 | if (count == 0) |
|
197 | 197 | setRange(d->m_categories.first(), d->m_categories.last()); |
|
198 | 198 | else |
|
199 | 199 | setRange(d->m_minCategory, d->m_categories.last()); |
|
200 | 200 | |
|
201 | 201 | emit categoriesChanged(); |
|
202 | 202 | emit countChanged(); |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | /*! |
|
206 | 206 | Appends \a category to axis. A maximum of the axis will be changed to last \a category. |
|
207 | 207 | If there were no categories previously defined, minimum of axis will be also changed to \a category. |
|
208 | 208 | A \a category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. |
|
209 | 209 | */ |
|
210 | 210 | void QBarCategoryAxis::append(const QString &category) |
|
211 | 211 | { |
|
212 | 212 | Q_D(QBarCategoryAxis); |
|
213 | 213 | |
|
214 | 214 | int count = d->m_categories.count(); |
|
215 | 215 | |
|
216 | 216 | if (!d->m_categories.contains(category) && !category.isNull()) |
|
217 | 217 | d->m_categories.append(category); |
|
218 | 218 | |
|
219 | 219 | if (d->m_categories.count() == count) |
|
220 | 220 | return; |
|
221 | 221 | |
|
222 | 222 | if (count == 0) |
|
223 | 223 | setRange(d->m_categories.last(), d->m_categories.last()); |
|
224 | 224 | else |
|
225 | 225 | setRange(d->m_minCategory, d->m_categories.last()); |
|
226 | 226 | |
|
227 | 227 | emit categoriesChanged(); |
|
228 | 228 | emit countChanged(); |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Removes \a category from axis. Removing category which is currently maximum or minimum |
|
233 | 233 | will affect the axis range. |
|
234 | 234 | */ |
|
235 | 235 | void QBarCategoryAxis::remove(const QString &category) |
|
236 | 236 | { |
|
237 | 237 | Q_D(QBarCategoryAxis); |
|
238 | 238 | |
|
239 | 239 | if (d->m_categories.contains(category)) { |
|
240 | 240 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
241 | 241 | if (!d->m_categories.isEmpty()) { |
|
242 | 242 | if (d->m_minCategory == category) { |
|
243 | 243 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
244 | 244 | } else if (d->m_maxCategory == category) { |
|
245 | 245 | setRange(d->m_minCategory, d->m_categories.last()); |
|
246 | 246 | } else { |
|
247 | 247 | d->updateCategoryDomain(); |
|
248 | 248 | } |
|
249 | 249 | } else { |
|
250 | 250 | setRange(QString::null, QString::null); |
|
251 | 251 | } |
|
252 | 252 | emit categoriesChanged(); |
|
253 | 253 | emit countChanged(); |
|
254 | 254 | } |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | /*! |
|
258 | 258 | Inserts \a category to axis at \a index. A \a category has to be valid QStrings and can not be duplicated. |
|
259 | 259 | If \a category is prepended or appended to categories, minimum and maximum of axis is updated accordingly. |
|
260 | 260 | */ |
|
261 | 261 | void QBarCategoryAxis::insert(int index, const QString &category) |
|
262 | 262 | { |
|
263 | 263 | Q_D(QBarCategoryAxis); |
|
264 | 264 | |
|
265 | 265 | int count = d->m_categories.count(); |
|
266 | 266 | |
|
267 | 267 | if (!d->m_categories.contains(category) && !category.isNull()) |
|
268 | 268 | d->m_categories.insert(index, category); |
|
269 | 269 | |
|
270 | 270 | if (d->m_categories.count() == count) |
|
271 | 271 | return; |
|
272 | 272 | |
|
273 | 273 | if (count == 0) { |
|
274 | 274 | setRange(d->m_categories.first(), d->m_categories.first()); |
|
275 | 275 | } else if (index == 0) { |
|
276 | 276 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
277 | 277 | } else if (index == count) { |
|
278 | 278 | setRange(d->m_minCategory, d->m_categories.last()); |
|
279 | 279 | } else { |
|
280 | 280 | d->updateCategoryDomain(); |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | emit categoriesChanged(); |
|
284 | 284 | emit countChanged(); |
|
285 | 285 | } |
|
286 | 286 | |
|
287 | 287 | /*! |
|
288 | 288 | Replaces \a oldCategory with \a newCategory. If \a oldCategory does not exist on the axis nothing is done. |
|
289 | 289 | A \a newCategory has to be valid QStrings and can not be duplicated. In case of replacing minimum or maximum category, |
|
290 | 290 | minimum and maximum of axis is updated accordingly. |
|
291 | 291 | */ |
|
292 | 292 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) |
|
293 | 293 | { |
|
294 | 294 | Q_D(QBarCategoryAxis); |
|
295 | 295 | |
|
296 | 296 | int pos = d->m_categories.indexOf(oldCategory); |
|
297 | 297 | |
|
298 | 298 | if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { |
|
299 | 299 | d->m_categories.replace(pos, newCategory); |
|
300 | 300 | if (d->m_minCategory == oldCategory) |
|
301 | 301 | setRange(newCategory, d->m_maxCategory); |
|
302 | 302 | else if (d->m_maxCategory == oldCategory) |
|
303 | 303 | setRange(d->m_minCategory, newCategory); |
|
304 | 304 | |
|
305 | 305 | emit categoriesChanged(); |
|
306 | 306 | emit countChanged(); |
|
307 | 307 | } |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | /*! |
|
311 | 311 | Removes all categories. Sets the maximum and minimum of the axis's range to QString::null. |
|
312 | 312 | */ |
|
313 | 313 | void QBarCategoryAxis::clear() |
|
314 | 314 | { |
|
315 | 315 | Q_D(QBarCategoryAxis); |
|
316 | 316 | d->m_categories.clear(); |
|
317 | 317 | setRange(QString::null, QString::null); |
|
318 | 318 | emit categoriesChanged(); |
|
319 | 319 | emit countChanged(); |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | /*! |
|
323 | 323 | Set \a categories and discards the old ones, range of axis is adjusted to match first and last category in \a categories. |
|
324 | 324 | A category has to be valid QStrings and can not be duplicated. |
|
325 | 325 | */ |
|
326 | 326 | void QBarCategoryAxis::setCategories(const QStringList &categories) |
|
327 | 327 | { |
|
328 | 328 | Q_D(QBarCategoryAxis); |
|
329 | 329 | d->m_categories.clear(); |
|
330 | 330 | d->m_minCategory = QString::null; |
|
331 | 331 | d->m_maxCategory = QString::null; |
|
332 | 332 | d->m_min = 0; |
|
333 | 333 | d->m_max = 0; |
|
334 | 334 | d->m_count = 0; |
|
335 | 335 | append(categories); |
|
336 | 336 | } |
|
337 | 337 | |
|
338 | 338 | /*! |
|
339 | 339 | Returns categories |
|
340 | 340 | */ |
|
341 | 341 | QStringList QBarCategoryAxis::categories() |
|
342 | 342 | { |
|
343 | 343 | Q_D(QBarCategoryAxis); |
|
344 | 344 | return d->m_categories; |
|
345 | 345 | } |
|
346 | 346 | |
|
347 | 347 | /*! |
|
348 | 348 | Returns number of categories. |
|
349 | 349 | */ |
|
350 | 350 | int QBarCategoryAxis::count() const |
|
351 | 351 | { |
|
352 | 352 | Q_D(const QBarCategoryAxis); |
|
353 | 353 | return d->m_categories.count(); |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | /*! |
|
357 | 357 | Returns category at \a index. Index must be valid. |
|
358 | 358 | */ |
|
359 | 359 | QString QBarCategoryAxis::at(int index) const |
|
360 | 360 | { |
|
361 | 361 | Q_D(const QBarCategoryAxis); |
|
362 | 362 | return d->m_categories.at(index); |
|
363 | 363 | } |
|
364 | 364 | |
|
365 | 365 | /*! |
|
366 | 366 | Sets minimum category to \a min. |
|
367 | 367 | */ |
|
368 | 368 | void QBarCategoryAxis::setMin(const QString &min) |
|
369 | 369 | { |
|
370 | 370 | Q_D(QBarCategoryAxis); |
|
371 | 371 | d->setRange(min, d->m_maxCategory); |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | /*! |
|
375 | 375 | Returns minimum category. |
|
376 | 376 | */ |
|
377 | 377 | QString QBarCategoryAxis::min() const |
|
378 | 378 | { |
|
379 | 379 | Q_D(const QBarCategoryAxis); |
|
380 | 380 | return d->m_minCategory; |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | /*! |
|
384 | 384 | Sets maximum category to \a max. |
|
385 | 385 | */ |
|
386 | 386 | void QBarCategoryAxis::setMax(const QString &max) |
|
387 | 387 | { |
|
388 | 388 | Q_D(QBarCategoryAxis); |
|
389 | 389 | d->setRange(d->m_minCategory, max); |
|
390 | 390 | } |
|
391 | 391 | |
|
392 | 392 | /*! |
|
393 | 393 | Returns maximum category |
|
394 | 394 | */ |
|
395 | 395 | QString QBarCategoryAxis::max() const |
|
396 | 396 | { |
|
397 | 397 | Q_D(const QBarCategoryAxis); |
|
398 | 398 | return d->m_maxCategory; |
|
399 | 399 | } |
|
400 | 400 | |
|
401 | 401 | /*! |
|
402 | 402 | Sets range from \a minCategory to \a maxCategory |
|
403 | 403 | */ |
|
404 | 404 | void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) |
|
405 | 405 | { |
|
406 | 406 | Q_D(QBarCategoryAxis); |
|
407 | 407 | d->setRange(minCategory,maxCategory); |
|
408 | 408 | } |
|
409 | 409 | |
|
410 | 410 | /*! |
|
411 | 411 | Returns the type of the axis |
|
412 | 412 | */ |
|
413 | 413 | QAbstractAxis::AxisType QBarCategoryAxis::type() const |
|
414 | 414 | { |
|
415 | 415 | return AxisTypeBarCategory; |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
419 | 419 | |
|
420 | 420 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q) |
|
421 | 421 | : QAbstractAxisPrivate(q), |
|
422 | 422 | m_min(0.0), |
|
423 | 423 | m_max(0.0), |
|
424 | 424 | m_count(0) |
|
425 | 425 | { |
|
426 | 426 | |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() |
|
430 | 430 | { |
|
431 | 431 | |
|
432 | 432 | } |
|
433 | 433 | |
|
434 | 434 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) |
|
435 | 435 | { |
|
436 | 436 | setRange(min, m_maxCategory); |
|
437 | 437 | } |
|
438 | 438 | |
|
439 | 439 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) |
|
440 | 440 | { |
|
441 | 441 | setRange(m_minCategory, max); |
|
442 | 442 | } |
|
443 | 443 | |
|
444 | 444 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
445 | 445 | { |
|
446 | 446 | QString value1 = min.toString(); |
|
447 | 447 | QString value2 = max.toString(); |
|
448 | 448 | setRange(value1, value2); |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | void QBarCategoryAxisPrivate::setRange(qreal min, qreal max) |
|
452 | 452 | { |
|
453 | 453 | Q_Q(QBarCategoryAxis); |
|
454 | 454 | |
|
455 | 455 | bool categoryChanged = false; |
|
456 | 456 | bool changed = false; |
|
457 | 457 | |
|
458 | 458 | if (min > max) |
|
459 | 459 | return; |
|
460 | 460 | |
|
461 | 461 | if (!qFuzzyIsNull(m_min - min)) { |
|
462 | 462 | m_min = min; |
|
463 | 463 | changed = true; |
|
464 | 464 | |
|
465 | 465 | int imin = m_min + 0.5; |
|
466 | 466 | if (imin >= 0 && imin < m_categories.count()) { |
|
467 | 467 | QString minCategory = m_categories.at(imin); |
|
468 | 468 | if (m_minCategory != minCategory && !minCategory.isEmpty()) { |
|
469 | 469 | m_minCategory = minCategory; |
|
470 | 470 | categoryChanged = true; |
|
471 | 471 | emit q->minChanged(minCategory); |
|
472 | 472 | } |
|
473 | 473 | } |
|
474 | 474 | |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | if (!qFuzzyIsNull(m_max - max)) { |
|
478 | 478 | m_max = max; |
|
479 | 479 | changed = true; |
|
480 | 480 | |
|
481 | 481 | int imax = m_max - 0.5; |
|
482 | 482 | if (imax >= 0 && imax < m_categories.count()) { |
|
483 | 483 | QString maxCategory = m_categories.at(imax); |
|
484 | 484 | if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { |
|
485 | 485 | m_maxCategory = maxCategory; |
|
486 | 486 | categoryChanged = true; |
|
487 | 487 | emit q->maxChanged(maxCategory); |
|
488 | 488 | } |
|
489 | 489 | } |
|
490 | 490 | } |
|
491 | 491 | |
|
492 | 492 | if (categoryChanged){ |
|
493 | 493 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
494 | 494 | } |
|
495 | 495 | |
|
496 | 496 | if (changed) { |
|
497 | 497 | emit rangeChanged(m_min,m_max); |
|
498 | 498 | } |
|
499 | 499 | } |
|
500 | 500 | |
|
501 | 501 | void QBarCategoryAxisPrivate::setRange(const QString &minCategory, const QString &maxCategory) |
|
502 | 502 | { |
|
503 | 503 | Q_Q(QBarCategoryAxis); |
|
504 | 504 | bool changed = false; |
|
505 | 505 | |
|
506 | 506 | //special case in case or clearing all categories |
|
507 | 507 | if (minCategory.isNull() && maxCategory.isNull()) { |
|
508 | 508 | m_minCategory = minCategory; |
|
509 | 509 | m_maxCategory = maxCategory; |
|
510 | 510 | m_min = 0; |
|
511 | 511 | m_max = 0; |
|
512 | 512 | m_count = 0; |
|
513 | 513 | emit q->minChanged(minCategory); |
|
514 | 514 | emit q->maxChanged(maxCategory); |
|
515 | 515 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
516 | 516 | emit rangeChanged(m_min,m_max); |
|
517 | 517 | } |
|
518 | 518 | |
|
519 | 519 | if (m_categories.indexOf(maxCategory) < m_categories.indexOf(minCategory)) |
|
520 | 520 | return; |
|
521 | 521 | |
|
522 | 522 | if (!minCategory.isEmpty() && m_minCategory != minCategory && m_categories.contains(minCategory)) { |
|
523 | 523 | m_minCategory = minCategory; |
|
524 | 524 | m_min = m_categories.indexOf(m_minCategory) - 0.5; |
|
525 | 525 | changed = true; |
|
526 | 526 | emit q->minChanged(minCategory); |
|
527 | 527 | } |
|
528 | 528 | |
|
529 | 529 | if (!maxCategory.isEmpty() && m_maxCategory != maxCategory && m_categories.contains(maxCategory)) { |
|
530 | 530 | m_maxCategory = maxCategory; |
|
531 | 531 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; |
|
532 | 532 | changed = true; |
|
533 | 533 | emit q->maxChanged(maxCategory); |
|
534 | 534 | } |
|
535 | 535 | |
|
536 | 536 | if (changed) { |
|
537 | 537 | m_count = m_max - m_min; |
|
538 | 538 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
539 | 539 | emit rangeChanged(m_min,m_max); |
|
540 | 540 | } |
|
541 | 541 | } |
|
542 | 542 | |
|
543 | 543 | void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
544 | 544 | { |
|
545 | 545 | Q_Q(QBarCategoryAxis); |
|
546 | 546 | ChartAxisElement* axis(0); |
|
547 | 547 | if (orientation() == Qt::Vertical) |
|
548 | 548 | axis = new ChartBarCategoryAxisY(q,parent); |
|
549 | 549 | if (orientation() == Qt::Horizontal) |
|
550 | 550 | axis = new ChartBarCategoryAxisX(q,parent); |
|
551 | 551 | |
|
552 | 552 | m_item.reset(axis); |
|
553 | 553 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
554 | 554 | } |
|
555 | 555 | |
|
556 | 556 | void QBarCategoryAxisPrivate::updateCategoryDomain() |
|
557 | 557 | { |
|
558 | 558 | bool changed = false; |
|
559 | 559 | |
|
560 | 560 | qreal tmpMin = m_categories.indexOf(m_minCategory) - 0.5; |
|
561 | 561 | if (!qFuzzyIsNull(m_min - tmpMin)) { |
|
562 | 562 | m_min = tmpMin; |
|
563 | 563 | changed = true; |
|
564 | 564 | } |
|
565 | 565 | qreal tmpMax = m_categories.indexOf(m_maxCategory) + 0.5; |
|
566 | 566 | if (!qFuzzyIsNull(m_max - tmpMax)) { |
|
567 | 567 | m_max = tmpMax; |
|
568 | 568 | changed = true; |
|
569 | 569 | } |
|
570 | 570 | m_count = m_max - m_min; |
|
571 | 571 | |
|
572 | 572 | if (changed) |
|
573 | 573 | emit rangeChanged(m_min,m_max); |
|
574 | 574 | } |
|
575 | 575 | |
|
576 | 576 | |
|
577 | 577 | void QBarCategoryAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
578 | 578 | { |
|
579 | 579 | Q_Q(QBarCategoryAxis); |
|
580 | 580 | if (m_max == m_min) { |
|
581 | 581 | int min; |
|
582 | 582 | int max; |
|
583 | 583 | if (orientation() == Qt::Vertical) { |
|
584 | 584 | min = domain->minY() + 0.5; |
|
585 | 585 | max = domain->maxY() - 0.5; |
|
586 | 586 | } else { |
|
587 | 587 | min = domain->minX() + 0.5; |
|
588 | 588 | max = domain->maxX() - 0.5; |
|
589 | 589 | } |
|
590 | 590 | |
|
591 | 591 | if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) |
|
592 | 592 | q->setRange(m_categories.at(min), m_categories.at(max)); |
|
593 | 593 | } else { |
|
594 | 594 | if (orientation() == Qt::Vertical) |
|
595 | 595 | domain->setRangeY(m_min, m_max); |
|
596 | 596 | else |
|
597 | 597 | domain->setRangeX(m_min, m_max); |
|
598 | 598 | } |
|
599 | 599 | } |
|
600 | 600 | |
|
601 | 601 | #include "moc_qbarcategoryaxis.cpp" |
|
602 | 602 | #include "moc_qbarcategoryaxis_p.cpp" |
|
603 | 603 | |
|
604 | 604 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,342 +1,342 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qcategoryaxis.h" |
|
22 | 22 | #include "qcategoryaxis_p.h" |
|
23 | 23 | #include "chartcategoryaxisx_p.h" |
|
24 | 24 | #include "chartcategoryaxisy_p.h" |
|
25 | 25 | #include "polarchartcategoryaxisangular_p.h" |
|
26 | 26 | #include "polarchartcategoryaxisradial_p.h" |
|
27 | 27 | #include "qchart.h" |
|
28 | 28 | #include <qmath.h> |
|
29 | 29 | #include <QDebug> |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | /*! |
|
33 | 33 | \class QCategoryAxis |
|
34 | 34 | \inmodule Qt Charts |
|
35 | 35 | \brief The QCategoryAxis class allows putting a named ranges on the axis. |
|
36 | 36 | \mainclass |
|
37 | 37 | |
|
38 | 38 | This class can be used when the underlying data needs to be given extra meaning. |
|
39 | 39 | Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely. |
|
40 | 40 | |
|
41 | 41 | Example code on how to use QCategoryAxis: |
|
42 | 42 | \table |
|
43 | 43 | \row |
|
44 | 44 | \li \br |
|
45 | 45 | \br |
|
46 | 46 | \code |
|
47 | 47 | QChartView *chartView = new QChartView; |
|
48 | 48 | QLineSeries *series = new QLineSeries; |
|
49 | 49 | // ... |
|
50 | 50 | chartView->chart()->addSeries(series); |
|
51 | 51 | |
|
52 | 52 | QCategoryAxis *axisY = new QCategoryAxis; |
|
53 | 53 | axisY->setMin(0); |
|
54 | 54 | axisY->setMax(52); |
|
55 | 55 | axisY->setStartValue(15); |
|
56 | 56 | axisY->append("First", 20); |
|
57 | 57 | axisY->append("Second", 37); |
|
58 | 58 | axisY->append("Third", 52); |
|
59 | 59 | chartView->chart()->setAxisY(axisY, series); |
|
60 | 60 | \endcode |
|
61 | 61 | \li \br |
|
62 | 62 | \inlineimage api_category_axis.png |
|
63 | 63 | \endtable |
|
64 | 64 | */ |
|
65 | 65 | #ifdef QDOC_QT5 |
|
66 | 66 | /*! |
|
67 | 67 | \qmltype CategoryAxis |
|
68 | 68 | \instantiates QCategoryAxis |
|
69 | 69 | \inqmlmodule QtCommercial.Chart |
|
70 | 70 | |
|
71 |
\include |
|
|
71 | \include doc/src/categoryaxis.qdocinc | |
|
72 | 72 | */ |
|
73 | 73 | #else |
|
74 | 74 | /*! |
|
75 | 75 | \qmlclass CategoryAxis QCategoryAxis |
|
76 | 76 | |
|
77 | 77 | \include ../doc/src/categoryaxis.qdocinc |
|
78 | 78 | */ |
|
79 | 79 | #endif |
|
80 | 80 | |
|
81 | 81 | /*! |
|
82 | 82 | \property QCategoryAxis::startValue |
|
83 | 83 | Defines the low end of the first category on the axis. |
|
84 | 84 | */ |
|
85 | 85 | /*! |
|
86 | 86 | \qmlproperty int CategoryAxis::startValue |
|
87 | 87 | Defines the low end of the first category on the axis. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \property QCategoryAxis::count |
|
92 | 92 | The count of categories. |
|
93 | 93 | */ |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty int CategoryAxis::count |
|
96 | 96 | The count of categories. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QCategoryAxis::categoriesLabels |
|
101 | 101 | The category labels as a string list. |
|
102 | 102 | */ |
|
103 | 103 | /*! |
|
104 | 104 | \qmlproperty StringList CategoryAxis::categoriesLabels |
|
105 | 105 | The category labels as a list of strings. |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \fn void QCategoryAxis::categoriesChanged() |
|
110 | 110 | Axis emits signal when the categories of the axis have changed. |
|
111 | 111 | */ |
|
112 | 112 | |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | Constructs an axis object which is a child of \a parent. |
|
116 | 116 | */ |
|
117 | 117 | QCategoryAxis::QCategoryAxis(QObject *parent): |
|
118 | 118 | QValueAxis(*new QCategoryAxisPrivate(this), parent) |
|
119 | 119 | { |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | Destroys the object |
|
124 | 124 | */ |
|
125 | 125 | QCategoryAxis::~QCategoryAxis() |
|
126 | 126 | { |
|
127 | 127 | Q_D(QCategoryAxis); |
|
128 | 128 | if (d->m_chart) |
|
129 | 129 | d->m_chart->removeAxis(this); |
|
130 | 130 | } |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \internal |
|
134 | 134 | */ |
|
135 | 135 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d, QObject *parent): QValueAxis(d, parent) |
|
136 | 136 | { |
|
137 | 137 | |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | /*! |
|
141 | 141 | \qmlmethod CategoryAxis::append(string label, real endValue) |
|
142 | 142 | Appends new category to the axis with an \a label. Category label has to be unique. |
|
143 | 143 | Parameter \a endValue specifies the high end limit of the category. |
|
144 | 144 | It has to be greater than the high end limit of the previous category. |
|
145 | 145 | Otherwise the method returns without adding a new category. |
|
146 | 146 | */ |
|
147 | 147 | /*! |
|
148 | 148 | Appends new category to the axis with an \a categoryLabel. |
|
149 | 149 | Category label has to be unique. |
|
150 | 150 | Parameter \a categoryEndValue specifies the high end limit of the category. |
|
151 | 151 | It has to be greater than the high end limit of the previous category. |
|
152 | 152 | Otherwise the method returns without adding a new category. |
|
153 | 153 | */ |
|
154 | 154 | void QCategoryAxis::append(const QString &categoryLabel, qreal categoryEndValue) |
|
155 | 155 | { |
|
156 | 156 | Q_D(QCategoryAxis); |
|
157 | 157 | |
|
158 | 158 | if (!d->m_categories.contains(categoryLabel)) { |
|
159 | 159 | if (d->m_categories.isEmpty()) { |
|
160 | 160 | Range range(d->m_categoryMinimum, categoryEndValue); |
|
161 | 161 | d->m_categoriesMap.insert(categoryLabel, range); |
|
162 | 162 | d->m_categories.append(categoryLabel); |
|
163 | 163 | emit categoriesChanged(); |
|
164 | 164 | } else if (categoryEndValue > endValue(d->m_categories.last())) { |
|
165 | 165 | Range previousRange = d->m_categoriesMap.value(d->m_categories.last()); |
|
166 | 166 | d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue)); |
|
167 | 167 | d->m_categories.append(categoryLabel); |
|
168 | 168 | emit categoriesChanged(); |
|
169 | 169 | } |
|
170 | 170 | } |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | Sets \a min to be the low end limit of the first category on the axis. |
|
175 | 175 | If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range. |
|
176 | 176 | Otherwise nothing is done. |
|
177 | 177 | */ |
|
178 | 178 | void QCategoryAxis::setStartValue(qreal min) |
|
179 | 179 | { |
|
180 | 180 | Q_D(QCategoryAxis); |
|
181 | 181 | if (d->m_categories.isEmpty()) { |
|
182 | 182 | d->m_categoryMinimum = min; |
|
183 | 183 | emit categoriesChanged(); |
|
184 | 184 | } else { |
|
185 | 185 | Range range = d->m_categoriesMap.value(d->m_categories.first()); |
|
186 | 186 | if (min < range.second) { |
|
187 | 187 | d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second)); |
|
188 | 188 | emit categoriesChanged(); |
|
189 | 189 | } |
|
190 | 190 | } |
|
191 | 191 | } |
|
192 | 192 | |
|
193 | 193 | /*! |
|
194 | 194 | Returns the low end limit of the category specified by an \a categoryLabel |
|
195 | 195 | */ |
|
196 | 196 | qreal QCategoryAxis::startValue(const QString &categoryLabel) const |
|
197 | 197 | { |
|
198 | 198 | Q_D(const QCategoryAxis); |
|
199 | 199 | if (categoryLabel.isEmpty()) |
|
200 | 200 | return d->m_categoryMinimum; |
|
201 | 201 | return d->m_categoriesMap.value(categoryLabel).first; |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 | 205 | Returns the high end limit of the interval specified by an \a categoryLabel |
|
206 | 206 | */ |
|
207 | 207 | qreal QCategoryAxis::endValue(const QString &categoryLabel) const |
|
208 | 208 | { |
|
209 | 209 | Q_D(const QCategoryAxis); |
|
210 | 210 | return d->m_categoriesMap.value(categoryLabel).second; |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | \qmlmethod CategoryAxis::remove(string label) |
|
215 | 215 | Removes a category specified by the \a label from the axis |
|
216 | 216 | */ |
|
217 | 217 | /*! |
|
218 | 218 | Removes an interval specified by the \a categoryLabel from the axis |
|
219 | 219 | */ |
|
220 | 220 | void QCategoryAxis::remove(const QString &categoryLabel) |
|
221 | 221 | { |
|
222 | 222 | Q_D(QCategoryAxis); |
|
223 | 223 | int labelIndex = d->m_categories.indexOf(categoryLabel); |
|
224 | 224 | |
|
225 | 225 | // check if such label exists |
|
226 | 226 | if (labelIndex != -1) { |
|
227 | 227 | d->m_categories.removeAt(labelIndex); |
|
228 | 228 | d->m_categoriesMap.remove(categoryLabel); |
|
229 | 229 | |
|
230 | 230 | // the range of the interval that follows (if exists) needs to be updated |
|
231 | 231 | if (labelIndex < d->m_categories.count()) { |
|
232 | 232 | QString label = d->m_categories.at(labelIndex); |
|
233 | 233 | Range range = d->m_categoriesMap.value(label); |
|
234 | 234 | |
|
235 | 235 | // set the range |
|
236 | 236 | if (labelIndex == 0) { |
|
237 | 237 | range.first = d->m_categoryMinimum; |
|
238 | 238 | d->m_categoriesMap.insert(label, range); |
|
239 | 239 | } else { |
|
240 | 240 | range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second; |
|
241 | 241 | d->m_categoriesMap.insert(label, range); |
|
242 | 242 | } |
|
243 | 243 | } |
|
244 | 244 | emit categoriesChanged(); |
|
245 | 245 | } |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | /*! |
|
249 | 249 | \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel) |
|
250 | 250 | Replaces \a oldLabel of an existing category with a \a newLabel. |
|
251 | 251 | If the old label does not exist the method returns without making any changes. |
|
252 | 252 | */ |
|
253 | 253 | /*! |
|
254 | 254 | Replaces \a oldLabel of an existing category with a \a newLabel |
|
255 | 255 | If the old label does not exist the method returns without making any changes. |
|
256 | 256 | */ |
|
257 | 257 | void QCategoryAxis::replaceLabel(const QString &oldLabel, const QString &newLabel) |
|
258 | 258 | { |
|
259 | 259 | Q_D(QCategoryAxis); |
|
260 | 260 | int labelIndex = d->m_categories.indexOf(oldLabel); |
|
261 | 261 | |
|
262 | 262 | // check if such label exists |
|
263 | 263 | if (labelIndex != -1) { |
|
264 | 264 | d->m_categories.replace(labelIndex, newLabel); |
|
265 | 265 | Range range = d->m_categoriesMap.value(oldLabel); |
|
266 | 266 | d->m_categoriesMap.remove(oldLabel); |
|
267 | 267 | d->m_categoriesMap.insert(newLabel, range); |
|
268 | 268 | emit categoriesChanged(); |
|
269 | 269 | } |
|
270 | 270 | } |
|
271 | 271 | |
|
272 | 272 | /*! |
|
273 | 273 | Returns the list of the intervals labels |
|
274 | 274 | */ |
|
275 | 275 | QStringList QCategoryAxis::categoriesLabels() |
|
276 | 276 | { |
|
277 | 277 | Q_D(QCategoryAxis); |
|
278 | 278 | return d->m_categories; |
|
279 | 279 | } |
|
280 | 280 | |
|
281 | 281 | /*! |
|
282 | 282 | Returns number of intervals. |
|
283 | 283 | */ |
|
284 | 284 | int QCategoryAxis::count() const |
|
285 | 285 | { |
|
286 | 286 | Q_D(const QCategoryAxis); |
|
287 | 287 | return d->m_categories.count(); |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | /*! |
|
291 | 291 | Returns the type of the axis |
|
292 | 292 | */ |
|
293 | 293 | QAbstractAxis::AxisType QCategoryAxis::type() const |
|
294 | 294 | { |
|
295 | 295 | return QAbstractAxis::AxisTypeCategory; |
|
296 | 296 | } |
|
297 | 297 | |
|
298 | 298 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
299 | 299 | |
|
300 | 300 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis *q) |
|
301 | 301 | : QValueAxisPrivate(q), |
|
302 | 302 | m_categoryMinimum(0) |
|
303 | 303 | { |
|
304 | 304 | |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | QCategoryAxisPrivate::~QCategoryAxisPrivate() |
|
308 | 308 | { |
|
309 | 309 | |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | int QCategoryAxisPrivate::ticksCount() const |
|
313 | 313 | { |
|
314 | 314 | return m_categories.count() + 1; |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | void QCategoryAxisPrivate::initializeGraphics(QGraphicsItem *parent) |
|
318 | 318 | { |
|
319 | 319 | Q_Q(QCategoryAxis); |
|
320 | 320 | ChartAxisElement *axis(0); |
|
321 | 321 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
322 | 322 | if (orientation() == Qt::Vertical) |
|
323 | 323 | axis = new ChartCategoryAxisY(q,parent); |
|
324 | 324 | else if (orientation() == Qt::Horizontal) |
|
325 | 325 | axis = new ChartCategoryAxisX(q,parent); |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
329 | 329 | if (orientation() == Qt::Vertical) |
|
330 | 330 | axis = new PolarChartCategoryAxisRadial(q, parent); |
|
331 | 331 | if (orientation() == Qt::Horizontal) |
|
332 | 332 | axis = new PolarChartCategoryAxisAngular(q, parent); |
|
333 | 333 | } |
|
334 | 334 | |
|
335 | 335 | m_item.reset(axis); |
|
336 | 336 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | #include "moc_qcategoryaxis.cpp" |
|
340 | 340 | #include "moc_qcategoryaxis_p.cpp" |
|
341 | 341 | |
|
342 | 342 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,391 +1,391 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qdatetimeaxis.h" |
|
22 | 22 | #include "qdatetimeaxis_p.h" |
|
23 | 23 | #include "chartdatetimeaxisx_p.h" |
|
24 | 24 | #include "chartdatetimeaxisy_p.h" |
|
25 | 25 | #include "polarchartdatetimeaxisangular_p.h" |
|
26 | 26 | #include "polarchartdatetimeaxisradial_p.h" |
|
27 | 27 | #include "abstractdomain_p.h" |
|
28 | 28 | #include "qchart.h" |
|
29 | 29 | #include <float.h> |
|
30 | 30 | #include <cmath> |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | /*! |
|
34 | 34 | \class QDateTimeAxis |
|
35 | 35 | \inmodule Qt Charts |
|
36 | 36 | \brief The QDateTimeAxis class is used for manipulating chart's axis. |
|
37 | 37 | \mainclass |
|
38 | 38 | |
|
39 | 39 | The labels can be configured by setting an appropriate DateTime format. |
|
40 | 40 | QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE. |
|
41 | 41 | There are also other limitiation related to QDateTime. Please refer to QDateTime documentation. |
|
42 | 42 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
43 | 43 | |
|
44 | 44 | Note: QDateTimeAxis is disabled on ARM architecture. |
|
45 | 45 | |
|
46 | 46 | \image api_datatime_axis.png |
|
47 | 47 | |
|
48 | 48 | QDateTimeAxis can be used with any QXYSeries. |
|
49 | 49 | To add a data point to the series QDateTime::toMSecsSinceEpoch() is used. |
|
50 | 50 | \code |
|
51 | 51 | QLineSeries *series = new QLineSeries; |
|
52 | 52 | |
|
53 | 53 | QDateTime xValue; |
|
54 | 54 | xValue.setDate(QDate(2012, 1 , 18)); |
|
55 | 55 | xValue.setTime(QTime(9, 34)); |
|
56 | 56 | qreal yValue = 12; |
|
57 | 57 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
58 | 58 | |
|
59 | 59 | xValue.setDate(QDate(2013, 5 , 11)); |
|
60 | 60 | xValue.setTime(QTime(11, 14)); |
|
61 | 61 | qreal yValue = 22; |
|
62 | 62 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
63 | 63 | \endcode |
|
64 | 64 | |
|
65 | 65 | Adding the series to the chart and setting up the QDateTimeAxis. |
|
66 | 66 | \code |
|
67 | 67 | QChartView *chartView = new QChartView; |
|
68 | 68 | chartView->chart()->addSeries(series); |
|
69 | 69 | |
|
70 | 70 | // ... |
|
71 | 71 | QDateTimeAxis *axisX = new QDateTimeAxis; |
|
72 | 72 | axisX->setFormat("dd-MM-yyyy h:mm"); |
|
73 | 73 | chartView->chart()->setAxisX(axisX, series); |
|
74 | 74 | \endcode |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | #ifdef QDOC_QT5 |
|
78 | 78 | /*! |
|
79 | 79 | \qmltype DateTimeAxis |
|
80 | 80 | \instantiates QDateTimeAxis |
|
81 | 81 | \inqmlmodule QtCommercial.Chart |
|
82 | 82 | |
|
83 |
\include |
|
|
83 | \include doc/src/datetimeaxis.qdocinc | |
|
84 | 84 | */ |
|
85 | 85 | #else |
|
86 | 86 | /*! |
|
87 | 87 | \qmlclass DateTimeAxis QDateTimeAxis |
|
88 | 88 | |
|
89 | 89 | \include ../doc/src/datetimeaxis.qdocinc |
|
90 | 90 | */ |
|
91 | 91 | #endif |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \property QDateTimeAxis::min |
|
95 | 95 | Defines the minimum value on the axis. |
|
96 | 96 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty real ValuesAxis::min |
|
100 | 100 | Defines the minimum value on the axis. |
|
101 | 101 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \property QDateTimeAxis::max |
|
106 | 106 | Defines the maximum value on the axis. |
|
107 | 107 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
108 | 108 | */ |
|
109 | 109 | /*! |
|
110 | 110 | \qmlproperty real ValuesAxis::max |
|
111 | 111 | Defines the maximum value on the axis. |
|
112 | 112 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
113 | 113 | */ |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | \fn void QDateTimeAxis::minChanged(QDateTime min) |
|
117 | 117 | Axis emits signal when \a min of axis has changed. |
|
118 | 118 | */ |
|
119 | 119 | /*! |
|
120 | 120 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) |
|
121 | 121 | Axis emits signal when \a min of axis has changed. |
|
122 | 122 | */ |
|
123 | 123 | |
|
124 | 124 | /*! |
|
125 | 125 | \fn void QDateTimeAxis::maxChanged(QDateTime max) |
|
126 | 126 | Axis emits signal when \a max of axis has changed. |
|
127 | 127 | */ |
|
128 | 128 | /*! |
|
129 | 129 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) |
|
130 | 130 | Axis emits signal when \a max of axis has changed. |
|
131 | 131 | */ |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) |
|
135 | 135 | Axis emits signal when \a min or \a max of axis has changed. |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \property QDateTimeAxis::tickCount |
|
140 | 140 | The number of tick marks for the axis. |
|
141 | 141 | */ |
|
142 | 142 | |
|
143 | 143 | /*! |
|
144 | 144 | \qmlproperty int DateTimeAxis::tickCount |
|
145 | 145 | The number of tick marks for the axis. |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | /*! |
|
149 | 149 | \property QDateTimeAxis::format |
|
150 | 150 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
151 | 151 | Check QDateTime documentation for information on how the string should be defined. |
|
152 | 152 | */ |
|
153 | 153 | /*! |
|
154 | 154 | \qmlproperty string DateTimeAxis::format |
|
155 | 155 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
156 | 156 | Check QDateTime documentation for information on how the string should be defined. |
|
157 | 157 | */ |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | \fn void QDateTimeAxis::tickCountChanged(int tickCount) |
|
161 | 161 | Axis emits signal when \a tickCount number on axis have changed. |
|
162 | 162 | */ |
|
163 | 163 | /*! |
|
164 | 164 | \qmlsignal DateTimeAxis::tickCountChanged(int tickCount) |
|
165 | 165 | Axis emits signal when \a tickCount number on axis have changed. |
|
166 | 166 | */ |
|
167 | 167 | |
|
168 | 168 | /*! |
|
169 | 169 | \fn void QDateTimeAxis::formatChanged(QString format) |
|
170 | 170 | Axis emits signal when \a format of the axis has changed. |
|
171 | 171 | */ |
|
172 | 172 | /*! |
|
173 | 173 | \qmlsignal DateTimeAxis::onFormatChanged(string format) |
|
174 | 174 | Axis emits signal when \a format of the axis has changed. |
|
175 | 175 | */ |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | Constructs an axis object which is a child of \a parent. |
|
179 | 179 | */ |
|
180 | 180 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : |
|
181 | 181 | QAbstractAxis(*new QDateTimeAxisPrivate(this), parent) |
|
182 | 182 | { |
|
183 | 183 | |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | 187 | \internal |
|
188 | 188 | */ |
|
189 | 189 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
190 | 190 | { |
|
191 | 191 | |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | /*! |
|
195 | 195 | Destroys the object |
|
196 | 196 | */ |
|
197 | 197 | QDateTimeAxis::~QDateTimeAxis() |
|
198 | 198 | { |
|
199 | 199 | Q_D(QDateTimeAxis); |
|
200 | 200 | if (d->m_chart) |
|
201 | 201 | d->m_chart->removeAxis(this); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | void QDateTimeAxis::setMin(QDateTime min) |
|
205 | 205 | { |
|
206 | 206 | Q_D(QDateTimeAxis); |
|
207 | 207 | if (min.isValid()) |
|
208 | 208 | d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch()))); |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | QDateTime QDateTimeAxis::min() const |
|
212 | 212 | { |
|
213 | 213 | Q_D(const QDateTimeAxis); |
|
214 | 214 | return QDateTime::fromMSecsSinceEpoch(d->m_min); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | void QDateTimeAxis::setMax(QDateTime max) |
|
218 | 218 | { |
|
219 | 219 | Q_D(QDateTimeAxis); |
|
220 | 220 | if (max.isValid()) |
|
221 | 221 | d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch()); |
|
222 | 222 | } |
|
223 | 223 | |
|
224 | 224 | QDateTime QDateTimeAxis::max() const |
|
225 | 225 | { |
|
226 | 226 | Q_D(const QDateTimeAxis); |
|
227 | 227 | return QDateTime::fromMSecsSinceEpoch(d->m_max); |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | Sets range from \a min to \a max on the axis. |
|
232 | 232 | If min is greater than max then this function returns without making any changes. |
|
233 | 233 | */ |
|
234 | 234 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) |
|
235 | 235 | { |
|
236 | 236 | Q_D(QDateTimeAxis); |
|
237 | 237 | if (!min.isValid() || !max.isValid() || min > max) |
|
238 | 238 | return; |
|
239 | 239 | |
|
240 | 240 | d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch()); |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | void QDateTimeAxis::setFormat(QString format) |
|
244 | 244 | { |
|
245 | 245 | Q_D(QDateTimeAxis); |
|
246 | 246 | if (d->m_format != format) { |
|
247 | 247 | d->m_format = format; |
|
248 | 248 | emit formatChanged(format); |
|
249 | 249 | } |
|
250 | 250 | } |
|
251 | 251 | |
|
252 | 252 | QString QDateTimeAxis::format() const |
|
253 | 253 | { |
|
254 | 254 | Q_D(const QDateTimeAxis); |
|
255 | 255 | return d->m_format; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | /*! |
|
259 | 259 | Sets \a count for ticks on the axis. |
|
260 | 260 | */ |
|
261 | 261 | void QDateTimeAxis::setTickCount(int count) |
|
262 | 262 | { |
|
263 | 263 | Q_D(QDateTimeAxis); |
|
264 | 264 | if (d->m_tickCount != count && count >= 2) { |
|
265 | 265 | d->m_tickCount = count; |
|
266 | 266 | emit tickCountChanged(count); |
|
267 | 267 | } |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | \fn int QDateTimeAxis::tickCount() const |
|
272 | 272 | Return number of ticks on the axis |
|
273 | 273 | */ |
|
274 | 274 | int QDateTimeAxis::tickCount() const |
|
275 | 275 | { |
|
276 | 276 | Q_D(const QDateTimeAxis); |
|
277 | 277 | return d->m_tickCount; |
|
278 | 278 | } |
|
279 | 279 | |
|
280 | 280 | /*! |
|
281 | 281 | Returns the type of the axis |
|
282 | 282 | */ |
|
283 | 283 | QAbstractAxis::AxisType QDateTimeAxis::type() const |
|
284 | 284 | { |
|
285 | 285 | return AxisTypeDateTime; |
|
286 | 286 | } |
|
287 | 287 | |
|
288 | 288 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
289 | 289 | |
|
290 | 290 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) |
|
291 | 291 | : QAbstractAxisPrivate(q), |
|
292 | 292 | m_min(0), |
|
293 | 293 | m_max(0), |
|
294 | 294 | m_tickCount(5) |
|
295 | 295 | { |
|
296 | 296 | m_format = "dd-MM-yyyy\nh:mm"; |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
|
300 | 300 | { |
|
301 | 301 | |
|
302 | 302 | } |
|
303 | 303 | |
|
304 | 304 | void QDateTimeAxisPrivate::setRange(qreal min,qreal max) |
|
305 | 305 | { |
|
306 | 306 | Q_Q(QDateTimeAxis); |
|
307 | 307 | |
|
308 | 308 | bool changed = false; |
|
309 | 309 | |
|
310 | 310 | if (m_min != min) { |
|
311 | 311 | m_min = min; |
|
312 | 312 | changed = true; |
|
313 | 313 | emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min)); |
|
314 | 314 | } |
|
315 | 315 | |
|
316 | 316 | if (m_max != max) { |
|
317 | 317 | m_max = max; |
|
318 | 318 | changed = true; |
|
319 | 319 | emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max)); |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | if (changed) { |
|
323 | 323 | emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max)); |
|
324 | 324 | emit rangeChanged(m_min,m_max); |
|
325 | 325 | } |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | |
|
329 | 329 | void QDateTimeAxisPrivate::setMin(const QVariant &min) |
|
330 | 330 | { |
|
331 | 331 | Q_Q(QDateTimeAxis); |
|
332 | 332 | if (min.canConvert(QVariant::DateTime)) |
|
333 | 333 | q->setMin(min.toDateTime()); |
|
334 | 334 | } |
|
335 | 335 | |
|
336 | 336 | void QDateTimeAxisPrivate::setMax(const QVariant &max) |
|
337 | 337 | { |
|
338 | 338 | |
|
339 | 339 | Q_Q(QDateTimeAxis); |
|
340 | 340 | if (max.canConvert(QVariant::DateTime)) |
|
341 | 341 | q->setMax(max.toDateTime()); |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
345 | 345 | { |
|
346 | 346 | Q_Q(QDateTimeAxis); |
|
347 | 347 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) |
|
348 | 348 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
352 | 352 | { |
|
353 | 353 | Q_Q(QDateTimeAxis); |
|
354 | 354 | ChartAxisElement *axis(0); |
|
355 | 355 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
356 | 356 | if (orientation() == Qt::Vertical) |
|
357 | 357 | axis = new ChartDateTimeAxisY(q,parent); |
|
358 | 358 | if (orientation() == Qt::Horizontal) |
|
359 | 359 | axis = new ChartDateTimeAxisX(q,parent); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
363 | 363 | if (orientation() == Qt::Vertical) |
|
364 | 364 | axis = new PolarChartDateTimeAxisRadial(q, parent); |
|
365 | 365 | if (orientation() == Qt::Horizontal) |
|
366 | 366 | axis = new PolarChartDateTimeAxisAngular(q, parent); |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | m_item.reset(axis); |
|
370 | 370 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
374 | 374 | { |
|
375 | 375 | if (m_max == m_min) { |
|
376 | 376 | if (orientation() == Qt::Vertical) |
|
377 | 377 | setRange(domain->minY(), domain->maxY()); |
|
378 | 378 | else |
|
379 | 379 | setRange(domain->minX(), domain->maxX()); |
|
380 | 380 | } else { |
|
381 | 381 | if (orientation() == Qt::Vertical) |
|
382 | 382 | domain->setRangeY(m_min, m_max); |
|
383 | 383 | else |
|
384 | 384 | domain->setRangeX(m_min, m_max); |
|
385 | 385 | } |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | #include "moc_qdatetimeaxis.cpp" |
|
389 | 389 | #include "moc_qdatetimeaxis_p.cpp" |
|
390 | 390 | |
|
391 | 391 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,402 +1,402 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qlogvalueaxis.h" |
|
22 | 22 | #include "qlogvalueaxis_p.h" |
|
23 | 23 | #include "chartlogvalueaxisx_p.h" |
|
24 | 24 | #include "chartlogvalueaxisy_p.h" |
|
25 | 25 | #include "polarchartlogvalueaxisangular_p.h" |
|
26 | 26 | #include "polarchartlogvalueaxisradial_p.h" |
|
27 | 27 | #include "abstractdomain_p.h" |
|
28 | 28 | #include <float.h> |
|
29 | 29 | #include <cmath> |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | /*! |
|
33 | 33 | \class QLogValueAxis |
|
34 | 34 | \inmodule Qt Charts |
|
35 | 35 | \brief The QLogValueAxis class is used for manipulating chart's axis. |
|
36 | 36 | \mainclass |
|
37 | 37 | |
|
38 | 38 | \note If a QLogValueAxis is attached to a series with one or more points with |
|
39 | 39 | negative or zero values on the associated dimension, the series will not be |
|
40 | 40 | plotted at all. This is particularly relevant when XYModelMappers are used, |
|
41 | 41 | since empty cells in models typically contain zero values. |
|
42 | 42 | */ |
|
43 | 43 | |
|
44 | 44 | #ifdef QDOC_QT5 |
|
45 | 45 | /*! |
|
46 | 46 | \qmltype LogValueAxis |
|
47 | 47 | \instantiates QLogValueAxis |
|
48 | 48 | \inqmlmodule QtCommercial.Chart |
|
49 | 49 | |
|
50 |
\include |
|
|
50 | \include doc/src/logvalueaxis.qdocinc | |
|
51 | 51 | */ |
|
52 | 52 | #else |
|
53 | 53 | /*! |
|
54 | 54 | \qmlclass LogValueAxis QLogValueAxis |
|
55 | 55 | |
|
56 | 56 | \include ../doc/src/logvalueaxis.qdocinc |
|
57 | 57 | */ |
|
58 | 58 | #endif |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \property QLogValueAxis::min |
|
62 | 62 | Defines the minimum value on the axis. |
|
63 | 63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
64 | 64 | Value has to be greater than 0. |
|
65 | 65 | */ |
|
66 | 66 | /*! |
|
67 | 67 | \qmlproperty real LogValueAxis::min |
|
68 | 68 | Defines the minimum value on the axis. |
|
69 | 69 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
70 | 70 | Value has to be greater than 0. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QLogValueAxis::max |
|
75 | 75 | Defines the maximum value on the axis. |
|
76 | 76 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
77 | 77 | Value has to be greater than 0. |
|
78 | 78 | */ |
|
79 | 79 | /*! |
|
80 | 80 | \qmlproperty real LogValueAxis::max |
|
81 | 81 | Defines the maximum value on the axis. |
|
82 | 82 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
83 | 83 | Value has to be greater than 0. |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | 87 | \property QLogValueAxis::base |
|
88 | 88 | Defines the base of the logarithm. |
|
89 | 89 | Value has to be greater than 0 and not equal 1 |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty real LogValueAxis::base |
|
93 | 93 | Defines the maximum value on the axis. |
|
94 | 94 | Defines the base of the logarithm. |
|
95 | 95 | Value has to be greater than 0 and not equal 1 |
|
96 | 96 | */ |
|
97 | 97 | |
|
98 | 98 | /*! |
|
99 | 99 | \property QLogValueAxis::labelFormat |
|
100 | 100 | Defines the label format of the axis. |
|
101 | 101 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
102 | 102 | See QString::sprintf() for additional details. |
|
103 | 103 | */ |
|
104 | 104 | /*! |
|
105 | 105 | \qmlproperty real LogValueAxis::labelFormat |
|
106 | 106 | Defines the label format of the axis. |
|
107 | 107 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
108 | 108 | See QString::sprintf() for additional details. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \fn void QLogValueAxis::minChanged(qreal min) |
|
113 | 113 | Axis emits signal when \a min of axis has changed. |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | 116 | \qmlsignal LogValueAxis::onMinChanged(qreal min) |
|
117 | 117 | Axis emits signal when \a min of axis has changed. |
|
118 | 118 | */ |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | \fn void QLogValueAxis::maxChanged(qreal max) |
|
122 | 122 | Axis emits signal when \a max of axis has changed. |
|
123 | 123 | */ |
|
124 | 124 | /*! |
|
125 | 125 | \qmlsignal LogValueAxis::onMaxChanged(qreal max) |
|
126 | 126 | Axis emits signal when \a max of axis has changed. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \fn void QLogValueAxis::rangeChanged(qreal min, qreal max) |
|
131 | 131 | Axis emits signal when \a min or \a max of axis has changed. |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \fn void QLogValueAxis::labelFormatChanged(const QString &format) |
|
136 | 136 | Axis emits signal when \a format of axis labels has changed. |
|
137 | 137 | */ |
|
138 | 138 | /*! |
|
139 | 139 | \qmlsignal LogValueAxis::labelFormatChanged(const QString &format) |
|
140 | 140 | Axis emits signal when \a format of axis labels has changed. |
|
141 | 141 | */ |
|
142 | 142 | |
|
143 | 143 | /*! |
|
144 | 144 | \fn void QLogValueAxis::baseChanged(qreal base) |
|
145 | 145 | Axis emits signal when \a base of logarithm of the axis has changed. |
|
146 | 146 | */ |
|
147 | 147 | /*! |
|
148 | 148 | \qmlsignal LogValueAxis::baseChanged(qreal base) |
|
149 | 149 | Axis emits signal when \a base of logarithm of the axis has changed. |
|
150 | 150 | */ |
|
151 | 151 | |
|
152 | 152 | /*! |
|
153 | 153 | Constructs an axis object which is a child of \a parent. |
|
154 | 154 | */ |
|
155 | 155 | QLogValueAxis::QLogValueAxis(QObject *parent) : |
|
156 | 156 | QAbstractAxis(*new QLogValueAxisPrivate(this), parent) |
|
157 | 157 | { |
|
158 | 158 | |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \internal |
|
163 | 163 | */ |
|
164 | 164 | QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
165 | 165 | { |
|
166 | 166 | |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | /*! |
|
170 | 170 | Destroys the object |
|
171 | 171 | */ |
|
172 | 172 | QLogValueAxis::~QLogValueAxis() |
|
173 | 173 | { |
|
174 | 174 | Q_D(QLogValueAxis); |
|
175 | 175 | if (d->m_chart) |
|
176 | 176 | d->m_chart->removeAxis(this); |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | void QLogValueAxis::setMin(qreal min) |
|
180 | 180 | { |
|
181 | 181 | Q_D(QLogValueAxis); |
|
182 | 182 | setRange(min, qMax(d->m_max, min)); |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | qreal QLogValueAxis::min() const |
|
186 | 186 | { |
|
187 | 187 | Q_D(const QLogValueAxis); |
|
188 | 188 | return d->m_min; |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | void QLogValueAxis::setMax(qreal max) |
|
192 | 192 | { |
|
193 | 193 | Q_D(QLogValueAxis); |
|
194 | 194 | setRange(qMin(d->m_min, max), max); |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | qreal QLogValueAxis::max() const |
|
198 | 198 | { |
|
199 | 199 | Q_D(const QLogValueAxis); |
|
200 | 200 | return d->m_max; |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | Sets range from \a min to \a max on the axis. |
|
205 | 205 | If min is greater than max then this function returns without making any changes. |
|
206 | 206 | */ |
|
207 | 207 | void QLogValueAxis::setRange(qreal min, qreal max) |
|
208 | 208 | { |
|
209 | 209 | Q_D(QLogValueAxis); |
|
210 | 210 | bool changed = false; |
|
211 | 211 | |
|
212 | 212 | if (min > max) |
|
213 | 213 | return; |
|
214 | 214 | |
|
215 | 215 | if (min > 0) { |
|
216 | 216 | if (!qFuzzyCompare(d->m_min, min)) { |
|
217 | 217 | d->m_min = min; |
|
218 | 218 | changed = true; |
|
219 | 219 | emit minChanged(min); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | if (!qFuzzyCompare(d->m_max, max)) { |
|
223 | 223 | d->m_max = max; |
|
224 | 224 | changed = true; |
|
225 | 225 | emit maxChanged(max); |
|
226 | 226 | } |
|
227 | 227 | |
|
228 | 228 | if (changed) { |
|
229 | 229 | emit rangeChanged(min, max); |
|
230 | 230 | emit d->rangeChanged(min,max); |
|
231 | 231 | } |
|
232 | 232 | } |
|
233 | 233 | } |
|
234 | 234 | |
|
235 | 235 | void QLogValueAxis::setLabelFormat(const QString &format) |
|
236 | 236 | { |
|
237 | 237 | Q_D(QLogValueAxis); |
|
238 | 238 | d->m_format = format; |
|
239 | 239 | emit labelFormatChanged(format); |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | QString QLogValueAxis::labelFormat() const |
|
243 | 243 | { |
|
244 | 244 | Q_D(const QLogValueAxis); |
|
245 | 245 | return d->m_format; |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | void QLogValueAxis::setBase(qreal base) |
|
249 | 249 | { |
|
250 | 250 | // check if base is correct |
|
251 | 251 | if (qFuzzyCompare(base, 1)) |
|
252 | 252 | return; |
|
253 | 253 | |
|
254 | 254 | if (base > 0) { |
|
255 | 255 | Q_D(QLogValueAxis); |
|
256 | 256 | d->m_base = base; |
|
257 | 257 | emit baseChanged(base); |
|
258 | 258 | } |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | qreal QLogValueAxis::base() const |
|
262 | 262 | { |
|
263 | 263 | Q_D(const QLogValueAxis); |
|
264 | 264 | return d->m_base; |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | /*! |
|
268 | 268 | Returns the type of the axis |
|
269 | 269 | */ |
|
270 | 270 | QAbstractAxis::AxisType QLogValueAxis::type() const |
|
271 | 271 | { |
|
272 | 272 | return AxisTypeLogValue; |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
276 | 276 | |
|
277 | 277 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) |
|
278 | 278 | : QAbstractAxisPrivate(q), |
|
279 | 279 | m_min(1), |
|
280 | 280 | m_max(1), |
|
281 | 281 | m_base(10), |
|
282 | 282 | m_format(QString::null) |
|
283 | 283 | { |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | QLogValueAxisPrivate::~QLogValueAxisPrivate() |
|
287 | 287 | { |
|
288 | 288 | |
|
289 | 289 | } |
|
290 | 290 | |
|
291 | 291 | void QLogValueAxisPrivate::setMin(const QVariant &min) |
|
292 | 292 | { |
|
293 | 293 | Q_Q(QLogValueAxis); |
|
294 | 294 | bool ok; |
|
295 | 295 | qreal value = min.toReal(&ok); |
|
296 | 296 | if (ok) |
|
297 | 297 | q->setMin(value); |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | void QLogValueAxisPrivate::setMax(const QVariant &max) |
|
301 | 301 | { |
|
302 | 302 | |
|
303 | 303 | Q_Q(QLogValueAxis); |
|
304 | 304 | bool ok; |
|
305 | 305 | qreal value = max.toReal(&ok); |
|
306 | 306 | if (ok) |
|
307 | 307 | q->setMax(value); |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
311 | 311 | { |
|
312 | 312 | Q_Q(QLogValueAxis); |
|
313 | 313 | bool ok1; |
|
314 | 314 | bool ok2; |
|
315 | 315 | qreal value1 = min.toReal(&ok1); |
|
316 | 316 | qreal value2 = max.toReal(&ok2); |
|
317 | 317 | if (ok1 && ok2) |
|
318 | 318 | q->setRange(value1, value2); |
|
319 | 319 | } |
|
320 | 320 | |
|
321 | 321 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) |
|
322 | 322 | { |
|
323 | 323 | Q_Q(QLogValueAxis); |
|
324 | 324 | bool changed = false; |
|
325 | 325 | |
|
326 | 326 | if (min > max) |
|
327 | 327 | return; |
|
328 | 328 | |
|
329 | 329 | if (min > 0) { |
|
330 | 330 | if (!qFuzzyCompare(m_min, min)) { |
|
331 | 331 | m_min = min; |
|
332 | 332 | changed = true; |
|
333 | 333 | emit q->minChanged(min); |
|
334 | 334 | } |
|
335 | 335 | |
|
336 | 336 | if (!qFuzzyCompare(m_max, max)) { |
|
337 | 337 | m_max = max; |
|
338 | 338 | changed = true; |
|
339 | 339 | emit q->maxChanged(max); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | if (changed) { |
|
343 | 343 | emit rangeChanged(min,max); |
|
344 | 344 | emit q->rangeChanged(min, max); |
|
345 | 345 | } |
|
346 | 346 | } |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem *parent) |
|
350 | 350 | { |
|
351 | 351 | Q_Q(QLogValueAxis); |
|
352 | 352 | ChartAxisElement *axis(0); |
|
353 | 353 | |
|
354 | 354 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
355 | 355 | if (orientation() == Qt::Vertical) |
|
356 | 356 | axis = new ChartLogValueAxisY(q,parent); |
|
357 | 357 | if (orientation() == Qt::Horizontal) |
|
358 | 358 | axis = new ChartLogValueAxisX(q,parent); |
|
359 | 359 | } |
|
360 | 360 | |
|
361 | 361 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
362 | 362 | if (orientation() == Qt::Vertical) |
|
363 | 363 | axis = new PolarChartLogValueAxisRadial(q, parent); |
|
364 | 364 | if (orientation() == Qt::Horizontal) |
|
365 | 365 | axis = new PolarChartLogValueAxisAngular(q, parent); |
|
366 | 366 | } |
|
367 | 367 | |
|
368 | 368 | m_item.reset(axis); |
|
369 | 369 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
370 | 370 | } |
|
371 | 371 | |
|
372 | 372 | |
|
373 | 373 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
374 | 374 | { |
|
375 | 375 | if (orientation() == Qt::Vertical) { |
|
376 | 376 | if (!qFuzzyCompare(m_max, m_min)) { |
|
377 | 377 | domain->setRangeY(m_min, m_max); |
|
378 | 378 | } else if ( domain->minY() > 0) { |
|
379 | 379 | setRange(domain->minY(), domain->maxY()); |
|
380 | 380 | } else if (domain->maxY() > 0) { |
|
381 | 381 | domain->setRangeY(m_min, domain->maxY()); |
|
382 | 382 | } else { |
|
383 | 383 | domain->setRangeY(1, 10); |
|
384 | 384 | } |
|
385 | 385 | } |
|
386 | 386 | if (orientation() == Qt::Horizontal) { |
|
387 | 387 | if (!qFuzzyCompare(m_max, m_min)) { |
|
388 | 388 | domain->setRangeX(m_min, m_max); |
|
389 | 389 | } else if (domain->minX() > 0){ |
|
390 | 390 | setRange(domain->minX(), domain->maxX()); |
|
391 | 391 | } else if (domain->maxX() > 0) { |
|
392 | 392 | domain->setRangeX(m_min, domain->maxX()); |
|
393 | 393 | } else { |
|
394 | 394 | domain->setRangeX(1, 10); |
|
395 | 395 | } |
|
396 | 396 | } |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | #include "moc_qlogvalueaxis.cpp" |
|
400 | 400 | #include "moc_qlogvalueaxis_p.cpp" |
|
401 | 401 | |
|
402 | 402 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,1015 +1,1015 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qabstractaxis.h" |
|
22 | 22 | #include "qabstractaxis_p.h" |
|
23 | 23 | #include "chartdataset_p.h" |
|
24 | 24 | #include "charttheme_p.h" |
|
25 | 25 | #include "qchart_p.h" |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \class QAbstractAxis |
|
31 | 31 | \inmodule Qt Charts |
|
32 | 32 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | Each series can be bound to one or more horizontal and vertical axes, but mixing axis types |
|
36 | 36 | that would result in different domains is not supported, such as specifying |
|
37 | 37 | QValueAxis and QLogValueAxis on the same orientation. |
|
38 | 38 | |
|
39 | 39 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, |
|
40 | 40 | and shades can be individually controlled. |
|
41 | 41 | */ |
|
42 | 42 | #ifdef QDOC_QT5 |
|
43 | 43 | /*! |
|
44 | 44 | \qmltype AbstractAxis |
|
45 | 45 | \instantiates QAbstractAxis |
|
46 | 46 | \inqmlmodule QtCommercial.Chart |
|
47 | 47 | |
|
48 |
\include |
|
|
48 | \include doc/src/abstractaxis.qdocinc | |
|
49 | 49 | */ |
|
50 | 50 | #else |
|
51 | 51 | /*! |
|
52 | 52 | \qmlclass AbstractAxis QAbstractAxis |
|
53 | 53 | |
|
54 | 54 | \include ../doc/src/abstractaxis.qdocinc |
|
55 | 55 | */ |
|
56 | 56 | #endif |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \enum QAbstractAxis::AxisType |
|
60 | 60 | |
|
61 | 61 | The type of the series object. |
|
62 | 62 | |
|
63 | 63 | \value AxisTypeNoAxis |
|
64 | 64 | \value AxisTypeValue |
|
65 | 65 | \value AxisTypeBarCategory |
|
66 | 66 | \value AxisTypeCategory |
|
67 | 67 | \value AxisTypeDateTime |
|
68 | 68 | \value AxisTypeLogValue |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | *\fn void QAbstractAxis::type() const |
|
73 | 73 | Returns the type of the axis |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \property QAbstractAxis::lineVisible |
|
78 | 78 | The visibility of the axis line |
|
79 | 79 | */ |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty bool AbstractAxis::lineVisible |
|
82 | 82 | The visibility of the axis line |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QAbstractAxis::linePen |
|
87 | 87 | The pen of the line. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \property QAbstractAxis::labelsVisible |
|
92 | 92 | Defines if axis labels are visible. |
|
93 | 93 | */ |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty bool AbstractAxis::labelsVisible |
|
96 | 96 | Defines if axis labels are visible. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QAbstractAxis::labelsPen |
|
101 | 101 | \deprecated |
|
102 | 102 | The pen of the labels. |
|
103 | 103 | */ |
|
104 | 104 | |
|
105 | 105 | /*! |
|
106 | 106 | \property QAbstractAxis::labelsBrush |
|
107 | 107 | The brush of the labels. Only the color of the brush is relevant. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | \property QAbstractAxis::visible |
|
112 | 112 | The visibility of the axis. |
|
113 | 113 | */ |
|
114 | 114 | /*! |
|
115 | 115 | \qmlproperty bool AbstractAxis::visible |
|
116 | 116 | The visibility of the axis. |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | \property QAbstractAxis::gridVisible |
|
121 | 121 | The visibility of the grid lines. |
|
122 | 122 | */ |
|
123 | 123 | /*! |
|
124 | 124 | \qmlproperty bool AbstractAxis::gridVisible |
|
125 | 125 | The visibility of the grid lines. |
|
126 | 126 | */ |
|
127 | 127 | |
|
128 | 128 | /*! |
|
129 | 129 | \property QAbstractAxis::color |
|
130 | 130 | The color of the axis and ticks. |
|
131 | 131 | */ |
|
132 | 132 | /*! |
|
133 | 133 | \qmlproperty color AbstractAxis::color |
|
134 | 134 | The color of the axis and ticks. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \property QAbstractAxis::gridLinePen |
|
139 | 139 | The pen of the grid line. |
|
140 | 140 | */ |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | \property QAbstractAxis::labelsFont |
|
144 | 144 | The font of the axis labels. |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \qmlproperty Font AbstractAxis::labelsFont |
|
149 | 149 | The font of the axis labels. |
|
150 | 150 | |
|
151 | 151 | See the Qt documentation for more details of Font. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | \property QAbstractAxis::labelsColor |
|
156 | 156 | The color of the axis labels. |
|
157 | 157 | */ |
|
158 | 158 | /*! |
|
159 | 159 | \qmlproperty color AbstractAxis::labelsColor |
|
160 | 160 | The color of the axis labels. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \property QAbstractAxis::labelsAngle |
|
165 | 165 | The angle of the axis labels in degrees. |
|
166 | 166 | */ |
|
167 | 167 | /*! |
|
168 | 168 | \qmlproperty int AbstractAxis::labelsAngle |
|
169 | 169 | The angle of the axis labels in degrees. |
|
170 | 170 | */ |
|
171 | 171 | |
|
172 | 172 | /*! |
|
173 | 173 | \property QAbstractAxis::shadesVisible |
|
174 | 174 | The visibility of the axis shades. |
|
175 | 175 | */ |
|
176 | 176 | /*! |
|
177 | 177 | \qmlproperty bool AbstractAxis::shadesVisible |
|
178 | 178 | The visibility of the axis shades. |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \property QAbstractAxis::shadesColor |
|
183 | 183 | The fill (brush) color of the axis shades. |
|
184 | 184 | */ |
|
185 | 185 | /*! |
|
186 | 186 | \qmlproperty color AbstractAxis::shadesColor |
|
187 | 187 | The fill (brush) color of the axis shades. |
|
188 | 188 | */ |
|
189 | 189 | |
|
190 | 190 | /*! |
|
191 | 191 | \property QAbstractAxis::shadesBorderColor |
|
192 | 192 | The border (pen) color of the axis shades. |
|
193 | 193 | */ |
|
194 | 194 | /*! |
|
195 | 195 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
196 | 196 | The border (pen) color of the axis shades. |
|
197 | 197 | */ |
|
198 | 198 | |
|
199 | 199 | /*! |
|
200 | 200 | \property QAbstractAxis::shadesPen |
|
201 | 201 | The pen of the axis shades (area between grid lines). |
|
202 | 202 | */ |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 | 205 | \property QAbstractAxis::shadesBrush |
|
206 | 206 | The brush of the axis shades (area between grid lines). |
|
207 | 207 | */ |
|
208 | 208 | |
|
209 | 209 | /*! |
|
210 | 210 | \property QAbstractAxis::titleVisible |
|
211 | 211 | The visibility of the axis title. By default the value is true. |
|
212 | 212 | */ |
|
213 | 213 | /*! |
|
214 | 214 | \qmlproperty bool AbstractAxis::titleVisible |
|
215 | 215 | The visibility of the axis title. By default the value is true. |
|
216 | 216 | */ |
|
217 | 217 | |
|
218 | 218 | /*! |
|
219 | 219 | \property QAbstractAxis::titleText |
|
220 | 220 | The title of the axis. Empty by default. Axis titles support html formatting. |
|
221 | 221 | */ |
|
222 | 222 | /*! |
|
223 | 223 | \qmlproperty String AbstractAxis::titleText |
|
224 | 224 | The title of the axis. Empty by default. Axis titles support html formatting. |
|
225 | 225 | */ |
|
226 | 226 | |
|
227 | 227 | /*! |
|
228 | 228 | \property QAbstractAxis::titlePen |
|
229 | 229 | \deprecated |
|
230 | 230 | The pen of the title text. |
|
231 | 231 | */ |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | \property QAbstractAxis::titleBrush |
|
235 | 235 | The brush of the title text. Only the color of the brush is relevant. |
|
236 | 236 | */ |
|
237 | 237 | |
|
238 | 238 | /*! |
|
239 | 239 | \property QAbstractAxis::titleFont |
|
240 | 240 | The font of the title of the axis. |
|
241 | 241 | */ |
|
242 | 242 | /*! |
|
243 | 243 | \qmlproperty Font AbstractAxis::titleFont |
|
244 | 244 | The font of the title of the axis. |
|
245 | 245 | */ |
|
246 | 246 | |
|
247 | 247 | /*! |
|
248 | 248 | \property QAbstractAxis::orientation |
|
249 | 249 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. |
|
250 | 250 | */ |
|
251 | 251 | /*! |
|
252 | 252 | \qmlproperty Qt.Orientation AbstractAxis::orientation |
|
253 | 253 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series. |
|
254 | 254 | */ |
|
255 | 255 | |
|
256 | 256 | /*! |
|
257 | 257 | \property QAbstractAxis::alignment |
|
258 | 258 | The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop. |
|
259 | 259 | */ |
|
260 | 260 | /*! |
|
261 | 261 | \qmlproperty alignment AbstractAxis::alignment |
|
262 | 262 | The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop. |
|
263 | 263 | */ |
|
264 | 264 | |
|
265 | 265 | /*! |
|
266 | 266 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
267 | 267 | Visibility of the axis has changed to \a visible. |
|
268 | 268 | */ |
|
269 | 269 | /*! |
|
270 | 270 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
271 | 271 | Visibility of the axis has changed to \a visible. |
|
272 | 272 | */ |
|
273 | 273 | |
|
274 | 274 | /*! |
|
275 | 275 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) |
|
276 | 276 | The pen of the line of the axis has changed to \a pen. |
|
277 | 277 | */ |
|
278 | 278 | |
|
279 | 279 | /*! |
|
280 | 280 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
281 | 281 | Visibility of the axis line has changed to \a visible. |
|
282 | 282 | */ |
|
283 | 283 | /*! |
|
284 | 284 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
285 | 285 | Visibility of the axis line has changed to \a visible. |
|
286 | 286 | */ |
|
287 | 287 | |
|
288 | 288 | /*! |
|
289 | 289 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
290 | 290 | Visibility of the labels of the axis has changed to \a visible. |
|
291 | 291 | */ |
|
292 | 292 | /*! |
|
293 | 293 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
294 | 294 | Visibility of the labels of the axis has changed to \a visible. |
|
295 | 295 | */ |
|
296 | 296 | |
|
297 | 297 | /*! |
|
298 | 298 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) |
|
299 | 299 | The font of the axis labels has changed to \a font. |
|
300 | 300 | */ |
|
301 | 301 | /*! |
|
302 | 302 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) |
|
303 | 303 | The font of the axis labels has changed to \a font. |
|
304 | 304 | */ |
|
305 | 305 | |
|
306 | 306 | /*! |
|
307 | 307 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) |
|
308 | 308 | \deprecated |
|
309 | 309 | The pen of the axis labels has changed to \a pen. |
|
310 | 310 | */ |
|
311 | 311 | |
|
312 | 312 | /*! |
|
313 | 313 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) |
|
314 | 314 | The brush of the axis labels has changed to \a brush. |
|
315 | 315 | */ |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | \fn void QAbstractAxis::labelsAngleChanged(int angle) |
|
319 | 319 | The angle of the axis labels has changed to \a angle. |
|
320 | 320 | */ |
|
321 | 321 | /*! |
|
322 | 322 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) |
|
323 | 323 | The angle of the axis labels has changed to \a angle. |
|
324 | 324 | */ |
|
325 | 325 | |
|
326 | 326 | /*! |
|
327 | 327 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
328 | 328 | Visibility of the grid lines of the axis has changed to \a visible. |
|
329 | 329 | */ |
|
330 | 330 | /*! |
|
331 | 331 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
332 | 332 | Visibility of the grid lines of the axis has changed to \a visible. |
|
333 | 333 | */ |
|
334 | 334 | |
|
335 | 335 | /*! |
|
336 | 336 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) |
|
337 | 337 | The pen of the grid line has changed to \a pen. |
|
338 | 338 | */ |
|
339 | 339 | |
|
340 | 340 | /*! |
|
341 | 341 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
342 | 342 | Emitted if the \a color of the axis is changed. |
|
343 | 343 | */ |
|
344 | 344 | /*! |
|
345 | 345 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
346 | 346 | Emitted if the \a color of the axis is changed. |
|
347 | 347 | */ |
|
348 | 348 | |
|
349 | 349 | /*! |
|
350 | 350 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
351 | 351 | Emitted if the \a color of the axis labels is changed. |
|
352 | 352 | */ |
|
353 | 353 | /*! |
|
354 | 354 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
355 | 355 | Emitted if the \a color of the axis labels is changed. |
|
356 | 356 | */ |
|
357 | 357 | |
|
358 | 358 | /*! |
|
359 | 359 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) |
|
360 | 360 | Visibility of the title text of the axis has changed to \a visible. |
|
361 | 361 | */ |
|
362 | 362 | /*! |
|
363 | 363 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) |
|
364 | 364 | Visibility of the title text of the axis has changed to \a visible. |
|
365 | 365 | */ |
|
366 | 366 | |
|
367 | 367 | /*! |
|
368 | 368 | \fn void QAbstractAxis::titleTextChanged(const QString& text) |
|
369 | 369 | The text of the axis title has changed to \a text. |
|
370 | 370 | */ |
|
371 | 371 | /*! |
|
372 | 372 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) |
|
373 | 373 | The text of the axis title has changed to \a text. |
|
374 | 374 | */ |
|
375 | 375 | |
|
376 | 376 | /*! |
|
377 | 377 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) |
|
378 | 378 | \deprecated |
|
379 | 379 | The pen of the axis shades has changed to \a pen. |
|
380 | 380 | */ |
|
381 | 381 | |
|
382 | 382 | /*! |
|
383 | 383 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) |
|
384 | 384 | The brush of the axis title has changed to \a brush. |
|
385 | 385 | */ |
|
386 | 386 | |
|
387 | 387 | /*! |
|
388 | 388 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) |
|
389 | 389 | The font of the axis title has changed to \a font. |
|
390 | 390 | */ |
|
391 | 391 | /*! |
|
392 | 392 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) |
|
393 | 393 | The font of the axis title has changed to \a font. |
|
394 | 394 | */ |
|
395 | 395 | |
|
396 | 396 | /*! |
|
397 | 397 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
398 | 398 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
399 | 399 | */ |
|
400 | 400 | /*! |
|
401 | 401 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
402 | 402 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
403 | 403 | */ |
|
404 | 404 | |
|
405 | 405 | /*! |
|
406 | 406 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
407 | 407 | Emitted if the \a color of the axis shades is changed. |
|
408 | 408 | */ |
|
409 | 409 | /*! |
|
410 | 410 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
411 | 411 | Emitted if the \a color of the axis shades is changed. |
|
412 | 412 | */ |
|
413 | 413 | |
|
414 | 414 | /*! |
|
415 | 415 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
416 | 416 | Emitted if the border \a color of the axis shades is changed. |
|
417 | 417 | */ |
|
418 | 418 | /*! |
|
419 | 419 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
420 | 420 | Emitted if the border \a color of the axis shades is changed. |
|
421 | 421 | */ |
|
422 | 422 | |
|
423 | 423 | /*! |
|
424 | 424 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) |
|
425 | 425 | The brush of the axis shades has changed to \a brush. |
|
426 | 426 | */ |
|
427 | 427 | |
|
428 | 428 | /*! |
|
429 | 429 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) |
|
430 | 430 | The pen of the axis shades has changed to \a pen. |
|
431 | 431 | */ |
|
432 | 432 | |
|
433 | 433 | /*! |
|
434 | 434 | \internal |
|
435 | 435 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
436 | 436 | QChart when axis added. |
|
437 | 437 | */ |
|
438 | 438 | |
|
439 | 439 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
440 | 440 | : QObject(parent), |
|
441 | 441 | d_ptr(&d) |
|
442 | 442 | { |
|
443 | 443 | } |
|
444 | 444 | |
|
445 | 445 | /*! |
|
446 | 446 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
447 | 447 | */ |
|
448 | 448 | |
|
449 | 449 | QAbstractAxis::~QAbstractAxis() |
|
450 | 450 | { |
|
451 | 451 | if (d_ptr->m_chart) |
|
452 | 452 | qFatal("Still binded axis detected !"); |
|
453 | 453 | } |
|
454 | 454 | |
|
455 | 455 | /*! |
|
456 | 456 | Sets \a pen used to draw axis line and ticks. |
|
457 | 457 | */ |
|
458 | 458 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
459 | 459 | { |
|
460 | 460 | if (d_ptr->m_axisPen != pen) { |
|
461 | 461 | d_ptr->m_axisPen = pen; |
|
462 | 462 | emit linePenChanged(pen); |
|
463 | 463 | } |
|
464 | 464 | } |
|
465 | 465 | |
|
466 | 466 | /*! |
|
467 | 467 | Returns pen used to draw axis and ticks. |
|
468 | 468 | */ |
|
469 | 469 | QPen QAbstractAxis::linePen() const |
|
470 | 470 | { |
|
471 | 471 | if (d_ptr->m_axisPen == QChartPrivate::defaultPen()) |
|
472 | 472 | return QPen(); |
|
473 | 473 | else |
|
474 | 474 | return d_ptr->m_axisPen; |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | void QAbstractAxis::setLinePenColor(QColor color) |
|
478 | 478 | { |
|
479 | 479 | QPen p = d_ptr->m_axisPen; |
|
480 | 480 | if (p.color() != color) { |
|
481 | 481 | p.setColor(color); |
|
482 | 482 | setLinePen(p); |
|
483 | 483 | emit colorChanged(color); |
|
484 | 484 | } |
|
485 | 485 | } |
|
486 | 486 | |
|
487 | 487 | QColor QAbstractAxis::linePenColor() const |
|
488 | 488 | { |
|
489 | 489 | return linePen().color(); |
|
490 | 490 | } |
|
491 | 491 | |
|
492 | 492 | /*! |
|
493 | 493 | Sets if axis and ticks are \a visible. |
|
494 | 494 | */ |
|
495 | 495 | void QAbstractAxis::setLineVisible(bool visible) |
|
496 | 496 | { |
|
497 | 497 | if (d_ptr->m_arrowVisible != visible) { |
|
498 | 498 | d_ptr->m_arrowVisible = visible; |
|
499 | 499 | emit lineVisibleChanged(visible); |
|
500 | 500 | } |
|
501 | 501 | } |
|
502 | 502 | |
|
503 | 503 | bool QAbstractAxis::isLineVisible() const |
|
504 | 504 | { |
|
505 | 505 | return d_ptr->m_arrowVisible; |
|
506 | 506 | } |
|
507 | 507 | |
|
508 | 508 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
509 | 509 | { |
|
510 | 510 | if (d_ptr->m_gridLineVisible != visible) { |
|
511 | 511 | d_ptr->m_gridLineVisible = visible; |
|
512 | 512 | emit gridVisibleChanged(visible); |
|
513 | 513 | } |
|
514 | 514 | } |
|
515 | 515 | |
|
516 | 516 | bool QAbstractAxis::isGridLineVisible() const |
|
517 | 517 | { |
|
518 | 518 | return d_ptr->m_gridLineVisible; |
|
519 | 519 | } |
|
520 | 520 | |
|
521 | 521 | /*! |
|
522 | 522 | Sets \a pen used to draw grid line. |
|
523 | 523 | */ |
|
524 | 524 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
525 | 525 | { |
|
526 | 526 | if (d_ptr->m_gridLinePen != pen) { |
|
527 | 527 | d_ptr->m_gridLinePen = pen; |
|
528 | 528 | emit gridLinePenChanged(pen); |
|
529 | 529 | } |
|
530 | 530 | } |
|
531 | 531 | |
|
532 | 532 | /*! |
|
533 | 533 | Returns pen used to draw grid. |
|
534 | 534 | */ |
|
535 | 535 | QPen QAbstractAxis::gridLinePen() const |
|
536 | 536 | { |
|
537 | 537 | if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen()) |
|
538 | 538 | return QPen(); |
|
539 | 539 | else |
|
540 | 540 | return d_ptr->m_gridLinePen; |
|
541 | 541 | } |
|
542 | 542 | |
|
543 | 543 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
544 | 544 | { |
|
545 | 545 | if (d_ptr->m_labelsVisible != visible) { |
|
546 | 546 | d_ptr->m_labelsVisible = visible; |
|
547 | 547 | emit labelsVisibleChanged(visible); |
|
548 | 548 | } |
|
549 | 549 | } |
|
550 | 550 | |
|
551 | 551 | bool QAbstractAxis::labelsVisible() const |
|
552 | 552 | { |
|
553 | 553 | return d_ptr->m_labelsVisible; |
|
554 | 554 | } |
|
555 | 555 | |
|
556 | 556 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
557 | 557 | { |
|
558 | 558 | if (d_ptr->m_labelsPen != pen) { |
|
559 | 559 | d_ptr->m_labelsPen = pen; |
|
560 | 560 | emit labelsPenChanged(pen); |
|
561 | 561 | } |
|
562 | 562 | } |
|
563 | 563 | |
|
564 | 564 | QPen QAbstractAxis::labelsPen() const |
|
565 | 565 | { |
|
566 | 566 | if (d_ptr->m_labelsPen == QChartPrivate::defaultPen()) |
|
567 | 567 | return QPen(); |
|
568 | 568 | else |
|
569 | 569 | return d_ptr->m_labelsPen; |
|
570 | 570 | } |
|
571 | 571 | |
|
572 | 572 | /*! |
|
573 | 573 | Sets \a brush used to draw labels. |
|
574 | 574 | */ |
|
575 | 575 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
576 | 576 | { |
|
577 | 577 | if (d_ptr->m_labelsBrush != brush) { |
|
578 | 578 | d_ptr->m_labelsBrush = brush; |
|
579 | 579 | emit labelsBrushChanged(brush); |
|
580 | 580 | } |
|
581 | 581 | } |
|
582 | 582 | |
|
583 | 583 | /*! |
|
584 | 584 | Returns brush used to draw labels. |
|
585 | 585 | */ |
|
586 | 586 | QBrush QAbstractAxis::labelsBrush() const |
|
587 | 587 | { |
|
588 | 588 | if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush()) |
|
589 | 589 | return QBrush(); |
|
590 | 590 | else |
|
591 | 591 | return d_ptr->m_labelsBrush; |
|
592 | 592 | } |
|
593 | 593 | |
|
594 | 594 | /*! |
|
595 | 595 | Sets \a font used to draw labels. |
|
596 | 596 | */ |
|
597 | 597 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
598 | 598 | { |
|
599 | 599 | if (d_ptr->m_labelsFont != font) { |
|
600 | 600 | d_ptr->m_labelsFont = font; |
|
601 | 601 | emit labelsFontChanged(font); |
|
602 | 602 | } |
|
603 | 603 | } |
|
604 | 604 | |
|
605 | 605 | /*! |
|
606 | 606 | Returns font used to draw labels. |
|
607 | 607 | */ |
|
608 | 608 | QFont QAbstractAxis::labelsFont() const |
|
609 | 609 | { |
|
610 | 610 | if (d_ptr->m_labelsFont == QChartPrivate::defaultFont()) |
|
611 | 611 | return QFont(); |
|
612 | 612 | else |
|
613 | 613 | return d_ptr->m_labelsFont; |
|
614 | 614 | } |
|
615 | 615 | |
|
616 | 616 | void QAbstractAxis::setLabelsAngle(int angle) |
|
617 | 617 | { |
|
618 | 618 | if (d_ptr->m_labelsAngle != angle) { |
|
619 | 619 | d_ptr->m_labelsAngle = angle; |
|
620 | 620 | emit labelsAngleChanged(angle); |
|
621 | 621 | } |
|
622 | 622 | } |
|
623 | 623 | |
|
624 | 624 | int QAbstractAxis::labelsAngle() const |
|
625 | 625 | { |
|
626 | 626 | return d_ptr->m_labelsAngle; |
|
627 | 627 | } |
|
628 | 628 | void QAbstractAxis::setLabelsColor(QColor color) |
|
629 | 629 | { |
|
630 | 630 | QBrush b = d_ptr->m_labelsBrush; |
|
631 | 631 | if (b.color() != color) { |
|
632 | 632 | b.setColor(color); |
|
633 | 633 | setLabelsBrush(b); |
|
634 | 634 | emit labelsColorChanged(color); |
|
635 | 635 | } |
|
636 | 636 | } |
|
637 | 637 | |
|
638 | 638 | QColor QAbstractAxis::labelsColor() const |
|
639 | 639 | { |
|
640 | 640 | return labelsBrush().color(); |
|
641 | 641 | } |
|
642 | 642 | |
|
643 | 643 | void QAbstractAxis::setTitleVisible(bool visible) |
|
644 | 644 | { |
|
645 | 645 | if (d_ptr->m_titleVisible != visible) { |
|
646 | 646 | d_ptr->m_titleVisible = visible; |
|
647 | 647 | emit titleVisibleChanged(visible); |
|
648 | 648 | } |
|
649 | 649 | } |
|
650 | 650 | |
|
651 | 651 | bool QAbstractAxis::isTitleVisible() const |
|
652 | 652 | { |
|
653 | 653 | return d_ptr->m_titleVisible; |
|
654 | 654 | } |
|
655 | 655 | |
|
656 | 656 | void QAbstractAxis::setTitlePen(const QPen &pen) |
|
657 | 657 | { |
|
658 | 658 | if (d_ptr->m_titlePen != pen) { |
|
659 | 659 | d_ptr->m_titlePen = pen; |
|
660 | 660 | emit titlePenChanged(pen); |
|
661 | 661 | } |
|
662 | 662 | } |
|
663 | 663 | |
|
664 | 664 | QPen QAbstractAxis::titlePen() const |
|
665 | 665 | { |
|
666 | 666 | if (d_ptr->m_titlePen == QChartPrivate::defaultPen()) |
|
667 | 667 | return QPen(); |
|
668 | 668 | else |
|
669 | 669 | return d_ptr->m_titlePen; |
|
670 | 670 | } |
|
671 | 671 | |
|
672 | 672 | /*! |
|
673 | 673 | Sets \a brush used to draw title. |
|
674 | 674 | */ |
|
675 | 675 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
|
676 | 676 | { |
|
677 | 677 | if (d_ptr->m_titleBrush != brush) { |
|
678 | 678 | d_ptr->m_titleBrush = brush; |
|
679 | 679 | emit titleBrushChanged(brush); |
|
680 | 680 | } |
|
681 | 681 | } |
|
682 | 682 | |
|
683 | 683 | /*! |
|
684 | 684 | Returns brush used to draw title. |
|
685 | 685 | */ |
|
686 | 686 | QBrush QAbstractAxis::titleBrush() const |
|
687 | 687 | { |
|
688 | 688 | if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush()) |
|
689 | 689 | return QBrush(); |
|
690 | 690 | else |
|
691 | 691 | return d_ptr->m_titleBrush; |
|
692 | 692 | } |
|
693 | 693 | |
|
694 | 694 | /*! |
|
695 | 695 | Sets \a font used to draw title. |
|
696 | 696 | */ |
|
697 | 697 | void QAbstractAxis::setTitleFont(const QFont &font) |
|
698 | 698 | { |
|
699 | 699 | if (d_ptr->m_titleFont != font) { |
|
700 | 700 | d_ptr->m_titleFont = font; |
|
701 | 701 | emit titleFontChanged(font); |
|
702 | 702 | } |
|
703 | 703 | } |
|
704 | 704 | |
|
705 | 705 | /*! |
|
706 | 706 | Returns font used to draw title. |
|
707 | 707 | */ |
|
708 | 708 | QFont QAbstractAxis::titleFont() const |
|
709 | 709 | { |
|
710 | 710 | if (d_ptr->m_titleFont == QChartPrivate::defaultFont()) |
|
711 | 711 | return QFont(); |
|
712 | 712 | else |
|
713 | 713 | return d_ptr->m_titleFont; |
|
714 | 714 | } |
|
715 | 715 | |
|
716 | 716 | void QAbstractAxis::setTitleText(const QString &title) |
|
717 | 717 | { |
|
718 | 718 | if (d_ptr->m_title != title) { |
|
719 | 719 | d_ptr->m_title = title; |
|
720 | 720 | emit titleTextChanged(title); |
|
721 | 721 | } |
|
722 | 722 | } |
|
723 | 723 | |
|
724 | 724 | QString QAbstractAxis::titleText() const |
|
725 | 725 | { |
|
726 | 726 | return d_ptr->m_title; |
|
727 | 727 | } |
|
728 | 728 | |
|
729 | 729 | |
|
730 | 730 | void QAbstractAxis::setShadesVisible(bool visible) |
|
731 | 731 | { |
|
732 | 732 | if (d_ptr->m_shadesVisible != visible) { |
|
733 | 733 | d_ptr->m_shadesVisible = visible; |
|
734 | 734 | emit shadesVisibleChanged(visible); |
|
735 | 735 | } |
|
736 | 736 | } |
|
737 | 737 | |
|
738 | 738 | bool QAbstractAxis::shadesVisible() const |
|
739 | 739 | { |
|
740 | 740 | return d_ptr->m_shadesVisible; |
|
741 | 741 | } |
|
742 | 742 | |
|
743 | 743 | /*! |
|
744 | 744 | Sets \a pen used to draw shades. |
|
745 | 745 | */ |
|
746 | 746 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
747 | 747 | { |
|
748 | 748 | if (d_ptr->m_shadesPen != pen) { |
|
749 | 749 | d_ptr->m_shadesPen = pen; |
|
750 | 750 | emit shadesPenChanged(pen); |
|
751 | 751 | } |
|
752 | 752 | } |
|
753 | 753 | |
|
754 | 754 | /*! |
|
755 | 755 | Returns pen used to draw shades. |
|
756 | 756 | */ |
|
757 | 757 | QPen QAbstractAxis::shadesPen() const |
|
758 | 758 | { |
|
759 | 759 | if (d_ptr->m_shadesPen == QChartPrivate::defaultPen()) |
|
760 | 760 | return QPen(); |
|
761 | 761 | else |
|
762 | 762 | return d_ptr->m_shadesPen; |
|
763 | 763 | } |
|
764 | 764 | |
|
765 | 765 | /*! |
|
766 | 766 | Sets \a brush used to draw shades. |
|
767 | 767 | */ |
|
768 | 768 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
769 | 769 | { |
|
770 | 770 | if (d_ptr->m_shadesBrush != brush) { |
|
771 | 771 | d_ptr->m_shadesBrush = brush; |
|
772 | 772 | emit shadesBrushChanged(brush); |
|
773 | 773 | } |
|
774 | 774 | } |
|
775 | 775 | |
|
776 | 776 | /*! |
|
777 | 777 | Returns brush used to draw shades. |
|
778 | 778 | */ |
|
779 | 779 | QBrush QAbstractAxis::shadesBrush() const |
|
780 | 780 | { |
|
781 | 781 | if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush()) |
|
782 | 782 | return QBrush(Qt::SolidPattern); |
|
783 | 783 | else |
|
784 | 784 | return d_ptr->m_shadesBrush; |
|
785 | 785 | } |
|
786 | 786 | |
|
787 | 787 | void QAbstractAxis::setShadesColor(QColor color) |
|
788 | 788 | { |
|
789 | 789 | QBrush b = d_ptr->m_shadesBrush; |
|
790 | 790 | if (b.color() != color) { |
|
791 | 791 | b.setColor(color); |
|
792 | 792 | setShadesBrush(b); |
|
793 | 793 | emit shadesColorChanged(color); |
|
794 | 794 | } |
|
795 | 795 | } |
|
796 | 796 | |
|
797 | 797 | QColor QAbstractAxis::shadesColor() const |
|
798 | 798 | { |
|
799 | 799 | return shadesBrush().color(); |
|
800 | 800 | } |
|
801 | 801 | |
|
802 | 802 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
803 | 803 | { |
|
804 | 804 | QPen p = d_ptr->m_shadesPen; |
|
805 | 805 | if (p.color() != color) { |
|
806 | 806 | p.setColor(color); |
|
807 | 807 | setShadesPen(p); |
|
808 | 808 | emit shadesColorChanged(color); |
|
809 | 809 | } |
|
810 | 810 | } |
|
811 | 811 | |
|
812 | 812 | QColor QAbstractAxis::shadesBorderColor() const |
|
813 | 813 | { |
|
814 | 814 | return shadesPen().color(); |
|
815 | 815 | } |
|
816 | 816 | |
|
817 | 817 | |
|
818 | 818 | bool QAbstractAxis::isVisible() const |
|
819 | 819 | { |
|
820 | 820 | return d_ptr->m_visible; |
|
821 | 821 | } |
|
822 | 822 | |
|
823 | 823 | /*! |
|
824 | 824 | Sets axis, shades, labels and grid lines to be visible. |
|
825 | 825 | */ |
|
826 | 826 | void QAbstractAxis::setVisible(bool visible) |
|
827 | 827 | { |
|
828 | 828 | if (d_ptr->m_visible != visible) { |
|
829 | 829 | d_ptr->m_visible = visible; |
|
830 | 830 | emit visibleChanged(visible); |
|
831 | 831 | } |
|
832 | 832 | } |
|
833 | 833 | |
|
834 | 834 | |
|
835 | 835 | /*! |
|
836 | 836 | Sets axis, shades, labels and grid lines to be visible. |
|
837 | 837 | */ |
|
838 | 838 | void QAbstractAxis::show() |
|
839 | 839 | { |
|
840 | 840 | setVisible(true); |
|
841 | 841 | } |
|
842 | 842 | |
|
843 | 843 | /*! |
|
844 | 844 | Sets axis, shades, labels and grid lines to not be visible. |
|
845 | 845 | */ |
|
846 | 846 | void QAbstractAxis::hide() |
|
847 | 847 | { |
|
848 | 848 | setVisible(false); |
|
849 | 849 | } |
|
850 | 850 | |
|
851 | 851 | /*! |
|
852 | 852 | Sets the minimum value shown on the axis. |
|
853 | 853 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
854 | 854 | If the conversion is impossible then the function call does nothing |
|
855 | 855 | */ |
|
856 | 856 | void QAbstractAxis::setMin(const QVariant &min) |
|
857 | 857 | { |
|
858 | 858 | d_ptr->setMin(min); |
|
859 | 859 | } |
|
860 | 860 | |
|
861 | 861 | /*! |
|
862 | 862 | Sets the maximum value shown on the axis. |
|
863 | 863 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
864 | 864 | If the conversion is impossible then the function call does nothing |
|
865 | 865 | */ |
|
866 | 866 | void QAbstractAxis::setMax(const QVariant &max) |
|
867 | 867 | { |
|
868 | 868 | d_ptr->setMax(max); |
|
869 | 869 | } |
|
870 | 870 | |
|
871 | 871 | /*! |
|
872 | 872 | Sets the range shown on the axis. |
|
873 | 873 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
874 | 874 | If the conversion is impossible then the function call does nothing. |
|
875 | 875 | */ |
|
876 | 876 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
877 | 877 | { |
|
878 | 878 | d_ptr->setRange(min, max); |
|
879 | 879 | } |
|
880 | 880 | |
|
881 | 881 | |
|
882 | 882 | /*! |
|
883 | 883 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
884 | 884 | */ |
|
885 | 885 | Qt::Orientation QAbstractAxis::orientation() |
|
886 | 886 | { |
|
887 | 887 | return d_ptr->orientation(); |
|
888 | 888 | } |
|
889 | 889 | |
|
890 | 890 | Qt::Alignment QAbstractAxis::alignment() const |
|
891 | 891 | { |
|
892 | 892 | return d_ptr->alignment(); |
|
893 | 893 | } |
|
894 | 894 | |
|
895 | 895 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
896 | 896 | |
|
897 | 897 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
898 | 898 | : q_ptr(q), |
|
899 | 899 | m_chart(0), |
|
900 | 900 | m_alignment(0), |
|
901 | 901 | m_orientation(Qt::Orientation(0)), |
|
902 | 902 | m_visible(true), |
|
903 | 903 | m_arrowVisible(true), |
|
904 | 904 | m_axisPen(QChartPrivate::defaultPen()), |
|
905 | 905 | m_axisBrush(QChartPrivate::defaultBrush()), |
|
906 | 906 | m_gridLineVisible(true), |
|
907 | 907 | m_gridLinePen(QChartPrivate::defaultPen()), |
|
908 | 908 | m_labelsVisible(true), |
|
909 | 909 | m_labelsPen(QChartPrivate::defaultPen()), |
|
910 | 910 | m_labelsBrush(QChartPrivate::defaultBrush()), |
|
911 | 911 | m_labelsFont(QChartPrivate::defaultFont()), |
|
912 | 912 | m_labelsAngle(0), |
|
913 | 913 | m_titleVisible(true), |
|
914 | 914 | m_titlePen(QChartPrivate::defaultPen()), |
|
915 | 915 | m_titleBrush(QChartPrivate::defaultBrush()), |
|
916 | 916 | m_titleFont(QChartPrivate::defaultFont()), |
|
917 | 917 | m_shadesVisible(false), |
|
918 | 918 | m_shadesPen(QChartPrivate::defaultPen()), |
|
919 | 919 | m_shadesBrush(QChartPrivate::defaultBrush()), |
|
920 | 920 | m_shadesOpacity(1.0), |
|
921 | 921 | m_dirty(false) |
|
922 | 922 | { |
|
923 | 923 | } |
|
924 | 924 | |
|
925 | 925 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
926 | 926 | { |
|
927 | 927 | } |
|
928 | 928 | |
|
929 | 929 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
|
930 | 930 | { |
|
931 | 931 | switch(alignment) { |
|
932 | 932 | case Qt::AlignTop: |
|
933 | 933 | case Qt::AlignBottom: |
|
934 | 934 | m_orientation = Qt::Horizontal; |
|
935 | 935 | break; |
|
936 | 936 | case Qt::AlignLeft: |
|
937 | 937 | case Qt::AlignRight: |
|
938 | 938 | m_orientation = Qt::Vertical; |
|
939 | 939 | break; |
|
940 | 940 | default: |
|
941 | 941 | qWarning()<<"No alignment specified !"; |
|
942 | 942 | break; |
|
943 | 943 | }; |
|
944 | 944 | m_alignment=alignment; |
|
945 | 945 | } |
|
946 | 946 | |
|
947 | 947 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
|
948 | 948 | { |
|
949 | 949 | if (forced || QChartPrivate::defaultPen() == m_axisPen) |
|
950 | 950 | q_ptr->setLinePen(theme->axisLinePen()); |
|
951 | 951 | |
|
952 | 952 | if (forced || QChartPrivate::defaultPen() == m_gridLinePen) |
|
953 | 953 | q_ptr->setGridLinePen(theme->girdLinePen()); |
|
954 | 954 | |
|
955 | 955 | if (forced || QChartPrivate::defaultBrush() == m_labelsBrush) |
|
956 | 956 | q_ptr->setLabelsBrush(theme->labelBrush()); |
|
957 | 957 | if (forced || QChartPrivate::defaultPen() == m_labelsPen) |
|
958 | 958 | q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
959 | 959 | if (forced || QChartPrivate::defaultFont() == m_labelsFont) |
|
960 | 960 | q_ptr->setLabelsFont(theme->labelFont()); |
|
961 | 961 | |
|
962 | 962 | if (forced || QChartPrivate::defaultBrush() == m_titleBrush) |
|
963 | 963 | q_ptr->setTitleBrush(theme->labelBrush()); |
|
964 | 964 | if (forced || QChartPrivate::defaultPen() == m_titlePen) |
|
965 | 965 | q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons |
|
966 | 966 | if (forced || QChartPrivate::defaultFont() == m_titleFont) { |
|
967 | 967 | QFont font(m_labelsFont); |
|
968 | 968 | font.setBold(true); |
|
969 | 969 | q_ptr->setTitleFont(font); |
|
970 | 970 | } |
|
971 | 971 | |
|
972 | 972 | if (forced || QChartPrivate::defaultBrush() == m_shadesBrush) |
|
973 | 973 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
|
974 | 974 | if (forced || QChartPrivate::defaultPen() == m_shadesPen) |
|
975 | 975 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
|
976 | 976 | |
|
977 | 977 | bool axisX = m_orientation == Qt::Horizontal; |
|
978 | 978 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
|
979 | 979 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
|
980 | 980 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
|
981 | 981 | q_ptr->setShadesVisible(true); |
|
982 | 982 | } else if (forced) { |
|
983 | 983 | q_ptr->setShadesVisible(false); |
|
984 | 984 | } |
|
985 | 985 | } |
|
986 | 986 | |
|
987 | 987 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
|
988 | 988 | { |
|
989 | 989 | setRange(min,max); |
|
990 | 990 | } |
|
991 | 991 | |
|
992 | 992 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
993 | 993 | { |
|
994 | 994 | Q_UNUSED(parent); |
|
995 | 995 | } |
|
996 | 996 | |
|
997 | 997 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
998 | 998 | { |
|
999 | 999 | ChartAxisElement *axis = m_item.data(); |
|
1000 | 1000 | Q_ASSERT(axis); |
|
1001 | 1001 | if (axis->animation()) |
|
1002 | 1002 | axis->animation()->stopAndDestroyLater(); |
|
1003 | 1003 | |
|
1004 | 1004 | if (options.testFlag(QChart::GridAxisAnimations)) |
|
1005 | 1005 | axis->setAnimation(new AxisAnimation(axis)); |
|
1006 | 1006 | else |
|
1007 | 1007 | axis->setAnimation(0); |
|
1008 | 1008 | } |
|
1009 | 1009 | |
|
1010 | 1010 | |
|
1011 | 1011 | |
|
1012 | 1012 | #include "moc_qabstractaxis.cpp" |
|
1013 | 1013 | #include "moc_qabstractaxis_p.cpp" |
|
1014 | 1014 | |
|
1015 | 1015 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,431 +1,431 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qvalueaxis.h" |
|
22 | 22 | #include "qvalueaxis_p.h" |
|
23 | 23 | #include "chartvalueaxisx_p.h" |
|
24 | 24 | #include "chartvalueaxisy_p.h" |
|
25 | 25 | #include "abstractdomain_p.h" |
|
26 | 26 | #include "polarchartvalueaxisangular_p.h" |
|
27 | 27 | #include "polarchartvalueaxisradial_p.h" |
|
28 | 28 | #include "chartdataset_p.h" |
|
29 | 29 | #include "chartpresenter_p.h" |
|
30 | 30 | #include "charttheme_p.h" |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | /*! |
|
35 | 35 | \class QValueAxis |
|
36 | 36 | \inmodule Qt Charts |
|
37 | 37 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
41 | 41 | Values of axis are drawn to position of ticks. |
|
42 | 42 | |
|
43 | 43 | Example code on how to use QValueAxis. |
|
44 | 44 | \code |
|
45 | 45 | QChartView *chartView = new QChartView; |
|
46 | 46 | QLineSeries *series = new QLineSeries; |
|
47 | 47 | // ... |
|
48 | 48 | chartView->chart()->addSeries(series); |
|
49 | 49 | |
|
50 | 50 | QValueAxis *axisX = new QValueAxis; |
|
51 | 51 | axisX->setRange(10, 20.5); |
|
52 | 52 | axisX->setTickCount(10); |
|
53 | 53 | axisX->setLabelFormat("%.2f"); |
|
54 | 54 | chartView->chart()->setAxisX(axisX, series); |
|
55 | 55 | \endcode |
|
56 | 56 | */ |
|
57 | 57 | #ifdef QDOC_QT5 |
|
58 | 58 | /*! |
|
59 | 59 | \qmltype ValueAxis |
|
60 | 60 | \instantiates QValueAxis |
|
61 | 61 | \inqmlmodule QtCommercial.Chart |
|
62 | 62 | |
|
63 |
\include |
|
|
63 | \include doc/src/valueaxis.qdocinc | |
|
64 | 64 | */ |
|
65 | 65 | #else |
|
66 | 66 | /*! |
|
67 | 67 | \qmlclass ValueAxis QValueAxis |
|
68 | 68 | |
|
69 | 69 | \include ../doc/src/valueaxis.qdocinc |
|
70 | 70 | */ |
|
71 | 71 | #endif |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QValueAxis::min |
|
75 | 75 | Defines the minimum value on the axis. |
|
76 | 76 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
77 | 77 | */ |
|
78 | 78 | /*! |
|
79 | 79 | \qmlproperty real ValueAxis::min |
|
80 | 80 | Defines the minimum value on the axis. |
|
81 | 81 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
82 | 82 | */ |
|
83 | 83 | |
|
84 | 84 | /*! |
|
85 | 85 | \property QValueAxis::max |
|
86 | 86 | Defines the maximum value on the axis. |
|
87 | 87 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty real ValueAxis::max |
|
91 | 91 | Defines the maximum value on the axis. |
|
92 | 92 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | \property QValueAxis::tickCount |
|
97 | 97 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. |
|
98 | 98 | The default value is 5, and it can not be below 2. |
|
99 | 99 | */ |
|
100 | 100 | /*! |
|
101 | 101 | \qmlproperty real ValueAxis::tickCount |
|
102 | 102 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. |
|
103 | 103 | The default value is 5, and it can not be below 2. |
|
104 | 104 | */ |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | \property QValueAxis::labelFormat |
|
108 | 108 | Defines the label format of the axis. |
|
109 | 109 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
110 | 110 | See QString::sprintf() for additional details. |
|
111 | 111 | */ |
|
112 | 112 | /*! |
|
113 | 113 | \qmlproperty real ValueAxis::labelFormat |
|
114 | 114 | Defines the label format of the axis. |
|
115 | 115 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
116 | 116 | See QString::sprintf() for additional details. |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | \fn void QValueAxis::minChanged(qreal min) |
|
121 | 121 | Axis emits signal when \a min of axis has changed. |
|
122 | 122 | */ |
|
123 | 123 | /*! |
|
124 | 124 | \qmlsignal ValueAxis::onMinChanged(real min) |
|
125 | 125 | Axis emits signal when \a min of axis has changed. |
|
126 | 126 | */ |
|
127 | 127 | |
|
128 | 128 | /*! |
|
129 | 129 | \fn void QValueAxis::maxChanged(qreal max) |
|
130 | 130 | Axis emits signal when \a max of axis has changed. |
|
131 | 131 | */ |
|
132 | 132 | /*! |
|
133 | 133 | \qmlsignal ValueAxis::onMaxChanged(real max) |
|
134 | 134 | Axis emits signal when \a max of axis has changed. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \fn void QValueAxis::tickCountChanged(int tickCount) |
|
139 | 139 | Axis emits signal when \a tickCount of axis has changed. |
|
140 | 140 | */ |
|
141 | 141 | /*! |
|
142 | 142 | \qmlsignal ValueAxis::tickCountChanged(int tickCount) |
|
143 | 143 | Axis emits signal when \a tickCount of axis has changed. |
|
144 | 144 | */ |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
148 | 148 | Axis emits signal when \a min or \a max of axis has changed. |
|
149 | 149 | */ |
|
150 | 150 | |
|
151 | 151 | /*! |
|
152 | 152 | \fn void QValueAxis::labelFormatChanged(const QString &format) |
|
153 | 153 | Axis emits signal when \a format of axis labels has changed. |
|
154 | 154 | */ |
|
155 | 155 | /*! |
|
156 | 156 | \qmlsignal ValueAxis::labelFormatChanged(const QString &format) |
|
157 | 157 | Axis emits signal when \a format of axis labels has changed. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | \property QValueAxis::niceNumbersEnabled |
|
162 | 162 | \obsolete |
|
163 | 163 | Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead. |
|
164 | 164 | */ |
|
165 | 165 | |
|
166 | 166 | /*! |
|
167 | 167 | \qmlproperty bool ValueAxis::niceNumbersEnabled |
|
168 | 168 | Deprecated; Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead. |
|
169 | 169 | */ |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | Constructs an axis object which is a child of \a parent. |
|
173 | 173 | */ |
|
174 | 174 | QValueAxis::QValueAxis(QObject *parent) : |
|
175 | 175 | QAbstractAxis(*new QValueAxisPrivate(this), parent) |
|
176 | 176 | { |
|
177 | 177 | |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | /*! |
|
181 | 181 | \internal |
|
182 | 182 | */ |
|
183 | 183 | QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent) |
|
184 | 184 | : QAbstractAxis(d, parent) |
|
185 | 185 | { |
|
186 | 186 | |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | /*! |
|
190 | 190 | Destroys the object |
|
191 | 191 | */ |
|
192 | 192 | QValueAxis::~QValueAxis() |
|
193 | 193 | { |
|
194 | 194 | Q_D(QValueAxis); |
|
195 | 195 | if (d->m_chart) |
|
196 | 196 | d->m_chart->removeAxis(this); |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | void QValueAxis::setMin(qreal min) |
|
200 | 200 | { |
|
201 | 201 | Q_D(QValueAxis); |
|
202 | 202 | setRange(min, qMax(d->m_max, min)); |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | qreal QValueAxis::min() const |
|
206 | 206 | { |
|
207 | 207 | Q_D(const QValueAxis); |
|
208 | 208 | return d->m_min; |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | void QValueAxis::setMax(qreal max) |
|
212 | 212 | { |
|
213 | 213 | Q_D(QValueAxis); |
|
214 | 214 | setRange(qMin(d->m_min, max), max); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | qreal QValueAxis::max() const |
|
218 | 218 | { |
|
219 | 219 | Q_D(const QValueAxis); |
|
220 | 220 | return d->m_max; |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | /*! |
|
224 | 224 | Sets range from \a min to \a max on the axis. |
|
225 | 225 | If min is greater than max then this function returns without making any changes. |
|
226 | 226 | */ |
|
227 | 227 | void QValueAxis::setRange(qreal min, qreal max) |
|
228 | 228 | { |
|
229 | 229 | Q_D(QValueAxis); |
|
230 | 230 | d->setRange(min,max); |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | void QValueAxis::setTickCount(int count) |
|
234 | 234 | { |
|
235 | 235 | Q_D(QValueAxis); |
|
236 | 236 | if (d->m_tickCount != count && count >= 2) { |
|
237 | 237 | d->m_tickCount = count; |
|
238 | 238 | emit tickCountChanged(count); |
|
239 | 239 | } |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | int QValueAxis::tickCount() const |
|
243 | 243 | { |
|
244 | 244 | Q_D(const QValueAxis); |
|
245 | 245 | return d->m_tickCount; |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
249 | 249 | { |
|
250 | 250 | Q_D(QValueAxis); |
|
251 | 251 | qWarning() << "Deprecated; Using this function can lead to unexpected behavior. " \ |
|
252 | 252 | "Use applyNiceNumbers() instead."; |
|
253 | 253 | if(enable) { |
|
254 | 254 | QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); |
|
255 | 255 | QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); |
|
256 | 256 | applyNiceNumbers(); |
|
257 | 257 | } |
|
258 | 258 | else { |
|
259 | 259 | QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); |
|
260 | 260 | QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); |
|
261 | 261 | } |
|
262 | 262 | d->m_niceNumbersEnabled=enable; |
|
263 | 263 | } |
|
264 | 264 | |
|
265 | 265 | bool QValueAxis::niceNumbersEnabled() const |
|
266 | 266 | { |
|
267 | 267 | Q_D(const QValueAxis); |
|
268 | 268 | qWarning() << "Deprecated; Using this function can lead to unexpected behavior. " \ |
|
269 | 269 | "Use applyNiceNumbers() instead."; |
|
270 | 270 | return d->m_niceNumbersEnabled; |
|
271 | 271 | } |
|
272 | 272 | |
|
273 | 273 | void QValueAxis::setLabelFormat(const QString &format) |
|
274 | 274 | { |
|
275 | 275 | Q_D(QValueAxis); |
|
276 | 276 | d->m_format = format; |
|
277 | 277 | emit labelFormatChanged(format); |
|
278 | 278 | } |
|
279 | 279 | |
|
280 | 280 | QString QValueAxis::labelFormat() const |
|
281 | 281 | { |
|
282 | 282 | Q_D(const QValueAxis); |
|
283 | 283 | return d->m_format; |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | /*! |
|
287 | 287 | Returns the type of the axis |
|
288 | 288 | */ |
|
289 | 289 | QAbstractAxis::AxisType QValueAxis::type() const |
|
290 | 290 | { |
|
291 | 291 | return AxisTypeValue; |
|
292 | 292 | } |
|
293 | 293 | |
|
294 | 294 | /*! |
|
295 | 295 | This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that |
|
296 | 296 | can be expressed as form of 1*10^n, 2* 10^n or 5*10^n as a nice numbers. These numbers are used for spacing the ticks. |
|
297 | 297 | This method will modify the current range and number of ticks. |
|
298 | 298 | \sa setRange(), setTickCount() |
|
299 | 299 | */ |
|
300 | 300 | void QValueAxis::applyNiceNumbers() |
|
301 | 301 | { |
|
302 | 302 | Q_D(QValueAxis); |
|
303 | 303 | if(d->m_applying) return; |
|
304 | 304 | qreal min = d->m_min; |
|
305 | 305 | qreal max = d->m_max; |
|
306 | 306 | int ticks = d->m_tickCount; |
|
307 | 307 | AbstractDomain::looseNiceNumbers(min,max,ticks); |
|
308 | 308 | d->m_applying=true; |
|
309 | 309 | d->setRange(min,max); |
|
310 | 310 | setTickCount(ticks); |
|
311 | 311 | d->m_applying=false; |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
315 | 315 | |
|
316 | 316 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) |
|
317 | 317 | : QAbstractAxisPrivate(q), |
|
318 | 318 | m_min(0), |
|
319 | 319 | m_max(0), |
|
320 | 320 | m_tickCount(5), |
|
321 | 321 | m_format(QString::null), |
|
322 | 322 | m_applying(false), |
|
323 | 323 | m_niceNumbersEnabled(false) |
|
324 | 324 | { |
|
325 | 325 | |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | QValueAxisPrivate::~QValueAxisPrivate() |
|
329 | 329 | { |
|
330 | 330 | |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
334 | 334 | { |
|
335 | 335 | Q_Q(QValueAxis); |
|
336 | 336 | bool ok; |
|
337 | 337 | qreal value = min.toReal(&ok); |
|
338 | 338 | if (ok) |
|
339 | 339 | q->setMin(value); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
343 | 343 | { |
|
344 | 344 | Q_Q(QValueAxis); |
|
345 | 345 | bool ok; |
|
346 | 346 | qreal value = max.toReal(&ok); |
|
347 | 347 | if (ok) |
|
348 | 348 | q->setMax(value); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
352 | 352 | { |
|
353 | 353 | Q_Q(QValueAxis); |
|
354 | 354 | bool ok1; |
|
355 | 355 | bool ok2; |
|
356 | 356 | qreal value1 = min.toReal(&ok1); |
|
357 | 357 | qreal value2 = max.toReal(&ok2); |
|
358 | 358 | if (ok1 && ok2) |
|
359 | 359 | q->setRange(value1, value2); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | void QValueAxisPrivate::setRange(qreal min, qreal max) |
|
363 | 363 | { |
|
364 | 364 | Q_Q(QValueAxis); |
|
365 | 365 | bool changed = false; |
|
366 | 366 | |
|
367 | 367 | if (min > max) |
|
368 | 368 | return; |
|
369 | 369 | |
|
370 | 370 | if (!qFuzzyCompare(m_min,min)) { |
|
371 | 371 | m_min = min; |
|
372 | 372 | changed = true; |
|
373 | 373 | emit q->minChanged(min); |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | if (!qFuzzyCompare(m_max,max)) { |
|
377 | 377 | m_max = max; |
|
378 | 378 | changed = true; |
|
379 | 379 | emit q->maxChanged(max); |
|
380 | 380 | } |
|
381 | 381 | |
|
382 | 382 | if (changed) { |
|
383 | 383 | emit rangeChanged(min,max); |
|
384 | 384 | emit q->rangeChanged(min, max); |
|
385 | 385 | } |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent) |
|
389 | 389 | { |
|
390 | 390 | Q_Q(QValueAxis); |
|
391 | 391 | ChartAxisElement *axis(0); |
|
392 | 392 | |
|
393 | 393 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
394 | 394 | if (orientation() == Qt::Vertical) |
|
395 | 395 | axis = new ChartValueAxisY(q,parent); |
|
396 | 396 | if (orientation() == Qt::Horizontal) |
|
397 | 397 | axis = new ChartValueAxisX(q,parent); |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
401 | 401 | if (orientation() == Qt::Vertical) |
|
402 | 402 | axis = new PolarChartValueAxisRadial(q, parent); |
|
403 | 403 | if (orientation() == Qt::Horizontal) |
|
404 | 404 | axis = new PolarChartValueAxisAngular(q, parent); |
|
405 | 405 | } |
|
406 | 406 | |
|
407 | 407 | m_item.reset(axis); |
|
408 | 408 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
409 | 409 | } |
|
410 | 410 | |
|
411 | 411 | |
|
412 | 412 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
413 | 413 | { |
|
414 | 414 | if (orientation() == Qt::Vertical) { |
|
415 | 415 | if (!qFuzzyIsNull(m_max - m_min)) |
|
416 | 416 | domain->setRangeY(m_min, m_max); |
|
417 | 417 | else |
|
418 | 418 | setRange(domain->minY(), domain->maxY()); |
|
419 | 419 | } |
|
420 | 420 | if (orientation() == Qt::Horizontal) { |
|
421 | 421 | if (!qFuzzyIsNull(m_max - m_min)) |
|
422 | 422 | domain->setRangeX(m_min, m_max); |
|
423 | 423 | else |
|
424 | 424 | setRange(domain->minX(), domain->maxX()); |
|
425 | 425 | } |
|
426 | 426 | } |
|
427 | 427 | |
|
428 | 428 | #include "moc_qvalueaxis.cpp" |
|
429 | 429 | #include "moc_qvalueaxis_p.cpp" |
|
430 | 430 | |
|
431 | 431 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,125 +1,125 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qhorizontalbarseries.h" |
|
22 | 22 | #include "qhorizontalbarseries_p.h" |
|
23 | 23 | #include "horizontalbarchartitem_p.h" |
|
24 | 24 | #include "qbarcategoryaxis.h" |
|
25 | 25 | |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QHorizontalBarSeries |
|
34 | 34 | \inmodule Qt Charts |
|
35 | 35 | \brief Series for creating horizontal bar chart. |
|
36 | 36 | \mainclass |
|
37 | 37 | |
|
38 | 38 | QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
39 | 39 | as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data |
|
40 | 40 | from sets to categories, which are defined by a QStringList. |
|
41 | 41 | |
|
42 | 42 | See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart. |
|
43 | 43 | \image examples_horizontalbarchart.png |
|
44 | 44 | |
|
45 | 45 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries |
|
46 | 46 | */ |
|
47 | 47 | #ifdef QDOC_QT5 |
|
48 | 48 | /*! |
|
49 | 49 | \qmltype HorizontalBarSeries |
|
50 | 50 | \instantiates QHorizontalBarSeries |
|
51 | 51 | \inqmlmodule QtCommercial.Chart |
|
52 | 52 | |
|
53 |
\include |
|
|
53 | \include doc/src/horizontalbarseries.qdocinc | |
|
54 | 54 | */ |
|
55 | 55 | #else |
|
56 | 56 | /*! |
|
57 | 57 | \qmlclass HorizontalBarSeries QHorizontalBarSeries |
|
58 | 58 | |
|
59 | 59 | \include ../doc/src/horizontalbarseries.qdocinc |
|
60 | 60 | */ |
|
61 | 61 | #endif |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | Constructs empty QHorizontalBarSeries. |
|
65 | 65 | QHorizontalBarSeries is QObject which is a child of a \a parent. |
|
66 | 66 | */ |
|
67 | 67 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) |
|
68 | 68 | : QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) |
|
69 | 69 | { |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | Destructor. |
|
74 | 74 | Removes series from chart. |
|
75 | 75 | */ |
|
76 | 76 | QHorizontalBarSeries::~QHorizontalBarSeries() |
|
77 | 77 | { |
|
78 | 78 | Q_D(QHorizontalBarSeries); |
|
79 | 79 | if (d->m_chart) |
|
80 | 80 | d->m_chart->removeSeries(this); |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | Returns QChartSeries::SeriesTypeHorizontalBar. |
|
85 | 85 | */ |
|
86 | 86 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const |
|
87 | 87 | { |
|
88 | 88 | return QAbstractSeries::SeriesTypeHorizontalBar; |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 | 92 | |
|
93 | 93 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) |
|
94 | 94 | : QAbstractBarSeriesPrivate(q) |
|
95 | 95 | { |
|
96 | 96 | |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void QHorizontalBarSeriesPrivate::initializeDomain() |
|
100 | 100 | { |
|
101 | 101 | qreal minX(domain()->minX()); |
|
102 | 102 | qreal minY(domain()->minY()); |
|
103 | 103 | qreal maxX(domain()->maxX()); |
|
104 | 104 | qreal maxY(domain()->maxY()); |
|
105 | 105 | |
|
106 | 106 | qreal y = categoryCount(); |
|
107 | 107 | minX = qMin(minX, min()); |
|
108 | 108 | minY = qMin(minY, - (qreal)0.5); |
|
109 | 109 | maxX = qMax(maxX, max()); |
|
110 | 110 | maxY = qMax(maxY, y - (qreal)0.5); |
|
111 | 111 | |
|
112 | 112 | domain()->setRange(minX, maxX, minY, maxY); |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
116 | 116 | { |
|
117 | 117 | Q_Q(QHorizontalBarSeries); |
|
118 | 118 | HorizontalBarChartItem *bar = new HorizontalBarChartItem(q,parent); |
|
119 | 119 | m_item.reset(bar); |
|
120 | 120 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
121 | 121 | } |
|
122 | 122 | |
|
123 | 123 | #include "moc_qhorizontalbarseries.cpp" |
|
124 | 124 | |
|
125 | 125 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,121 +1,121 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 | #include "qhorizontalpercentbarseries.h" |
|
21 | 21 | #include "qhorizontalpercentbarseries_p.h" |
|
22 | 22 | #include "horizontalpercentbarchartitem_p.h" |
|
23 | 23 | |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \class QHorizontalPercentBarSeries |
|
31 | 31 | \inmodule Qt Charts |
|
32 | 32 | \brief Series for creating horizontal percent bar chart. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | QHorizontalPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
36 | 36 | as groups, where bars in same category are grouped next to each other. QHorizontalPercentBarSeries groups the data |
|
37 | 37 | from sets to categories, which are defined by a QStringList. |
|
38 | 38 | |
|
39 | 39 | See the \l {HorizontalPercentBarChart Example} {horizontal percent bar chart example} to learn how to create a horizontal percent bar chart. |
|
40 | 40 | \image examples_horizontalpercentbarchart.png |
|
41 | 41 | |
|
42 | 42 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalBarSeries |
|
43 | 43 | */ |
|
44 | 44 | #ifdef QDOC_QT5 |
|
45 | 45 | /*! |
|
46 | 46 | \qmltype HorizontalPercentBarSeries |
|
47 | 47 | \instantiates QHorizontalPercentBarSeries |
|
48 | 48 | \inqmlmodule QtCommercial.Chart |
|
49 | 49 | |
|
50 |
\include |
|
|
50 | \include doc/src/horizontalpercentbarseries.qdocinc | |
|
51 | 51 | */ |
|
52 | 52 | #else |
|
53 | 53 | /*! |
|
54 | 54 | \qmlclass HorizontalPercentBarSeries QHorizontalPercentBarSeries |
|
55 | 55 | |
|
56 | 56 | \include ../doc/src/horizontalpercentbarseries.qdocinc |
|
57 | 57 | */ |
|
58 | 58 | #endif |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | Constructs empty QHorizontalPercentBarSeries. |
|
62 | 62 | QHorizontalPercentBarSeries is QObject which is a child of a \a parent. |
|
63 | 63 | */ |
|
64 | 64 | QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) : |
|
65 | 65 | QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent) |
|
66 | 66 | { |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | /*! |
|
70 | 70 | Returns QAbstractSeries::SeriesTypeHorizontalPercentBar. |
|
71 | 71 | */ |
|
72 | 72 | QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const |
|
73 | 73 | { |
|
74 | 74 | return QAbstractSeries::SeriesTypeHorizontalPercentBar; |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | Destructor. |
|
79 | 79 | Removes series from chart. |
|
80 | 80 | */ |
|
81 | 81 | QHorizontalPercentBarSeries::~QHorizontalPercentBarSeries() |
|
82 | 82 | { |
|
83 | 83 | Q_D(QHorizontalPercentBarSeries); |
|
84 | 84 | if (d->m_chart) |
|
85 | 85 | d->m_chart->removeSeries(this); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 | 89 | |
|
90 | 90 | QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
91 | 91 | { |
|
92 | 92 | |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | void QHorizontalPercentBarSeriesPrivate::initializeDomain() |
|
96 | 96 | { |
|
97 | 97 | qreal minX(domain()->minX()); |
|
98 | 98 | qreal minY(domain()->minY()); |
|
99 | 99 | qreal maxX(domain()->maxX()); |
|
100 | 100 | qreal maxY(domain()->maxY()); |
|
101 | 101 | |
|
102 | 102 | qreal y = categoryCount(); |
|
103 | 103 | minX = 0; |
|
104 | 104 | maxX = 100; |
|
105 | 105 | minY = qMin(minY, - (qreal)0.5); |
|
106 | 106 | maxY = qMax(maxY, y - (qreal)0.5); |
|
107 | 107 | |
|
108 | 108 | domain()->setRange(minX, maxX, minY, maxY); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
112 | 112 | { |
|
113 | 113 | Q_Q(QHorizontalPercentBarSeries); |
|
114 | 114 | HorizontalPercentBarChartItem *bar = new HorizontalPercentBarChartItem(q,parent); |
|
115 | 115 | m_item.reset(bar); |
|
116 | 116 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | #include "moc_qhorizontalpercentbarseries.cpp" |
|
120 | 120 | |
|
121 | 121 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,120 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 | #include "qhorizontalstackedbarseries.h" |
|
21 | 21 | #include "qhorizontalstackedbarseries_p.h" |
|
22 | 22 | #include "horizontalstackedbarchartitem_p.h" |
|
23 | 23 | |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | /*! |
|
29 | 29 | \class QHorizontalStackedBarSeries |
|
30 | 30 | \inmodule Qt Charts |
|
31 | 31 | \brief Series for creating horizontal stacked bar chart. |
|
32 | 32 | \mainclass |
|
33 | 33 | |
|
34 | 34 | QHorizontalStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
35 | 35 | as groups, where bars in same category are grouped next to each other. QHorizontalStackedBarSeries groups the data |
|
36 | 36 | from sets to categories, which are defined by a QStringList. |
|
37 | 37 | |
|
38 | 38 | See the \l {HorizontalStackedBarChart Example} {horizontal stacked bar chart example} to learn how to create a horizontal stacked bar chart. |
|
39 | 39 | \image examples_horizontalstackedbarchart.png |
|
40 | 40 | |
|
41 | 41 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalPercentBarSeries, QHorizontalBarSeries |
|
42 | 42 | */ |
|
43 | 43 | #ifdef QDOC_QT5 |
|
44 | 44 | /*! |
|
45 | 45 | \qmltype HorizontalStackedBarSeries |
|
46 | 46 | \instantiates QHorizontalStackedBarSeries |
|
47 | 47 | \inqmlmodule QtCommercial.Chart |
|
48 | 48 | |
|
49 |
\include |
|
|
49 | \include doc/src/horizontalstackedbarseries.qdocinc | |
|
50 | 50 | */ |
|
51 | 51 | #else |
|
52 | 52 | /*! |
|
53 | 53 | \qmlclass HorizontalStackedBarSeries QHorizontalStackedBarSeries |
|
54 | 54 | |
|
55 | 55 | \include ../doc/src/horizontalstackedbarseries.qdocinc |
|
56 | 56 | */ |
|
57 | 57 | #endif |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | Constructs empty QHorizontalStackedBarSeries. |
|
61 | 61 | QHorizontalStackedBarSeries is QObject which is a child of a \a parent. |
|
62 | 62 | */ |
|
63 | 63 | QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent) |
|
64 | 64 | : QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent) |
|
65 | 65 | { |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | Destructor. |
|
70 | 70 | Removes series from chart. |
|
71 | 71 | */ |
|
72 | 72 | QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries() |
|
73 | 73 | { |
|
74 | 74 | Q_D(QHorizontalStackedBarSeries); |
|
75 | 75 | if (d->m_chart) |
|
76 | 76 | d->m_chart->removeSeries(this); |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | Returns QAbstractSeries::SeriesTypeHorizontalStackedBar. |
|
81 | 81 | */ |
|
82 | 82 | QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const |
|
83 | 83 | { |
|
84 | 84 | return QAbstractSeries::SeriesTypeHorizontalStackedBar; |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 | 88 | |
|
89 | 89 | QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
90 | 90 | { |
|
91 | 91 | |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | void QHorizontalStackedBarSeriesPrivate::initializeDomain() |
|
95 | 95 | { |
|
96 | 96 | qreal minX(domain()->minX()); |
|
97 | 97 | qreal minY(domain()->minY()); |
|
98 | 98 | qreal maxX(domain()->maxX()); |
|
99 | 99 | qreal maxY(domain()->maxY()); |
|
100 | 100 | |
|
101 | 101 | qreal y = categoryCount(); |
|
102 | 102 | minX = qMin(minX, bottom()); |
|
103 | 103 | minY = qMin(minY, - (qreal)0.5); |
|
104 | 104 | maxX = qMax(maxX, top()); |
|
105 | 105 | maxY = qMax(maxY, y - (qreal)0.5); |
|
106 | 106 | |
|
107 | 107 | domain()->setRange(minX, maxX, minY, maxY); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent) |
|
111 | 111 | { |
|
112 | 112 | Q_Q(QHorizontalStackedBarSeries); |
|
113 | 113 | HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent); |
|
114 | 114 | m_item.reset(bar); |
|
115 | 115 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | #include "moc_qhorizontalstackedbarseries.cpp" |
|
119 | 119 | |
|
120 | 120 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,927 +1,927 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qabstractbarseries.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "abstractdomain_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "qvalueaxis.h" |
|
29 | 29 | #include "qbarcategoryaxis.h" |
|
30 | 30 | #include "qbarlegendmarker.h" |
|
31 | 31 | #include "baranimation_p.h" |
|
32 | 32 | #include "abstractbarchartitem_p.h" |
|
33 | 33 | #include "qchart_p.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | /*! |
|
38 | 38 | \class QAbstractBarSeries |
|
39 | 39 | \inmodule Qt Charts |
|
40 | 40 | \brief Series for creating a bar chart. |
|
41 | 41 | \mainclass |
|
42 | 42 | |
|
43 | 43 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
44 | 44 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
45 | 45 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
46 | 46 | shows the x-values. |
|
47 | 47 | |
|
48 | 48 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
49 | 49 | \image examples_barchart.png |
|
50 | 50 | |
|
51 | 51 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
52 | 52 | */ |
|
53 | 53 | #ifdef QDOC_QT5 |
|
54 | 54 | /*! |
|
55 | 55 | \qmltype AbstractBarSeries |
|
56 | 56 | \instantiates QAbstractBarSeries |
|
57 | 57 | \inqmlmodule QtCommercial.Chart |
|
58 | 58 | |
|
59 |
\include |
|
|
59 | \include doc/src/abstractbarseries.qdocinc | |
|
60 | 60 | */ |
|
61 | 61 | #else |
|
62 | 62 | /*! |
|
63 | 63 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
64 | 64 | |
|
65 | 65 | \include ../doc/src/abstractbarseries.qdocinc |
|
66 | 66 | */ |
|
67 | 67 | #endif |
|
68 | 68 | |
|
69 | 69 | /*! |
|
70 | 70 | \qmlproperty AbstractAxis AbstractBarSeries::axisX |
|
71 | 71 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for |
|
72 | 72 | the series. |
|
73 | 73 | \sa axisXTop |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \qmlproperty AbstractAxis AbstractBarSeries::axisY |
|
78 | 78 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
79 | 79 | the series. |
|
80 | 80 | \sa axisYRight |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty AbstractAxis AbstractBarSeries::axisXTop |
|
85 | 85 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
86 | 86 | axisXTop, but not both. |
|
87 | 87 | \sa axisX |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \qmlproperty AbstractAxis AbstractBarSeries::axisYRight |
|
92 | 92 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
93 | 93 | or axisYRight, but not both. |
|
94 | 94 | \sa axisY |
|
95 | 95 | */ |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | \property QAbstractBarSeries::barWidth |
|
99 | 99 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
100 | 100 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
101 | 101 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
102 | 102 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
103 | 103 | \sa QBarSeries |
|
104 | 104 | */ |
|
105 | 105 | /*! |
|
106 | 106 | \qmlproperty real AbstractBarSeries::barWidth |
|
107 | 107 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
108 | 108 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
109 | 109 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
110 | 110 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
111 | 111 | */ |
|
112 | 112 | |
|
113 | 113 | /*! |
|
114 | 114 | \property QAbstractBarSeries::count |
|
115 | 115 | Holds the number of sets in series. |
|
116 | 116 | */ |
|
117 | 117 | /*! |
|
118 | 118 | \qmlproperty int AbstractBarSeries::count |
|
119 | 119 | Holds the number of sets in series. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \property QAbstractBarSeries::labelsVisible |
|
124 | 124 | Defines the visibility of the labels in series |
|
125 | 125 | */ |
|
126 | 126 | /*! |
|
127 | 127 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
128 | 128 | Defines the visibility of the labels in series |
|
129 | 129 | */ |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
133 | 133 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
134 | 134 | Clicked bar inside set is indexed by \a index |
|
135 | 135 | */ |
|
136 | 136 | /*! |
|
137 | 137 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
138 | 138 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
139 | 139 | Clicked bar inside set is indexed by \a index |
|
140 | 140 | */ |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
144 | 144 | |
|
145 | 145 | The signal is emitted if mouse is hovered on top of series. |
|
146 | 146 | Parameter \a barset is the pointer of barset, where hover happened. |
|
147 | 147 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \fn void QAbstractBarSeries::hovered(bool status, int index, QBarSet* barset) |
|
152 | 152 | |
|
153 | 153 | The signal is emitted if mouse is hovered on top of series. |
|
154 | 154 | Parameter \a barset is the pointer of barset, where hover happened. |
|
155 | 155 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
156 | 156 | Hovered bar inside the set is indexed by \a index. |
|
157 | 157 | */ |
|
158 | 158 | /*! |
|
159 | 159 | \qmlsignal AbstractBarSeries::onHovered(bool status, int index, BarSet barset) |
|
160 | 160 | |
|
161 | 161 | The signal is emitted if mouse is hovered on top of series. |
|
162 | 162 | Parameter \a barset is the pointer of barset, where hover happened. |
|
163 | 163 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
164 | 164 | Hovered bar inside the set is indexed by \a index. |
|
165 | 165 | */ |
|
166 | 166 | |
|
167 | 167 | /*! |
|
168 | 168 | \fn void QAbstractBarSeries::countChanged() |
|
169 | 169 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
170 | 170 | */ |
|
171 | 171 | /*! |
|
172 | 172 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
173 | 173 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
174 | 174 | */ |
|
175 | 175 | |
|
176 | 176 | /*! |
|
177 | 177 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
178 | 178 | This signal is emitted when labels visibility have changed. |
|
179 | 179 | \sa isLabelsVisible(), setLabelsVisible() |
|
180 | 180 | */ |
|
181 | 181 | |
|
182 | 182 | /*! |
|
183 | 183 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
184 | 184 | This signal is emitted when \a sets have been added to the series. |
|
185 | 185 | \sa append(), insert() |
|
186 | 186 | */ |
|
187 | 187 | /*! |
|
188 | 188 | \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset) |
|
189 | 189 | Emitted when \a barset has been added to the series. |
|
190 | 190 | */ |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
194 | 194 | This signal is emitted when \a sets have been removed from the series. |
|
195 | 195 | \sa remove() |
|
196 | 196 | */ |
|
197 | 197 | /*! |
|
198 | 198 | \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset) |
|
199 | 199 | Emitted when \a barset has been removed from the series. |
|
200 | 200 | */ |
|
201 | 201 | |
|
202 | 202 | /*! |
|
203 | 203 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
204 | 204 | Returns bar set at \a index. Returns null if the index is not valid. |
|
205 | 205 | */ |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
209 | 209 | Adds a new bar set with \a label and \a values to \a index. Values is a list of reals. |
|
210 | 210 | For example: |
|
211 | 211 | \code |
|
212 | 212 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
213 | 213 | \endcode |
|
214 | 214 | */ |
|
215 | 215 | |
|
216 | 216 | /*! |
|
217 | 217 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
218 | 218 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
219 | 219 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
220 | 220 | appended. |
|
221 | 221 | \sa AbstractBarSeries::append() |
|
222 | 222 | */ |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
226 | 226 | Removes the barset from the series. Returns true if successful, false otherwise. |
|
227 | 227 | */ |
|
228 | 228 | |
|
229 | 229 | /*! |
|
230 | 230 | \qmlmethod AbstractBarSeries::clear() |
|
231 | 231 | Removes all barsets from the series. |
|
232 | 232 | */ |
|
233 | 233 | |
|
234 | 234 | /*! |
|
235 | 235 | Destructs abstractbarseries and owned barsets. |
|
236 | 236 | */ |
|
237 | 237 | QAbstractBarSeries::~QAbstractBarSeries() |
|
238 | 238 | { |
|
239 | 239 | |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | /*! |
|
243 | 243 | \internal |
|
244 | 244 | */ |
|
245 | 245 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) |
|
246 | 246 | : QAbstractSeries(o, parent) |
|
247 | 247 | { |
|
248 | 248 | Q_D(QAbstractSeries); |
|
249 | 249 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
250 | 250 | } |
|
251 | 251 | |
|
252 | 252 | /*! |
|
253 | 253 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
254 | 254 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
255 | 255 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
256 | 256 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
257 | 257 | */ |
|
258 | 258 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
259 | 259 | { |
|
260 | 260 | Q_D(QAbstractBarSeries); |
|
261 | 261 | d->setBarWidth(width); |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | /*! |
|
265 | 265 | Returns the width of the bars of the series. |
|
266 | 266 | \sa setBarWidth() |
|
267 | 267 | */ |
|
268 | 268 | qreal QAbstractBarSeries::barWidth() const |
|
269 | 269 | { |
|
270 | 270 | Q_D(const QAbstractBarSeries); |
|
271 | 271 | return d->barWidth(); |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | /*! |
|
275 | 275 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
276 | 276 | Returns true, if appending succeeded. |
|
277 | 277 | */ |
|
278 | 278 | bool QAbstractBarSeries::append(QBarSet *set) |
|
279 | 279 | { |
|
280 | 280 | Q_D(QAbstractBarSeries); |
|
281 | 281 | bool success = d->append(set); |
|
282 | 282 | if (success) { |
|
283 | 283 | QList<QBarSet *> sets; |
|
284 | 284 | sets.append(set); |
|
285 | 285 | set->setParent(this); |
|
286 | 286 | emit barsetsAdded(sets); |
|
287 | 287 | emit countChanged(); |
|
288 | 288 | } |
|
289 | 289 | return success; |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | /*! |
|
293 | 293 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
294 | 294 | was successful. |
|
295 | 295 | Returns true, if set was removed. |
|
296 | 296 | */ |
|
297 | 297 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
298 | 298 | { |
|
299 | 299 | Q_D(QAbstractBarSeries); |
|
300 | 300 | bool success = d->remove(set); |
|
301 | 301 | if (success) { |
|
302 | 302 | QList<QBarSet *> sets; |
|
303 | 303 | sets.append(set); |
|
304 | 304 | set->setParent(0); |
|
305 | 305 | emit barsetsRemoved(sets); |
|
306 | 306 | emit countChanged(); |
|
307 | 307 | delete set; |
|
308 | 308 | set = 0; |
|
309 | 309 | } |
|
310 | 310 | return success; |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | /*! |
|
314 | 314 | Takes a single \a set from the series. Does not delete the barset object. |
|
315 | 315 | |
|
316 | 316 | NOTE: The series remains as the barset's parent object. You must set the |
|
317 | 317 | parent object to take full ownership. |
|
318 | 318 | |
|
319 | 319 | Returns true if take was successful. |
|
320 | 320 | */ |
|
321 | 321 | bool QAbstractBarSeries::take(QBarSet *set) |
|
322 | 322 | { |
|
323 | 323 | Q_D(QAbstractBarSeries); |
|
324 | 324 | bool success = d->remove(set); |
|
325 | 325 | if (success) { |
|
326 | 326 | QList<QBarSet *> sets; |
|
327 | 327 | sets.append(set); |
|
328 | 328 | emit barsetsRemoved(sets); |
|
329 | 329 | emit countChanged(); |
|
330 | 330 | } |
|
331 | 331 | return success; |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | /*! |
|
335 | 335 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
336 | 336 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, |
|
337 | 337 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
338 | 338 | and function returns false. |
|
339 | 339 | */ |
|
340 | 340 | bool QAbstractBarSeries::append(QList<QBarSet *> sets) |
|
341 | 341 | { |
|
342 | 342 | Q_D(QAbstractBarSeries); |
|
343 | 343 | bool success = d->append(sets); |
|
344 | 344 | if (success) { |
|
345 | 345 | emit barsetsAdded(sets); |
|
346 | 346 | emit countChanged(); |
|
347 | 347 | } |
|
348 | 348 | return success; |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | /*! |
|
352 | 352 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
353 | 353 | Returns true, if inserting succeeded. |
|
354 | 354 | |
|
355 | 355 | */ |
|
356 | 356 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
357 | 357 | { |
|
358 | 358 | Q_D(QAbstractBarSeries); |
|
359 | 359 | bool success = d->insert(index, set); |
|
360 | 360 | if (success) { |
|
361 | 361 | QList<QBarSet *> sets; |
|
362 | 362 | sets.append(set); |
|
363 | 363 | emit barsetsAdded(sets); |
|
364 | 364 | emit countChanged(); |
|
365 | 365 | } |
|
366 | 366 | return success; |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | /*! |
|
370 | 370 | Removes all barsets from the series. Deletes removed sets. |
|
371 | 371 | */ |
|
372 | 372 | void QAbstractBarSeries::clear() |
|
373 | 373 | { |
|
374 | 374 | Q_D(QAbstractBarSeries); |
|
375 | 375 | QList<QBarSet *> sets = barSets(); |
|
376 | 376 | bool success = d->remove(sets); |
|
377 | 377 | if (success) { |
|
378 | 378 | emit barsetsRemoved(sets); |
|
379 | 379 | emit countChanged(); |
|
380 | 380 | foreach (QBarSet *set, sets) |
|
381 | 381 | delete set; |
|
382 | 382 | } |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | /*! |
|
386 | 386 | Returns number of sets in series. |
|
387 | 387 | */ |
|
388 | 388 | int QAbstractBarSeries::count() const |
|
389 | 389 | { |
|
390 | 390 | Q_D(const QAbstractBarSeries); |
|
391 | 391 | return d->m_barSets.count(); |
|
392 | 392 | } |
|
393 | 393 | |
|
394 | 394 | /*! |
|
395 | 395 | Returns a list of sets in series. Keeps ownership of sets. |
|
396 | 396 | */ |
|
397 | 397 | QList<QBarSet *> QAbstractBarSeries::barSets() const |
|
398 | 398 | { |
|
399 | 399 | Q_D(const QAbstractBarSeries); |
|
400 | 400 | return d->m_barSets; |
|
401 | 401 | } |
|
402 | 402 | |
|
403 | 403 | /*! |
|
404 | 404 | Sets the visibility of labels in series to \a visible |
|
405 | 405 | */ |
|
406 | 406 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
407 | 407 | { |
|
408 | 408 | Q_D(QAbstractBarSeries); |
|
409 | 409 | if (d->m_labelsVisible != visible) { |
|
410 | 410 | d->setLabelsVisible(visible); |
|
411 | 411 | emit labelsVisibleChanged(); |
|
412 | 412 | } |
|
413 | 413 | } |
|
414 | 414 | |
|
415 | 415 | /*! |
|
416 | 416 | Returns the visibility of labels |
|
417 | 417 | */ |
|
418 | 418 | bool QAbstractBarSeries::isLabelsVisible() const |
|
419 | 419 | { |
|
420 | 420 | Q_D(const QAbstractBarSeries); |
|
421 | 421 | return d->m_labelsVisible; |
|
422 | 422 | } |
|
423 | 423 | |
|
424 | 424 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
425 | 425 | |
|
426 | 426 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
427 | 427 | QAbstractSeriesPrivate(q), |
|
428 | 428 | m_barWidth(0.5), // Default value is 50% of category width |
|
429 | 429 | m_labelsVisible(false), |
|
430 | 430 | m_visible(true), |
|
431 | 431 | m_blockBarUpdate(false) |
|
432 | 432 | { |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
436 | 436 | { |
|
437 | 437 | // No categories defined. return count of longest set. |
|
438 | 438 | int count = 0; |
|
439 | 439 | for (int i = 0; i < m_barSets.count(); i++) { |
|
440 | 440 | if (m_barSets.at(i)->count() > count) |
|
441 | 441 | count = m_barSets.at(i)->count(); |
|
442 | 442 | } |
|
443 | 443 | |
|
444 | 444 | return count; |
|
445 | 445 | } |
|
446 | 446 | |
|
447 | 447 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
448 | 448 | { |
|
449 | 449 | if (width < 0.0) |
|
450 | 450 | width = 0.0; |
|
451 | 451 | m_barWidth = width; |
|
452 | 452 | emit updatedLayout(); |
|
453 | 453 | } |
|
454 | 454 | |
|
455 | 455 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
456 | 456 | { |
|
457 | 457 | return m_barWidth; |
|
458 | 458 | } |
|
459 | 459 | |
|
460 | 460 | QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index) |
|
461 | 461 | { |
|
462 | 462 | return m_barSets.at(index); |
|
463 | 463 | } |
|
464 | 464 | |
|
465 | 465 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
466 | 466 | { |
|
467 | 467 | m_visible = visible; |
|
468 | 468 | emit visibleChanged(); |
|
469 | 469 | } |
|
470 | 470 | |
|
471 | 471 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
472 | 472 | { |
|
473 | 473 | m_labelsVisible = visible; |
|
474 | 474 | emit labelsVisibleChanged(visible); |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | qreal QAbstractBarSeriesPrivate::min() |
|
478 | 478 | { |
|
479 | 479 | if (m_barSets.count() <= 0) |
|
480 | 480 | return 0; |
|
481 | 481 | |
|
482 | 482 | qreal min = INT_MAX; |
|
483 | 483 | |
|
484 | 484 | for (int i = 0; i < m_barSets.count(); i++) { |
|
485 | 485 | int categoryCount = m_barSets.at(i)->count(); |
|
486 | 486 | for (int j = 0; j < categoryCount; j++) { |
|
487 | 487 | qreal temp = m_barSets.at(i)->at(j); |
|
488 | 488 | if (temp < min) |
|
489 | 489 | min = temp; |
|
490 | 490 | } |
|
491 | 491 | } |
|
492 | 492 | return min; |
|
493 | 493 | } |
|
494 | 494 | |
|
495 | 495 | qreal QAbstractBarSeriesPrivate::max() |
|
496 | 496 | { |
|
497 | 497 | if (m_barSets.count() <= 0) |
|
498 | 498 | return 0; |
|
499 | 499 | |
|
500 | 500 | qreal max = INT_MIN; |
|
501 | 501 | |
|
502 | 502 | for (int i = 0; i < m_barSets.count(); i++) { |
|
503 | 503 | int categoryCount = m_barSets.at(i)->count(); |
|
504 | 504 | for (int j = 0; j < categoryCount; j++) { |
|
505 | 505 | qreal temp = m_barSets.at(i)->at(j); |
|
506 | 506 | if (temp > max) |
|
507 | 507 | max = temp; |
|
508 | 508 | } |
|
509 | 509 | } |
|
510 | 510 | |
|
511 | 511 | return max; |
|
512 | 512 | } |
|
513 | 513 | |
|
514 | 514 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
515 | 515 | { |
|
516 | 516 | if ((set < 0) || (set >= m_barSets.count())) |
|
517 | 517 | return 0; // No set, no value. |
|
518 | 518 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
519 | 519 | return 0; // No category, no value. |
|
520 | 520 | |
|
521 | 521 | return m_barSets.at(set)->at(category); |
|
522 | 522 | } |
|
523 | 523 | |
|
524 | 524 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
525 | 525 | { |
|
526 | 526 | if ((set < 0) || (set >= m_barSets.count())) |
|
527 | 527 | return 0; // No set, no value. |
|
528 | 528 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
529 | 529 | return 0; // No category, no value. |
|
530 | 530 | |
|
531 | 531 | qreal value = m_barSets.at(set)->at(category); |
|
532 | 532 | qreal sum = categorySum(category); |
|
533 | 533 | if (qFuzzyCompare(sum, 0)) |
|
534 | 534 | return 0; |
|
535 | 535 | |
|
536 | 536 | return value / sum; |
|
537 | 537 | } |
|
538 | 538 | |
|
539 | 539 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
540 | 540 | { |
|
541 | 541 | qreal sum(0); |
|
542 | 542 | int count = m_barSets.count(); // Count sets |
|
543 | 543 | for (int set = 0; set < count; set++) { |
|
544 | 544 | if (category < m_barSets.at(set)->count()) |
|
545 | 545 | sum += m_barSets.at(set)->at(category); |
|
546 | 546 | } |
|
547 | 547 | return sum; |
|
548 | 548 | } |
|
549 | 549 | |
|
550 | 550 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
551 | 551 | { |
|
552 | 552 | qreal sum(0); |
|
553 | 553 | int count = m_barSets.count(); // Count sets |
|
554 | 554 | for (int set = 0; set < count; set++) { |
|
555 | 555 | if (category < m_barSets.at(set)->count()) |
|
556 | 556 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
557 | 557 | } |
|
558 | 558 | return sum; |
|
559 | 559 | } |
|
560 | 560 | |
|
561 | 561 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
562 | 562 | { |
|
563 | 563 | qreal max = INT_MIN; |
|
564 | 564 | int count = categoryCount(); |
|
565 | 565 | for (int i = 0; i < count; i++) { |
|
566 | 566 | qreal sum = categorySum(i); |
|
567 | 567 | if (sum > max) |
|
568 | 568 | max = sum; |
|
569 | 569 | } |
|
570 | 570 | return max; |
|
571 | 571 | } |
|
572 | 572 | |
|
573 | 573 | qreal QAbstractBarSeriesPrivate::minX() |
|
574 | 574 | { |
|
575 | 575 | if (m_barSets.count() <= 0) |
|
576 | 576 | return 0; |
|
577 | 577 | |
|
578 | 578 | qreal min = INT_MAX; |
|
579 | 579 | |
|
580 | 580 | for (int i = 0; i < m_barSets.count(); i++) { |
|
581 | 581 | int categoryCount = m_barSets.at(i)->count(); |
|
582 | 582 | for (int j = 0; j < categoryCount; j++) { |
|
583 | 583 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
584 | 584 | if (temp < min) |
|
585 | 585 | min = temp; |
|
586 | 586 | } |
|
587 | 587 | } |
|
588 | 588 | return min; |
|
589 | 589 | } |
|
590 | 590 | |
|
591 | 591 | qreal QAbstractBarSeriesPrivate::maxX() |
|
592 | 592 | { |
|
593 | 593 | if (m_barSets.count() <= 0) |
|
594 | 594 | return 0; |
|
595 | 595 | |
|
596 | 596 | qreal max = INT_MIN; |
|
597 | 597 | |
|
598 | 598 | for (int i = 0; i < m_barSets.count(); i++) { |
|
599 | 599 | int categoryCount = m_barSets.at(i)->count(); |
|
600 | 600 | for (int j = 0; j < categoryCount; j++) { |
|
601 | 601 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
602 | 602 | if (temp > max) |
|
603 | 603 | max = temp; |
|
604 | 604 | } |
|
605 | 605 | } |
|
606 | 606 | |
|
607 | 607 | return max; |
|
608 | 608 | } |
|
609 | 609 | |
|
610 | 610 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) |
|
611 | 611 | { |
|
612 | 612 | // Returns top (sum of all positive values) of category. |
|
613 | 613 | // Returns 0, if all values are negative |
|
614 | 614 | qreal top(0); |
|
615 | 615 | int count = m_barSets.count(); |
|
616 | 616 | for (int set = 0; set < count; set++) { |
|
617 | 617 | if (category < m_barSets.at(set)->count()) { |
|
618 | 618 | qreal temp = m_barSets.at(set)->at(category); |
|
619 | 619 | if (temp > 0) { |
|
620 | 620 | top += temp; |
|
621 | 621 | } |
|
622 | 622 | } |
|
623 | 623 | } |
|
624 | 624 | return top; |
|
625 | 625 | } |
|
626 | 626 | |
|
627 | 627 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) |
|
628 | 628 | { |
|
629 | 629 | // Returns bottom (sum of all negative values) of category |
|
630 | 630 | // Returns 0, if all values are positive |
|
631 | 631 | qreal bottom(0); |
|
632 | 632 | int count = m_barSets.count(); |
|
633 | 633 | for (int set = 0; set < count; set++) { |
|
634 | 634 | if (category < m_barSets.at(set)->count()) { |
|
635 | 635 | qreal temp = m_barSets.at(set)->at(category); |
|
636 | 636 | if (temp < 0) { |
|
637 | 637 | bottom += temp; |
|
638 | 638 | } |
|
639 | 639 | } |
|
640 | 640 | } |
|
641 | 641 | return bottom; |
|
642 | 642 | } |
|
643 | 643 | |
|
644 | 644 | qreal QAbstractBarSeriesPrivate::top() |
|
645 | 645 | { |
|
646 | 646 | // Returns top of all categories |
|
647 | 647 | qreal top(0); |
|
648 | 648 | int count = categoryCount(); |
|
649 | 649 | for (int i = 0; i < count; i++) { |
|
650 | 650 | qreal temp = categoryTop(i); |
|
651 | 651 | if (temp > top) |
|
652 | 652 | top = temp; |
|
653 | 653 | } |
|
654 | 654 | return top; |
|
655 | 655 | } |
|
656 | 656 | |
|
657 | 657 | qreal QAbstractBarSeriesPrivate::bottom() |
|
658 | 658 | { |
|
659 | 659 | // Returns bottom of all categories |
|
660 | 660 | qreal bottom(0); |
|
661 | 661 | int count = categoryCount(); |
|
662 | 662 | for (int i = 0; i < count; i++) { |
|
663 | 663 | qreal temp = categoryBottom(i); |
|
664 | 664 | if (temp < bottom) |
|
665 | 665 | bottom = temp; |
|
666 | 666 | } |
|
667 | 667 | return bottom; |
|
668 | 668 | } |
|
669 | 669 | |
|
670 | 670 | bool QAbstractBarSeriesPrivate::blockBarUpdate() |
|
671 | 671 | { |
|
672 | 672 | return m_blockBarUpdate; |
|
673 | 673 | } |
|
674 | 674 | |
|
675 | 675 | void QAbstractBarSeriesPrivate::initializeDomain() |
|
676 | 676 | { |
|
677 | 677 | qreal minX(domain()->minX()); |
|
678 | 678 | qreal minY(domain()->minY()); |
|
679 | 679 | qreal maxX(domain()->maxX()); |
|
680 | 680 | qreal maxY(domain()->maxY()); |
|
681 | 681 | |
|
682 | 682 | qreal seriesMinX = this->minX(); |
|
683 | 683 | qreal seriesMaxX = this->maxX(); |
|
684 | 684 | qreal y = max(); |
|
685 | 685 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
686 | 686 | minY = qMin(minY, y); |
|
687 | 687 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
688 | 688 | maxY = qMax(maxY, y); |
|
689 | 689 | |
|
690 | 690 | domain()->setRange(minX, maxX, minY, maxY); |
|
691 | 691 | } |
|
692 | 692 | |
|
693 | 693 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
694 | 694 | { |
|
695 | 695 | Q_Q(QAbstractBarSeries); |
|
696 | 696 | QList<QLegendMarker*> markers; |
|
697 | 697 | |
|
698 | 698 | foreach(QBarSet* set, q->barSets()) { |
|
699 | 699 | QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend); |
|
700 | 700 | markers << marker; |
|
701 | 701 | } |
|
702 | 702 | return markers; |
|
703 | 703 | } |
|
704 | 704 | |
|
705 | 705 | |
|
706 | 706 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
707 | 707 | { |
|
708 | 708 | if ((m_barSets.contains(set)) || (set == 0)) |
|
709 | 709 | return false; // Fail if set is already in list or set is null. |
|
710 | 710 | |
|
711 | 711 | m_barSets.append(set); |
|
712 | 712 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
713 | 713 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
714 | 714 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
715 | 715 | |
|
716 | 716 | emit restructuredBars(); // this notifies barchartitem |
|
717 | 717 | return true; |
|
718 | 718 | } |
|
719 | 719 | |
|
720 | 720 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
721 | 721 | { |
|
722 | 722 | if (!m_barSets.contains(set)) |
|
723 | 723 | return false; // Fail if set is not in list |
|
724 | 724 | |
|
725 | 725 | m_barSets.removeOne(set); |
|
726 | 726 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
727 | 727 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
728 | 728 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
729 | 729 | |
|
730 | 730 | emit restructuredBars(); // this notifies barchartitem |
|
731 | 731 | return true; |
|
732 | 732 | } |
|
733 | 733 | |
|
734 | 734 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets) |
|
735 | 735 | { |
|
736 | 736 | foreach (QBarSet *set, sets) { |
|
737 | 737 | if ((set == 0) || (m_barSets.contains(set))) |
|
738 | 738 | return false; // Fail if any of the sets is null or is already appended. |
|
739 | 739 | if (sets.count(set) != 1) |
|
740 | 740 | return false; // Also fail if same set is more than once in given list. |
|
741 | 741 | } |
|
742 | 742 | |
|
743 | 743 | foreach (QBarSet *set, sets) { |
|
744 | 744 | m_barSets.append(set); |
|
745 | 745 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
746 | 746 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
747 | 747 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
748 | 748 | } |
|
749 | 749 | |
|
750 | 750 | emit restructuredBars(); // this notifies barchartitem |
|
751 | 751 | return true; |
|
752 | 752 | } |
|
753 | 753 | |
|
754 | 754 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets) |
|
755 | 755 | { |
|
756 | 756 | if (sets.count() == 0) |
|
757 | 757 | return false; |
|
758 | 758 | |
|
759 | 759 | foreach (QBarSet *set, sets) { |
|
760 | 760 | if ((set == 0) || (!m_barSets.contains(set))) |
|
761 | 761 | return false; // Fail if any of the sets is null or is not in series |
|
762 | 762 | if (sets.count(set) != 1) |
|
763 | 763 | return false; // Also fail if same set is more than once in given list. |
|
764 | 764 | } |
|
765 | 765 | |
|
766 | 766 | foreach (QBarSet *set, sets) { |
|
767 | 767 | m_barSets.removeOne(set); |
|
768 | 768 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
769 | 769 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
770 | 770 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
771 | 771 | } |
|
772 | 772 | |
|
773 | 773 | emit restructuredBars(); // this notifies barchartitem |
|
774 | 774 | |
|
775 | 775 | return true; |
|
776 | 776 | } |
|
777 | 777 | |
|
778 | 778 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
779 | 779 | { |
|
780 | 780 | if ((m_barSets.contains(set)) || (set == 0)) |
|
781 | 781 | return false; // Fail if set is already in list or set is null. |
|
782 | 782 | |
|
783 | 783 | m_barSets.insert(index, set); |
|
784 | 784 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
785 | 785 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
786 | 786 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
787 | 787 | |
|
788 | 788 | emit restructuredBars(); // this notifies barchartitem |
|
789 | 789 | return true; |
|
790 | 790 | } |
|
791 | 791 | |
|
792 | 792 | void QAbstractBarSeriesPrivate::initializeAxes() |
|
793 | 793 | { |
|
794 | 794 | Q_Q(QAbstractBarSeries); |
|
795 | 795 | |
|
796 | 796 | foreach(QAbstractAxis* axis, m_axes) { |
|
797 | 797 | |
|
798 | 798 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
799 | 799 | switch (q->type()) { |
|
800 | 800 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
801 | 801 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
802 | 802 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
803 | 803 | if (axis->orientation() == Qt::Vertical) |
|
804 | 804 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
805 | 805 | break; |
|
806 | 806 | case QAbstractSeries::SeriesTypeBar: |
|
807 | 807 | case QAbstractSeries::SeriesTypePercentBar: |
|
808 | 808 | case QAbstractSeries::SeriesTypeStackedBar: |
|
809 | 809 | case QAbstractSeries::SeriesTypeBoxPlot: |
|
810 | 810 | if (axis->orientation() == Qt::Horizontal) |
|
811 | 811 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
812 | 812 | break; |
|
813 | 813 | default: |
|
814 | 814 | qWarning() << "Unexpected series type"; |
|
815 | 815 | break; |
|
816 | 816 | } |
|
817 | 817 | } |
|
818 | 818 | } |
|
819 | 819 | } |
|
820 | 820 | |
|
821 | 821 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
822 | 822 | { |
|
823 | 823 | Q_Q(const QAbstractBarSeries); |
|
824 | 824 | |
|
825 | 825 | switch (q->type()) { |
|
826 | 826 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
827 | 827 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
828 | 828 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
829 | 829 | if (orientation == Qt::Vertical) |
|
830 | 830 | return QAbstractAxis::AxisTypeBarCategory; |
|
831 | 831 | break; |
|
832 | 832 | case QAbstractSeries::SeriesTypeBar: |
|
833 | 833 | case QAbstractSeries::SeriesTypePercentBar: |
|
834 | 834 | case QAbstractSeries::SeriesTypeStackedBar: |
|
835 | 835 | case QAbstractSeries::SeriesTypeBoxPlot: |
|
836 | 836 | if (orientation == Qt::Horizontal) |
|
837 | 837 | return QAbstractAxis::AxisTypeBarCategory; |
|
838 | 838 | break; |
|
839 | 839 | default: |
|
840 | 840 | qWarning() << "Unexpected series type"; |
|
841 | 841 | break; |
|
842 | 842 | } |
|
843 | 843 | return QAbstractAxis::AxisTypeValue; |
|
844 | 844 | |
|
845 | 845 | } |
|
846 | 846 | |
|
847 | 847 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) |
|
848 | 848 | { |
|
849 | 849 | QStringList categories; |
|
850 | 850 | if (axis->categories().isEmpty()) { |
|
851 | 851 | for (int i(1); i < categoryCount() + 1; i++) |
|
852 | 852 | categories << QString::number(i); |
|
853 | 853 | axis->append(categories); |
|
854 | 854 | } |
|
855 | 855 | } |
|
856 | 856 | |
|
857 | 857 | QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
858 | 858 | { |
|
859 | 859 | if (defaultAxisType(orientation) == QAbstractAxis::AxisTypeBarCategory) |
|
860 | 860 | return new QBarCategoryAxis; |
|
861 | 861 | else |
|
862 | 862 | return new QValueAxis; |
|
863 | 863 | } |
|
864 | 864 | |
|
865 | 865 | void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
866 | 866 | { |
|
867 | 867 | m_blockBarUpdate = true; // Ensures that the bars are not updated before the theme is ready |
|
868 | 868 | |
|
869 | 869 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
870 | 870 | |
|
871 | 871 | qreal takeAtPos = 0.5; |
|
872 | 872 | qreal step = 0.2; |
|
873 | 873 | if (m_barSets.count() > 1) { |
|
874 | 874 | step = 1.0 / (qreal) m_barSets.count(); |
|
875 | 875 | if (m_barSets.count() % gradients.count()) |
|
876 | 876 | step *= gradients.count(); |
|
877 | 877 | else |
|
878 | 878 | step *= (gradients.count() - 1); |
|
879 | 879 | } |
|
880 | 880 | |
|
881 | 881 | for (int i(0); i < m_barSets.count(); i++) { |
|
882 | 882 | int colorIndex = (index + i) % gradients.count(); |
|
883 | 883 | if (i > 0 && i %gradients.count() == 0) { |
|
884 | 884 | // There is no dedicated base color for each sets, generate more colors |
|
885 | 885 | takeAtPos += step; |
|
886 | 886 | if (takeAtPos == 1.0) |
|
887 | 887 | takeAtPos += step; |
|
888 | 888 | takeAtPos -= (int) takeAtPos; |
|
889 | 889 | } |
|
890 | 890 | if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_brush) |
|
891 | 891 | m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos)); |
|
892 | 892 | |
|
893 | 893 | // Pick label color from the opposite end of the gradient. |
|
894 | 894 | // 0.3 as a boundary seems to work well. |
|
895 | 895 | if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_labelBrush) { |
|
896 | 896 | if (takeAtPos < 0.3) |
|
897 | 897 | m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1)); |
|
898 | 898 | else |
|
899 | 899 | m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0)); |
|
900 | 900 | } |
|
901 | 901 | if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->d_ptr->m_pen) { |
|
902 | 902 | QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); |
|
903 | 903 | m_barSets.at(i)->setPen(c); |
|
904 | 904 | } |
|
905 | 905 | } |
|
906 | 906 | m_blockBarUpdate = false; |
|
907 | 907 | emit updatedBars(); |
|
908 | 908 | } |
|
909 | 909 | |
|
910 | 910 | void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
911 | 911 | { |
|
912 | 912 | AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data()); |
|
913 | 913 | Q_ASSERT(bar); |
|
914 | 914 | if (bar->animation()) |
|
915 | 915 | bar->animation()->stopAndDestroyLater(); |
|
916 | 916 | |
|
917 | 917 | if (options.testFlag(QChart::SeriesAnimations)) |
|
918 | 918 | bar->setAnimation(new BarAnimation(bar)); |
|
919 | 919 | else |
|
920 | 920 | bar->setAnimation(0); |
|
921 | 921 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
922 | 922 | } |
|
923 | 923 | |
|
924 | 924 | #include "moc_qabstractbarseries.cpp" |
|
925 | 925 | #include "moc_qabstractbarseries_p.cpp" |
|
926 | 926 | |
|
927 | 927 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,673 +1,673 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qbarset.h" |
|
22 | 22 | #include "qbarset_p.h" |
|
23 | 23 | #include "charthelpers_p.h" |
|
24 | 24 | #include "qchart_p.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | /*! |
|
29 | 29 | \class QBarSet |
|
30 | 30 | \inmodule Qt Charts |
|
31 | 31 | \brief Building block for different bar charts. |
|
32 | 32 | |
|
33 | 33 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
34 | 34 | First value of set is assumed to belong to first category, second to second category and so on. |
|
35 | 35 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
36 | 36 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
37 | 37 | |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
41 | 41 | */ |
|
42 | 42 | #ifdef QDOC_QT5 |
|
43 | 43 | /*! |
|
44 | 44 | \qmltype BarSet |
|
45 | 45 | \instantiates QBarSet |
|
46 | 46 | \inqmlmodule QtCommercial.Chart |
|
47 | 47 | |
|
48 |
\include |
|
|
48 | \include doc/src/barset.qdocinc | |
|
49 | 49 | */ |
|
50 | 50 | #else |
|
51 | 51 | /*! |
|
52 | 52 | \qmlclass BarSet QBarSet |
|
53 | 53 | |
|
54 | 54 | \include ../doc/src/barset.qdocinc |
|
55 | 55 | */ |
|
56 | 56 | #endif |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QBarSet::label |
|
60 | 60 | Defines the label of the bar set. |
|
61 | 61 | */ |
|
62 | 62 | /*! |
|
63 | 63 | \qmlproperty string BarSet::label |
|
64 | 64 | Defines the label of the bar set. |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \property QBarSet::pen |
|
69 | 69 | \brief Defines the pen used by the bar set. |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \property QBarSet::brush |
|
74 | 74 | \brief Defines the brush used by the bar set. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QBarSet::labelBrush |
|
79 | 79 | \brief Defines the brush used by the bar set's label. |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \property QBarSet::labelFont |
|
84 | 84 | \brief Defines the font used by the bar set's label. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \qmlproperty Font BarSet::labelFont |
|
89 | 89 | Defines the font used by the bar set's label. |
|
90 | 90 | |
|
91 | 91 | See the Qt documentation for more details of Font. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QBarSet::color |
|
96 | 96 | The fill (brush) color of the bar set. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty color BarSet::color |
|
100 | 100 | The fill (brush) color of the bar set. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \property QBarSet::borderColor |
|
105 | 105 | The line (pen) color of the bar set. |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty color BarSet::borderColor |
|
109 | 109 | The line (pen) color of the bar set. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \qmlproperty real BarSet::borderWidth |
|
114 | 114 | The width of the border line. By default the width is 2.0. |
|
115 | 115 | */ |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | 118 | \property QBarSet::labelColor |
|
119 | 119 | The text (label) color of the bar set. |
|
120 | 120 | */ |
|
121 | 121 | /*! |
|
122 | 122 | \qmlproperty color BarSet::labelColor |
|
123 | 123 | The text (label) color of the bar set. |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | /*! |
|
127 | 127 | \fn void QBarSet::clicked(int index) |
|
128 | 128 | |
|
129 | 129 | The signal is emitted if the user clicks with a mouse on top of bar set. |
|
130 | 130 | Clicked bar inside set is indexed by \a index |
|
131 | 131 | */ |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \fn void QBarSet::hovered(bool status) |
|
135 | 135 | |
|
136 | 136 | The signal is emitted if mouse is hovered on top of bar set. |
|
137 | 137 | Parameter \a status is true, if mouse entered on top of bar set, false if mouse left from top of bar set. |
|
138 | 138 | */ |
|
139 | 139 | |
|
140 | 140 | /*! |
|
141 | 141 | \fn void QBarSet::hovered(bool status, int index) |
|
142 | 142 | |
|
143 | 143 | The signal is emitted if mouse is hovered on top of bar set. |
|
144 | 144 | Parameter \a status is true, if mouse entered on top of bar set, false if mouse left from top of bar set. |
|
145 | 145 | Hovered bar inside the set is indexed by \a index. |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QBarSet::labelChanged() |
|
151 | 151 | This signal is emitted when the label of the bar set has changed. |
|
152 | 152 | \sa label |
|
153 | 153 | */ |
|
154 | 154 | /*! |
|
155 | 155 | \qmlsignal BarSet::onLabelChanged() |
|
156 | 156 | This signal is emitted when the label of the bar set has changed. |
|
157 | 157 | */ |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | \fn void QBarSet::penChanged() |
|
161 | 161 | This signal is emitted when the pen of the bar set has changed. |
|
162 | 162 | \sa pen |
|
163 | 163 | */ |
|
164 | 164 | |
|
165 | 165 | /*! |
|
166 | 166 | \fn void QBarSet::brushChanged() |
|
167 | 167 | This signal is emitted when the brush of the bar set has changed. |
|
168 | 168 | \sa brush |
|
169 | 169 | */ |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | \fn void QBarSet::labelBrushChanged() |
|
173 | 173 | This signal is emitted when the brush of the bar set's label has changed. |
|
174 | 174 | \sa labelBrush |
|
175 | 175 | */ |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | \fn void QBarSet::labelFontChanged() |
|
179 | 179 | This signal is emitted when the font of the bar set's label has changed. |
|
180 | 180 | \sa labelBrush |
|
181 | 181 | */ |
|
182 | 182 | |
|
183 | 183 | /*! |
|
184 | 184 | \fn void QBarSet::colorChanged(QColor) |
|
185 | 185 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
186 | 186 | */ |
|
187 | 187 | /*! |
|
188 | 188 | \qmlsignal BarSet::onColorChanged(color color) |
|
189 | 189 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
190 | 190 | */ |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | \fn void QBarSet::borderColorChanged(QColor) |
|
194 | 194 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
195 | 195 | */ |
|
196 | 196 | /*! |
|
197 | 197 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
198 | 198 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
199 | 199 | */ |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | \fn void QBarSet::labelColorChanged(QColor) |
|
203 | 203 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
204 | 204 | */ |
|
205 | 205 | /*! |
|
206 | 206 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
207 | 207 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
208 | 208 | */ |
|
209 | 209 | |
|
210 | 210 | /*! |
|
211 | 211 | \fn void QBarSet::valuesAdded(int index, int count) |
|
212 | 212 | This signal is emitted when new values have been added to the set. |
|
213 | 213 | Parameter \a index indicates the position of the first inserted value. |
|
214 | 214 | Parameter \a count is the number of inserted values. |
|
215 | 215 | \sa append(), insert() |
|
216 | 216 | */ |
|
217 | 217 | /*! |
|
218 | 218 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
219 | 219 | This signal is emitted when new values have been added to the set. |
|
220 | 220 | Parameter \a index indicates the position of the first inserted value. |
|
221 | 221 | Parameter \a count is the number of inserted values. |
|
222 | 222 | */ |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
226 | 226 | This signal is emitted values have been removed from the set. |
|
227 | 227 | Parameter \a index indicates the position of the first removed value. |
|
228 | 228 | Parameter \a count is the number of removed values. |
|
229 | 229 | \sa remove() |
|
230 | 230 | */ |
|
231 | 231 | /*! |
|
232 | 232 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
233 | 233 | This signal is emitted values have been removed from the set. |
|
234 | 234 | Parameter \a index indicates the position of the first removed value. |
|
235 | 235 | Parameter \a count is the number of removed values. |
|
236 | 236 | */ |
|
237 | 237 | |
|
238 | 238 | /*! |
|
239 | 239 | \fn void QBarSet::valueChanged(int index) |
|
240 | 240 | This signal is emitted values the value in the set has been modified. |
|
241 | 241 | Parameter \a index indicates the position of the modified value. |
|
242 | 242 | \sa at() |
|
243 | 243 | */ |
|
244 | 244 | /*! |
|
245 | 245 | \qmlsignal BarSet::onValueChanged(int index) |
|
246 | 246 | This signal is emitted values the value in the set has been modified. |
|
247 | 247 | Parameter \a index indicates the position of the modified value. |
|
248 | 248 | */ |
|
249 | 249 | |
|
250 | 250 | /*! |
|
251 | 251 | \qmlproperty int BarSet::count |
|
252 | 252 | The count of values on the bar set |
|
253 | 253 | */ |
|
254 | 254 | |
|
255 | 255 | /*! |
|
256 | 256 | \qmlproperty QVariantList BarSet::values |
|
257 | 257 | The values of the bar set. You can set either a list of reals or a list of points as values. If you set a list of |
|
258 | 258 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
259 | 259 | x-coordinate. For example: |
|
260 | 260 | \code |
|
261 | 261 | myBarSet1.values = [0, 5, 1, 5]; |
|
262 | 262 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
263 | 263 | \endcode |
|
264 | 264 | */ |
|
265 | 265 | |
|
266 | 266 | /*! |
|
267 | 267 | Constructs QBarSet with a label of \a label and with parent of \a parent. |
|
268 | 268 | */ |
|
269 | 269 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
270 | 270 | : QObject(parent), |
|
271 | 271 | d_ptr(new QBarSetPrivate(label, this)) |
|
272 | 272 | { |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Destroys the bar set. |
|
277 | 277 | */ |
|
278 | 278 | QBarSet::~QBarSet() |
|
279 | 279 | { |
|
280 | 280 | // NOTE: d_ptr destroyed by QObject |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | /*! |
|
284 | 284 | Sets new \a label for set. |
|
285 | 285 | */ |
|
286 | 286 | void QBarSet::setLabel(const QString label) |
|
287 | 287 | { |
|
288 | 288 | d_ptr->m_label = label; |
|
289 | 289 | emit labelChanged(); |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | /*! |
|
293 | 293 | Returns label of the set. |
|
294 | 294 | */ |
|
295 | 295 | QString QBarSet::label() const |
|
296 | 296 | { |
|
297 | 297 | return d_ptr->m_label; |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | /*! |
|
301 | 301 | Appends new value \a value to the end of set. |
|
302 | 302 | */ |
|
303 | 303 | void QBarSet::append(const qreal value) |
|
304 | 304 | { |
|
305 | 305 | // Convert to QPointF |
|
306 | 306 | int index = d_ptr->m_values.count(); |
|
307 | 307 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
308 | 308 | emit valuesAdded(index, 1); |
|
309 | 309 | } |
|
310 | 310 | |
|
311 | 311 | /*! |
|
312 | 312 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
313 | 313 | are appended to end of bar set. |
|
314 | 314 | \sa append() |
|
315 | 315 | */ |
|
316 | 316 | void QBarSet::append(const QList<qreal> &values) |
|
317 | 317 | { |
|
318 | 318 | int index = d_ptr->m_values.count(); |
|
319 | 319 | d_ptr->append(values); |
|
320 | 320 | emit valuesAdded(index, values.count()); |
|
321 | 321 | } |
|
322 | 322 | |
|
323 | 323 | /*! |
|
324 | 324 | Convenience operator. Same as append, with real \a value. |
|
325 | 325 | \sa append() |
|
326 | 326 | */ |
|
327 | 327 | QBarSet &QBarSet::operator << (const qreal &value) |
|
328 | 328 | { |
|
329 | 329 | append(value); |
|
330 | 330 | return *this; |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Inserts new \a value on the \a index position. |
|
335 | 335 | The value that is currently at this postion is moved to position index + 1 |
|
336 | 336 | \sa remove() |
|
337 | 337 | */ |
|
338 | 338 | void QBarSet::insert(const int index, const qreal value) |
|
339 | 339 | { |
|
340 | 340 | d_ptr->insert(index, value); |
|
341 | 341 | emit valuesAdded(index, 1); |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | /*! |
|
345 | 345 | Removes \a count number of values from the set starting at \a index. |
|
346 | 346 | \sa insert() |
|
347 | 347 | */ |
|
348 | 348 | void QBarSet::remove(const int index, const int count) |
|
349 | 349 | { |
|
350 | 350 | int removedCount = d_ptr->remove(index, count); |
|
351 | 351 | if (removedCount > 0) |
|
352 | 352 | emit valuesRemoved(index, removedCount); |
|
353 | 353 | return; |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | /*! |
|
357 | 357 | Sets a new value \a value to set, indexed by \a index. |
|
358 | 358 | */ |
|
359 | 359 | void QBarSet::replace(const int index, const qreal value) |
|
360 | 360 | { |
|
361 | 361 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
362 | 362 | d_ptr->replace(index, value); |
|
363 | 363 | emit valueChanged(index); |
|
364 | 364 | } |
|
365 | 365 | } |
|
366 | 366 | |
|
367 | 367 | |
|
368 | 368 | /*! |
|
369 | 369 | Returns value of set indexed by \a index. |
|
370 | 370 | If the index is out of bounds 0.0 is returned. |
|
371 | 371 | */ |
|
372 | 372 | qreal QBarSet::at(const int index) const |
|
373 | 373 | { |
|
374 | 374 | if (index < 0 || index >= d_ptr->m_values.count()) |
|
375 | 375 | return 0; |
|
376 | 376 | return d_ptr->m_values.at(index).y(); |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | /*! |
|
380 | 380 | Returns value of set indexed by \a index. |
|
381 | 381 | If the index is out of bounds 0.0 is returned. |
|
382 | 382 | */ |
|
383 | 383 | qreal QBarSet::operator [](const int index) const |
|
384 | 384 | { |
|
385 | 385 | return at(index); |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | /*! |
|
389 | 389 | Returns count of values in set. |
|
390 | 390 | */ |
|
391 | 391 | int QBarSet::count() const |
|
392 | 392 | { |
|
393 | 393 | return d_ptr->m_values.count(); |
|
394 | 394 | } |
|
395 | 395 | |
|
396 | 396 | /*! |
|
397 | 397 | Returns sum of all values in the bar set. |
|
398 | 398 | */ |
|
399 | 399 | qreal QBarSet::sum() const |
|
400 | 400 | { |
|
401 | 401 | qreal total(0); |
|
402 | 402 | for (int i = 0; i < d_ptr->m_values.count(); i++) |
|
403 | 403 | total += d_ptr->m_values.at(i).y(); |
|
404 | 404 | return total; |
|
405 | 405 | } |
|
406 | 406 | |
|
407 | 407 | /*! |
|
408 | 408 | Sets pen for set. Bars of this set are drawn using \a pen |
|
409 | 409 | */ |
|
410 | 410 | void QBarSet::setPen(const QPen &pen) |
|
411 | 411 | { |
|
412 | 412 | if (d_ptr->m_pen != pen) { |
|
413 | 413 | d_ptr->m_pen = pen; |
|
414 | 414 | emit d_ptr->updatedBars(); |
|
415 | 415 | emit penChanged(); |
|
416 | 416 | } |
|
417 | 417 | } |
|
418 | 418 | |
|
419 | 419 | /*! |
|
420 | 420 | Returns pen of the set. |
|
421 | 421 | */ |
|
422 | 422 | QPen QBarSet::pen() const |
|
423 | 423 | { |
|
424 | 424 | if (d_ptr->m_pen == QChartPrivate::defaultPen()) |
|
425 | 425 | return QPen(); |
|
426 | 426 | else |
|
427 | 427 | return d_ptr->m_pen; |
|
428 | 428 | } |
|
429 | 429 | |
|
430 | 430 | /*! |
|
431 | 431 | Sets brush for the set. Bars of this set are drawn using \a brush. |
|
432 | 432 | */ |
|
433 | 433 | void QBarSet::setBrush(const QBrush &brush) |
|
434 | 434 | { |
|
435 | 435 | if (d_ptr->m_brush != brush) { |
|
436 | 436 | d_ptr->m_brush = brush; |
|
437 | 437 | emit d_ptr->updatedBars(); |
|
438 | 438 | emit brushChanged(); |
|
439 | 439 | } |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | /*! |
|
443 | 443 | Returns brush of the set. |
|
444 | 444 | */ |
|
445 | 445 | QBrush QBarSet::brush() const |
|
446 | 446 | { |
|
447 | 447 | if (d_ptr->m_brush == QChartPrivate::defaultBrush()) |
|
448 | 448 | return QBrush(); |
|
449 | 449 | else |
|
450 | 450 | return d_ptr->m_brush; |
|
451 | 451 | } |
|
452 | 452 | |
|
453 | 453 | /*! |
|
454 | 454 | Sets \a brush of the values that are drawn on top of this bar set. |
|
455 | 455 | */ |
|
456 | 456 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
457 | 457 | { |
|
458 | 458 | if (d_ptr->m_labelBrush != brush) { |
|
459 | 459 | d_ptr->m_labelBrush = brush; |
|
460 | 460 | emit d_ptr->updatedBars(); |
|
461 | 461 | emit labelBrushChanged(); |
|
462 | 462 | } |
|
463 | 463 | } |
|
464 | 464 | |
|
465 | 465 | /*! |
|
466 | 466 | Returns brush of the values that are drawn on top of this bar set. |
|
467 | 467 | */ |
|
468 | 468 | QBrush QBarSet::labelBrush() const |
|
469 | 469 | { |
|
470 | 470 | if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush()) |
|
471 | 471 | return QBrush(); |
|
472 | 472 | else |
|
473 | 473 | return d_ptr->m_labelBrush; |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | /*! |
|
477 | 477 | Sets the \a font for values that are drawn on top of this bar set. |
|
478 | 478 | */ |
|
479 | 479 | void QBarSet::setLabelFont(const QFont &font) |
|
480 | 480 | { |
|
481 | 481 | if (d_ptr->m_labelFont != font) { |
|
482 | 482 | d_ptr->m_labelFont = font; |
|
483 | 483 | emit d_ptr->updatedBars(); |
|
484 | 484 | emit labelFontChanged(); |
|
485 | 485 | } |
|
486 | 486 | |
|
487 | 487 | } |
|
488 | 488 | |
|
489 | 489 | /*! |
|
490 | 490 | Returns the pen for values that are drawn on top of this bar set. |
|
491 | 491 | */ |
|
492 | 492 | QFont QBarSet::labelFont() const |
|
493 | 493 | { |
|
494 | 494 | return d_ptr->m_labelFont; |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | /*! |
|
498 | 498 | Returns the color of the brush of bar set. |
|
499 | 499 | */ |
|
500 | 500 | QColor QBarSet::color() |
|
501 | 501 | { |
|
502 | 502 | return brush().color(); |
|
503 | 503 | } |
|
504 | 504 | |
|
505 | 505 | /*! |
|
506 | 506 | Sets the \a color of brush for this bar set. |
|
507 | 507 | */ |
|
508 | 508 | void QBarSet::setColor(QColor color) |
|
509 | 509 | { |
|
510 | 510 | QBrush b = brush(); |
|
511 | 511 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { |
|
512 | 512 | b.setColor(color); |
|
513 | 513 | if (b.style() == Qt::NoBrush) { |
|
514 | 514 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) |
|
515 | 515 | // This prevents theme to override color defined in QML side: |
|
516 | 516 | // BarSet { label: "Bob"; color:"red"; values: [1,2,3] } |
|
517 | 517 | // The color must be obeyed, since user wanted it. |
|
518 | 518 | b.setStyle(Qt::SolidPattern); |
|
519 | 519 | } |
|
520 | 520 | setBrush(b); |
|
521 | 521 | emit colorChanged(color); |
|
522 | 522 | } |
|
523 | 523 | } |
|
524 | 524 | |
|
525 | 525 | /*! |
|
526 | 526 | Returns the color of pen of this bar set. |
|
527 | 527 | */ |
|
528 | 528 | QColor QBarSet::borderColor() |
|
529 | 529 | { |
|
530 | 530 | return pen().color(); |
|
531 | 531 | } |
|
532 | 532 | |
|
533 | 533 | /*! |
|
534 | 534 | Sets the color of pen for this bar set. |
|
535 | 535 | */ |
|
536 | 536 | void QBarSet::setBorderColor(QColor color) |
|
537 | 537 | { |
|
538 | 538 | QPen p = pen(); |
|
539 | 539 | if (p.color() != color) { |
|
540 | 540 | p.setColor(color); |
|
541 | 541 | setPen(p); |
|
542 | 542 | emit borderColorChanged(color); |
|
543 | 543 | } |
|
544 | 544 | } |
|
545 | 545 | |
|
546 | 546 | /*! |
|
547 | 547 | Returns the color of labels of this bar set. |
|
548 | 548 | */ |
|
549 | 549 | QColor QBarSet::labelColor() |
|
550 | 550 | { |
|
551 | 551 | return labelBrush().color(); |
|
552 | 552 | } |
|
553 | 553 | |
|
554 | 554 | /*! |
|
555 | 555 | Sets the color of labels for this bar set. |
|
556 | 556 | */ |
|
557 | 557 | void QBarSet::setLabelColor(QColor color) |
|
558 | 558 | { |
|
559 | 559 | QBrush b = labelBrush(); |
|
560 | 560 | if (b == QBrush()) |
|
561 | 561 | b.setStyle(Qt::SolidPattern); |
|
562 | 562 | |
|
563 | 563 | if (b.color() != color) { |
|
564 | 564 | b.setColor(color); |
|
565 | 565 | setLabelBrush(b); |
|
566 | 566 | emit labelColorChanged(color); |
|
567 | 567 | } |
|
568 | 568 | } |
|
569 | 569 | |
|
570 | 570 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
571 | 571 | |
|
572 | 572 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
573 | 573 | q_ptr(parent), |
|
574 | 574 | m_label(label), |
|
575 | 575 | m_pen(QChartPrivate::defaultPen()), |
|
576 | 576 | m_brush(QChartPrivate::defaultBrush()), |
|
577 | 577 | m_labelBrush(QChartPrivate::defaultBrush()) |
|
578 | 578 | { |
|
579 | 579 | } |
|
580 | 580 | |
|
581 | 581 | QBarSetPrivate::~QBarSetPrivate() |
|
582 | 582 | { |
|
583 | 583 | } |
|
584 | 584 | |
|
585 | 585 | void QBarSetPrivate::append(QPointF value) |
|
586 | 586 | { |
|
587 | 587 | if (isValidValue(value)) { |
|
588 | 588 | m_values.append(value); |
|
589 | 589 | emit restructuredBars(); |
|
590 | 590 | } |
|
591 | 591 | } |
|
592 | 592 | |
|
593 | 593 | void QBarSetPrivate::append(QList<QPointF> values) |
|
594 | 594 | { |
|
595 | 595 | for (int i = 0; i < values.count(); i++) { |
|
596 | 596 | if (isValidValue(values.at(i))) |
|
597 | 597 | m_values.append(values.at(i)); |
|
598 | 598 | } |
|
599 | 599 | emit restructuredBars(); |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | void QBarSetPrivate::append(QList<qreal> values) |
|
603 | 603 | { |
|
604 | 604 | int index = m_values.count(); |
|
605 | 605 | for (int i = 0; i < values.count(); i++) { |
|
606 | 606 | if (isValidValue(values.at(i))) { |
|
607 | 607 | m_values.append(QPointF(index, values.at(i))); |
|
608 | 608 | index++; |
|
609 | 609 | } |
|
610 | 610 | } |
|
611 | 611 | emit restructuredBars(); |
|
612 | 612 | } |
|
613 | 613 | |
|
614 | 614 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
615 | 615 | { |
|
616 | 616 | m_values.insert(index, QPointF(index, value)); |
|
617 | 617 | emit restructuredBars(); |
|
618 | 618 | } |
|
619 | 619 | |
|
620 | 620 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
621 | 621 | { |
|
622 | 622 | m_values.insert(index, value); |
|
623 | 623 | emit restructuredBars(); |
|
624 | 624 | } |
|
625 | 625 | |
|
626 | 626 | int QBarSetPrivate::remove(const int index, const int count) |
|
627 | 627 | { |
|
628 | 628 | int removeCount = count; |
|
629 | 629 | |
|
630 | 630 | if ((index < 0) || (m_values.count() == 0)) |
|
631 | 631 | return 0; // Invalid index or not values in list, remove nothing. |
|
632 | 632 | else if ((index + count) > m_values.count()) |
|
633 | 633 | removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed. |
|
634 | 634 | |
|
635 | 635 | int c = 0; |
|
636 | 636 | while (c < removeCount) { |
|
637 | 637 | m_values.removeAt(index); |
|
638 | 638 | c++; |
|
639 | 639 | } |
|
640 | 640 | emit restructuredBars(); |
|
641 | 641 | return removeCount; |
|
642 | 642 | } |
|
643 | 643 | |
|
644 | 644 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
645 | 645 | { |
|
646 | 646 | m_values.replace(index, QPointF(index, value)); |
|
647 | 647 | emit updatedLayout(); |
|
648 | 648 | } |
|
649 | 649 | |
|
650 | 650 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
651 | 651 | { |
|
652 | 652 | m_values.replace(index, value); |
|
653 | 653 | emit updatedLayout(); |
|
654 | 654 | } |
|
655 | 655 | |
|
656 | 656 | qreal QBarSetPrivate::pos(const int index) |
|
657 | 657 | { |
|
658 | 658 | if (index < 0 || index >= m_values.count()) |
|
659 | 659 | return 0; |
|
660 | 660 | return m_values.at(index).x(); |
|
661 | 661 | } |
|
662 | 662 | |
|
663 | 663 | qreal QBarSetPrivate::value(const int index) |
|
664 | 664 | { |
|
665 | 665 | if (index < 0 || index >= m_values.count()) |
|
666 | 666 | return 0; |
|
667 | 667 | return m_values.at(index).y(); |
|
668 | 668 | } |
|
669 | 669 | |
|
670 | 670 | #include "moc_qbarset.cpp" |
|
671 | 671 | #include "moc_qbarset_p.cpp" |
|
672 | 672 | |
|
673 | 673 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,248 +1,248 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qhbarmodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QHBarModelMapper |
|
27 | 27 | \inmodule Qt Charts |
|
28 | 28 | \brief Horizontal model mapper for bar series. |
|
29 | 29 | \mainclass |
|
30 | 30 | |
|
31 | 31 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
32 | 32 | Horizontal model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. |
|
33 | 33 | Model mapper maintains equal size of all the BarSets. |
|
34 | 34 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
35 | 35 | \note Used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
36 | 36 | */ |
|
37 | 37 | #ifdef QDOC_QT5 |
|
38 | 38 | /*! |
|
39 | 39 | \qmltype HBarModelMapper |
|
40 | 40 | \instantiates QHBarModelMapper |
|
41 | 41 | \inqmlmodule QtCommercial.Chart |
|
42 | 42 | |
|
43 |
\include |
|
|
43 | \include doc/src/hbarmodelmapper.qdocinc | |
|
44 | 44 | */ |
|
45 | 45 | #else |
|
46 | 46 | /*! |
|
47 | 47 | \qmlclass HBarModelMapper QHBarModelMapper |
|
48 | 48 | |
|
49 | 49 | \include ../doc/src/hbarmodelmapper.qdocinc |
|
50 | 50 | */ |
|
51 | 51 | #endif |
|
52 | 52 | |
|
53 | 53 | /*! |
|
54 | 54 | \property QHBarModelMapper::series |
|
55 | 55 | \brief Defines the QPieSeries object that is used by the mapper. |
|
56 | 56 | |
|
57 | 57 | All the data in the series is discarded when it is set to the mapper. |
|
58 | 58 | When new series is specified the old series is disconnected (it preserves its data) |
|
59 | 59 | */ |
|
60 | 60 | /*! |
|
61 | 61 | \qmlproperty AbstractBarSeries HBarModelMapper::series |
|
62 | 62 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
63 | 63 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \property QHBarModelMapper::model |
|
68 | 68 | \brief Defines the model that is used by the mapper. |
|
69 | 69 | */ |
|
70 | 70 | /*! |
|
71 | 71 | \qmlproperty SomeModel HBarModelMapper::model |
|
72 | 72 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model |
|
73 | 73 | and expose it to QML. Note: the model has to support adding/removing rows/columns and modifying |
|
74 | 74 | the data of the cells. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QHBarModelMapper::firstBarSetRow |
|
79 | 79 | \brief Defines which column of the model is used as the data source for the first bar set. |
|
80 | 80 | |
|
81 | 81 | Default value is: -1 (invalid mapping) |
|
82 | 82 | */ |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty int HBarModelMapper::firstBarSetRow |
|
85 | 85 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 |
|
86 | 86 | (invalid mapping). |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \property QHBarModelMapper::lastBarSetRow |
|
91 | 91 | \brief Defines which column of the model is used as the data source for the last bar set. |
|
92 | 92 | |
|
93 | 93 | Default value is: -1 (invalid mapping) |
|
94 | 94 | */ |
|
95 | 95 | /*! |
|
96 | 96 | \qmlproperty int HBarModelMapper::lastBarSetRow |
|
97 | 97 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 |
|
98 | 98 | (invalid mapping). |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \property QHBarModelMapper::firstColumn |
|
103 | 103 | \brief Defines which column of the model contains the first values of the QBarSets in the series. |
|
104 | 104 | |
|
105 | 105 | Minimal and default value is: 0 |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty int HBarModelMapper::firstColumn |
|
109 | 109 | Defines which column of the model contains the first values of the QBarSets in the series. |
|
110 | 110 | The default value is 0. |
|
111 | 111 | */ |
|
112 | 112 | |
|
113 | 113 | /*! |
|
114 | 114 | \property QHBarModelMapper::columnCount |
|
115 | 115 | \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. |
|
116 | 116 | |
|
117 | 117 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
118 | 118 | */ |
|
119 | 119 | /*! |
|
120 | 120 | \qmlproperty int HBarModelMapper::columnCount |
|
121 | 121 | Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
122 | 122 | -1 (count limited by the number of columns in the model) |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \fn void QHBarModelMapper::seriesReplaced() |
|
127 | 127 | |
|
128 | 128 | Emitted when the series to which mapper is connected to has changed. |
|
129 | 129 | */ |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | \fn void QHBarModelMapper::modelReplaced() |
|
133 | 133 | |
|
134 | 134 | Emitted when the model to which mapper is connected to has changed. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
|
139 | 139 | |
|
140 | 140 | Emitted when the firstBarSetRow has changed. |
|
141 | 141 | */ |
|
142 | 142 | |
|
143 | 143 | /*! |
|
144 | 144 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
|
145 | 145 | |
|
146 | 146 | Emitted when the lastBarSetRow has changed. |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QHBarModelMapper::firstColumnChanged() |
|
151 | 151 | Emitted when the firstColumn has changed. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | \fn void QHBarModelMapper::columnCountChanged() |
|
156 | 156 | Emitted when the columnCount has changed. |
|
157 | 157 | */ |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | Constructs a mapper object which is a child of \a parent. |
|
161 | 161 | */ |
|
162 | 162 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
163 | 163 | QBarModelMapper(parent) |
|
164 | 164 | { |
|
165 | 165 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | QAbstractItemModel *QHBarModelMapper::model() const |
|
169 | 169 | { |
|
170 | 170 | return QBarModelMapper::model(); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void QHBarModelMapper::setModel(QAbstractItemModel *model) |
|
174 | 174 | { |
|
175 | 175 | if (model != QBarModelMapper::model()) { |
|
176 | 176 | QBarModelMapper::setModel(model); |
|
177 | 177 | emit modelReplaced(); |
|
178 | 178 | } |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | QAbstractBarSeries *QHBarModelMapper::series() const |
|
182 | 182 | { |
|
183 | 183 | return QBarModelMapper::series(); |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
187 | 187 | { |
|
188 | 188 | if (series != QBarModelMapper::series()) { |
|
189 | 189 | QBarModelMapper::setSeries(series); |
|
190 | 190 | emit seriesReplaced(); |
|
191 | 191 | } |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | int QHBarModelMapper::firstBarSetRow() const |
|
195 | 195 | { |
|
196 | 196 | return QBarModelMapper::firstBarSetSection(); |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
200 | 200 | { |
|
201 | 201 | if (firstBarSetRow != firstBarSetSection()) { |
|
202 | 202 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
203 | 203 | emit firstBarSetRowChanged(); |
|
204 | 204 | } |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | int QHBarModelMapper::lastBarSetRow() const |
|
208 | 208 | { |
|
209 | 209 | return QBarModelMapper::lastBarSetSection(); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
213 | 213 | { |
|
214 | 214 | if (lastBarSetRow != lastBarSetSection()) { |
|
215 | 215 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
216 | 216 | emit lastBarSetRowChanged(); |
|
217 | 217 | } |
|
218 | 218 | } |
|
219 | 219 | |
|
220 | 220 | int QHBarModelMapper::firstColumn() const |
|
221 | 221 | { |
|
222 | 222 | return QBarModelMapper::first(); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | void QHBarModelMapper::setFirstColumn(int firstColumn) |
|
226 | 226 | { |
|
227 | 227 | if (firstColumn != first()) { |
|
228 | 228 | QBarModelMapper::setFirst(firstColumn); |
|
229 | 229 | emit firstColumnChanged(); |
|
230 | 230 | } |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | int QHBarModelMapper::columnCount() const |
|
234 | 234 | { |
|
235 | 235 | return QBarModelMapper::count(); |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | void QHBarModelMapper::setColumnCount(int columnCount) |
|
239 | 239 | { |
|
240 | 240 | if (columnCount != count()) { |
|
241 | 241 | QBarModelMapper::setCount(columnCount); |
|
242 | 242 | emit columnCountChanged(); |
|
243 | 243 | } |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | #include "moc_qhbarmodelmapper.cpp" |
|
247 | 247 | |
|
248 | 248 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,246 +1,246 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qvbarmodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QVBarModelMapper |
|
27 | 27 | \inmodule Qt Charts |
|
28 | 28 | \brief Vertical model mapper for bar series. |
|
29 | 29 | \mainclass |
|
30 | 30 | |
|
31 | 31 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
32 | 32 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. |
|
33 | 33 | Model mapper maintains equal size of all the BarSets. |
|
34 | 34 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
35 | 35 | \note Used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
36 | 36 | */ |
|
37 | 37 | #ifdef QDOC_QT5 |
|
38 | 38 | /*! |
|
39 | 39 | \qmltype VBarModelMapper |
|
40 | 40 | \instantiates QVBarModelMapper |
|
41 | 41 | \inqmlmodule QtCommercial.Chart |
|
42 | 42 | |
|
43 |
\include |
|
|
43 | \include doc/src/vbarmodelmapper.qdocinc | |
|
44 | 44 | */ |
|
45 | 45 | #else |
|
46 | 46 | /*! |
|
47 | 47 | \qmlclass VBarModelMapper QVBarModelMapper |
|
48 | 48 | |
|
49 | 49 | \include ../doc/src/vbarmodelmapper.qdocinc |
|
50 | 50 | */ |
|
51 | 51 | #endif |
|
52 | 52 | |
|
53 | 53 | /*! |
|
54 | 54 | \property QVBarModelMapper::series |
|
55 | 55 | \brief Defines the QBarSeries object that is used by the mapper. |
|
56 | 56 | |
|
57 | 57 | All the data in the series is discarded when it is set to the mapper. |
|
58 | 58 | When new series is specified the old series is disconnected (it preserves its data) |
|
59 | 59 | */ |
|
60 | 60 | /*! |
|
61 | 61 | \qmlproperty AbstractBarSeries VBarModelMapper::series |
|
62 | 62 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
63 | 63 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \property QVBarModelMapper::model |
|
68 | 68 | \brief Defines the model that is used by the mapper. |
|
69 | 69 | */ |
|
70 | 70 | /*! |
|
71 | 71 | \qmlproperty SomeModel VBarModelMapper::model |
|
72 | 72 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model |
|
73 | 73 | and expose it to QML. Note: the model has to support adding/removing rows/columns and modifying |
|
74 | 74 | the data of the cells. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QVBarModelMapper::firstBarSetColumn |
|
79 | 79 | \brief Defines which column of the model is used as the data source for the first bar set. |
|
80 | 80 | |
|
81 | 81 | Default value is: -1 (invalid mapping) |
|
82 | 82 | */ |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
85 | 85 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
86 | 86 | is: -1 (invalid mapping). |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \property QVBarModelMapper::lastBarSetColumn |
|
91 | 91 | \brief Defines which column of the model is used as the data source for the last bar set. |
|
92 | 92 | |
|
93 | 93 | Default value is: -1 (invalid mapping) |
|
94 | 94 | */ |
|
95 | 95 | /*! |
|
96 | 96 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
97 | 97 | Defines which column of the model is used as the data source for the last bar set. Default |
|
98 | 98 | value is: -1 (invalid mapping). |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \property QVBarModelMapper::firstRow |
|
103 | 103 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
104 | 104 | |
|
105 | 105 | Minimal and default value is: 0 |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty int VBarModelMapper::firstRow |
|
109 | 109 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
110 | 110 | The default value is 0. |
|
111 | 111 | */ |
|
112 | 112 | |
|
113 | 113 | /*! |
|
114 | 114 | \property QVBarModelMapper::rowCount |
|
115 | 115 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. |
|
116 | 116 | |
|
117 | 117 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
118 | 118 | */ |
|
119 | 119 | /*! |
|
120 | 120 | \qmlproperty int VBarModelMapper::rowCount |
|
121 | 121 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
122 | 122 | -1 (count limited by the number of rows in the model) |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \fn void QVBarModelMapper::seriesReplaced() |
|
127 | 127 | |
|
128 | 128 | Emitted when the series to which mapper is connected to has changed. |
|
129 | 129 | */ |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | \fn void QVBarModelMapper::modelReplaced() |
|
133 | 133 | |
|
134 | 134 | Emitted when the model to which mapper is connected to has changed. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
139 | 139 | Emitted when the firstBarSetColumn has changed. |
|
140 | 140 | */ |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
144 | 144 | Emitted when the lastBarSetColumn has changed. |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \fn void QVBarModelMapper::firstRowChanged() |
|
149 | 149 | Emitted when the firstRow has changed. |
|
150 | 150 | */ |
|
151 | 151 | |
|
152 | 152 | /*! |
|
153 | 153 | \fn void QVBarModelMapper::rowCountChanged() |
|
154 | 154 | Emitted when the rowCount has changed. |
|
155 | 155 | */ |
|
156 | 156 | |
|
157 | 157 | /*! |
|
158 | 158 | Constructs a mapper object which is a child of \a parent. |
|
159 | 159 | */ |
|
160 | 160 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
161 | 161 | QBarModelMapper(parent) |
|
162 | 162 | { |
|
163 | 163 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | QAbstractItemModel *QVBarModelMapper::model() const |
|
167 | 167 | { |
|
168 | 168 | return QBarModelMapper::model(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | void QVBarModelMapper::setModel(QAbstractItemModel *model) |
|
172 | 172 | { |
|
173 | 173 | if (model != QBarModelMapper::model()) { |
|
174 | 174 | QBarModelMapper::setModel(model); |
|
175 | 175 | emit modelReplaced(); |
|
176 | 176 | } |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | QAbstractBarSeries *QVBarModelMapper::series() const |
|
180 | 180 | { |
|
181 | 181 | return QBarModelMapper::series(); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
185 | 185 | { |
|
186 | 186 | if (series != QBarModelMapper::series()) { |
|
187 | 187 | QBarModelMapper::setSeries(series); |
|
188 | 188 | emit seriesReplaced(); |
|
189 | 189 | } |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | int QVBarModelMapper::firstBarSetColumn() const |
|
193 | 193 | { |
|
194 | 194 | return QBarModelMapper::firstBarSetSection(); |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
198 | 198 | { |
|
199 | 199 | if (firstBarSetColumn != firstBarSetSection()) { |
|
200 | 200 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
201 | 201 | emit firstBarSetColumnChanged(); |
|
202 | 202 | } |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | int QVBarModelMapper::lastBarSetColumn() const |
|
206 | 206 | { |
|
207 | 207 | return QBarModelMapper::lastBarSetSection(); |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
211 | 211 | { |
|
212 | 212 | if (lastBarSetColumn != lastBarSetSection()) { |
|
213 | 213 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
214 | 214 | emit lastBarSetColumnChanged(); |
|
215 | 215 | } |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | int QVBarModelMapper::firstRow() const |
|
219 | 219 | { |
|
220 | 220 | return QBarModelMapper::first(); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
224 | 224 | { |
|
225 | 225 | if (firstRow != first()) { |
|
226 | 226 | QBarModelMapper::setFirst(firstRow); |
|
227 | 227 | emit firstRowChanged(); |
|
228 | 228 | } |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | int QVBarModelMapper::rowCount() const |
|
232 | 232 | { |
|
233 | 233 | return QBarModelMapper::count(); |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | void QVBarModelMapper::setRowCount(int rowCount) |
|
237 | 237 | { |
|
238 | 238 | if (rowCount != count()) { |
|
239 | 239 | QBarModelMapper::setCount(rowCount); |
|
240 | 240 | emit rowCountChanged(); |
|
241 | 241 | } |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | #include "moc_qvbarmodelmapper.cpp" |
|
245 | 245 | |
|
246 | 246 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,124 +1,124 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qbarseries.h" |
|
22 | 22 | #include "qbarseries_p.h" |
|
23 | 23 | #include "barchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "qvalueaxis.h" |
|
27 | 27 | #include "qbarcategoryaxis.h" |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | /*! |
|
32 | 32 | \class QBarSeries |
|
33 | 33 | \inmodule Qt Charts |
|
34 | 34 | \brief Series for creating bar chart. |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | 38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data |
|
39 | 39 | from sets to categories, which are defined by a QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. |
|
42 | 42 | \image examples_barchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
45 | 45 | */ |
|
46 | 46 | #ifdef QDOC_QT5 |
|
47 | 47 | /*! |
|
48 | 48 | \qmltype BarSeries |
|
49 | 49 | \instantiates QBarSeries |
|
50 | 50 | \inqmlmodule QtCommercial.Chart |
|
51 | 51 | |
|
52 |
\include |
|
|
52 | \include doc/src/barseries.qdocinc | |
|
53 | 53 | */ |
|
54 | 54 | #else |
|
55 | 55 | /*! |
|
56 | 56 | \qmlclass BarSeries QBarSeries |
|
57 | 57 | |
|
58 | 58 | \include ../doc/src/barseries.qdocinc |
|
59 | 59 | */ |
|
60 | 60 | #endif |
|
61 | 61 | |
|
62 | 62 | /*! |
|
63 | 63 | Constructs empty QBarSeries. |
|
64 | 64 | QBarSeries is QObject which is a child of a \a parent. |
|
65 | 65 | */ |
|
66 | 66 | QBarSeries::QBarSeries(QObject *parent) |
|
67 | 67 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) |
|
68 | 68 | { |
|
69 | 69 | |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | Returns QAbstractSeries::SeriesTypeBar. |
|
74 | 74 | */ |
|
75 | 75 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
76 | 76 | { |
|
77 | 77 | return QAbstractSeries::SeriesTypeBar; |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | Destructor. Removes series from chart. |
|
82 | 82 | */ |
|
83 | 83 | QBarSeries::~QBarSeries() |
|
84 | 84 | { |
|
85 | 85 | Q_D(QBarSeries); |
|
86 | 86 | if (d->m_chart) |
|
87 | 87 | d->m_chart->removeSeries(this); |
|
88 | 88 | } |
|
89 | 89 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 | 90 | |
|
91 | 91 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
92 | 92 | { |
|
93 | 93 | |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | void QBarSeriesPrivate::initializeDomain() |
|
97 | 97 | { |
|
98 | 98 | qreal minX(domain()->minX()); |
|
99 | 99 | qreal minY(domain()->minY()); |
|
100 | 100 | qreal maxX(domain()->maxX()); |
|
101 | 101 | qreal maxY(domain()->maxY()); |
|
102 | 102 | |
|
103 | 103 | qreal x = categoryCount(); |
|
104 | 104 | minX = qMin(minX, - (qreal)0.5); |
|
105 | 105 | minY = qMin(minY, min()); |
|
106 | 106 | maxX = qMax(maxX, x - (qreal)0.5); |
|
107 | 107 | maxY = qMax(maxY, max()); |
|
108 | 108 | |
|
109 | 109 | domain()->setRange(minX, maxX, minY, maxY); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | |
|
113 | 113 | void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
114 | 114 | { |
|
115 | 115 | Q_Q(QBarSeries); |
|
116 | 116 | BarChartItem *bar = new BarChartItem(q,parent); |
|
117 | 117 | m_item.reset(bar); |
|
118 | 118 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | #include "moc_qbarseries.cpp" |
|
122 | 122 | |
|
123 | 123 | QTCOMMERCIALCHART_END_NAMESPACE |
|
124 | 124 |
@@ -1,123 +1,123 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qpercentbarseries.h" |
|
22 | 22 | #include "qpercentbarseries_p.h" |
|
23 | 23 | #include "percentbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "qvalueaxis.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \class QPercentBarSeries |
|
32 | 32 | \inmodule Qt Charts |
|
33 | 33 | \brief Series for creating percent bar chart. |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 | 36 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | 37 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
38 | 38 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
39 | 39 | |
|
40 | 40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
41 | 41 | \image examples_percentbarchart.png |
|
42 | 42 | |
|
43 | 43 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries |
|
44 | 44 | */ |
|
45 | 45 | #ifdef QDOC_QT5 |
|
46 | 46 | /*! |
|
47 | 47 | \qmltype PercentBarSeries |
|
48 | 48 | \instantiates QPercentBarSeries |
|
49 | 49 | \inqmlmodule QtCommercial.Chart |
|
50 | 50 | |
|
51 |
\include |
|
|
51 | \include doc/src/persentbarseries.qdocinc | |
|
52 | 52 | */ |
|
53 | 53 | #else |
|
54 | 54 | /*! |
|
55 | 55 | \qmlclass PercentBarSeries QPercentBarSeries |
|
56 | 56 | |
|
57 | 57 | \include ../doc/src/persentbarseries.qdocinc |
|
58 | 58 | */ |
|
59 | 59 | #endif |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | Constructs empty QPercentBarSeries. |
|
63 | 63 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
64 | 64 | */ |
|
65 | 65 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
66 | 66 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
67 | 67 | { |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | /*! |
|
71 | 71 | Destructor. Removes series from chart. |
|
72 | 72 | */ |
|
73 | 73 | QPercentBarSeries::~QPercentBarSeries() |
|
74 | 74 | { |
|
75 | 75 | Q_D(QPercentBarSeries); |
|
76 | 76 | if (d->m_chart) |
|
77 | 77 | d->m_chart->removeSeries(this); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | Returns QAbstractSeries::SeriesTypePercentBar. |
|
82 | 82 | */ |
|
83 | 83 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
84 | 84 | { |
|
85 | 85 | return QAbstractSeries::SeriesTypePercentBar; |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 | 89 | |
|
90 | 90 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
91 | 91 | { |
|
92 | 92 | |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | void QPercentBarSeriesPrivate::initializeDomain() |
|
96 | 96 | { |
|
97 | 97 | qreal minX(domain()->minX()); |
|
98 | 98 | qreal minY(domain()->minY()); |
|
99 | 99 | qreal maxX(domain()->maxX()); |
|
100 | 100 | qreal maxY(domain()->maxY()); |
|
101 | 101 | |
|
102 | 102 | qreal x = categoryCount(); |
|
103 | 103 | minX = qMin(minX, - (qreal)0.5); |
|
104 | 104 | maxX = qMax(maxX, x - (qreal)0.5); |
|
105 | 105 | minY = 0; |
|
106 | 106 | maxY = 100; |
|
107 | 107 | |
|
108 | 108 | domain()->setRange(minX, maxX, minY, maxY); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | |
|
112 | 112 | void QPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
113 | 113 | { |
|
114 | 114 | Q_Q(QPercentBarSeries); |
|
115 | 115 | PercentBarChartItem *bar = new PercentBarChartItem(q,parent); |
|
116 | 116 | m_item.reset(bar); |
|
117 | 117 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | #include "moc_qpercentbarseries.cpp" |
|
121 | 121 | |
|
122 | 122 | QTCOMMERCIALCHART_END_NAMESPACE |
|
123 | 123 |
@@ -1,122 +1,122 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qstackedbarseries.h" |
|
22 | 22 | #include "qstackedbarseries_p.h" |
|
23 | 23 | #include "stackedbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "qvalueaxis.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \class QStackedBarSeries |
|
32 | 32 | \inmodule Qt Charts |
|
33 | 33 | \brief Series for creating stacked bar chart. |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 | 36 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | 37 | as stacks, where bars in same category are stacked on top of each other. |
|
38 | 38 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
39 | 39 | |
|
40 | 40 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
41 | 41 | \image examples_stackedbarchart.png |
|
42 | 42 | |
|
43 | 43 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries |
|
44 | 44 | */ |
|
45 | 45 | |
|
46 | 46 | #ifdef QDOC_QT5 |
|
47 | 47 | /*! |
|
48 | 48 | \qmltype StackedBarSeries |
|
49 | 49 | \instantiates QStackedBarSeries |
|
50 | 50 | \inqmlmodule QtCommercial.Chart |
|
51 | 51 | |
|
52 |
\include |
|
|
52 | \include doc/src/stackedbarseries.qdocinc | |
|
53 | 53 | */ |
|
54 | 54 | #else |
|
55 | 55 | /*! |
|
56 | 56 | \qmlclass StackedBarSeries QStackedBarSeries |
|
57 | 57 | |
|
58 | 58 | \include ../doc/src/stackedbarseries.qdocinc |
|
59 | 59 | */ |
|
60 | 60 | #endif |
|
61 | 61 | |
|
62 | 62 | /*! |
|
63 | 63 | Constructs empty QStackedBarSeries. |
|
64 | 64 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
65 | 65 | */ |
|
66 | 66 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
67 | 67 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
68 | 68 | { |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | Destructor. Removes series from chart. |
|
73 | 73 | */ |
|
74 | 74 | QStackedBarSeries::~QStackedBarSeries() |
|
75 | 75 | { |
|
76 | 76 | Q_D(QStackedBarSeries); |
|
77 | 77 | if (d->m_chart) |
|
78 | 78 | d->m_chart->removeSeries(this); |
|
79 | 79 | } |
|
80 | 80 | /*! |
|
81 | 81 | Returns QAbstractSeries::SeriesTypeStackedBar. |
|
82 | 82 | */ |
|
83 | 83 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
84 | 84 | { |
|
85 | 85 | return QAbstractSeries::SeriesTypeStackedBar; |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 | 89 | |
|
90 | 90 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
91 | 91 | { |
|
92 | 92 | |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | void QStackedBarSeriesPrivate::initializeDomain() |
|
96 | 96 | { |
|
97 | 97 | qreal minX(domain()->minX()); |
|
98 | 98 | qreal minY(domain()->minY()); |
|
99 | 99 | qreal maxX(domain()->maxX()); |
|
100 | 100 | qreal maxY(domain()->maxY()); |
|
101 | 101 | |
|
102 | 102 | qreal x = categoryCount(); |
|
103 | 103 | minX = qMin(minX, - (qreal)0.5); |
|
104 | 104 | minY = qMin(minY, bottom()); |
|
105 | 105 | maxX = qMax(maxX, x - (qreal)0.5); |
|
106 | 106 | maxY = qMax(maxY, top()); |
|
107 | 107 | |
|
108 | 108 | domain()->setRange(minX, maxX, minY, maxY); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
112 | 112 | { |
|
113 | 113 | Q_Q(QStackedBarSeries); |
|
114 | 114 | StackedBarChartItem *bar = new StackedBarChartItem(q,parent); |
|
115 | 115 | m_item.reset(bar); |
|
116 | 116 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | #include "moc_qstackedbarseries.cpp" |
|
120 | 120 | |
|
121 | 121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
122 | 122 |
@@ -1,246 +1,246 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qvboxplotmodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QVBoxPlotModelMapper |
|
27 | 27 | \inmodule Qt Charts |
|
28 | 28 | \brief Vertical model mapper for bar series |
|
29 | 29 | \mainclass |
|
30 | 30 | |
|
31 | 31 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
32 | 32 | Vertical model mapper is used to create a connection between QBoxPlotSeries and QAbstractItemModel derived model object. |
|
33 | 33 | Model mapper maintains equal size of all the QBoxSets. |
|
34 | 34 | \note used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
35 | 35 | */ |
|
36 | 36 | #ifdef QDOC_QT5 |
|
37 | 37 | /*! |
|
38 | 38 | \qmltype VBoxPlotModelMapper |
|
39 | 39 | \instantiates QVBoxPlotModelMapper |
|
40 | 40 | \inqmlmodule QtCommercial.Chart |
|
41 | 41 | |
|
42 |
\include |
|
|
42 | \include doc/src/vboxplotmodelmapper.qdocinc | |
|
43 | 43 | */ |
|
44 | 44 | #else |
|
45 | 45 | /*! |
|
46 | 46 | \qmlclass VBoxPlotModelMapper QVBoxPlotModelMapper |
|
47 | 47 | |
|
48 | 48 | \include ../doc/src/vboxplotmodelmapper.qdocinc |
|
49 | 49 | */ |
|
50 | 50 | #endif |
|
51 | 51 | |
|
52 | 52 | /*! |
|
53 | 53 | \property QVBoxPlotModelMapper::series |
|
54 | 54 | \brief Defines the QBoxPlotSeries object that is used by the mapper. |
|
55 | 55 | |
|
56 | 56 | All the data in the series is discarded when it is set to the mapper. |
|
57 | 57 | When new series is specified the old series is disconnected (it preserves its data) |
|
58 | 58 | */ |
|
59 | 59 | /*! |
|
60 | 60 | \qmlproperty AbstractBarSeries VBoxPlotModelMapper::series |
|
61 | 61 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
62 | 62 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
63 | 63 | */ |
|
64 | 64 | |
|
65 | 65 | /*! |
|
66 | 66 | \property QVBoxPlotModelMapper::model |
|
67 | 67 | \brief Defines the model that is used by the mapper. |
|
68 | 68 | */ |
|
69 | 69 | /*! |
|
70 | 70 | \qmlproperty SomeModel VBoxPlotModelMapper::model |
|
71 | 71 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model |
|
72 | 72 | and expose it to QML. \note the model has to support adding/removing rows/columns and modifying |
|
73 | 73 | the data of the cells. |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \property QVBoxPlotModelMapper::firstBoxSetColumn |
|
78 | 78 | \brief Defines which column of the model is used as the data source for the first box-and-whiskers set. |
|
79 | 79 | |
|
80 | 80 | Default value is: -1 (invalid mapping) |
|
81 | 81 | */ |
|
82 | 82 | /*! |
|
83 | 83 | \qmlproperty int VBarModelMapper::firstBoxSetColumn |
|
84 | 84 | Defines which column of the model is used as the data source for the first box-and-whiskers set. Default value |
|
85 | 85 | is: -1 (invalid mapping). |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QVBoxPlotModelMapper::lastBoxSetColumn |
|
90 | 90 | \brief Defines which column of the model is used as the data source for the last box-and-whiskers set. |
|
91 | 91 | |
|
92 | 92 | Default value is: -1 (invalid mapping) |
|
93 | 93 | */ |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty int VBarModelMapper::lastBoxSetColumn |
|
96 | 96 | Defines which column of the model is used as the data source for the last box-and-whiskers set. Default |
|
97 | 97 | value is: -1 (invalid mapping). |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \property QVBoxPlotModelMapper::firstRow |
|
102 | 102 | \brief Defines which row of the model contains the first values of the QBoxSets in the series. |
|
103 | 103 | |
|
104 | 104 | Minimal and default value is: 0 |
|
105 | 105 | */ |
|
106 | 106 | /*! |
|
107 | 107 | \qmlproperty int VBoxPlotModelMapper::firstRow |
|
108 | 108 | Defines which row of the model contains the first values of the QBoxSets in the series. |
|
109 | 109 | The default value is 0. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \property QVBoxPlotModelMapper::rowCount |
|
114 | 114 | \brief Defines the number of rows of the model that are mapped as the data for QBoxPlotSeries |
|
115 | 115 | |
|
116 | 116 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
117 | 117 | */ |
|
118 | 118 | /*! |
|
119 | 119 | \qmlproperty int VBoxModelMapper::rowCount |
|
120 | 120 | Defines the number of rows of the model that are mapped as the data for QBoxPlotSeries. The default value is |
|
121 | 121 | -1 (count limited by the number of rows in the model) |
|
122 | 122 | */ |
|
123 | 123 | |
|
124 | 124 | /*! |
|
125 | 125 | \fn void QVBoxPlotModelMapper::seriesReplaced() |
|
126 | 126 | |
|
127 | 127 | Emitted when the series to which mapper is connected to has changed. |
|
128 | 128 | */ |
|
129 | 129 | |
|
130 | 130 | /*! |
|
131 | 131 | \fn void QVBoxPlotModelMapper::modelReplaced() |
|
132 | 132 | |
|
133 | 133 | Emitted when the model to which mapper is connected to has changed. |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | \fn void QVBoxPlotModelMapper::firstBoxSetColumnChanged() |
|
138 | 138 | Emitted when the firstBoxSetColumn has changed. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QVBoxPlotModelMapper::lastBoxSetColumnChanged() |
|
143 | 143 | Emitted when the lastBoxSetColumn has changed. |
|
144 | 144 | */ |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | \fn void QVBoxPlotModelMapper::firstRowChanged() |
|
148 | 148 | Emitted when the firstRow has changed. |
|
149 | 149 | */ |
|
150 | 150 | |
|
151 | 151 | /*! |
|
152 | 152 | \fn void QVBoxPlotModelMapper::rowCountChanged() |
|
153 | 153 | Emitted when the rowCount has changed. |
|
154 | 154 | */ |
|
155 | 155 | |
|
156 | 156 | /*! |
|
157 | 157 | Constructs a mapper object which is a child of \a parent. |
|
158 | 158 | */ |
|
159 | 159 | QVBoxPlotModelMapper::QVBoxPlotModelMapper(QObject *parent) : |
|
160 | 160 | QBoxPlotModelMapper(parent) |
|
161 | 161 | { |
|
162 | 162 | QBoxPlotModelMapper::setOrientation(Qt::Vertical); |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | QAbstractItemModel *QVBoxPlotModelMapper::model() const |
|
166 | 166 | { |
|
167 | 167 | return QBoxPlotModelMapper::model(); |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | void QVBoxPlotModelMapper::setModel(QAbstractItemModel *model) |
|
171 | 171 | { |
|
172 | 172 | if (model != QBoxPlotModelMapper::model()) { |
|
173 | 173 | QBoxPlotModelMapper::setModel(model); |
|
174 | 174 | emit modelReplaced(); |
|
175 | 175 | } |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | QBoxPlotSeries *QVBoxPlotModelMapper::series() const |
|
179 | 179 | { |
|
180 | 180 | return QBoxPlotModelMapper::series(); |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | void QVBoxPlotModelMapper::setSeries(QBoxPlotSeries *series) |
|
184 | 184 | { |
|
185 | 185 | if (series != QBoxPlotModelMapper::series()) { |
|
186 | 186 | QBoxPlotModelMapper::setSeries(series); |
|
187 | 187 | emit seriesReplaced(); |
|
188 | 188 | } |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | int QVBoxPlotModelMapper::firstBoxSetColumn() const |
|
192 | 192 | { |
|
193 | 193 | return QBoxPlotModelMapper::firstBoxSetSection(); |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | void QVBoxPlotModelMapper::setFirstBoxSetColumn(int firstBoxSetColumn) |
|
197 | 197 | { |
|
198 | 198 | if (firstBoxSetColumn != firstBoxSetSection()) { |
|
199 | 199 | QBoxPlotModelMapper::setFirstBoxSetSection(firstBoxSetColumn); |
|
200 | 200 | emit firstBoxSetColumnChanged(); |
|
201 | 201 | } |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | int QVBoxPlotModelMapper::lastBoxSetColumn() const |
|
205 | 205 | { |
|
206 | 206 | return QBoxPlotModelMapper::lastBoxSetSection(); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | void QVBoxPlotModelMapper::setLastBoxSetColumn(int lastBoxSetColumn) |
|
210 | 210 | { |
|
211 | 211 | if (lastBoxSetColumn != lastBoxSetSection()) { |
|
212 | 212 | QBoxPlotModelMapper::setLastBoxSetSection(lastBoxSetColumn); |
|
213 | 213 | emit lastBoxSetColumnChanged(); |
|
214 | 214 | } |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | int QVBoxPlotModelMapper::firstRow() const |
|
218 | 218 | { |
|
219 | 219 | return QBoxPlotModelMapper::first(); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | void QVBoxPlotModelMapper::setFirstRow(int firstRow) |
|
223 | 223 | { |
|
224 | 224 | if (firstRow != first()) { |
|
225 | 225 | QBoxPlotModelMapper::setFirst(firstRow); |
|
226 | 226 | emit firstRowChanged(); |
|
227 | 227 | } |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | int QVBoxPlotModelMapper::rowCount() const |
|
231 | 231 | { |
|
232 | 232 | return QBoxPlotModelMapper::count(); |
|
233 | 233 | } |
|
234 | 234 | |
|
235 | 235 | void QVBoxPlotModelMapper::setRowCount(int rowCount) |
|
236 | 236 | { |
|
237 | 237 | if (rowCount != count()) { |
|
238 | 238 | QBoxPlotModelMapper::setCount(rowCount); |
|
239 | 239 | emit rowCountChanged(); |
|
240 | 240 | } |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | #include "moc_qvboxplotmodelmapper.cpp" |
|
244 | 244 | |
|
245 | 245 | QTCOMMERCIALCHART_END_NAMESPACE |
|
246 | 246 |
@@ -1,592 +1,592 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qlegend.h" |
|
22 | 22 | #include "qlegend_p.h" |
|
23 | 23 | #include "qabstractseries.h" |
|
24 | 24 | #include "qabstractseries_p.h" |
|
25 | 25 | #include "qchart_p.h" |
|
26 | 26 | #include "legendlayout_p.h" |
|
27 | 27 | #include "chartpresenter_p.h" |
|
28 | 28 | #include "abstractchartlayout_p.h" |
|
29 | 29 | #include "qlegendmarker.h" |
|
30 | 30 | #include "qlegendmarker_p.h" |
|
31 | 31 | #include "legendmarkeritem_p.h" |
|
32 | 32 | #include "chartdataset_p.h" |
|
33 | 33 | #include <QPainter> |
|
34 | 34 | #include <QPen> |
|
35 | 35 | #include <QGraphicsItemGroup> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | /*! |
|
40 | 40 | \class QLegend |
|
41 | 41 | \inmodule Qt Charts |
|
42 | 42 | \brief Legend object. |
|
43 | 43 | \mainclass |
|
44 | 44 | |
|
45 | 45 | QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when |
|
46 | 46 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
47 | 47 | handle the drawing manually. |
|
48 | 48 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
49 | 49 | |
|
50 | 50 | \image examples_percentbarchart_legend.png |
|
51 | 51 | |
|
52 | 52 | \sa QChart |
|
53 | 53 | */ |
|
54 | 54 | #ifdef QDOC_QT5 |
|
55 | 55 | /*! |
|
56 | 56 | \qmltype Legend |
|
57 | 57 | \instantiates QLegend |
|
58 | 58 | \inqmlmodule QtCommercial.Chart |
|
59 | 59 | |
|
60 |
\include |
|
|
60 | \include doc/src/legend.qdocinc | |
|
61 | 61 | */ |
|
62 | 62 | #else |
|
63 | 63 | /*! |
|
64 | 64 | \qmlclass Legend QLegend |
|
65 | 65 | |
|
66 | 66 | \include ../doc/src/legend.qdocinc |
|
67 | 67 | */ |
|
68 | 68 | #endif |
|
69 | 69 | |
|
70 | 70 | /*! |
|
71 | 71 | \property QLegend::alignment |
|
72 | 72 | \brief The alignment of the legend. |
|
73 | 73 | |
|
74 | 74 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
75 | 75 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
76 | 76 | */ |
|
77 | 77 | /*! |
|
78 | 78 | \qmlproperty Qt.Alignment Legend::alignment |
|
79 | 79 | \brief The alignment of the legend. |
|
80 | 80 | |
|
81 | 81 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
82 | 82 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QLegend::backgroundVisible |
|
87 | 87 | Whether the legend background is visible or not. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty bool Legend::backgroundVisible |
|
91 | 91 | Whether the legend background is visible or not. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QLegend::color |
|
96 | 96 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
97 | 97 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
98 | 98 | */ |
|
99 | 99 | /*! |
|
100 | 100 | \qmlproperty color Legend::color |
|
101 | 101 | The color of the legend, i.e. the background (brush) color. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \property QLegend::borderColor |
|
106 | 106 | The border color of the legend, i.e. the line color. |
|
107 | 107 | */ |
|
108 | 108 | /*! |
|
109 | 109 | \qmlproperty color Legend::borderColor |
|
110 | 110 | The border color of the legend, i.e. the line color. |
|
111 | 111 | */ |
|
112 | 112 | |
|
113 | 113 | /*! |
|
114 | 114 | \property QLegend::font |
|
115 | 115 | The font of markers used by legend |
|
116 | 116 | */ |
|
117 | 117 | /*! |
|
118 | 118 | \qmlproperty Font Legend::font |
|
119 | 119 | The font of markers used by legend |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \property QLegend::labelColor |
|
124 | 124 | The color of brush used to draw labels. |
|
125 | 125 | */ |
|
126 | 126 | /*! |
|
127 | 127 | \qmlproperty color QLegend::labelColor |
|
128 | 128 | The color of brush used to draw labels. |
|
129 | 129 | */ |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
133 | 133 | The visibility of the legend background changed to \a visible. |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | \fn void QLegend::colorChanged(QColor) |
|
138 | 138 | The color of the legend background changed to \a color. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QLegend::borderColorChanged(QColor) |
|
143 | 143 | The border color of the legend background changed to \a color. |
|
144 | 144 | */ |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | \fn void QLegend::fontChanged(QFont) |
|
148 | 148 | The font of markers of the legend changed to \a font. |
|
149 | 149 | */ |
|
150 | 150 | |
|
151 | 151 | /*! |
|
152 | 152 | \fn void QLegend::labelColorChanged(QColor color) |
|
153 | 153 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
154 | 154 | */ |
|
155 | 155 | |
|
156 | 156 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
157 | 157 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
158 | 158 | { |
|
159 | 159 | setZValue(ChartPresenter::LegendZValue); |
|
160 | 160 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
161 | 161 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
162 | 162 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
163 | 163 | setLayout(d_ptr->m_layout); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | /*! |
|
167 | 167 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
168 | 168 | */ |
|
169 | 169 | QLegend::~QLegend() |
|
170 | 170 | { |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | \internal |
|
175 | 175 | */ |
|
176 | 176 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
177 | 177 | { |
|
178 | 178 | Q_UNUSED(option) |
|
179 | 179 | Q_UNUSED(widget) |
|
180 | 180 | |
|
181 | 181 | if (!d_ptr->m_backgroundVisible) |
|
182 | 182 | return; |
|
183 | 183 | |
|
184 | 184 | painter->setOpacity(opacity()); |
|
185 | 185 | painter->setPen(d_ptr->m_pen); |
|
186 | 186 | painter->setBrush(d_ptr->m_brush); |
|
187 | 187 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Sets the \a brush of legend. Brush affects the background of legend. |
|
193 | 193 | */ |
|
194 | 194 | void QLegend::setBrush(const QBrush &brush) |
|
195 | 195 | { |
|
196 | 196 | if (d_ptr->m_brush != brush) { |
|
197 | 197 | d_ptr->m_brush = brush; |
|
198 | 198 | update(); |
|
199 | 199 | emit colorChanged(brush.color()); |
|
200 | 200 | } |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | Returns the brush used by legend. |
|
205 | 205 | */ |
|
206 | 206 | QBrush QLegend::brush() const |
|
207 | 207 | { |
|
208 | 208 | return d_ptr->m_brush; |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | void QLegend::setColor(QColor color) |
|
212 | 212 | { |
|
213 | 213 | QBrush b = d_ptr->m_brush; |
|
214 | 214 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
215 | 215 | b.setStyle(Qt::SolidPattern); |
|
216 | 216 | b.setColor(color); |
|
217 | 217 | setBrush(b); |
|
218 | 218 | } |
|
219 | 219 | } |
|
220 | 220 | |
|
221 | 221 | QColor QLegend::color() |
|
222 | 222 | { |
|
223 | 223 | return d_ptr->m_brush.color(); |
|
224 | 224 | } |
|
225 | 225 | |
|
226 | 226 | /*! |
|
227 | 227 | Sets the \a pen of legend. Pen affects the legend borders. |
|
228 | 228 | */ |
|
229 | 229 | void QLegend::setPen(const QPen &pen) |
|
230 | 230 | { |
|
231 | 231 | if (d_ptr->m_pen != pen) { |
|
232 | 232 | d_ptr->m_pen = pen; |
|
233 | 233 | update(); |
|
234 | 234 | emit borderColorChanged(pen.color()); |
|
235 | 235 | } |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | /*! |
|
239 | 239 | Returns the pen used by legend |
|
240 | 240 | */ |
|
241 | 241 | |
|
242 | 242 | QPen QLegend::pen() const |
|
243 | 243 | { |
|
244 | 244 | return d_ptr->m_pen; |
|
245 | 245 | } |
|
246 | 246 | |
|
247 | 247 | void QLegend::setFont(const QFont &font) |
|
248 | 248 | { |
|
249 | 249 | if (d_ptr->m_font != font) { |
|
250 | 250 | d_ptr->m_font = font; |
|
251 | 251 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
252 | 252 | marker->setFont(d_ptr->m_font); |
|
253 | 253 | } |
|
254 | 254 | layout()->invalidate(); |
|
255 | 255 | emit fontChanged(font); |
|
256 | 256 | } |
|
257 | 257 | } |
|
258 | 258 | |
|
259 | 259 | QFont QLegend::font() const |
|
260 | 260 | { |
|
261 | 261 | return d_ptr->m_font; |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | void QLegend::setBorderColor(QColor color) |
|
265 | 265 | { |
|
266 | 266 | QPen p = d_ptr->m_pen; |
|
267 | 267 | if (p.color() != color) { |
|
268 | 268 | p.setColor(color); |
|
269 | 269 | setPen(p); |
|
270 | 270 | } |
|
271 | 271 | } |
|
272 | 272 | |
|
273 | 273 | QColor QLegend::borderColor() |
|
274 | 274 | { |
|
275 | 275 | return d_ptr->m_pen.color(); |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Set brush used to draw labels to \a brush. |
|
280 | 280 | */ |
|
281 | 281 | void QLegend::setLabelBrush(const QBrush &brush) |
|
282 | 282 | { |
|
283 | 283 | if (d_ptr->m_labelBrush != brush) { |
|
284 | 284 | d_ptr->m_labelBrush = brush; |
|
285 | 285 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
286 | 286 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
287 | 287 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
288 | 288 | // instead of mapping it from label brush color |
|
289 | 289 | marker->setPen(brush.color()); |
|
290 | 290 | } |
|
291 | 291 | emit labelColorChanged(brush.color()); |
|
292 | 292 | } |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | /*! |
|
296 | 296 | Brush used to draw labels. |
|
297 | 297 | */ |
|
298 | 298 | QBrush QLegend::labelBrush() const |
|
299 | 299 | { |
|
300 | 300 | return d_ptr->m_labelBrush; |
|
301 | 301 | } |
|
302 | 302 | |
|
303 | 303 | void QLegend::setLabelColor(QColor color) |
|
304 | 304 | { |
|
305 | 305 | QBrush b = d_ptr->m_labelBrush; |
|
306 | 306 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
307 | 307 | b.setStyle(Qt::SolidPattern); |
|
308 | 308 | b.setColor(color); |
|
309 | 309 | setLabelBrush(b); |
|
310 | 310 | } |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | QColor QLegend::labelColor() const |
|
314 | 314 | { |
|
315 | 315 | return d_ptr->m_labelBrush.color(); |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | |
|
319 | 319 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
320 | 320 | { |
|
321 | 321 | if (d_ptr->m_alignment != alignment) { |
|
322 | 322 | d_ptr->m_alignment = alignment; |
|
323 | 323 | layout()->invalidate(); |
|
324 | 324 | } |
|
325 | 325 | } |
|
326 | 326 | |
|
327 | 327 | Qt::Alignment QLegend::alignment() const |
|
328 | 328 | { |
|
329 | 329 | return d_ptr->m_alignment; |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | /*! |
|
333 | 333 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
334 | 334 | */ |
|
335 | 335 | void QLegend::detachFromChart() |
|
336 | 336 | { |
|
337 | 337 | d_ptr->m_attachedToChart = false; |
|
338 | 338 | // layout()->invalidate(); |
|
339 | 339 | d_ptr->m_chart->layout()->invalidate(); |
|
340 | 340 | setParent(0); |
|
341 | 341 | |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | /*! |
|
345 | 345 | Attaches the legend to chart. Chart may change layout of the legend. |
|
346 | 346 | */ |
|
347 | 347 | void QLegend::attachToChart() |
|
348 | 348 | { |
|
349 | 349 | d_ptr->m_attachedToChart = true; |
|
350 | 350 | // layout()->invalidate(); |
|
351 | 351 | d_ptr->m_chart->layout()->invalidate(); |
|
352 | 352 | setParent(d_ptr->m_chart); |
|
353 | 353 | } |
|
354 | 354 | |
|
355 | 355 | /*! |
|
356 | 356 | Returns true, if legend is attached to chart. |
|
357 | 357 | */ |
|
358 | 358 | bool QLegend::isAttachedToChart() |
|
359 | 359 | { |
|
360 | 360 | return d_ptr->m_attachedToChart; |
|
361 | 361 | } |
|
362 | 362 | |
|
363 | 363 | /*! |
|
364 | 364 | Sets the visibility of legend background to \a visible |
|
365 | 365 | */ |
|
366 | 366 | void QLegend::setBackgroundVisible(bool visible) |
|
367 | 367 | { |
|
368 | 368 | if (d_ptr->m_backgroundVisible != visible) { |
|
369 | 369 | d_ptr->m_backgroundVisible = visible; |
|
370 | 370 | update(); |
|
371 | 371 | emit backgroundVisibleChanged(visible); |
|
372 | 372 | } |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | /*! |
|
376 | 376 | Returns the visibility of legend background |
|
377 | 377 | */ |
|
378 | 378 | bool QLegend::isBackgroundVisible() const |
|
379 | 379 | { |
|
380 | 380 | return d_ptr->m_backgroundVisible; |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | /*! |
|
384 | 384 | Returns the list of markers in legend. The list can be filtered with \a series parameter. |
|
385 | 385 | If \a series is given, only markers related to that series are returned. |
|
386 | 386 | */ |
|
387 | 387 | QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const |
|
388 | 388 | { |
|
389 | 389 | return d_ptr->markers(series); |
|
390 | 390 | } |
|
391 | 391 | |
|
392 | 392 | /*! |
|
393 | 393 | \internal \a event see QGraphicsWidget for details |
|
394 | 394 | */ |
|
395 | 395 | void QLegend::hideEvent(QHideEvent *event) |
|
396 | 396 | { |
|
397 | 397 | if (isAttachedToChart()) |
|
398 | 398 | d_ptr->m_presenter->layout()->invalidate(); |
|
399 | 399 | QGraphicsWidget::hideEvent(event); |
|
400 | 400 | } |
|
401 | 401 | /*! |
|
402 | 402 | \internal \a event see QGraphicsWidget for details |
|
403 | 403 | */ |
|
404 | 404 | void QLegend::showEvent(QShowEvent *event) |
|
405 | 405 | { |
|
406 | 406 | if (isAttachedToChart()) |
|
407 | 407 | layout()->invalidate(); |
|
408 | 408 | QGraphicsWidget::showEvent(event); |
|
409 | 409 | //layout activation will show the items |
|
410 | 410 | } |
|
411 | 411 | |
|
412 | 412 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
413 | 413 | |
|
414 | 414 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
415 | 415 | : q_ptr(q), |
|
416 | 416 | m_presenter(presenter), |
|
417 | 417 | m_layout(new LegendLayout(q)), |
|
418 | 418 | m_chart(chart), |
|
419 | 419 | m_items(new QGraphicsItemGroup(q)), |
|
420 | 420 | m_alignment(Qt::AlignTop), |
|
421 | 421 | m_brush(QBrush()), |
|
422 | 422 | m_pen(QPen()), |
|
423 | 423 | m_labelBrush(QBrush()), |
|
424 | 424 | m_diameter(5), |
|
425 | 425 | m_attachedToChart(true), |
|
426 | 426 | m_backgroundVisible(false) |
|
427 | 427 | { |
|
428 | 428 | m_items->setHandlesChildEvents(false); |
|
429 | 429 | } |
|
430 | 430 | |
|
431 | 431 | QLegendPrivate::~QLegendPrivate() |
|
432 | 432 | { |
|
433 | 433 | |
|
434 | 434 | } |
|
435 | 435 | |
|
436 | 436 | void QLegendPrivate::setOffset(const QPointF &offset) |
|
437 | 437 | { |
|
438 | 438 | m_layout->setOffset(offset.x(), offset.y()); |
|
439 | 439 | } |
|
440 | 440 | |
|
441 | 441 | QPointF QLegendPrivate::offset() const |
|
442 | 442 | { |
|
443 | 443 | return m_layout->offset(); |
|
444 | 444 | } |
|
445 | 445 | |
|
446 | 446 | int QLegendPrivate::roundness(qreal size) |
|
447 | 447 | { |
|
448 | 448 | return 100 * m_diameter / int(size); |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series) |
|
452 | 452 | { |
|
453 | 453 | // Return all markers |
|
454 | 454 | if (!series) { |
|
455 | 455 | return m_markers; |
|
456 | 456 | } |
|
457 | 457 | |
|
458 | 458 | // Create filtered list |
|
459 | 459 | QList<QLegendMarker *> markers; |
|
460 | 460 | foreach (QLegendMarker *marker, m_markers) { |
|
461 | 461 | if (marker->series() == series) { |
|
462 | 462 | markers.append(marker); |
|
463 | 463 | } |
|
464 | 464 | } |
|
465 | 465 | return markers; |
|
466 | 466 | } |
|
467 | 467 | |
|
468 | 468 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) |
|
469 | 469 | { |
|
470 | 470 | if (m_series.contains(series)) { |
|
471 | 471 | return; |
|
472 | 472 | } |
|
473 | 473 | |
|
474 | 474 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
475 | 475 | decorateMarkers(newMarkers); |
|
476 | 476 | addMarkers(newMarkers); |
|
477 | 477 | |
|
478 | 478 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
479 | 479 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
480 | 480 | |
|
481 | 481 | m_series.append(series); |
|
482 | 482 | m_items->setVisible(false); |
|
483 | 483 | m_layout->invalidate(); |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
487 | 487 | { |
|
488 | 488 | if (m_series.contains(series)) { |
|
489 | 489 | m_series.removeOne(series); |
|
490 | 490 | } |
|
491 | 491 | |
|
492 | 492 | // Find out, which markers to remove |
|
493 | 493 | QList<QLegendMarker *> removed; |
|
494 | 494 | foreach (QLegendMarker *m, m_markers) { |
|
495 | 495 | if (m->series() == series) { |
|
496 | 496 | removed << m; |
|
497 | 497 | } |
|
498 | 498 | } |
|
499 | 499 | removeMarkers(removed); |
|
500 | 500 | |
|
501 | 501 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
502 | 502 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
503 | 503 | |
|
504 | 504 | m_layout->invalidate(); |
|
505 | 505 | } |
|
506 | 506 | |
|
507 | 507 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
508 | 508 | { |
|
509 | 509 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
510 | 510 | Q_ASSERT(series); |
|
511 | 511 | |
|
512 | 512 | foreach (QLegendMarker *marker, m_markers) { |
|
513 | 513 | if (marker->series() == series) { |
|
514 | 514 | marker->setVisible(series->isVisible()); |
|
515 | 515 | } |
|
516 | 516 | } |
|
517 | 517 | |
|
518 | 518 | if (m_chart->isVisible()) |
|
519 | 519 | m_layout->invalidate(); |
|
520 | 520 | } |
|
521 | 521 | |
|
522 | 522 | void QLegendPrivate::handleCountChanged() |
|
523 | 523 | { |
|
524 | 524 | // Here we handle the changes in marker count. |
|
525 | 525 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. |
|
526 | 526 | |
|
527 | 527 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); |
|
528 | 528 | QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr); |
|
529 | 529 | |
|
530 | 530 | // Find out removed markers and created markers |
|
531 | 531 | QList<QLegendMarker *> removedMarkers; |
|
532 | 532 | foreach (QLegendMarker *oldMarker, m_markers) { |
|
533 | 533 | // we have marker, which is related to sender. |
|
534 | 534 | if (oldMarker->series() == series->q_ptr) { |
|
535 | 535 | bool found = false; |
|
536 | 536 | foreach(QLegendMarker *newMarker, createdMarkers) { |
|
537 | 537 | // New marker considered existing if: |
|
538 | 538 | // - d_ptr->relatedObject() is same for both markers. |
|
539 | 539 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { |
|
540 | 540 | // Delete the new marker, since we already have existing marker, that might be connected on user side. |
|
541 | 541 | found = true; |
|
542 | 542 | createdMarkers.removeOne(newMarker); |
|
543 | 543 | delete newMarker; |
|
544 | 544 | } |
|
545 | 545 | } |
|
546 | 546 | if (!found) { |
|
547 | 547 | // No related object found for marker, add to removedMarkers list |
|
548 | 548 | removedMarkers << oldMarker; |
|
549 | 549 | } |
|
550 | 550 | } |
|
551 | 551 | } |
|
552 | 552 | |
|
553 | 553 | removeMarkers(removedMarkers); |
|
554 | 554 | decorateMarkers(createdMarkers); |
|
555 | 555 | addMarkers(createdMarkers); |
|
556 | 556 | |
|
557 | 557 | q_ptr->layout()->invalidate(); |
|
558 | 558 | } |
|
559 | 559 | |
|
560 | 560 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) |
|
561 | 561 | { |
|
562 | 562 | foreach (QLegendMarker *marker, markers) { |
|
563 | 563 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
564 | 564 | m_markers << marker; |
|
565 | 565 | m_markerHash.insert(marker->d_ptr->item(), marker); |
|
566 | 566 | } |
|
567 | 567 | } |
|
568 | 568 | |
|
569 | 569 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) |
|
570 | 570 | { |
|
571 | 571 | foreach (QLegendMarker *marker, markers) { |
|
572 | 572 | marker->d_ptr->item()->setVisible(false); |
|
573 | 573 | m_items->removeFromGroup(marker->d_ptr->item()); |
|
574 | 574 | m_markers.removeOne(marker); |
|
575 | 575 | m_markerHash.remove(marker->d_ptr->item()); |
|
576 | 576 | delete marker; |
|
577 | 577 | } |
|
578 | 578 | } |
|
579 | 579 | |
|
580 | 580 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) |
|
581 | 581 | { |
|
582 | 582 | foreach (QLegendMarker *marker, markers) { |
|
583 | 583 | marker->setFont(m_font); |
|
584 | 584 | marker->setLabelBrush(m_labelBrush); |
|
585 | 585 | } |
|
586 | 586 | } |
|
587 | 587 | |
|
588 | 588 | |
|
589 | 589 | #include "moc_qlegend.cpp" |
|
590 | 590 | #include "moc_qlegend_p.cpp" |
|
591 | 591 | |
|
592 | 592 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,167 +1,167 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qlineseries.h" |
|
22 | 22 | #include "qlineseries_p.h" |
|
23 | 23 | #include "linechartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "qchart_p.h" |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \class QLineSeries |
|
31 | 31 | \inmodule Qt Charts |
|
32 | 32 | \brief The QLineSeries class is used for making line charts. |
|
33 | 33 | |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 | 36 | A line chart is used to show information as a series of data points |
|
37 | 37 | connected by straight lines. |
|
38 | 38 | |
|
39 | 39 | \image examples_linechart.png |
|
40 | 40 | |
|
41 | 41 | Creating basic line chart is simple: |
|
42 | 42 | \code |
|
43 | 43 | QLineSeries* series = new QLineSeries(); |
|
44 | 44 | series->append(0, 6); |
|
45 | 45 | series->append(2, 4); |
|
46 | 46 | ... |
|
47 | 47 | chart->addSeries(series); |
|
48 | 48 | \endcode |
|
49 | 49 | */ |
|
50 | 50 | #ifdef QDOC_QT5 |
|
51 | 51 | /*! |
|
52 | 52 | \qmltype LineSeries |
|
53 | 53 | \instantiates QLineSeries |
|
54 | 54 | \inqmlmodule QtCommercial.Chart |
|
55 | 55 | |
|
56 |
\include |
|
|
56 | \include doc/src/lineseries.qdocinc | |
|
57 | 57 | */ |
|
58 | 58 | #else |
|
59 | 59 | /*! |
|
60 | 60 | \qmlclass LineSeries QLineSeries |
|
61 | 61 | |
|
62 | 62 | \include ../doc/src/lineseries.qdocinc |
|
63 | 63 | */ |
|
64 | 64 | #endif |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \fn virtual SeriesType QLineSeries::type() const |
|
68 | 68 | \brief Returns type of series. |
|
69 | 69 | \sa QAbstractSeries, SeriesType |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \qmlproperty real LineSeries::width |
|
74 | 74 | The width of the line. By default the width is 2.0. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \qmlproperty Qt::PenStyle LineSeries::style |
|
79 | 79 | Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine, |
|
80 | 80 | Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API. |
|
81 | 81 | By default the style is Qt.SolidLine. |
|
82 | 82 | */ |
|
83 | 83 | |
|
84 | 84 | /*! |
|
85 | 85 | \qmlproperty Qt::PenCapStyle LineSeries::capStyle |
|
86 | 86 | Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By |
|
87 | 87 | default the cap style is Qt.SquareCap. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | Constructs empty series object which is a child of \a parent. |
|
92 | 92 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
93 | 93 | */ |
|
94 | 94 | QLineSeries::QLineSeries(QObject *parent) |
|
95 | 95 | : QXYSeries(*new QLineSeriesPrivate(this), parent) |
|
96 | 96 | { |
|
97 | 97 | |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \internal |
|
102 | 102 | */ |
|
103 | 103 | QLineSeries::QLineSeries(QLineSeriesPrivate &d, QObject *parent) |
|
104 | 104 | : QXYSeries(d, parent) |
|
105 | 105 | { |
|
106 | 106 | |
|
107 | 107 | } |
|
108 | 108 | /*! |
|
109 | 109 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
110 | 110 | and are deleted when mentioned object are destroyed. |
|
111 | 111 | */ |
|
112 | 112 | QLineSeries::~QLineSeries() |
|
113 | 113 | { |
|
114 | 114 | Q_D(QLineSeries); |
|
115 | 115 | if (d->m_chart) |
|
116 | 116 | d->m_chart->removeSeries(this); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | QAbstractSeries::SeriesType QLineSeries::type() const |
|
120 | 120 | { |
|
121 | 121 | return QAbstractSeries::SeriesTypeLine; |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | /* |
|
125 | 125 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
126 | 126 | { |
|
127 | 127 | Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size()); |
|
128 | 128 | int size = series.d_func()->m_x.size(); |
|
129 | 129 | for (int i=0; i<size; i++) { |
|
130 | 130 | debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") "; |
|
131 | 131 | } |
|
132 | 132 | return debug.space(); |
|
133 | 133 | } |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
137 | 137 | |
|
138 | 138 | QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries *q) |
|
139 | 139 | : QXYSeriesPrivate(q) |
|
140 | 140 | { |
|
141 | 141 | |
|
142 | 142 | }; |
|
143 | 143 | |
|
144 | 144 | void QLineSeriesPrivate::initializeGraphics(QGraphicsItem *parent) |
|
145 | 145 | { |
|
146 | 146 | Q_Q(QLineSeries); |
|
147 | 147 | LineChartItem *line = new LineChartItem(q,parent); |
|
148 | 148 | m_item.reset(line); |
|
149 | 149 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
153 | 153 | { |
|
154 | 154 | Q_Q(QLineSeries); |
|
155 | 155 | const QList<QColor> colors = theme->seriesColors(); |
|
156 | 156 | |
|
157 | 157 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
158 | 158 | QPen pen; |
|
159 | 159 | pen.setColor(colors.at(index % colors.size())); |
|
160 | 160 | pen.setWidthF(2); |
|
161 | 161 | q->setPen(pen); |
|
162 | 162 | } |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | #include "moc_qlineseries.cpp" |
|
166 | 166 | |
|
167 | 167 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,257 +1,257 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qhpiemodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QHPieModelMapper |
|
27 | 27 | \inmodule Qt Charts |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows. |
|
32 | 32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync. |
|
33 | 33 | \note Used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | 34 | */ |
|
35 | 35 | #ifdef QDOC_QT5 |
|
36 | 36 | /*! |
|
37 | 37 | \qmltype HPieModelMapper |
|
38 | 38 | \instantiates QHPieModelMapper |
|
39 | 39 | \inqmlmodule QtCommercial.Chart |
|
40 | 40 | |
|
41 |
\include |
|
|
41 | \include doc/src/hpiemodelmapper.qdocinc | |
|
42 | 42 | */ |
|
43 | 43 | #else |
|
44 | 44 | /*! |
|
45 | 45 | \qmlclass HPieModelMapper QHPieModelMapper |
|
46 | 46 | |
|
47 | 47 | \include ../doc/src/hpiemodelmapper.qdocinc |
|
48 | 48 | */ |
|
49 | 49 | #endif |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | \property QHPieModelMapper::series |
|
53 | 53 | \brief Defines the QPieSeries object that is used by the mapper. |
|
54 | 54 | |
|
55 | 55 | All the data in the series is discarded when it is set to the mapper. |
|
56 | 56 | When new series is specified the old series is disconnected (it preserves its data) |
|
57 | 57 | */ |
|
58 | 58 | /*! |
|
59 | 59 | \qmlproperty PieSeries HPieModelMapper::series |
|
60 | 60 | Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a |
|
61 | 61 | PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper. |
|
62 | 62 | When new series is specified the old series is disconnected (it preserves its data). |
|
63 | 63 | */ |
|
64 | 64 | |
|
65 | 65 | /*! |
|
66 | 66 | \property QHPieModelMapper::model |
|
67 | 67 | \brief Defines the model that is used by the mapper. |
|
68 | 68 | */ |
|
69 | 69 | /*! |
|
70 | 70 | \qmlproperty SomeModel HPieModelMapper::model |
|
71 | 71 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model |
|
72 | 72 | and expose it to QML. Note: the model has to support adding/removing rows/columns and modifying |
|
73 | 73 | the data of the cells. |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \property QHPieModelMapper::valuesRow |
|
78 | 78 | \brief Defines which row of the model is kept in sync with the values of the pie's slices. |
|
79 | 79 | |
|
80 | 80 | Default value is: -1 (invalid mapping) |
|
81 | 81 | */ |
|
82 | 82 | /*! |
|
83 | 83 | \qmlproperty int HPieModelMapper::valuesRow |
|
84 | 84 | Defines which row of the model is kept in sync with the values of the pie's slices. Default value is: -1 (invalid |
|
85 | 85 | mapping). |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QHPieModelMapper::labelsRow |
|
90 | 90 | \brief Defines which row of the model is kept in sync with the labels of the pie's slices. |
|
91 | 91 | |
|
92 | 92 | Default value is: -1 (invalid mapping) |
|
93 | 93 | */ |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty int HPieModelMapper::labelsRow |
|
96 | 96 | Defines which row of the model is kept in sync with the labels of the pie's slices |
|
97 | 97 | Default value is: -1 (invalid mapping) |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \property QHPieModelMapper::firstColumn |
|
102 | 102 | \brief Defines which column of the model contains the first slice value. |
|
103 | 103 | |
|
104 | 104 | Minimal and default value is: 0 |
|
105 | 105 | */ |
|
106 | 106 | /*! |
|
107 | 107 | \qmlproperty int HPieModelMapper::firstColumn |
|
108 | 108 | Defines which column of the model contains the first slice value. |
|
109 | 109 | The default value is 0. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \property QHPieModelMapper::columnCount |
|
114 | 114 | \brief Defines the number of columns of the model that are mapped as the data for QPieSeries. |
|
115 | 115 | |
|
116 | 116 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
117 | 117 | */ |
|
118 | 118 | /*! |
|
119 | 119 | \qmlproperty int HPieModelMapper::columnCount |
|
120 | 120 | Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is |
|
121 | 121 | -1 (count limited by the number of columns in the model) |
|
122 | 122 | */ |
|
123 | 123 | |
|
124 | 124 | /*! |
|
125 | 125 | \fn void QHPieModelMapper::seriesReplaced() |
|
126 | 126 | Emitted when the series to which mapper is connected to has changed. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \fn void QHPieModelMapper::modelReplaced() |
|
131 | 131 | Emitted when the model to which mapper is connected to has changed. |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \fn void QHPieModelMapper::valuesRowChanged() |
|
136 | 136 | Emitted when the valuesRow has changed. |
|
137 | 137 | */ |
|
138 | 138 | |
|
139 | 139 | /*! |
|
140 | 140 | \fn void QHPieModelMapper::labelsRowChanged() |
|
141 | 141 | Emitted when the labelsRow has changed. |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \fn void QHPieModelMapper::firstColumnChanged() |
|
146 | 146 | Emitted when the firstColumn has changed. |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QHPieModelMapper::columnCountChanged() |
|
151 | 151 | Emitted when the columnCount has changed. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | Constructs a mapper object which is a child of \a parent. |
|
156 | 156 | */ |
|
157 | 157 | QHPieModelMapper::QHPieModelMapper(QObject *parent) : |
|
158 | 158 | QPieModelMapper(parent) |
|
159 | 159 | { |
|
160 | 160 | setOrientation(Qt::Horizontal); |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | QAbstractItemModel *QHPieModelMapper::model() const |
|
164 | 164 | { |
|
165 | 165 | return QPieModelMapper::model(); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void QHPieModelMapper::setModel(QAbstractItemModel *model) |
|
169 | 169 | { |
|
170 | 170 | if (model != QPieModelMapper::model()) { |
|
171 | 171 | QPieModelMapper::setModel(model); |
|
172 | 172 | emit modelReplaced(); |
|
173 | 173 | } |
|
174 | 174 | } |
|
175 | 175 | |
|
176 | 176 | QPieSeries *QHPieModelMapper::series() const |
|
177 | 177 | { |
|
178 | 178 | return QPieModelMapper::series(); |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | void QHPieModelMapper::setSeries(QPieSeries *series) |
|
182 | 182 | { |
|
183 | 183 | if (series != QPieModelMapper::series()) { |
|
184 | 184 | QPieModelMapper::setSeries(series); |
|
185 | 185 | emit seriesReplaced(); |
|
186 | 186 | } |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | /*! |
|
190 | 190 | Returns which row of the model is kept in sync with the values of the pie's slices |
|
191 | 191 | */ |
|
192 | 192 | int QHPieModelMapper::valuesRow() const |
|
193 | 193 | { |
|
194 | 194 | return valuesSection(); |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | /*! |
|
198 | 198 | Sets the model row that is kept in sync with the pie slices values. |
|
199 | 199 | Parameter \a valuesRow specifies the row of the model. |
|
200 | 200 | */ |
|
201 | 201 | void QHPieModelMapper::setValuesRow(int valuesRow) |
|
202 | 202 | { |
|
203 | 203 | if (valuesRow != valuesSection()) { |
|
204 | 204 | setValuesSection(valuesRow); |
|
205 | 205 | emit valuesRowChanged(); |
|
206 | 206 | } |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | /*! |
|
210 | 210 | Returns which row of the model is kept in sync with the labels of the pie's slices |
|
211 | 211 | */ |
|
212 | 212 | int QHPieModelMapper::labelsRow() const |
|
213 | 213 | { |
|
214 | 214 | return labelsSection(); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | /*! |
|
218 | 218 | Sets the model row that is kept in sync with the pie's slices labels. |
|
219 | 219 | Parameter \a labelsRow specifies the row of the model. |
|
220 | 220 | */ |
|
221 | 221 | void QHPieModelMapper::setLabelsRow(int labelsRow) |
|
222 | 222 | { |
|
223 | 223 | if (labelsRow != labelsSection()) { |
|
224 | 224 | setLabelsSection(labelsRow); |
|
225 | 225 | emit labelsRowChanged(); |
|
226 | 226 | } |
|
227 | 227 | } |
|
228 | 228 | |
|
229 | 229 | int QHPieModelMapper::firstColumn() const |
|
230 | 230 | { |
|
231 | 231 | return first(); |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | void QHPieModelMapper::setFirstColumn(int firstColumn) |
|
235 | 235 | { |
|
236 | 236 | if (firstColumn != first()) { |
|
237 | 237 | setFirst(firstColumn); |
|
238 | 238 | emit firstColumnChanged(); |
|
239 | 239 | } |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | int QHPieModelMapper::columnCount() const |
|
243 | 243 | { |
|
244 | 244 | return count(); |
|
245 | 245 | } |
|
246 | 246 | |
|
247 | 247 | void QHPieModelMapper::setColumnCount(int columnCount) |
|
248 | 248 | { |
|
249 | 249 | if (columnCount != count()) { |
|
250 | 250 | setCount(columnCount); |
|
251 | 251 | emit columnCountChanged(); |
|
252 | 252 | } |
|
253 | 253 | } |
|
254 | 254 | |
|
255 | 255 | #include "moc_qhpiemodelmapper.cpp" |
|
256 | 256 | |
|
257 | 257 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,942 +1,942 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qpieseries.h" |
|
22 | 22 | #include "qpieseries_p.h" |
|
23 | 23 | #include "qpieslice.h" |
|
24 | 24 | #include "qpieslice_p.h" |
|
25 | 25 | #include "pieslicedata_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "qabstractaxis.h" |
|
29 | 29 | #include "pieanimation_p.h" |
|
30 | 30 | #include "charthelpers_p.h" |
|
31 | 31 | |
|
32 | 32 | #include "qpielegendmarker.h" |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \class QPieSeries |
|
38 | 38 | \inmodule Qt Charts |
|
39 | 39 | \brief Pie series API for Qt Charts. |
|
40 | 40 | |
|
41 | 41 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
42 | 42 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
43 | 43 | The actual slice size is determined by that relative value. |
|
44 | 44 | |
|
45 | 45 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0. |
|
46 | 46 | These relate to the actual chart rectangle. |
|
47 | 47 | |
|
48 | 48 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
49 | 49 | This can be done by setting a starting angle and angle span to the series. |
|
50 | 50 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
51 | 51 | |
|
52 | 52 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. |
|
53 | 53 | \table 100% |
|
54 | 54 | \row |
|
55 | 55 | \li \image examples_piechart.png |
|
56 | 56 | \li \image examples_donutchart.png |
|
57 | 57 | \endtable |
|
58 | 58 | */ |
|
59 | 59 | #ifdef QDOC_QT5 |
|
60 | 60 | /*! |
|
61 | 61 | \qmltype PieSeries |
|
62 | 62 | \instantiates QPieSeries |
|
63 | 63 | \inqmlmodule QtCommercial.Chart |
|
64 | 64 | |
|
65 |
\include |
|
|
65 | \include doc/src/pieseries.qdocinc | |
|
66 | 66 | */ |
|
67 | 67 | #else |
|
68 | 68 | /*! |
|
69 | 69 | \qmlclass PieSeries QPieSeries |
|
70 | 70 | |
|
71 | 71 | \include ../doc/src/pieseries.qdocinc |
|
72 | 72 | */ |
|
73 | 73 | #endif |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \property QPieSeries::horizontalPosition |
|
77 | 77 | \brief Defines the horizontal position of the pie. |
|
78 | 78 | |
|
79 | 79 | The value is a relative value to the chart rectangle where: |
|
80 | 80 | |
|
81 | 81 | \list |
|
82 | 82 | \li 0.0 is the absolute left. |
|
83 | 83 | \li 1.0 is the absolute right. |
|
84 | 84 | \endlist |
|
85 | 85 | Default value is 0.5 (center). |
|
86 | 86 | \sa verticalPosition |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty real PieSeries::horizontalPosition |
|
91 | 91 | |
|
92 | 92 | Defines the horizontal position of the pie. |
|
93 | 93 | |
|
94 | 94 | The value is a relative value to the chart rectangle where: |
|
95 | 95 | |
|
96 | 96 | \list |
|
97 | 97 | \li 0.0 is the absolute left. |
|
98 | 98 | \li 1.0 is the absolute right. |
|
99 | 99 | \endlist |
|
100 | 100 | Default value is 0.5 (center). |
|
101 | 101 | \sa verticalPosition |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \property QPieSeries::verticalPosition |
|
106 | 106 | \brief Defines the vertical position of the pie. |
|
107 | 107 | |
|
108 | 108 | The value is a relative value to the chart rectangle where: |
|
109 | 109 | |
|
110 | 110 | \list |
|
111 | 111 | \li 0.0 is the absolute top. |
|
112 | 112 | \li 1.0 is the absolute bottom. |
|
113 | 113 | \endlist |
|
114 | 114 | Default value is 0.5 (center). |
|
115 | 115 | \sa horizontalPosition |
|
116 | 116 | */ |
|
117 | 117 | |
|
118 | 118 | /*! |
|
119 | 119 | \qmlproperty real PieSeries::verticalPosition |
|
120 | 120 | |
|
121 | 121 | Defines the vertical position of the pie. |
|
122 | 122 | |
|
123 | 123 | The value is a relative value to the chart rectangle where: |
|
124 | 124 | |
|
125 | 125 | \list |
|
126 | 126 | \li 0.0 is the absolute top. |
|
127 | 127 | \li 1.0 is the absolute bottom. |
|
128 | 128 | \endlist |
|
129 | 129 | Default value is 0.5 (center). |
|
130 | 130 | \sa horizontalPosition |
|
131 | 131 | */ |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \property QPieSeries::size |
|
135 | 135 | \brief Defines the pie size. |
|
136 | 136 | |
|
137 | 137 | The value is a relative value to the chart rectangle where: |
|
138 | 138 | |
|
139 | 139 | \list |
|
140 | 140 | \li 0.0 is the minimum size (pie not drawn). |
|
141 | 141 | \li 1.0 is the maximum size that can fit the chart. |
|
142 | 142 | \endlist |
|
143 | 143 | |
|
144 | 144 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. |
|
145 | 145 | |
|
146 | 146 | Default value is 0.7. |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \qmlproperty real PieSeries::size |
|
151 | 151 | |
|
152 | 152 | Defines the pie size. |
|
153 | 153 | |
|
154 | 154 | The value is a relative value to the chart rectangle where: |
|
155 | 155 | |
|
156 | 156 | \list |
|
157 | 157 | \li 0.0 is the minimum size (pie not drawn). |
|
158 | 158 | \li 1.0 is the maximum size that can fit the chart. |
|
159 | 159 | \endlist |
|
160 | 160 | |
|
161 | 161 | Default value is 0.7. |
|
162 | 162 | */ |
|
163 | 163 | |
|
164 | 164 | /*! |
|
165 | 165 | \property QPieSeries::holeSize |
|
166 | 166 | \brief Defines the donut hole size. |
|
167 | 167 | |
|
168 | 168 | The value is a relative value to the chart rectangle where: |
|
169 | 169 | |
|
170 | 170 | \list |
|
171 | 171 | \li 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
172 | 172 | \li 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
173 | 173 | \endlist |
|
174 | 174 | |
|
175 | 175 | The value is never greater then size property. |
|
176 | 176 | Default value is 0.0. |
|
177 | 177 | */ |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | \qmlproperty real PieSeries::holeSize |
|
181 | 181 | |
|
182 | 182 | Defines the donut hole size. |
|
183 | 183 | |
|
184 | 184 | The value is a relative value to the chart rectangle where: |
|
185 | 185 | |
|
186 | 186 | \list |
|
187 | 187 | \li 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
188 | 188 | \li 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
189 | 189 | \endlist |
|
190 | 190 | |
|
191 | 191 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. |
|
192 | 192 | |
|
193 | 193 | Default value is 0.0. |
|
194 | 194 | */ |
|
195 | 195 | |
|
196 | 196 | /*! |
|
197 | 197 | \property QPieSeries::startAngle |
|
198 | 198 | \brief Defines the starting angle of the pie. |
|
199 | 199 | |
|
200 | 200 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
201 | 201 | |
|
202 | 202 | Default is value is 0. |
|
203 | 203 | */ |
|
204 | 204 | |
|
205 | 205 | /*! |
|
206 | 206 | \qmlproperty real PieSeries::startAngle |
|
207 | 207 | |
|
208 | 208 | Defines the starting angle of the pie. |
|
209 | 209 | |
|
210 | 210 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
211 | 211 | |
|
212 | 212 | Default is value is 0. |
|
213 | 213 | */ |
|
214 | 214 | |
|
215 | 215 | /*! |
|
216 | 216 | \property QPieSeries::endAngle |
|
217 | 217 | \brief Defines the ending angle of the pie. |
|
218 | 218 | |
|
219 | 219 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
220 | 220 | |
|
221 | 221 | Default is value is 360. |
|
222 | 222 | */ |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | \qmlproperty real PieSeries::endAngle |
|
226 | 226 | |
|
227 | 227 | Defines the ending angle of the pie. |
|
228 | 228 | |
|
229 | 229 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
230 | 230 | |
|
231 | 231 | Default is value is 360. |
|
232 | 232 | */ |
|
233 | 233 | |
|
234 | 234 | /*! |
|
235 | 235 | \property QPieSeries::count |
|
236 | 236 | |
|
237 | 237 | Number of slices in the series. |
|
238 | 238 | */ |
|
239 | 239 | |
|
240 | 240 | /*! |
|
241 | 241 | \qmlproperty int PieSeries::count |
|
242 | 242 | |
|
243 | 243 | Number of slices in the series. |
|
244 | 244 | */ |
|
245 | 245 | |
|
246 | 246 | /*! |
|
247 | 247 | \fn void QPieSeries::countChanged() |
|
248 | 248 | Emitted when the slice count has changed. |
|
249 | 249 | \sa count |
|
250 | 250 | */ |
|
251 | 251 | /*! |
|
252 | 252 | \qmlsignal PieSeries::onCountChanged() |
|
253 | 253 | Emitted when the slice count has changed. |
|
254 | 254 | */ |
|
255 | 255 | |
|
256 | 256 | /*! |
|
257 | 257 | \property QPieSeries::sum |
|
258 | 258 | |
|
259 | 259 | Sum of all slices. |
|
260 | 260 | |
|
261 | 261 | The series keeps track of the sum of all slices it holds. |
|
262 | 262 | */ |
|
263 | 263 | |
|
264 | 264 | /*! |
|
265 | 265 | \qmlproperty real PieSeries::sum |
|
266 | 266 | |
|
267 | 267 | Sum of all slices. |
|
268 | 268 | |
|
269 | 269 | The series keeps track of the sum of all slices it holds. |
|
270 | 270 | */ |
|
271 | 271 | |
|
272 | 272 | /*! |
|
273 | 273 | \fn void QPieSeries::sumChanged() |
|
274 | 274 | Emitted when the sum of all slices has changed. |
|
275 | 275 | \sa sum |
|
276 | 276 | */ |
|
277 | 277 | /*! |
|
278 | 278 | \qmlsignal PieSeries::onSumChanged() |
|
279 | 279 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
280 | 280 | change value of a slice. |
|
281 | 281 | */ |
|
282 | 282 | |
|
283 | 283 | /*! |
|
284 | 284 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
285 | 285 | |
|
286 | 286 | This signal is emitted when \a slices have been added to the series. |
|
287 | 287 | |
|
288 | 288 | \sa append(), insert() |
|
289 | 289 | */ |
|
290 | 290 | /*! |
|
291 | 291 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
292 | 292 | Emitted when \a slice has been added to the series. |
|
293 | 293 | */ |
|
294 | 294 | |
|
295 | 295 | /*! |
|
296 | 296 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
297 | 297 | This signal is emitted when \a slices have been removed from the series. |
|
298 | 298 | \sa remove() |
|
299 | 299 | */ |
|
300 | 300 | /*! |
|
301 | 301 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
302 | 302 | Emitted when \a slice has been removed from the series. |
|
303 | 303 | */ |
|
304 | 304 | |
|
305 | 305 | /*! |
|
306 | 306 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
307 | 307 | This signal is emitted when a \a slice has been clicked. |
|
308 | 308 | \sa QPieSlice::clicked() |
|
309 | 309 | */ |
|
310 | 310 | /*! |
|
311 | 311 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
312 | 312 | This signal is emitted when a \a slice has been clicked. |
|
313 | 313 | */ |
|
314 | 314 | |
|
315 | 315 | /*! |
|
316 | 316 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
317 | 317 | This signal is emitted when user has hovered over or away from the \a slice. |
|
318 | 318 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
319 | 319 | \sa QPieSlice::hovered() |
|
320 | 320 | */ |
|
321 | 321 | /*! |
|
322 | 322 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
323 | 323 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
324 | 324 | over the slice and false when hover has moved away from the slice. |
|
325 | 325 | */ |
|
326 | 326 | |
|
327 | 327 | /*! |
|
328 | 328 | \qmlmethod PieSlice PieSeries::at(int index) |
|
329 | 329 | Returns slice at \a index. Returns null if the index is not valid. |
|
330 | 330 | */ |
|
331 | 331 | |
|
332 | 332 | /*! |
|
333 | 333 | \qmlmethod PieSlice PieSeries::find(string label) |
|
334 | 334 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
335 | 335 | */ |
|
336 | 336 | |
|
337 | 337 | /*! |
|
338 | 338 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
339 | 339 | Adds a new slice with \a label and \a value to the pie. |
|
340 | 340 | */ |
|
341 | 341 | |
|
342 | 342 | /*! |
|
343 | 343 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
344 | 344 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. |
|
345 | 345 | */ |
|
346 | 346 | |
|
347 | 347 | /*! |
|
348 | 348 | \qmlmethod PieSeries::clear() |
|
349 | 349 | Removes all slices from the pie. |
|
350 | 350 | */ |
|
351 | 351 | |
|
352 | 352 | /*! |
|
353 | 353 | Constructs a series object which is a child of \a parent. |
|
354 | 354 | */ |
|
355 | 355 | QPieSeries::QPieSeries(QObject *parent) |
|
356 | 356 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) |
|
357 | 357 | { |
|
358 | 358 | Q_D(QPieSeries); |
|
359 | 359 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | /*! |
|
363 | 363 | Destroys the series and its slices. |
|
364 | 364 | */ |
|
365 | 365 | QPieSeries::~QPieSeries() |
|
366 | 366 | { |
|
367 | 367 | // NOTE: d_prt destroyed by QObject |
|
368 | 368 | clear(); |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | /*! |
|
372 | 372 | Returns QAbstractSeries::SeriesTypePie. |
|
373 | 373 | */ |
|
374 | 374 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
375 | 375 | { |
|
376 | 376 | return QAbstractSeries::SeriesTypePie; |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | /*! |
|
380 | 380 | Appends a single \a slice to the series. |
|
381 | 381 | Slice ownership is passed to the series. |
|
382 | 382 | |
|
383 | 383 | Returns true if append was succesfull. |
|
384 | 384 | */ |
|
385 | 385 | bool QPieSeries::append(QPieSlice *slice) |
|
386 | 386 | { |
|
387 | 387 | return append(QList<QPieSlice *>() << slice); |
|
388 | 388 | } |
|
389 | 389 | |
|
390 | 390 | /*! |
|
391 | 391 | Appends an array of \a slices to the series. |
|
392 | 392 | Slice ownership is passed to the series. |
|
393 | 393 | |
|
394 | 394 | Returns true if append was successful. |
|
395 | 395 | */ |
|
396 | 396 | bool QPieSeries::append(QList<QPieSlice *> slices) |
|
397 | 397 | { |
|
398 | 398 | Q_D(QPieSeries); |
|
399 | 399 | |
|
400 | 400 | if (slices.count() == 0) |
|
401 | 401 | return false; |
|
402 | 402 | |
|
403 | 403 | foreach (QPieSlice *s, slices) { |
|
404 | 404 | if (!s || d->m_slices.contains(s)) |
|
405 | 405 | return false; |
|
406 | 406 | if (s->series()) // already added to some series |
|
407 | 407 | return false; |
|
408 | 408 | if (!isValidValue(s->value())) |
|
409 | 409 | return false; |
|
410 | 410 | } |
|
411 | 411 | |
|
412 | 412 | foreach (QPieSlice *s, slices) { |
|
413 | 413 | s->setParent(this); |
|
414 | 414 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
415 | 415 | d->m_slices << s; |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | d->updateDerivativeData(); |
|
419 | 419 | |
|
420 | 420 | foreach(QPieSlice * s, slices) { |
|
421 | 421 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
422 | 422 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
423 | 423 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
424 | 424 | } |
|
425 | 425 | |
|
426 | 426 | emit added(slices); |
|
427 | 427 | emit countChanged(); |
|
428 | 428 | |
|
429 | 429 | return true; |
|
430 | 430 | } |
|
431 | 431 | |
|
432 | 432 | /*! |
|
433 | 433 | Appends a single \a slice to the series and returns a reference to the series. |
|
434 | 434 | Slice ownership is passed to the series. |
|
435 | 435 | */ |
|
436 | 436 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) |
|
437 | 437 | { |
|
438 | 438 | append(slice); |
|
439 | 439 | return *this; |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | |
|
443 | 443 | /*! |
|
444 | 444 | Appends a single slice to the series with give \a value and \a label. |
|
445 | 445 | Slice ownership is passed to the series. |
|
446 | 446 | Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series. |
|
447 | 447 | */ |
|
448 | 448 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
449 | 449 | { |
|
450 | 450 | if (isValidValue(value)) { |
|
451 | 451 | QPieSlice *slice = new QPieSlice(label, value); |
|
452 | 452 | append(slice); |
|
453 | 453 | return slice; |
|
454 | 454 | } else { |
|
455 | 455 | return 0; |
|
456 | 456 | } |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | /*! |
|
460 | 460 | Inserts a single \a slice to the series before the slice at \a index position. |
|
461 | 461 | Slice ownership is passed to the series. |
|
462 | 462 | |
|
463 | 463 | Returns true if insert was successful. |
|
464 | 464 | */ |
|
465 | 465 | bool QPieSeries::insert(int index, QPieSlice *slice) |
|
466 | 466 | { |
|
467 | 467 | Q_D(QPieSeries); |
|
468 | 468 | |
|
469 | 469 | if (index < 0 || index > d->m_slices.count()) |
|
470 | 470 | return false; |
|
471 | 471 | |
|
472 | 472 | if (!slice || d->m_slices.contains(slice)) |
|
473 | 473 | return false; |
|
474 | 474 | |
|
475 | 475 | if (slice->series()) // already added to some series |
|
476 | 476 | return false; |
|
477 | 477 | |
|
478 | 478 | if (!isValidValue(slice->value())) |
|
479 | 479 | return false; |
|
480 | 480 | |
|
481 | 481 | slice->setParent(this); |
|
482 | 482 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
483 | 483 | d->m_slices.insert(index, slice); |
|
484 | 484 | |
|
485 | 485 | d->updateDerivativeData(); |
|
486 | 486 | |
|
487 | 487 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
488 | 488 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
489 | 489 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
490 | 490 | |
|
491 | 491 | emit added(QList<QPieSlice *>() << slice); |
|
492 | 492 | emit countChanged(); |
|
493 | 493 | |
|
494 | 494 | return true; |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | /*! |
|
498 | 498 | Removes a single \a slice from the series and deletes the slice. |
|
499 | 499 | |
|
500 | 500 | Do not reference the pointer after this call. |
|
501 | 501 | |
|
502 | 502 | Returns true if remove was successful. |
|
503 | 503 | */ |
|
504 | 504 | bool QPieSeries::remove(QPieSlice *slice) |
|
505 | 505 | { |
|
506 | 506 | Q_D(QPieSeries); |
|
507 | 507 | |
|
508 | 508 | if (!d->m_slices.removeOne(slice)) |
|
509 | 509 | return false; |
|
510 | 510 | |
|
511 | 511 | d->updateDerivativeData(); |
|
512 | 512 | |
|
513 | 513 | emit removed(QList<QPieSlice *>() << slice); |
|
514 | 514 | emit countChanged(); |
|
515 | 515 | |
|
516 | 516 | delete slice; |
|
517 | 517 | slice = 0; |
|
518 | 518 | |
|
519 | 519 | return true; |
|
520 | 520 | } |
|
521 | 521 | |
|
522 | 522 | /*! |
|
523 | 523 | Takes a single \a slice from the series. Does not destroy the slice object. |
|
524 | 524 | |
|
525 | 525 | \note The series remains as the slice's parent object. You must set the |
|
526 | 526 | parent object to take full ownership. |
|
527 | 527 | |
|
528 | 528 | Returns true if take was successful. |
|
529 | 529 | */ |
|
530 | 530 | bool QPieSeries::take(QPieSlice *slice) |
|
531 | 531 | { |
|
532 | 532 | Q_D(QPieSeries); |
|
533 | 533 | |
|
534 | 534 | if (!d->m_slices.removeOne(slice)) |
|
535 | 535 | return false; |
|
536 | 536 | |
|
537 | 537 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; |
|
538 | 538 | slice->disconnect(d); |
|
539 | 539 | |
|
540 | 540 | d->updateDerivativeData(); |
|
541 | 541 | |
|
542 | 542 | emit removed(QList<QPieSlice *>() << slice); |
|
543 | 543 | emit countChanged(); |
|
544 | 544 | |
|
545 | 545 | return true; |
|
546 | 546 | } |
|
547 | 547 | |
|
548 | 548 | /*! |
|
549 | 549 | Clears all slices from the series. |
|
550 | 550 | */ |
|
551 | 551 | void QPieSeries::clear() |
|
552 | 552 | { |
|
553 | 553 | Q_D(QPieSeries); |
|
554 | 554 | if (d->m_slices.count() == 0) |
|
555 | 555 | return; |
|
556 | 556 | |
|
557 | 557 | QList<QPieSlice *> slices = d->m_slices; |
|
558 | 558 | foreach (QPieSlice *s, d->m_slices) |
|
559 | 559 | d->m_slices.removeOne(s); |
|
560 | 560 | |
|
561 | 561 | d->updateDerivativeData(); |
|
562 | 562 | |
|
563 | 563 | emit removed(slices); |
|
564 | 564 | emit countChanged(); |
|
565 | 565 | |
|
566 | 566 | foreach (QPieSlice *s, slices) |
|
567 | 567 | delete s; |
|
568 | 568 | } |
|
569 | 569 | |
|
570 | 570 | /*! |
|
571 | 571 | Returns a list of slices that belong to this series. |
|
572 | 572 | */ |
|
573 | 573 | QList<QPieSlice *> QPieSeries::slices() const |
|
574 | 574 | { |
|
575 | 575 | Q_D(const QPieSeries); |
|
576 | 576 | return d->m_slices; |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | /*! |
|
580 | 580 | returns the number of the slices in this series. |
|
581 | 581 | */ |
|
582 | 582 | int QPieSeries::count() const |
|
583 | 583 | { |
|
584 | 584 | Q_D(const QPieSeries); |
|
585 | 585 | return d->m_slices.count(); |
|
586 | 586 | } |
|
587 | 587 | |
|
588 | 588 | /*! |
|
589 | 589 | Returns true is the series is empty. |
|
590 | 590 | */ |
|
591 | 591 | bool QPieSeries::isEmpty() const |
|
592 | 592 | { |
|
593 | 593 | Q_D(const QPieSeries); |
|
594 | 594 | return d->m_slices.isEmpty(); |
|
595 | 595 | } |
|
596 | 596 | |
|
597 | 597 | /*! |
|
598 | 598 | Returns the sum of all slice values in this series. |
|
599 | 599 | |
|
600 | 600 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
601 | 601 | */ |
|
602 | 602 | qreal QPieSeries::sum() const |
|
603 | 603 | { |
|
604 | 604 | Q_D(const QPieSeries); |
|
605 | 605 | return d->m_sum; |
|
606 | 606 | } |
|
607 | 607 | |
|
608 | 608 | void QPieSeries::setHoleSize(qreal holeSize) |
|
609 | 609 | { |
|
610 | 610 | Q_D(QPieSeries); |
|
611 | 611 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); |
|
612 | 612 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); |
|
613 | 613 | } |
|
614 | 614 | |
|
615 | 615 | qreal QPieSeries::holeSize() const |
|
616 | 616 | { |
|
617 | 617 | Q_D(const QPieSeries); |
|
618 | 618 | return d->m_holeRelativeSize; |
|
619 | 619 | } |
|
620 | 620 | |
|
621 | 621 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
622 | 622 | { |
|
623 | 623 | Q_D(QPieSeries); |
|
624 | 624 | |
|
625 | 625 | if (relativePosition < 0.0) |
|
626 | 626 | relativePosition = 0.0; |
|
627 | 627 | if (relativePosition > 1.0) |
|
628 | 628 | relativePosition = 1.0; |
|
629 | 629 | |
|
630 | 630 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { |
|
631 | 631 | d->m_pieRelativeHorPos = relativePosition; |
|
632 | 632 | emit d->horizontalPositionChanged(); |
|
633 | 633 | } |
|
634 | 634 | } |
|
635 | 635 | |
|
636 | 636 | qreal QPieSeries::horizontalPosition() const |
|
637 | 637 | { |
|
638 | 638 | Q_D(const QPieSeries); |
|
639 | 639 | return d->m_pieRelativeHorPos; |
|
640 | 640 | } |
|
641 | 641 | |
|
642 | 642 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
643 | 643 | { |
|
644 | 644 | Q_D(QPieSeries); |
|
645 | 645 | |
|
646 | 646 | if (relativePosition < 0.0) |
|
647 | 647 | relativePosition = 0.0; |
|
648 | 648 | if (relativePosition > 1.0) |
|
649 | 649 | relativePosition = 1.0; |
|
650 | 650 | |
|
651 | 651 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { |
|
652 | 652 | d->m_pieRelativeVerPos = relativePosition; |
|
653 | 653 | emit d->verticalPositionChanged(); |
|
654 | 654 | } |
|
655 | 655 | } |
|
656 | 656 | |
|
657 | 657 | qreal QPieSeries::verticalPosition() const |
|
658 | 658 | { |
|
659 | 659 | Q_D(const QPieSeries); |
|
660 | 660 | return d->m_pieRelativeVerPos; |
|
661 | 661 | } |
|
662 | 662 | |
|
663 | 663 | void QPieSeries::setPieSize(qreal relativeSize) |
|
664 | 664 | { |
|
665 | 665 | Q_D(QPieSeries); |
|
666 | 666 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
667 | 667 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); |
|
668 | 668 | |
|
669 | 669 | } |
|
670 | 670 | |
|
671 | 671 | qreal QPieSeries::pieSize() const |
|
672 | 672 | { |
|
673 | 673 | Q_D(const QPieSeries); |
|
674 | 674 | return d->m_pieRelativeSize; |
|
675 | 675 | } |
|
676 | 676 | |
|
677 | 677 | |
|
678 | 678 | void QPieSeries::setPieStartAngle(qreal angle) |
|
679 | 679 | { |
|
680 | 680 | Q_D(QPieSeries); |
|
681 | 681 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) |
|
682 | 682 | return; |
|
683 | 683 | d->m_pieStartAngle = angle; |
|
684 | 684 | d->updateDerivativeData(); |
|
685 | 685 | emit d->pieStartAngleChanged(); |
|
686 | 686 | } |
|
687 | 687 | |
|
688 | 688 | qreal QPieSeries::pieStartAngle() const |
|
689 | 689 | { |
|
690 | 690 | Q_D(const QPieSeries); |
|
691 | 691 | return d->m_pieStartAngle; |
|
692 | 692 | } |
|
693 | 693 | |
|
694 | 694 | /*! |
|
695 | 695 | Sets the end angle of the pie. |
|
696 | 696 | |
|
697 | 697 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
698 | 698 | |
|
699 | 699 | \a angle must be greater than start angle. |
|
700 | 700 | |
|
701 | 701 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
702 | 702 | */ |
|
703 | 703 | void QPieSeries::setPieEndAngle(qreal angle) |
|
704 | 704 | { |
|
705 | 705 | Q_D(QPieSeries); |
|
706 | 706 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) |
|
707 | 707 | return; |
|
708 | 708 | d->m_pieEndAngle = angle; |
|
709 | 709 | d->updateDerivativeData(); |
|
710 | 710 | emit d->pieEndAngleChanged(); |
|
711 | 711 | } |
|
712 | 712 | |
|
713 | 713 | /*! |
|
714 | 714 | Returns the end angle of the pie. |
|
715 | 715 | |
|
716 | 716 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
717 | 717 | |
|
718 | 718 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
719 | 719 | */ |
|
720 | 720 | qreal QPieSeries::pieEndAngle() const |
|
721 | 721 | { |
|
722 | 722 | Q_D(const QPieSeries); |
|
723 | 723 | return d->m_pieEndAngle; |
|
724 | 724 | } |
|
725 | 725 | |
|
726 | 726 | /*! |
|
727 | 727 | Sets the all the slice labels \a visible or invisible. |
|
728 | 728 | |
|
729 | 729 | Note that this affects only the current slices in the series. |
|
730 | 730 | If user adds a new slice the default label visibility is false. |
|
731 | 731 | |
|
732 | 732 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
733 | 733 | */ |
|
734 | 734 | void QPieSeries::setLabelsVisible(bool visible) |
|
735 | 735 | { |
|
736 | 736 | Q_D(QPieSeries); |
|
737 | 737 | foreach (QPieSlice *s, d->m_slices) |
|
738 | 738 | s->setLabelVisible(visible); |
|
739 | 739 | } |
|
740 | 740 | |
|
741 | 741 | /*! |
|
742 | 742 | Sets the all the slice labels \a position |
|
743 | 743 | |
|
744 | 744 | Note that this affects only the current slices in the series. |
|
745 | 745 | If user adds a new slice the default label position is LabelOutside |
|
746 | 746 | |
|
747 | 747 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
748 | 748 | */ |
|
749 | 749 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
750 | 750 | { |
|
751 | 751 | Q_D(QPieSeries); |
|
752 | 752 | foreach (QPieSlice *s, d->m_slices) |
|
753 | 753 | s->setLabelPosition(position); |
|
754 | 754 | } |
|
755 | 755 | |
|
756 | 756 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
757 | 757 | |
|
758 | 758 | |
|
759 | 759 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
760 | 760 | QAbstractSeriesPrivate(parent), |
|
761 | 761 | m_pieRelativeHorPos(0.5), |
|
762 | 762 | m_pieRelativeVerPos(0.5), |
|
763 | 763 | m_pieRelativeSize(0.7), |
|
764 | 764 | m_pieStartAngle(0), |
|
765 | 765 | m_pieEndAngle(360), |
|
766 | 766 | m_sum(0), |
|
767 | 767 | m_holeRelativeSize(0.0) |
|
768 | 768 | { |
|
769 | 769 | } |
|
770 | 770 | |
|
771 | 771 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
772 | 772 | { |
|
773 | 773 | } |
|
774 | 774 | |
|
775 | 775 | void QPieSeriesPrivate::updateDerivativeData() |
|
776 | 776 | { |
|
777 | 777 | // calculate sum of all slices |
|
778 | 778 | qreal sum = 0; |
|
779 | 779 | foreach (QPieSlice *s, m_slices) |
|
780 | 780 | sum += s->value(); |
|
781 | 781 | |
|
782 | 782 | if (!qFuzzyCompare(m_sum, sum)) { |
|
783 | 783 | m_sum = sum; |
|
784 | 784 | emit q_func()->sumChanged(); |
|
785 | 785 | } |
|
786 | 786 | |
|
787 | 787 | // nothing to show.. |
|
788 | 788 | if (qFuzzyCompare(m_sum, 0)) |
|
789 | 789 | return; |
|
790 | 790 | |
|
791 | 791 | // update slice attributes |
|
792 | 792 | qreal sliceAngle = m_pieStartAngle; |
|
793 | 793 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
794 | 794 | QVector<QPieSlice *> changed; |
|
795 | 795 | foreach (QPieSlice *s, m_slices) { |
|
796 | 796 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
797 | 797 | d->setPercentage(s->value() / m_sum); |
|
798 | 798 | d->setStartAngle(sliceAngle); |
|
799 | 799 | d->setAngleSpan(pieSpan * s->percentage()); |
|
800 | 800 | sliceAngle += s->angleSpan(); |
|
801 | 801 | } |
|
802 | 802 | |
|
803 | 803 | |
|
804 | 804 | emit calculatedDataChanged(); |
|
805 | 805 | } |
|
806 | 806 | |
|
807 | 807 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
808 | 808 | { |
|
809 | 809 | bool changed = false; |
|
810 | 810 | |
|
811 | 811 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { |
|
812 | 812 | m_holeRelativeSize = innerSize; |
|
813 | 813 | changed = true; |
|
814 | 814 | } |
|
815 | 815 | |
|
816 | 816 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { |
|
817 | 817 | m_pieRelativeSize = outerSize; |
|
818 | 818 | changed = true; |
|
819 | 819 | } |
|
820 | 820 | |
|
821 | 821 | if (changed) |
|
822 | 822 | emit pieSizeChanged(); |
|
823 | 823 | } |
|
824 | 824 | |
|
825 | 825 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
826 | 826 | { |
|
827 | 827 | return series->d_func(); |
|
828 | 828 | } |
|
829 | 829 | |
|
830 | 830 | void QPieSeriesPrivate::sliceValueChanged() |
|
831 | 831 | { |
|
832 | 832 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
833 | 833 | updateDerivativeData(); |
|
834 | 834 | } |
|
835 | 835 | |
|
836 | 836 | void QPieSeriesPrivate::sliceClicked() |
|
837 | 837 | { |
|
838 | 838 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
839 | 839 | Q_ASSERT(m_slices.contains(slice)); |
|
840 | 840 | Q_Q(QPieSeries); |
|
841 | 841 | emit q->clicked(slice); |
|
842 | 842 | } |
|
843 | 843 | |
|
844 | 844 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
845 | 845 | { |
|
846 | 846 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
847 | 847 | Q_ASSERT(m_slices.contains(slice)); |
|
848 | 848 | Q_Q(QPieSeries); |
|
849 | 849 | emit q->hovered(slice, state); |
|
850 | 850 | } |
|
851 | 851 | |
|
852 | 852 | void QPieSeriesPrivate::initializeDomain() |
|
853 | 853 | { |
|
854 | 854 | // does not apply to pie |
|
855 | 855 | } |
|
856 | 856 | |
|
857 | 857 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
858 | 858 | { |
|
859 | 859 | Q_Q(QPieSeries); |
|
860 | 860 | PieChartItem *pie = new PieChartItem(q,parent); |
|
861 | 861 | m_item.reset(pie); |
|
862 | 862 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
863 | 863 | } |
|
864 | 864 | |
|
865 | 865 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
866 | 866 | { |
|
867 | 867 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); |
|
868 | 868 | Q_ASSERT(item); |
|
869 | 869 | if (item->animation()) |
|
870 | 870 | item->animation()->stopAndDestroyLater(); |
|
871 | 871 | |
|
872 | 872 | if (options.testFlag(QChart::SeriesAnimations)) |
|
873 | 873 | item->setAnimation(new PieAnimation(item)); |
|
874 | 874 | else |
|
875 | 875 | item->setAnimation(0); |
|
876 | 876 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
877 | 877 | } |
|
878 | 878 | |
|
879 | 879 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
880 | 880 | { |
|
881 | 881 | Q_Q(QPieSeries); |
|
882 | 882 | QList<QLegendMarker*> markers; |
|
883 | 883 | foreach(QPieSlice* slice, q->slices()) { |
|
884 | 884 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); |
|
885 | 885 | markers << marker; |
|
886 | 886 | } |
|
887 | 887 | return markers; |
|
888 | 888 | } |
|
889 | 889 | |
|
890 | 890 | void QPieSeriesPrivate::initializeAxes() |
|
891 | 891 | { |
|
892 | 892 | |
|
893 | 893 | } |
|
894 | 894 | |
|
895 | 895 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
896 | 896 | { |
|
897 | 897 | Q_UNUSED(orientation); |
|
898 | 898 | return QAbstractAxis::AxisTypeNoAxis; |
|
899 | 899 | } |
|
900 | 900 | |
|
901 | 901 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
902 | 902 | { |
|
903 | 903 | Q_UNUSED(orientation); |
|
904 | 904 | return 0; |
|
905 | 905 | } |
|
906 | 906 | |
|
907 | 907 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
908 | 908 | { |
|
909 | 909 | //Q_Q(QPieSeries); |
|
910 | 910 | //const QList<QColor>& colors = theme->seriesColors(); |
|
911 | 911 | const QList<QGradient>& gradients = theme->seriesGradients(); |
|
912 | 912 | |
|
913 | 913 | for (int i(0); i < m_slices.count(); i++) { |
|
914 | 914 | |
|
915 | 915 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); |
|
916 | 916 | |
|
917 | 917 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
918 | 918 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); |
|
919 | 919 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); |
|
920 | 920 | |
|
921 | 921 | QPieSlice *s = m_slices.at(i); |
|
922 | 922 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
923 | 923 | |
|
924 | 924 | if (forced || d->m_data.m_slicePen.isThemed()) |
|
925 | 925 | d->setPen(penColor, true); |
|
926 | 926 | |
|
927 | 927 | if (forced || d->m_data.m_sliceBrush.isThemed()) |
|
928 | 928 | d->setBrush(brushColor, true); |
|
929 | 929 | |
|
930 | 930 | if (forced || d->m_data.m_labelBrush.isThemed()) |
|
931 | 931 | d->setLabelBrush(theme->labelBrush().color(), true); |
|
932 | 932 | |
|
933 | 933 | if (forced || d->m_data.m_labelFont.isThemed()) |
|
934 | 934 | d->setLabelFont(theme->labelFont(), true); |
|
935 | 935 | } |
|
936 | 936 | } |
|
937 | 937 | |
|
938 | 938 | |
|
939 | 939 | #include "moc_qpieseries.cpp" |
|
940 | 940 | #include "moc_qpieseries_p.cpp" |
|
941 | 941 | |
|
942 | 942 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,784 +1,784 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qpieslice.h" |
|
22 | 22 | #include "qpieslice_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QPieSlice |
|
28 | 28 | \inmodule Qt Charts |
|
29 | 29 | \brief Defines a slice in pie series. |
|
30 | 30 | |
|
31 | 31 | This object defines the properties of a single slice in a QPieSeries. |
|
32 | 32 | |
|
33 | 33 | In addition to the obvious value and label properties the user can also control |
|
34 | 34 | the visual appearance of a slice. By modifying the visual appearance also means that |
|
35 | 35 | the user is overriding the default appearance set by the theme. |
|
36 | 36 | |
|
37 | 37 | Note that if the user has customized slices and theme is changed all customizations will be lost. |
|
38 | 38 | |
|
39 | 39 | To enable user interaction with the pie some basic signals are provided about clicking and hovering. |
|
40 | 40 | */ |
|
41 | 41 | |
|
42 | 42 | #ifdef QDOC_QT5 |
|
43 | 43 | /*! |
|
44 | 44 | \qmltype PieSlice |
|
45 | 45 | \instantiates QPieSlice |
|
46 | 46 | \inqmlmodule QtCommercial.Chart |
|
47 | 47 | |
|
48 |
\include |
|
|
48 | \include doc/src/pieslice.qdocinc | |
|
49 | 49 | */ |
|
50 | 50 | #else |
|
51 | 51 | /*! |
|
52 | 52 | \qmlclass PieSlice QPieSlice |
|
53 | 53 | |
|
54 | 54 | \include ../doc/src/pieslice.qdocinc |
|
55 | 55 | */ |
|
56 | 56 | #endif |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \enum QPieSlice::LabelPosition |
|
60 | 60 | |
|
61 | 61 | This enum describes the position of the slice label. |
|
62 | 62 | |
|
63 | 63 | \value LabelOutside Label is outside the slice with an arm. |
|
64 | 64 | \value LabelInsideHorizontal Label is centered inside the slice and laid out horizontally. |
|
65 | 65 | \value LabelInsideTangential Label is centered inside the slice and rotated to be parallel to the tangential of the slice's arc. |
|
66 | 66 | \value LabelInsideNormal Label is centered inside the slice rotated to be parallel to the normal of the slice's arc. |
|
67 | 67 | */ |
|
68 | 68 | |
|
69 | 69 | /*! |
|
70 | 70 | \property QPieSlice::label |
|
71 | 71 | Label of the slice. |
|
72 | 72 | \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor |
|
73 | 73 | */ |
|
74 | 74 | /*! |
|
75 | 75 | \qmlproperty string PieSlice::label |
|
76 | 76 | Label (text) of the slice. |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \fn void QPieSlice::labelChanged() |
|
81 | 81 | This signal emitted when the slice label has been changed. |
|
82 | 82 | \sa label |
|
83 | 83 | */ |
|
84 | 84 | /*! |
|
85 | 85 | \qmlsignal PieSlice::onLabelChanged() |
|
86 | 86 | This signal emitted when the slice label has been changed. |
|
87 | 87 | \sa label |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \property QPieSlice::value |
|
92 | 92 | Value of the slice. |
|
93 | 93 | Note that if users sets a negative value it is converted to a positive value. |
|
94 | 94 | \sa percentage(), QPieSeries::sum() |
|
95 | 95 | */ |
|
96 | 96 | /*! |
|
97 | 97 | \qmlproperty real PieSlice::value |
|
98 | 98 | Value of the slice. Note that if users sets a negative value it is converted to a positive value. |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \fn void QPieSlice::valueChanged() |
|
103 | 103 | This signal is emitted when the slice value changes. |
|
104 | 104 | \sa value |
|
105 | 105 | */ |
|
106 | 106 | /*! |
|
107 | 107 | \qmlsignal PieSlice::onValueChanged() |
|
108 | 108 | This signal is emitted when the slice value changes. |
|
109 | 109 | \sa value |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \property QPieSlice::labelVisible |
|
114 | 114 | Defines the visibility of slice label. By default the label is not visible. |
|
115 | 115 | \sa label, labelBrush, labelFont, labelArmLengthFactor |
|
116 | 116 | */ |
|
117 | 117 | /*! |
|
118 | 118 | \qmlproperty bool PieSlice::labelVisible |
|
119 | 119 | Defines the visibility of slice label. By default the label is not visible. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \fn void QPieSlice::labelVisibleChanged() |
|
124 | 124 | This signal emitted when visibility of the slice label has changed. |
|
125 | 125 | \sa labelVisible |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlsignal PieSlice::onLabelVisibleChanged() |
|
129 | 129 | This signal emitted when visibility of the slice label has changed. |
|
130 | 130 | \sa labelVisible |
|
131 | 131 | */ |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \property QPieSlice::exploded |
|
135 | 135 | If set to true the slice is "exploded" away from the pie. |
|
136 | 136 | \sa explodeDistanceFactor |
|
137 | 137 | */ |
|
138 | 138 | /*! |
|
139 | 139 | \qmlproperty bool PieSlice::exploded |
|
140 | 140 | If set to true the slice is "exploded" away from the pie. |
|
141 | 141 | \sa explodeDistanceFactor |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \property QPieSlice::pen |
|
146 | 146 | Pen used to draw the slice border. |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QPieSlice::penChanged() |
|
151 | 151 | This signal is emitted when the pen of the slice has changed. |
|
152 | 152 | \sa pen |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \property QPieSlice::borderColor |
|
157 | 157 | Color used to draw the slice border. |
|
158 | 158 | This is a convenience property for modifying the slice pen. |
|
159 | 159 | \sa pen, borderWidth |
|
160 | 160 | */ |
|
161 | 161 | /*! |
|
162 | 162 | \qmlproperty color PieSlice::borderColor |
|
163 | 163 | Color used to draw the slice border (pen color). |
|
164 | 164 | \sa borderWidth |
|
165 | 165 | */ |
|
166 | 166 | |
|
167 | 167 | /*! |
|
168 | 168 | \fn void QPieSlice::borderColorChanged() |
|
169 | 169 | This signal is emitted when slice border color changes. |
|
170 | 170 | \sa pen, borderColor |
|
171 | 171 | */ |
|
172 | 172 | /*! |
|
173 | 173 | \qmlsignal PieSlice::onBorderColorChanged() |
|
174 | 174 | This signal is emitted when slice border color changes. |
|
175 | 175 | \sa borderColor |
|
176 | 176 | */ |
|
177 | 177 | |
|
178 | 178 | /*! |
|
179 | 179 | \property QPieSlice::borderWidth |
|
180 | 180 | Width of the slice border. |
|
181 | 181 | This is a convenience property for modifying the slice pen. |
|
182 | 182 | \sa pen, borderColor |
|
183 | 183 | */ |
|
184 | 184 | /*! |
|
185 | 185 | \qmlproperty int PieSlice::borderWidth |
|
186 | 186 | Width of the slice border. |
|
187 | 187 | This is a convenience property for modifying the slice pen. |
|
188 | 188 | \sa borderColor |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | \fn void QPieSlice::borderWidthChanged() |
|
193 | 193 | This signal is emitted when slice border width changes. |
|
194 | 194 | \sa pen, borderWidth |
|
195 | 195 | */ |
|
196 | 196 | /*! |
|
197 | 197 | \qmlsignal PieSlice::onBorderWidthChanged() |
|
198 | 198 | This signal is emitted when slice border width changes. |
|
199 | 199 | \sa borderWidth |
|
200 | 200 | */ |
|
201 | 201 | |
|
202 | 202 | /*! |
|
203 | 203 | \property QPieSlice::brush |
|
204 | 204 | Brush used to draw the slice. |
|
205 | 205 | */ |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | \fn void QPieSlice::brushChanged() |
|
209 | 209 | This signal is emitted when the brush of the slice has changed. |
|
210 | 210 | \sa brush |
|
211 | 211 | */ |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | \property QPieSlice::color |
|
215 | 215 | Fill (brush) color of the slice. |
|
216 | 216 | This is a convenience property for modifying the slice brush. |
|
217 | 217 | \sa brush |
|
218 | 218 | */ |
|
219 | 219 | /*! |
|
220 | 220 | \qmlproperty color PieSlice::color |
|
221 | 221 | Fill (brush) color of the slice. |
|
222 | 222 | */ |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | \fn void QPieSlice::colorChanged() |
|
226 | 226 | This signal is emitted when slice color changes. |
|
227 | 227 | \sa brush |
|
228 | 228 | */ |
|
229 | 229 | /*! |
|
230 | 230 | \qmlsignal PieSlice::onColorChanged() |
|
231 | 231 | This signal is emitted when slice color changes. |
|
232 | 232 | */ |
|
233 | 233 | |
|
234 | 234 | /*! |
|
235 | 235 | \property QPieSlice::labelBrush |
|
236 | 236 | Brush used to draw label and label arm of the slice. |
|
237 | 237 | \sa label, labelVisible, labelFont, labelArmLengthFactor |
|
238 | 238 | */ |
|
239 | 239 | |
|
240 | 240 | /*! |
|
241 | 241 | \fn void QPieSlice::labelBrushChanged() |
|
242 | 242 | This signal is emitted when the label brush of the slice has changed. |
|
243 | 243 | \sa labelBrush |
|
244 | 244 | */ |
|
245 | 245 | |
|
246 | 246 | /*! |
|
247 | 247 | \property QPieSlice::labelColor |
|
248 | 248 | Color used to draw the slice label. |
|
249 | 249 | This is a convenience property for modifying the slice label brush. |
|
250 | 250 | \sa labelBrush |
|
251 | 251 | */ |
|
252 | 252 | /*! |
|
253 | 253 | \qmlproperty color PieSlice::labelColor |
|
254 | 254 | Color used to draw the slice label. |
|
255 | 255 | */ |
|
256 | 256 | |
|
257 | 257 | /*! |
|
258 | 258 | \fn void QPieSlice::labelColorChanged() |
|
259 | 259 | This signal is emitted when slice label color changes. |
|
260 | 260 | \sa labelColor |
|
261 | 261 | */ |
|
262 | 262 | /*! |
|
263 | 263 | \qmlsignal PieSlice::onLabelColorChanged() |
|
264 | 264 | This signal is emitted when slice label color changes. |
|
265 | 265 | \sa labelColor |
|
266 | 266 | */ |
|
267 | 267 | |
|
268 | 268 | /*! |
|
269 | 269 | \property QPieSlice::labelFont |
|
270 | 270 | Font used for drawing label text. |
|
271 | 271 | \sa label, labelVisible, labelArmLengthFactor |
|
272 | 272 | */ |
|
273 | 273 | |
|
274 | 274 | /*! |
|
275 | 275 | \fn void QPieSlice::labelFontChanged() |
|
276 | 276 | This signal is emitted when the label font of the slice has changed. |
|
277 | 277 | \sa labelFont |
|
278 | 278 | */ |
|
279 | 279 | |
|
280 | 280 | /*! |
|
281 | 281 | \qmlproperty Font PieSlice::labelFont |
|
282 | 282 | |
|
283 | 283 | Defines the font used for slice label. |
|
284 | 284 | |
|
285 | 285 | See the Qt documentation for more details of Font. |
|
286 | 286 | |
|
287 | 287 | \sa labelVisible, labelPosition |
|
288 | 288 | */ |
|
289 | 289 | |
|
290 | 290 | /*! |
|
291 | 291 | \property QPieSlice::labelPosition |
|
292 | 292 | Position of the slice label. |
|
293 | 293 | \sa label, labelVisible |
|
294 | 294 | */ |
|
295 | 295 | /*! |
|
296 | 296 | \qmlproperty LabelPosition PieSlice::labelPosition |
|
297 | 297 | Position of the slice label. One of PieSlice.LabelOutside, PieSlice.LabelInsideHorizontal, |
|
298 | 298 | PieSlice.LabelInsideTangential or PieSlice.LabelInsideNormal. By default the position is |
|
299 | 299 | PieSlice.LabelOutside. |
|
300 | 300 | \sa labelVisible |
|
301 | 301 | */ |
|
302 | 302 | |
|
303 | 303 | /*! |
|
304 | 304 | \property QPieSlice::labelArmLengthFactor |
|
305 | 305 | Defines the length of the label arm. |
|
306 | 306 | The factor is relative to pie radius. For example: |
|
307 | 307 | 1.0 means the length is the same as the radius. |
|
308 | 308 | 0.5 means the length is half of the radius. |
|
309 | 309 | By default the arm length is 0.15 |
|
310 | 310 | \sa label, labelVisible, labelBrush, labelFont |
|
311 | 311 | */ |
|
312 | 312 | /*! |
|
313 | 313 | \qmlproperty real PieSlice::labelArmLengthFactor |
|
314 | 314 | Defines the length of the label arm. |
|
315 | 315 | The factor is relative to pie radius. For example: |
|
316 | 316 | 1.0 means the length is the same as the radius. |
|
317 | 317 | 0.5 means the length is half of the radius. |
|
318 | 318 | By default the arm length is 0.15 |
|
319 | 319 | \sa labelVisible |
|
320 | 320 | */ |
|
321 | 321 | |
|
322 | 322 | /*! |
|
323 | 323 | \property QPieSlice::explodeDistanceFactor |
|
324 | 324 | When the slice is exploded this factor defines how far the slice is exploded away from the pie. |
|
325 | 325 | The factor is relative to pie radius. For example: |
|
326 | 326 | 1.0 means the distance is the same as the radius. |
|
327 | 327 | 0.5 means the distance is half of the radius. |
|
328 | 328 | By default the distance is is 0.15 |
|
329 | 329 | \sa exploded |
|
330 | 330 | */ |
|
331 | 331 | /*! |
|
332 | 332 | \qmlproperty real PieSlice::explodeDistanceFactor |
|
333 | 333 | When the slice is exploded this factor defines how far the slice is exploded away from the pie. |
|
334 | 334 | The factor is relative to pie radius. For example: |
|
335 | 335 | 1.0 means the distance is the same as the radius. |
|
336 | 336 | 0.5 means the distance is half of the radius. |
|
337 | 337 | By default the distance is is 0.15 |
|
338 | 338 | \sa exploded |
|
339 | 339 | */ |
|
340 | 340 | |
|
341 | 341 | /*! |
|
342 | 342 | \property QPieSlice::percentage |
|
343 | 343 | Percentage of the slice compared to the sum of all slices in the series. |
|
344 | 344 | The actual value ranges from 0.0 to 1.0. |
|
345 | 345 | Updated automatically once the slice is added to the series. |
|
346 | 346 | \sa value, QPieSeries::sum |
|
347 | 347 | */ |
|
348 | 348 | /*! |
|
349 | 349 | \qmlproperty real PieSlice::percentage |
|
350 | 350 | Percentage of the slice compared to the sum of all slices in the series. |
|
351 | 351 | The actual value ranges from 0.0 to 1.0. |
|
352 | 352 | Updated automatically once the slice is added to the series. |
|
353 | 353 | */ |
|
354 | 354 | |
|
355 | 355 | /*! |
|
356 | 356 | \fn void QPieSlice::percentageChanged() |
|
357 | 357 | This signal is emitted when the percentage of the slice has changed. |
|
358 | 358 | \sa percentage |
|
359 | 359 | */ |
|
360 | 360 | /*! |
|
361 | 361 | \qmlsignal void PieSlice::onPercentageChanged() |
|
362 | 362 | This signal is emitted when the percentage of the slice has changed. |
|
363 | 363 | \sa percentage |
|
364 | 364 | */ |
|
365 | 365 | |
|
366 | 366 | /*! |
|
367 | 367 | \property QPieSlice::startAngle |
|
368 | 368 | Defines the starting angle of this slice in the series it belongs to. |
|
369 | 369 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
370 | 370 | Updated automatically once the slice is added to the series. |
|
371 | 371 | */ |
|
372 | 372 | /*! |
|
373 | 373 | \qmlproperty real PieSlice::startAngle |
|
374 | 374 | Defines the starting angle of this slice in the series it belongs to. |
|
375 | 375 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
376 | 376 | Updated automatically once the slice is added to the series. |
|
377 | 377 | */ |
|
378 | 378 | |
|
379 | 379 | /*! |
|
380 | 380 | \fn void QPieSlice::startAngleChanged() |
|
381 | 381 | This signal is emitted when the starting angle f the slice has changed. |
|
382 | 382 | \sa startAngle |
|
383 | 383 | */ |
|
384 | 384 | /*! |
|
385 | 385 | \qmlsignal PieSlice::onStartAngleChanged() |
|
386 | 386 | This signal is emitted when the starting angle f the slice has changed. |
|
387 | 387 | \sa startAngle |
|
388 | 388 | */ |
|
389 | 389 | |
|
390 | 390 | /*! |
|
391 | 391 | \property QPieSlice::angleSpan |
|
392 | 392 | Span of the slice in degrees. |
|
393 | 393 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
394 | 394 | Updated automatically once the slice is added to the series. |
|
395 | 395 | */ |
|
396 | 396 | /*! |
|
397 | 397 | \qmlproperty real PieSlice::angleSpan |
|
398 | 398 | Span of the slice in degrees. |
|
399 | 399 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
400 | 400 | Updated automatically once the slice is added to the series. |
|
401 | 401 | */ |
|
402 | 402 | |
|
403 | 403 | /*! |
|
404 | 404 | \fn void QPieSlice::angleSpanChanged() |
|
405 | 405 | This signal is emitted when the angle span of the slice has changed. |
|
406 | 406 | \sa angleSpan |
|
407 | 407 | */ |
|
408 | 408 | /*! |
|
409 | 409 | \qmlsignal PieSlice::onAngleSpanChanged() |
|
410 | 410 | This signal is emitted when the angle span of the slice has changed. |
|
411 | 411 | \sa angleSpan |
|
412 | 412 | */ |
|
413 | 413 | |
|
414 | 414 | /*! |
|
415 | 415 | \fn void QPieSlice::clicked() |
|
416 | 416 | This signal is emitted when user has clicked the slice. |
|
417 | 417 | \sa QPieSeries::clicked() |
|
418 | 418 | */ |
|
419 | 419 | /*! |
|
420 | 420 | \qmlsignal PieSlice::onClicked() |
|
421 | 421 | This signal is emitted when user has clicked the slice. |
|
422 | 422 | */ |
|
423 | 423 | |
|
424 | 424 | /*! |
|
425 | 425 | \fn void QPieSlice::hovered(bool state) |
|
426 | 426 | This signal is emitted when user has hovered over or away from the slice. |
|
427 | 427 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
428 | 428 | \sa QPieSeries::hovered() |
|
429 | 429 | */ |
|
430 | 430 | /*! |
|
431 | 431 | \qmlsignal PieSlice::onHovered(bool state) |
|
432 | 432 | This signal is emitted when user has hovered over or away from the slice. |
|
433 | 433 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
434 | 434 | */ |
|
435 | 435 | |
|
436 | 436 | /*! |
|
437 | 437 | Constructs an empty slice with a \a parent. |
|
438 | 438 | \sa QPieSeries::append(), QPieSeries::insert() |
|
439 | 439 | */ |
|
440 | 440 | QPieSlice::QPieSlice(QObject *parent) |
|
441 | 441 | : QObject(parent), |
|
442 | 442 | d_ptr(new QPieSlicePrivate(this)) |
|
443 | 443 | { |
|
444 | 444 | |
|
445 | 445 | } |
|
446 | 446 | |
|
447 | 447 | /*! |
|
448 | 448 | Constructs an empty slice with given \a value, \a label and a \a parent. |
|
449 | 449 | \sa QPieSeries::append(), QPieSeries::insert() |
|
450 | 450 | */ |
|
451 | 451 | QPieSlice::QPieSlice(QString label, qreal value, QObject *parent) |
|
452 | 452 | : QObject(parent), |
|
453 | 453 | d_ptr(new QPieSlicePrivate(this)) |
|
454 | 454 | { |
|
455 | 455 | setValue(value); |
|
456 | 456 | setLabel(label); |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | /*! |
|
460 | 460 | Destroys the slice. |
|
461 | 461 | User should not delete the slice if it has been added to the series. |
|
462 | 462 | */ |
|
463 | 463 | QPieSlice::~QPieSlice() |
|
464 | 464 | { |
|
465 | 465 | |
|
466 | 466 | } |
|
467 | 467 | |
|
468 | 468 | void QPieSlice::setLabel(QString label) |
|
469 | 469 | { |
|
470 | 470 | if (d_ptr->m_data.m_labelText != label) { |
|
471 | 471 | d_ptr->m_data.m_labelText = label; |
|
472 | 472 | emit labelChanged(); |
|
473 | 473 | } |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | QString QPieSlice::label() const |
|
477 | 477 | { |
|
478 | 478 | return d_ptr->m_data.m_labelText; |
|
479 | 479 | } |
|
480 | 480 | |
|
481 | 481 | void QPieSlice::setValue(qreal value) |
|
482 | 482 | { |
|
483 | 483 | value = qAbs(value); // negative values not allowed |
|
484 | 484 | if (!qFuzzyCompare(d_ptr->m_data.m_value, value)) { |
|
485 | 485 | d_ptr->m_data.m_value = value; |
|
486 | 486 | emit valueChanged(); |
|
487 | 487 | } |
|
488 | 488 | } |
|
489 | 489 | |
|
490 | 490 | qreal QPieSlice::value() const |
|
491 | 491 | { |
|
492 | 492 | return d_ptr->m_data.m_value; |
|
493 | 493 | } |
|
494 | 494 | |
|
495 | 495 | void QPieSlice::setLabelVisible(bool visible) |
|
496 | 496 | { |
|
497 | 497 | if (d_ptr->m_data.m_isLabelVisible != visible) { |
|
498 | 498 | d_ptr->m_data.m_isLabelVisible = visible; |
|
499 | 499 | emit labelVisibleChanged(); |
|
500 | 500 | } |
|
501 | 501 | } |
|
502 | 502 | |
|
503 | 503 | bool QPieSlice::isLabelVisible() const |
|
504 | 504 | { |
|
505 | 505 | return d_ptr->m_data.m_isLabelVisible; |
|
506 | 506 | } |
|
507 | 507 | |
|
508 | 508 | void QPieSlice::setExploded(bool exploded) |
|
509 | 509 | { |
|
510 | 510 | if (d_ptr->m_data.m_isExploded != exploded) { |
|
511 | 511 | d_ptr->m_data.m_isExploded = exploded; |
|
512 | 512 | emit d_ptr->explodedChanged(); |
|
513 | 513 | } |
|
514 | 514 | } |
|
515 | 515 | |
|
516 | 516 | QPieSlice::LabelPosition QPieSlice::labelPosition() |
|
517 | 517 | { |
|
518 | 518 | return d_ptr->m_data.m_labelPosition; |
|
519 | 519 | } |
|
520 | 520 | |
|
521 | 521 | void QPieSlice::setLabelPosition(LabelPosition position) |
|
522 | 522 | { |
|
523 | 523 | if (d_ptr->m_data.m_labelPosition != position) { |
|
524 | 524 | d_ptr->m_data.m_labelPosition = position; |
|
525 | 525 | emit d_ptr->labelPositionChanged(); |
|
526 | 526 | } |
|
527 | 527 | } |
|
528 | 528 | |
|
529 | 529 | bool QPieSlice::isExploded() const |
|
530 | 530 | { |
|
531 | 531 | return d_ptr->m_data.m_isExploded; |
|
532 | 532 | } |
|
533 | 533 | |
|
534 | 534 | void QPieSlice::setPen(const QPen &pen) |
|
535 | 535 | { |
|
536 | 536 | d_ptr->setPen(pen, false); |
|
537 | 537 | } |
|
538 | 538 | |
|
539 | 539 | QPen QPieSlice::pen() const |
|
540 | 540 | { |
|
541 | 541 | return d_ptr->m_data.m_slicePen; |
|
542 | 542 | } |
|
543 | 543 | |
|
544 | 544 | QColor QPieSlice::borderColor() |
|
545 | 545 | { |
|
546 | 546 | return pen().color(); |
|
547 | 547 | } |
|
548 | 548 | |
|
549 | 549 | void QPieSlice::setBorderColor(QColor color) |
|
550 | 550 | { |
|
551 | 551 | QPen p = pen(); |
|
552 | 552 | if (color != p.color()) { |
|
553 | 553 | p.setColor(color); |
|
554 | 554 | setPen(p); |
|
555 | 555 | } |
|
556 | 556 | } |
|
557 | 557 | |
|
558 | 558 | int QPieSlice::borderWidth() |
|
559 | 559 | { |
|
560 | 560 | return pen().width(); |
|
561 | 561 | } |
|
562 | 562 | |
|
563 | 563 | void QPieSlice::setBorderWidth(int width) |
|
564 | 564 | { |
|
565 | 565 | QPen p = pen(); |
|
566 | 566 | if (width != p.width()) { |
|
567 | 567 | p.setWidth(width); |
|
568 | 568 | setPen(p); |
|
569 | 569 | } |
|
570 | 570 | } |
|
571 | 571 | |
|
572 | 572 | void QPieSlice::setBrush(const QBrush &brush) |
|
573 | 573 | { |
|
574 | 574 | d_ptr->setBrush(brush, false); |
|
575 | 575 | } |
|
576 | 576 | |
|
577 | 577 | QBrush QPieSlice::brush() const |
|
578 | 578 | { |
|
579 | 579 | return d_ptr->m_data.m_sliceBrush; |
|
580 | 580 | } |
|
581 | 581 | |
|
582 | 582 | QColor QPieSlice::color() |
|
583 | 583 | { |
|
584 | 584 | return brush().color(); |
|
585 | 585 | } |
|
586 | 586 | |
|
587 | 587 | void QPieSlice::setColor(QColor color) |
|
588 | 588 | { |
|
589 | 589 | QBrush b = brush(); |
|
590 | 590 | |
|
591 | 591 | if (b == QBrush()) |
|
592 | 592 | b.setStyle(Qt::SolidPattern); |
|
593 | 593 | b.setColor(color); |
|
594 | 594 | setBrush(b); |
|
595 | 595 | } |
|
596 | 596 | |
|
597 | 597 | void QPieSlice::setLabelBrush(const QBrush &brush) |
|
598 | 598 | { |
|
599 | 599 | d_ptr->setLabelBrush(brush, false); |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | QBrush QPieSlice::labelBrush() const |
|
603 | 603 | { |
|
604 | 604 | return d_ptr->m_data.m_labelBrush; |
|
605 | 605 | } |
|
606 | 606 | |
|
607 | 607 | QColor QPieSlice::labelColor() |
|
608 | 608 | { |
|
609 | 609 | return labelBrush().color(); |
|
610 | 610 | } |
|
611 | 611 | |
|
612 | 612 | void QPieSlice::setLabelColor(QColor color) |
|
613 | 613 | { |
|
614 | 614 | QBrush b = labelBrush(); |
|
615 | 615 | if (color != b.color()) { |
|
616 | 616 | b.setColor(color); |
|
617 | 617 | setLabelBrush(b); |
|
618 | 618 | } |
|
619 | 619 | } |
|
620 | 620 | |
|
621 | 621 | void QPieSlice::setLabelFont(const QFont &font) |
|
622 | 622 | { |
|
623 | 623 | d_ptr->setLabelFont(font, false); |
|
624 | 624 | } |
|
625 | 625 | |
|
626 | 626 | QFont QPieSlice::labelFont() const |
|
627 | 627 | { |
|
628 | 628 | return d_ptr->m_data.m_labelFont; |
|
629 | 629 | } |
|
630 | 630 | |
|
631 | 631 | void QPieSlice::setLabelArmLengthFactor(qreal factor) |
|
632 | 632 | { |
|
633 | 633 | if (!qFuzzyCompare(d_ptr->m_data.m_labelArmLengthFactor, factor)) { |
|
634 | 634 | d_ptr->m_data.m_labelArmLengthFactor = factor; |
|
635 | 635 | emit d_ptr->labelArmLengthFactorChanged(); |
|
636 | 636 | } |
|
637 | 637 | } |
|
638 | 638 | |
|
639 | 639 | qreal QPieSlice::labelArmLengthFactor() const |
|
640 | 640 | { |
|
641 | 641 | return d_ptr->m_data.m_labelArmLengthFactor; |
|
642 | 642 | } |
|
643 | 643 | |
|
644 | 644 | void QPieSlice::setExplodeDistanceFactor(qreal factor) |
|
645 | 645 | { |
|
646 | 646 | if (!qFuzzyCompare(d_ptr->m_data.m_explodeDistanceFactor, factor)) { |
|
647 | 647 | d_ptr->m_data.m_explodeDistanceFactor = factor; |
|
648 | 648 | emit d_ptr->explodeDistanceFactorChanged(); |
|
649 | 649 | } |
|
650 | 650 | } |
|
651 | 651 | |
|
652 | 652 | qreal QPieSlice::explodeDistanceFactor() const |
|
653 | 653 | { |
|
654 | 654 | return d_ptr->m_data.m_explodeDistanceFactor; |
|
655 | 655 | } |
|
656 | 656 | |
|
657 | 657 | qreal QPieSlice::percentage() const |
|
658 | 658 | { |
|
659 | 659 | return d_ptr->m_data.m_percentage; |
|
660 | 660 | } |
|
661 | 661 | |
|
662 | 662 | qreal QPieSlice::startAngle() const |
|
663 | 663 | { |
|
664 | 664 | return d_ptr->m_data.m_startAngle; |
|
665 | 665 | } |
|
666 | 666 | |
|
667 | 667 | qreal QPieSlice::angleSpan() const |
|
668 | 668 | { |
|
669 | 669 | return d_ptr->m_data.m_angleSpan; |
|
670 | 670 | } |
|
671 | 671 | |
|
672 | 672 | /*! |
|
673 | 673 | Returns the series that this slice belongs to. |
|
674 | 674 | |
|
675 | 675 | \sa QPieSeries::append() |
|
676 | 676 | */ |
|
677 | 677 | QPieSeries *QPieSlice::series() const |
|
678 | 678 | { |
|
679 | 679 | return d_ptr->m_series; |
|
680 | 680 | } |
|
681 | 681 | |
|
682 | 682 | QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent) |
|
683 | 683 | : QObject(parent), |
|
684 | 684 | q_ptr(parent), |
|
685 | 685 | m_series(0) |
|
686 | 686 | { |
|
687 | 687 | |
|
688 | 688 | } |
|
689 | 689 | |
|
690 | 690 | QPieSlicePrivate::~QPieSlicePrivate() |
|
691 | 691 | { |
|
692 | 692 | |
|
693 | 693 | } |
|
694 | 694 | |
|
695 | 695 | QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice) |
|
696 | 696 | { |
|
697 | 697 | return slice->d_func(); |
|
698 | 698 | } |
|
699 | 699 | |
|
700 | 700 | void QPieSlicePrivate::setPen(const QPen &pen, bool themed) |
|
701 | 701 | { |
|
702 | 702 | if (m_data.m_slicePen != pen) { |
|
703 | 703 | |
|
704 | 704 | QPen oldPen = m_data.m_slicePen; |
|
705 | 705 | |
|
706 | 706 | m_data.m_slicePen = pen; |
|
707 | 707 | m_data.m_slicePen.setThemed(themed); |
|
708 | 708 | |
|
709 | 709 | emit q_ptr->penChanged(); |
|
710 | 710 | if (oldPen.color() != pen.color()) |
|
711 | 711 | emit q_ptr->borderColorChanged(); |
|
712 | 712 | if (oldPen.width() != pen.width()) |
|
713 | 713 | emit q_ptr->borderWidthChanged(); |
|
714 | 714 | } |
|
715 | 715 | } |
|
716 | 716 | |
|
717 | 717 | void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed) |
|
718 | 718 | { |
|
719 | 719 | if (m_data.m_sliceBrush != brush) { |
|
720 | 720 | |
|
721 | 721 | QBrush oldBrush = m_data.m_sliceBrush; |
|
722 | 722 | |
|
723 | 723 | m_data.m_sliceBrush = brush; |
|
724 | 724 | m_data.m_sliceBrush.setThemed(themed); |
|
725 | 725 | |
|
726 | 726 | emit q_ptr->brushChanged(); |
|
727 | 727 | if (oldBrush.color() != brush.color()) |
|
728 | 728 | emit q_ptr->colorChanged(); |
|
729 | 729 | } |
|
730 | 730 | } |
|
731 | 731 | |
|
732 | 732 | void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed) |
|
733 | 733 | { |
|
734 | 734 | if (m_data.m_labelBrush != brush) { |
|
735 | 735 | |
|
736 | 736 | QBrush oldBrush = m_data.m_labelBrush; |
|
737 | 737 | |
|
738 | 738 | m_data.m_labelBrush = brush; |
|
739 | 739 | m_data.m_labelBrush.setThemed(themed); |
|
740 | 740 | |
|
741 | 741 | emit q_ptr->labelBrushChanged(); |
|
742 | 742 | if (oldBrush.color() != brush.color()) |
|
743 | 743 | emit q_ptr->labelColorChanged(); |
|
744 | 744 | } |
|
745 | 745 | } |
|
746 | 746 | |
|
747 | 747 | void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed) |
|
748 | 748 | { |
|
749 | 749 | if (m_data.m_labelFont != font) { |
|
750 | 750 | m_data.m_labelFont = font; |
|
751 | 751 | m_data.m_labelFont.setThemed(themed); |
|
752 | 752 | emit q_ptr->labelFontChanged(); |
|
753 | 753 | } |
|
754 | 754 | } |
|
755 | 755 | |
|
756 | 756 | void QPieSlicePrivate::setPercentage(qreal percentage) |
|
757 | 757 | { |
|
758 | 758 | if (!qFuzzyCompare(m_data.m_percentage, percentage)) { |
|
759 | 759 | m_data.m_percentage = percentage; |
|
760 | 760 | emit q_ptr->percentageChanged(); |
|
761 | 761 | } |
|
762 | 762 | } |
|
763 | 763 | |
|
764 | 764 | void QPieSlicePrivate::setStartAngle(qreal angle) |
|
765 | 765 | { |
|
766 | 766 | if (!qFuzzyCompare(m_data.m_startAngle, angle)) { |
|
767 | 767 | m_data.m_startAngle = angle; |
|
768 | 768 | emit q_ptr->startAngleChanged(); |
|
769 | 769 | } |
|
770 | 770 | } |
|
771 | 771 | |
|
772 | 772 | void QPieSlicePrivate::setAngleSpan(qreal span) |
|
773 | 773 | { |
|
774 | 774 | if (!qFuzzyCompare(m_data.m_angleSpan, span)) { |
|
775 | 775 | m_data.m_angleSpan = span; |
|
776 | 776 | emit q_ptr->angleSpanChanged(); |
|
777 | 777 | } |
|
778 | 778 | } |
|
779 | 779 | |
|
780 | 780 | QTCOMMERCIALCHART_END_NAMESPACE |
|
781 | 781 | |
|
782 | 782 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
783 | 783 | #include "moc_qpieslice.cpp" |
|
784 | 784 | #include "moc_qpieslice_p.cpp" |
@@ -1,260 +1,260 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qvpiemodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QVPieModelMapper |
|
27 | 27 | \inmodule Qt Charts |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns. |
|
32 | 32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync. |
|
33 | 33 | \note Used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | 34 | */ |
|
35 | 35 | #ifdef QDOC_QT5 |
|
36 | 36 | /*! |
|
37 | 37 | \qmltype VPieModelMapper |
|
38 | 38 | \instantiates QVPieModelMapper |
|
39 | 39 | \inqmlmodule QtCommercial.Chart |
|
40 | 40 | |
|
41 |
\include |
|
|
41 | \include doc/src/vpiemodelmapper.qdocinc | |
|
42 | 42 | */ |
|
43 | 43 | #else |
|
44 | 44 | /*! |
|
45 | 45 | \qmlclass VPieModelMapper QVPieModelMapper |
|
46 | 46 | |
|
47 | 47 | \include ../doc/src/vpiemodelmapper.qdocinc |
|
48 | 48 | */ |
|
49 | 49 | #endif |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | \property QVPieModelMapper::series |
|
53 | 53 | \brief Defines the QPieSeries object that is used by the mapper. |
|
54 | 54 | All the data in the series is discarded when it is set to the mapper. |
|
55 | 55 | When new series is specified the old series is disconnected (it preserves its data) |
|
56 | 56 | */ |
|
57 | 57 | /*! |
|
58 | 58 | \qmlproperty PieSeries VPieModelMapper::series |
|
59 | 59 | Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a |
|
60 | 60 | PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper. |
|
61 | 61 | When new series is specified the old series is disconnected (it preserves its data). |
|
62 | 62 | */ |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | \property QVPieModelMapper::model |
|
66 | 66 | \brief Defines the model that is used by the mapper. |
|
67 | 67 | */ |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty SomeModel VPieModelMapper::model |
|
70 | 70 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model |
|
71 | 71 | and expose it to QML. Note: the model has to support adding/removing rows/columns and modifying |
|
72 | 72 | the data of the cells. |
|
73 | 73 | */ |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \property QVPieModelMapper::valuesColumn |
|
77 | 77 | \brief Defines which column of the model is kept in sync with the values of the pie's slices. |
|
78 | 78 | |
|
79 | 79 | Default value is: -1 (invalid mapping) |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty int VPieModelMapper::valuesColumn |
|
83 | 83 | Defines which column of the model is kept in sync with the values of the pie's slices. Default value is -1 (invalid |
|
84 | 84 | mapping). |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QVPieModelMapper::labelsColumn |
|
89 | 89 | \brief Defines which column of the model is kept in sync with the labels of the pie's slices. |
|
90 | 90 | |
|
91 | 91 | Default value is: -1 (invalid mapping) |
|
92 | 92 | */ |
|
93 | 93 | /*! |
|
94 | 94 | \qmlproperty int VPieModelMapper::labelsColumn |
|
95 | 95 | Defines which column of the model is kept in sync with the labels of the pie's slices. Default value is -1 (invalid |
|
96 | 96 | mapping). |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QVPieModelMapper::firstRow |
|
101 | 101 | \brief Defines which row of the model contains the first slice value. |
|
102 | 102 | |
|
103 | 103 | Minimal and default value is: 0 |
|
104 | 104 | */ |
|
105 | 105 | /*! |
|
106 | 106 | \qmlproperty int VPieModelMapper::firstRow |
|
107 | 107 | Defines which row of the model contains the first slice value. |
|
108 | 108 | The default value is 0. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \property QVPieModelMapper::rowCount |
|
113 | 113 | \brief Defines the number of rows of the model that are mapped as the data for QPieSeries. |
|
114 | 114 | |
|
115 | 115 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
116 | 116 | */ |
|
117 | 117 | /*! |
|
118 | 118 | \qmlproperty int VPieModelMapper::columnCount |
|
119 | 119 | Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is |
|
120 | 120 | -1 (count limited by the number of rows in the model) |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QVPieModelMapper::seriesReplaced() |
|
125 | 125 | |
|
126 | 126 | Emitted when the series to which mapper is connected to has changed. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \fn void QVPieModelMapper::modelReplaced() |
|
131 | 131 | |
|
132 | 132 | Emitted when the model to which mapper is connected to has changed. |
|
133 | 133 | */ |
|
134 | 134 | |
|
135 | 135 | /*! |
|
136 | 136 | \fn void QVPieModelMapper::valuesColumnChanged() |
|
137 | 137 | |
|
138 | 138 | Emitted when the valuesColumn has changed. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QVPieModelMapper::labelsColumnChanged() |
|
143 | 143 | |
|
144 | 144 | Emitted when the labelsColumn has changed. |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \fn void QVPieModelMapper::firstRowChanged() |
|
149 | 149 | Emitted when the firstRow has changed. |
|
150 | 150 | */ |
|
151 | 151 | |
|
152 | 152 | /*! |
|
153 | 153 | \fn void QVPieModelMapper::rowCountChanged() |
|
154 | 154 | Emitted when the rowCount has changed. |
|
155 | 155 | */ |
|
156 | 156 | |
|
157 | 157 | /*! |
|
158 | 158 | Constructs a mapper object which is a child of \a parent. |
|
159 | 159 | */ |
|
160 | 160 | QVPieModelMapper::QVPieModelMapper(QObject *parent) : |
|
161 | 161 | QPieModelMapper(parent) |
|
162 | 162 | { |
|
163 | 163 | QPieModelMapper::setOrientation(Qt::Vertical); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | QAbstractItemModel *QVPieModelMapper::model() const |
|
167 | 167 | { |
|
168 | 168 | return QPieModelMapper::model(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | void QVPieModelMapper::setModel(QAbstractItemModel *model) |
|
172 | 172 | { |
|
173 | 173 | if (model != QPieModelMapper::model()) { |
|
174 | 174 | QPieModelMapper::setModel(model); |
|
175 | 175 | emit modelReplaced(); |
|
176 | 176 | } |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | QPieSeries *QVPieModelMapper::series() const |
|
180 | 180 | { |
|
181 | 181 | return QPieModelMapper::series(); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void QVPieModelMapper::setSeries(QPieSeries *series) |
|
185 | 185 | { |
|
186 | 186 | if (series != QPieModelMapper::series()) { |
|
187 | 187 | QPieModelMapper::setSeries(series); |
|
188 | 188 | emit seriesReplaced(); |
|
189 | 189 | } |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | Returns which column of the model is kept in sync with the values of the pie's slices |
|
194 | 194 | */ |
|
195 | 195 | int QVPieModelMapper::valuesColumn() const |
|
196 | 196 | { |
|
197 | 197 | return QPieModelMapper::valuesSection(); |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | Sets the model column that is kept in sync with the pie slices values. |
|
202 | 202 | Parameter \a valuesColumn specifies the row of the model. |
|
203 | 203 | */ |
|
204 | 204 | void QVPieModelMapper::setValuesColumn(int valuesColumn) |
|
205 | 205 | { |
|
206 | 206 | if (valuesColumn != valuesSection()) { |
|
207 | 207 | QPieModelMapper::setValuesSection(valuesColumn); |
|
208 | 208 | emit valuesColumnChanged(); |
|
209 | 209 | } |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | /*! |
|
213 | 213 | Returns which column of the model is kept in sync with the labels of the pie's slices |
|
214 | 214 | */ |
|
215 | 215 | int QVPieModelMapper::labelsColumn() const |
|
216 | 216 | { |
|
217 | 217 | return QPieModelMapper::labelsSection(); |
|
218 | 218 | } |
|
219 | 219 | |
|
220 | 220 | /*! |
|
221 | 221 | Sets the model column that is kept in sync with the pie's slices labels. |
|
222 | 222 | Parameter \a labelsColumn specifies the row of the model. |
|
223 | 223 | */ |
|
224 | 224 | void QVPieModelMapper::setLabelsColumn(int labelsColumn) |
|
225 | 225 | { |
|
226 | 226 | if (labelsColumn != labelsSection()) { |
|
227 | 227 | QPieModelMapper::setLabelsSection(labelsColumn); |
|
228 | 228 | emit labelsColumnChanged(); |
|
229 | 229 | } |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | int QVPieModelMapper::firstRow() const |
|
233 | 233 | { |
|
234 | 234 | return first(); |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | void QVPieModelMapper::setFirstRow(int firstRow) |
|
238 | 238 | { |
|
239 | 239 | if (firstRow != first()) { |
|
240 | 240 | setFirst(firstRow); |
|
241 | 241 | emit firstRowChanged(); |
|
242 | 242 | } |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | int QVPieModelMapper::rowCount() const |
|
246 | 246 | { |
|
247 | 247 | return count(); |
|
248 | 248 | } |
|
249 | 249 | |
|
250 | 250 | void QVPieModelMapper::setRowCount(int rowCount) |
|
251 | 251 | { |
|
252 | 252 | if (rowCount != count()) { |
|
253 | 253 | setCount(rowCount); |
|
254 | 254 | emit rowCountChanged(); |
|
255 | 255 | } |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | #include "moc_qvpiemodelmapper.cpp" |
|
259 | 259 | |
|
260 | 260 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,323 +1,323 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qabstractseries.h" |
|
22 | 22 | #include "qabstractseries_p.h" |
|
23 | 23 | #include "chartdataset_p.h" |
|
24 | 24 | #include "qchart.h" |
|
25 | 25 | #include "qchart_p.h" |
|
26 | 26 | #include "chartitem_p.h" |
|
27 | 27 | #include "xydomain_p.h" |
|
28 | 28 | #include "xlogydomain_p.h" |
|
29 | 29 | #include "logxydomain_p.h" |
|
30 | 30 | #include "logxlogydomain_p.h" |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | /*! |
|
35 | 35 | \class QAbstractSeries |
|
36 | 36 | \inmodule Qt Charts |
|
37 | 37 | \brief Base class for all Qt Chart series. |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | Usually you use the series type specific inherited classes instead of the base class. |
|
41 | 41 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
42 | 42 | QPercentBarSeries, QPieSeries |
|
43 | 43 | */ |
|
44 | 44 | #ifdef QDOC_QT5 |
|
45 | 45 | /*! |
|
46 | 46 | \qmltype AbstractSeries |
|
47 | 47 | \instantiates QAbstractSeries |
|
48 | 48 | \inqmlmodule QtCommercial.Chart |
|
49 | 49 | |
|
50 |
\include |
|
|
50 | \include doc/src/abstractseries.qdocinc | |
|
51 | 51 | */ |
|
52 | 52 | #else |
|
53 | 53 | /*! |
|
54 | 54 | \qmlclass AbstractSeries QAbstractSeries |
|
55 | 55 | |
|
56 | 56 | \include ../doc/src/abstractseries.qdocinc |
|
57 | 57 | */ |
|
58 | 58 | #endif |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \enum QAbstractSeries::SeriesType |
|
62 | 62 | |
|
63 | 63 | The type of the series object. |
|
64 | 64 | |
|
65 | 65 | \value SeriesTypeLine |
|
66 | 66 | \value SeriesTypeArea |
|
67 | 67 | \value SeriesTypeBar |
|
68 | 68 | \value SeriesTypeStackedBar |
|
69 | 69 | \value SeriesTypePercentBar |
|
70 | 70 | \value SeriesTypePie |
|
71 | 71 | \value SeriesTypeScatter |
|
72 | 72 | \value SeriesTypeSpline |
|
73 | 73 | \value SeriesTypeHorizontalBar |
|
74 | 74 | \value SeriesTypeHorizontalStackedBar |
|
75 | 75 | \value SeriesTypeHorizontalPercentBar |
|
76 | 76 | \value SeriesTypeBoxPlot |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \property QAbstractSeries::type |
|
81 | 81 | The type of the series. |
|
82 | 82 | */ |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
85 | 85 | The type of the series. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QAbstractSeries::name |
|
90 | 90 | \brief name of the series property. The name is shown in legend for series and supports html formatting. |
|
91 | 91 | */ |
|
92 | 92 | /*! |
|
93 | 93 | \qmlproperty string AbstractSeries::name |
|
94 | 94 | Name of the series. The name is shown in legend for series and supports html formatting. |
|
95 | 95 | */ |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | \fn void QAbstractSeries::nameChanged() |
|
99 | 99 | This signal is emitted when the series name changes. |
|
100 | 100 | */ |
|
101 | 101 | /*! |
|
102 | 102 | \qmlsignal AbstractSeries::onNameChanged() |
|
103 | 103 | This signal is emitted when the series name changes. |
|
104 | 104 | */ |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | \property QAbstractSeries::visible |
|
108 | 108 | \brief whether the series is visible or not; true by default. |
|
109 | 109 | */ |
|
110 | 110 | /*! |
|
111 | 111 | \qmlproperty bool AbstractSeries::visible |
|
112 | 112 | Visibility of the series. True by default. |
|
113 | 113 | */ |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | \fn void QAbstractSeries::visibleChanged() |
|
117 | 117 | Emitted when the series visibility changes. |
|
118 | 118 | */ |
|
119 | 119 | /*! |
|
120 | 120 | \qmlsignal AbstractSeries::onVisibleChanged() |
|
121 | 121 | Emitted when the series visibility changes. |
|
122 | 122 | */ |
|
123 | 123 | |
|
124 | 124 | /*! |
|
125 | 125 | \property QAbstractSeries::opacity |
|
126 | 126 | \brief The opacity of the series. |
|
127 | 127 | |
|
128 | 128 | By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
129 | 129 | */ |
|
130 | 130 | /*! |
|
131 | 131 | \qmlproperty real AbstractSeries::opacity |
|
132 | 132 | The opacity of the series. By default the opacity is 1.0. |
|
133 | 133 | The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | \fn void QAbstractSeries::opacityChanged() |
|
138 | 138 | Emitted when the opacity of the series changes. |
|
139 | 139 | */ |
|
140 | 140 | /*! |
|
141 | 141 | \qmlsignal AbstractSeries::onOpacityChanged() |
|
142 | 142 | Emitted when the opacity of the series changes. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \internal |
|
147 | 147 | \brief Constructs QAbstractSeries object with \a parent. |
|
148 | 148 | */ |
|
149 | 149 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
150 | 150 | QObject(parent), |
|
151 | 151 | d_ptr(&d) |
|
152 | 152 | { |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \brief Virtual destructor for the chart series. |
|
157 | 157 | */ |
|
158 | 158 | QAbstractSeries::~QAbstractSeries() |
|
159 | 159 | { |
|
160 | 160 | if (d_ptr->m_chart) |
|
161 | 161 | qFatal("Series still bound to a chart when destroyed!"); |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | void QAbstractSeries::setName(const QString &name) |
|
165 | 165 | { |
|
166 | 166 | if (name != d_ptr->m_name) { |
|
167 | 167 | d_ptr->m_name = name; |
|
168 | 168 | emit nameChanged(); |
|
169 | 169 | } |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | QString QAbstractSeries::name() const |
|
173 | 173 | { |
|
174 | 174 | return d_ptr->m_name; |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | void QAbstractSeries::setVisible(bool visible) |
|
178 | 178 | { |
|
179 | 179 | if (visible != d_ptr->m_visible) { |
|
180 | 180 | d_ptr->m_visible = visible; |
|
181 | 181 | emit visibleChanged(); |
|
182 | 182 | } |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | bool QAbstractSeries::isVisible() const |
|
186 | 186 | { |
|
187 | 187 | return d_ptr->m_visible; |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | 190 | qreal QAbstractSeries::opacity() const |
|
191 | 191 | { |
|
192 | 192 | return d_ptr->m_opacity; |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | void QAbstractSeries::setOpacity(qreal opacity) |
|
196 | 196 | { |
|
197 | 197 | if (opacity != d_ptr->m_opacity) { |
|
198 | 198 | d_ptr->m_opacity = opacity; |
|
199 | 199 | emit opacityChanged(); |
|
200 | 200 | } |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | \brief Returns the chart where series belongs to. |
|
205 | 205 | |
|
206 | 206 | Set automatically when the series is added to the chart |
|
207 | 207 | and unset when the series is removed from the chart. |
|
208 | 208 | */ |
|
209 | 209 | QChart *QAbstractSeries::chart() const |
|
210 | 210 | { |
|
211 | 211 | return d_ptr->m_chart; |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | /*! |
|
215 | 215 | \brief Sets the visibility of the series to true. |
|
216 | 216 | |
|
217 | 217 | \sa setVisible(), isVisible() |
|
218 | 218 | */ |
|
219 | 219 | void QAbstractSeries::show() |
|
220 | 220 | { |
|
221 | 221 | setVisible(true); |
|
222 | 222 | } |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | \brief Sets the visibility of the series to false. |
|
226 | 226 | |
|
227 | 227 | \sa setVisible(), isVisible() |
|
228 | 228 | */ |
|
229 | 229 | void QAbstractSeries::hide() |
|
230 | 230 | { |
|
231 | 231 | setVisible(false); |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | /*! |
|
235 | 235 | Attach \a axis to the series. |
|
236 | 236 | \return true if the axis was attached successfully, false otherwise. |
|
237 | 237 | \note If multiple axes of same orientation are attached to same series, |
|
238 | 238 | they will have same min/max ranges. |
|
239 | 239 | \sa QChart::addAxis(), QChart::createDefaultAxes() |
|
240 | 240 | */ |
|
241 | 241 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) |
|
242 | 242 | { |
|
243 | 243 | if(d_ptr->m_chart) { |
|
244 | 244 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis); |
|
245 | 245 | } else { |
|
246 | 246 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
247 | 247 | return false; |
|
248 | 248 | } |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | /*! |
|
252 | 252 | Detach \a axis from the series. |
|
253 | 253 | \return true if the axis was detached successfully, false otherwise. |
|
254 | 254 | \sa QChart::removeAxis() |
|
255 | 255 | */ |
|
256 | 256 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) |
|
257 | 257 | { |
|
258 | 258 | if(d_ptr->m_chart) { |
|
259 | 259 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis); |
|
260 | 260 | } |
|
261 | 261 | else { |
|
262 | 262 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
263 | 263 | return false; |
|
264 | 264 | } |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | /*! |
|
268 | 268 | Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except |
|
269 | 269 | in case of a QPieSeries, which does not have any axes attached. |
|
270 | 270 | \sa attachAxis(), detachAxis() |
|
271 | 271 | */ |
|
272 | 272 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() |
|
273 | 273 | { |
|
274 | 274 | return d_ptr->m_axes; |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | 277 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
278 | 278 | |
|
279 | 279 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) |
|
280 | 280 | : q_ptr(q), |
|
281 | 281 | m_chart(0), |
|
282 | 282 | m_item(0), |
|
283 | 283 | m_domain(new XYDomain()), |
|
284 | 284 | m_visible(true), |
|
285 | 285 | m_opacity(1.0) |
|
286 | 286 | { |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
290 | 290 | { |
|
291 | 291 | } |
|
292 | 292 | |
|
293 | 293 | void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) |
|
294 | 294 | { |
|
295 | 295 | Q_ASSERT(domain); |
|
296 | 296 | if(m_domain.data()!=domain) { |
|
297 | 297 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); |
|
298 | 298 | m_domain.reset(domain); |
|
299 | 299 | if(!m_item.isNull()) { |
|
300 | 300 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
301 | 301 | m_item->handleDomainUpdated(); |
|
302 | 302 | } |
|
303 | 303 | } |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
307 | 307 | { |
|
308 | 308 | Q_ASSERT(!m_item.isNull()); |
|
309 | 309 | Q_UNUSED(parent); |
|
310 | 310 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
314 | 314 | { |
|
315 | 315 | Q_UNUSED(options); |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | #include "moc_qabstractseries.cpp" |
|
319 | 319 | #include "moc_qabstractseries_p.cpp" |
|
320 | 320 | |
|
321 | 321 | QTCOMMERCIALCHART_END_NAMESPACE |
|
322 | 322 | |
|
323 | 323 |
@@ -1,308 +1,308 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qscatterseries.h" |
|
22 | 22 | #include "qscatterseries_p.h" |
|
23 | 23 | #include "scatterchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "scatteranimation_p.h" |
|
27 | 27 | #include "qchart_p.h" |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \class QScatterSeries |
|
31 | 31 | \inmodule Qt Charts |
|
32 | 32 | \brief The QScatterSeries class is used for making scatter charts. |
|
33 | 33 | |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 | 36 | The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis |
|
37 | 37 | and the vertical axis. |
|
38 | 38 | |
|
39 | 39 | \image examples_scatterchart.png |
|
40 | 40 | |
|
41 | 41 | Creating basic scatter chart is simple: |
|
42 | 42 | \code |
|
43 | 43 | QScatterSeries* series = new QScatterSeries(); |
|
44 | 44 | series->append(0, 6); |
|
45 | 45 | series->append(2, 4); |
|
46 | 46 | ... |
|
47 | 47 | chart->addSeries(series); |
|
48 | 48 | \endcode |
|
49 | 49 | */ |
|
50 | 50 | #ifdef QDOC_QT5 |
|
51 | 51 | /*! |
|
52 | 52 | \qmltype ScatterSeries |
|
53 | 53 | \instantiates QScatterSeries |
|
54 | 54 | \inqmlmodule QtCommercial.Chart |
|
55 | 55 | |
|
56 |
\include |
|
|
56 | \include doc/src/scatterseries.qdocinc | |
|
57 | 57 | */ |
|
58 | 58 | #else |
|
59 | 59 | /*! |
|
60 | 60 | \qmlclass ScatterSeries QScatterSeries |
|
61 | 61 | |
|
62 | 62 | \include ../doc/src/scatterseries.qdocinc |
|
63 | 63 | */ |
|
64 | 64 | #endif |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \enum QScatterSeries::MarkerShape |
|
68 | 68 | |
|
69 | 69 | This enum describes the shape used when rendering marker items. |
|
70 | 70 | |
|
71 | 71 | \value MarkerShapeCircle |
|
72 | 72 | \value MarkerShapeRectangle |
|
73 | 73 | */ |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \property QScatterSeries::color |
|
77 | 77 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
78 | 78 | \sa QScatterSeries::brush() |
|
79 | 79 | */ |
|
80 | 80 | |
|
81 | 81 | /*! |
|
82 | 82 | \property QScatterSeries::borderColor |
|
83 | 83 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
84 | 84 | \sa QScatterSeries::pen() |
|
85 | 85 | */ |
|
86 | 86 | /*! |
|
87 | 87 | \qmlproperty color ScatterSeries::borderColor |
|
88 | 88 | Border (pen) color of the series. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty real ScatterSeries::borderWidth |
|
93 | 93 | The width of the border line. By default the width is 2.0. |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \property QScatterSeries::markerShape |
|
98 | 98 | Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle. |
|
99 | 99 | */ |
|
100 | 100 | /*! |
|
101 | 101 | \qmlproperty MarkerShape ScatterSeries::markerShape |
|
102 | 102 | Defines the shape of the marker used to draw the points in the series. One of ScatterSeries |
|
103 | 103 | ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle. |
|
104 | 104 | The default shape is ScatterSeries.MarkerShapeCircle. |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \property QScatterSeries::markerSize |
|
109 | 109 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. |
|
110 | 110 | */ |
|
111 | 111 | /*! |
|
112 | 112 | \qmlproperty real ScatterSeries::markerSize |
|
113 | 113 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \fn void QScatterSeries::colorChanged(QColor color) |
|
118 | 118 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
119 | 119 | */ |
|
120 | 120 | |
|
121 | 121 | /*! |
|
122 | 122 | \fn void QScatterSeries::borderColorChanged(QColor color) |
|
123 | 123 | Signal is emitted when the line (pen) color has changed to \a color. |
|
124 | 124 | */ |
|
125 | 125 | /*! |
|
126 | 126 | \qmlsignal ScatterSeries::borderColorChanged(color color) |
|
127 | 127 | Signal is emitted when the line (pen) color has changed to \a color. |
|
128 | 128 | */ |
|
129 | 129 | |
|
130 | 130 | /*! |
|
131 | 131 | \fn QAbstractSeries::SeriesType QScatterSeries::type() const |
|
132 | 132 | Returns QAbstractSeries::SeriesTypeScatter. |
|
133 | 133 | \sa QAbstractSeries, SeriesType |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | Constructs a series object which is a child of \a parent. |
|
140 | 140 | */ |
|
141 | 141 | QScatterSeries::QScatterSeries(QObject *parent) |
|
142 | 142 | : QXYSeries(*new QScatterSeriesPrivate(this), parent) |
|
143 | 143 | { |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
148 | 148 | */ |
|
149 | 149 | QScatterSeries::~QScatterSeries() |
|
150 | 150 | { |
|
151 | 151 | Q_D(QScatterSeries); |
|
152 | 152 | if (d->m_chart) |
|
153 | 153 | d->m_chart->removeSeries(this); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | QAbstractSeries::SeriesType QScatterSeries::type() const |
|
157 | 157 | { |
|
158 | 158 | return QAbstractSeries::SeriesTypeScatter; |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the |
|
163 | 163 | pen from chart theme is used. |
|
164 | 164 | \sa QChart::setTheme() |
|
165 | 165 | */ |
|
166 | 166 | void QScatterSeries::setPen(const QPen &pen) |
|
167 | 167 | { |
|
168 | 168 | Q_D(QXYSeries); |
|
169 | 169 | if (d->m_pen != pen) { |
|
170 | 170 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
171 | 171 | d->m_pen = pen; |
|
172 | 172 | emit d->updated(); |
|
173 | 173 | if (emitColorChanged) |
|
174 | 174 | emit borderColorChanged(pen.color()); |
|
175 | 175 | } |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | /*! |
|
179 | 179 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
180 | 180 | from chart theme setting is used. |
|
181 | 181 | \sa QChart::setTheme() |
|
182 | 182 | */ |
|
183 | 183 | void QScatterSeries::setBrush(const QBrush &brush) |
|
184 | 184 | { |
|
185 | 185 | Q_D(QScatterSeries); |
|
186 | 186 | if (d->m_brush != brush) { |
|
187 | 187 | bool emitColorChanged = d->m_brush.color() != brush.color(); |
|
188 | 188 | d->m_brush = brush; |
|
189 | 189 | emit d->updated(); |
|
190 | 190 | if (emitColorChanged) |
|
191 | 191 | emit colorChanged(brush.color()); |
|
192 | 192 | } |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | void QScatterSeries::setColor(const QColor &color) |
|
196 | 196 | { |
|
197 | 197 | QBrush b = brush(); |
|
198 | 198 | if (b == QBrush()) |
|
199 | 199 | b.setStyle(Qt::SolidPattern); |
|
200 | 200 | b.setColor(color); |
|
201 | 201 | setBrush(b); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | QColor QScatterSeries::color() const |
|
205 | 205 | { |
|
206 | 206 | return brush().color(); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | void QScatterSeries::setBorderColor(const QColor &color) |
|
210 | 210 | { |
|
211 | 211 | QPen p = pen(); |
|
212 | 212 | if (p.color() != color) { |
|
213 | 213 | p.setColor(color); |
|
214 | 214 | setPen(p); |
|
215 | 215 | } |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | QColor QScatterSeries::borderColor() const |
|
219 | 219 | { |
|
220 | 220 | return pen().color(); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | QScatterSeries::MarkerShape QScatterSeries::markerShape() const |
|
224 | 224 | { |
|
225 | 225 | Q_D(const QScatterSeries); |
|
226 | 226 | return d->m_shape; |
|
227 | 227 | } |
|
228 | 228 | |
|
229 | 229 | void QScatterSeries::setMarkerShape(MarkerShape shape) |
|
230 | 230 | { |
|
231 | 231 | Q_D(QScatterSeries); |
|
232 | 232 | if (d->m_shape != shape) { |
|
233 | 233 | d->m_shape = shape; |
|
234 | 234 | emit d->updated(); |
|
235 | 235 | } |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | qreal QScatterSeries::markerSize() const |
|
239 | 239 | { |
|
240 | 240 | Q_D(const QScatterSeries); |
|
241 | 241 | return d->m_size; |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | void QScatterSeries::setMarkerSize(qreal size) |
|
245 | 245 | { |
|
246 | 246 | Q_D(QScatterSeries); |
|
247 | 247 | |
|
248 | 248 | if (!qFuzzyCompare(d->m_size, size)) { |
|
249 | 249 | d->m_size = size; |
|
250 | 250 | emit d->updated(); |
|
251 | 251 | } |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
255 | 255 | |
|
256 | 256 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q) |
|
257 | 257 | : QXYSeriesPrivate(q), |
|
258 | 258 | m_shape(QScatterSeries::MarkerShapeCircle), |
|
259 | 259 | m_size(15.0) |
|
260 | 260 | { |
|
261 | 261 | } |
|
262 | 262 | |
|
263 | 263 | void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
264 | 264 | { |
|
265 | 265 | Q_Q(QScatterSeries); |
|
266 | 266 | ScatterChartItem *scatter = new ScatterChartItem(q,parent); |
|
267 | 267 | m_item.reset(scatter); |
|
268 | 268 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
272 | 272 | { |
|
273 | 273 | Q_Q(QScatterSeries); |
|
274 | 274 | const QList<QColor> colors = theme->seriesColors(); |
|
275 | 275 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
276 | 276 | |
|
277 | 277 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
278 | 278 | QPen pen; |
|
279 | 279 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); |
|
280 | 280 | pen.setWidthF(2); |
|
281 | 281 | q->setPen(pen); |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | if (forced || QChartPrivate::defaultBrush() == m_brush) { |
|
285 | 285 | QBrush brush(colors.at(index % colors.size())); |
|
286 | 286 | q->setBrush(brush); |
|
287 | 287 | } |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
291 | 291 | { |
|
292 | 292 | ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data()); |
|
293 | 293 | Q_ASSERT(item); |
|
294 | 294 | |
|
295 | 295 | if (item->animation()) |
|
296 | 296 | item->animation()->stopAndDestroyLater(); |
|
297 | 297 | |
|
298 | 298 | if (options.testFlag(QChart::SeriesAnimations)) |
|
299 | 299 | item->setAnimation(new ScatterAnimation(item)); |
|
300 | 300 | else |
|
301 | 301 | item->setAnimation(0); |
|
302 | 302 | |
|
303 | 303 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | #include "moc_qscatterseries.cpp" |
|
307 | 307 | |
|
308 | 308 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,159 +1,159 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qsplineseries.h" |
|
22 | 22 | #include "qsplineseries_p.h" |
|
23 | 23 | #include "splinechartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "splineanimation_p.h" |
|
27 | 27 | #include "qchart_p.h" |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \class QSplineSeries |
|
31 | 31 | \inmodule Qt Charts |
|
32 | 32 | \brief Series type used to store data needed to draw a spline. |
|
33 | 33 | |
|
34 | 34 | QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline |
|
35 | 35 | Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn. |
|
36 | 36 | |
|
37 | 37 | \image examples_splinechart.png |
|
38 | 38 | |
|
39 | 39 | Creating basic spline chart is simple: |
|
40 | 40 | \code |
|
41 | 41 | QSplineSeries* series = new QSplineSeries(); |
|
42 | 42 | series->append(0, 6); |
|
43 | 43 | series->append(2, 4); |
|
44 | 44 | ... |
|
45 | 45 | chart->addSeries(series); |
|
46 | 46 | \endcode |
|
47 | 47 | */ |
|
48 | 48 | #ifdef QDOC_QT5 |
|
49 | 49 | /*! |
|
50 | 50 | \qmltype SplineSeries |
|
51 | 51 | \instantiates QSplineSeries |
|
52 | 52 | \inqmlmodule QtCommercial.Chart |
|
53 | 53 | |
|
54 |
\include |
|
|
54 | \include doc/src/splineseries.qdocinc | |
|
55 | 55 | */ |
|
56 | 56 | #else |
|
57 | 57 | /*! |
|
58 | 58 | \qmlclass SplineSeries QSplineSeries |
|
59 | 59 | |
|
60 | 60 | \include ../doc/src/splineseries.qdocinc |
|
61 | 61 | */ |
|
62 | 62 | #endif |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | \fn QSeriesType QSplineSeries::type() const |
|
66 | 66 | Returns the type of the series |
|
67 | 67 | */ |
|
68 | 68 | |
|
69 | 69 | /*! |
|
70 | 70 | \qmlproperty real SplineSeries::width |
|
71 | 71 | The width of the line. By default the width is 2.0. |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \qmlproperty Qt::PenStyle SplineSeries::style |
|
76 | 76 | Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine, |
|
77 | 77 | Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API. |
|
78 | 78 | By default the style is Qt.SolidLine. |
|
79 | 79 | */ |
|
80 | 80 | |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty Qt::PenCapStyle SplineSeries::capStyle |
|
83 | 83 | Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By |
|
84 | 84 | default the cap style is Qt.SquareCap. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | Constructs empty series object which is a child of \a parent. |
|
91 | 91 | When series object is added to a QChart instance then the ownerships is transferred. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | QSplineSeries::QSplineSeries(QObject *parent) |
|
95 | 95 | : QLineSeries(*new QSplineSeriesPrivate(this), parent) |
|
96 | 96 | { |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | Destroys the object. |
|
101 | 101 | */ |
|
102 | 102 | QSplineSeries::~QSplineSeries() |
|
103 | 103 | { |
|
104 | 104 | Q_D(QSplineSeries); |
|
105 | 105 | if (d->m_chart) |
|
106 | 106 | d->m_chart->removeSeries(this); |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | QAbstractSeries::SeriesType QSplineSeries::type() const |
|
110 | 110 | { |
|
111 | 111 | return QAbstractSeries::SeriesTypeSpline; |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | 114 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
115 | 115 | |
|
116 | 116 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q) |
|
117 | 117 | : QLineSeriesPrivate(q) |
|
118 | 118 | { |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
122 | 122 | { |
|
123 | 123 | Q_Q(QSplineSeries); |
|
124 | 124 | SplineChartItem *spline = new SplineChartItem(q,parent); |
|
125 | 125 | m_item.reset(spline); |
|
126 | 126 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
130 | 130 | { |
|
131 | 131 | Q_Q(QSplineSeries); |
|
132 | 132 | const QList<QColor> colors = theme->seriesColors(); |
|
133 | 133 | |
|
134 | 134 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
135 | 135 | QPen pen; |
|
136 | 136 | pen.setColor(colors.at(index % colors.size())); |
|
137 | 137 | pen.setWidthF(2); |
|
138 | 138 | q->setPen(pen); |
|
139 | 139 | } |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
143 | 143 | { |
|
144 | 144 | SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); |
|
145 | 145 | Q_ASSERT(item); |
|
146 | 146 | if (item->animation()) |
|
147 | 147 | item->animation()->stopAndDestroyLater(); |
|
148 | 148 | |
|
149 | 149 | if (options.testFlag(QChart::SeriesAnimations)) |
|
150 | 150 | item->setAnimation(new SplineAnimation(item)); |
|
151 | 151 | else |
|
152 | 152 | item->setAnimation(0); |
|
153 | 153 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | #include "moc_qsplineseries.cpp" |
|
157 | 157 | #include "moc_qsplineseries_p.cpp" |
|
158 | 158 | |
|
159 | 159 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,246 +1,246 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qhxymodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QHXYModelMapper |
|
27 | 27 | \inmodule Qt Charts |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. |
|
32 | 32 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. |
|
33 | 33 | Note: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | 34 | */ |
|
35 | 35 | #ifdef QDOC_QT5 |
|
36 | 36 | /*! |
|
37 | 37 | \qmltype HXYModelMapper |
|
38 | 38 | \instantiates QHXYModelMapper |
|
39 | 39 | \inqmlmodule QtCommercial.Chart |
|
40 | 40 | |
|
41 |
\include |
|
|
41 | \include doc/src/hxymodelmapper.qdocinc | |
|
42 | 42 | */ |
|
43 | 43 | #else |
|
44 | 44 | /*! |
|
45 | 45 | \qmlclass HXYModelMapper QHXYModelMapper |
|
46 | 46 | |
|
47 | 47 | \include ../doc/src/hxymodelmapper.qdocinc |
|
48 | 48 | */ |
|
49 | 49 | #endif |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | \property QHXYModelMapper::series |
|
53 | 53 | \brief Defines the QXYSeries object that is used by the mapper. |
|
54 | 54 | |
|
55 | 55 | All the data in the series is discarded when it is set to the mapper. |
|
56 | 56 | When new series is specified the old series is disconnected (it preserves its data) |
|
57 | 57 | */ |
|
58 | 58 | /*! |
|
59 | 59 | \qmlproperty XYSeries HXYModelMapper::series |
|
60 | 60 | Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to |
|
61 | 61 | the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
62 | 62 | */ |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | \property QHXYModelMapper::model |
|
66 | 66 | \brief Defines the model that is used by the mapper. |
|
67 | 67 | */ |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty SomeModel HXYModelMapper::model |
|
70 | 70 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model |
|
71 | 71 | and expose it to QML. Note: the model has to support adding/removing rows/columns and modifying |
|
72 | 72 | the data of the cells. |
|
73 | 73 | */ |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \property QHXYModelMapper::xRow |
|
77 | 77 | \brief Defines which row of the model is kept in sync with the x values of the QXYSeries. |
|
78 | 78 | |
|
79 | 79 | Default value is: -1 (invalid mapping) |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty int HXYModelMapper::xRow |
|
83 | 83 | Defines which row of the model is kept in sync with the x values of the series. Default value is -1 (invalid |
|
84 | 84 | mapping). |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QHXYModelMapper::yRow |
|
89 | 89 | \brief Defines which row of the model is kept in sync with the y values of the QXYSeries. |
|
90 | 90 | |
|
91 | 91 | Default value is: -1 (invalid mapping) |
|
92 | 92 | */ |
|
93 | 93 | /*! |
|
94 | 94 | \qmlproperty int HXYModelMapper::yRow |
|
95 | 95 | Defines which row of the model is kept in sync with the y values of the series. Default value is -1 |
|
96 | 96 | (invalid mapping). |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QHXYModelMapper::firstColumn |
|
101 | 101 | \brief Defines which column of the model contains the data for the first point of the series. |
|
102 | 102 | |
|
103 | 103 | Minimal and default value is: 0 |
|
104 | 104 | */ |
|
105 | 105 | /*! |
|
106 | 106 | \qmlproperty int HXYModelMapper::firstColumn |
|
107 | 107 | Defines which column of the model contains the data for the first point of the series. |
|
108 | 108 | The default value is 0. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \property QHXYModelMapper::columnCount |
|
113 | 113 | \brief Defines the number of columns of the model that are mapped as the data for series. |
|
114 | 114 | |
|
115 | 115 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
116 | 116 | */ |
|
117 | 117 | /*! |
|
118 | 118 | \qmlproperty int HXYModelMapper::columnCount |
|
119 | 119 | Defines the number of columns of the model that are mapped as the data for series. The default value is |
|
120 | 120 | -1 (count limited by the number of columns in the model) |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QHXYModelMapper::seriesReplaced() |
|
125 | 125 | |
|
126 | 126 | Emitted when the series to which mapper is connected to has changed. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \fn void QHXYModelMapper::modelReplaced() |
|
131 | 131 | |
|
132 | 132 | Emitted when the model to which mapper is connected to has changed. |
|
133 | 133 | */ |
|
134 | 134 | |
|
135 | 135 | /*! |
|
136 | 136 | \fn void QHXYModelMapper::xRowChanged() |
|
137 | 137 | |
|
138 | 138 | Emitted when the xRow has changed. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QHXYModelMapper::yRowChanged() |
|
143 | 143 | |
|
144 | 144 | Emitted when the yRow has changed. |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \fn void QHXYModelMapper::firstColumnChanged() |
|
149 | 149 | Emitted when the firstColumn has changed. |
|
150 | 150 | */ |
|
151 | 151 | |
|
152 | 152 | /*! |
|
153 | 153 | \fn void QHXYModelMapper::columnCountChanged() |
|
154 | 154 | Emitted when the columnCount has changed. |
|
155 | 155 | */ |
|
156 | 156 | |
|
157 | 157 | /*! |
|
158 | 158 | Constructs a mapper object which is a child of \a parent. |
|
159 | 159 | */ |
|
160 | 160 | QHXYModelMapper::QHXYModelMapper(QObject *parent) : |
|
161 | 161 | QXYModelMapper(parent) |
|
162 | 162 | { |
|
163 | 163 | QXYModelMapper::setOrientation(Qt::Horizontal); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | QAbstractItemModel *QHXYModelMapper::model() const |
|
167 | 167 | { |
|
168 | 168 | return QXYModelMapper::model(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | void QHXYModelMapper::setModel(QAbstractItemModel *model) |
|
172 | 172 | { |
|
173 | 173 | if (model != QXYModelMapper::model()) { |
|
174 | 174 | QXYModelMapper::setModel(model); |
|
175 | 175 | emit modelReplaced(); |
|
176 | 176 | } |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | QXYSeries *QHXYModelMapper::series() const |
|
180 | 180 | { |
|
181 | 181 | return QXYModelMapper::series(); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void QHXYModelMapper::setSeries(QXYSeries *series) |
|
185 | 185 | { |
|
186 | 186 | if (series != QXYModelMapper::series()) { |
|
187 | 187 | QXYModelMapper::setSeries(series); |
|
188 | 188 | emit seriesReplaced(); |
|
189 | 189 | } |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | int QHXYModelMapper::xRow() const |
|
193 | 193 | { |
|
194 | 194 | return QXYModelMapper::xSection(); |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | void QHXYModelMapper::setXRow(int xRow) |
|
198 | 198 | { |
|
199 | 199 | if (xRow != xSection()) { |
|
200 | 200 | QXYModelMapper::setXSection(xRow); |
|
201 | 201 | emit xRowChanged(); |
|
202 | 202 | } |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | int QHXYModelMapper::yRow() const |
|
206 | 206 | { |
|
207 | 207 | return QXYModelMapper::ySection(); |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | void QHXYModelMapper::setYRow(int yRow) |
|
211 | 211 | { |
|
212 | 212 | if (yRow != ySection()) { |
|
213 | 213 | QXYModelMapper::setYSection(yRow); |
|
214 | 214 | emit yRowChanged(); |
|
215 | 215 | } |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | int QHXYModelMapper::firstColumn() const |
|
219 | 219 | { |
|
220 | 220 | return first(); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | void QHXYModelMapper::setFirstColumn(int firstColumn) |
|
224 | 224 | { |
|
225 | 225 | if (firstColumn != first()) { |
|
226 | 226 | setFirst(firstColumn); |
|
227 | 227 | emit firstColumnChanged(); |
|
228 | 228 | } |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | int QHXYModelMapper::columnCount() const |
|
232 | 232 | { |
|
233 | 233 | return count(); |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | void QHXYModelMapper::setColumnCount(int columnCount) |
|
237 | 237 | { |
|
238 | 238 | if (columnCount != count()) { |
|
239 | 239 | setCount(columnCount); |
|
240 | 240 | emit columnCountChanged(); |
|
241 | 241 | } |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | #include "moc_qhxymodelmapper.cpp" |
|
245 | 245 | |
|
246 | 246 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,246 +1,246 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qvxymodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QVXYModelMapper |
|
27 | 27 | \inmodule Qt Charts |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. |
|
32 | 32 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. |
|
33 | 33 | Note: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | 34 | */ |
|
35 | 35 | #ifdef QDOC_QT5 |
|
36 | 36 | /*! |
|
37 | 37 | \qmltype VXYModelMapper |
|
38 | 38 | \instantiates QVXYModelMapper |
|
39 | 39 | \inqmlmodule QtCommercial.Chart |
|
40 | 40 | |
|
41 |
\include |
|
|
41 | \include doc/src/vxymodelmapper.qdocinc | |
|
42 | 42 | */ |
|
43 | 43 | #else |
|
44 | 44 | /*! |
|
45 | 45 | \qmlclass VXYModelMapper QVXYModelMapper |
|
46 | 46 | |
|
47 | 47 | \include ../doc/src/vxymodelmapper.qdocinc |
|
48 | 48 | */ |
|
49 | 49 | #endif |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | \property QVXYModelMapper::series |
|
53 | 53 | \brief Defines the QXYSeries object that is used by the mapper. |
|
54 | 54 | |
|
55 | 55 | All the data in the series is discarded when it is set to the mapper. |
|
56 | 56 | When new series is specified the old series is disconnected (it preserves its data) |
|
57 | 57 | */ |
|
58 | 58 | /*! |
|
59 | 59 | \qmlproperty XYSeries VXYModelMapper::series |
|
60 | 60 | Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to |
|
61 | 61 | the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
62 | 62 | */ |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | \property QVXYModelMapper::model |
|
66 | 66 | \brief Defines the model that is used by the mapper. |
|
67 | 67 | */ |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty SomeModel VXYModelMapper::model |
|
70 | 70 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model |
|
71 | 71 | and expose it to QML. Note: the model has to support adding/removing rows/columns and modifying |
|
72 | 72 | the data of the cells. |
|
73 | 73 | */ |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \property QVXYModelMapper::xColumn |
|
77 | 77 | \brief Defines which column of the model is kept in sync with the x values of QXYSeries. |
|
78 | 78 | |
|
79 | 79 | Default value is: -1 (invalid mapping) |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty int VXYModelMapper::xColumn |
|
83 | 83 | Defines which column of the model is kept in sync with the x values of the series. Default value is -1 (invalid |
|
84 | 84 | mapping). |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QVXYModelMapper::yColumn |
|
89 | 89 | \brief Defines which column of the model is kept in sync with the y values of QXYSeries. |
|
90 | 90 | |
|
91 | 91 | Default value is: -1 (invalid mapping) |
|
92 | 92 | */ |
|
93 | 93 | /*! |
|
94 | 94 | \qmlproperty int VXYModelMapper::yColumn |
|
95 | 95 | Defines which column of the model is kept in sync with the y values of the series. Default value is -1 (invalid |
|
96 | 96 | mapping). |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QVXYModelMapper::firstRow |
|
101 | 101 | \brief Defines which row of the model contains the data for the first point of the series. |
|
102 | 102 | |
|
103 | 103 | Minimal and default value is: 0 |
|
104 | 104 | */ |
|
105 | 105 | /*! |
|
106 | 106 | \qmlproperty int VXYModelMapper::firstRow |
|
107 | 107 | Defines which row of the model contains the data for the first point of the series. |
|
108 | 108 | The default value is 0. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \property QVXYModelMapper::rowCount |
|
113 | 113 | \brief Defines the number of rows of the model that are mapped as the data for series. |
|
114 | 114 | |
|
115 | 115 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
116 | 116 | */ |
|
117 | 117 | /*! |
|
118 | 118 | \qmlproperty int VXYModelMapper::columnCount |
|
119 | 119 | Defines the number of rows of the model that are mapped as the data for series. The default value is |
|
120 | 120 | -1 (count limited by the number of rows in the model). |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QVXYModelMapper::seriesReplaced() |
|
125 | 125 | |
|
126 | 126 | Emitted when the series to which mapper is connected to has changed. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \fn void QVXYModelMapper::modelReplaced() |
|
131 | 131 | |
|
132 | 132 | Emitted when the model to which mapper is connected to has changed. |
|
133 | 133 | */ |
|
134 | 134 | |
|
135 | 135 | /*! |
|
136 | 136 | \fn void QVXYModelMapper::xColumnChanged() |
|
137 | 137 | |
|
138 | 138 | Emitted when the xColumn has changed. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QVXYModelMapper::yColumnChanged() |
|
143 | 143 | |
|
144 | 144 | Emitted when the yColumn has changed. |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \fn void QVXYModelMapper::firstRowChanged() |
|
149 | 149 | Emitted when the firstRow has changed. |
|
150 | 150 | */ |
|
151 | 151 | |
|
152 | 152 | /*! |
|
153 | 153 | \fn void QVXYModelMapper::rowCountChanged() |
|
154 | 154 | Emitted when the rowCount has changed. |
|
155 | 155 | */ |
|
156 | 156 | |
|
157 | 157 | /*! |
|
158 | 158 | Constructs a mapper object which is a child of \a parent. |
|
159 | 159 | */ |
|
160 | 160 | QVXYModelMapper::QVXYModelMapper(QObject *parent) : |
|
161 | 161 | QXYModelMapper(parent) |
|
162 | 162 | { |
|
163 | 163 | QXYModelMapper::setOrientation(Qt::Vertical); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | QAbstractItemModel *QVXYModelMapper::model() const |
|
167 | 167 | { |
|
168 | 168 | return QXYModelMapper::model(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | void QVXYModelMapper::setModel(QAbstractItemModel *model) |
|
172 | 172 | { |
|
173 | 173 | if (model != QXYModelMapper::model()) { |
|
174 | 174 | QXYModelMapper::setModel(model); |
|
175 | 175 | emit modelReplaced(); |
|
176 | 176 | } |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | QXYSeries *QVXYModelMapper::series() const |
|
180 | 180 | { |
|
181 | 181 | return QXYModelMapper::series(); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void QVXYModelMapper::setSeries(QXYSeries *series) |
|
185 | 185 | { |
|
186 | 186 | if (series != QXYModelMapper::series()) { |
|
187 | 187 | QXYModelMapper::setSeries(series); |
|
188 | 188 | emit seriesReplaced(); |
|
189 | 189 | } |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | int QVXYModelMapper::xColumn() const |
|
193 | 193 | { |
|
194 | 194 | return QXYModelMapper::xSection(); |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | void QVXYModelMapper::setXColumn(int xColumn) |
|
198 | 198 | { |
|
199 | 199 | if (xColumn != xSection()) { |
|
200 | 200 | QXYModelMapper::setXSection(xColumn); |
|
201 | 201 | emit xColumnChanged(); |
|
202 | 202 | } |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | int QVXYModelMapper::yColumn() const |
|
206 | 206 | { |
|
207 | 207 | return QXYModelMapper::ySection(); |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | void QVXYModelMapper::setYColumn(int yColumn) |
|
211 | 211 | { |
|
212 | 212 | if (yColumn != ySection()) { |
|
213 | 213 | QXYModelMapper::setYSection(yColumn); |
|
214 | 214 | emit yColumnChanged(); |
|
215 | 215 | } |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | int QVXYModelMapper::firstRow() const |
|
219 | 219 | { |
|
220 | 220 | return first(); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | void QVXYModelMapper::setFirstRow(int firstRow) |
|
224 | 224 | { |
|
225 | 225 | if (firstRow != first()) { |
|
226 | 226 | setFirst(firstRow); |
|
227 | 227 | emit firstRowChanged(); |
|
228 | 228 | } |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | int QVXYModelMapper::rowCount() const |
|
232 | 232 | { |
|
233 | 233 | return count(); |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | void QVXYModelMapper::setRowCount(int rowCount) |
|
237 | 237 | { |
|
238 | 238 | if (rowCount != count()) { |
|
239 | 239 | setCount(rowCount); |
|
240 | 240 | emit rowCountChanged(); |
|
241 | 241 | } |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | #include "moc_qvxymodelmapper.cpp" |
|
245 | 245 | |
|
246 | 246 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,607 +1,607 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 "qxyseries.h" |
|
22 | 22 | #include "qxyseries_p.h" |
|
23 | 23 | #include "abstractdomain_p.h" |
|
24 | 24 | #include "qvalueaxis.h" |
|
25 | 25 | #include "xychart_p.h" |
|
26 | 26 | #include "qxylegendmarker.h" |
|
27 | 27 | #include "charthelpers_p.h" |
|
28 | 28 | #include "qchart_p.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QXYSeries |
|
34 | 34 | \inmodule Qt Charts |
|
35 | 35 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
36 | 36 | */ |
|
37 | 37 | #ifdef QDOC_QT5 |
|
38 | 38 | /*! |
|
39 | 39 | \qmltype XYSeries |
|
40 | 40 | \instantiates QXYSeries |
|
41 | 41 | \inqmlmodule QtCommercial.Chart |
|
42 | 42 | |
|
43 |
\include |
|
|
43 | \include doc/src/xyseries.qdocinc | |
|
44 | 44 | */ |
|
45 | 45 | #else |
|
46 | 46 | /*! |
|
47 | 47 | \qmlclass XYSeries QXYSeries |
|
48 | 48 | |
|
49 | 49 | \include ../doc/src/xyseries.qdocinc |
|
50 | 50 | */ |
|
51 | 51 | #endif |
|
52 | 52 | |
|
53 | 53 | /*! |
|
54 | 54 | \qmlproperty AbstractAxis XYSeries::axisX |
|
55 | 55 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for |
|
56 | 56 | the series. |
|
57 | 57 | \sa axisXTop |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \qmlproperty AbstractAxis XYSeries::axisY |
|
62 | 62 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
63 | 63 | the series. |
|
64 | 64 | \sa axisYRight |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \qmlproperty AbstractAxis XYSeries::axisXTop |
|
69 | 69 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
70 | 70 | axisXTop, but not both. |
|
71 | 71 | \sa axisX |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \qmlproperty AbstractAxis XYSeries::axisYRight |
|
76 | 76 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
77 | 77 | or axisYRight, but not both. |
|
78 | 78 | \sa axisY |
|
79 | 79 | */ |
|
80 | 80 | |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty AbstractAxis XYSeries::axisAngular |
|
83 | 83 | The angular axis used for the series, drawn around the polar chart view. |
|
84 | 84 | \sa axisX |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \qmlproperty AbstractAxis XYSeries::axisRadial |
|
89 | 89 | The radial axis used for the series, drawn inside the polar chart view. |
|
90 | 90 | \sa axisY |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \property QXYSeries::pointsVisible |
|
95 | 95 | Controls if the data points are visible and should be drawn. |
|
96 | 96 | */ |
|
97 | 97 | /*! |
|
98 | 98 | \qmlproperty bool XYSeries::pointsVisible |
|
99 | 99 | Controls if the data points are visible and should be drawn. |
|
100 | 100 | */ |
|
101 | 101 | |
|
102 | 102 | /*! |
|
103 | 103 | \fn QPen QXYSeries::pen() const |
|
104 | 104 | \brief Returns pen used to draw points for series. |
|
105 | 105 | \sa setPen() |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \fn QBrush QXYSeries::brush() const |
|
110 | 110 | \brief Returns brush used to draw points for series. |
|
111 | 111 | \sa setBrush() |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | \property QXYSeries::color |
|
116 | 116 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
117 | 117 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
118 | 118 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
119 | 119 | */ |
|
120 | 120 | /*! |
|
121 | 121 | \qmlproperty color XYSeries::color |
|
122 | 122 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
123 | 123 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | /*! |
|
127 | 127 | \fn void QXYSeries::clicked(const QPointF& point) |
|
128 | 128 | \brief Signal is emitted when user clicks the \a point on chart. |
|
129 | 129 | */ |
|
130 | 130 | /*! |
|
131 | 131 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
132 | 132 | Signal is emitted when user clicks the \a point on chart. For example: |
|
133 | 133 | \code |
|
134 | 134 | LineSeries { |
|
135 | 135 | XYPoint { x: 0; y: 0 } |
|
136 | 136 | XYPoint { x: 1.1; y: 2.1 } |
|
137 | 137 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
138 | 138 | } |
|
139 | 139 | \endcode |
|
140 | 140 | */ |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | \fn void QXYSeries::hovered(const QPointF &point, bool state) |
|
144 | 144 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
145 | 145 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
146 | 146 | the series. |
|
147 | 147 | */ |
|
148 | 148 | /*! |
|
149 | 149 | \qmlsignal XYSeries::onHovered(point point, bool state) |
|
150 | 150 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
151 | 151 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
152 | 152 | the series. |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QXYSeries::pointReplaced(int index) |
|
157 | 157 | Signal is emitted when a point has been replaced at \a index. |
|
158 | 158 | \sa replace() |
|
159 | 159 | */ |
|
160 | 160 | /*! |
|
161 | 161 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
162 | 162 | Signal is emitted when a point has been replaced at \a index. |
|
163 | 163 | */ |
|
164 | 164 | |
|
165 | 165 | /*! |
|
166 | 166 | \fn void QXYSeries::pointsReplaced() |
|
167 | 167 | Signal is emitted when all points have been replaced with other points. |
|
168 | 168 | \sa replace() |
|
169 | 169 | */ |
|
170 | 170 | /*! |
|
171 | 171 | \qmlsignal XYSeries::onPointsReplaced() |
|
172 | 172 | */ |
|
173 | 173 | |
|
174 | 174 | /*! |
|
175 | 175 | \fn void QXYSeries::pointAdded(int index) |
|
176 | 176 | Signal is emitted when a point has been added at \a index. |
|
177 | 177 | \sa append(), insert() |
|
178 | 178 | */ |
|
179 | 179 | /*! |
|
180 | 180 | \qmlsignal XYSeries::onPointAdded(int index) |
|
181 | 181 | Signal is emitted when a point has been added at \a index. |
|
182 | 182 | */ |
|
183 | 183 | |
|
184 | 184 | /*! |
|
185 | 185 | \fn void QXYSeries::pointRemoved(int index) |
|
186 | 186 | Signal is emitted when a point has been removed from \a index. |
|
187 | 187 | \sa remove() |
|
188 | 188 | */ |
|
189 | 189 | /*! |
|
190 | 190 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
191 | 191 | Signal is emitted when a point has been removed from \a index. |
|
192 | 192 | */ |
|
193 | 193 | |
|
194 | 194 | /*! |
|
195 | 195 | \fn void QXYSeries::colorChanged(QColor color) |
|
196 | 196 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
197 | 197 | */ |
|
198 | 198 | /*! |
|
199 | 199 | \qmlsignal XYSeries::onColorChanged(color color) |
|
200 | 200 | Signal is emitted when the line (pen) color has changed to \a color. |
|
201 | 201 | */ |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | \fn void QXYSeriesPrivate::updated() |
|
205 | 205 | \brief \internal |
|
206 | 206 | */ |
|
207 | 207 | |
|
208 | 208 | /*! |
|
209 | 209 | \qmlmethod XYSeries::append(real x, real y) |
|
210 | 210 | Append point (\a x, \a y) to the series |
|
211 | 211 | */ |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
215 | 215 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
216 | 216 | exist. |
|
217 | 217 | */ |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | \qmlmethod XYSeries::remove(real x, real y) |
|
221 | 221 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
222 | 222 | */ |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
226 | 226 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
227 | 227 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
228 | 228 | */ |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | \qmlmethod QPointF XYSeries::at(int index) |
|
232 | 232 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
233 | 233 | */ |
|
234 | 234 | |
|
235 | 235 | /*! |
|
236 | 236 | \internal |
|
237 | 237 | |
|
238 | 238 | Constructs empty series object which is a child of \a parent. |
|
239 | 239 | When series object is added to QChart instance ownerships is transferred. |
|
240 | 240 | */ |
|
241 | 241 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) |
|
242 | 242 | : QAbstractSeries(d, parent) |
|
243 | 243 | { |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | /*! |
|
247 | 247 | Destroys the object. Series added to QChart instances are owned by those, |
|
248 | 248 | and are destroyed when QChart instances are destroyed. |
|
249 | 249 | */ |
|
250 | 250 | QXYSeries::~QXYSeries() |
|
251 | 251 | { |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | /*! |
|
255 | 255 | Adds data point (\a x, \a y) to the series. |
|
256 | 256 | */ |
|
257 | 257 | void QXYSeries::append(qreal x, qreal y) |
|
258 | 258 | { |
|
259 | 259 | append(QPointF(x, y)); |
|
260 | 260 | } |
|
261 | 261 | |
|
262 | 262 | /*! |
|
263 | 263 | This is an overloaded function. |
|
264 | 264 | Adds data \a point to the series. |
|
265 | 265 | */ |
|
266 | 266 | void QXYSeries::append(const QPointF &point) |
|
267 | 267 | { |
|
268 | 268 | Q_D(QXYSeries); |
|
269 | 269 | |
|
270 | 270 | if (isValidValue(point)) { |
|
271 | 271 | d->m_points << point; |
|
272 | 272 | emit pointAdded(d->m_points.count() - 1); |
|
273 | 273 | } |
|
274 | 274 | } |
|
275 | 275 | |
|
276 | 276 | /*! |
|
277 | 277 | This is an overloaded function. |
|
278 | 278 | Adds list of data \a points to the series. |
|
279 | 279 | */ |
|
280 | 280 | void QXYSeries::append(const QList<QPointF> &points) |
|
281 | 281 | { |
|
282 | 282 | foreach (const QPointF &point , points) |
|
283 | 283 | append(point); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | /*! |
|
287 | 287 | Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY). |
|
288 | 288 | \sa QXYSeries::pointReplaced() |
|
289 | 289 | */ |
|
290 | 290 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) |
|
291 | 291 | { |
|
292 | 292 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | /*! |
|
296 | 296 | Replaces \a oldPoint with \a newPoint. |
|
297 | 297 | \sa QXYSeries::pointReplaced() |
|
298 | 298 | */ |
|
299 | 299 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) |
|
300 | 300 | { |
|
301 | 301 | Q_D(QXYSeries); |
|
302 | 302 | int index = d->m_points.indexOf(oldPoint); |
|
303 | 303 | if (index == -1) |
|
304 | 304 | return; |
|
305 | 305 | replace(index, newPoint); |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | /*! |
|
309 | 309 | Replaces the point at \a index with data point (\a newX, \a newY). |
|
310 | 310 | \sa QXYSeries::pointReplaced() |
|
311 | 311 | */ |
|
312 | 312 | void QXYSeries::replace(int index, qreal newX, qreal newY) |
|
313 | 313 | { |
|
314 | 314 | replace(index, QPointF(newX, newY)); |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | Replaces the point at \a index with \a newPoint. |
|
319 | 319 | \sa QXYSeries::pointReplaced() |
|
320 | 320 | */ |
|
321 | 321 | void QXYSeries::replace(int index, const QPointF &newPoint) |
|
322 | 322 | { |
|
323 | 323 | Q_D(QXYSeries); |
|
324 | 324 | if (isValidValue(newPoint)) { |
|
325 | 325 | d->m_points[index] = newPoint; |
|
326 | 326 | emit pointReplaced(index); |
|
327 | 327 | } |
|
328 | 328 | } |
|
329 | 329 | |
|
330 | 330 | /*! |
|
331 | 331 | Replaces the current points with \a points. |
|
332 | 332 | \note This is much faster than replacing data points one by one, |
|
333 | 333 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() |
|
334 | 334 | when the points have been replaced. |
|
335 | 335 | \sa QXYSeries::pointsReplaced() |
|
336 | 336 | */ |
|
337 | 337 | void QXYSeries::replace(QList<QPointF> points) |
|
338 | 338 | { |
|
339 | 339 | Q_D(QXYSeries); |
|
340 | 340 | d->m_points = points.toVector(); |
|
341 | 341 | emit pointsReplaced(); |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | /*! |
|
345 | 345 | Removes the point (\a x, \a y) from the series. |
|
346 | 346 | */ |
|
347 | 347 | void QXYSeries::remove(qreal x, qreal y) |
|
348 | 348 | { |
|
349 | 349 | remove(QPointF(x, y)); |
|
350 | 350 | } |
|
351 | 351 | |
|
352 | 352 | /*! |
|
353 | 353 | Removes the \a point from the series. |
|
354 | 354 | */ |
|
355 | 355 | void QXYSeries::remove(const QPointF &point) |
|
356 | 356 | { |
|
357 | 357 | Q_D(QXYSeries); |
|
358 | 358 | int index = d->m_points.indexOf(point); |
|
359 | 359 | if (index == -1) |
|
360 | 360 | return; |
|
361 | 361 | remove(index); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | /*! |
|
365 | 365 | Removes the point at \a index from the series. |
|
366 | 366 | */ |
|
367 | 367 | void QXYSeries::remove(int index) |
|
368 | 368 | { |
|
369 | 369 | Q_D(QXYSeries); |
|
370 | 370 | d->m_points.remove(index); |
|
371 | 371 | emit pointRemoved(index); |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | /*! |
|
375 | 375 | Inserts a \a point in the series at \a index position. |
|
376 | 376 | */ |
|
377 | 377 | void QXYSeries::insert(int index, const QPointF &point) |
|
378 | 378 | { |
|
379 | 379 | Q_D(QXYSeries); |
|
380 | 380 | if (isValidValue(point)) { |
|
381 | 381 | d->m_points.insert(index, point); |
|
382 | 382 | emit pointAdded(index); |
|
383 | 383 | } |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | /*! |
|
387 | 387 | Removes all points from the series. |
|
388 | 388 | */ |
|
389 | 389 | void QXYSeries::clear() |
|
390 | 390 | { |
|
391 | 391 | Q_D(QXYSeries); |
|
392 | 392 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
393 | 393 | remove(d->m_points.at(i)); |
|
394 | 394 | } |
|
395 | 395 | |
|
396 | 396 | /*! |
|
397 | 397 | Returns list of points in the series. |
|
398 | 398 | */ |
|
399 | 399 | QList<QPointF> QXYSeries::points() const |
|
400 | 400 | { |
|
401 | 401 | Q_D(const QXYSeries); |
|
402 | 402 | return d->m_points.toList(); |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | /*! |
|
406 | 406 | Returns point at \a index in internal points vector. |
|
407 | 407 | */ |
|
408 | 408 | const QPointF &QXYSeries::at(int index) const |
|
409 | 409 | { |
|
410 | 410 | Q_D(const QXYSeries); |
|
411 | 411 | return d->m_points.at(index); |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | /*! |
|
415 | 415 | Returns number of data points within series. |
|
416 | 416 | */ |
|
417 | 417 | int QXYSeries::count() const |
|
418 | 418 | { |
|
419 | 419 | Q_D(const QXYSeries); |
|
420 | 420 | return d->m_points.count(); |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | |
|
424 | 424 | /*! |
|
425 | 425 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
426 | 426 | pen from chart theme is used. |
|
427 | 427 | \sa QChart::setTheme() |
|
428 | 428 | */ |
|
429 | 429 | void QXYSeries::setPen(const QPen &pen) |
|
430 | 430 | { |
|
431 | 431 | Q_D(QXYSeries); |
|
432 | 432 | if (d->m_pen != pen) { |
|
433 | 433 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
434 | 434 | d->m_pen = pen; |
|
435 | 435 | emit d->updated(); |
|
436 | 436 | if (emitColorChanged) |
|
437 | 437 | emit colorChanged(pen.color()); |
|
438 | 438 | } |
|
439 | 439 | } |
|
440 | 440 | |
|
441 | 441 | QPen QXYSeries::pen() const |
|
442 | 442 | { |
|
443 | 443 | Q_D(const QXYSeries); |
|
444 | 444 | if (d->m_pen == QChartPrivate::defaultPen()) |
|
445 | 445 | return QPen(); |
|
446 | 446 | else |
|
447 | 447 | return d->m_pen; |
|
448 | 448 | } |
|
449 | 449 | |
|
450 | 450 | /*! |
|
451 | 451 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
452 | 452 | from chart theme setting is used. |
|
453 | 453 | \sa QChart::setTheme() |
|
454 | 454 | */ |
|
455 | 455 | void QXYSeries::setBrush(const QBrush &brush) |
|
456 | 456 | { |
|
457 | 457 | Q_D(QXYSeries); |
|
458 | 458 | if (d->m_brush != brush) { |
|
459 | 459 | d->m_brush = brush; |
|
460 | 460 | emit d->updated(); |
|
461 | 461 | } |
|
462 | 462 | } |
|
463 | 463 | |
|
464 | 464 | QBrush QXYSeries::brush() const |
|
465 | 465 | { |
|
466 | 466 | Q_D(const QXYSeries); |
|
467 | 467 | if (d->m_brush == QChartPrivate::defaultBrush()) |
|
468 | 468 | return QBrush(); |
|
469 | 469 | else |
|
470 | 470 | return d->m_brush; |
|
471 | 471 | } |
|
472 | 472 | |
|
473 | 473 | void QXYSeries::setColor(const QColor &color) |
|
474 | 474 | { |
|
475 | 475 | QPen p = pen(); |
|
476 | 476 | if (p.color() != color) { |
|
477 | 477 | p.setColor(color); |
|
478 | 478 | setPen(p); |
|
479 | 479 | } |
|
480 | 480 | } |
|
481 | 481 | |
|
482 | 482 | QColor QXYSeries::color() const |
|
483 | 483 | { |
|
484 | 484 | return pen().color(); |
|
485 | 485 | } |
|
486 | 486 | |
|
487 | 487 | void QXYSeries::setPointsVisible(bool visible) |
|
488 | 488 | { |
|
489 | 489 | Q_D(QXYSeries); |
|
490 | 490 | if (d->m_pointsVisible != visible) { |
|
491 | 491 | d->m_pointsVisible = visible; |
|
492 | 492 | emit d->updated(); |
|
493 | 493 | } |
|
494 | 494 | } |
|
495 | 495 | |
|
496 | 496 | bool QXYSeries::pointsVisible() const |
|
497 | 497 | { |
|
498 | 498 | Q_D(const QXYSeries); |
|
499 | 499 | return d->m_pointsVisible; |
|
500 | 500 | } |
|
501 | 501 | |
|
502 | 502 | |
|
503 | 503 | /*! |
|
504 | 504 | Stream operator for adding a data \a point to the series. |
|
505 | 505 | \sa append() |
|
506 | 506 | */ |
|
507 | 507 | QXYSeries &QXYSeries::operator<< (const QPointF &point) |
|
508 | 508 | { |
|
509 | 509 | append(point); |
|
510 | 510 | return *this; |
|
511 | 511 | } |
|
512 | 512 | |
|
513 | 513 | |
|
514 | 514 | /*! |
|
515 | 515 | Stream operator for adding a list of \a points to the series. |
|
516 | 516 | \sa append() |
|
517 | 517 | */ |
|
518 | 518 | |
|
519 | 519 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) |
|
520 | 520 | { |
|
521 | 521 | append(points); |
|
522 | 522 | return *this; |
|
523 | 523 | } |
|
524 | 524 | |
|
525 | 525 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
526 | 526 | |
|
527 | 527 | |
|
528 | 528 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) |
|
529 | 529 | : QAbstractSeriesPrivate(q), |
|
530 | 530 | m_pen(QChartPrivate::defaultPen()), |
|
531 | 531 | m_brush(QChartPrivate::defaultBrush()), |
|
532 | 532 | m_pointsVisible(false) |
|
533 | 533 | { |
|
534 | 534 | } |
|
535 | 535 | |
|
536 | 536 | void QXYSeriesPrivate::initializeDomain() |
|
537 | 537 | { |
|
538 | 538 | qreal minX(0); |
|
539 | 539 | qreal minY(0); |
|
540 | 540 | qreal maxX(1); |
|
541 | 541 | qreal maxY(1); |
|
542 | 542 | |
|
543 | 543 | Q_Q(QXYSeries); |
|
544 | 544 | |
|
545 | 545 | const QList<QPointF>& points = q->points(); |
|
546 | 546 | |
|
547 | 547 | if (!points.isEmpty()) { |
|
548 | 548 | minX = points[0].x(); |
|
549 | 549 | minY = points[0].y(); |
|
550 | 550 | maxX = minX; |
|
551 | 551 | maxY = minY; |
|
552 | 552 | |
|
553 | 553 | for (int i = 0; i < points.count(); i++) { |
|
554 | 554 | qreal x = points[i].x(); |
|
555 | 555 | qreal y = points[i].y(); |
|
556 | 556 | minX = qMin(minX, x); |
|
557 | 557 | minY = qMin(minY, y); |
|
558 | 558 | maxX = qMax(maxX, x); |
|
559 | 559 | maxY = qMax(maxY, y); |
|
560 | 560 | } |
|
561 | 561 | } |
|
562 | 562 | |
|
563 | 563 | domain()->setRange(minX, maxX, minY, maxY); |
|
564 | 564 | } |
|
565 | 565 | |
|
566 | 566 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
567 | 567 | { |
|
568 | 568 | Q_Q(QXYSeries); |
|
569 | 569 | QList<QLegendMarker*> list; |
|
570 | 570 | return list << new QXYLegendMarker(q,legend); |
|
571 | 571 | } |
|
572 | 572 | |
|
573 | 573 | void QXYSeriesPrivate::initializeAxes() |
|
574 | 574 | { |
|
575 | 575 | |
|
576 | 576 | } |
|
577 | 577 | |
|
578 | 578 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
579 | 579 | { |
|
580 | 580 | Q_UNUSED(orientation); |
|
581 | 581 | return QAbstractAxis::AxisTypeValue; |
|
582 | 582 | } |
|
583 | 583 | |
|
584 | 584 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
585 | 585 | { |
|
586 | 586 | Q_UNUSED(orientation); |
|
587 | 587 | return new QValueAxis; |
|
588 | 588 | } |
|
589 | 589 | |
|
590 | 590 | void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
591 | 591 | { |
|
592 | 592 | XYChart *item = static_cast<XYChart *>(m_item.data()); |
|
593 | 593 | Q_ASSERT(item); |
|
594 | 594 | if (item->animation()) |
|
595 | 595 | item->animation()->stopAndDestroyLater(); |
|
596 | 596 | |
|
597 | 597 | if (options.testFlag(QChart::SeriesAnimations)) |
|
598 | 598 | item->setAnimation(new XYAnimation(item)); |
|
599 | 599 | else |
|
600 | 600 | item->setAnimation(0); |
|
601 | 601 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
602 | 602 | } |
|
603 | 603 | |
|
604 | 604 | #include "moc_qxyseries.cpp" |
|
605 | 605 | #include "moc_qxyseries_p.cpp" |
|
606 | 606 | |
|
607 | 607 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now