@@ -1,281 +1,346 | |||
|
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 | \section1 Example Usage |
|
38 | 38 | |
|
39 | 39 | \beginfloatleft |
|
40 | 40 | \image demos_qmlchart1.png |
|
41 | 41 | \endfloat |
|
42 | 42 | \clearfloat |
|
43 | 43 | */ |
|
44 | 44 | |
|
45 | 45 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
46 | 46 | : QDeclarativeItem(parent), |
|
47 | 47 | m_chart(new QChart(this)) |
|
48 | 48 | { |
|
49 | 49 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
50 | 50 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | DeclarativeChart::~DeclarativeChart() |
|
54 | 54 | { |
|
55 | 55 | delete m_chart; |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
59 | 59 | { |
|
60 | 60 | if (event->type() == QEvent::ChildAdded) { |
|
61 | 61 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
62 | 62 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
63 | 63 | } |
|
64 | 64 | } |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | void DeclarativeChart::componentComplete() |
|
68 | 68 | { |
|
69 | 69 | // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max(); |
|
70 | 70 | foreach(QObject *child, children()) { |
|
71 | 71 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
72 | 72 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
73 | 73 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
74 | 74 | } |
|
75 | 75 | } |
|
76 | 76 | // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max(); |
|
77 | 77 | |
|
78 | 78 | QDeclarativeItem::componentComplete(); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
82 | 82 | { |
|
83 | 83 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
84 | 84 | if (newGeometry.isValid()) { |
|
85 | 85 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
86 | 86 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
87 | 87 | } |
|
88 | 88 | } |
|
89 | 89 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
93 | 93 | { |
|
94 | 94 | Q_UNUSED(option) |
|
95 | 95 | Q_UNUSED(widget) |
|
96 | 96 | |
|
97 | 97 | // TODO: optimized? |
|
98 | 98 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
102 | 102 | { |
|
103 | 103 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
104 | 104 | if (chartTheme != m_chart->theme()) { |
|
105 | 105 | m_chart->setTheme(chartTheme); |
|
106 | 106 | themeChanged(); |
|
107 | 107 | } |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
111 | 111 | { |
|
112 | 112 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
116 | 116 | { |
|
117 | 117 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
118 | 118 | if (animationOptions != m_chart->animationOptions()) { |
|
119 | 119 | m_chart->setAnimationOptions(animationOptions); |
|
120 | 120 | animationOptionsChanged(); |
|
121 | 121 | } |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
125 | 125 | { |
|
126 | 126 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
127 | 127 | return DeclarativeChart::AllAnimations; |
|
128 | 128 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
129 | 129 | return DeclarativeChart::GridAxisAnimations; |
|
130 | 130 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
131 | 131 | return DeclarativeChart::SeriesAnimations; |
|
132 | 132 | else |
|
133 | 133 | return DeclarativeChart::NoAnimation; |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | void DeclarativeChart::setTitle(QString title) |
|
137 | 137 | { |
|
138 | 138 | if (title != m_chart->title()) { |
|
139 | 139 | m_chart->setTitle(title); |
|
140 | 140 | emit titleChanged(); |
|
141 | 141 | } |
|
142 | 142 | } |
|
143 | 143 | QString DeclarativeChart::title() |
|
144 | 144 | { |
|
145 | 145 | return m_chart->title(); |
|
146 | 146 | } |
|
147 | 147 | |
|
148 | 148 | QAxis *DeclarativeChart::axisX() |
|
149 | 149 | { |
|
150 | 150 | return m_chart->axisX(); |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | QAxis *DeclarativeChart::axisY() |
|
154 | 154 | { |
|
155 | 155 | return m_chart->axisY(); |
|
156 | 156 | } |
|
157 | 157 | |
|
158 | 158 | QLegend *DeclarativeChart::legend() |
|
159 | 159 | { |
|
160 | 160 | return m_chart->legend(); |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | QVariantList DeclarativeChart::axisXLabels() |
|
164 | 164 | { |
|
165 | 165 | QVariantList labels; |
|
166 | 166 | foreach (qreal value, m_chart->axisX()->categories()->values()) { |
|
167 | 167 | labels.append(value); |
|
168 | 168 | labels.append(m_chart->axisX()->categories()->label(value)); |
|
169 | 169 | } |
|
170 | 170 | return labels; |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void DeclarativeChart::setAxisXLabels(QVariantList list) |
|
174 | 174 | { |
|
175 | 175 | QVariant value(QVariant::Invalid); |
|
176 | 176 | foreach (QVariant element, list) { |
|
177 | 177 | if (value.isValid() && element.type() == QVariant::String) { |
|
178 | 178 | m_chart->axisX()->categories()->insert(value.toDouble(), element.toString()); |
|
179 | 179 | value = QVariant(QVariant::Invalid); |
|
180 | 180 | } else { |
|
181 | 181 | if (element.canConvert(QVariant::Double)) |
|
182 | 182 | value = element; |
|
183 | 183 | } |
|
184 | 184 | } |
|
185 | 185 | emit axisLabelsChanged(); |
|
186 | 186 | } |
|
187 | 187 | |
|
188 | 188 | void DeclarativeChart::setTitleColor(QColor color) |
|
189 | 189 | { |
|
190 | 190 | QBrush b = m_chart->titleBrush(); |
|
191 | 191 | if (color != b.color()) { |
|
192 | 192 | b.setColor(color); |
|
193 | 193 | m_chart->setTitleBrush(b); |
|
194 | 194 | emit titleColorChanged(); |
|
195 | 195 | } |
|
196 | 196 | } |
|
197 | 197 | |
|
198 | 198 | QColor DeclarativeChart::titleColor() |
|
199 | 199 | { |
|
200 | 200 | return m_chart->titleBrush().color(); |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
204 | 204 | { |
|
205 | 205 | QBrush b = m_chart->backgroundBrush(); |
|
206 | 206 | if (color != b.color()) { |
|
207 | 207 | b.setColor(color); |
|
208 | 208 | m_chart->setBackgroundBrush(b); |
|
209 | 209 | emit backgroundColorChanged(); |
|
210 | 210 | } |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | QColor DeclarativeChart::backgroundColor() |
|
214 | 214 | { |
|
215 | 215 | return m_chart->backgroundBrush().color(); |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | int DeclarativeChart::count() |
|
219 | 219 | { |
|
220 | 220 | return m_chart->series().count(); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
|
224 | { | |
|
225 | if (enabled != m_chart->isBackgroundDropShadowEnabled()) { | |
|
226 | m_chart->setBackgroundDropShadowEnabled(enabled); | |
|
227 | dropShadowEnabledChanged(enabled); | |
|
228 | } | |
|
229 | } | |
|
230 | ||
|
231 | bool DeclarativeChart::dropShadowEnabled() | |
|
232 | { | |
|
233 | return m_chart->isBackgroundDropShadowEnabled(); | |
|
234 | } | |
|
235 | ||
|
236 | void DeclarativeChart::zoom(qreal factor) | |
|
237 | { | |
|
238 | m_chart->zoom(factor); | |
|
239 | } | |
|
240 | ||
|
241 | void DeclarativeChart::scrollLeft(qreal pixels) | |
|
242 | { | |
|
243 | m_chart->scroll(QPointF(pixels, 0)); | |
|
244 | } | |
|
245 | ||
|
246 | void DeclarativeChart::scrollRight(qreal pixels) | |
|
247 | { | |
|
248 | m_chart->scroll(QPointF(-pixels, 0)); | |
|
249 | } | |
|
250 | ||
|
251 | void DeclarativeChart::scrollUp(qreal pixels) | |
|
252 | { | |
|
253 | m_chart->scroll(QPointF(0, pixels)); | |
|
254 | } | |
|
255 | ||
|
256 | void DeclarativeChart::scrollDown(qreal pixels) | |
|
257 | { | |
|
258 | m_chart->scroll(QPointF(0, -pixels)); | |
|
259 | } | |
|
260 | ||
|
261 | //void DeclarativeChart::scrollLeft(qreal ticks) | |
|
262 | //{ | |
|
263 | // m_chart->scroll(QPointF(ticksToPixels(m_chart->axisX(), ticks), 0)); | |
|
264 | //} | |
|
265 | ||
|
266 | //void DeclarativeChart::scrollRight(qreal ticks) | |
|
267 | //{ | |
|
268 | // m_chart->scroll(QPointF(-ticksToPixels(m_chart->axisX(), ticks), 0)); | |
|
269 | //} | |
|
270 | ||
|
271 | //void DeclarativeChart::scrollUp(qreal ticks) | |
|
272 | //{ | |
|
273 | // m_chart->scroll(QPointF(0, ticksToPixels(m_chart->axisY(), ticks))); | |
|
274 | //} | |
|
275 | ||
|
276 | //void DeclarativeChart::scrollDown(qreal ticks) | |
|
277 | //{ | |
|
278 | // m_chart->scroll(QPointF(0, -ticksToPixels(m_chart->axisY(), ticks))); | |
|
279 | //} | |
|
280 | ||
|
281 | //qreal DeclarativeChart::ticksToPixels(QAxis *axis, qreal ticks) | |
|
282 | //{ | |
|
283 | // qreal tickCount = axis->max() - axis->min(); | |
|
284 | // qreal tickPixels = (m_chart->size().width() - m_chart->margins().width() * 2) / tickCount; | |
|
285 | // return tickPixels * ticks; | |
|
286 | //} | |
|
287 | ||
|
223 | 288 | QAbstractSeries *DeclarativeChart::series(int index) |
|
224 | 289 | { |
|
225 | 290 | if (index < m_chart->series().count()) { |
|
226 | 291 | return m_chart->series().at(index); |
|
227 | 292 | } |
|
228 | 293 | return 0; |
|
229 | 294 | } |
|
230 | 295 | |
|
231 | 296 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
232 | 297 | { |
|
233 | 298 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
234 | 299 | if (series->name() == seriesName) |
|
235 | 300 | return series; |
|
236 | 301 | } |
|
237 | 302 | return 0; |
|
238 | 303 | } |
|
239 | 304 | |
|
240 | 305 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
241 | 306 | { |
|
242 | 307 | QAbstractSeries *series = 0; |
|
243 | 308 | switch (type) { |
|
244 | 309 | case DeclarativeChart::SeriesTypeLine: |
|
245 | 310 | series = new DeclarativeLineSeries(); |
|
246 | 311 | break; |
|
247 | 312 | case DeclarativeChart::SeriesTypeArea: |
|
248 | 313 | series = new DeclarativeAreaSeries(); |
|
249 | 314 | break; |
|
250 | 315 | case DeclarativeChart::SeriesTypeBar: |
|
251 | 316 | series = new DeclarativeBarSeries(); |
|
252 | 317 | break; |
|
253 | 318 | case DeclarativeChart::SeriesTypeStackedBar: |
|
254 | 319 | // TODO |
|
255 | 320 | break; |
|
256 | 321 | case DeclarativeChart::SeriesTypePercentBar: |
|
257 | 322 | // TODO |
|
258 | 323 | break; |
|
259 | 324 | case DeclarativeChart::SeriesTypeGroupedBar: |
|
260 | 325 | series = new DeclarativeGroupedBarSeries(); |
|
261 | 326 | break; |
|
262 | 327 | case DeclarativeChart::SeriesTypePie: |
|
263 | 328 | series = new DeclarativePieSeries(); |
|
264 | 329 | break; |
|
265 | 330 | case DeclarativeChart::SeriesTypeScatter: |
|
266 | 331 | series = new DeclarativeScatterSeries(); |
|
267 | 332 | break; |
|
268 | 333 | case DeclarativeChart::SeriesTypeSpline: |
|
269 | 334 | series = new DeclarativeSplineSeries(); |
|
270 | 335 | break; |
|
271 | 336 | default: |
|
272 | 337 | qWarning() << "Illegal series type"; |
|
273 | 338 | } |
|
274 | 339 | series->setName(name); |
|
275 | 340 | m_chart->addSeries(series); |
|
276 | 341 | return series; |
|
277 | 342 | } |
|
278 | 343 | |
|
279 | 344 | #include "moc_declarativechart.cpp" |
|
280 | 345 | |
|
281 | 346 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,130 +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 NOTIFY themeChanged) |
|
38 | 38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions NOTIFY animationOptionsChanged) |
|
39 | 39 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
|
40 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
|
40 | 41 | Q_PROPERTY(QAxis *axisX READ axisX) |
|
41 | 42 | Q_PROPERTY(QAxis *axisY READ axisY) |
|
42 | 43 | Q_PROPERTY(QLegend *legend READ legend) |
|
43 | 44 | // TODO: how to define axis labels? This is not very convenient |
|
44 | 45 | Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged) |
|
45 | 46 | Q_PROPERTY(int count READ count) |
|
46 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
|
47 | 47 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
48 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) | |
|
48 | 49 | Q_ENUMS(Animation) |
|
49 | 50 | Q_ENUMS(Theme) |
|
50 | 51 | Q_ENUMS(SeriesType) |
|
51 | 52 | |
|
52 | 53 | public: |
|
53 | 54 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
54 | 55 | enum Theme { |
|
55 | 56 | ChartThemeLight = 0, |
|
56 | 57 | ChartThemeBlueCerulean, |
|
57 | 58 | ChartThemeDark, |
|
58 | 59 | ChartThemeBrownSand, |
|
59 | 60 | ChartThemeBlueNcs, |
|
60 | 61 | ChartThemeHighContrast, |
|
61 | 62 | ChartThemeBlueIcy |
|
62 | 63 | }; |
|
63 | 64 | |
|
64 | 65 | enum Animation { |
|
65 | 66 | NoAnimation = 0x0, |
|
66 | 67 | GridAxisAnimations = 0x1, |
|
67 | 68 | SeriesAnimations =0x2, |
|
68 | 69 | AllAnimations = 0x3 |
|
69 | 70 | }; |
|
70 | 71 | |
|
71 | 72 | enum SeriesType { |
|
72 | 73 | SeriesTypeLine, |
|
73 | 74 | SeriesTypeArea, |
|
74 | 75 | SeriesTypeBar, |
|
75 | 76 | SeriesTypeStackedBar, |
|
76 | 77 | SeriesTypePercentBar, |
|
77 | 78 | SeriesTypeGroupedBar, |
|
78 | 79 | SeriesTypePie, |
|
79 | 80 | SeriesTypeScatter, |
|
80 | 81 | SeriesTypeSpline |
|
81 | 82 | }; |
|
82 | 83 | |
|
83 | 84 | public: |
|
84 | 85 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
85 | 86 | ~DeclarativeChart(); |
|
86 | 87 | |
|
87 | 88 | public: // From QDeclarativeItem/QGraphicsItem |
|
88 | 89 | void childEvent(QChildEvent *event); |
|
89 | 90 | void componentComplete(); |
|
90 | 91 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
91 | 92 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
92 | 93 | |
|
93 | 94 | public: |
|
94 | 95 | void setTheme(DeclarativeChart::Theme theme); |
|
95 | 96 | DeclarativeChart::Theme theme(); |
|
96 | 97 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
97 | 98 | DeclarativeChart::Animation animationOptions(); |
|
98 | 99 | void setTitle(QString title); |
|
99 | 100 | QString title(); |
|
100 | 101 | QAxis *axisX(); |
|
101 | 102 | QAxis *axisY(); |
|
102 | 103 | QLegend *legend(); |
|
103 | 104 | QVariantList axisXLabels(); |
|
104 | 105 | void setAxisXLabels(QVariantList list); |
|
105 | 106 | void setTitleColor(QColor color); |
|
106 | 107 | QColor titleColor(); |
|
107 | 108 | void setBackgroundColor(QColor color); |
|
108 | 109 | QColor backgroundColor(); |
|
109 | 110 | int count(); |
|
111 | void setDropShadowEnabled(bool enabled); | |
|
112 | bool dropShadowEnabled(); | |
|
113 | Q_INVOKABLE void zoom(qreal factor); | |
|
114 | Q_INVOKABLE void scrollLeft(qreal pixels); | |
|
115 | Q_INVOKABLE void scrollRight(qreal pixels); | |
|
116 | Q_INVOKABLE void scrollUp(qreal pixels); | |
|
117 | Q_INVOKABLE void scrollDown(qreal pixels); | |
|
110 | 118 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
111 | 119 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
112 | 120 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
113 | 121 | |
|
114 | 122 | Q_SIGNALS: |
|
115 | 123 | void themeChanged(); |
|
116 | 124 | void animationOptionsChanged(); |
|
117 | 125 | void titleChanged(); |
|
118 | 126 | void axisLabelsChanged(); |
|
119 | 127 | void titleColorChanged(); |
|
120 | 128 | void backgroundColorChanged(); |
|
129 | void dropShadowEnabledChanged(bool enabled); | |
|
121 | 130 | |
|
122 | 131 | public: |
|
123 | 132 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
124 | 133 | // multi inheritance, so we now have a QChart as a member instead |
|
125 | 134 | QChart *m_chart; |
|
126 | 135 | }; |
|
127 | 136 | |
|
128 | 137 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | 138 | |
|
130 | 139 | #endif // DECLARATIVECHART_H |
@@ -1,254 +1,283 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | Flow { |
|
26 | 26 | id: flow |
|
27 | 27 | spacing: 5 |
|
28 | 28 | flow: Flow.TopToBottom |
|
29 | 29 | property variant series // TODO: rename to chart |
|
30 | 30 | |
|
31 | 31 | onSeriesChanged: { |
|
32 | 32 | legendConnections.target = series.legend; |
|
33 | 33 | axisXConnections.target = series.axisX; |
|
34 | 34 | axisYConnections.target = series.axisY; |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | Connections { |
|
38 | 38 | target: series |
|
39 | 39 | ignoreUnknownSignals: true |
|
40 | 40 | onVisibleChanged: console.log("chart.onVisibleChanged: " + series.visible); |
|
41 | 41 | onThemeChanged: console.log("chart.onThemeChanged: " + series.theme); |
|
42 | 42 | onLegendChanged: console.log("chart.onLegendChanged: " + series.legend); |
|
43 | 43 | onAnimationOptionsChanged: console.log("chart.onAnimationOptionsChanged: " + series.animationOptions); |
|
44 | 44 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + series.titleColor); |
|
45 | 45 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); |
|
46 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); | |
|
46 | 47 | } |
|
47 | 48 | |
|
48 | 49 | Connections { |
|
49 | 50 | id: legendConnections |
|
50 | 51 | ignoreUnknownSignals: true |
|
51 | 52 | onAlignmentChanged: console.log("legend.onAlignmentChanged: " + alignment); |
|
52 | 53 | onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); |
|
53 | 54 | onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
54 | 55 | onColorChanged: console.log("legend.onColorChanged: " + color); |
|
55 | 56 | onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); |
|
56 | 57 | } |
|
57 | 58 | |
|
58 | 59 | Connections { |
|
59 | 60 | id: axisXConnections |
|
60 | 61 | ignoreUnknownSignals: true |
|
61 | 62 | onColorChanged: console.log("axisX.onColorChanged: " + color); |
|
62 | 63 | onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); |
|
63 | 64 | onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); |
|
64 | 65 | onLabelsAngleChanged: console.log("axisX.onLabelsAngleChanged: " + angle); |
|
65 | 66 | onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); |
|
66 | 67 | onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); |
|
67 | 68 | onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); |
|
68 | 69 | onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); |
|
69 | 70 | onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); |
|
70 | 71 | onNiceNumbersEnabledChanged: console.log("axisX.onNiceNumbersEnabledChanged: " + enabled); |
|
71 | 72 | onTicksCountChanged: console.log("axisX.onTicksCountChanged: " + count); |
|
72 | 73 | } |
|
73 | 74 | |
|
74 | 75 | Connections { |
|
75 | 76 | id: axisYConnections |
|
76 | 77 | ignoreUnknownSignals: true |
|
77 | 78 | onColorChanged: console.log("axisY.onColorChanged: " + color); |
|
78 | 79 | onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); |
|
79 | 80 | onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); |
|
80 | 81 | onLabelsAngleChanged: console.log("axisY.onLabelsAngleChanged: " + angle); |
|
81 | 82 | onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); |
|
82 | 83 | onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); |
|
83 | 84 | onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); |
|
84 | 85 | onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); |
|
85 | 86 | onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
86 | 87 | onNiceNumbersEnabledChanged: console.log("axisY.onNiceNumbersEnabledChanged: " + enabled); |
|
87 | 88 | onTicksCountChanged: console.log("axisY.onTicksCountChanged: " + count); |
|
88 | 89 | } |
|
89 | 90 | |
|
90 | 91 | Button { |
|
91 | 92 | text: "visible" |
|
92 | 93 | onClicked: series.visible = !series.visible; |
|
93 | 94 | } |
|
94 | 95 | Button { |
|
95 | 96 | text: "theme +" |
|
96 | 97 | onClicked: series.theme++; |
|
97 | 98 | } |
|
98 | 99 | Button { |
|
99 | 100 | text: "theme -" |
|
100 | 101 | onClicked: series.theme--; |
|
101 | 102 | } |
|
102 | 103 | Button { |
|
103 | 104 | text: "animation opt +" |
|
104 | 105 | onClicked: series.animationOptions++; |
|
105 | 106 | } |
|
106 | 107 | Button { |
|
107 | 108 | text: "animation opt -" |
|
108 | 109 | onClicked: series.animationOptions--; |
|
109 | 110 | } |
|
110 | 111 | Button { |
|
111 | 112 | text: "title color" |
|
112 | 113 | onClicked: series.titleColor = main.nextColor(); |
|
113 | 114 | } |
|
114 | 115 | Button { |
|
115 | 116 | text: "background color" |
|
116 | 117 | onClicked: series.backgroundColor = main.nextColor(); |
|
117 | 118 | } |
|
118 | 119 | Button { |
|
120 | text: "drop shadow enabled" | |
|
121 | onClicked: series.dropShadowEnabled = !series.dropShadowEnabled; | |
|
122 | } | |
|
123 | Button { | |
|
124 | text: "zoom +" | |
|
125 | onClicked: series.zoom(2); | |
|
126 | } | |
|
127 | Button { | |
|
128 | text: "zoom -" | |
|
129 | onClicked: series.zoom(0.5); | |
|
130 | } | |
|
131 | Button { | |
|
132 | text: "scroll left" | |
|
133 | onClicked: series.scrollLeft(10); | |
|
134 | } | |
|
135 | Button { | |
|
136 | text: "scroll right" | |
|
137 | onClicked: series.scrollRight(10); | |
|
138 | } | |
|
139 | Button { | |
|
140 | text: "scroll up" | |
|
141 | onClicked: series.scrollUp(10); | |
|
142 | } | |
|
143 | Button { | |
|
144 | text: "scroll down" | |
|
145 | onClicked: series.scrollDown(10); | |
|
146 | } | |
|
147 | Button { | |
|
119 | 148 | text: "legend visible" |
|
120 | 149 | onClicked: series.legend.visible = !series.legend.visible; |
|
121 | 150 | } |
|
122 | 151 | Button { |
|
123 | 152 | text: "legend bckgrd visible" |
|
124 | 153 | onClicked: series.legend.backgroundVisible = !series.legend.backgroundVisible; |
|
125 | 154 | } |
|
126 | 155 | Button { |
|
127 | 156 | text: "legend color" |
|
128 | 157 | onClicked: series.legend.color = main.nextColor(); |
|
129 | 158 | } |
|
130 | 159 | Button { |
|
131 | 160 | text: "legend border color" |
|
132 | 161 | onClicked: series.legend.borderColor = main.nextColor(); |
|
133 | 162 | } |
|
134 | 163 | Button { |
|
135 | 164 | text: "legend top" |
|
136 | 165 | onClicked: series.legend.alignment ^= Qt.AlignTop; |
|
137 | 166 | } |
|
138 | 167 | Button { |
|
139 | 168 | text: "legend bottom" |
|
140 | 169 | onClicked: series.legend.alignment ^= Qt.AlignBottom; |
|
141 | 170 | } |
|
142 | 171 | Button { |
|
143 | 172 | text: "legend left" |
|
144 | 173 | onClicked: series.legend.alignment ^= Qt.AlignLeft; |
|
145 | 174 | } |
|
146 | 175 | Button { |
|
147 | 176 | text: "legend right" |
|
148 | 177 | onClicked: series.legend.alignment ^= Qt.AlignRight; |
|
149 | 178 | } |
|
150 | 179 | Button { |
|
151 | 180 | text: "axis X nice nmb" |
|
152 | 181 | onClicked: series.axisX.niceNumbersEnabled = !series.axisX.niceNumbersEnabled; |
|
153 | 182 | } |
|
154 | 183 | Button { |
|
155 | 184 | text: "axis X visible" |
|
156 | 185 | onClicked: series.axisX.visible = !series.axisX.visible; |
|
157 | 186 | } |
|
158 | 187 | Button { |
|
159 | 188 | text: "axis X grid visible" |
|
160 | 189 | onClicked: series.axisX.gridVisible = !series.axisX.gridVisible; |
|
161 | 190 | } |
|
162 | 191 | Button { |
|
163 | 192 | text: "axis X labels visible" |
|
164 | 193 | onClicked: series.axisX.labelsVisible = !series.axisX.labelsVisible; |
|
165 | 194 | } |
|
166 | 195 | Button { |
|
167 | 196 | text: "axis X color" |
|
168 | 197 | onClicked: series.axisX.color = main.nextColor(); |
|
169 | 198 | } |
|
170 | 199 | Button { |
|
171 | 200 | text: "axis X labels color" |
|
172 | 201 | onClicked: series.axisX.labelsColor = main.nextColor(); |
|
173 | 202 | } |
|
174 | 203 | Button { |
|
175 | 204 | text: "axis X labels angle +" |
|
176 | 205 | onClicked: series.axisX.labelsAngle += 5; |
|
177 | 206 | } |
|
178 | 207 | Button { |
|
179 | 208 | text: "axis X labels angle -" |
|
180 | 209 | onClicked: series.axisX.labelsAngle -= 5; |
|
181 | 210 | } |
|
182 | 211 | Button { |
|
183 | 212 | text: "axis X shades visible" |
|
184 | 213 | onClicked: series.axisX.shadesVisible = !series.axisX.shadesVisible; |
|
185 | 214 | } |
|
186 | 215 | Button { |
|
187 | 216 | text: "axis X shades color" |
|
188 | 217 | onClicked: series.axisX.shadesColor = main.nextColor(); |
|
189 | 218 | } |
|
190 | 219 | Button { |
|
191 | 220 | text: "axis X shades bcolor" |
|
192 | 221 | onClicked: series.axisX.shadesBorderColor = main.nextColor(); |
|
193 | 222 | } |
|
194 | 223 | Button { |
|
195 | 224 | text: "axis X ticks count +" |
|
196 | 225 | onClicked: series.axisX.ticksCount++; |
|
197 | 226 | } |
|
198 | 227 | Button { |
|
199 | 228 | text: "axis X ticks count -" |
|
200 | 229 | onClicked: series.axisX.ticksCount--; |
|
201 | 230 | } |
|
202 | 231 | Button { |
|
203 | 232 | text: "axis Y nice nmb" |
|
204 | 233 | onClicked: series.axisY.niceNumbersEnabled = !series.axisY.niceNumbersEnabled; |
|
205 | 234 | } |
|
206 | 235 | Button { |
|
207 | 236 | text: "axis Y visible" |
|
208 | 237 | onClicked: series.axisY.visible = !series.axisY.visible; |
|
209 | 238 | } |
|
210 | 239 | Button { |
|
211 | 240 | text: "axis Y grid visible" |
|
212 | 241 | onClicked: series.axisY.gridVisible = !series.axisY.gridVisible; |
|
213 | 242 | } |
|
214 | 243 | Button { |
|
215 | 244 | text: "axis Y labels visible" |
|
216 | 245 | onClicked: series.axisY.labelsVisible = !series.axisY.labelsVisible; |
|
217 | 246 | } |
|
218 | 247 | Button { |
|
219 | 248 | text: "axis Y color" |
|
220 | 249 | onClicked: series.axisY.color = main.nextColor(); |
|
221 | 250 | } |
|
222 | 251 | Button { |
|
223 | 252 | text: "axis Y labels color" |
|
224 | 253 | onClicked: series.axisY.labelsColor = main.nextColor(); |
|
225 | 254 | } |
|
226 | 255 | Button { |
|
227 | 256 | text: "axis Y labels angle +" |
|
228 | 257 | onClicked: series.axisY.labelsAngle += 5; |
|
229 | 258 | } |
|
230 | 259 | Button { |
|
231 | 260 | text: "axis Y labels angle -" |
|
232 | 261 | onClicked: series.axisY.labelsAngle -= 5; |
|
233 | 262 | } |
|
234 | 263 | Button { |
|
235 | 264 | text: "axis Y shades visible" |
|
236 | 265 | onClicked: series.axisY.shadesVisible = !series.axisY.shadesVisible; |
|
237 | 266 | } |
|
238 | 267 | Button { |
|
239 | 268 | text: "axis Y shades color" |
|
240 | 269 | onClicked: series.axisY.shadesColor = main.nextColor(); |
|
241 | 270 | } |
|
242 | 271 | Button { |
|
243 | 272 | text: "axis Y shades bcolor" |
|
244 | 273 | onClicked: series.axisY.shadesBorderColor = main.nextColor(); |
|
245 | 274 | } |
|
246 | 275 | Button { |
|
247 | 276 | text: "axis Y ticks count +" |
|
248 | 277 | onClicked: series.axisY.ticksCount++; |
|
249 | 278 | } |
|
250 | 279 | Button { |
|
251 | 280 | text: "axis Y ticks count -" |
|
252 | 281 | onClicked: series.axisY.ticksCount--; |
|
253 | 282 | } |
|
254 | 283 | } |
General Comments 0
You need to be logged in to leave comments.
Login now