@@ -0,0 +1,114 | |||
|
1 | /*! | |
|
2 | \qmlclass Font QFont | |
|
3 | \brief Defines the font used for drawing text. | |
|
4 | ||
|
5 | Font instantiates the C++ class QFont | |
|
6 | */ | |
|
7 | ||
|
8 | // NOTE: This is a copy-paste from: | |
|
9 | // <qt dir>\src\declarative\graphicsitems\qdeclarativetext.cpp | |
|
10 | ||
|
11 | /*! | |
|
12 | \qmlproperty string Font::family | |
|
13 | ||
|
14 | Sets the family name of the font. | |
|
15 | ||
|
16 | The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]". | |
|
17 | If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen. | |
|
18 | If the family isn't available a family will be set using the font matching algorithm. | |
|
19 | */ | |
|
20 | ||
|
21 | /*! | |
|
22 | \qmlproperty bool Font::bold | |
|
23 | ||
|
24 | Sets whether the font weight is bold. | |
|
25 | */ | |
|
26 | ||
|
27 | /*! | |
|
28 | \qmlproperty enumeration Font::weight | |
|
29 | ||
|
30 | Sets the font's weight. | |
|
31 | ||
|
32 | The weight can be one of: | |
|
33 | \list | |
|
34 | \o Font.Light | |
|
35 | \o Font.Normal - the default | |
|
36 | \o Font.DemiBold | |
|
37 | \o Font.Bold | |
|
38 | \o Font.Black | |
|
39 | \endlist | |
|
40 | ||
|
41 | \qml | |
|
42 | Text { text: "Hello"; font.weight: Font.DemiBold } | |
|
43 | \endqml | |
|
44 | */ | |
|
45 | ||
|
46 | /*! | |
|
47 | \qmlproperty bool Font::italic | |
|
48 | ||
|
49 | Sets whether the font has an italic style. | |
|
50 | */ | |
|
51 | ||
|
52 | /*! | |
|
53 | \qmlproperty bool Font::underline | |
|
54 | ||
|
55 | Sets whether the text is underlined. | |
|
56 | */ | |
|
57 | ||
|
58 | /*! | |
|
59 | \qmlproperty bool Font::strikeout | |
|
60 | ||
|
61 | Sets whether the font has a strikeout style. | |
|
62 | */ | |
|
63 | ||
|
64 | /*! | |
|
65 | \qmlproperty real Font::pointSize | |
|
66 | ||
|
67 | Sets the font size in points. The point size must be greater than zero. | |
|
68 | */ | |
|
69 | ||
|
70 | /*! | |
|
71 | \qmlproperty int Font::pixelSize | |
|
72 | ||
|
73 | Sets the font size in pixels. | |
|
74 | ||
|
75 | Using this function makes the font device dependent. | |
|
76 | Use \c pointSize to set the size of the font in a device independent manner. | |
|
77 | */ | |
|
78 | ||
|
79 | /*! | |
|
80 | \qmlproperty real Font::letterSpacing | |
|
81 | ||
|
82 | Sets the letter spacing for the font. | |
|
83 | ||
|
84 | Letter spacing changes the default spacing between individual letters in the font. | |
|
85 | A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing. | |
|
86 | */ | |
|
87 | ||
|
88 | /*! | |
|
89 | \qmlproperty real Font::wordSpacing | |
|
90 | ||
|
91 | Sets the word spacing for the font. | |
|
92 | ||
|
93 | Word spacing changes the default spacing between individual words. | |
|
94 | A positive value increases the word spacing by a corresponding amount of pixels, | |
|
95 | while a negative value decreases the inter-word spacing accordingly. | |
|
96 | */ | |
|
97 | ||
|
98 | /*! | |
|
99 | \qmlproperty enumeration Font::capitalization | |
|
100 | ||
|
101 | Sets the capitalization for the text. | |
|
102 | ||
|
103 | \list | |
|
104 | \o Font.MixedCase - This is the normal text rendering option where no capitalization change is applied. | |
|
105 | \o Font.AllUppercase - This alters the text to be rendered in all uppercase type. | |
|
106 | \o Font.AllLowercase - This alters the text to be rendered in all lowercase type. | |
|
107 | \o Font.SmallCaps - This alters the text to be rendered in small-caps type. | |
|
108 | \o Font.Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. | |
|
109 | \endlist | |
|
110 | ||
|
111 | \qml | |
|
112 | Text { text: "Hello"; font.capitalization: Font.AllLowercase } | |
|
113 | \endqml | |
|
114 | */ |
@@ -1,375 +1,392 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "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 "declarativescatterseries.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \qmlclass ChartView DeclarativeChart |
|
34 | 34 | |
|
35 | 35 | ChartView element is the parent that is responsible for showing different chart series types. |
|
36 | 36 | |
|
37 | 37 | The following QML shows how to create a simple chart with one pie series: |
|
38 | 38 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
39 | 39 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
40 | 40 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
41 | 41 | |
|
42 | 42 | \beginfloatleft |
|
43 | 43 | \image examples_qmlpiechart.png |
|
44 | 44 | \endfloat |
|
45 | 45 | \clearfloat |
|
46 | 46 | */ |
|
47 | 47 | |
|
48 | 48 | /*! |
|
49 | 49 | \qmlproperty Theme ChartView::theme |
|
50 | 50 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
51 | 51 | widths and chart background. |
|
52 | 52 | */ |
|
53 | 53 | |
|
54 | 54 | /*! |
|
55 | 55 | \qmlproperty Animation ChartView::animation |
|
56 | 56 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
57 | 57 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | \qmlproperty Font ChartView::titleFont | |
|
62 | The title font of the chart | |
|
63 | ||
|
64 | See the \l {Font} {QML Font Element} for detailed documentation. | |
|
65 | */ | |
|
66 | ||
|
67 | /*! | |
|
61 | 68 | \qmlproperty string ChartView::title |
|
62 | 69 | The title of the chart, shown on top of the chart. |
|
63 | 70 | \sa ChartView::titleColor |
|
64 | 71 | */ |
|
65 | 72 | |
|
66 | 73 | /*! |
|
67 | 74 | \qmlproperty string ChartView::titleColor |
|
68 | 75 | The color of the title text. |
|
69 | 76 | */ |
|
70 | 77 | |
|
71 | 78 | /*! |
|
72 | 79 | \qmlproperty Axis ChartView::axisX |
|
73 | 80 | The x-axis of the chart. |
|
74 | 81 | */ |
|
75 | 82 | |
|
76 | 83 | /*! |
|
77 | 84 | \qmlproperty Axis ChartView::axisY |
|
78 | 85 | The default y-axis of the chart. |
|
79 | 86 | */ |
|
80 | 87 | |
|
81 | 88 | /*! |
|
82 | 89 | \qmlproperty Legend ChartView::legend |
|
83 | 90 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
84 | 91 | */ |
|
85 | 92 | |
|
86 | 93 | /*! |
|
87 | 94 | \qmlproperty int ChartView::count |
|
88 | 95 | The count of series added to the chart. |
|
89 | 96 | */ |
|
90 | 97 | |
|
91 | 98 | /*! |
|
92 | 99 | \qmlproperty color ChartView::backgroundColor |
|
93 | 100 | The color of the chart's background. By default background color is defined by chart theme. |
|
94 | 101 | \sa ChartView::theme |
|
95 | 102 | */ |
|
96 | 103 | |
|
97 | 104 | /*! |
|
98 | 105 | \qmlproperty bool ChartView::dropShadowEnabled |
|
99 | 106 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
100 | 107 | */ |
|
101 | 108 | |
|
102 | 109 | /*! |
|
103 | 110 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
104 | 111 | The y-axis of the series. This is the same as the default y-axis of the chart, unless you have |
|
105 | 112 | explicitly defined the series to have a non-default y-axis. |
|
106 | 113 | */ |
|
107 | 114 | |
|
108 | 115 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
109 | 116 | : QDeclarativeItem(parent), |
|
110 | 117 | m_chart(new QChart(this)) |
|
111 | 118 | { |
|
112 | 119 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
113 | 120 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
114 | 121 | } |
|
115 | 122 | |
|
116 | 123 | DeclarativeChart::~DeclarativeChart() |
|
117 | 124 | { |
|
118 | 125 | delete m_chart; |
|
119 | 126 | } |
|
120 | 127 | |
|
121 | 128 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
122 | 129 | { |
|
123 | 130 | if (event->type() == QEvent::ChildAdded) { |
|
124 | 131 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
125 | 132 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
126 | 133 | } |
|
127 | 134 | } |
|
128 | 135 | } |
|
129 | 136 | |
|
130 | 137 | void DeclarativeChart::componentComplete() |
|
131 | 138 | { |
|
132 | 139 | foreach(QObject *child, children()) { |
|
133 | 140 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
134 | 141 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
135 | 142 | // TODO: how about optional y-axis? |
|
136 | 143 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
137 | 144 | } |
|
138 | 145 | } |
|
139 | 146 | QDeclarativeItem::componentComplete(); |
|
140 | 147 | } |
|
141 | 148 | |
|
142 | 149 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
143 | 150 | { |
|
144 | 151 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
145 | 152 | if (newGeometry.isValid()) { |
|
146 | 153 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
147 | 154 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
148 | 155 | } |
|
149 | 156 | } |
|
150 | 157 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
151 | 158 | } |
|
152 | 159 | |
|
153 | 160 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
154 | 161 | { |
|
155 | 162 | Q_UNUSED(option) |
|
156 | 163 | Q_UNUSED(widget) |
|
157 | 164 | |
|
158 | 165 | // TODO: optimized? |
|
159 | 166 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
160 | 167 | } |
|
161 | 168 | |
|
162 | 169 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
163 | 170 | { |
|
164 | 171 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
165 | 172 | if (chartTheme != m_chart->theme()) |
|
166 | 173 | m_chart->setTheme(chartTheme); |
|
167 | 174 | } |
|
168 | 175 | |
|
169 | 176 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
170 | 177 | { |
|
171 | 178 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
172 | 179 | } |
|
173 | 180 | |
|
174 | 181 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
175 | 182 | { |
|
176 | 183 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
177 | 184 | if (animationOptions != m_chart->animationOptions()) |
|
178 | 185 | m_chart->setAnimationOptions(animationOptions); |
|
179 | 186 | } |
|
180 | 187 | |
|
181 | 188 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
182 | 189 | { |
|
183 | 190 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
184 | 191 | return DeclarativeChart::AllAnimations; |
|
185 | 192 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
186 | 193 | return DeclarativeChart::GridAxisAnimations; |
|
187 | 194 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
188 | 195 | return DeclarativeChart::SeriesAnimations; |
|
189 | 196 | else |
|
190 | 197 | return DeclarativeChart::NoAnimation; |
|
191 | 198 | } |
|
192 | 199 | |
|
193 | 200 | void DeclarativeChart::setTitle(QString title) |
|
194 | 201 | { |
|
195 | 202 | if (title != m_chart->title()) |
|
196 | 203 | m_chart->setTitle(title); |
|
197 | 204 | } |
|
198 | 205 | QString DeclarativeChart::title() |
|
199 | 206 | { |
|
200 | 207 | return m_chart->title(); |
|
201 | 208 | } |
|
202 | 209 | |
|
203 | 210 | QAxis *DeclarativeChart::axisX() |
|
204 | 211 | { |
|
205 | 212 | return m_chart->axisX(); |
|
206 | 213 | } |
|
207 | 214 | |
|
208 | 215 | QAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
209 | 216 | { |
|
210 | 217 | return m_chart->axisY(series); |
|
211 | 218 | } |
|
212 | 219 | |
|
213 | 220 | QLegend *DeclarativeChart::legend() |
|
214 | 221 | { |
|
215 | 222 | return m_chart->legend(); |
|
216 | 223 | } |
|
217 | 224 | |
|
218 | 225 | QVariantList DeclarativeChart::axisXLabels() |
|
219 | 226 | { |
|
220 | 227 | QVariantList labels; |
|
221 | 228 | foreach (qreal value, m_chart->axisX()->categories()->values()) { |
|
222 | 229 | labels.append(value); |
|
223 | 230 | labels.append(m_chart->axisX()->categories()->label(value)); |
|
224 | 231 | } |
|
225 | 232 | return labels; |
|
226 | 233 | } |
|
227 | 234 | |
|
228 | 235 | void DeclarativeChart::setAxisXLabels(QVariantList list) |
|
229 | 236 | { |
|
230 | 237 | QVariant value(QVariant::Invalid); |
|
231 | 238 | foreach (QVariant element, list) { |
|
232 | 239 | if (value.isValid() && element.type() == QVariant::String) { |
|
233 | 240 | m_chart->axisX()->categories()->insert(value.toDouble(), element.toString()); |
|
234 | 241 | value = QVariant(QVariant::Invalid); |
|
235 | 242 | } else { |
|
236 | 243 | if (element.canConvert(QVariant::Double)) |
|
237 | 244 | value = element; |
|
238 | 245 | } |
|
239 | 246 | } |
|
240 | 247 | emit axisLabelsChanged(); |
|
241 | 248 | } |
|
242 | 249 | |
|
243 | 250 | void DeclarativeChart::setTitleColor(QColor color) |
|
244 | 251 | { |
|
245 | 252 | QBrush b = m_chart->titleBrush(); |
|
246 | 253 | if (color != b.color()) { |
|
247 | 254 | b.setColor(color); |
|
248 | 255 | m_chart->setTitleBrush(b); |
|
249 | 256 | emit titleColorChanged(); |
|
250 | 257 | } |
|
251 | 258 | } |
|
252 | 259 | |
|
260 | QFont DeclarativeChart::titleFont() const | |
|
261 | { | |
|
262 | return m_chart->titleFont(); | |
|
263 | } | |
|
264 | ||
|
265 | void DeclarativeChart::setTitleFont(const QFont& font) | |
|
266 | { | |
|
267 | m_chart->setTitleFont(font); | |
|
268 | } | |
|
269 | ||
|
253 | 270 | QColor DeclarativeChart::titleColor() |
|
254 | 271 | { |
|
255 | 272 | return m_chart->titleBrush().color(); |
|
256 | 273 | } |
|
257 | 274 | |
|
258 | 275 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
259 | 276 | { |
|
260 | 277 | QBrush b = m_chart->backgroundBrush(); |
|
261 | 278 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
262 | 279 | b.setStyle(Qt::SolidPattern); |
|
263 | 280 | b.setColor(color); |
|
264 | 281 | m_chart->setBackgroundBrush(b); |
|
265 | 282 | emit backgroundColorChanged(); |
|
266 | 283 | } |
|
267 | 284 | } |
|
268 | 285 | |
|
269 | 286 | QColor DeclarativeChart::backgroundColor() |
|
270 | 287 | { |
|
271 | 288 | return m_chart->backgroundBrush().color(); |
|
272 | 289 | } |
|
273 | 290 | |
|
274 | 291 | int DeclarativeChart::count() |
|
275 | 292 | { |
|
276 | 293 | return m_chart->series().count(); |
|
277 | 294 | } |
|
278 | 295 | |
|
279 | 296 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
280 | 297 | { |
|
281 | 298 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
282 | 299 | m_chart->setDropShadowEnabled(enabled); |
|
283 | 300 | dropShadowEnabledChanged(enabled); |
|
284 | 301 | } |
|
285 | 302 | } |
|
286 | 303 | |
|
287 | 304 | bool DeclarativeChart::dropShadowEnabled() |
|
288 | 305 | { |
|
289 | 306 | return m_chart->isDropShadowEnabled(); |
|
290 | 307 | } |
|
291 | 308 | |
|
292 | 309 | void DeclarativeChart::zoom(qreal factor) |
|
293 | 310 | { |
|
294 | 311 | m_chart->zoom(factor); |
|
295 | 312 | } |
|
296 | 313 | |
|
297 | 314 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
298 | 315 | { |
|
299 | 316 | m_chart->scroll(QPointF(pixels, 0)); |
|
300 | 317 | } |
|
301 | 318 | |
|
302 | 319 | void DeclarativeChart::scrollRight(qreal pixels) |
|
303 | 320 | { |
|
304 | 321 | m_chart->scroll(QPointF(-pixels, 0)); |
|
305 | 322 | } |
|
306 | 323 | |
|
307 | 324 | void DeclarativeChart::scrollUp(qreal pixels) |
|
308 | 325 | { |
|
309 | 326 | m_chart->scroll(QPointF(0, pixels)); |
|
310 | 327 | } |
|
311 | 328 | |
|
312 | 329 | void DeclarativeChart::scrollDown(qreal pixels) |
|
313 | 330 | { |
|
314 | 331 | m_chart->scroll(QPointF(0, -pixels)); |
|
315 | 332 | } |
|
316 | 333 | |
|
317 | 334 | QAbstractSeries *DeclarativeChart::series(int index) |
|
318 | 335 | { |
|
319 | 336 | if (index < m_chart->series().count()) { |
|
320 | 337 | return m_chart->series().at(index); |
|
321 | 338 | } |
|
322 | 339 | return 0; |
|
323 | 340 | } |
|
324 | 341 | |
|
325 | 342 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
326 | 343 | { |
|
327 | 344 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
328 | 345 | if (series->name() == seriesName) |
|
329 | 346 | return series; |
|
330 | 347 | } |
|
331 | 348 | return 0; |
|
332 | 349 | } |
|
333 | 350 | |
|
334 | 351 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
335 | 352 | { |
|
336 | 353 | QAbstractSeries *series = 0; |
|
337 | 354 | switch (type) { |
|
338 | 355 | case DeclarativeChart::SeriesTypeLine: |
|
339 | 356 | series = new DeclarativeLineSeries(); |
|
340 | 357 | break; |
|
341 | 358 | case DeclarativeChart::SeriesTypeArea: |
|
342 | 359 | series = new DeclarativeAreaSeries(); |
|
343 | 360 | break; |
|
344 | 361 | case DeclarativeChart::SeriesTypeBar: |
|
345 | 362 | series = new DeclarativeBarSeries(); |
|
346 | 363 | break; |
|
347 | 364 | case DeclarativeChart::SeriesTypeStackedBar: |
|
348 | 365 | // TODO |
|
349 | 366 | break; |
|
350 | 367 | case DeclarativeChart::SeriesTypePercentBar: |
|
351 | 368 | // TODO |
|
352 | 369 | break; |
|
353 | 370 | case DeclarativeChart::SeriesTypeGroupedBar: |
|
354 | 371 | series = new DeclarativeGroupedBarSeries(); |
|
355 | 372 | break; |
|
356 | 373 | case DeclarativeChart::SeriesTypePie: |
|
357 | 374 | series = new DeclarativePieSeries(); |
|
358 | 375 | break; |
|
359 | 376 | case DeclarativeChart::SeriesTypeScatter: |
|
360 | 377 | series = new DeclarativeScatterSeries(); |
|
361 | 378 | break; |
|
362 | 379 | case DeclarativeChart::SeriesTypeSpline: |
|
363 | 380 | series = new DeclarativeSplineSeries(); |
|
364 | 381 | break; |
|
365 | 382 | default: |
|
366 | 383 | qWarning() << "Illegal series type"; |
|
367 | 384 | } |
|
368 | 385 | series->setName(name); |
|
369 | 386 | m_chart->addSeries(series); |
|
370 | 387 | return series; |
|
371 | 388 | } |
|
372 | 389 | |
|
373 | 390 | #include "moc_declarativechart.cpp" |
|
374 | 391 | |
|
375 | 392 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,136 +1,139 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVECHART_H |
|
22 | 22 | #define DECLARATIVECHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QtCore/QtGlobal> |
|
25 | 25 | #include <QDeclarativeItem> |
|
26 | 26 | #include <qchart.h> |
|
27 | 27 | #include <QAxis> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | // TODO: Derive from QChart for easier definition of properties? |
|
32 | 32 | class DeclarativeChart : public QDeclarativeItem |
|
33 | 33 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
34 | 34 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
38 | 38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
39 | 39 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
40 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) | |
|
40 | 41 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
41 | 42 | Q_PROPERTY(QAxis *axisX READ axisX) |
|
42 | 43 | Q_PROPERTY(QAxis *axisY READ axisY) |
|
43 | 44 | Q_PROPERTY(QLegend *legend READ legend) |
|
44 | 45 | // TODO: how to define axis labels? This is not very convenient |
|
45 | 46 | Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged) |
|
46 | 47 | Q_PROPERTY(int count READ count) |
|
47 | 48 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
48 | 49 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
49 | 50 | Q_ENUMS(Animation) |
|
50 | 51 | Q_ENUMS(Theme) |
|
51 | 52 | Q_ENUMS(SeriesType) |
|
52 | 53 | |
|
53 | 54 | public: |
|
54 | 55 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
55 | 56 | enum Theme { |
|
56 | 57 | ChartThemeLight = 0, |
|
57 | 58 | ChartThemeBlueCerulean, |
|
58 | 59 | ChartThemeDark, |
|
59 | 60 | ChartThemeBrownSand, |
|
60 | 61 | ChartThemeBlueNcs, |
|
61 | 62 | ChartThemeHighContrast, |
|
62 | 63 | ChartThemeBlueIcy |
|
63 | 64 | }; |
|
64 | 65 | |
|
65 | 66 | enum Animation { |
|
66 | 67 | NoAnimation = 0x0, |
|
67 | 68 | GridAxisAnimations = 0x1, |
|
68 | 69 | SeriesAnimations =0x2, |
|
69 | 70 | AllAnimations = 0x3 |
|
70 | 71 | }; |
|
71 | 72 | |
|
72 | 73 | enum SeriesType { |
|
73 | 74 | SeriesTypeLine, |
|
74 | 75 | SeriesTypeArea, |
|
75 | 76 | SeriesTypeBar, |
|
76 | 77 | SeriesTypeStackedBar, |
|
77 | 78 | SeriesTypePercentBar, |
|
78 | 79 | SeriesTypeGroupedBar, |
|
79 | 80 | SeriesTypePie, |
|
80 | 81 | SeriesTypeScatter, |
|
81 | 82 | SeriesTypeSpline |
|
82 | 83 | }; |
|
83 | 84 | |
|
84 | 85 | public: |
|
85 | 86 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
86 | 87 | ~DeclarativeChart(); |
|
87 | 88 | |
|
88 | 89 | public: // From QDeclarativeItem/QGraphicsItem |
|
89 | 90 | void childEvent(QChildEvent *event); |
|
90 | 91 | void componentComplete(); |
|
91 | 92 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
92 | 93 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
93 | 94 | |
|
94 | 95 | public: |
|
95 | 96 | void setTheme(DeclarativeChart::Theme theme); |
|
96 | 97 | DeclarativeChart::Theme theme(); |
|
97 | 98 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
98 | 99 | DeclarativeChart::Animation animationOptions(); |
|
99 | 100 | void setTitle(QString title); |
|
100 | 101 | QString title(); |
|
101 | 102 | QAxis *axisX(); |
|
102 | 103 | Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0); |
|
103 | 104 | QLegend *legend(); |
|
104 | 105 | QVariantList axisXLabels(); |
|
105 | 106 | void setAxisXLabels(QVariantList list); |
|
107 | QFont titleFont() const; | |
|
108 | void setTitleFont(const QFont& font); | |
|
106 | 109 | void setTitleColor(QColor color); |
|
107 | 110 | QColor titleColor(); |
|
108 | 111 | void setBackgroundColor(QColor color); |
|
109 | 112 | QColor backgroundColor(); |
|
110 | 113 | int count(); |
|
111 | 114 | void setDropShadowEnabled(bool enabled); |
|
112 | 115 | bool dropShadowEnabled(); |
|
113 | 116 | Q_INVOKABLE void zoom(qreal factor); |
|
114 | 117 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
115 | 118 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
116 | 119 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
117 | 120 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
118 | 121 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
119 | 122 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
120 | 123 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
121 | 124 | |
|
122 | 125 | Q_SIGNALS: |
|
123 | 126 | void axisLabelsChanged(); |
|
124 | 127 | void titleColorChanged(); |
|
125 | 128 | void backgroundColorChanged(); |
|
126 | 129 | void dropShadowEnabledChanged(bool enabled); |
|
127 | 130 | |
|
128 | 131 | public: |
|
129 | 132 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
130 | 133 | // multi inheritance, so we now have a QChart as a member instead |
|
131 | 134 | QChart *m_chart; |
|
132 | 135 | }; |
|
133 | 136 | |
|
134 | 137 | QTCOMMERCIALCHART_END_NAMESPACE |
|
135 | 138 | |
|
136 | 139 | #endif // DECLARATIVECHART_H |
@@ -1,654 +1,665 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qaxis.h" |
|
22 | 22 | #include "qaxis_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QAxis |
|
28 | 28 | \brief The QAxis class is used for manipulating chart's axis |
|
29 | 29 | and for adding optional axes to the chart. |
|
30 | 30 | \mainclass |
|
31 | 31 | |
|
32 | 32 | There is only one x Axis, however there can be multiple y axes. |
|
33 | 33 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
34 | 34 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | 35 | */ |
|
36 | 36 | |
|
37 | 37 | /*! |
|
38 | 38 | \qmlclass Axis QAxis |
|
39 | 39 | \brief The Axis element is used for manipulating chart's axes |
|
40 | 40 | |
|
41 | 41 | There is only one x Axis, however there can be multiple y axes on a ChartView. |
|
42 | 42 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
43 | 43 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | 44 | |
|
45 | 45 | To access Axes you can use ChartView API. For example: |
|
46 | 46 | \code |
|
47 | 47 | ChartView { |
|
48 | 48 | axisX.min: 0 |
|
49 | 49 | axisX.max: 3 |
|
50 | 50 | axisX.ticksCount: 4 |
|
51 | 51 | axisY.min: 0 |
|
52 | 52 | axisY.max: 4 |
|
53 | 53 | // Add a few series... |
|
54 | 54 | } |
|
55 | 55 | \endcode |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QAxis::labelsVisible |
|
60 | 60 | Defines if axis labels are visible. |
|
61 | 61 | */ |
|
62 | 62 | /*! |
|
63 | 63 | \qmlproperty bool Axis::labelsVisible |
|
64 | 64 | Defines if axis labels are visible. |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \property QAxis::min |
|
69 | 69 | Defines the minimum value on the axis. |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty real Axis::min |
|
73 | 73 | Defines the minimum value on the axis. |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \property QAxis::max |
|
78 | 78 | Defines the maximum value on the axis. |
|
79 | 79 | */ |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty real Axis::max |
|
82 | 82 | Defines the maximum value on the axis. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QAxis::visible |
|
87 | 87 | The visibility of the axis. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty bool Axis::visible |
|
91 | 91 | The visibility of the axis. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QAxis::gridVisible |
|
96 | 96 | The visibility of the grid lines. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty bool Axis::gridVisible |
|
100 | 100 | The visibility of the grid lines. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \property QAxis::color |
|
105 | 105 | The color of the axis and ticks. |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty color Axis::color |
|
109 | 109 | The color of the axis and ticks. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | \property QAxis::labelsFont | |
|
114 | The font of the axis labels. | |
|
115 | */ | |
|
116 | /*! | |
|
117 | \qmlproperty Font Axis::labelsFont | |
|
118 | The font of the axis labels. | |
|
119 | ||
|
120 | See the \l {Font} {QML Font Element} for detailed documentation. | |
|
121 | */ | |
|
122 | ||
|
123 | /*! | |
|
113 | 124 | \property QAxis::labelsColor |
|
114 | 125 | The color of the axis labels. |
|
115 | 126 | */ |
|
116 | 127 | /*! |
|
117 | 128 | \qmlproperty color Axis::labelsColor |
|
118 | 129 | The color of the axis labels. |
|
119 | 130 | */ |
|
120 | 131 | |
|
121 | 132 | /*! |
|
122 | 133 | \property QAxis::labelsAngle |
|
123 | 134 | The angle of the axis labels in degrees. |
|
124 | 135 | */ |
|
125 | 136 | /*! |
|
126 | 137 | \qmlproperty int Axis::labelsAngle |
|
127 | 138 | The angle of the axis labels in degrees. |
|
128 | 139 | */ |
|
129 | 140 | |
|
130 | 141 | /*! |
|
131 | 142 | \property QAxis::shadesVisible |
|
132 | 143 | The visibility of the axis shades. |
|
133 | 144 | */ |
|
134 | 145 | /*! |
|
135 | 146 | \qmlproperty bool Axis::shadesVisible |
|
136 | 147 | The visibility of the axis shades. |
|
137 | 148 | */ |
|
138 | 149 | |
|
139 | 150 | /*! |
|
140 | 151 | \property QAxis::shadesColor |
|
141 | 152 | The fill (brush) color of the axis shades. |
|
142 | 153 | */ |
|
143 | 154 | /*! |
|
144 | 155 | \qmlproperty color Axis::shadesColor |
|
145 | 156 | The fill (brush) color of the axis shades. |
|
146 | 157 | */ |
|
147 | 158 | |
|
148 | 159 | /*! |
|
149 | 160 | \property QAxis::shadesBorderColor |
|
150 | 161 | The border (pen) color of the axis shades. |
|
151 | 162 | */ |
|
152 | 163 | /*! |
|
153 | 164 | \qmlproperty color Axis::shadesBorderColor |
|
154 | 165 | The border (pen) color of the axis shades. |
|
155 | 166 | */ |
|
156 | 167 | |
|
157 | 168 | /*! |
|
158 | 169 | \property QAxis::ticksCount |
|
159 | 170 | The number of tick marks for the axis. |
|
160 | 171 | */ |
|
161 | 172 | /*! |
|
162 | 173 | \qmlproperty int Axis::ticksCount |
|
163 | 174 | The number of tick marks for the axis. |
|
164 | 175 | */ |
|
165 | 176 | |
|
166 | 177 | /*! |
|
167 | 178 | \property QAxis::niceNumbersEnabled |
|
168 | 179 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
169 | 180 | */ |
|
170 | 181 | /*! |
|
171 | 182 | \qmlproperty bool Axis::niceNumbersEnabled |
|
172 | 183 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
173 | 184 | */ |
|
174 | 185 | |
|
175 | 186 | /*! |
|
176 | 187 | \fn void QAxis::visibleChanged(bool) |
|
177 | 188 | Visiblity of the axis has changed to \a visible. |
|
178 | 189 | */ |
|
179 | 190 | |
|
180 | 191 | /*! |
|
181 | 192 | \fn void QAxis::labelsVisibleChanged(bool) |
|
182 | 193 | Visiblity of the labels of the axis has changed to \a visible. |
|
183 | 194 | */ |
|
184 | 195 | |
|
185 | 196 | /*! |
|
186 | 197 | \fn void QAxis::gridVisibleChanged(bool) |
|
187 | 198 | Visiblity of the grid lines of the axis has changed to \a visible. |
|
188 | 199 | */ |
|
189 | 200 | |
|
190 | 201 | /*! |
|
191 | 202 | \fn void QAxis::minChanged(qreal min) |
|
192 | 203 | Axis emits signal when \a min of axis has changed. |
|
193 | 204 | */ |
|
194 | 205 | |
|
195 | 206 | /*! |
|
196 | 207 | \fn void QAxis::maxChanged(qreal max) |
|
197 | 208 | Axis emits signal when \a max of axis has changed. |
|
198 | 209 | */ |
|
199 | 210 | |
|
200 | 211 | /*! |
|
201 | 212 | \fn void QAxis::rangeChanged(qreal min, qreal max) |
|
202 | 213 | Axis emits signal when \a min or \a max of axis has changed. |
|
203 | 214 | */ |
|
204 | 215 | |
|
205 | 216 | /*! |
|
206 | 217 | \fn QChartAxisCategories* QAxis::categories() |
|
207 | 218 | Returns pointer to the list of categories which correspond to the values on the axis. |
|
208 | 219 | */ |
|
209 | 220 | |
|
210 | 221 | /*! |
|
211 | 222 | \fn void QAxis::colorChanged(QColor) |
|
212 | 223 | Emitted if the \a color of the axis is changed. |
|
213 | 224 | */ |
|
214 | 225 | |
|
215 | 226 | /*! |
|
216 | 227 | \fn void QAxis::labelsColorChanged(QColor) |
|
217 | 228 | Emitted if the \a color of the axis labels is changed. |
|
218 | 229 | */ |
|
219 | 230 | |
|
220 | 231 | /*! |
|
221 | 232 | \fn void QAxis::shadesVisibleChanged(bool) |
|
222 | 233 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
223 | 234 | */ |
|
224 | 235 | |
|
225 | 236 | /*! |
|
226 | 237 | \fn void QAxis::shadesColorChanged(QColor) |
|
227 | 238 | Emitted if the \a color of the axis shades is changed. |
|
228 | 239 | */ |
|
229 | 240 | |
|
230 | 241 | /*! |
|
231 | 242 | \fn void QAxis::shadesBorderColorChanged(QColor) |
|
232 | 243 | Emitted if the border \a color of the axis shades is changed. |
|
233 | 244 | */ |
|
234 | 245 | |
|
235 | 246 | /*! |
|
236 | 247 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
237 | 248 | QChart when axis added. |
|
238 | 249 | */ |
|
239 | 250 | QAxis::QAxis(QObject *parent) : QObject(parent), |
|
240 | 251 | d_ptr(new QAxisPrivate(this)) |
|
241 | 252 | { |
|
242 | 253 | |
|
243 | 254 | } |
|
244 | 255 | |
|
245 | 256 | /*! |
|
246 | 257 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
247 | 258 | */ |
|
248 | 259 | |
|
249 | 260 | QAxis::~QAxis() |
|
250 | 261 | { |
|
251 | 262 | } |
|
252 | 263 | |
|
253 | 264 | /*! |
|
254 | 265 | Sets \a pen used to draw axis line and ticks. |
|
255 | 266 | */ |
|
256 | 267 | void QAxis::setAxisPen(const QPen &pen) |
|
257 | 268 | { |
|
258 | 269 | if (d_ptr->m_axisPen!=pen) { |
|
259 | 270 | d_ptr->m_axisPen = pen; |
|
260 | 271 | emit d_ptr->updated(); |
|
261 | 272 | } |
|
262 | 273 | } |
|
263 | 274 | |
|
264 | 275 | /*! |
|
265 | 276 | Returns pen used to draw axis and ticks. |
|
266 | 277 | */ |
|
267 | 278 | QPen QAxis::axisPen() const |
|
268 | 279 | { |
|
269 | 280 | return d_ptr->m_axisPen; |
|
270 | 281 | } |
|
271 | 282 | |
|
272 | 283 | void QAxis::setAxisPenColor(QColor color) |
|
273 | 284 | { |
|
274 | 285 | QPen p = d_ptr->m_axisPen; |
|
275 | 286 | if (p.color() != color) { |
|
276 | 287 | p.setColor(color); |
|
277 | 288 | setAxisPen(p); |
|
278 | 289 | emit colorChanged(color); |
|
279 | 290 | } |
|
280 | 291 | } |
|
281 | 292 | |
|
282 | 293 | QColor QAxis::axisPenColor() const |
|
283 | 294 | { |
|
284 | 295 | return d_ptr->m_axisPen.color(); |
|
285 | 296 | } |
|
286 | 297 | |
|
287 | 298 | /*! |
|
288 | 299 | Sets if axis and ticks are \a visible. |
|
289 | 300 | */ |
|
290 | 301 | void QAxis::setAxisVisible(bool visible) |
|
291 | 302 | { |
|
292 | 303 | if (d_ptr->m_axisVisible != visible) { |
|
293 | 304 | d_ptr->m_axisVisible = visible; |
|
294 | 305 | emit d_ptr->updated(); |
|
295 | 306 | emit visibleChanged(visible); |
|
296 | 307 | } |
|
297 | 308 | } |
|
298 | 309 | |
|
299 | 310 | bool QAxis::isAxisVisible() const |
|
300 | 311 | { |
|
301 | 312 | return d_ptr->m_axisVisible; |
|
302 | 313 | } |
|
303 | 314 | |
|
304 | 315 | void QAxis::setGridLineVisible(bool visible) |
|
305 | 316 | { |
|
306 | 317 | if (d_ptr->m_gridLineVisible != visible) { |
|
307 | 318 | d_ptr->m_gridLineVisible = visible; |
|
308 | 319 | emit d_ptr->updated(); |
|
309 | 320 | emit gridVisibleChanged(visible); |
|
310 | 321 | } |
|
311 | 322 | } |
|
312 | 323 | |
|
313 | 324 | bool QAxis::isGridLineVisible() const |
|
314 | 325 | { |
|
315 | 326 | return d_ptr->m_gridLineVisible; |
|
316 | 327 | } |
|
317 | 328 | |
|
318 | 329 | /*! |
|
319 | 330 | Sets \a pen used to draw grid line. |
|
320 | 331 | */ |
|
321 | 332 | void QAxis::setGridLinePen(const QPen &pen) |
|
322 | 333 | { |
|
323 | 334 | if (d_ptr->m_gridLinePen != pen) { |
|
324 | 335 | d_ptr->m_gridLinePen = pen; |
|
325 | 336 | emit d_ptr->updated(); |
|
326 | 337 | } |
|
327 | 338 | } |
|
328 | 339 | |
|
329 | 340 | /*! |
|
330 | 341 | Returns pen used to draw grid. |
|
331 | 342 | */ |
|
332 | 343 | QPen QAxis::gridLinePen() const |
|
333 | 344 | { |
|
334 | 345 | return d_ptr->m_gridLinePen; |
|
335 | 346 | } |
|
336 | 347 | |
|
337 | 348 | void QAxis::setLabelsVisible(bool visible) |
|
338 | 349 | { |
|
339 | 350 | if (d_ptr->m_labelsVisible != visible) { |
|
340 | 351 | d_ptr->m_labelsVisible = visible; |
|
341 | 352 | emit d_ptr->updated(); |
|
342 | 353 | emit labelsVisibleChanged(visible); |
|
343 | 354 | } |
|
344 | 355 | } |
|
345 | 356 | |
|
346 | 357 | bool QAxis::labelsVisible() const |
|
347 | 358 | { |
|
348 | 359 | return d_ptr->m_labelsVisible; |
|
349 | 360 | } |
|
350 | 361 | |
|
351 | 362 | /*! |
|
352 | 363 | Sets \a pen used to draw labels. |
|
353 | 364 | */ |
|
354 | 365 | void QAxis::setLabelsPen(const QPen &pen) |
|
355 | 366 | { |
|
356 | 367 | if (d_ptr->m_labelsPen != pen) { |
|
357 | 368 | d_ptr->m_labelsPen = pen; |
|
358 | 369 | emit d_ptr->updated(); |
|
359 | 370 | } |
|
360 | 371 | } |
|
361 | 372 | |
|
362 | 373 | /*! |
|
363 | 374 | Returns the pen used to labels. |
|
364 | 375 | */ |
|
365 | 376 | QPen QAxis::labelsPen() const |
|
366 | 377 | { |
|
367 | 378 | return d_ptr->m_labelsPen; |
|
368 | 379 | } |
|
369 | 380 | |
|
370 | 381 | /*! |
|
371 | 382 | Sets \a brush used to draw labels. |
|
372 | 383 | */ |
|
373 | 384 | void QAxis::setLabelsBrush(const QBrush &brush) |
|
374 | 385 | { |
|
375 | 386 | if (d_ptr->m_labelsBrush != brush) { |
|
376 | 387 | d_ptr->m_labelsBrush = brush; |
|
377 | 388 | emit d_ptr->updated(); |
|
378 | 389 | } |
|
379 | 390 | } |
|
380 | 391 | |
|
381 | 392 | /*! |
|
382 | 393 | Returns brush used to draw labels. |
|
383 | 394 | */ |
|
384 | 395 | QBrush QAxis::labelsBrush() const |
|
385 | 396 | { |
|
386 | 397 | return d_ptr->m_labelsBrush; |
|
387 | 398 | } |
|
388 | 399 | |
|
389 | 400 | /*! |
|
390 | 401 | Sets \a font used to draw labels. |
|
391 | 402 | */ |
|
392 | 403 | void QAxis::setLabelsFont(const QFont &font) |
|
393 | 404 | { |
|
394 | 405 | if (d_ptr->m_labelsFont != font) { |
|
395 | 406 | d_ptr->m_labelsFont = font; |
|
396 | 407 | emit d_ptr->updated(); |
|
397 | 408 | } |
|
398 | 409 | } |
|
399 | 410 | |
|
400 | 411 | /*! |
|
401 | 412 | Returns font used to draw labels. |
|
402 | 413 | */ |
|
403 | 414 | QFont QAxis::labelsFont() const |
|
404 | 415 | { |
|
405 | 416 | return d_ptr->m_labelsFont; |
|
406 | 417 | } |
|
407 | 418 | |
|
408 | 419 | void QAxis::setLabelsAngle(int angle) |
|
409 | 420 | { |
|
410 | 421 | if (d_ptr->m_labelsAngle != angle) { |
|
411 | 422 | d_ptr->m_labelsAngle = angle; |
|
412 | 423 | emit d_ptr->updated(); |
|
413 | 424 | } |
|
414 | 425 | } |
|
415 | 426 | |
|
416 | 427 | int QAxis::labelsAngle() const |
|
417 | 428 | { |
|
418 | 429 | return d_ptr->m_labelsAngle; |
|
419 | 430 | } |
|
420 | 431 | |
|
421 | 432 | void QAxis::setLabelsColor(QColor color) |
|
422 | 433 | { |
|
423 | 434 | QBrush b = d_ptr->m_labelsBrush; |
|
424 | 435 | if (b.color() != color) { |
|
425 | 436 | b.setColor(color); |
|
426 | 437 | setLabelsBrush(b); |
|
427 | 438 | emit labelsColorChanged(color); |
|
428 | 439 | } |
|
429 | 440 | } |
|
430 | 441 | |
|
431 | 442 | QColor QAxis::labelsColor() const |
|
432 | 443 | { |
|
433 | 444 | return d_ptr->m_labelsBrush.color(); |
|
434 | 445 | } |
|
435 | 446 | |
|
436 | 447 | void QAxis::setShadesVisible(bool visible) |
|
437 | 448 | { |
|
438 | 449 | if (d_ptr->m_shadesVisible != visible) { |
|
439 | 450 | d_ptr->m_shadesVisible = visible; |
|
440 | 451 | emit d_ptr->updated(); |
|
441 | 452 | emit shadesVisibleChanged(visible); |
|
442 | 453 | } |
|
443 | 454 | } |
|
444 | 455 | |
|
445 | 456 | bool QAxis::shadesVisible() const |
|
446 | 457 | { |
|
447 | 458 | return d_ptr->m_shadesVisible; |
|
448 | 459 | } |
|
449 | 460 | |
|
450 | 461 | /*! |
|
451 | 462 | Sets \a pen used to draw shades. |
|
452 | 463 | */ |
|
453 | 464 | void QAxis::setShadesPen(const QPen &pen) |
|
454 | 465 | { |
|
455 | 466 | if (d_ptr->m_shadesPen != pen) { |
|
456 | 467 | d_ptr->m_shadesPen = pen; |
|
457 | 468 | emit d_ptr->updated(); |
|
458 | 469 | } |
|
459 | 470 | } |
|
460 | 471 | |
|
461 | 472 | /*! |
|
462 | 473 | Returns pen used to draw shades. |
|
463 | 474 | */ |
|
464 | 475 | QPen QAxis::shadesPen() const |
|
465 | 476 | { |
|
466 | 477 | return d_ptr->m_shadesPen; |
|
467 | 478 | } |
|
468 | 479 | |
|
469 | 480 | /*! |
|
470 | 481 | Sets \a brush used to draw shades. |
|
471 | 482 | */ |
|
472 | 483 | void QAxis::setShadesBrush(const QBrush &brush) |
|
473 | 484 | { |
|
474 | 485 | if (d_ptr->m_shadesBrush != brush) { |
|
475 | 486 | d_ptr->m_shadesBrush = brush; |
|
476 | 487 | emit d_ptr->updated(); |
|
477 | 488 | emit shadesColorChanged(brush.color()); |
|
478 | 489 | } |
|
479 | 490 | } |
|
480 | 491 | |
|
481 | 492 | /*! |
|
482 | 493 | \brief Returns brush used to draw shades. |
|
483 | 494 | */ |
|
484 | 495 | QBrush QAxis::shadesBrush() const |
|
485 | 496 | { |
|
486 | 497 | return d_ptr->m_shadesBrush; |
|
487 | 498 | } |
|
488 | 499 | |
|
489 | 500 | void QAxis::setShadesColor(QColor color) |
|
490 | 501 | { |
|
491 | 502 | QBrush b = d_ptr->m_shadesBrush; |
|
492 | 503 | b.setColor(color); |
|
493 | 504 | setShadesBrush(b); |
|
494 | 505 | } |
|
495 | 506 | |
|
496 | 507 | QColor QAxis::shadesColor() const |
|
497 | 508 | { |
|
498 | 509 | return d_ptr->m_shadesBrush.color(); |
|
499 | 510 | } |
|
500 | 511 | |
|
501 | 512 | void QAxis::setShadesBorderColor(QColor color) |
|
502 | 513 | { |
|
503 | 514 | QPen p = d_ptr->m_shadesPen; |
|
504 | 515 | p.setColor(color); |
|
505 | 516 | setShadesPen(p); |
|
506 | 517 | } |
|
507 | 518 | |
|
508 | 519 | QColor QAxis::shadesBorderColor() const |
|
509 | 520 | { |
|
510 | 521 | return d_ptr->m_shadesPen.color(); |
|
511 | 522 | } |
|
512 | 523 | |
|
513 | 524 | void QAxis::setMin(qreal min) |
|
514 | 525 | { |
|
515 | 526 | setRange(min,d_ptr->m_max); |
|
516 | 527 | } |
|
517 | 528 | |
|
518 | 529 | qreal QAxis::min() const |
|
519 | 530 | { |
|
520 | 531 | return d_ptr->m_min; |
|
521 | 532 | } |
|
522 | 533 | |
|
523 | 534 | void QAxis::setMax(qreal max) |
|
524 | 535 | { |
|
525 | 536 | setRange(d_ptr->m_min,max); |
|
526 | 537 | } |
|
527 | 538 | |
|
528 | 539 | qreal QAxis::max() const |
|
529 | 540 | { |
|
530 | 541 | return d_ptr->m_max; |
|
531 | 542 | } |
|
532 | 543 | |
|
533 | 544 | /*! |
|
534 | 545 | Sets range from \a min to \a max on the axis. |
|
535 | 546 | */ |
|
536 | 547 | void QAxis::setRange(qreal min, qreal max) |
|
537 | 548 | { |
|
538 | 549 | bool changed = false; |
|
539 | 550 | if (!qFuzzyIsNull(d_ptr->m_min - min)) { |
|
540 | 551 | d_ptr->m_min = min; |
|
541 | 552 | changed = true; |
|
542 | 553 | emit minChanged(min); |
|
543 | 554 | } |
|
544 | 555 | |
|
545 | 556 | if (!qFuzzyIsNull(d_ptr->m_max - max)) { |
|
546 | 557 | d_ptr->m_max = max; |
|
547 | 558 | changed = true; |
|
548 | 559 | emit maxChanged(max); |
|
549 | 560 | } |
|
550 | 561 | |
|
551 | 562 | if (changed) { |
|
552 | 563 | emit rangeChanged(d_ptr->m_min,d_ptr->m_max); |
|
553 | 564 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
554 | 565 | } |
|
555 | 566 | } |
|
556 | 567 | |
|
557 | 568 | /*! |
|
558 | 569 | Sets \a count for ticks on the axis. |
|
559 | 570 | */ |
|
560 | 571 | void QAxis::setTicksCount(int count) |
|
561 | 572 | { |
|
562 | 573 | if (d_ptr->m_ticksCount != count) { |
|
563 | 574 | d_ptr->m_ticksCount = count; |
|
564 | 575 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
565 | 576 | } |
|
566 | 577 | } |
|
567 | 578 | |
|
568 | 579 | /*! |
|
569 | 580 | \fn int QAxis::ticksCount() const |
|
570 | 581 | Return number of ticks on the axis |
|
571 | 582 | */ |
|
572 | 583 | int QAxis::ticksCount() const |
|
573 | 584 | { |
|
574 | 585 | return d_ptr->m_ticksCount; |
|
575 | 586 | } |
|
576 | 587 | |
|
577 | 588 | /*! |
|
578 | 589 | Sets axis, shades, labels and grid lines to be visible. |
|
579 | 590 | */ |
|
580 | 591 | void QAxis::show() |
|
581 | 592 | { |
|
582 | 593 | d_ptr->m_axisVisible=true; |
|
583 | 594 | d_ptr->m_gridLineVisible=true; |
|
584 | 595 | d_ptr->m_labelsVisible=true; |
|
585 | 596 | d_ptr->m_shadesVisible=true; |
|
586 | 597 | emit d_ptr->updated(); |
|
587 | 598 | } |
|
588 | 599 | |
|
589 | 600 | /*! |
|
590 | 601 | Sets axis, shades, labels and grid lines to not be visible. |
|
591 | 602 | */ |
|
592 | 603 | void QAxis::hide() |
|
593 | 604 | { |
|
594 | 605 | d_ptr->m_axisVisible = false; |
|
595 | 606 | d_ptr->m_gridLineVisible = false; |
|
596 | 607 | d_ptr->m_labelsVisible = false; |
|
597 | 608 | d_ptr->m_shadesVisible = false; |
|
598 | 609 | emit d_ptr->updated(); |
|
599 | 610 | } |
|
600 | 611 | |
|
601 | 612 | void QAxis::setNiceNumbersEnabled(bool enable) |
|
602 | 613 | { |
|
603 | 614 | if (d_ptr->m_niceNumbers != enable){ |
|
604 | 615 | d_ptr->m_niceNumbers = enable; |
|
605 | 616 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
606 | 617 | } |
|
607 | 618 | } |
|
608 | 619 | |
|
609 | 620 | bool QAxis::niceNumbersEnabled() const |
|
610 | 621 | { |
|
611 | 622 | return d_ptr->m_niceNumbers; |
|
612 | 623 | } |
|
613 | 624 | |
|
614 | 625 | QAxisCategories* QAxis::categories() |
|
615 | 626 | { |
|
616 | 627 | return &d_ptr->m_category; |
|
617 | 628 | } |
|
618 | 629 | |
|
619 | 630 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
620 | 631 | |
|
621 | 632 | QAxisPrivate::QAxisPrivate(QAxis* q): |
|
622 | 633 | q_ptr(q), |
|
623 | 634 | m_axisVisible(true), |
|
624 | 635 | m_gridLineVisible(true), |
|
625 | 636 | m_labelsVisible(true), |
|
626 | 637 | m_labelsAngle(0), |
|
627 | 638 | m_shadesVisible(false), |
|
628 | 639 | m_shadesBrush(Qt::SolidPattern), |
|
629 | 640 | m_shadesOpacity(1.0), |
|
630 | 641 | m_min(0), |
|
631 | 642 | m_max(0), |
|
632 | 643 | m_ticksCount(5), |
|
633 | 644 | m_niceNumbers(false) |
|
634 | 645 | { |
|
635 | 646 | |
|
636 | 647 | } |
|
637 | 648 | |
|
638 | 649 | QAxisPrivate::~QAxisPrivate() |
|
639 | 650 | { |
|
640 | 651 | |
|
641 | 652 | } |
|
642 | 653 | |
|
643 | 654 | void QAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
644 | 655 | { |
|
645 | 656 | q_ptr->setRange(min,max); |
|
646 | 657 | q_ptr->setTicksCount(count); |
|
647 | 658 | } |
|
648 | 659 | |
|
649 | 660 | QTCOMMERCIALCHART_END_NAMESPACE |
|
650 | 661 | |
|
651 | 662 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
652 | 663 | |
|
653 | 664 | #include "moc_qaxis.cpp" |
|
654 | 665 | #include "moc_qaxis_p.cpp" |
@@ -1,135 +1,136 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QAXIS_H |
|
22 | 22 | #define QAXIS_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <qaxiscategories.h> |
|
26 | 26 | #include <QPen> |
|
27 | 27 | #include <QFont> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QAxisPrivate; |
|
32 | 32 | |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAxis : public QObject |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged) |
|
37 | 37 | Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) |
|
38 | 38 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
39 | 39 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) |
|
40 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) | |
|
40 | 41 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
41 | 42 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
42 | 43 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
43 | 44 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
44 | 45 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
45 | 46 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) |
|
46 | 47 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) |
|
47 | 48 | Q_PROPERTY(int ticksCount READ ticksCount WRITE setTicksCount) |
|
48 | 49 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) |
|
49 | 50 | |
|
50 | 51 | public: |
|
51 | 52 | |
|
52 | 53 | QAxis(QObject *parent =0); |
|
53 | 54 | ~QAxis(); |
|
54 | 55 | |
|
55 | 56 | //axis handling |
|
56 | 57 | bool isAxisVisible() const; |
|
57 | 58 | void setAxisVisible(bool visible = true); |
|
58 | 59 | void setAxisPen(const QPen &pen); |
|
59 | 60 | QPen axisPen() const; |
|
60 | 61 | void setAxisPenColor(QColor color); |
|
61 | 62 | QColor axisPenColor() const; |
|
62 | 63 | |
|
63 | 64 | //grid handling |
|
64 | 65 | bool isGridLineVisible() const; |
|
65 | 66 | void setGridLineVisible(bool visible = true); |
|
66 | 67 | void setGridLinePen(const QPen &pen); |
|
67 | 68 | QPen gridLinePen() const; |
|
68 | 69 | |
|
69 | 70 | //labels handling |
|
70 | 71 | bool labelsVisible() const; |
|
71 | 72 | void setLabelsVisible(bool visible = true); |
|
72 | 73 | void setLabelsPen(const QPen &pen); |
|
73 | 74 | QPen labelsPen() const; |
|
74 | 75 | void setLabelsBrush(const QBrush &brush); |
|
75 | 76 | QBrush labelsBrush() const; |
|
76 | 77 | void setLabelsFont(const QFont &font); |
|
77 | 78 | QFont labelsFont() const; |
|
78 | 79 | void setLabelsAngle(int angle); |
|
79 | 80 | int labelsAngle() const; |
|
80 | 81 | void setLabelsColor(QColor color); |
|
81 | 82 | QColor labelsColor() const; |
|
82 | 83 | |
|
83 | 84 | //shades handling |
|
84 | 85 | bool shadesVisible() const; |
|
85 | 86 | void setShadesVisible(bool visible = true); |
|
86 | 87 | void setShadesPen(const QPen &pen); |
|
87 | 88 | QPen shadesPen() const; |
|
88 | 89 | void setShadesBrush(const QBrush &brush); |
|
89 | 90 | QBrush shadesBrush() const; |
|
90 | 91 | void setShadesColor(QColor color); |
|
91 | 92 | QColor shadesColor() const; |
|
92 | 93 | void setShadesBorderColor(QColor color); |
|
93 | 94 | QColor shadesBorderColor() const; |
|
94 | 95 | |
|
95 | 96 | //range handling |
|
96 | 97 | void setMin(qreal min); |
|
97 | 98 | qreal min() const; |
|
98 | 99 | void setMax(qreal max); |
|
99 | 100 | qreal max() const; |
|
100 | 101 | void setRange(qreal min, qreal max); |
|
101 | 102 | |
|
102 | 103 | //ticks handling |
|
103 | 104 | void setTicksCount(int count); |
|
104 | 105 | int ticksCount() const; |
|
105 | 106 | |
|
106 | 107 | void setNiceNumbersEnabled(bool enable = true); |
|
107 | 108 | bool niceNumbersEnabled() const; |
|
108 | 109 | |
|
109 | 110 | QAxisCategories* categories(); |
|
110 | 111 | |
|
111 | 112 | void show(); |
|
112 | 113 | void hide(); |
|
113 | 114 | |
|
114 | 115 | Q_SIGNALS: |
|
115 | 116 | void visibleChanged(bool visible); |
|
116 | 117 | void labelsVisibleChanged(bool visible); |
|
117 | 118 | void gridVisibleChanged(bool visible); |
|
118 | 119 | void rangeChanged(qreal min, qreal max); |
|
119 | 120 | void colorChanged(QColor color); |
|
120 | 121 | void labelsColorChanged(QColor color); |
|
121 | 122 | void shadesVisibleChanged(bool visible); |
|
122 | 123 | void shadesColorChanged(QColor color); |
|
123 | 124 | void shadesBorderColorChanged(QColor color); |
|
124 | 125 | void minChanged(qreal min); |
|
125 | 126 | void maxChanged(qreal max); |
|
126 | 127 | |
|
127 | 128 | private: |
|
128 | 129 | QScopedPointer<QAxisPrivate> d_ptr; |
|
129 | 130 | Q_DISABLE_COPY(QAxis) |
|
130 | 131 | friend class ChartDataSet; |
|
131 | 132 | friend class ChartAxis; |
|
132 | 133 | }; |
|
133 | 134 | |
|
134 | 135 | QTCOMMERCIALCHART_END_NAMESPACE |
|
135 | 136 | #endif /* QCHARTAXIS_H_ */ |
@@ -1,648 +1,655 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarset.h" |
|
22 | 22 | #include "qbarset_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QBarSet |
|
28 | 28 | \brief Building block for different bar charts |
|
29 | 29 | |
|
30 | 30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | 31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | 32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | 33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | 34 | |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | 38 | */ |
|
39 | 39 | /*! |
|
40 | 40 | \qmlclass BarSet QBarSet |
|
41 | 41 | |
|
42 | 42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
43 | 43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
44 | 44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
45 | 45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
46 | 46 | \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \property QBarSet::label |
|
51 | 51 | Defines the label of the barSet. |
|
52 | 52 | */ |
|
53 | 53 | /*! |
|
54 | 54 | \qmlproperty string BarSet::label |
|
55 | 55 | Defines the label of the barSet. |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QBarSet::pen |
|
60 | 60 | \brief Defines the pen used by the barSet. |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QBarSet::brush |
|
65 | 65 | \brief Defines the brush used by the barSet. |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QBarSet::labelBrush |
|
70 | 70 | \brief Defines the brush used by the barSet's label. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QBarSet::labelFont |
|
75 | 75 | \brief Defines the font used by the barSet's label. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | \qmlproperty Font BarSet::labelFont | |
|
80 | Defines the font used by the barSet's label. | |
|
81 | ||
|
82 | See the \l {Font} {QML Font Element} for detailed documentation. | |
|
83 | */ | |
|
84 | ||
|
85 | /*! | |
|
79 | 86 | \property QBarSet::color |
|
80 | 87 | The fill (brush) color of the bar set. |
|
81 | 88 | */ |
|
82 | 89 | /*! |
|
83 | 90 | \qmlproperty color BarSet::color |
|
84 | 91 | The fill (brush) color of the bar set. |
|
85 | 92 | */ |
|
86 | 93 | |
|
87 | 94 | /*! |
|
88 | 95 | \property QBarSet::borderColor |
|
89 | 96 | The line (pen) color of the bar set. |
|
90 | 97 | */ |
|
91 | 98 | /*! |
|
92 | 99 | \qmlproperty color BarSet::borderColor |
|
93 | 100 | The line (pen) color of the bar set. |
|
94 | 101 | */ |
|
95 | 102 | |
|
96 | 103 | /*! |
|
97 | 104 | \property QBarSet::labelColor |
|
98 | 105 | The text (label) color of the bar set. |
|
99 | 106 | */ |
|
100 | 107 | /*! |
|
101 | 108 | \qmlproperty color BarSet::labelColor |
|
102 | 109 | The text (label) color of the bar set. |
|
103 | 110 | */ |
|
104 | 111 | |
|
105 | 112 | /*! |
|
106 | 113 | \fn void QBarSet::clicked(int index) |
|
107 | 114 | |
|
108 | 115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
109 | 116 | Clicked bar inside set is indexed by \a index |
|
110 | 117 | */ |
|
111 | 118 | |
|
112 | 119 | /*! |
|
113 | 120 | \fn void QBarSet::hovered(bool status) |
|
114 | 121 | |
|
115 | 122 | The signal is emitted if mouse is hovered on top of barset. |
|
116 | 123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
117 | 124 | */ |
|
118 | 125 | |
|
119 | 126 | |
|
120 | 127 | /*! |
|
121 | 128 | \fn void QBarSet::labelChanged() |
|
122 | 129 | This signal is emitted when the label of the barSet has changed. |
|
123 | 130 | \sa label |
|
124 | 131 | */ |
|
125 | 132 | |
|
126 | 133 | /*! |
|
127 | 134 | \fn void QBarSet::penChanged() |
|
128 | 135 | This signal is emitted when the pen of the barSet has changed. |
|
129 | 136 | \sa pen |
|
130 | 137 | */ |
|
131 | 138 | |
|
132 | 139 | /*! |
|
133 | 140 | \fn void QBarSet::brushChanged() |
|
134 | 141 | This signal is emitted when the brush of the barSet has changed. |
|
135 | 142 | \sa brush |
|
136 | 143 | */ |
|
137 | 144 | |
|
138 | 145 | /*! |
|
139 | 146 | \fn void QBarSet::labelBrushChanged() |
|
140 | 147 | This signal is emitted when the brush of the barSet's label has changed. |
|
141 | 148 | \sa labelBrush |
|
142 | 149 | */ |
|
143 | 150 | |
|
144 | 151 | /*! |
|
145 | 152 | \fn void QBarSet::labelFontChanged() |
|
146 | 153 | This signal is emitted when the font of the barSet's label has changed. |
|
147 | 154 | \sa labelBrush |
|
148 | 155 | */ |
|
149 | 156 | |
|
150 | 157 | /*! |
|
151 | 158 | \fn void QBarSet::colorChanged(QColor) |
|
152 | 159 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
153 | 160 | */ |
|
154 | 161 | /*! |
|
155 | 162 | \qmlsignal BarSet::onColorChanged(color color) |
|
156 | 163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
157 | 164 | */ |
|
158 | 165 | |
|
159 | 166 | /*! |
|
160 | 167 | \fn void QBarSet::borderColorChanged(QColor) |
|
161 | 168 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
162 | 169 | */ |
|
163 | 170 | /*! |
|
164 | 171 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
165 | 172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
166 | 173 | */ |
|
167 | 174 | |
|
168 | 175 | /*! |
|
169 | 176 | \fn void QBarSet::labelColorChanged(QColor) |
|
170 | 177 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
171 | 178 | */ |
|
172 | 179 | /*! |
|
173 | 180 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
174 | 181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
175 | 182 | */ |
|
176 | 183 | |
|
177 | 184 | /*! |
|
178 | 185 | \fn void QBarSet::valuesAdded(int index, int count) |
|
179 | 186 | This signal is emitted when new values have been added to the set. |
|
180 | 187 | Parameter \a index indicates the position of the first inserted value. |
|
181 | 188 | Parameter \a count is the number of iserted values. |
|
182 | 189 | \sa append(), insert() |
|
183 | 190 | */ |
|
184 | 191 | /*! |
|
185 | 192 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
186 | 193 | This signal is emitted when new values have been added to the set. |
|
187 | 194 | Parameter \a index indicates the position of the first inserted value. |
|
188 | 195 | Parameter \a count is the number of iserted values. |
|
189 | 196 | */ |
|
190 | 197 | |
|
191 | 198 | /*! |
|
192 | 199 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
193 | 200 | This signal is emitted values have been removed from the set. |
|
194 | 201 | Parameter \a index indicates the position of the first removed value. |
|
195 | 202 | Parameter \a count is the number of removed values. |
|
196 | 203 | \sa remove() |
|
197 | 204 | */ |
|
198 | 205 | /*! |
|
199 | 206 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
200 | 207 | This signal is emitted values have been removed from the set. |
|
201 | 208 | Parameter \a index indicates the position of the first removed value. |
|
202 | 209 | Parameter \a count is the number of removed values. |
|
203 | 210 | */ |
|
204 | 211 | |
|
205 | 212 | /*! |
|
206 | 213 | \fn void QBarSet::valueChanged(int index) |
|
207 | 214 | This signal is emitted values the value in the set has been modified. |
|
208 | 215 | Parameter \a index indicates the position of the modified value. |
|
209 | 216 | \sa at() |
|
210 | 217 | */ |
|
211 | 218 | /*! |
|
212 | 219 | \qmlsignal BarSet::onValueChanged(int index) |
|
213 | 220 | This signal is emitted values the value in the set has been modified. |
|
214 | 221 | Parameter \a index indicates the position of the modified value. |
|
215 | 222 | */ |
|
216 | 223 | |
|
217 | 224 | /*! |
|
218 | 225 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
219 | 226 | */ |
|
220 | 227 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
221 | 228 | : QObject(parent) |
|
222 | 229 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
223 | 230 | { |
|
224 | 231 | } |
|
225 | 232 | |
|
226 | 233 | /*! |
|
227 | 234 | Destroys the barset |
|
228 | 235 | */ |
|
229 | 236 | QBarSet::~QBarSet() |
|
230 | 237 | { |
|
231 | 238 | // NOTE: d_ptr destroyed by QObject |
|
232 | 239 | } |
|
233 | 240 | |
|
234 | 241 | /*! |
|
235 | 242 | Sets new \a label for set. |
|
236 | 243 | */ |
|
237 | 244 | void QBarSet::setLabel(const QString label) |
|
238 | 245 | { |
|
239 | 246 | d_ptr->m_label = label; |
|
240 | 247 | emit labelChanged(); |
|
241 | 248 | } |
|
242 | 249 | |
|
243 | 250 | /*! |
|
244 | 251 | Returns label of the set. |
|
245 | 252 | */ |
|
246 | 253 | QString QBarSet::label() const |
|
247 | 254 | { |
|
248 | 255 | return d_ptr->m_label; |
|
249 | 256 | } |
|
250 | 257 | |
|
251 | 258 | /*! |
|
252 | 259 | Appends a point to set. Parameter \a value x coordinate defines the |
|
253 | 260 | position in x-axis and y coordinate defines the height of bar. |
|
254 | 261 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) |
|
255 | 262 | the x values are used or ignored. |
|
256 | 263 | */ |
|
257 | 264 | void QBarSet::append(const QPointF value) |
|
258 | 265 | { |
|
259 | 266 | int index = d_ptr->m_values.count(); |
|
260 | 267 | d_ptr->append(value); |
|
261 | 268 | emit valuesAdded(index, 1); |
|
262 | 269 | } |
|
263 | 270 | |
|
264 | 271 | /*! |
|
265 | 272 | Appends a list of \a values to set. Works like append with single point. |
|
266 | 273 | \sa append() |
|
267 | 274 | */ |
|
268 | 275 | void QBarSet::append(const QList<QPointF> &values) |
|
269 | 276 | { |
|
270 | 277 | int index = d_ptr->m_values.count(); |
|
271 | 278 | d_ptr->append(values); |
|
272 | 279 | emit valuesAdded(index, values.count()); |
|
273 | 280 | } |
|
274 | 281 | |
|
275 | 282 | /*! |
|
276 | 283 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, |
|
277 | 284 | with x coordinate being the index of appended value and y coordinate is the value. |
|
278 | 285 | */ |
|
279 | 286 | void QBarSet::append(const qreal value) |
|
280 | 287 | { |
|
281 | 288 | // Convert to QPointF and use other append(QPointF) method. |
|
282 | 289 | append(QPointF(d_ptr->m_values.count(), value)); |
|
283 | 290 | } |
|
284 | 291 | |
|
285 | 292 | /*! |
|
286 | 293 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
287 | 294 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. |
|
288 | 295 | \sa append() |
|
289 | 296 | */ |
|
290 | 297 | void QBarSet::append(const QList<qreal> &values) |
|
291 | 298 | { |
|
292 | 299 | int index = d_ptr->m_values.count(); |
|
293 | 300 | d_ptr->append(values); |
|
294 | 301 | emit valuesAdded(index, values.count()); |
|
295 | 302 | } |
|
296 | 303 | |
|
297 | 304 | /*! |
|
298 | 305 | Convinience operator. Same as append, with real \a value. |
|
299 | 306 | \sa append() |
|
300 | 307 | */ |
|
301 | 308 | QBarSet& QBarSet::operator << (const qreal &value) |
|
302 | 309 | { |
|
303 | 310 | append(value); |
|
304 | 311 | return *this; |
|
305 | 312 | } |
|
306 | 313 | |
|
307 | 314 | /*! |
|
308 | 315 | Convinience operator. Same as append, with QPointF \a value. |
|
309 | 316 | \sa append() |
|
310 | 317 | */ |
|
311 | 318 | QBarSet& QBarSet::operator << (const QPointF &value) |
|
312 | 319 | { |
|
313 | 320 | append(value); |
|
314 | 321 | return *this; |
|
315 | 322 | } |
|
316 | 323 | |
|
317 | 324 | /*! |
|
318 | 325 | Inserts new \a value on the \a index position. |
|
319 | 326 | The value that is currently at this postion is moved to postion index + 1 |
|
320 | 327 | \sa remove() |
|
321 | 328 | */ |
|
322 | 329 | void QBarSet::insert(const int index, const qreal value) |
|
323 | 330 | { |
|
324 | 331 | d_ptr->insert(index, value); |
|
325 | 332 | emit valuesAdded(index,1); |
|
326 | 333 | } |
|
327 | 334 | |
|
328 | 335 | /*! |
|
329 | 336 | Inserts new \a value on the \a index position. |
|
330 | 337 | The value that is currently at this postion is moved to postion index + 1 |
|
331 | 338 | \sa remove() |
|
332 | 339 | */ |
|
333 | 340 | void QBarSet::insert(const int index, const QPointF value) |
|
334 | 341 | { |
|
335 | 342 | d_ptr->insert(index,value); |
|
336 | 343 | emit valuesAdded(index,1); |
|
337 | 344 | } |
|
338 | 345 | |
|
339 | 346 | /*! |
|
340 | 347 | Removes \a count number of values from the set starting at \a index. |
|
341 | 348 | \sa insert() |
|
342 | 349 | */ |
|
343 | 350 | void QBarSet::remove(const int index, const int count) |
|
344 | 351 | { |
|
345 | 352 | int removedCount = d_ptr->remove(index,count); |
|
346 | 353 | if (removedCount > 0) { |
|
347 | 354 | emit valuesRemoved(index,removedCount); |
|
348 | 355 | } |
|
349 | 356 | return; |
|
350 | 357 | } |
|
351 | 358 | |
|
352 | 359 | /*! |
|
353 | 360 | Sets a new value \a value to set, indexed by \a index |
|
354 | 361 | */ |
|
355 | 362 | void QBarSet::replace(const int index, const qreal value) |
|
356 | 363 | { |
|
357 | 364 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
358 | 365 | d_ptr->replace(index,value); |
|
359 | 366 | emit valueChanged(index); |
|
360 | 367 | } |
|
361 | 368 | } |
|
362 | 369 | |
|
363 | 370 | /*! |
|
364 | 371 | Sets a new value \a value to set, indexed by \a index |
|
365 | 372 | */ |
|
366 | 373 | void QBarSet::replace(const int index, const QPointF value) |
|
367 | 374 | { |
|
368 | 375 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
369 | 376 | d_ptr->replace(index,value); |
|
370 | 377 | emit valueChanged(index); |
|
371 | 378 | } |
|
372 | 379 | } |
|
373 | 380 | |
|
374 | 381 | /*! |
|
375 | 382 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. |
|
376 | 383 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
377 | 384 | of the QPointF (if appended with QPointF append). |
|
378 | 385 | If the index is out of bounds QPointF(0, 0.0) is returned. |
|
379 | 386 | */ |
|
380 | 387 | QPointF QBarSet::at(const int index) const |
|
381 | 388 | { |
|
382 | 389 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
383 | 390 | return QPointF(index, 0.0); |
|
384 | 391 | } |
|
385 | 392 | |
|
386 | 393 | return d_ptr->m_values.at(index); |
|
387 | 394 | } |
|
388 | 395 | |
|
389 | 396 | /*! |
|
390 | 397 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. |
|
391 | 398 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
392 | 399 | of the QPointF (if appended with QPointF append). |
|
393 | 400 | */ |
|
394 | 401 | QPointF QBarSet::operator [](const int index) const |
|
395 | 402 | { |
|
396 | 403 | return d_ptr->m_values.at(index); |
|
397 | 404 | } |
|
398 | 405 | |
|
399 | 406 | /*! |
|
400 | 407 | Returns count of values in set. |
|
401 | 408 | */ |
|
402 | 409 | int QBarSet::count() const |
|
403 | 410 | { |
|
404 | 411 | return d_ptr->m_values.count(); |
|
405 | 412 | } |
|
406 | 413 | |
|
407 | 414 | /*! |
|
408 | 415 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. |
|
409 | 416 | */ |
|
410 | 417 | qreal QBarSet::sum() const |
|
411 | 418 | { |
|
412 | 419 | qreal total(0); |
|
413 | 420 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
414 | 421 | //total += d_ptr->m_values.at(i); |
|
415 | 422 | total += d_ptr->m_values.at(i).y(); |
|
416 | 423 | } |
|
417 | 424 | return total; |
|
418 | 425 | } |
|
419 | 426 | |
|
420 | 427 | /*! |
|
421 | 428 | Sets pen for set. Bars of this set are drawn using \a pen |
|
422 | 429 | */ |
|
423 | 430 | void QBarSet::setPen(const QPen &pen) |
|
424 | 431 | { |
|
425 | 432 | if(d_ptr->m_pen!=pen){ |
|
426 | 433 | d_ptr->m_pen = pen; |
|
427 | 434 | emit d_ptr->updatedBars(); |
|
428 | 435 | emit penChanged(); |
|
429 | 436 | } |
|
430 | 437 | } |
|
431 | 438 | |
|
432 | 439 | /*! |
|
433 | 440 | Returns pen of the set. |
|
434 | 441 | */ |
|
435 | 442 | QPen QBarSet::pen() const |
|
436 | 443 | { |
|
437 | 444 | return d_ptr->m_pen; |
|
438 | 445 | } |
|
439 | 446 | |
|
440 | 447 | /*! |
|
441 | 448 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
442 | 449 | */ |
|
443 | 450 | void QBarSet::setBrush(const QBrush &brush) |
|
444 | 451 | { |
|
445 | 452 | if(d_ptr->m_brush!=brush){ |
|
446 | 453 | d_ptr->m_brush = brush; |
|
447 | 454 | emit d_ptr->updatedBars(); |
|
448 | 455 | emit brushChanged(); |
|
449 | 456 | } |
|
450 | 457 | } |
|
451 | 458 | |
|
452 | 459 | /*! |
|
453 | 460 | Returns brush of the set. |
|
454 | 461 | */ |
|
455 | 462 | QBrush QBarSet::brush() const |
|
456 | 463 | { |
|
457 | 464 | return d_ptr->m_brush; |
|
458 | 465 | } |
|
459 | 466 | |
|
460 | 467 | /*! |
|
461 | 468 | Sets \a brush of the values that are drawn on top of this barset |
|
462 | 469 | */ |
|
463 | 470 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
464 | 471 | { |
|
465 | 472 | if(d_ptr->m_labelBrush!=brush){ |
|
466 | 473 | d_ptr->m_labelBrush = brush; |
|
467 | 474 | emit d_ptr->updatedBars(); |
|
468 | 475 | emit labelBrushChanged(); |
|
469 | 476 | } |
|
470 | 477 | } |
|
471 | 478 | |
|
472 | 479 | /*! |
|
473 | 480 | Returns brush of the values that are drawn on top of this barset |
|
474 | 481 | */ |
|
475 | 482 | QBrush QBarSet::labelBrush() const |
|
476 | 483 | { |
|
477 | 484 | return d_ptr->m_labelBrush; |
|
478 | 485 | } |
|
479 | 486 | |
|
480 | 487 | /*! |
|
481 | 488 | Sets the \a font for values that are drawn on top of this barset |
|
482 | 489 | */ |
|
483 | 490 | void QBarSet::setLabelFont(const QFont &font) |
|
484 | 491 | { |
|
485 | 492 | if(d_ptr->m_labelFont!=font) { |
|
486 | 493 | d_ptr->m_labelFont = font; |
|
487 | 494 | emit d_ptr->updatedBars(); |
|
488 | 495 | emit labelFontChanged(); |
|
489 | 496 | } |
|
490 | 497 | |
|
491 | 498 | } |
|
492 | 499 | |
|
493 | 500 | /*! |
|
494 | 501 | Returns the pen for values that are drawn on top of this barset |
|
495 | 502 | */ |
|
496 | 503 | QFont QBarSet::labelFont() const |
|
497 | 504 | { |
|
498 | 505 | return d_ptr->m_labelFont; |
|
499 | 506 | } |
|
500 | 507 | |
|
501 | 508 | /*! |
|
502 | 509 | Returns the color of the brush of barset. |
|
503 | 510 | */ |
|
504 | 511 | QColor QBarSet::color() |
|
505 | 512 | { |
|
506 | 513 | return brush().color(); |
|
507 | 514 | } |
|
508 | 515 | |
|
509 | 516 | /*! |
|
510 | 517 | Sets the \a color of brush for this barset |
|
511 | 518 | */ |
|
512 | 519 | void QBarSet::setColor(QColor color) |
|
513 | 520 | { |
|
514 | 521 | QBrush b = brush(); |
|
515 | 522 | if (b.color() != color) { |
|
516 | 523 | b.setColor(color); |
|
517 | 524 | setBrush(b); |
|
518 | 525 | emit colorChanged(color); |
|
519 | 526 | } |
|
520 | 527 | } |
|
521 | 528 | |
|
522 | 529 | /*! |
|
523 | 530 | Returns the color of pen of this barset |
|
524 | 531 | */ |
|
525 | 532 | QColor QBarSet::borderColor() |
|
526 | 533 | { |
|
527 | 534 | return pen().color(); |
|
528 | 535 | } |
|
529 | 536 | |
|
530 | 537 | /*! |
|
531 | 538 | Sets the color of pen for this barset |
|
532 | 539 | */ |
|
533 | 540 | void QBarSet::setBorderColor(QColor color) |
|
534 | 541 | { |
|
535 | 542 | QPen p = pen(); |
|
536 | 543 | if (p.color() != color) { |
|
537 | 544 | p.setColor(color); |
|
538 | 545 | setPen(p); |
|
539 | 546 | emit borderColorChanged(color); |
|
540 | 547 | } |
|
541 | 548 | } |
|
542 | 549 | |
|
543 | 550 | /*! |
|
544 | 551 | Returns the color of labels of this barset |
|
545 | 552 | */ |
|
546 | 553 | QColor QBarSet::labelColor() |
|
547 | 554 | { |
|
548 | 555 | return labelBrush().color(); |
|
549 | 556 | } |
|
550 | 557 | |
|
551 | 558 | /*! |
|
552 | 559 | Sets the color of labels for this barset |
|
553 | 560 | */ |
|
554 | 561 | void QBarSet::setLabelColor(QColor color) |
|
555 | 562 | { |
|
556 | 563 | QBrush b = labelBrush(); |
|
557 | 564 | if (b.color() != color) { |
|
558 | 565 | b.setColor(color); |
|
559 | 566 | setLabelBrush(b); |
|
560 | 567 | emit labelColorChanged(color); |
|
561 | 568 | } |
|
562 | 569 | } |
|
563 | 570 | |
|
564 | 571 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
565 | 572 | |
|
566 | 573 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
567 | 574 | q_ptr(parent), |
|
568 | 575 | m_label(label) |
|
569 | 576 | { |
|
570 | 577 | } |
|
571 | 578 | |
|
572 | 579 | QBarSetPrivate::~QBarSetPrivate() |
|
573 | 580 | { |
|
574 | 581 | } |
|
575 | 582 | |
|
576 | 583 | void QBarSetPrivate::append(QPointF value) |
|
577 | 584 | { |
|
578 | 585 | m_values.append(value); |
|
579 | 586 | emit restructuredBars(); |
|
580 | 587 | } |
|
581 | 588 | |
|
582 | 589 | void QBarSetPrivate::append(QList<QPointF> values) |
|
583 | 590 | { |
|
584 | 591 | for (int i=0; i<values.count(); i++) { |
|
585 | 592 | m_values.append(values.at(i)); |
|
586 | 593 | } |
|
587 | 594 | emit restructuredBars(); |
|
588 | 595 | } |
|
589 | 596 | |
|
590 | 597 | void QBarSetPrivate::append(QList<qreal> values) |
|
591 | 598 | { |
|
592 | 599 | int index = m_values.count(); |
|
593 | 600 | for (int i=0; i<values.count(); i++) { |
|
594 | 601 | m_values.append(QPointF(index,values.at(i))); |
|
595 | 602 | index++; |
|
596 | 603 | } |
|
597 | 604 | emit restructuredBars(); |
|
598 | 605 | } |
|
599 | 606 | |
|
600 | 607 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
601 | 608 | { |
|
602 | 609 | m_values.insert(index, QPointF(index, value)); |
|
603 | 610 | emit restructuredBars(); |
|
604 | 611 | } |
|
605 | 612 | |
|
606 | 613 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
607 | 614 | { |
|
608 | 615 | m_values.insert(index, value); |
|
609 | 616 | emit restructuredBars(); |
|
610 | 617 | } |
|
611 | 618 | |
|
612 | 619 | int QBarSetPrivate::remove(const int index, const int count) |
|
613 | 620 | { |
|
614 | 621 | int removeCount = count; |
|
615 | 622 | |
|
616 | 623 | if ((index <0) || (m_values.count() == 0)) { |
|
617 | 624 | // Invalid index or not values in list, remove nothing. |
|
618 | 625 | return 0; |
|
619 | 626 | } else if ((index + count) > m_values.count()) { |
|
620 | 627 | // Trying to remove more items than list has. Limit amount to be removed. |
|
621 | 628 | removeCount = m_values.count() - index; |
|
622 | 629 | } |
|
623 | 630 | |
|
624 | 631 | int c = 0; |
|
625 | 632 | while (c < removeCount) { |
|
626 | 633 | m_values.removeAt(index); |
|
627 | 634 | c++; |
|
628 | 635 | } |
|
629 | 636 | emit restructuredBars(); |
|
630 | 637 | return removeCount; |
|
631 | 638 | } |
|
632 | 639 | |
|
633 | 640 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
634 | 641 | { |
|
635 | 642 | m_values.replace(index,QPointF(index,value)); |
|
636 | 643 | emit updatedBars(); |
|
637 | 644 | } |
|
638 | 645 | |
|
639 | 646 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
640 | 647 | { |
|
641 | 648 | m_values.replace(index,value); |
|
642 | 649 | emit updatedBars(); |
|
643 | 650 | } |
|
644 | 651 | |
|
645 | 652 | #include "moc_qbarset.cpp" |
|
646 | 653 | #include "moc_qbarset_p.cpp" |
|
647 | 654 | |
|
648 | 655 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,769 +1,779 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "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 | \brief Defines a slice in pie series. |
|
29 | 29 | |
|
30 | 30 | This object defines the properties of a single slice in a QPieSeries. |
|
31 | 31 | |
|
32 | 32 | In addition to the obvious value and label properties the user can also control |
|
33 | 33 | the visual appearance of a slice. By modifying the visual appearance also means that |
|
34 | 34 | the user is overriding the default appearance set by the theme. |
|
35 | 35 | |
|
36 | 36 | Note that if the user has customized slices and theme is changed all customizations will be lost. |
|
37 | 37 | |
|
38 | 38 | To enable user interaction with the pie some basic signals are provided about clicking and hovering. |
|
39 | 39 | */ |
|
40 | 40 | |
|
41 | 41 | /*! |
|
42 | 42 | \qmlclass PieSlice QPieSlice |
|
43 | 43 | PieSlice defines the properties of a single slice in a PieSeries. The element should be used |
|
44 | 44 | as a child for a PieSeries. For example: |
|
45 | 45 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
46 | 46 | |
|
47 | 47 | An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append |
|
48 | 48 | method. |
|
49 | 49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4 |
|
50 | 50 | |
|
51 | 51 | In that case you may want to use PieSeries.at or PieSeries.find to access the properties of |
|
52 | 52 | an individual PieSlice instance. |
|
53 | 53 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5 |
|
54 | 54 | \sa PieSeries |
|
55 | 55 | */ |
|
56 | 56 | |
|
57 | 57 | /*! |
|
58 | 58 | \enum QPieSlice::LabelPosition |
|
59 | 59 | |
|
60 | 60 | This enum describes the position of the slice label. |
|
61 | 61 | |
|
62 | 62 | \value LabelOutside Label is outside the slice with an arm. |
|
63 | 63 | \value LabelInside Label is centered inside the slice. |
|
64 | 64 | |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \property QPieSlice::label |
|
69 | 69 | Label of the slice. |
|
70 | 70 | \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor |
|
71 | 71 | */ |
|
72 | 72 | /*! |
|
73 | 73 | \qmlproperty string PieSlice::label |
|
74 | 74 | Label (text) of the slice. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \fn void QPieSlice::labelChanged() |
|
79 | 79 | This signal emitted when the slice label has been changed. |
|
80 | 80 | \sa label |
|
81 | 81 | */ |
|
82 | 82 | /*! |
|
83 | 83 | \qmlsignal PieSlice::labelChanged() |
|
84 | 84 | This signal emitted when the slice label has been changed. |
|
85 | 85 | \sa label |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QPieSlice::value |
|
90 | 90 | Value of the slice. |
|
91 | 91 | Note that if users sets a negative value it is converted to a positive value. |
|
92 | 92 | \sa percentage(), QPieSeries::sum() |
|
93 | 93 | */ |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty real PieSlice::value |
|
96 | 96 | Value of the slice. Note that if users sets a negative value it is converted to a positive value. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \fn void QPieSlice::valueChanged() |
|
101 | 101 | This signal is emitted when the slice value changes. |
|
102 | 102 | \sa value |
|
103 | 103 | */ |
|
104 | 104 | /*! |
|
105 | 105 | \qmlsignal PieSlice::valueChanged() |
|
106 | 106 | This signal is emitted when the slice value changes. |
|
107 | 107 | \sa value |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | \property QPieSlice::labelVisible |
|
112 | 112 | Defines the visibility of slice label. By default the label is not visible. |
|
113 | 113 | \sa label, labelBrush, labelFont, labelArmLengthFactor |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | 116 | \qmlproperty bool PieSlice::labelVisible |
|
117 | 117 | Defines the visibility of slice label. By default the label is not visible. |
|
118 | 118 | */ |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | \fn void QPieSlice::labelVisibleChanged() |
|
122 | 122 | This signal emitted when visibility of the slice label has changed. |
|
123 | 123 | \sa labelVisible |
|
124 | 124 | */ |
|
125 | 125 | /*! |
|
126 | 126 | \qmlsignal PieSlice::labelVisibleChanged() |
|
127 | 127 | This signal emitted when visibility of the slice label has changed. |
|
128 | 128 | \sa labelVisible |
|
129 | 129 | */ |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | \property QPieSlice::exploded |
|
133 | 133 | If set to true the slice is "exploded" away from the pie. |
|
134 | 134 | \sa explodeDistanceFactor |
|
135 | 135 | */ |
|
136 | 136 | /*! |
|
137 | 137 | \qmlproperty bool PieSlice::exploded |
|
138 | 138 | If set to true the slice is "exploded" away from the pie. |
|
139 | 139 | \sa explodeDistanceFactor |
|
140 | 140 | */ |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | \property QPieSlice::pen |
|
144 | 144 | Pen used to draw the slice border. |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \fn void QPieSlice::penChanged() |
|
149 | 149 | This signal is emitted when the pen of the slice has changed. |
|
150 | 150 | \sa pen |
|
151 | 151 | */ |
|
152 | 152 | |
|
153 | 153 | /*! |
|
154 | 154 | \property QPieSlice::borderColor |
|
155 | 155 | Color used to draw the slice border. |
|
156 | 156 | This is a convenience property for modifying the slice pen. |
|
157 | 157 | \sa pen, borderWidth |
|
158 | 158 | */ |
|
159 | 159 | /*! |
|
160 | 160 | \qmlproperty color PieSlice::borderColor |
|
161 | 161 | Color used to draw the slice border (pen color). |
|
162 | 162 | \sa borderWidth |
|
163 | 163 | */ |
|
164 | 164 | |
|
165 | 165 | /*! |
|
166 | 166 | \fn void QPieSlice::borderColorChanged() |
|
167 | 167 | This signal is emitted when slice border color changes. |
|
168 | 168 | \sa pen, borderColor |
|
169 | 169 | */ |
|
170 | 170 | /*! |
|
171 | 171 | \qmlsignal PieSlice::borderColorChanged() |
|
172 | 172 | This signal is emitted when slice border color changes. |
|
173 | 173 | \sa borderColor |
|
174 | 174 | */ |
|
175 | 175 | |
|
176 | 176 | /*! |
|
177 | 177 | \property QPieSlice::borderWidth |
|
178 | 178 | Width of the slice border. |
|
179 | 179 | This is a convenience property for modifying the slice pen. |
|
180 | 180 | \sa pen, borderColor |
|
181 | 181 | */ |
|
182 | 182 | /*! |
|
183 | 183 | \qmlproperty int PieSlice::borderWidth |
|
184 | 184 | Width of the slice border. |
|
185 | 185 | This is a convenience property for modifying the slice pen. |
|
186 | 186 | \sa borderColor |
|
187 | 187 | */ |
|
188 | 188 | |
|
189 | 189 | /*! |
|
190 | 190 | \fn void QPieSlice::borderWidthChanged() |
|
191 | 191 | This signal is emitted when slice border width changes. |
|
192 | 192 | \sa pen, borderWidth |
|
193 | 193 | */ |
|
194 | 194 | /*! |
|
195 | 195 | \qmlsignal PieSlice::borderWidthChanged() |
|
196 | 196 | This signal is emitted when slice border width changes. |
|
197 | 197 | \sa borderWidth |
|
198 | 198 | */ |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | \property QPieSlice::brush |
|
202 | 202 | Brush used to draw the slice. |
|
203 | 203 | */ |
|
204 | 204 | |
|
205 | 205 | /*! |
|
206 | 206 | \fn void QPieSlice::brushChanged() |
|
207 | 207 | This signal is emitted when the brush of the slice has changed. |
|
208 | 208 | \sa brush |
|
209 | 209 | */ |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | \property QPieSlice::color |
|
213 | 213 | Fill (brush) color of the slice. |
|
214 | 214 | This is a convenience property for modifying the slice brush. |
|
215 | 215 | \sa brush |
|
216 | 216 | */ |
|
217 | 217 | /*! |
|
218 | 218 | \qmlproperty color PieSlice::color |
|
219 | 219 | Fill (brush) color of the slice. |
|
220 | 220 | */ |
|
221 | 221 | |
|
222 | 222 | /*! |
|
223 | 223 | \fn void QPieSlice::colorChanged() |
|
224 | 224 | This signal is emitted when slice color changes. |
|
225 | 225 | \sa brush |
|
226 | 226 | */ |
|
227 | 227 | /*! |
|
228 | 228 | \qmlsignal PieSlice::colorChanged() |
|
229 | 229 | This signal is emitted when slice color changes. |
|
230 | 230 | */ |
|
231 | 231 | |
|
232 | 232 | /*! |
|
233 | 233 | \property QPieSlice::labelBrush |
|
234 | 234 | Brush used to draw label and label arm of the slice. |
|
235 | 235 | \sa label, labelVisible, labelFont, labelArmLengthFactor |
|
236 | 236 | */ |
|
237 | 237 | |
|
238 | 238 | /*! |
|
239 | 239 | \fn void QPieSlice::labelBrushChanged() |
|
240 | 240 | This signal is emitted when the label pen of the slice has changed. |
|
241 | 241 | \sa labelBrush |
|
242 | 242 | */ |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | \property QPieSlice::labelColor |
|
246 | 246 | Color used to draw the slice label. |
|
247 | 247 | This is a convenience property for modifying the slice label brush. |
|
248 | 248 | \sa labelBrush |
|
249 | 249 | */ |
|
250 | 250 | /*! |
|
251 | 251 | \qmlproperty color PieSlice::labelColor |
|
252 | 252 | Color used to draw the slice label. |
|
253 | 253 | */ |
|
254 | 254 | |
|
255 | 255 | /*! |
|
256 | 256 | \fn void QPieSlice::labelColorChanged() |
|
257 | 257 | This signal is emitted when slice label color changes. |
|
258 | 258 | \sa labelColor |
|
259 | 259 | */ |
|
260 | 260 | /*! |
|
261 | 261 | \qmlsignal PieSlice::labelColorChanged() |
|
262 | 262 | This signal is emitted when slice label color changes. |
|
263 | 263 | \sa labelColor |
|
264 | 264 | */ |
|
265 | 265 | |
|
266 | 266 | /*! |
|
267 | 267 | \property QPieSlice::labelFont |
|
268 | 268 | Font used for drawing label text. |
|
269 | 269 | \sa label, labelVisible, labelArmLengthFactor |
|
270 | 270 | */ |
|
271 | 271 | |
|
272 | 272 | /*! |
|
273 | 273 | \fn void QPieSlice::labelFontChanged() |
|
274 | 274 | This signal is emitted when the label font of the slice has changed. |
|
275 | 275 | \sa labelFont |
|
276 | 276 | */ |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | \qmlproperty Font PieSlice::labelFont | |
|
280 | ||
|
281 | Defines the font used for slice label. | |
|
282 | ||
|
283 | See the \l {Font} {QML Font Element} for detailed documentation. | |
|
284 | ||
|
285 | \sa labelVisible, labelPosition | |
|
286 | */ | |
|
287 | ||
|
288 | /*! | |
|
279 | 289 | \property QPieSlice::labelPosition |
|
280 | 290 | Position of the slice label. |
|
281 | 291 | \sa label, labelVisible |
|
282 | 292 | */ |
|
283 | 293 | /*! |
|
284 | 294 | \qmlproperty LabelPosition PieSlice::labelPosition |
|
285 | 295 | Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside. |
|
286 | 296 | \sa labelVisible |
|
287 | 297 | */ |
|
288 | 298 | |
|
289 | 299 | /*! |
|
290 | 300 | \property QPieSlice::labelArmLengthFactor |
|
291 | 301 | Defines the length of the label arm. |
|
292 | 302 | The factor is relative to pie radius. For example: |
|
293 | 303 | 1.0 means the length is the same as the radius. |
|
294 | 304 | 0.5 means the length is half of the radius. |
|
295 | 305 | By default the arm length is 0.15 |
|
296 | 306 | \sa label, labelVisible, labelBrush, labelFont |
|
297 | 307 | */ |
|
298 | 308 | /*! |
|
299 | 309 | \qmlproperty real PieSlice::labelArmLengthFactor |
|
300 | 310 | Defines the length of the label arm. |
|
301 | 311 | The factor is relative to pie radius. For example: |
|
302 | 312 | 1.0 means the length is the same as the radius. |
|
303 | 313 | 0.5 means the length is half of the radius. |
|
304 | 314 | By default the arm length is 0.15 |
|
305 | 315 | \sa labelVisible |
|
306 | 316 | */ |
|
307 | 317 | |
|
308 | 318 | /*! |
|
309 | 319 | \property QPieSlice::explodeDistanceFactor |
|
310 | 320 | When the slice is exploded this factor defines how far the slice is exploded away from the pie. |
|
311 | 321 | The factor is relative to pie radius. For example: |
|
312 | 322 | 1.0 means the distance is the same as the radius. |
|
313 | 323 | 0.5 means the distance is half of the radius. |
|
314 | 324 | By default the distance is is 0.15 |
|
315 | 325 | \sa exploded |
|
316 | 326 | */ |
|
317 | 327 | /*! |
|
318 | 328 | \qmlproperty real PieSlice::explodeDistanceFactor |
|
319 | 329 | When the slice is exploded this factor defines how far the slice is exploded away from the pie. |
|
320 | 330 | The factor is relative to pie radius. For example: |
|
321 | 331 | 1.0 means the distance is the same as the radius. |
|
322 | 332 | 0.5 means the distance is half of the radius. |
|
323 | 333 | By default the distance is is 0.15 |
|
324 | 334 | \sa exploded |
|
325 | 335 | */ |
|
326 | 336 | |
|
327 | 337 | /*! |
|
328 | 338 | \property QPieSlice::percentage |
|
329 | 339 | Percentage of the slice compared to the sum of all slices in the series. |
|
330 | 340 | The actual value ranges from 0.0 to 1.0. |
|
331 | 341 | Updated automatically once the slice is added to the series. |
|
332 | 342 | \sa value, QPieSeries::sum |
|
333 | 343 | */ |
|
334 | 344 | /*! |
|
335 | 345 | \qmlproperty real PieSlice::percentage |
|
336 | 346 | Percentage of the slice compared to the sum of all slices in the series. |
|
337 | 347 | The actual value ranges from 0.0 to 1.0. |
|
338 | 348 | Updated automatically once the slice is added to the series. |
|
339 | 349 | */ |
|
340 | 350 | |
|
341 | 351 | /*! |
|
342 | 352 | \fn void QPieSlice::percentageChanged() |
|
343 | 353 | This signal is emitted when the percentage of the slice has changed. |
|
344 | 354 | \sa percentage |
|
345 | 355 | */ |
|
346 | 356 | /*! |
|
347 | 357 | \qmlsignal void PieSlice::percentageChanged() |
|
348 | 358 | This signal is emitted when the percentage of the slice has changed. |
|
349 | 359 | \sa percentage |
|
350 | 360 | */ |
|
351 | 361 | |
|
352 | 362 | /*! |
|
353 | 363 | \property QPieSlice::startAngle |
|
354 | 364 | Defines the starting angle of this slice in the series it belongs to. |
|
355 | 365 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
356 | 366 | Updated automatically once the slice is added to the series. |
|
357 | 367 | */ |
|
358 | 368 | /*! |
|
359 | 369 | \qmlproperty real PieSlice::startAngle |
|
360 | 370 | Defines the starting angle of this slice in the series it belongs to. |
|
361 | 371 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
362 | 372 | Updated automatically once the slice is added to the series. |
|
363 | 373 | */ |
|
364 | 374 | |
|
365 | 375 | /*! |
|
366 | 376 | \fn void QPieSlice::startAngleChanged() |
|
367 | 377 | This signal is emitted when the starting angle f the slice has changed. |
|
368 | 378 | \sa startAngle |
|
369 | 379 | */ |
|
370 | 380 | /*! |
|
371 | 381 | \qmlsignal PieSlice::startAngleChanged() |
|
372 | 382 | This signal is emitted when the starting angle f the slice has changed. |
|
373 | 383 | \sa startAngle |
|
374 | 384 | */ |
|
375 | 385 | |
|
376 | 386 | /*! |
|
377 | 387 | \property QPieSlice::angleSpan |
|
378 | 388 | Span of the slice in degrees. |
|
379 | 389 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
380 | 390 | Updated automatically once the slice is added to the series. |
|
381 | 391 | */ |
|
382 | 392 | /*! |
|
383 | 393 | \qmlproperty real PieSlice::angleSpan |
|
384 | 394 | Span of the slice in degrees. |
|
385 | 395 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
386 | 396 | Updated automatically once the slice is added to the series. |
|
387 | 397 | */ |
|
388 | 398 | |
|
389 | 399 | /*! |
|
390 | 400 | \fn void QPieSlice::angleSpanChanged() |
|
391 | 401 | This signal is emitted when the angle span of the slice has changed. |
|
392 | 402 | \sa angleSpan |
|
393 | 403 | */ |
|
394 | 404 | /*! |
|
395 | 405 | \qmlsignal PieSlice::angleSpanChanged() |
|
396 | 406 | This signal is emitted when the angle span of the slice has changed. |
|
397 | 407 | \sa angleSpan |
|
398 | 408 | */ |
|
399 | 409 | |
|
400 | 410 | /*! |
|
401 | 411 | \fn void QPieSlice::clicked() |
|
402 | 412 | This signal is emitted when user has clicked the slice. |
|
403 | 413 | \sa QPieSeries::clicked() |
|
404 | 414 | */ |
|
405 | 415 | /*! |
|
406 | 416 | \qmlsignal PieSlice::onClicked() |
|
407 | 417 | This signal is emitted when user has clicked the slice. |
|
408 | 418 | */ |
|
409 | 419 | |
|
410 | 420 | /*! |
|
411 | 421 | \fn void QPieSlice::hovered(bool state) |
|
412 | 422 | This signal is emitted when user has hovered over or away from the slice. |
|
413 | 423 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
414 | 424 | \sa QPieSeries::hovered() |
|
415 | 425 | */ |
|
416 | 426 | /*! |
|
417 | 427 | \qmlsignal PieSlice::onHovered(bool state) |
|
418 | 428 | This signal is emitted when user has hovered over or away from the slice. |
|
419 | 429 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
420 | 430 | */ |
|
421 | 431 | |
|
422 | 432 | /*! |
|
423 | 433 | Constructs an empty slice with a \a parent. |
|
424 | 434 | \sa QPieSeries::append(), QPieSeries::insert() |
|
425 | 435 | */ |
|
426 | 436 | QPieSlice::QPieSlice(QObject *parent) |
|
427 | 437 | :QObject(parent), |
|
428 | 438 | d_ptr(new QPieSlicePrivate(this)) |
|
429 | 439 | { |
|
430 | 440 | |
|
431 | 441 | } |
|
432 | 442 | |
|
433 | 443 | /*! |
|
434 | 444 | Constructs an empty slice with given \a value, \a label and a \a parent. |
|
435 | 445 | \sa QPieSeries::append(), QPieSeries::insert() |
|
436 | 446 | */ |
|
437 | 447 | QPieSlice::QPieSlice(QString label, qreal value, QObject *parent) |
|
438 | 448 | :QObject(parent), |
|
439 | 449 | d_ptr(new QPieSlicePrivate(this)) |
|
440 | 450 | { |
|
441 | 451 | setValue(value); |
|
442 | 452 | setLabel(label); |
|
443 | 453 | } |
|
444 | 454 | |
|
445 | 455 | /*! |
|
446 | 456 | Destroys the slice. |
|
447 | 457 | User should not delete the slice if it has been added to the series. |
|
448 | 458 | */ |
|
449 | 459 | QPieSlice::~QPieSlice() |
|
450 | 460 | { |
|
451 | 461 | |
|
452 | 462 | } |
|
453 | 463 | |
|
454 | 464 | void QPieSlice::setLabel(QString label) |
|
455 | 465 | { |
|
456 | 466 | if (d_ptr->m_data.m_labelText != label) { |
|
457 | 467 | d_ptr->m_data.m_labelText = label; |
|
458 | 468 | emit labelChanged(); |
|
459 | 469 | } |
|
460 | 470 | } |
|
461 | 471 | |
|
462 | 472 | QString QPieSlice::label() const |
|
463 | 473 | { |
|
464 | 474 | return d_ptr->m_data.m_labelText; |
|
465 | 475 | } |
|
466 | 476 | |
|
467 | 477 | void QPieSlice::setValue(qreal value) |
|
468 | 478 | { |
|
469 | 479 | value = qAbs(value); // negative values not allowed |
|
470 | 480 | if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) { |
|
471 | 481 | d_ptr->m_data.m_value = value; |
|
472 | 482 | emit valueChanged(); |
|
473 | 483 | } |
|
474 | 484 | } |
|
475 | 485 | |
|
476 | 486 | qreal QPieSlice::value() const |
|
477 | 487 | { |
|
478 | 488 | return d_ptr->m_data.m_value; |
|
479 | 489 | } |
|
480 | 490 | |
|
481 | 491 | void QPieSlice::setLabelVisible(bool visible) |
|
482 | 492 | { |
|
483 | 493 | if (d_ptr->m_data.m_isLabelVisible != visible) { |
|
484 | 494 | d_ptr->m_data.m_isLabelVisible = visible; |
|
485 | 495 | emit labelVisibleChanged(); |
|
486 | 496 | } |
|
487 | 497 | } |
|
488 | 498 | |
|
489 | 499 | bool QPieSlice::isLabelVisible() const |
|
490 | 500 | { |
|
491 | 501 | return d_ptr->m_data.m_isLabelVisible; |
|
492 | 502 | } |
|
493 | 503 | |
|
494 | 504 | void QPieSlice::setExploded(bool exploded) |
|
495 | 505 | { |
|
496 | 506 | if (d_ptr->m_data.m_isExploded != exploded) { |
|
497 | 507 | d_ptr->m_data.m_isExploded = exploded; |
|
498 | 508 | emit d_ptr->explodedChanged(); |
|
499 | 509 | } |
|
500 | 510 | } |
|
501 | 511 | |
|
502 | 512 | QPieSlice::LabelPosition QPieSlice::labelPosition() |
|
503 | 513 | { |
|
504 | 514 | return d_ptr->m_data.m_labelPosition; |
|
505 | 515 | } |
|
506 | 516 | |
|
507 | 517 | void QPieSlice::setLabelPosition(LabelPosition position) |
|
508 | 518 | { |
|
509 | 519 | if (d_ptr->m_data.m_labelPosition != position) { |
|
510 | 520 | d_ptr->m_data.m_labelPosition = position; |
|
511 | 521 | emit d_ptr->labelPositionChanged(); |
|
512 | 522 | } |
|
513 | 523 | } |
|
514 | 524 | |
|
515 | 525 | bool QPieSlice::isExploded() const |
|
516 | 526 | { |
|
517 | 527 | return d_ptr->m_data.m_isExploded; |
|
518 | 528 | } |
|
519 | 529 | |
|
520 | 530 | void QPieSlice::setPen(const QPen &pen) |
|
521 | 531 | { |
|
522 | 532 | d_ptr->setPen(pen, false); |
|
523 | 533 | } |
|
524 | 534 | |
|
525 | 535 | QPen QPieSlice::pen() const |
|
526 | 536 | { |
|
527 | 537 | return d_ptr->m_data.m_slicePen; |
|
528 | 538 | } |
|
529 | 539 | |
|
530 | 540 | QColor QPieSlice::borderColor() |
|
531 | 541 | { |
|
532 | 542 | return pen().color(); |
|
533 | 543 | } |
|
534 | 544 | |
|
535 | 545 | void QPieSlice::setBorderColor(QColor color) |
|
536 | 546 | { |
|
537 | 547 | QPen p = pen(); |
|
538 | 548 | if (color != p.color()) { |
|
539 | 549 | p.setColor(color); |
|
540 | 550 | setPen(p); |
|
541 | 551 | } |
|
542 | 552 | } |
|
543 | 553 | |
|
544 | 554 | int QPieSlice::borderWidth() |
|
545 | 555 | { |
|
546 | 556 | return pen().width(); |
|
547 | 557 | } |
|
548 | 558 | |
|
549 | 559 | void QPieSlice::setBorderWidth(int width) |
|
550 | 560 | { |
|
551 | 561 | QPen p = pen(); |
|
552 | 562 | if (width != p.width()) { |
|
553 | 563 | p.setWidth(width); |
|
554 | 564 | setPen(p); |
|
555 | 565 | } |
|
556 | 566 | } |
|
557 | 567 | |
|
558 | 568 | void QPieSlice::setBrush(const QBrush &brush) |
|
559 | 569 | { |
|
560 | 570 | d_ptr->setBrush(brush, false); |
|
561 | 571 | } |
|
562 | 572 | |
|
563 | 573 | QBrush QPieSlice::brush() const |
|
564 | 574 | { |
|
565 | 575 | return d_ptr->m_data.m_sliceBrush; |
|
566 | 576 | } |
|
567 | 577 | |
|
568 | 578 | QColor QPieSlice::color() |
|
569 | 579 | { |
|
570 | 580 | return brush().color(); |
|
571 | 581 | } |
|
572 | 582 | |
|
573 | 583 | void QPieSlice::setColor(QColor color) |
|
574 | 584 | { |
|
575 | 585 | QBrush b = brush(); |
|
576 | 586 | if (color != b.color()) { |
|
577 | 587 | b.setColor(color); |
|
578 | 588 | setBrush(b); |
|
579 | 589 | } |
|
580 | 590 | } |
|
581 | 591 | |
|
582 | 592 | void QPieSlice::setLabelBrush(const QBrush &brush) |
|
583 | 593 | { |
|
584 | 594 | d_ptr->setLabelBrush(brush, false); |
|
585 | 595 | } |
|
586 | 596 | |
|
587 | 597 | QBrush QPieSlice::labelBrush() const |
|
588 | 598 | { |
|
589 | 599 | return d_ptr->m_data.m_labelBrush; |
|
590 | 600 | } |
|
591 | 601 | |
|
592 | 602 | QColor QPieSlice::labelColor() |
|
593 | 603 | { |
|
594 | 604 | return labelBrush().color(); |
|
595 | 605 | } |
|
596 | 606 | |
|
597 | 607 | void QPieSlice::setLabelColor(QColor color) |
|
598 | 608 | { |
|
599 | 609 | QBrush b = labelBrush(); |
|
600 | 610 | if (color != b.color()) { |
|
601 | 611 | b.setColor(color); |
|
602 | 612 | setLabelBrush(b); |
|
603 | 613 | } |
|
604 | 614 | } |
|
605 | 615 | |
|
606 | 616 | void QPieSlice::setLabelFont(const QFont &font) |
|
607 | 617 | { |
|
608 | 618 | d_ptr->setLabelFont(font, false); |
|
609 | 619 | } |
|
610 | 620 | |
|
611 | 621 | QFont QPieSlice::labelFont() const |
|
612 | 622 | { |
|
613 | 623 | return d_ptr->m_data.m_labelFont; |
|
614 | 624 | } |
|
615 | 625 | |
|
616 | 626 | void QPieSlice::setLabelArmLengthFactor(qreal factor) |
|
617 | 627 | { |
|
618 | 628 | if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) { |
|
619 | 629 | d_ptr->m_data.m_labelArmLengthFactor = factor; |
|
620 | 630 | emit d_ptr->labelArmLengthFactorChanged(); |
|
621 | 631 | } |
|
622 | 632 | } |
|
623 | 633 | |
|
624 | 634 | qreal QPieSlice::labelArmLengthFactor() const |
|
625 | 635 | { |
|
626 | 636 | return d_ptr->m_data.m_labelArmLengthFactor; |
|
627 | 637 | } |
|
628 | 638 | |
|
629 | 639 | void QPieSlice::setExplodeDistanceFactor(qreal factor) |
|
630 | 640 | { |
|
631 | 641 | if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) { |
|
632 | 642 | d_ptr->m_data.m_explodeDistanceFactor = factor; |
|
633 | 643 | emit d_ptr->explodeDistanceFactorChanged(); |
|
634 | 644 | } |
|
635 | 645 | } |
|
636 | 646 | |
|
637 | 647 | qreal QPieSlice::explodeDistanceFactor() const |
|
638 | 648 | { |
|
639 | 649 | return d_ptr->m_data.m_explodeDistanceFactor; |
|
640 | 650 | } |
|
641 | 651 | |
|
642 | 652 | qreal QPieSlice::percentage() const |
|
643 | 653 | { |
|
644 | 654 | return d_ptr->m_data.m_percentage; |
|
645 | 655 | } |
|
646 | 656 | |
|
647 | 657 | qreal QPieSlice::startAngle() const |
|
648 | 658 | { |
|
649 | 659 | return d_ptr->m_data.m_startAngle; |
|
650 | 660 | } |
|
651 | 661 | |
|
652 | 662 | qreal QPieSlice::angleSpan() const |
|
653 | 663 | { |
|
654 | 664 | return d_ptr->m_data.m_angleSpan; |
|
655 | 665 | } |
|
656 | 666 | |
|
657 | 667 | /*! |
|
658 | 668 | Returns the series that this slice belongs to. |
|
659 | 669 | |
|
660 | 670 | \sa QPieSeries::append() |
|
661 | 671 | */ |
|
662 | 672 | QPieSeries *QPieSlice::series() const |
|
663 | 673 | { |
|
664 | 674 | return d_ptr->m_series; |
|
665 | 675 | } |
|
666 | 676 | |
|
667 | 677 | QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent) |
|
668 | 678 | :QObject(parent), |
|
669 | 679 | q_ptr(parent), |
|
670 | 680 | m_series(0) |
|
671 | 681 | { |
|
672 | 682 | |
|
673 | 683 | } |
|
674 | 684 | |
|
675 | 685 | QPieSlicePrivate::~QPieSlicePrivate() |
|
676 | 686 | { |
|
677 | 687 | |
|
678 | 688 | } |
|
679 | 689 | |
|
680 | 690 | QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice) |
|
681 | 691 | { |
|
682 | 692 | return slice->d_func(); |
|
683 | 693 | } |
|
684 | 694 | |
|
685 | 695 | void QPieSlicePrivate::setPen(const QPen &pen, bool themed) |
|
686 | 696 | { |
|
687 | 697 | if (m_data.m_slicePen != pen) { |
|
688 | 698 | |
|
689 | 699 | QPen oldPen = m_data.m_slicePen; |
|
690 | 700 | |
|
691 | 701 | m_data.m_slicePen = pen; |
|
692 | 702 | m_data.m_slicePen.setThemed(themed); |
|
693 | 703 | |
|
694 | 704 | emit q_ptr->penChanged(); |
|
695 | 705 | if (oldPen.color() != pen.color()) |
|
696 | 706 | emit q_ptr->borderColorChanged(); |
|
697 | 707 | if (oldPen.width() != pen.width()) |
|
698 | 708 | emit q_ptr->borderWidthChanged(); |
|
699 | 709 | } |
|
700 | 710 | } |
|
701 | 711 | |
|
702 | 712 | void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed) |
|
703 | 713 | { |
|
704 | 714 | if (m_data.m_sliceBrush != brush) { |
|
705 | 715 | |
|
706 | 716 | QBrush oldBrush = m_data.m_sliceBrush; |
|
707 | 717 | |
|
708 | 718 | m_data.m_sliceBrush = brush; |
|
709 | 719 | m_data.m_sliceBrush.setThemed(themed); |
|
710 | 720 | |
|
711 | 721 | emit q_ptr->brushChanged(); |
|
712 | 722 | if (oldBrush.color() != brush.color()) |
|
713 | 723 | emit q_ptr->colorChanged(); |
|
714 | 724 | } |
|
715 | 725 | } |
|
716 | 726 | |
|
717 | 727 | void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed) |
|
718 | 728 | { |
|
719 | 729 | if (m_data.m_labelBrush != brush) { |
|
720 | 730 | |
|
721 | 731 | QBrush oldBrush = m_data.m_labelBrush; |
|
722 | 732 | |
|
723 | 733 | m_data.m_labelBrush = brush; |
|
724 | 734 | m_data.m_labelBrush.setThemed(themed); |
|
725 | 735 | |
|
726 | 736 | emit q_ptr->labelBrushChanged(); |
|
727 | 737 | if (oldBrush.color() != brush.color()) |
|
728 | 738 | emit q_ptr->labelColorChanged(); |
|
729 | 739 | } |
|
730 | 740 | } |
|
731 | 741 | |
|
732 | 742 | void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed) |
|
733 | 743 | { |
|
734 | 744 | if (m_data.m_labelFont != font) { |
|
735 | 745 | m_data.m_labelFont = font; |
|
736 | 746 | m_data.m_labelFont.setThemed(themed); |
|
737 | 747 | emit q_ptr->labelFontChanged(); |
|
738 | 748 | } |
|
739 | 749 | } |
|
740 | 750 | |
|
741 | 751 | void QPieSlicePrivate::setPercentage(qreal percentage) |
|
742 | 752 | { |
|
743 | 753 | if (!qFuzzyIsNull(m_data.m_percentage - percentage)) { |
|
744 | 754 | m_data.m_percentage = percentage; |
|
745 | 755 | emit q_ptr->percentageChanged(); |
|
746 | 756 | } |
|
747 | 757 | } |
|
748 | 758 | |
|
749 | 759 | void QPieSlicePrivate::setStartAngle(qreal angle) |
|
750 | 760 | { |
|
751 | 761 | if (!qFuzzyIsNull(m_data.m_startAngle - angle)) { |
|
752 | 762 | m_data.m_startAngle = angle; |
|
753 | 763 | emit q_ptr->startAngleChanged(); |
|
754 | 764 | } |
|
755 | 765 | } |
|
756 | 766 | |
|
757 | 767 | void QPieSlicePrivate::setAngleSpan(qreal span) |
|
758 | 768 | { |
|
759 | 769 | if (!qFuzzyIsNull(m_data.m_angleSpan - span)) { |
|
760 | 770 | m_data.m_angleSpan = span; |
|
761 | 771 | emit q_ptr->angleSpanChanged(); |
|
762 | 772 | } |
|
763 | 773 | } |
|
764 | 774 | |
|
765 | 775 | QTCOMMERCIALCHART_END_NAMESPACE |
|
766 | 776 | |
|
767 | 777 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
768 | 778 | #include "moc_qpieslice.cpp" |
|
769 | 779 | #include "moc_qpieslice_p.cpp" |
General Comments 0
You need to be logged in to leave comments.
Login now