##// END OF EJS Templates
renamed QBarCategoryAxis related files
Marek Rosa -
r1810:62c8384299b9
parent child
Show More
@@ -1,515 +1,515
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include "declarativelineseries.h"
23 #include "declarativelineseries.h"
24 #include "declarativeareaseries.h"
24 #include "declarativeareaseries.h"
25 #include "declarativebarseries.h"
25 #include "declarativebarseries.h"
26 #include "declarativepieseries.h"
26 #include "declarativepieseries.h"
27 #include "declarativesplineseries.h"
27 #include "declarativesplineseries.h"
28 #include "declarativescatterseries.h"
28 #include "declarativescatterseries.h"
29 #include "qbarcategoriesaxis.h"
29 #include "qbarcategoryaxis.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \qmlclass ChartView DeclarativeChart
34 \qmlclass ChartView DeclarativeChart
35
35
36 ChartView element is the parent that is responsible for showing different chart series types.
36 ChartView element is the parent that is responsible for showing different chart series types.
37
37
38 The following QML shows how to create a simple chart with one pie series:
38 The following QML shows how to create a simple chart with one pie series:
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
41 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
41 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
42
42
43 \beginfloatleft
43 \beginfloatleft
44 \image examples_qmlpiechart.png
44 \image examples_qmlpiechart.png
45 \endfloat
45 \endfloat
46 \clearfloat
46 \clearfloat
47 */
47 */
48
48
49 /*!
49 /*!
50 \qmlproperty Theme ChartView::theme
50 \qmlproperty Theme ChartView::theme
51 Theme defines the visual appearance of the chart, including for example colors, fonts, line
51 Theme defines the visual appearance of the chart, including for example colors, fonts, line
52 widths and chart background.
52 widths and chart background.
53 */
53 */
54
54
55 /*!
55 /*!
56 \qmlproperty Animation ChartView::animation
56 \qmlproperty Animation ChartView::animation
57 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
57 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
58 ChartView.SeriesAnimations or ChartView.AllAnimations.
58 ChartView.SeriesAnimations or ChartView.AllAnimations.
59 */
59 */
60
60
61 /*!
61 /*!
62 \qmlproperty Font ChartView::titleFont
62 \qmlproperty Font ChartView::titleFont
63 The title font of the chart
63 The title font of the chart
64
64
65 See the \l {Font} {QML Font Element} for detailed documentation.
65 See the \l {Font} {QML Font Element} for detailed documentation.
66 */
66 */
67
67
68 /*!
68 /*!
69 \qmlproperty string ChartView::title
69 \qmlproperty string ChartView::title
70 The title of the chart, shown on top of the chart.
70 The title of the chart, shown on top of the chart.
71 \sa ChartView::titleColor
71 \sa ChartView::titleColor
72 */
72 */
73
73
74 /*!
74 /*!
75 \qmlproperty string ChartView::titleColor
75 \qmlproperty string ChartView::titleColor
76 The color of the title text.
76 The color of the title text.
77 */
77 */
78
78
79 /*!
79 /*!
80 \qmlproperty Axis ChartView::axisX
80 \qmlproperty Axis ChartView::axisX
81 The x-axis of the chart.
81 The x-axis of the chart.
82 */
82 */
83
83
84 /*!
84 /*!
85 \qmlproperty Axis ChartView::axisY
85 \qmlproperty Axis ChartView::axisY
86 The default y-axis of the chart.
86 The default y-axis of the chart.
87 */
87 */
88
88
89 /*!
89 /*!
90 \qmlproperty Legend ChartView::legend
90 \qmlproperty Legend ChartView::legend
91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
92 */
92 */
93
93
94 /*!
94 /*!
95 \qmlproperty int ChartView::count
95 \qmlproperty int ChartView::count
96 The count of series added to the chart.
96 The count of series added to the chart.
97 */
97 */
98
98
99 /*!
99 /*!
100 \qmlproperty color ChartView::backgroundColor
100 \qmlproperty color ChartView::backgroundColor
101 The color of the chart's background. By default background color is defined by chart theme.
101 The color of the chart's background. By default background color is defined by chart theme.
102 \sa ChartView::theme
102 \sa ChartView::theme
103 */
103 */
104
104
105 /*!
105 /*!
106 \qmlproperty bool ChartView::dropShadowEnabled
106 \qmlproperty bool ChartView::dropShadowEnabled
107 The chart's border drop shadow. Set to true to enable drop shadow.
107 The chart's border drop shadow. Set to true to enable drop shadow.
108 */
108 */
109
109
110 /*!
110 /*!
111 \qmlproperty real ChartView::topMargin
111 \qmlproperty real ChartView::topMargin
112 The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin
112 The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin
113 area of the chart view. Top margin area is also used by legend, if aligned to top.
113 area of the chart view. Top margin area is also used by legend, if aligned to top.
114 */
114 */
115
115
116 /*!
116 /*!
117 \qmlproperty real ChartView::bottomMargin
117 \qmlproperty real ChartView::bottomMargin
118 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
118 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
119 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
119 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
120 */
120 */
121
121
122 /*!
122 /*!
123 \qmlproperty real ChartView::leftMargin
123 \qmlproperty real ChartView::leftMargin
124 The space between the left side of chart view and the left side of the plot area. The left margin area may be used by
124 The space between the left side of chart view and the left side of the plot area. The left margin area may be used by
125 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
125 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
126 */
126 */
127
127
128 /*!
128 /*!
129 \qmlproperty real ChartView::rightMargin
129 \qmlproperty real ChartView::rightMargin
130 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
130 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
131 by legend (if aligned to right).
131 by legend (if aligned to right).
132 */
132 */
133
133
134 /*!
134 /*!
135 \qmlmethod AbstractSeries ChartView::series(int index)
135 \qmlmethod AbstractSeries ChartView::series(int index)
136 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
136 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
137 the count property of the chart.
137 the count property of the chart.
138 */
138 */
139
139
140 /*!
140 /*!
141 \qmlmethod AbstractSeries ChartView::series(string name)
141 \qmlmethod AbstractSeries ChartView::series(string name)
142 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
142 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
143 */
143 */
144
144
145 /*!
145 /*!
146 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
146 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
147 Creates a series object of \a type to the chart. For example:
147 Creates a series object of \a type to the chart. For example:
148 \code
148 \code
149 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
149 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
150 scatter.markerSize = 22;
150 scatter.markerSize = 22;
151 scatter.append(1.1, 2.0);
151 scatter.append(1.1, 2.0);
152 \endcode
152 \endcode
153 */
153 */
154
154
155 /*!
155 /*!
156 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
156 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
157 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
157 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
158 */
158 */
159
159
160 /*!
160 /*!
161 \qmlmethod ChartView::zoomY(real factor)
161 \qmlmethod ChartView::zoomY(real factor)
162 Zooms in by \a factor on the center of the chart.
162 Zooms in by \a factor on the center of the chart.
163 */
163 */
164
164
165 /*!
165 /*!
166 \qmlmethod ChartView::scrollLeft(real pixels)
166 \qmlmethod ChartView::scrollLeft(real pixels)
167 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
167 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
168 \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max
168 \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max
169 */
169 */
170
170
171 /*!
171 /*!
172 \qmlmethod ChartView::scrollRight(real pixels)
172 \qmlmethod ChartView::scrollRight(real pixels)
173 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
173 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
174 \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max
174 \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max
175 */
175 */
176
176
177 /*!
177 /*!
178 \qmlmethod ChartView::scrollUp(real pixels)
178 \qmlmethod ChartView::scrollUp(real pixels)
179 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
179 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
180 \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max
180 \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max
181 */
181 */
182
182
183 /*!
183 /*!
184 \qmlmethod ChartView::scrollDown(real pixels)
184 \qmlmethod ChartView::scrollDown(real pixels)
185 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
185 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
186 \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max
186 \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max
187 */
187 */
188
188
189 /*!
189 /*!
190 \qmlsignal ChartView::onTopMarginChanged(real margin)
190 \qmlsignal ChartView::onTopMarginChanged(real margin)
191 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
191 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
192 related properties of the legend or chart title.
192 related properties of the legend or chart title.
193 */
193 */
194
194
195 /*!
195 /*!
196 \qmlsignal ChartView::onBottomMarginChanged(real margin)
196 \qmlsignal ChartView::onBottomMarginChanged(real margin)
197 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
197 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
198 related properties of the legend or chart title.
198 related properties of the legend or chart title.
199 */
199 */
200
200
201 /*!
201 /*!
202 \qmlsignal ChartView::onLeftMarginChanged(real margin)
202 \qmlsignal ChartView::onLeftMarginChanged(real margin)
203 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
203 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
204 related properties of the legend or chart title.
204 related properties of the legend or chart title.
205 */
205 */
206
206
207 /*!
207 /*!
208 \qmlsignal ChartView::onRightMarginChanged(real margin)
208 \qmlsignal ChartView::onRightMarginChanged(real margin)
209 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
209 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
210 related properties of the legend or chart title.
210 related properties of the legend or chart title.
211 */
211 */
212
212
213 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
213 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
214 : QDeclarativeItem(parent),
214 : QDeclarativeItem(parent),
215 m_chart(new QChart(this))
215 m_chart(new QChart(this))
216 {
216 {
217 setFlag(QGraphicsItem::ItemHasNoContents, false);
217 setFlag(QGraphicsItem::ItemHasNoContents, false);
218 // m_chart->axisX()->setNiceNumbersEnabled(false);
218 // m_chart->axisX()->setNiceNumbersEnabled(false);
219 m_chartMargins = m_chart->margins();
219 m_chartMargins = m_chart->margins();
220 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
220 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
221 }
221 }
222
222
223 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
223 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
224 {
224 {
225 if (m_chartMargins.top() != newMargins.top())
225 if (m_chartMargins.top() != newMargins.top())
226 topMarginChanged(m_chart->margins().top());
226 topMarginChanged(m_chart->margins().top());
227 if (m_chartMargins.bottom() != newMargins.bottom())
227 if (m_chartMargins.bottom() != newMargins.bottom())
228 bottomMarginChanged(m_chart->margins().bottom());
228 bottomMarginChanged(m_chart->margins().bottom());
229 if (m_chartMargins.left() != newMargins.left())
229 if (m_chartMargins.left() != newMargins.left())
230 leftMarginChanged(m_chart->margins().left());
230 leftMarginChanged(m_chart->margins().left());
231 if (m_chartMargins.right() != newMargins.right())
231 if (m_chartMargins.right() != newMargins.right())
232 rightMarginChanged(m_chart->margins().right());
232 rightMarginChanged(m_chart->margins().right());
233
233
234 m_chartMargins = m_chart->margins();
234 m_chartMargins = m_chart->margins();
235 }
235 }
236
236
237 DeclarativeChart::~DeclarativeChart()
237 DeclarativeChart::~DeclarativeChart()
238 {
238 {
239 delete m_chart;
239 delete m_chart;
240 }
240 }
241
241
242 void DeclarativeChart::childEvent(QChildEvent *event)
242 void DeclarativeChart::childEvent(QChildEvent *event)
243 {
243 {
244 if (event->type() == QEvent::ChildAdded) {
244 if (event->type() == QEvent::ChildAdded) {
245 if (qobject_cast<QAbstractSeries *>(event->child())) {
245 if (qobject_cast<QAbstractSeries *>(event->child())) {
246 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
246 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
247 }
247 }
248 }
248 }
249 }
249 }
250
250
251 void DeclarativeChart::componentComplete()
251 void DeclarativeChart::componentComplete()
252 {
252 {
253 foreach(QObject *child, children()) {
253 foreach(QObject *child, children()) {
254 if (qobject_cast<QAbstractSeries *>(child)) {
254 if (qobject_cast<QAbstractSeries *>(child)) {
255 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
255 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
256 // TODO: how about optional y-axis?
256 // TODO: how about optional y-axis?
257 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
257 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
258 }else if(qobject_cast<QAbstractAxis *>(child)){
258 }else if(qobject_cast<QAbstractAxis *>(child)){
259
259
260 }
260 }
261 }
261 }
262 QDeclarativeItem::componentComplete();
262 QDeclarativeItem::componentComplete();
263 }
263 }
264
264
265 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
265 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
266 {
266 {
267 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
267 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
268 if (newGeometry.isValid()) {
268 if (newGeometry.isValid()) {
269 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
269 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
270 m_chart->resize(newGeometry.width(), newGeometry.height());
270 m_chart->resize(newGeometry.width(), newGeometry.height());
271 }
271 }
272 }
272 }
273 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
273 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
274 }
274 }
275
275
276 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
276 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
277 {
277 {
278 Q_UNUSED(option)
278 Q_UNUSED(option)
279 Q_UNUSED(widget)
279 Q_UNUSED(widget)
280
280
281 // TODO: optimized?
281 // TODO: optimized?
282 painter->setRenderHint(QPainter::Antialiasing, true);
282 painter->setRenderHint(QPainter::Antialiasing, true);
283 }
283 }
284
284
285 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
285 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
286 {
286 {
287 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
287 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
288 if (chartTheme != m_chart->theme())
288 if (chartTheme != m_chart->theme())
289 m_chart->setTheme(chartTheme);
289 m_chart->setTheme(chartTheme);
290 }
290 }
291
291
292 DeclarativeChart::Theme DeclarativeChart::theme()
292 DeclarativeChart::Theme DeclarativeChart::theme()
293 {
293 {
294 return (DeclarativeChart::Theme) m_chart->theme();
294 return (DeclarativeChart::Theme) m_chart->theme();
295 }
295 }
296
296
297 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
297 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
298 {
298 {
299 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
299 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
300 if (animationOptions != m_chart->animationOptions())
300 if (animationOptions != m_chart->animationOptions())
301 m_chart->setAnimationOptions(animationOptions);
301 m_chart->setAnimationOptions(animationOptions);
302 }
302 }
303
303
304 DeclarativeChart::Animation DeclarativeChart::animationOptions()
304 DeclarativeChart::Animation DeclarativeChart::animationOptions()
305 {
305 {
306 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
306 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
307 return DeclarativeChart::AllAnimations;
307 return DeclarativeChart::AllAnimations;
308 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
308 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
309 return DeclarativeChart::GridAxisAnimations;
309 return DeclarativeChart::GridAxisAnimations;
310 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
310 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
311 return DeclarativeChart::SeriesAnimations;
311 return DeclarativeChart::SeriesAnimations;
312 else
312 else
313 return DeclarativeChart::NoAnimation;
313 return DeclarativeChart::NoAnimation;
314 }
314 }
315
315
316 void DeclarativeChart::setTitle(QString title)
316 void DeclarativeChart::setTitle(QString title)
317 {
317 {
318 if (title != m_chart->title())
318 if (title != m_chart->title())
319 m_chart->setTitle(title);
319 m_chart->setTitle(title);
320 }
320 }
321 QString DeclarativeChart::title()
321 QString DeclarativeChart::title()
322 {
322 {
323 return m_chart->title();
323 return m_chart->title();
324 }
324 }
325
325
326 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
326 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
327 {
327 {
328 return m_chart->axisX(series);
328 return m_chart->axisX(series);
329 }
329 }
330
330
331 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
331 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
332 {
332 {
333 return m_chart->axisY(series);
333 return m_chart->axisY(series);
334 }
334 }
335
335
336 QLegend *DeclarativeChart::legend()
336 QLegend *DeclarativeChart::legend()
337 {
337 {
338 return m_chart->legend();
338 return m_chart->legend();
339 }
339 }
340
340
341 void DeclarativeChart::setTitleColor(QColor color)
341 void DeclarativeChart::setTitleColor(QColor color)
342 {
342 {
343 QBrush b = m_chart->titleBrush();
343 QBrush b = m_chart->titleBrush();
344 if (color != b.color()) {
344 if (color != b.color()) {
345 b.setColor(color);
345 b.setColor(color);
346 m_chart->setTitleBrush(b);
346 m_chart->setTitleBrush(b);
347 emit titleColorChanged(color);
347 emit titleColorChanged(color);
348 }
348 }
349 }
349 }
350
350
351 QFont DeclarativeChart::titleFont() const
351 QFont DeclarativeChart::titleFont() const
352 {
352 {
353 return m_chart->titleFont();
353 return m_chart->titleFont();
354 }
354 }
355
355
356 void DeclarativeChart::setTitleFont(const QFont& font)
356 void DeclarativeChart::setTitleFont(const QFont& font)
357 {
357 {
358 m_chart->setTitleFont(font);
358 m_chart->setTitleFont(font);
359 }
359 }
360
360
361 QColor DeclarativeChart::titleColor()
361 QColor DeclarativeChart::titleColor()
362 {
362 {
363 return m_chart->titleBrush().color();
363 return m_chart->titleBrush().color();
364 }
364 }
365
365
366 void DeclarativeChart::setBackgroundColor(QColor color)
366 void DeclarativeChart::setBackgroundColor(QColor color)
367 {
367 {
368 QBrush b = m_chart->backgroundBrush();
368 QBrush b = m_chart->backgroundBrush();
369 if (b.style() != Qt::SolidPattern || color != b.color()) {
369 if (b.style() != Qt::SolidPattern || color != b.color()) {
370 b.setStyle(Qt::SolidPattern);
370 b.setStyle(Qt::SolidPattern);
371 b.setColor(color);
371 b.setColor(color);
372 m_chart->setBackgroundBrush(b);
372 m_chart->setBackgroundBrush(b);
373 emit backgroundColorChanged();
373 emit backgroundColorChanged();
374 }
374 }
375 }
375 }
376
376
377 QColor DeclarativeChart::backgroundColor()
377 QColor DeclarativeChart::backgroundColor()
378 {
378 {
379 return m_chart->backgroundBrush().color();
379 return m_chart->backgroundBrush().color();
380 }
380 }
381
381
382 int DeclarativeChart::count()
382 int DeclarativeChart::count()
383 {
383 {
384 return m_chart->series().count();
384 return m_chart->series().count();
385 }
385 }
386
386
387 void DeclarativeChart::setDropShadowEnabled(bool enabled)
387 void DeclarativeChart::setDropShadowEnabled(bool enabled)
388 {
388 {
389 if (enabled != m_chart->isDropShadowEnabled()) {
389 if (enabled != m_chart->isDropShadowEnabled()) {
390 m_chart->setDropShadowEnabled(enabled);
390 m_chart->setDropShadowEnabled(enabled);
391 dropShadowEnabledChanged(enabled);
391 dropShadowEnabledChanged(enabled);
392 }
392 }
393 }
393 }
394
394
395 bool DeclarativeChart::dropShadowEnabled()
395 bool DeclarativeChart::dropShadowEnabled()
396 {
396 {
397 return m_chart->isDropShadowEnabled();
397 return m_chart->isDropShadowEnabled();
398 }
398 }
399
399
400 qreal DeclarativeChart::topMargin()
400 qreal DeclarativeChart::topMargin()
401 {
401 {
402 return m_chart->margins().top();
402 return m_chart->margins().top();
403 }
403 }
404
404
405 qreal DeclarativeChart::bottomMargin()
405 qreal DeclarativeChart::bottomMargin()
406 {
406 {
407 return m_chart->margins().bottom();
407 return m_chart->margins().bottom();
408 }
408 }
409
409
410 qreal DeclarativeChart::leftMargin()
410 qreal DeclarativeChart::leftMargin()
411 {
411 {
412 return m_chart->margins().left();
412 return m_chart->margins().left();
413 }
413 }
414
414
415 qreal DeclarativeChart::rightMargin()
415 qreal DeclarativeChart::rightMargin()
416 {
416 {
417 return m_chart->margins().right();
417 return m_chart->margins().right();
418 }
418 }
419
419
420 void DeclarativeChart::zoom(qreal factor)
420 void DeclarativeChart::zoom(qreal factor)
421 {
421 {
422 m_chart->zoom(factor);
422 m_chart->zoom(factor);
423 }
423 }
424
424
425 void DeclarativeChart::scrollLeft(qreal pixels)
425 void DeclarativeChart::scrollLeft(qreal pixels)
426 {
426 {
427 m_chart->scroll(pixels, 0);
427 m_chart->scroll(pixels, 0);
428 }
428 }
429
429
430 void DeclarativeChart::scrollRight(qreal pixels)
430 void DeclarativeChart::scrollRight(qreal pixels)
431 {
431 {
432 m_chart->scroll(-pixels, 0);
432 m_chart->scroll(-pixels, 0);
433 }
433 }
434
434
435 void DeclarativeChart::scrollUp(qreal pixels)
435 void DeclarativeChart::scrollUp(qreal pixels)
436 {
436 {
437 m_chart->scroll(0, pixels);
437 m_chart->scroll(0, pixels);
438 }
438 }
439
439
440 void DeclarativeChart::scrollDown(qreal pixels)
440 void DeclarativeChart::scrollDown(qreal pixels)
441 {
441 {
442 m_chart->scroll(0, -pixels);
442 m_chart->scroll(0, -pixels);
443 }
443 }
444
444
445 QAbstractSeries *DeclarativeChart::series(int index)
445 QAbstractSeries *DeclarativeChart::series(int index)
446 {
446 {
447 if (index < m_chart->series().count()) {
447 if (index < m_chart->series().count()) {
448 return m_chart->series().at(index);
448 return m_chart->series().at(index);
449 }
449 }
450 return 0;
450 return 0;
451 }
451 }
452
452
453 QAbstractSeries *DeclarativeChart::series(QString seriesName)
453 QAbstractSeries *DeclarativeChart::series(QString seriesName)
454 {
454 {
455 foreach(QAbstractSeries *series, m_chart->series()) {
455 foreach(QAbstractSeries *series, m_chart->series()) {
456 if (series->name() == seriesName)
456 if (series->name() == seriesName)
457 return series;
457 return series;
458 }
458 }
459 return 0;
459 return 0;
460 }
460 }
461
461
462 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
462 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
463 {
463 {
464 QAbstractSeries *series = 0;
464 QAbstractSeries *series = 0;
465 switch (type) {
465 switch (type) {
466 case DeclarativeChart::SeriesTypeLine:
466 case DeclarativeChart::SeriesTypeLine:
467 series = new DeclarativeLineSeries();
467 series = new DeclarativeLineSeries();
468 break;
468 break;
469 case DeclarativeChart::SeriesTypeArea:
469 case DeclarativeChart::SeriesTypeArea:
470 series = new DeclarativeAreaSeries();
470 series = new DeclarativeAreaSeries();
471 break;
471 break;
472 case DeclarativeChart::SeriesTypeStackedBar:
472 case DeclarativeChart::SeriesTypeStackedBar:
473 series = new DeclarativeStackedBarSeries();
473 series = new DeclarativeStackedBarSeries();
474 break;
474 break;
475 case DeclarativeChart::SeriesTypePercentBar:
475 case DeclarativeChart::SeriesTypePercentBar:
476 series = new DeclarativePercentBarSeries();
476 series = new DeclarativePercentBarSeries();
477 break;
477 break;
478 case DeclarativeChart::SeriesTypeBar:
478 case DeclarativeChart::SeriesTypeBar:
479 series = new DeclarativeBarSeries();
479 series = new DeclarativeBarSeries();
480 break;
480 break;
481 case DeclarativeChart::SeriesTypePie:
481 case DeclarativeChart::SeriesTypePie:
482 series = new DeclarativePieSeries();
482 series = new DeclarativePieSeries();
483 break;
483 break;
484 case DeclarativeChart::SeriesTypeScatter:
484 case DeclarativeChart::SeriesTypeScatter:
485 series = new DeclarativeScatterSeries();
485 series = new DeclarativeScatterSeries();
486 break;
486 break;
487 case DeclarativeChart::SeriesTypeSpline:
487 case DeclarativeChart::SeriesTypeSpline:
488 series = new DeclarativeSplineSeries();
488 series = new DeclarativeSplineSeries();
489 break;
489 break;
490 default:
490 default:
491 qWarning() << "Illegal series type";
491 qWarning() << "Illegal series type";
492 }
492 }
493 series->setName(name);
493 series->setName(name);
494 m_chart->addSeries(series);
494 m_chart->addSeries(series);
495 return series;
495 return series;
496 }
496 }
497
497
498 void DeclarativeChart::setAxisX(QAbstractAxis* axis, QAbstractSeries *series)
498 void DeclarativeChart::setAxisX(QAbstractAxis* axis, QAbstractSeries *series)
499 {
499 {
500 m_chart->setAxisX(axis,series);
500 m_chart->setAxisX(axis,series);
501 }
501 }
502
502
503 void DeclarativeChart::setAxisY(QAbstractAxis* axis, QAbstractSeries *series)
503 void DeclarativeChart::setAxisY(QAbstractAxis* axis, QAbstractSeries *series)
504 {
504 {
505 m_chart->setAxisY(axis,series);
505 m_chart->setAxisY(axis,series);
506 }
506 }
507
507
508 void DeclarativeChart::createDefaultAxes()
508 void DeclarativeChart::createDefaultAxes()
509 {
509 {
510 m_chart->createDefaultAxes();
510 m_chart->createDefaultAxes();
511 }
511 }
512
512
513 #include "moc_declarativechart.cpp"
513 #include "moc_declarativechart.cpp"
514
514
515 QTCOMMERCIALCHART_END_NAMESPACE
515 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,101 +1,101
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 #include <QtDeclarative/qdeclarative.h>
22 #include <QtDeclarative/qdeclarative.h>
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qvalueaxis.h"
25 #include "qvalueaxis.h"
26 #include "qbarcategoriesaxis.h"
26 #include "qbarcategoryaxis.h"
27 #include "declarativechart.h"
27 #include "declarativechart.h"
28 #include "declarativexypoint.h"
28 #include "declarativexypoint.h"
29 #include "declarativelineseries.h"
29 #include "declarativelineseries.h"
30 #include "declarativesplineseries.h"
30 #include "declarativesplineseries.h"
31 #include "declarativeareaseries.h"
31 #include "declarativeareaseries.h"
32 #include "declarativescatterseries.h"
32 #include "declarativescatterseries.h"
33 #include "declarativebarseries.h"
33 #include "declarativebarseries.h"
34 #include "declarativepieseries.h"
34 #include "declarativepieseries.h"
35 #include "qvxymodelmapper.h"
35 #include "qvxymodelmapper.h"
36 #include "qhxymodelmapper.h"
36 #include "qhxymodelmapper.h"
37 #include "qhpiemodelmapper.h"
37 #include "qhpiemodelmapper.h"
38 #include "qvpiemodelmapper.h"
38 #include "qvpiemodelmapper.h"
39 #include "qhbarmodelmapper.h"
39 #include "qhbarmodelmapper.h"
40 #include "qvbarmodelmapper.h"
40 #include "qvbarmodelmapper.h"
41 #include <QAbstractItemModel>
41 #include <QAbstractItemModel>
42
42
43 QTCOMMERCIALCHART_BEGIN_NAMESPACE
43 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44
44
45 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
45 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 virtual void registerTypes(const char *uri)
49 virtual void registerTypes(const char *uri)
50 {
50 {
51 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
51 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
52
52
53 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
53 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
54 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
54 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
55 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
55 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
56 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
56 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
57 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
57 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
58 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
58 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
59 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
59 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
60 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
60 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
61 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
61 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
62 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
62 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
63 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
63 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
64 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
64 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
65 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
65 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
66 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
66 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
67 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
67 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
68 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
68 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
69 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
69 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
70 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
70 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
71 qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis");
71 qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis");
72 qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis");
72 qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis");
73
73
74 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
74 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
75 QLatin1String("Trying to create uncreatable: Legend."));
75 QLatin1String("Trying to create uncreatable: Legend."));
76 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
76 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
77 QLatin1String("Trying to create uncreatable: XYSeries."));
77 QLatin1String("Trying to create uncreatable: XYSeries."));
78 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
78 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
79 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
79 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
80 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
80 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
81 QLatin1String("Trying to create uncreatable: XYModelMapper."));
81 QLatin1String("Trying to create uncreatable: XYModelMapper."));
82 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
82 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
83 QLatin1String("Trying to create uncreatable: PieModelMapper."));
83 QLatin1String("Trying to create uncreatable: PieModelMapper."));
84 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
84 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
85 QLatin1String("Trying to create uncreatable: BarModelMapper."));
85 QLatin1String("Trying to create uncreatable: BarModelMapper."));
86 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
86 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
87 QLatin1String("Trying to create uncreatable: AbstractSeries."));
87 QLatin1String("Trying to create uncreatable: AbstractSeries."));
88 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
88 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
89 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
89 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
90 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
90 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
91 QLatin1String("Trying to create uncreatable: AbstractAxis."));
91 QLatin1String("Trying to create uncreatable: AbstractAxis."));
92 }
92 }
93 };
93 };
94
94
95 #include "plugin.moc"
95 #include "plugin.moc"
96
96
97 QTCOMMERCIALCHART_END_NAMESPACE
97 QTCOMMERCIALCHART_END_NAMESPACE
98
98
99 QTCOMMERCIALCHART_USE_NAMESPACE
99 QTCOMMERCIALCHART_USE_NAMESPACE
100
100
101 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
101 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,52 +1,52
1 #Subdirectiores are defined here, because qt creator doesn't handle nested include(foo.pri) chains very well.
1 #Subdirectiores are defined here, because qt creator doesn't handle nested include(foo.pri) chains very well.
2
2
3 INCLUDEPATH += $$PWD \
3 INCLUDEPATH += $$PWD \
4 $$PWD/valueaxis \
4 $$PWD/valueaxis \
5 $$PWD/categoriesaxis \
5 $$PWD/barcategoryaxis \
6 $$PWD/intervalsaxis \
6 $$PWD/intervalsaxis \
7 $$PWD/datetimeaxis
7 $$PWD/datetimeaxis
8
8
9 DEPENDPATH += $$PWD \
9 DEPENDPATH += $$PWD \
10 $$PWD/valueaxis \
10 $$PWD/valueaxis \
11 $$PWD/categoriesaxis \
11 $$PWD/barcategoryaxis \
12 $$PWD/intervalsaxis \
12 $$PWD/intervalsaxis \
13 $$PWD/datetimeaxis
13 $$PWD/datetimeaxis
14
14
15 SOURCES += \
15 SOURCES += \
16 $$PWD/chartaxis.cpp \
16 $$PWD/chartaxis.cpp \
17 $$PWD/qabstractaxis.cpp \
17 $$PWD/qabstractaxis.cpp \
18 $$PWD/valueaxis/chartvalueaxisx.cpp \
18 $$PWD/valueaxis/chartvalueaxisx.cpp \
19 $$PWD/valueaxis/chartvalueaxisy.cpp \
19 $$PWD/valueaxis/chartvalueaxisy.cpp \
20 $$PWD/valueaxis/qvalueaxis.cpp \
20 $$PWD/valueaxis/qvalueaxis.cpp \
21 $$PWD/categoriesaxis/chartcategoriesaxisx.cpp \
21 $$PWD/barcategoryaxis/chartbarcategoryaxisx.cpp \
22 $$PWD/categoriesaxis/chartcategoriesaxisy.cpp \
22 $$PWD/barcategoryaxis/chartbarcategoryaxisy.cpp \
23 $$PWD/categoriesaxis/qbarcategoriesaxis.cpp \
23 $$PWD/barcategoryaxis/qbarcategoryaxis.cpp \
24 $$PWD/intervalsaxis/chartintervalsaxisx.cpp \
24 $$PWD/intervalsaxis/chartintervalsaxisx.cpp \
25 $$PWD/intervalsaxis/chartintervalsaxisy.cpp \
25 $$PWD/intervalsaxis/chartintervalsaxisy.cpp \
26 $$PWD/intervalsaxis/qintervalsaxis.cpp \
26 $$PWD/intervalsaxis/qintervalsaxis.cpp \
27 $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \
27 $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \
28 $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \
28 $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \
29 $$PWD/datetimeaxis/qdatetimeaxis.cpp
29 $$PWD/datetimeaxis/qdatetimeaxis.cpp
30
30
31 PRIVATE_HEADERS += \
31 PRIVATE_HEADERS += \
32 $$PWD/chartaxis_p.h \
32 $$PWD/chartaxis_p.h \
33 $$PWD/qabstractaxis_p.h \
33 $$PWD/qabstractaxis_p.h \
34 $$PWD/valueaxis/chartvalueaxisx_p.h \
34 $$PWD/valueaxis/chartvalueaxisx_p.h \
35 $$PWD/valueaxis/chartvalueaxisy_p.h \
35 $$PWD/valueaxis/chartvalueaxisy_p.h \
36 $$PWD/valueaxis/qvalueaxis_p.h \
36 $$PWD/valueaxis/qvalueaxis_p.h \
37 $$PWD/categoriesaxis/chartcategoriesaxisx_p.h \
37 $$PWD/barcategoryaxis/chartbarcategoryaxisx_p.h \
38 $$PWD/categoriesaxis/chartcategoriesaxisy_p.h \
38 $$PWD/barcategoryaxis/chartbarcategoryaxisy_p.h \
39 $$PWD/categoriesaxis/qbarcategoriesaxis_p.h \
39 $$PWD/barcategoryaxis/qbarcategoryaxis_p.h \
40 $$PWD/intervalsaxis/chartintervalsaxisx_p.h \
40 $$PWD/intervalsaxis/chartintervalsaxisx_p.h \
41 $$PWD/intervalsaxis/chartintervalsaxisy_p.h \
41 $$PWD/intervalsaxis/chartintervalsaxisy_p.h \
42 $$PWD/intervalsaxis/qintervalsaxis_p.h \
42 $$PWD/intervalsaxis/qintervalsaxis_p.h \
43 $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \
43 $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \
44 $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \
44 $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \
45 $$PWD/datetimeaxis/qdatetimeaxis_p.h
45 $$PWD/datetimeaxis/qdatetimeaxis_p.h
46
46
47 PUBLIC_HEADERS += \
47 PUBLIC_HEADERS += \
48 $$PWD/qabstractaxis.h \
48 $$PWD/qabstractaxis.h \
49 $$PWD/valueaxis/qvalueaxis.h \
49 $$PWD/valueaxis/qvalueaxis.h \
50 $$PWD/categoriesaxis/qbarcategoriesaxis.h \
50 $$PWD/barcategoryaxis/qbarcategoryaxis.h \
51 $$PWD/intervalsaxis/qintervalsaxis.h \
51 $$PWD/intervalsaxis/qintervalsaxis.h \
52 $$PWD/datetimeaxis/qdatetimeaxis.h
52 $$PWD/datetimeaxis/qdatetimeaxis.h
@@ -1,159 +1,159
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartcategoriesaxisx_p.h"
21 #include "chartbarcategoryaxisx_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qbarcategoriesaxis_p.h"
23 #include "qbarcategoryaxis_p.h"
24 #include <QDebug>
24 #include <QDebug>
25 #include <qmath.h>
25 #include <qmath.h>
26
26
27 static int label_padding = 5;
27 static int label_padding = 5;
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
31 ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
32 m_categoriesAxis(axis)
32 m_categoriesAxis(axis)
33 {
33 {
34
34
35 }
35 }
36
36
37 ChartCategoriesAxisX::~ChartCategoriesAxisX()
37 ChartCategoriesAxisX::~ChartCategoriesAxisX()
38 {
38 {
39 }
39 }
40
40
41 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
41 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
42 {
42 {
43 int count = m_categoriesAxis->d_ptr->count();
43 int count = m_categoriesAxis->d_ptr->count();
44
44
45 Q_ASSERT(count>=1);
45 Q_ASSERT(count>=1);
46
46
47 QVector<qreal> points;
47 QVector<qreal> points;
48 points.resize(count+2);
48 points.resize(count+2);
49
49
50 const qreal delta = m_rect.width()/(count);
50 const qreal delta = m_rect.width()/(count);
51 qreal offset =-m_min-0.5;
51 qreal offset =-m_min-0.5;
52
52
53 if(offset<=0) {
53 if(offset<=0) {
54 offset = int(offset * m_rect.width()/(m_max - m_min))%int(delta) + delta;
54 offset = int(offset * m_rect.width()/(m_max - m_min))%int(delta) + delta;
55 }
55 }
56 else {
56 else {
57 offset = int(offset * m_rect.width()/(m_max - m_min))%int(delta);
57 offset = int(offset * m_rect.width()/(m_max - m_min))%int(delta);
58 }
58 }
59
59
60 points[0] = m_rect.left();
60 points[0] = m_rect.left();
61 points[count+1] = m_rect.right();
61 points[count+1] = m_rect.right();
62
62
63 for (int i = 0; i < count; ++i) {
63 for (int i = 0; i < count; ++i) {
64 qreal x = offset + i * delta + m_rect.left();
64 qreal x = offset + i * delta + m_rect.left();
65 points[i+1] = x;
65 points[i+1] = x;
66 }
66 }
67 return points;
67 return points;
68 }
68 }
69
69
70 QStringList ChartCategoriesAxisX::createCategoryLabels(const QVector<qreal>& layout) const
70 QStringList ChartCategoriesAxisX::createCategoryLabels(const QVector<qreal>& layout) const
71 {
71 {
72 QStringList result;
72 QStringList result;
73 qreal d = (m_max - m_min)/m_rect.width();
73 qreal d = (m_max - m_min)/m_rect.width();
74 for (int i = 0;i < layout.count()-1; ++i) {
74 for (int i = 0;i < layout.count()-1; ++i) {
75 qreal x = qFloor((((layout[i+1] + layout[i])/2-m_rect.left())*d + m_min+0.5));
75 qreal x = qFloor((((layout[i+1] + layout[i])/2-m_rect.left())*d + m_min+0.5));
76 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
76 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
77 result << m_categoriesAxis->categories().at(x);
77 result << m_categoriesAxis->categories().at(x);
78 }
78 }
79 else {
79 else {
80 // No label for x coordinate
80 // No label for x coordinate
81 result << "";
81 result << "";
82 }
82 }
83 }
83 }
84 result << "";
84 result << "";
85 return result;
85 return result;
86 }
86 }
87
87
88
88
89 void ChartCategoriesAxisX::updateGeometry()
89 void ChartCategoriesAxisX::updateGeometry()
90 {
90 {
91 const QVector<qreal>& layout = ChartAxis::layout();
91 const QVector<qreal>& layout = ChartAxis::layout();
92
92
93 m_minWidth = 0;
93 m_minWidth = 0;
94 m_minHeight = 0;
94 m_minHeight = 0;
95
95
96 if(layout.isEmpty()) return;
96 if(layout.isEmpty()) return;
97
97
98 QStringList ticksList = createCategoryLabels(layout);
98 QStringList ticksList = createCategoryLabels(layout);
99
99
100 QList<QGraphicsItem *> lines = m_grid->childItems();
100 QList<QGraphicsItem *> lines = m_grid->childItems();
101 QList<QGraphicsItem *> labels = m_labels->childItems();
101 QList<QGraphicsItem *> labels = m_labels->childItems();
102 QList<QGraphicsItem *> shades = m_shades->childItems();
102 QList<QGraphicsItem *> shades = m_shades->childItems();
103 QList<QGraphicsItem *> axis = m_arrow->childItems();
103 QList<QGraphicsItem *> axis = m_arrow->childItems();
104
104
105 Q_ASSERT(labels.size() == ticksList.size());
105 Q_ASSERT(labels.size() == ticksList.size());
106 Q_ASSERT(layout.size() == ticksList.size());
106 Q_ASSERT(layout.size() == ticksList.size());
107
107
108 const qreal delta = m_rect.width()/(m_categoriesAxis->d_ptr->count());
108 const qreal delta = m_rect.width()/(m_categoriesAxis->d_ptr->count());
109
109
110 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
110 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
111 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
111 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
112
112
113 qreal width = m_rect.left();
113 qreal width = m_rect.left();
114 for (int i = 0; i < layout.size(); ++i) {
114 for (int i = 0; i < layout.size(); ++i) {
115 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
115 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
116 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
116 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
117 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
117 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
118 labelItem->setText(ticksList.at(i));
118 labelItem->setText(ticksList.at(i));
119 const QRectF& rect = labelItem->boundingRect();
119 const QRectF& rect = labelItem->boundingRect();
120 QPointF center = rect.center();
120 QPointF center = rect.center();
121 labelItem->setTransformOriginPoint(center.x(), center.y());
121 labelItem->setTransformOriginPoint(center.x(), center.y());
122
122
123 if(i==0){
123 if(i==0){
124 labelItem->setPos(layout[i+1] - (delta)/2 - center.x(), m_rect.bottom() + label_padding);
124 labelItem->setPos(layout[i+1] - (delta)/2 - center.x(), m_rect.bottom() + label_padding);
125 }else{
125 }else{
126 labelItem->setPos(layout[i] + (delta)/2 - center.x(), m_rect.bottom() + label_padding);
126 labelItem->setPos(layout[i] + (delta)/2 - center.x(), m_rect.bottom() + label_padding);
127 }
127 }
128
128
129 if(labelItem->pos().x()<=width || labelItem->pos().x()+ rect.width()>m_rect.right()) {
129 if(labelItem->pos().x()<=width || labelItem->pos().x()+ rect.width()>m_rect.right()) {
130 labelItem->setVisible(false);
130 labelItem->setVisible(false);
131 }
131 }
132 else {
132 else {
133 labelItem->setVisible(true);
133 labelItem->setVisible(true);
134 width=rect.width()+labelItem->pos().x();
134 width=rect.width()+labelItem->pos().x();
135 }
135 }
136
136
137 m_minWidth+=rect.width();
137 m_minWidth+=rect.width();
138 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
138 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
139
139
140 if ((i+1)%2 && i>1) {
140 if ((i+1)%2 && i>1) {
141 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
141 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
142 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
142 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
143 }
143 }
144 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
144 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
145 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
145 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
146 }
146 }
147 }
147 }
148
148
149 void ChartCategoriesAxisX::handleAxisUpdated()
149 void ChartCategoriesAxisX::handleAxisUpdated()
150 {
150 {
151 if(m_categoriesAxis->categories()!=m_categories)
151 if(m_categoriesAxis->categories()!=m_categories)
152 {
152 {
153 m_categories=m_categoriesAxis->categories();
153 m_categories=m_categoriesAxis->categories();
154 if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) updateGeometry();
154 if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) updateGeometry();
155 }
155 }
156 ChartAxis::handleAxisUpdated();
156 ChartAxis::handleAxisUpdated();
157 }
157 }
158
158
159 QTCOMMERCIALCHART_END_NAMESPACE
159 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file renamed from src/axis/categoriesaxis/chartcategoriesaxisx_p.h to src/axis/barcategoryaxis/chartbarcategoryaxisx_p.h
NO CONTENT: file renamed from src/axis/categoriesaxis/chartcategoriesaxisx_p.h to src/axis/barcategoryaxis/chartbarcategoryaxisx_p.h
@@ -1,160 +1,160
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartcategoriesaxisy_p.h"
21 #include "chartbarcategoryaxisy_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qbarcategoriesaxis_p.h"
23 #include "qbarcategoryaxis_p.h"
24 #include <qmath.h>
24 #include <qmath.h>
25
25
26 static int label_padding = 5;
26 static int label_padding = 5;
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 ChartCategoriesAxisY::ChartCategoriesAxisY(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
30 ChartCategoriesAxisY::ChartCategoriesAxisY(QBarCategoryAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
31 m_categoriesAxis(axis)
31 m_categoriesAxis(axis)
32 {
32 {
33 }
33 }
34
34
35 ChartCategoriesAxisY::~ChartCategoriesAxisY()
35 ChartCategoriesAxisY::~ChartCategoriesAxisY()
36 {
36 {
37 }
37 }
38
38
39 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
39 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
40 {
40 {
41 int count = m_categoriesAxis->d_ptr->count();
41 int count = m_categoriesAxis->d_ptr->count();
42
42
43 Q_ASSERT(count>=1);
43 Q_ASSERT(count>=1);
44
44
45 QVector<qreal> points;
45 QVector<qreal> points;
46 points.resize(count+2);
46 points.resize(count+2);
47
47
48 const qreal delta = m_rect.height()/(count);
48 const qreal delta = m_rect.height()/(count);
49 qreal offset = - m_min - 0.5;
49 qreal offset = - m_min - 0.5;
50
50
51 if(offset<=0) {
51 if(offset<=0) {
52 offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta) + delta;
52 offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta) + delta;
53 }
53 }
54 else {
54 else {
55 offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta);
55 offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta);
56 }
56 }
57
57
58 points[0] = m_rect.bottom();
58 points[0] = m_rect.bottom();
59 points[count+1] = m_rect.top();
59 points[count+1] = m_rect.top();
60
60
61 for (int i = 0; i < count; ++i) {
61 for (int i = 0; i < count; ++i) {
62 int y = m_rect.bottom() - i * delta - offset;
62 int y = m_rect.bottom() - i * delta - offset;
63 points[i+1] = y;
63 points[i+1] = y;
64 }
64 }
65 return points;
65 return points;
66 }
66 }
67
67
68 QStringList ChartCategoriesAxisY::createCategoryLabels(const QVector<qreal>& layout) const
68 QStringList ChartCategoriesAxisY::createCategoryLabels(const QVector<qreal>& layout) const
69 {
69 {
70 QStringList result;
70 QStringList result;
71 qreal d = (m_max - m_min)/m_rect.height();
71 qreal d = (m_max - m_min)/m_rect.height();
72 for (int i = 0;i < layout.count()-1; ++i) {
72 for (int i = 0;i < layout.count()-1; ++i) {
73 qreal x = qFloor(((m_rect.height()- (layout[i+1] + layout[i])/2 + m_rect.top())*d + m_min+0.5));
73 qreal x = qFloor(((m_rect.height()- (layout[i+1] + layout[i])/2 + m_rect.top())*d + m_min+0.5));
74 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
74 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
75 result << m_categoriesAxis->categories().at(x);
75 result << m_categoriesAxis->categories().at(x);
76 }
76 }
77 else {
77 else {
78 // No label for x coordinate
78 // No label for x coordinate
79 result << "";
79 result << "";
80 }
80 }
81 }
81 }
82 result << "";
82 result << "";
83 return result;
83 return result;
84 }
84 }
85
85
86 void ChartCategoriesAxisY::updateGeometry()
86 void ChartCategoriesAxisY::updateGeometry()
87 {
87 {
88 const QVector<qreal>& layout = ChartAxis::layout();
88 const QVector<qreal>& layout = ChartAxis::layout();
89
89
90 m_minWidth = 0;
90 m_minWidth = 0;
91 m_minHeight = 0;
91 m_minHeight = 0;
92
92
93 if(layout.isEmpty()) return;
93 if(layout.isEmpty()) return;
94
94
95 QStringList ticksList = createCategoryLabels(layout);
95 QStringList ticksList = createCategoryLabels(layout);
96
96
97 QList<QGraphicsItem *> lines = m_grid->childItems();
97 QList<QGraphicsItem *> lines = m_grid->childItems();
98 QList<QGraphicsItem *> labels = m_labels->childItems();
98 QList<QGraphicsItem *> labels = m_labels->childItems();
99 QList<QGraphicsItem *> shades = m_shades->childItems();
99 QList<QGraphicsItem *> shades = m_shades->childItems();
100 QList<QGraphicsItem *> axis = m_arrow->childItems();
100 QList<QGraphicsItem *> axis = m_arrow->childItems();
101
101
102 Q_ASSERT(labels.size() == ticksList.size());
102 Q_ASSERT(labels.size() == ticksList.size());
103 Q_ASSERT(layout.size() == ticksList.size());
103 Q_ASSERT(layout.size() == ticksList.size());
104
104
105 const qreal delta = m_rect.height()/(m_categoriesAxis->d_ptr->count());
105 const qreal delta = m_rect.height()/(m_categoriesAxis->d_ptr->count());
106
106
107 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
107 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
108 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
108 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
109
109
110 qreal height = m_rect.bottom();
110 qreal height = m_rect.bottom();
111 for (int i = 0; i < layout.size(); ++i) {
111 for (int i = 0; i < layout.size(); ++i) {
112 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
112 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
113 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
113 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
114 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
114 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
115 labelItem->setText(ticksList.at(i));
115 labelItem->setText(ticksList.at(i));
116 const QRectF& rect = labelItem->boundingRect();
116 const QRectF& rect = labelItem->boundingRect();
117 QPointF center = rect.center();
117 QPointF center = rect.center();
118 labelItem->setTransformOriginPoint(center.x(), center.y());
118 labelItem->setTransformOriginPoint(center.x(), center.y());
119
119
120 if(i==0) {
120 if(i==0) {
121 labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i+1] + (delta)/2 - center.y());
121 labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i+1] + (delta)/2 - center.y());
122 }
122 }
123 else {
123 else {
124 labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i] - (delta)/2 - center.y());
124 labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i] - (delta)/2 - center.y());
125 }
125 }
126
126
127 if(labelItem->pos().y()+rect.height()>= height || labelItem->pos().y() < m_rect.top()) {
127 if(labelItem->pos().y()+rect.height()>= height || labelItem->pos().y() < m_rect.top()) {
128 labelItem->setVisible(false);
128 labelItem->setVisible(false);
129 }
129 }
130 else {
130 else {
131 labelItem->setVisible(true);
131 labelItem->setVisible(true);
132 height=labelItem->pos().y();
132 height=labelItem->pos().y();
133 }
133 }
134
134
135 m_minWidth+=rect.width();
135 m_minWidth+=rect.width();
136 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
136 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
137
137
138 if ((i+1)%2 && i>1) {
138 if ((i+1)%2 && i>1) {
139 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
139 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
140 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
140 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
141 }
141 }
142 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
142 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
143 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
143 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
144 }
144 }
145 }
145 }
146
146
147 void ChartCategoriesAxisY::handleAxisUpdated()
147 void ChartCategoriesAxisY::handleAxisUpdated()
148 {
148 {
149
149
150 if(m_categoriesAxis->categories()!=m_categories)
150 if(m_categoriesAxis->categories()!=m_categories)
151 {
151 {
152 m_categories=m_categoriesAxis->categories();
152 m_categories=m_categoriesAxis->categories();
153 if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) {
153 if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) {
154 updateGeometry();
154 updateGeometry();
155 }
155 }
156 }
156 }
157 ChartAxis::handleAxisUpdated();
157 ChartAxis::handleAxisUpdated();
158 }
158 }
159
159
160 QTCOMMERCIALCHART_END_NAMESPACE
160 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file renamed from src/axis/categoriesaxis/chartcategoriesaxisy_p.h to src/axis/barcategoryaxis/chartbarcategoryaxisy_p.h
NO CONTENT: file renamed from src/axis/categoriesaxis/chartcategoriesaxisy_p.h to src/axis/barcategoryaxis/chartbarcategoryaxisy_p.h
@@ -1,471 +1,471
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarcategoriesaxis.h"
21 #include "qbarcategoryaxis.h"
22 #include "qbarcategoriesaxis_p.h"
22 #include "qbarcategoryaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartbarcategoryaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartbarcategoryaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 /*!
30 /*!
31 \class QBarCategoryAxis
31 \class QBarCategoryAxis
32 \brief The QBarCategoryAxis class is used for manipulating chart's axis.
32 \brief The QBarCategoryAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades.
35 BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades.
36 Categories are drawn between ticks. Note that you can use this also with lineseries too.
36 Categories are drawn between ticks. Note that you can use this also with lineseries too.
37 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
37 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
38 */
38 */
39
39
40 /*!
40 /*!
41 \qmlclass BarCategoriesAxis QBarCategoryAxis
41 \qmlclass BarCategoriesAxis QBarCategoryAxis
42 \brief The Axis element is used for manipulating chart's axes.
42 \brief The Axis element is used for manipulating chart's axes.
43
43
44 Axis can be setup to show axis line with tick marks, grid lines and shades.
44 Axis can be setup to show axis line with tick marks, grid lines and shades.
45 Categories are drawn between ticks. Note that you can use this also with lineseries too.
45 Categories are drawn between ticks. Note that you can use this also with lineseries too.
46
46
47 To access BarCategoriesAxis you can use ChartView API. For example:
47 To access BarCategoriesAxis you can use ChartView API. For example:
48 \code
48 \code
49 ChartView {
49 ChartView {
50 BarCategoriesAxis {
50 BarCategoriesAxis {
51 id: categoryAxis
51 id: categoryAxis
52 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
52 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
53 }
53 }
54 // Add a few series...
54 // Add a few series...
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \property QBarCategoryAxis::categories
60 \property QBarCategoryAxis::categories
61 Defines the categories of axis
61 Defines the categories of axis
62 */
62 */
63 /*!
63 /*!
64 \qmlproperty QStringList BarCategoriesAxis::categories
64 \qmlproperty QStringList BarCategoriesAxis::categories
65 Defines the categories of axis
65 Defines the categories of axis
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QBarCategoryAxis::min
69 \property QBarCategoryAxis::min
70 Defines the minimum value on the axis.
70 Defines the minimum value on the axis.
71 */
71 */
72 /*!
72 /*!
73 \qmlproperty QString BarCategoriesAxis::min
73 \qmlproperty QString BarCategoriesAxis::min
74 Defines the minimum value on the axis.
74 Defines the minimum value on the axis.
75 */
75 */
76
76
77 /*!
77 /*!
78 \property QBarCategoryAxis::max
78 \property QBarCategoryAxis::max
79 Defines the maximum value on the axis.
79 Defines the maximum value on the axis.
80 */
80 */
81 /*!
81 /*!
82 \qmlproperty QString BarCategoriesAxis::max
82 \qmlproperty QString BarCategoriesAxis::max
83 Defines the maximum value on the axis.
83 Defines the maximum value on the axis.
84 */
84 */
85
85
86
86
87 /*!
87 /*!
88 \fn void QBarCategoryAxis::categoriesChanged()
88 \fn void QBarCategoryAxis::categoriesChanged()
89 Axis emits signal when the categories of the axis has changed.
89 Axis emits signal when the categories of the axis has changed.
90 */
90 */
91 /*!
91 /*!
92 \fn void QBarCategoryAxis::minChanged(const QString &min)
92 \fn void QBarCategoryAxis::minChanged(const QString &min)
93 Axis emits signal when \a min of axis has changed.
93 Axis emits signal when \a min of axis has changed.
94 */
94 */
95 /*!
95 /*!
96 \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min)
96 \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min)
97 Axis emits signal when \a min of axis has changed.
97 Axis emits signal when \a min of axis has changed.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QBarCategoryAxis::maxChanged(const QString &max)
101 \fn void QBarCategoryAxis::maxChanged(const QString &max)
102 Axis emits signal when \a max of axis has changed.
102 Axis emits signal when \a max of axis has changed.
103 */
103 */
104 /*!
104 /*!
105 \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max)
105 \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max)
106 Axis emits signal when \a max of axis has changed.
106 Axis emits signal when \a max of axis has changed.
107 */
107 */
108
108
109 /*!
109 /*!
110 \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max)
110 \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max)
111 Axis emits signal when \a min or \a max of axis has changed.
111 Axis emits signal when \a min or \a max of axis has changed.
112 */
112 */
113
113
114 /*!
114 /*!
115 Constructs an axis object which is a child of \a parent.
115 Constructs an axis object which is a child of \a parent.
116 */
116 */
117 QBarCategoryAxis::QBarCategoryAxis(QObject *parent):
117 QBarCategoryAxis::QBarCategoryAxis(QObject *parent):
118 QAbstractAxis(*new QBarCategoryAxisPrivate(this),parent)
118 QAbstractAxis(*new QBarCategoryAxisPrivate(this),parent)
119 {
119 {
120 }
120 }
121
121
122 /*!
122 /*!
123 Destroys the object
123 Destroys the object
124 */
124 */
125 QBarCategoryAxis::~QBarCategoryAxis()
125 QBarCategoryAxis::~QBarCategoryAxis()
126 {
126 {
127 Q_D(QBarCategoryAxis);
127 Q_D(QBarCategoryAxis);
128 if(d->m_dataset){
128 if(d->m_dataset){
129 d->m_dataset->removeAxis(this);
129 d->m_dataset->removeAxis(this);
130 }
130 }
131 }
131 }
132
132
133 /*!
133 /*!
134 \internal
134 \internal
135 */
135 */
136 QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
136 QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
137 {
137 {
138
138
139 }
139 }
140
140
141 /*!
141 /*!
142 Appends \a categories to axis
142 Appends \a categories to axis
143 */
143 */
144 void QBarCategoryAxis::append(const QStringList &categories)
144 void QBarCategoryAxis::append(const QStringList &categories)
145 {
145 {
146 if(categories.isEmpty()) return;
146 if(categories.isEmpty()) return;
147
147
148 Q_D(QBarCategoryAxis);
148 Q_D(QBarCategoryAxis);
149 if (d->m_categories.isEmpty()) {
149 if (d->m_categories.isEmpty()) {
150 d->m_categories.append(categories);
150 d->m_categories.append(categories);
151 setRange(categories.first(),categories.last());
151 setRange(categories.first(),categories.last());
152 }else{
152 }else{
153 d->m_categories.append(categories);
153 d->m_categories.append(categories);
154 d->emitUpdated();
154 d->emitUpdated();
155 }
155 }
156 emit categoriesChanged();
156 emit categoriesChanged();
157 }
157 }
158
158
159 /*!
159 /*!
160 Appends \a category to axis
160 Appends \a category to axis
161 */
161 */
162 void QBarCategoryAxis::append(const QString &category)
162 void QBarCategoryAxis::append(const QString &category)
163 {
163 {
164 Q_D(QBarCategoryAxis);
164 Q_D(QBarCategoryAxis);
165 if (d->m_categories.isEmpty()) {
165 if (d->m_categories.isEmpty()) {
166 d->m_categories.append(category);
166 d->m_categories.append(category);
167 setRange(category,category);
167 setRange(category,category);
168 }else{
168 }else{
169 d->m_categories.append(category);
169 d->m_categories.append(category);
170 d->emitUpdated();
170 d->emitUpdated();
171 }
171 }
172 emit categoriesChanged();
172 emit categoriesChanged();
173 }
173 }
174
174
175 /*!
175 /*!
176 Removes \a category from axis
176 Removes \a category from axis
177 */
177 */
178 void QBarCategoryAxis::remove(const QString &category)
178 void QBarCategoryAxis::remove(const QString &category)
179 {
179 {
180 Q_D(QBarCategoryAxis);
180 Q_D(QBarCategoryAxis);
181 if (d->m_categories.contains(category)) {
181 if (d->m_categories.contains(category)) {
182 d->m_categories.removeAt(d->m_categories.indexOf(category));
182 d->m_categories.removeAt(d->m_categories.indexOf(category));
183 if(!d->m_categories.isEmpty())
183 if(!d->m_categories.isEmpty())
184 setRange(d->m_categories.first(),d->m_categories.last());
184 setRange(d->m_categories.first(),d->m_categories.last());
185 else
185 else
186 setRange(QString::null,QString::null);
186 setRange(QString::null,QString::null);
187 emit categoriesChanged();
187 emit categoriesChanged();
188 }
188 }
189 }
189 }
190
190
191 /*!
191 /*!
192 Inserts \a category to axis at \a index
192 Inserts \a category to axis at \a index
193 */
193 */
194 void QBarCategoryAxis::insert(int index, const QString &category)
194 void QBarCategoryAxis::insert(int index, const QString &category)
195 {
195 {
196 Q_D(QBarCategoryAxis);
196 Q_D(QBarCategoryAxis);
197 if (d->m_categories.isEmpty()) {
197 if (d->m_categories.isEmpty()) {
198 d->m_categories.insert(index,category);
198 d->m_categories.insert(index,category);
199 setRange(category,category);
199 setRange(category,category);
200 }else{
200 }else{
201 d->m_categories.insert(index,category);
201 d->m_categories.insert(index,category);
202 d->emitUpdated();
202 d->emitUpdated();
203 }
203 }
204 emit categoriesChanged();
204 emit categoriesChanged();
205 }
205 }
206
206
207 /*!
207 /*!
208 Replaces \a oldCategory with \a newCategory.
208 Replaces \a oldCategory with \a newCategory.
209 If \a oldCategory does not exits on the axis nothing is done.
209 If \a oldCategory does not exits on the axis nothing is done.
210 */
210 */
211 void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory)
211 void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory)
212 {
212 {
213 Q_D(QBarCategoryAxis);
213 Q_D(QBarCategoryAxis);
214 int pos = d->m_categories.indexOf(oldCategory);
214 int pos = d->m_categories.indexOf(oldCategory);
215 if (pos != -1) {
215 if (pos != -1) {
216 d->m_categories.replace(pos, newCategory);
216 d->m_categories.replace(pos, newCategory);
217 d->emitUpdated();
217 d->emitUpdated();
218 emit categoriesChanged();
218 emit categoriesChanged();
219 }
219 }
220 }
220 }
221
221
222 /*!
222 /*!
223 Removes all categories.
223 Removes all categories.
224 */
224 */
225 void QBarCategoryAxis::clear()
225 void QBarCategoryAxis::clear()
226 {
226 {
227 Q_D(QBarCategoryAxis);
227 Q_D(QBarCategoryAxis);
228 d->m_categories.clear();
228 d->m_categories.clear();
229 setRange(QString::null,QString::null);
229 setRange(QString::null,QString::null);
230 emit categoriesChanged();
230 emit categoriesChanged();
231 }
231 }
232
232
233 void QBarCategoryAxis::setCategories(const QStringList &categories)
233 void QBarCategoryAxis::setCategories(const QStringList &categories)
234 {
234 {
235 Q_D(QBarCategoryAxis);
235 Q_D(QBarCategoryAxis);
236 if(d->m_categories!=categories) {
236 if(d->m_categories!=categories) {
237 d->m_categories = categories;
237 d->m_categories = categories;
238 setRange(categories.first(),categories.last());
238 setRange(categories.first(),categories.last());
239 emit categoriesChanged();
239 emit categoriesChanged();
240 }
240 }
241 }
241 }
242
242
243 QStringList QBarCategoryAxis::categories()
243 QStringList QBarCategoryAxis::categories()
244 {
244 {
245 Q_D(QBarCategoryAxis);
245 Q_D(QBarCategoryAxis);
246 return d->m_categories;
246 return d->m_categories;
247 }
247 }
248
248
249 /*!
249 /*!
250 Returns number of categories.
250 Returns number of categories.
251 */
251 */
252 int QBarCategoryAxis::count() const
252 int QBarCategoryAxis::count() const
253 {
253 {
254 Q_D(const QBarCategoryAxis);
254 Q_D(const QBarCategoryAxis);
255 return d->m_categories.count();
255 return d->m_categories.count();
256 }
256 }
257
257
258 /*!
258 /*!
259 Returns category at \a index. Index must be valid.
259 Returns category at \a index. Index must be valid.
260 */
260 */
261 QString QBarCategoryAxis::at(int index) const
261 QString QBarCategoryAxis::at(int index) const
262 {
262 {
263 Q_D(const QBarCategoryAxis);
263 Q_D(const QBarCategoryAxis);
264 return d->m_categories.at(index);
264 return d->m_categories.at(index);
265 }
265 }
266
266
267 /*!
267 /*!
268 Sets minimum category to \a min.
268 Sets minimum category to \a min.
269 */
269 */
270 void QBarCategoryAxis::setMin(const QString& min)
270 void QBarCategoryAxis::setMin(const QString& min)
271 {
271 {
272 Q_D(QBarCategoryAxis);
272 Q_D(QBarCategoryAxis);
273 setRange(min,d->m_maxCategory);
273 setRange(min,d->m_maxCategory);
274 }
274 }
275
275
276 /*!
276 /*!
277 Returns minimum category.
277 Returns minimum category.
278 */
278 */
279 QString QBarCategoryAxis::min() const
279 QString QBarCategoryAxis::min() const
280 {
280 {
281 Q_D(const QBarCategoryAxis);
281 Q_D(const QBarCategoryAxis);
282 return d->m_minCategory;
282 return d->m_minCategory;
283 }
283 }
284
284
285 /*!
285 /*!
286 Sets maximum category to \a max.
286 Sets maximum category to \a max.
287 */
287 */
288 void QBarCategoryAxis::setMax(const QString& max)
288 void QBarCategoryAxis::setMax(const QString& max)
289 {
289 {
290 Q_D(QBarCategoryAxis);
290 Q_D(QBarCategoryAxis);
291 setRange(d->m_minCategory,max);
291 setRange(d->m_minCategory,max);
292 }
292 }
293
293
294 /*!
294 /*!
295 Returns maximum category
295 Returns maximum category
296 */
296 */
297 QString QBarCategoryAxis::max() const
297 QString QBarCategoryAxis::max() const
298 {
298 {
299 Q_D(const QBarCategoryAxis);
299 Q_D(const QBarCategoryAxis);
300 return d->m_maxCategory;
300 return d->m_maxCategory;
301 }
301 }
302
302
303 /*!
303 /*!
304 Sets range from \a minCategory to \a maxCategory
304 Sets range from \a minCategory to \a maxCategory
305 */
305 */
306 void QBarCategoryAxis::setRange(const QString& minCategory, const QString& maxCategory)
306 void QBarCategoryAxis::setRange(const QString& minCategory, const QString& maxCategory)
307 {
307 {
308 Q_D(QBarCategoryAxis);
308 Q_D(QBarCategoryAxis);
309
309
310 bool changed = false;
310 bool changed = false;
311
311
312 //special case
312 //special case
313 if(minCategory.isNull() && maxCategory.isNull()){
313 if(minCategory.isNull() && maxCategory.isNull()){
314 d->m_minCategory = minCategory;
314 d->m_minCategory = minCategory;
315 d->m_maxCategory = maxCategory;
315 d->m_maxCategory = maxCategory;
316 d->m_min = 0;
316 d->m_min = 0;
317 d->m_max = 0;
317 d->m_max = 0;
318 emit minChanged(minCategory);
318 emit minChanged(minCategory);
319 emit maxChanged(maxCategory);
319 emit maxChanged(maxCategory);
320 d->m_count=0;
320 d->m_count=0;
321 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
321 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
322 d->emitUpdated();
322 d->emitUpdated();
323 }
323 }
324
324
325 if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return;
325 if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return;
326
326
327 if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) {
327 if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) {
328 d->m_minCategory = minCategory;
328 d->m_minCategory = minCategory;
329 d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5;
329 d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5;
330 changed = true;
330 changed = true;
331 emit minChanged(minCategory);
331 emit minChanged(minCategory);
332 }
332 }
333
333
334 if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) {
334 if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) {
335 d->m_maxCategory = maxCategory;
335 d->m_maxCategory = maxCategory;
336 d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5;
336 d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5;
337 changed = true;
337 changed = true;
338 emit maxChanged(maxCategory);
338 emit maxChanged(maxCategory);
339 }
339 }
340
340
341 if (changed) {
341 if (changed) {
342 d->m_count=d->m_max - d->m_min;
342 d->m_count=d->m_max - d->m_min;
343 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
343 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
344 d->emitUpdated();
344 d->emitUpdated();
345 }
345 }
346 }
346 }
347
347
348 /*!
348 /*!
349 Returns the type of the axis
349 Returns the type of the axis
350 */
350 */
351 QAbstractAxis::AxisType QBarCategoryAxis::type() const
351 QAbstractAxis::AxisType QBarCategoryAxis::type() const
352 {
352 {
353 return AxisTypeCategories;
353 return AxisTypeCategories;
354 }
354 }
355
355
356 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
356 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
357
357
358 QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis* q):
358 QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis* q):
359 QAbstractAxisPrivate(q),
359 QAbstractAxisPrivate(q),
360 m_min(0.0),
360 m_min(0.0),
361 m_max(0.0),
361 m_max(0.0),
362 m_count(0)
362 m_count(0)
363 {
363 {
364
364
365 }
365 }
366
366
367 QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate()
367 QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate()
368 {
368 {
369
369
370 }
370 }
371
371
372 void QBarCategoryAxisPrivate::setMin(const QVariant &min)
372 void QBarCategoryAxisPrivate::setMin(const QVariant &min)
373 {
373 {
374 setRange(min,m_maxCategory);
374 setRange(min,m_maxCategory);
375 }
375 }
376
376
377 void QBarCategoryAxisPrivate::setMax(const QVariant &max)
377 void QBarCategoryAxisPrivate::setMax(const QVariant &max)
378 {
378 {
379 setRange(m_minCategory,max);
379 setRange(m_minCategory,max);
380 }
380 }
381
381
382 void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max)
382 void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max)
383 {
383 {
384 Q_Q(QBarCategoryAxis);
384 Q_Q(QBarCategoryAxis);
385 QString value1 = min.toString();
385 QString value1 = min.toString();
386 QString value2 = max.toString();
386 QString value2 = max.toString();
387 q->setRange(value1,value2);
387 q->setRange(value1,value2);
388 }
388 }
389
389
390 void QBarCategoryAxisPrivate::handleDomainUpdated()
390 void QBarCategoryAxisPrivate::handleDomainUpdated()
391 {
391 {
392 Q_Q(QBarCategoryAxis);
392 Q_Q(QBarCategoryAxis);
393 Domain* domain = qobject_cast<Domain*>(sender());
393 Domain* domain = qobject_cast<Domain*>(sender());
394
394
395 if(m_orientation==Qt::Horizontal) {
395 if(m_orientation==Qt::Horizontal) {
396 m_min = domain->minX();
396 m_min = domain->minX();
397 m_max = domain->maxX();
397 m_max = domain->maxX();
398 }
398 }
399 else if(m_orientation==Qt::Vertical) {
399 else if(m_orientation==Qt::Vertical) {
400 m_min = domain->minY();
400 m_min = domain->minY();
401 m_max = domain->maxY();
401 m_max = domain->maxY();
402 }
402 }
403
403
404 bool changed = false;
404 bool changed = false;
405
405
406 int min = m_min + 0.5;
406 int min = m_min + 0.5;
407 if(min>=0 && min<m_categories.count()) {
407 if(min>=0 && min<m_categories.count()) {
408 QString minCategory = m_categories.at(min);
408 QString minCategory = m_categories.at(min);
409 if(m_minCategory!=minCategory && !minCategory.isEmpty()) {
409 if(m_minCategory!=minCategory && !minCategory.isEmpty()) {
410 m_minCategory=minCategory;
410 m_minCategory=minCategory;
411 changed=true;
411 changed=true;
412 emit q->minChanged(minCategory);
412 emit q->minChanged(minCategory);
413 }
413 }
414 }
414 }
415 int max = m_max - 0.5;
415 int max = m_max - 0.5;
416 if(max>=0 && max<m_categories.count()) {
416 if(max>=0 && max<m_categories.count()) {
417 QString maxCategory = m_categories.at(max);
417 QString maxCategory = m_categories.at(max);
418 if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) {
418 if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) {
419 m_maxCategory=maxCategory;
419 m_maxCategory=maxCategory;
420 emit q->maxChanged(maxCategory);
420 emit q->maxChanged(maxCategory);
421 }
421 }
422 }
422 }
423
423
424 if (changed) {
424 if (changed) {
425 emit q->rangeChanged(m_minCategory,m_maxCategory);
425 emit q->rangeChanged(m_minCategory,m_maxCategory);
426 }
426 }
427 }
427 }
428
428
429 ChartAxis* QBarCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
429 ChartAxis* QBarCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
430 {
430 {
431 Q_Q(QBarCategoryAxis);
431 Q_Q(QBarCategoryAxis);
432 if(m_orientation == Qt::Vertical){
432 if(m_orientation == Qt::Vertical){
433 return new ChartCategoriesAxisY(q,presenter);
433 return new ChartCategoriesAxisY(q,presenter);
434 }else{
434 }else{
435 return new ChartCategoriesAxisX(q,presenter);
435 return new ChartCategoriesAxisX(q,presenter);
436 }
436 }
437 }
437 }
438
438
439 void QBarCategoryAxisPrivate::intializeDomain(Domain* domain)
439 void QBarCategoryAxisPrivate::intializeDomain(Domain* domain)
440 {
440 {
441
441
442 Q_Q(QBarCategoryAxis);
442 Q_Q(QBarCategoryAxis);
443 if(m_max==m_min) {
443 if(m_max==m_min) {
444 int min;
444 int min;
445 int max;
445 int max;
446 if(m_orientation==Qt::Vertical) {
446 if(m_orientation==Qt::Vertical) {
447 min = domain->minY() + 0.5;
447 min = domain->minY() + 0.5;
448 max = domain->maxY() - 0.5;
448 max = domain->maxY() - 0.5;
449 }
449 }
450 else {
450 else {
451 min = domain->minX() + 0.5;
451 min = domain->minX() + 0.5;
452 max = domain->maxX() - 0.5;
452 max = domain->maxX() - 0.5;
453 }
453 }
454
454
455 if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count())
455 if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count())
456 q->setRange(m_categories.at(min),m_categories.at(max));
456 q->setRange(m_categories.at(min),m_categories.at(max));
457 }
457 }
458 else {
458 else {
459 if(m_orientation==Qt::Vertical) {
459 if(m_orientation==Qt::Vertical) {
460 domain->setRangeY(m_min, m_max);
460 domain->setRangeY(m_min, m_max);
461 }
461 }
462 else {
462 else {
463 domain->setRangeX(m_min, m_max);
463 domain->setRangeX(m_min, m_max);
464 }
464 }
465 }
465 }
466 }
466 }
467
467
468 #include "moc_qbarcategoriesaxis.cpp"
468 #include "moc_qbarcategoryaxis.cpp"
469 #include "moc_qbarcategoriesaxis_p.cpp"
469 #include "moc_qbarcategoryaxis_p.cpp"
470
470
471 QTCOMMERCIALCHART_END_NAMESPACE
471 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file renamed from src/axis/categoriesaxis/qbarcategoriesaxis.h to src/axis/barcategoryaxis/qbarcategoryaxis.h
NO CONTENT: file renamed from src/axis/categoriesaxis/qbarcategoriesaxis.h to src/axis/barcategoryaxis/qbarcategoryaxis.h
@@ -1,76 +1,76
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBARCATEGORIESAXIS_P_H
30 #ifndef QBARCATEGORIESAXIS_P_H
31 #define QBARCATEGORIESAXIS_P_H
31 #define QBARCATEGORIESAXIS_P_H
32
32
33 #include "qbarcategoriesaxis.h"
33 #include "qbarcategoryaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class Domain;
38 class Domain;
39
39
40 class QBarCategoryAxisPrivate : public QAbstractAxisPrivate
40 class QBarCategoryAxisPrivate : public QAbstractAxisPrivate
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43
43
44 public:
44 public:
45 QBarCategoryAxisPrivate(QBarCategoryAxis *q);
45 QBarCategoryAxisPrivate(QBarCategoryAxis *q);
46 ~QBarCategoryAxisPrivate();
46 ~QBarCategoryAxisPrivate();
47
47
48 public:
48 public:
49 ChartAxis* createGraphics(ChartPresenter* presenter);
49 ChartAxis* createGraphics(ChartPresenter* presenter);
50 void intializeDomain(Domain* domain);
50 void intializeDomain(Domain* domain);
51 void handleDomainUpdated();
51 void handleDomainUpdated();
52 qreal min() { return m_min;}
52 qreal min() { return m_min;}
53 qreal max() { return m_max;}
53 qreal max() { return m_max;}
54 int count() const { return m_count; }
54 int count() const { return m_count; }
55
55
56 private:
56 private:
57 //range handling
57 //range handling
58 void setMin(const QVariant &min);
58 void setMin(const QVariant &min);
59 void setMax(const QVariant &max);
59 void setMax(const QVariant &max);
60 void setRange(const QVariant &min, const QVariant &max);
60 void setRange(const QVariant &min, const QVariant &max);
61
61
62 private:
62 private:
63 QStringList m_categories;
63 QStringList m_categories;
64 QString m_minCategory;
64 QString m_minCategory;
65 QString m_maxCategory;
65 QString m_maxCategory;
66 qreal m_min;
66 qreal m_min;
67 qreal m_max;
67 qreal m_max;
68 int m_count;
68 int m_count;
69
69
70 private:
70 private:
71 Q_DECLARE_PUBLIC(QBarCategoryAxis);
71 Q_DECLARE_PUBLIC(QBarCategoryAxis);
72 };
72 };
73
73
74 QTCOMMERCIALCHART_END_NAMESPACE
74 QTCOMMERCIALCHART_END_NAMESPACE
75
75
76 #endif // QBARCATEGORIESAXIS_P_H
76 #endif // QBARCATEGORIESAXIS_P_H
@@ -1,127 +1,127
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qhorizontalbarseries.h"
21 #include "qhorizontalbarseries.h"
22 #include "qhorizontalbarseries_p.h"
22 #include "qhorizontalbarseries_p.h"
23 #include "horizontalbarchartitem_p.h"
23 #include "horizontalbarchartitem_p.h"
24 #include "horizontalbaranimation_p.h"
24 #include "horizontalbaranimation_p.h"
25 #include "qbarcategoriesaxis.h"
25 #include "qbarcategoryaxis.h"
26
26
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29
29
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QHorizontalBarSeries
34 \class QHorizontalBarSeries
35 \brief Series for creating horizontal bar chart
35 \brief Series for creating horizontal bar chart
36 \mainclass
36 \mainclass
37
37
38 QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
39 as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data
39 as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data
40 from sets to categories, which are defined by a QStringList.
40 from sets to categories, which are defined by a QStringList.
41
41
42 See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart.
42 See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart.
43 \image examples_horizontalbarchart.png
43 \image examples_horizontalbarchart.png
44
44
45 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries
45 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries
46 */
46 */
47 /*
47 /*
48 // TODO:
48 // TODO:
49 \qmlclass Horizontal QHorizontalBarSeries
49 \qmlclass Horizontal QHorizontalBarSeries
50 \inherits AbstractBarSeries
50 \inherits AbstractBarSeries
51
51
52 The following QML shows how to create a simple grouped bar chart:
52 The following QML shows how to create a simple grouped bar chart:
53 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
53 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
54 \beginfloatleft
54 \beginfloatleft
55 \image demos_qmlchart6.png
55 \image demos_qmlchart6.png
56 \endfloat
56 \endfloat
57 \clearfloat
57 \clearfloat
58 */
58 */
59
59
60
60
61 /*!
61 /*!
62 Constructs empty QHorizontalBarSeries.
62 Constructs empty QHorizontalBarSeries.
63 QHorizontalBarSeries is QObject which is a child of a \a parent.
63 QHorizontalBarSeries is QObject which is a child of a \a parent.
64 */
64 */
65 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) :
65 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) :
66 QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
66 QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
67 {
67 {
68 }
68 }
69
69
70 /*!
70 /*!
71 Destructor
71 Destructor
72 Removes series from chart.
72 Removes series from chart.
73 */
73 */
74 QHorizontalBarSeries::~QHorizontalBarSeries()
74 QHorizontalBarSeries::~QHorizontalBarSeries()
75 {
75 {
76 Q_D(QHorizontalBarSeries);
76 Q_D(QHorizontalBarSeries);
77 if(d->m_dataset) {
77 if(d->m_dataset) {
78 d->m_dataset->removeSeries(this);
78 d->m_dataset->removeSeries(this);
79 }
79 }
80 }
80 }
81
81
82 /*!
82 /*!
83 Returns QChartSeries::SeriesTypeHorizontalBar.
83 Returns QChartSeries::SeriesTypeHorizontalBar.
84 */
84 */
85 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
85 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
86 {
86 {
87 return QAbstractSeries::SeriesTypeHorizontalBar;
87 return QAbstractSeries::SeriesTypeHorizontalBar;
88 }
88 }
89
89
90 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91
91
92 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q)
92 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q)
93 {
93 {
94
94
95 }
95 }
96
96
97 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
97 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
98 {
98 {
99 qreal minX(domain.minX());
99 qreal minX(domain.minX());
100 qreal minY(domain.minY());
100 qreal minY(domain.minY());
101 qreal maxX(domain.maxX());
101 qreal maxX(domain.maxX());
102 qreal maxY(domain.maxY());
102 qreal maxY(domain.maxY());
103
103
104 qreal y = categoryCount();
104 qreal y = categoryCount();
105 minX = qMin(minX, min());
105 minX = qMin(minX, min());
106 minY = qMin(minY, - (qreal)0.5);
106 minY = qMin(minY, - (qreal)0.5);
107 maxX = qMax(maxX, max());
107 maxX = qMax(maxX, max());
108 maxY = qMax(maxY, y - (qreal)0.5);
108 maxY = qMax(maxY, y - (qreal)0.5);
109
109
110 domain.setRange(minX,maxX,minY,maxY);
110 domain.setRange(minX,maxX,minY,maxY);
111 }
111 }
112
112
113 ChartElement* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
113 ChartElement* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
114 {
114 {
115 Q_Q(QHorizontalBarSeries);
115 Q_Q(QHorizontalBarSeries);
116
116
117 HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter);
117 HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter);
118 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
118 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
119 bar->setAnimation(new HorizontalBarAnimation(bar));
119 bar->setAnimation(new HorizontalBarAnimation(bar));
120 }
120 }
121 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
121 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
122 return bar;
122 return bar;
123 }
123 }
124
124
125 #include "moc_qhorizontalbarseries.cpp"
125 #include "moc_qhorizontalbarseries.cpp"
126
126
127 QTCOMMERCIALCHART_END_NAMESPACE
127 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,828 +1,828
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractbarseries.h"
21 #include "qabstractbarseries.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "qvalueaxis.h"
29 #include "qvalueaxis.h"
30 #include "qbarcategoriesaxis.h"
30 #include "qbarcategoryaxis.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QAbstractBarSeries
35 \class QAbstractBarSeries
36 \brief Series for creating a bar chart
36 \brief Series for creating a bar chart
37 \mainclass
37 \mainclass
38
38
39 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 shows the x-values.
42 shows the x-values.
43
43
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 \image examples_barchart.png
45 \image examples_barchart.png
46
46
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 */
48 */
49 /*!
49 /*!
50 \qmlclass AbstractBarSeries QAbstractBarSeries
50 \qmlclass AbstractBarSeries QAbstractBarSeries
51 \inherits QAbstractSeries
51 \inherits QAbstractSeries
52
52
53 The following QML shows how to create a simple bar chart:
53 The following QML shows how to create a simple bar chart:
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55
55
56 \beginfloatleft
56 \beginfloatleft
57 \image demos_qmlchart6.png
57 \image demos_qmlchart6.png
58 \endfloat
58 \endfloat
59 \clearfloat
59 \clearfloat
60 */
60 */
61
61
62 /*!
62 /*!
63 \property QAbstractBarSeries::barWidth
63 \property QAbstractBarSeries::barWidth
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
67 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
68 \sa QBarSeries
68 \sa QBarSeries
69 */
69 */
70 /*!
70 /*!
71 \qmlproperty real AbstractBarSeries::barWidth
71 \qmlproperty real AbstractBarSeries::barWidth
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
75 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
76 */
76 */
77
77
78 /*!
78 /*!
79 \property QAbstractBarSeries::count
79 \property QAbstractBarSeries::count
80 Holds the number of sets in series.
80 Holds the number of sets in series.
81 */
81 */
82 /*!
82 /*!
83 \qmlproperty int AbstractBarSeries::count
83 \qmlproperty int AbstractBarSeries::count
84 Holds the number of sets in series.
84 Holds the number of sets in series.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QAbstractBarSeries::labelsVisible
88 \property QAbstractBarSeries::labelsVisible
89 Defines the visibility of the labels in series
89 Defines the visibility of the labels in series
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty bool AbstractBarSeries::labelsVisible
92 \qmlproperty bool AbstractBarSeries::labelsVisible
93 Defines the visibility of the labels in series
93 Defines the visibility of the labels in series
94 */
94 */
95
95
96 /*!
96 /*!
97 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
97 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 Clicked bar inside set is indexed by \a index
99 Clicked bar inside set is indexed by \a index
100 */
100 */
101 /*!
101 /*!
102 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
102 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 Clicked bar inside set is indexed by \a index
104 Clicked bar inside set is indexed by \a index
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
108 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109
109
110 The signal is emitted if mouse is hovered on top of series.
110 The signal is emitted if mouse is hovered on top of series.
111 Parameter \a barset is the pointer of barset, where hover happened.
111 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 */
113 */
114 /*!
114 /*!
115 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
115 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
116
116
117 The signal is emitted if mouse is hovered on top of series.
117 The signal is emitted if mouse is hovered on top of series.
118 Parameter \a barset is the pointer of barset, where hover happened.
118 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QAbstractBarSeries::countChanged()
123 \fn void QAbstractBarSeries::countChanged()
124 This signal is emitted when barset count has been changed, for example by append or remove.
124 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal AbstractBarSeries::onCountChanged()
127 \qmlsignal AbstractBarSeries::onCountChanged()
128 This signal is emitted when barset count has been changed, for example by append or remove.
128 This signal is emitted when barset count has been changed, for example by append or remove.
129 */
129 */
130
130
131 /*!
131 /*!
132 \fn void QAbstractBarSeries::labelsVisibleChanged()
132 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 This signal is emitted when labels visibility have changed.
133 This signal is emitted when labels visibility have changed.
134 \sa isLabelsVisible(), setLabelsVisible()
134 \sa isLabelsVisible(), setLabelsVisible()
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
138 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 This signal is emitted when \a sets have been added to the series.
139 This signal is emitted when \a sets have been added to the series.
140 \sa append(), insert()
140 \sa append(), insert()
141 */
141 */
142 /*!
142 /*!
143 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
143 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
144 Emitted when \a barset has been added to the series.
144 Emitted when \a barset has been added to the series.
145 */
145 */
146
146
147 /*!
147 /*!
148 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
148 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 This signal is emitted when \a sets have been removed from the series.
149 This signal is emitted when \a sets have been removed from the series.
150 \sa remove()
150 \sa remove()
151 */
151 */
152 /*!
152 /*!
153 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
153 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
154 Emitted when \a barset has been removed from the series.
154 Emitted when \a barset has been removed from the series.
155 */
155 */
156
156
157 /*!
157 /*!
158 \qmlmethod BarSet AbstractBarSeries::at(int index)
158 \qmlmethod BarSet AbstractBarSeries::at(int index)
159 Returns bar set at \a index. Returns null if the index is not valid.
159 Returns bar set at \a index. Returns null if the index is not valid.
160 */
160 */
161
161
162 /*!
162 /*!
163 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
163 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
164 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
164 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
165 For example:
165 For example:
166 \code
166 \code
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 \endcode
169 \endcode
170 */
170 */
171
171
172 /*!
172 /*!
173 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
173 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
174 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
174 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
175 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
175 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 appended.
176 appended.
177 \sa AbstractBarSeries::append()
177 \sa AbstractBarSeries::append()
178 */
178 */
179
179
180 /*!
180 /*!
181 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
181 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
182 Removes the barset from the series. Returns true if successfull, false otherwise.
182 Removes the barset from the series. Returns true if successfull, false otherwise.
183 */
183 */
184
184
185 /*!
185 /*!
186 \qmlmethod AbstractBarSeries::clear()
186 \qmlmethod AbstractBarSeries::clear()
187 Removes all barsets from the series.
187 Removes all barsets from the series.
188 */
188 */
189
189
190 /*!
190 /*!
191 This is depreciated constructor.
191 This is depreciated constructor.
192 */
192 */
193 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
193 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
194 QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent)
194 QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent)
195 {
195 {
196 }
196 }
197
197
198 /*!
198 /*!
199 Destructs abstractbarseries and owned barsets.
199 Destructs abstractbarseries and owned barsets.
200 */
200 */
201 QAbstractBarSeries::~QAbstractBarSeries()
201 QAbstractBarSeries::~QAbstractBarSeries()
202 {
202 {
203
203
204 }
204 }
205
205
206 /*!
206 /*!
207 \internal
207 \internal
208 */
208 */
209 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
209 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
210 QAbstractSeries(d,parent)
210 QAbstractSeries(d,parent)
211 {
211 {
212 }
212 }
213
213
214 /*!
214 /*!
215 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
215 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
216 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
216 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
217 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
217 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
218 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
218 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
219 */
219 */
220 void QAbstractBarSeries::setBarWidth(qreal width)
220 void QAbstractBarSeries::setBarWidth(qreal width)
221 {
221 {
222 Q_D(QAbstractBarSeries);
222 Q_D(QAbstractBarSeries);
223 d->setBarWidth(width);
223 d->setBarWidth(width);
224 }
224 }
225
225
226 /*!
226 /*!
227 Returns the width of the bars of the series.
227 Returns the width of the bars of the series.
228 \sa setBarWidth()
228 \sa setBarWidth()
229 */
229 */
230 qreal QAbstractBarSeries::barWidth() const
230 qreal QAbstractBarSeries::barWidth() const
231 {
231 {
232 Q_D(const QAbstractBarSeries);
232 Q_D(const QAbstractBarSeries);
233 return d->barWidth();
233 return d->barWidth();
234 }
234 }
235
235
236 /*!
236 /*!
237 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
237 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
238 Returns true, if appending succeeded.
238 Returns true, if appending succeeded.
239 */
239 */
240 bool QAbstractBarSeries::append(QBarSet *set)
240 bool QAbstractBarSeries::append(QBarSet *set)
241 {
241 {
242 Q_D(QAbstractBarSeries);
242 Q_D(QAbstractBarSeries);
243 bool success = d->append(set);
243 bool success = d->append(set);
244 if (success) {
244 if (success) {
245 QList<QBarSet*> sets;
245 QList<QBarSet*> sets;
246 sets.append(set);
246 sets.append(set);
247 set->setParent(this);
247 set->setParent(this);
248 emit barsetsAdded(sets);
248 emit barsetsAdded(sets);
249 emit countChanged();
249 emit countChanged();
250 }
250 }
251 return success;
251 return success;
252 }
252 }
253
253
254 /*!
254 /*!
255 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
255 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
256 was successful.
256 was successful.
257 Returns true, if set was removed.
257 Returns true, if set was removed.
258 */
258 */
259 bool QAbstractBarSeries::remove(QBarSet *set)
259 bool QAbstractBarSeries::remove(QBarSet *set)
260 {
260 {
261 Q_D(QAbstractBarSeries);
261 Q_D(QAbstractBarSeries);
262 bool success = d->remove(set);
262 bool success = d->remove(set);
263 if (success) {
263 if (success) {
264 QList<QBarSet*> sets;
264 QList<QBarSet*> sets;
265 sets.append(set);
265 sets.append(set);
266 set->setParent(0);
266 set->setParent(0);
267 emit barsetsRemoved(sets);
267 emit barsetsRemoved(sets);
268 emit countChanged();
268 emit countChanged();
269 delete set;
269 delete set;
270 set = 0;
270 set = 0;
271 }
271 }
272 return success;
272 return success;
273 }
273 }
274
274
275 /*!
275 /*!
276 Takes a single \a set from the series. Does not delete the barset object.
276 Takes a single \a set from the series. Does not delete the barset object.
277
277
278 NOTE: The series remains as the barset's parent object. You must set the
278 NOTE: The series remains as the barset's parent object. You must set the
279 parent object to take full ownership.
279 parent object to take full ownership.
280
280
281 Returns true if take was successfull.
281 Returns true if take was successfull.
282 */
282 */
283 bool QAbstractBarSeries::take(QBarSet *set)
283 bool QAbstractBarSeries::take(QBarSet *set)
284 {
284 {
285 Q_D(QAbstractBarSeries);
285 Q_D(QAbstractBarSeries);
286 bool success = d->remove(set);
286 bool success = d->remove(set);
287 if (success) {
287 if (success) {
288 QList<QBarSet*> sets;
288 QList<QBarSet*> sets;
289 sets.append(set);
289 sets.append(set);
290 emit barsetsRemoved(sets);
290 emit barsetsRemoved(sets);
291 emit countChanged();
291 emit countChanged();
292 }
292 }
293 return success;
293 return success;
294 }
294 }
295
295
296 /*!
296 /*!
297 Adds a list of barsets to series. Takes ownership of \a sets.
297 Adds a list of barsets to series. Takes ownership of \a sets.
298 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
298 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
299 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
299 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
300 and function returns false.
300 and function returns false.
301 */
301 */
302 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
302 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
303 {
303 {
304 Q_D(QAbstractBarSeries);
304 Q_D(QAbstractBarSeries);
305 bool success = d->append(sets);
305 bool success = d->append(sets);
306 if (success) {
306 if (success) {
307 emit barsetsAdded(sets);
307 emit barsetsAdded(sets);
308 emit countChanged();
308 emit countChanged();
309 }
309 }
310 return success;
310 return success;
311 }
311 }
312
312
313 /*!
313 /*!
314 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
314 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
315 Returns true, if inserting succeeded.
315 Returns true, if inserting succeeded.
316
316
317 */
317 */
318 bool QAbstractBarSeries::insert(int index, QBarSet *set)
318 bool QAbstractBarSeries::insert(int index, QBarSet *set)
319 {
319 {
320 Q_D(QAbstractBarSeries);
320 Q_D(QAbstractBarSeries);
321 bool success = d->insert(index, set);
321 bool success = d->insert(index, set);
322 if (success) {
322 if (success) {
323 QList<QBarSet*> sets;
323 QList<QBarSet*> sets;
324 sets.append(set);
324 sets.append(set);
325 emit barsetsAdded(sets);
325 emit barsetsAdded(sets);
326 emit countChanged();
326 emit countChanged();
327 }
327 }
328 return success;
328 return success;
329 }
329 }
330
330
331 /*!
331 /*!
332 Removes all barsets from the series. Deletes removed sets.
332 Removes all barsets from the series. Deletes removed sets.
333 */
333 */
334 void QAbstractBarSeries::clear()
334 void QAbstractBarSeries::clear()
335 {
335 {
336 Q_D(QAbstractBarSeries);
336 Q_D(QAbstractBarSeries);
337 QList<QBarSet *> sets = barSets();
337 QList<QBarSet *> sets = barSets();
338 bool success = d->remove(sets);
338 bool success = d->remove(sets);
339 if (success) {
339 if (success) {
340 emit barsetsRemoved(sets);
340 emit barsetsRemoved(sets);
341 emit countChanged();
341 emit countChanged();
342 foreach (QBarSet* set, sets) {
342 foreach (QBarSet* set, sets) {
343 delete set;
343 delete set;
344 }
344 }
345 }
345 }
346 }
346 }
347
347
348 /*!
348 /*!
349 Returns number of sets in series.
349 Returns number of sets in series.
350 */
350 */
351 int QAbstractBarSeries::count() const
351 int QAbstractBarSeries::count() const
352 {
352 {
353 Q_D(const QAbstractBarSeries);
353 Q_D(const QAbstractBarSeries);
354 return d->m_barSets.count();
354 return d->m_barSets.count();
355 }
355 }
356
356
357 /*!
357 /*!
358 Returns a list of sets in series. Keeps ownership of sets.
358 Returns a list of sets in series. Keeps ownership of sets.
359 */
359 */
360 QList<QBarSet*> QAbstractBarSeries::barSets() const
360 QList<QBarSet*> QAbstractBarSeries::barSets() const
361 {
361 {
362 Q_D(const QAbstractBarSeries);
362 Q_D(const QAbstractBarSeries);
363 return d->m_barSets;
363 return d->m_barSets;
364 }
364 }
365
365
366 /*!
366 /*!
367 Sets the visibility of labels in series to \a visible
367 Sets the visibility of labels in series to \a visible
368 */
368 */
369 void QAbstractBarSeries::setLabelsVisible(bool visible)
369 void QAbstractBarSeries::setLabelsVisible(bool visible)
370 {
370 {
371 Q_D(QAbstractBarSeries);
371 Q_D(QAbstractBarSeries);
372 if (d->m_labelsVisible != visible) {
372 if (d->m_labelsVisible != visible) {
373 d->setLabelsVisible(visible);
373 d->setLabelsVisible(visible);
374 emit labelsVisibleChanged();
374 emit labelsVisibleChanged();
375 }
375 }
376 }
376 }
377
377
378 /*!
378 /*!
379 Returns the visibility of labels
379 Returns the visibility of labels
380 */
380 */
381 bool QAbstractBarSeries::isLabelsVisible() const
381 bool QAbstractBarSeries::isLabelsVisible() const
382 {
382 {
383 Q_D(const QAbstractBarSeries);
383 Q_D(const QAbstractBarSeries);
384 return d->m_labelsVisible;
384 return d->m_labelsVisible;
385 }
385 }
386
386
387 void QAbstractBarSeries::setGrouping(bool grouping)
387 void QAbstractBarSeries::setGrouping(bool grouping)
388 {
388 {
389 Q_D(QAbstractBarSeries);
389 Q_D(QAbstractBarSeries);
390 d->setGrouping(grouping);
390 d->setGrouping(grouping);
391 }
391 }
392
392
393
393
394
394
395 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
395 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
396
396
397 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
397 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
398 QAbstractSeriesPrivate(q),
398 QAbstractSeriesPrivate(q),
399 m_barWidth(0.5), // Default value is 50% of category width
399 m_barWidth(0.5), // Default value is 50% of category width
400 m_labelsVisible(false),
400 m_labelsVisible(false),
401 m_visible(true),
401 m_visible(true),
402 m_grouping(true)
402 m_grouping(true)
403 {
403 {
404 }
404 }
405
405
406 int QAbstractBarSeriesPrivate::categoryCount() const
406 int QAbstractBarSeriesPrivate::categoryCount() const
407 {
407 {
408 // No categories defined. return count of longest set.
408 // No categories defined. return count of longest set.
409 int count = 0;
409 int count = 0;
410 for (int i=0; i<m_barSets.count(); i++) {
410 for (int i=0; i<m_barSets.count(); i++) {
411 if (m_barSets.at(i)->count() > count) {
411 if (m_barSets.at(i)->count() > count) {
412 count = m_barSets.at(i)->count();
412 count = m_barSets.at(i)->count();
413 }
413 }
414 }
414 }
415
415
416 return count;
416 return count;
417 }
417 }
418
418
419 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
419 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
420 {
420 {
421 if (width < 0.0) {
421 if (width < 0.0) {
422 width = 0.0;
422 width = 0.0;
423 }
423 }
424 m_barWidth = width;
424 m_barWidth = width;
425 emit updatedBars();
425 emit updatedBars();
426 }
426 }
427
427
428 qreal QAbstractBarSeriesPrivate::barWidth() const
428 qreal QAbstractBarSeriesPrivate::barWidth() const
429 {
429 {
430 return m_barWidth;
430 return m_barWidth;
431 }
431 }
432
432
433 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
433 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
434 {
434 {
435 return m_barSets.at(index);
435 return m_barSets.at(index);
436 }
436 }
437
437
438 void QAbstractBarSeriesPrivate::setVisible(bool visible)
438 void QAbstractBarSeriesPrivate::setVisible(bool visible)
439 {
439 {
440 m_visible = visible;
440 m_visible = visible;
441 emit updatedBars();
441 emit updatedBars();
442 }
442 }
443
443
444 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
444 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
445 {
445 {
446 m_labelsVisible = visible;
446 m_labelsVisible = visible;
447 emit labelsVisibleChanged(visible);
447 emit labelsVisibleChanged(visible);
448 }
448 }
449
449
450 void QAbstractBarSeriesPrivate::setGrouping(bool grouping)
450 void QAbstractBarSeriesPrivate::setGrouping(bool grouping)
451 {
451 {
452 if (m_grouping != grouping) {
452 if (m_grouping != grouping) {
453 m_grouping = grouping;
453 m_grouping = grouping;
454 emit updatedBars();
454 emit updatedBars();
455 }
455 }
456 }
456 }
457
457
458 qreal QAbstractBarSeriesPrivate::min()
458 qreal QAbstractBarSeriesPrivate::min()
459 {
459 {
460 if (m_barSets.count() <= 0) {
460 if (m_barSets.count() <= 0) {
461 return 0;
461 return 0;
462 }
462 }
463 qreal min = INT_MAX;
463 qreal min = INT_MAX;
464
464
465 for (int i = 0; i < m_barSets.count(); i++) {
465 for (int i = 0; i < m_barSets.count(); i++) {
466 int categoryCount = m_barSets.at(i)->count();
466 int categoryCount = m_barSets.at(i)->count();
467 for (int j = 0; j < categoryCount; j++) {
467 for (int j = 0; j < categoryCount; j++) {
468 qreal temp = m_barSets.at(i)->at(j);
468 qreal temp = m_barSets.at(i)->at(j);
469 if (temp < min)
469 if (temp < min)
470 min = temp;
470 min = temp;
471 }
471 }
472 }
472 }
473 return min;
473 return min;
474 }
474 }
475
475
476 qreal QAbstractBarSeriesPrivate::max()
476 qreal QAbstractBarSeriesPrivate::max()
477 {
477 {
478 if (m_barSets.count() <= 0) {
478 if (m_barSets.count() <= 0) {
479 return 0;
479 return 0;
480 }
480 }
481 qreal max = INT_MIN;
481 qreal max = INT_MIN;
482
482
483 for (int i = 0; i < m_barSets.count(); i++) {
483 for (int i = 0; i < m_barSets.count(); i++) {
484 int categoryCount = m_barSets.at(i)->count();
484 int categoryCount = m_barSets.at(i)->count();
485 for (int j = 0; j < categoryCount; j++) {
485 for (int j = 0; j < categoryCount; j++) {
486 qreal temp = m_barSets.at(i)->at(j);
486 qreal temp = m_barSets.at(i)->at(j);
487 if (temp > max)
487 if (temp > max)
488 max = temp;
488 max = temp;
489 }
489 }
490 }
490 }
491
491
492 return max;
492 return max;
493 }
493 }
494
494
495 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
495 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
496 {
496 {
497 if ((set < 0) || (set >= m_barSets.count())) {
497 if ((set < 0) || (set >= m_barSets.count())) {
498 // No set, no value.
498 // No set, no value.
499 return 0;
499 return 0;
500 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
500 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
501 // No category, no value.
501 // No category, no value.
502 return 0;
502 return 0;
503 }
503 }
504
504
505 return m_barSets.at(set)->at(category);
505 return m_barSets.at(set)->at(category);
506 }
506 }
507
507
508 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
508 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
509 {
509 {
510 if ((set < 0) || (set >= m_barSets.count())) {
510 if ((set < 0) || (set >= m_barSets.count())) {
511 // No set, no value.
511 // No set, no value.
512 return 0;
512 return 0;
513 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
513 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
514 // No category, no value.
514 // No category, no value.
515 return 0;
515 return 0;
516 }
516 }
517
517
518 qreal value = m_barSets.at(set)->at(category);
518 qreal value = m_barSets.at(set)->at(category);
519 qreal sum = categorySum(category);
519 qreal sum = categorySum(category);
520 if ( qFuzzyIsNull(sum) ) {
520 if ( qFuzzyIsNull(sum) ) {
521 return 0;
521 return 0;
522 }
522 }
523
523
524 return value / sum;
524 return value / sum;
525 }
525 }
526
526
527 qreal QAbstractBarSeriesPrivate::categorySum(int category)
527 qreal QAbstractBarSeriesPrivate::categorySum(int category)
528 {
528 {
529 qreal sum(0);
529 qreal sum(0);
530 int count = m_barSets.count(); // Count sets
530 int count = m_barSets.count(); // Count sets
531 for (int set = 0; set < count; set++) {
531 for (int set = 0; set < count; set++) {
532 if (category < m_barSets.at(set)->count())
532 if (category < m_barSets.at(set)->count())
533 sum += m_barSets.at(set)->at(category);
533 sum += m_barSets.at(set)->at(category);
534 }
534 }
535 return sum;
535 return sum;
536 }
536 }
537
537
538 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
538 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
539 {
539 {
540 qreal sum(0);
540 qreal sum(0);
541 int count = m_barSets.count(); // Count sets
541 int count = m_barSets.count(); // Count sets
542 for (int set = 0; set < count; set++) {
542 for (int set = 0; set < count; set++) {
543 if (category < m_barSets.at(set)->count())
543 if (category < m_barSets.at(set)->count())
544 sum += qAbs(m_barSets.at(set)->at(category));
544 sum += qAbs(m_barSets.at(set)->at(category));
545 }
545 }
546 return sum;
546 return sum;
547 }
547 }
548
548
549 qreal QAbstractBarSeriesPrivate::maxCategorySum()
549 qreal QAbstractBarSeriesPrivate::maxCategorySum()
550 {
550 {
551 qreal max = INT_MIN;
551 qreal max = INT_MIN;
552 int count = categoryCount();
552 int count = categoryCount();
553 for (int i = 0; i < count; i++) {
553 for (int i = 0; i < count; i++) {
554 qreal sum = categorySum(i);
554 qreal sum = categorySum(i);
555 if (sum > max)
555 if (sum > max)
556 max = sum;
556 max = sum;
557 }
557 }
558 return max;
558 return max;
559 }
559 }
560
560
561 qreal QAbstractBarSeriesPrivate::minX()
561 qreal QAbstractBarSeriesPrivate::minX()
562 {
562 {
563 if (m_barSets.count() <= 0) {
563 if (m_barSets.count() <= 0) {
564 return 0;
564 return 0;
565 }
565 }
566 qreal min = INT_MAX;
566 qreal min = INT_MAX;
567
567
568 for (int i = 0; i < m_barSets.count(); i++) {
568 for (int i = 0; i < m_barSets.count(); i++) {
569 int categoryCount = m_barSets.at(i)->count();
569 int categoryCount = m_barSets.at(i)->count();
570 for (int j = 0; j < categoryCount; j++) {
570 for (int j = 0; j < categoryCount; j++) {
571 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
571 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
572 if (temp < min)
572 if (temp < min)
573 min = temp;
573 min = temp;
574 }
574 }
575 }
575 }
576 return min;
576 return min;
577 }
577 }
578
578
579 qreal QAbstractBarSeriesPrivate::maxX()
579 qreal QAbstractBarSeriesPrivate::maxX()
580 {
580 {
581 if (m_barSets.count() <= 0) {
581 if (m_barSets.count() <= 0) {
582 return 0;
582 return 0;
583 }
583 }
584 qreal max = INT_MIN;
584 qreal max = INT_MIN;
585
585
586 for (int i = 0; i < m_barSets.count(); i++) {
586 for (int i = 0; i < m_barSets.count(); i++) {
587 int categoryCount = m_barSets.at(i)->count();
587 int categoryCount = m_barSets.at(i)->count();
588 for (int j = 0; j < categoryCount; j++) {
588 for (int j = 0; j < categoryCount; j++) {
589 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
589 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
590 if (temp > max)
590 if (temp > max)
591 max = temp;
591 max = temp;
592 }
592 }
593 }
593 }
594
594
595 return max;
595 return max;
596 }
596 }
597
597
598
598
599 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
599 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
600 {
600 {
601 qreal minX(domain.minX());
601 qreal minX(domain.minX());
602 qreal minY(domain.minY());
602 qreal minY(domain.minY());
603 qreal maxX(domain.maxX());
603 qreal maxX(domain.maxX());
604 qreal maxY(domain.maxY());
604 qreal maxY(domain.maxY());
605
605
606 qreal seriesMinX = this->minX();
606 qreal seriesMinX = this->minX();
607 qreal seriesMaxX = this->maxX();
607 qreal seriesMaxX = this->maxX();
608 qreal y = max();
608 qreal y = max();
609 minX = qMin(minX, seriesMinX - (qreal)0.5);
609 minX = qMin(minX, seriesMinX - (qreal)0.5);
610 minY = qMin(minY, y);
610 minY = qMin(minY, y);
611 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
611 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
612 maxY = qMax(maxY, y);
612 maxY = qMax(maxY, y);
613
613
614 domain.setRange(minX,maxX,minY,maxY);
614 domain.setRange(minX,maxX,minY,maxY);
615 }
615 }
616
616
617 ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
617 ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
618 {
618 {
619 Q_UNUSED(presenter);
619 Q_UNUSED(presenter);
620 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
620 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
621 return 0;
621 return 0;
622 }
622 }
623
623
624 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
624 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
625 {
625 {
626 Q_Q(QAbstractBarSeries);
626 Q_Q(QAbstractBarSeries);
627 QList<LegendMarker*> markers;
627 QList<LegendMarker*> markers;
628 foreach(QBarSet* set, q->barSets()) {
628 foreach(QBarSet* set, q->barSets()) {
629 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
629 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
630 markers << marker;
630 markers << marker;
631 }
631 }
632
632
633 return markers;
633 return markers;
634 }
634 }
635
635
636 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
636 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
637 {
637 {
638 Q_Q(QAbstractBarSeries);
638 Q_Q(QAbstractBarSeries);
639 if ((m_barSets.contains(set)) || (set == 0)) {
639 if ((m_barSets.contains(set)) || (set == 0)) {
640 // Fail if set is already in list or set is null.
640 // Fail if set is already in list or set is null.
641 return false;
641 return false;
642 }
642 }
643 m_barSets.append(set);
643 m_barSets.append(set);
644 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
644 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
645 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
645 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
646 emit restructuredBars(); // this notifies barchartitem
646 emit restructuredBars(); // this notifies barchartitem
647 if (m_dataset) {
647 if (m_dataset) {
648 m_dataset->updateSeries(q); // this notifies legend
648 m_dataset->updateSeries(q); // this notifies legend
649 }
649 }
650 return true;
650 return true;
651 }
651 }
652
652
653 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
653 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
654 {
654 {
655 Q_Q(QAbstractBarSeries);
655 Q_Q(QAbstractBarSeries);
656 if (!m_barSets.contains(set)) {
656 if (!m_barSets.contains(set)) {
657 // Fail if set is not in list
657 // Fail if set is not in list
658 return false;
658 return false;
659 }
659 }
660 m_barSets.removeOne(set);
660 m_barSets.removeOne(set);
661 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
661 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
662 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
662 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
663 emit restructuredBars(); // this notifies barchartitem
663 emit restructuredBars(); // this notifies barchartitem
664 if (m_dataset) {
664 if (m_dataset) {
665 m_dataset->updateSeries(q); // this notifies legend
665 m_dataset->updateSeries(q); // this notifies legend
666 }
666 }
667 return true;
667 return true;
668 }
668 }
669
669
670 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
670 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
671 {
671 {
672 Q_Q(QAbstractBarSeries);
672 Q_Q(QAbstractBarSeries);
673 foreach (QBarSet* set, sets) {
673 foreach (QBarSet* set, sets) {
674 if ((set == 0) || (m_barSets.contains(set))) {
674 if ((set == 0) || (m_barSets.contains(set))) {
675 // Fail if any of the sets is null or is already appended.
675 // Fail if any of the sets is null or is already appended.
676 return false;
676 return false;
677 }
677 }
678 if (sets.count(set) != 1) {
678 if (sets.count(set) != 1) {
679 // Also fail if same set is more than once in given list.
679 // Also fail if same set is more than once in given list.
680 return false;
680 return false;
681 }
681 }
682 }
682 }
683
683
684 foreach (QBarSet* set, sets) {
684 foreach (QBarSet* set, sets) {
685 m_barSets.append(set);
685 m_barSets.append(set);
686 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
686 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
687 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
687 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
688 }
688 }
689 emit restructuredBars(); // this notifies barchartitem
689 emit restructuredBars(); // this notifies barchartitem
690 if (m_dataset) {
690 if (m_dataset) {
691 m_dataset->updateSeries(q); // this notifies legend
691 m_dataset->updateSeries(q); // this notifies legend
692 }
692 }
693 return true;
693 return true;
694 }
694 }
695
695
696 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
696 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
697 {
697 {
698 Q_Q(QAbstractBarSeries);
698 Q_Q(QAbstractBarSeries);
699 if (sets.count() == 0) {
699 if (sets.count() == 0) {
700 return false;
700 return false;
701 }
701 }
702 foreach (QBarSet* set, sets) {
702 foreach (QBarSet* set, sets) {
703 if ((set == 0) || (!m_barSets.contains(set))) {
703 if ((set == 0) || (!m_barSets.contains(set))) {
704 // Fail if any of the sets is null or is not in series
704 // Fail if any of the sets is null or is not in series
705 return false;
705 return false;
706 }
706 }
707 if (sets.count(set) != 1) {
707 if (sets.count(set) != 1) {
708 // Also fail if same set is more than once in given list.
708 // Also fail if same set is more than once in given list.
709 return false;
709 return false;
710 }
710 }
711 }
711 }
712
712
713 foreach (QBarSet* set, sets) {
713 foreach (QBarSet* set, sets) {
714 m_barSets.removeOne(set);
714 m_barSets.removeOne(set);
715 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
715 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
716 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
716 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
717 }
717 }
718
718
719 emit restructuredBars(); // this notifies barchartitem
719 emit restructuredBars(); // this notifies barchartitem
720 if (m_dataset) {
720 if (m_dataset) {
721 m_dataset->updateSeries(q); // this notifies legend
721 m_dataset->updateSeries(q); // this notifies legend
722 }
722 }
723 return true;
723 return true;
724 }
724 }
725
725
726 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
726 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
727 {
727 {
728 Q_Q(QAbstractBarSeries);
728 Q_Q(QAbstractBarSeries);
729 if ((m_barSets.contains(set)) || (set == 0)) {
729 if ((m_barSets.contains(set)) || (set == 0)) {
730 // Fail if set is already in list or set is null.
730 // Fail if set is already in list or set is null.
731 return false;
731 return false;
732 }
732 }
733 m_barSets.insert(index, set);
733 m_barSets.insert(index, set);
734 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
734 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
735 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
735 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
736 emit restructuredBars(); // this notifies barchartitem
736 emit restructuredBars(); // this notifies barchartitem
737 if (m_dataset) {
737 if (m_dataset) {
738 m_dataset->updateSeries(q); // this notifies legend
738 m_dataset->updateSeries(q); // this notifies legend
739 }
739 }
740 return true;
740 return true;
741 }
741 }
742
742
743 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
743 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
744 {
744 {
745 Q_Q(QAbstractBarSeries);
745 Q_Q(QAbstractBarSeries);
746
746
747 if(axis->type()==QAbstractAxis::AxisTypeCategories) {
747 if(axis->type()==QAbstractAxis::AxisTypeCategories) {
748
748
749 switch(q->type()) {
749 switch(q->type()) {
750
750
751 case QAbstractSeries::SeriesTypeHorizontalBar:
751 case QAbstractSeries::SeriesTypeHorizontalBar:
752 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
752 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
753 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
753 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
754
754
755 if(axis->orientation()==Qt::Vertical)
755 if(axis->orientation()==Qt::Vertical)
756 {
756 {
757 populateCategories(qobject_cast<QBarCategoryAxis*>(axis));
757 populateCategories(qobject_cast<QBarCategoryAxis*>(axis));
758 }
758 }
759 break;
759 break;
760 }
760 }
761 case QAbstractSeries::SeriesTypeBar:
761 case QAbstractSeries::SeriesTypeBar:
762 case QAbstractSeries::SeriesTypePercentBar:
762 case QAbstractSeries::SeriesTypePercentBar:
763 case QAbstractSeries::SeriesTypeStackedBar: {
763 case QAbstractSeries::SeriesTypeStackedBar: {
764
764
765 if(axis->orientation()==Qt::Horizontal)
765 if(axis->orientation()==Qt::Horizontal)
766 {
766 {
767 populateCategories(qobject_cast<QBarCategoryAxis*>(axis));
767 populateCategories(qobject_cast<QBarCategoryAxis*>(axis));
768 }
768 }
769 break;
769 break;
770 }
770 }
771 default:
771 default:
772 qWarning()<<"Unexpected series type";
772 qWarning()<<"Unexpected series type";
773 break;
773 break;
774
774
775 }
775 }
776 }
776 }
777 }
777 }
778
778
779 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
779 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
780 {
780 {
781 Q_Q(const QAbstractBarSeries);
781 Q_Q(const QAbstractBarSeries);
782
782
783 switch(q->type()) {
783 switch(q->type()) {
784
784
785 case QAbstractSeries::SeriesTypeHorizontalBar:
785 case QAbstractSeries::SeriesTypeHorizontalBar:
786 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
786 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
787 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
787 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
788
788
789 if(orientation==Qt::Vertical)
789 if(orientation==Qt::Vertical)
790 {
790 {
791 return QAbstractAxis::AxisTypeCategories;
791 return QAbstractAxis::AxisTypeCategories;
792 }
792 }
793 break;
793 break;
794 }
794 }
795 case QAbstractSeries::SeriesTypeBar:
795 case QAbstractSeries::SeriesTypeBar:
796 case QAbstractSeries::SeriesTypePercentBar:
796 case QAbstractSeries::SeriesTypePercentBar:
797 case QAbstractSeries::SeriesTypeStackedBar: {
797 case QAbstractSeries::SeriesTypeStackedBar: {
798
798
799 if(orientation==Qt::Horizontal)
799 if(orientation==Qt::Horizontal)
800 {
800 {
801 return QAbstractAxis::AxisTypeCategories;
801 return QAbstractAxis::AxisTypeCategories;
802 }
802 }
803 break;
803 break;
804 }
804 }
805 default:
805 default:
806 qWarning()<<"Unexpected series type";
806 qWarning()<<"Unexpected series type";
807 break;
807 break;
808
808
809 }
809 }
810 return QAbstractAxis::AxisTypeValues;
810 return QAbstractAxis::AxisTypeValues;
811
811
812 }
812 }
813
813
814 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis)
814 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis)
815 {
815 {
816 QStringList categories;
816 QStringList categories;
817 if(axis->categories().isEmpty()) {
817 if(axis->categories().isEmpty()) {
818 for (int i(1); i < categoryCount()+1; i++)
818 for (int i(1); i < categoryCount()+1; i++)
819 categories << QString::number(i);
819 categories << QString::number(i);
820 axis->append(categories);
820 axis->append(categories);
821 }
821 }
822 }
822 }
823
823
824 #include "moc_qabstractbarseries.cpp"
824 #include "moc_qabstractbarseries.cpp"
825 #include "moc_qabstractbarseries_p.cpp"
825 #include "moc_qabstractbarseries_p.cpp"
826
826
827
827
828 QTCOMMERCIALCHART_END_NAMESPACE
828 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,121 +1,121
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_p.h"
23 #include "barchartitem_p.h"
23 #include "barchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "baranimation_p.h"
26 #include "baranimation_p.h"
27 #include "qvalueaxis.h"
27 #include "qvalueaxis.h"
28 #include "qbarcategoriesaxis.h"
28 #include "qbarcategoryaxis.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QBarSeries
33 \class QBarSeries
34 \brief Series for creating bar chart
34 \brief Series for creating bar chart
35 \mainclass
35 \mainclass
36
36
37 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as groups, where bars in same category are grouped next to each other. QBarSeries groups the data
38 as groups, where bars in same category are grouped next to each other. QBarSeries groups the data
39 from sets to categories, which are defined by a QStringList.
39 from sets to categories, which are defined by a QStringList.
40
40
41 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
41 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
42 \image examples_barchart.png
42 \image examples_barchart.png
43
43
44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
45 */
45 */
46 /*!
46 /*!
47 \qmlclass BarSeries QBarSeries
47 \qmlclass BarSeries QBarSeries
48 \inherits AbstractBarSeries
48 \inherits AbstractBarSeries
49
49
50 The following QML shows how to create a simple grouped bar chart:
50 The following QML shows how to create a simple grouped bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
52 \beginfloatleft
52 \beginfloatleft
53 \image demos_qmlchart6.png
53 \image demos_qmlchart6.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 Constructs empty QBarSeries.
59 Constructs empty QBarSeries.
60 QBarSeries is QObject which is a child of a \a parent.
60 QBarSeries is QObject which is a child of a \a parent.
61 */
61 */
62 QBarSeries::QBarSeries(QObject *parent)
62 QBarSeries::QBarSeries(QObject *parent)
63 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
63 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns QChartSeries::SeriesTypeBar.
68 Returns QChartSeries::SeriesTypeBar.
69 */
69 */
70 QAbstractSeries::SeriesType QBarSeries::type() const
70 QAbstractSeries::SeriesType QBarSeries::type() const
71 {
71 {
72 return QAbstractSeries::SeriesTypeBar;
72 return QAbstractSeries::SeriesTypeBar;
73 }
73 }
74
74
75 QBarSeries::~QBarSeries()
75 QBarSeries::~QBarSeries()
76 {
76 {
77 Q_D(QBarSeries);
77 Q_D(QBarSeries);
78 if(d->m_dataset) {
78 if(d->m_dataset) {
79 d->m_dataset->removeSeries(this);
79 d->m_dataset->removeSeries(this);
80 }
80 }
81 }
81 }
82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83
83
84 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
84 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
85 {
85 {
86
86
87 }
87 }
88
88
89 void QBarSeriesPrivate::scaleDomain(Domain& domain)
89 void QBarSeriesPrivate::scaleDomain(Domain& domain)
90 {
90 {
91 qreal minX(domain.minX());
91 qreal minX(domain.minX());
92 qreal minY(domain.minY());
92 qreal minY(domain.minY());
93 qreal maxX(domain.maxX());
93 qreal maxX(domain.maxX());
94 qreal maxY(domain.maxY());
94 qreal maxY(domain.maxY());
95
95
96 qreal x = categoryCount();
96 qreal x = categoryCount();
97 minX = qMin(minX, - (qreal)0.5);
97 minX = qMin(minX, - (qreal)0.5);
98 minY = qMin(minY, min());
98 minY = qMin(minY, min());
99 maxX = qMax(maxX, x - (qreal)0.5);
99 maxX = qMax(maxX, x - (qreal)0.5);
100 maxY = qMax(maxY, max());
100 maxY = qMax(maxY, max());
101
101
102 domain.setRange(minX,maxX,minY,maxY);
102 domain.setRange(minX,maxX,minY,maxY);
103 }
103 }
104
104
105
105
106 ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
106 ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
107 {
107 {
108 Q_Q(QBarSeries);
108 Q_Q(QBarSeries);
109
109
110 BarChartItem* bar = new BarChartItem(q,presenter);
110 BarChartItem* bar = new BarChartItem(q,presenter);
111 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
111 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
112 bar->setAnimation(new BarAnimation(bar));
112 bar->setAnimation(new BarAnimation(bar));
113 }
113 }
114 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
114 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
115 return bar;
115 return bar;
116 }
116 }
117
117
118 #include "moc_qbarseries.cpp"
118 #include "moc_qbarseries.cpp"
119
119
120 QTCOMMERCIALCHART_END_NAMESPACE
120 QTCOMMERCIALCHART_END_NAMESPACE
121
121
@@ -1,484 +1,484
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qvalueaxis.h"
23 #include "qvalueaxis.h"
24 #include "qbarcategoriesaxis.h"
24 #include "qbarcategoryaxis.h"
25 #include "qvalueaxis_p.h"
25 #include "qvalueaxis_p.h"
26 #include "qintervalsaxis.h"
26 #include "qintervalsaxis.h"
27 #include "qdatetimeaxis.h"
27 #include "qdatetimeaxis.h"
28 #include "qabstractseries_p.h"
28 #include "qabstractseries_p.h"
29 #include "qabstractbarseries.h"
29 #include "qabstractbarseries.h"
30 #include "qstackedbarseries.h"
30 #include "qstackedbarseries.h"
31 #include "qpercentbarseries.h"
31 #include "qpercentbarseries.h"
32 #include "qpieseries.h"
32 #include "qpieseries.h"
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent)
36 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent)
37 {
37 {
38
38
39 }
39 }
40
40
41 ChartDataSet::~ChartDataSet()
41 ChartDataSet::~ChartDataSet()
42 {
42 {
43 removeAllSeries();
43 removeAllSeries();
44 }
44 }
45
45
46 void ChartDataSet::addSeries(QAbstractSeries* series)
46 void ChartDataSet::addSeries(QAbstractSeries* series)
47 {
47 {
48 Domain* domain = m_seriesDomainMap.value(series);
48 Domain* domain = m_seriesDomainMap.value(series);
49
49
50 if(domain) {
50 if(domain) {
51 qWarning() << "Can not add series. Series already on the chart";
51 qWarning() << "Can not add series. Series already on the chart";
52 return;
52 return;
53 }
53 }
54
54
55 domain = new Domain(series);
55 domain = new Domain(series);
56 m_seriesDomainMap.insert(series,domain);
56 m_seriesDomainMap.insert(series,domain);
57 series->d_ptr->scaleDomain(*domain);
57 series->d_ptr->scaleDomain(*domain);
58
58
59 createSeriesIndex(series);
59 createSeriesIndex(series);
60
60
61 series->setParent(this); // take ownership
61 series->setParent(this); // take ownership
62 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
62 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
63 series->d_ptr->m_dataset = this;
63 series->d_ptr->m_dataset = this;
64
64
65 emit seriesAdded(series,domain);
65 emit seriesAdded(series,domain);
66
66
67 }
67 }
68
68
69 void ChartDataSet::removeSeries(QAbstractSeries* series)
69 void ChartDataSet::removeSeries(QAbstractSeries* series)
70 {
70 {
71
71
72 if(!m_seriesDomainMap.contains(series)) {
72 if(!m_seriesDomainMap.contains(series)) {
73 qWarning()<<"Can not remove series. Series not found on the chart.";
73 qWarning()<<"Can not remove series. Series not found on the chart.";
74 return;
74 return;
75 }
75 }
76
76
77 emit seriesRemoved(series);
77 emit seriesRemoved(series);
78
78
79 Domain* domain = m_seriesDomainMap.take(series);
79 Domain* domain = m_seriesDomainMap.take(series);
80 delete domain;
80 delete domain;
81 domain = 0;
81 domain = 0;
82
82
83 removeSeriesIndex(series);
83 removeSeriesIndex(series);
84
84
85 series->setParent(0);
85 series->setParent(0);
86 series->d_ptr->m_chart = 0;
86 series->d_ptr->m_chart = 0;
87 series->d_ptr->m_dataset = 0;
87 series->d_ptr->m_dataset = 0;
88
88
89 removeAxes(series);
89 removeAxes(series);
90 }
90 }
91
91
92
92
93
93
94 void ChartDataSet::createSeriesIndex(QAbstractSeries* series)
94 void ChartDataSet::createSeriesIndex(QAbstractSeries* series)
95 {
95 {
96 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
96 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
97
97
98 int key=0;
98 int key=0;
99 while (i.hasNext()) {
99 while (i.hasNext()) {
100 i.next();
100 i.next();
101 if(i.key()!=key) {
101 if(i.key()!=key) {
102 break;
102 break;
103 }
103 }
104 key++;
104 key++;
105 }
105 }
106
106
107 m_indexSeriesMap.insert(key,series);
107 m_indexSeriesMap.insert(key,series);
108 }
108 }
109
109
110 void ChartDataSet::removeSeriesIndex(QAbstractSeries* series)
110 void ChartDataSet::removeSeriesIndex(QAbstractSeries* series)
111 {
111 {
112 int key = seriesIndex(series);
112 int key = seriesIndex(series);
113 Q_ASSERT(key!=-1);
113 Q_ASSERT(key!=-1);
114 m_indexSeriesMap.remove(key);
114 m_indexSeriesMap.remove(key);
115 }
115 }
116
116
117 void ChartDataSet::createDefaultAxes()
117 void ChartDataSet::createDefaultAxes()
118 {
118 {
119
119
120 if(m_seriesDomainMap.isEmpty()) return;
120 if(m_seriesDomainMap.isEmpty()) return;
121
121
122 QAbstractAxis::AxisTypes typeX(0);
122 QAbstractAxis::AxisTypes typeX(0);
123 QAbstractAxis::AxisTypes typeY(0);
123 QAbstractAxis::AxisTypes typeY(0);
124
124
125 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
125 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
126 while (i.hasNext()) {
126 while (i.hasNext()) {
127 i.next();
127 i.next();
128 removeAxes(i.key());
128 removeAxes(i.key());
129 }
129 }
130
130
131 i.toFront();
131 i.toFront();
132
132
133 while (i.hasNext()) {
133 while (i.hasNext()) {
134 i.next();
134 i.next();
135 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
135 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
136 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
136 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
137 if(axisX) typeX&=axisX->type();
137 if(axisX) typeX&=axisX->type();
138 else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal);
138 else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal);
139 if(axisY) typeY&=axisY->type();
139 if(axisY) typeY&=axisY->type();
140 else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical);
140 else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical);
141 }
141 }
142
142
143 createAxes(typeX,Qt::Horizontal);
143 createAxes(typeX,Qt::Horizontal);
144 createAxes(typeY,Qt::Vertical);
144 createAxes(typeY,Qt::Vertical);
145 }
145 }
146
146
147 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation)
147 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation)
148 {
148 {
149 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
149 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
150
150
151 if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories))
151 if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories))
152 {
152 {
153 while (i.hasNext()) {
153 while (i.hasNext()) {
154 i.next();
154 i.next();
155 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation);
155 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation);
156 if(!axis) continue;
156 if(!axis) continue;
157 initializeAxis(axis,i.key());
157 initializeAxis(axis,i.key());
158 emit axisAdded(axis,i.value());
158 emit axisAdded(axis,i.value());
159 }
159 }
160
160
161 }
161 }
162 else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
162 else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
163 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation);
163 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation);
164 i.toFront();
164 i.toFront();
165 while (i.hasNext()) {
165 while (i.hasNext()) {
166 i.next();
166 i.next();
167 initializeAxis(axis,i.key());
167 initializeAxis(axis,i.key());
168 }
168 }
169 emit axisAdded(axis,i.value());
169 emit axisAdded(axis,i.value());
170 }
170 }
171 }
171 }
172
172
173
173
174 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation)
174 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation)
175 {
175 {
176 QAbstractAxis* axis =0;
176 QAbstractAxis* axis =0;
177
177
178 switch(type) {
178 switch(type) {
179 case QAbstractAxis::AxisTypeValues:
179 case QAbstractAxis::AxisTypeValues:
180 axis = new QValueAxis(this);
180 axis = new QValueAxis(this);
181 break;
181 break;
182 case QAbstractAxis::AxisTypeCategories:
182 case QAbstractAxis::AxisTypeCategories:
183 axis = new QBarCategoryAxis(this);
183 axis = new QBarCategoryAxis(this);
184 break;
184 break;
185 case QAbstractAxis::AxisTypeIntervals:
185 case QAbstractAxis::AxisTypeIntervals:
186 axis = new QIntervalsAxis(this);
186 axis = new QIntervalsAxis(this);
187 break;
187 break;
188 case QAbstractAxis::AxisTypeDateTime:
188 case QAbstractAxis::AxisTypeDateTime:
189 axis = new QDateTimeAxis(this);
189 axis = new QDateTimeAxis(this);
190 break;
190 break;
191 default:
191 default:
192 axis = 0;
192 axis = 0;
193 break;
193 break;
194 }
194 }
195
195
196 if(axis)
196 if(axis)
197 axis->d_ptr->setOrientation(orientation);
197 axis->d_ptr->setOrientation(orientation);
198
198
199 return axis;
199 return axis;
200 }
200 }
201
201
202 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
202 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
203 {
203 {
204 Domain* domain = m_seriesDomainMap.value(series);
204 Domain* domain = m_seriesDomainMap.value(series);
205 axis->d_ptr->m_dataset = this;
205 axis->d_ptr->m_dataset = this;
206 series->d_ptr->initializeAxis(axis);
206 series->d_ptr->initializeAxis(axis);
207 axis->d_ptr->intializeDomain(domain);
207 axis->d_ptr->intializeDomain(domain);
208 if(axis->orientation()==Qt::Horizontal) {
208 if(axis->orientation()==Qt::Horizontal) {
209 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
209 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
210 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
210 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
211 m_seriesAxisXMap.insert(series,axis);
211 m_seriesAxisXMap.insert(series,axis);
212 }
212 }
213 else {
213 else {
214 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
214 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
215 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
215 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
216 m_seriesAxisYMap.insert(series,axis);
216 m_seriesAxisYMap.insert(series,axis);
217 }
217 }
218 axis->d_ptr->emitUpdated();
218 axis->d_ptr->emitUpdated();
219 }
219 }
220
220
221 void ChartDataSet::removeAxes(QAbstractSeries* series)
221 void ChartDataSet::removeAxes(QAbstractSeries* series)
222 {
222 {
223 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
223 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
224
224
225 if(axisX) {
225 if(axisX) {
226 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
226 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
227 int x = axesX.indexOf(axisX);
227 int x = axesX.indexOf(axisX);
228
228
229 if(x==-1) {
229 if(x==-1) {
230 emit axisRemoved(axisX);
230 emit axisRemoved(axisX);
231 axisX->d_ptr->m_dataset=0;
231 axisX->d_ptr->m_dataset=0;
232 axisX->deleteLater();
232 axisX->deleteLater();
233 }
233 }
234 }
234 }
235
235
236 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
236 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
237
237
238 if(axisY) {
238 if(axisY) {
239 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
239 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
240
240
241 int y = axesY.indexOf(axisY);
241 int y = axesY.indexOf(axisY);
242
242
243 if(y==-1) {
243 if(y==-1) {
244 emit axisRemoved(axisY);
244 emit axisRemoved(axisY);
245 axisY->d_ptr->m_dataset=0;
245 axisY->d_ptr->m_dataset=0;
246 axisY->deleteLater();
246 axisY->deleteLater();
247 }
247 }
248 }
248 }
249 }
249 }
250
250
251 void ChartDataSet::removeAxis(QAbstractAxis* axis)
251 void ChartDataSet::removeAxis(QAbstractAxis* axis)
252 {
252 {
253 if(!axis->d_ptr->m_dataset) {
253 if(!axis->d_ptr->m_dataset) {
254 qWarning()<<"UnBound axis found !";
254 qWarning()<<"UnBound axis found !";
255 return;
255 return;
256 }
256 }
257
257
258 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
258 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
259
259
260 if(axis->orientation()==Qt::Vertical) {
260 if(axis->orientation()==Qt::Vertical) {
261 seriesAxisMap= &m_seriesAxisYMap;
261 seriesAxisMap= &m_seriesAxisYMap;
262 }
262 }
263 else {
263 else {
264 seriesAxisMap= &m_seriesAxisXMap;
264 seriesAxisMap= &m_seriesAxisXMap;
265 }
265 }
266
266
267 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap);
267 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap);
268
268
269 while (i.hasNext()) {
269 while (i.hasNext()) {
270 i.next();
270 i.next();
271 if(i.value()==axis) {
271 if(i.value()==axis) {
272 removeSeries(i.key());
272 removeSeries(i.key());
273 }
273 }
274 }
274 }
275 }
275 }
276
276
277 void ChartDataSet::removeAllSeries()
277 void ChartDataSet::removeAllSeries()
278 {
278 {
279 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
279 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
280 foreach(QAbstractSeries *s , series) {
280 foreach(QAbstractSeries *s , series) {
281 removeSeries(s);
281 removeSeries(s);
282 }
282 }
283
283
284 Q_ASSERT(m_seriesAxisXMap.count()==0);
284 Q_ASSERT(m_seriesAxisXMap.count()==0);
285 Q_ASSERT(m_seriesAxisXMap.count()==0);
285 Q_ASSERT(m_seriesAxisXMap.count()==0);
286 Q_ASSERT(m_seriesDomainMap.count()==0);
286 Q_ASSERT(m_seriesDomainMap.count()==0);
287
287
288 qDeleteAll(series);
288 qDeleteAll(series);
289 }
289 }
290
290
291 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
291 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
292 {
292 {
293 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
293 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
294
294
295
295
296 blockAxisSignals(true);
296 blockAxisSignals(true);
297
297
298 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
298 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
299
299
300 while (i.hasNext()) {
300 while (i.hasNext()) {
301 i.next();
301 i.next();
302 i.value()->zoomIn(rect,size);
302 i.value()->zoomIn(rect,size);
303 }
303 }
304
304
305 blockAxisSignals(false);
305 blockAxisSignals(false);
306
306
307 }
307 }
308
308
309 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
309 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
310 {
310 {
311 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
311 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
312
312
313 blockAxisSignals(true);
313 blockAxisSignals(true);
314
314
315 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
315 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
316
316
317 while (i.hasNext()) {
317 while (i.hasNext()) {
318 i.next();
318 i.next();
319 i.value()->zoomOut(rect,size);
319 i.value()->zoomOut(rect,size);
320 }
320 }
321
321
322 blockAxisSignals(false);
322 blockAxisSignals(false);
323 }
323 }
324
324
325 void ChartDataSet::blockAxisSignals(bool enabled)
325 void ChartDataSet::blockAxisSignals(bool enabled)
326 {
326 {
327 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
327 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
328 while (i.hasNext()) {
328 while (i.hasNext()) {
329 i.next();
329 i.next();
330 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
330 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
331 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
331 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
332 if(axisX) {
332 if(axisX) {
333 axisX->d_ptr->blockSignals(enabled);
333 axisX->d_ptr->blockSignals(enabled);
334 if(!enabled) {
334 if(!enabled) {
335 axisX->d_ptr->setDirty(false);
335 axisX->d_ptr->setDirty(false);
336 axisX->d_ptr->emitUpdated();
336 axisX->d_ptr->emitUpdated();
337 }
337 }
338 }
338 }
339 if(axisY) {
339 if(axisY) {
340 axisY->d_ptr->blockSignals(enabled);
340 axisY->d_ptr->blockSignals(enabled);
341 if(!enabled) {
341 if(!enabled) {
342 axisY->d_ptr->setDirty(false);
342 axisY->d_ptr->setDirty(false);
343 axisY->d_ptr->emitUpdated();
343 axisY->d_ptr->emitUpdated();
344 }
344 }
345 }
345 }
346 }
346 }
347 }
347 }
348
348
349 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
349 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
350 {
350 {
351 int count=0;
351 int count=0;
352 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
352 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
353 while (i.hasNext()) {
353 while (i.hasNext()) {
354 i.next();
354 i.next();
355 if(i.key()->type()==type) count++;
355 if(i.key()->type()==type) count++;
356 }
356 }
357 return count;
357 return count;
358 }
358 }
359
359
360 int ChartDataSet::seriesIndex(QAbstractSeries *series)
360 int ChartDataSet::seriesIndex(QAbstractSeries *series)
361 {
361 {
362 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
362 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
363 while (i.hasNext()) {
363 while (i.hasNext()) {
364 i.next();
364 i.next();
365 if (i.value() == series)
365 if (i.value() == series)
366 return i.key();
366 return i.key();
367 }
367 }
368 return -1;
368 return -1;
369 }
369 }
370
370
371 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
371 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
372 {
372 {
373 if(series == 0) {
373 if(series == 0) {
374
374
375 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap);
375 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap);
376
376
377 while (i.hasNext()) {
377 while (i.hasNext()) {
378 i.next();
378 i.next();
379 if(i.value()->isVisible()) return i.value();
379 if(i.value()->isVisible()) return i.value();
380 }
380 }
381 return 0;
381 return 0;
382 }
382 }
383 return m_seriesAxisXMap.value(series);
383 return m_seriesAxisXMap.value(series);
384 }
384 }
385
385
386 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
386 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
387 {
387 {
388 if(series == 0) {
388 if(series == 0) {
389 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap);
389 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap);
390
390
391 while (i.hasNext()) {
391 while (i.hasNext()) {
392 i.next();
392 i.next();
393 if(i.value()->isVisible()) return i.value();
393 if(i.value()->isVisible()) return i.value();
394 }
394 }
395 return 0;
395 return 0;
396 }
396 }
397 return m_seriesAxisYMap.value(series);
397 return m_seriesAxisYMap.value(series);
398 }
398 }
399
399
400 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation)
400 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation)
401 {
401 {
402 Q_ASSERT(axis);
402 Q_ASSERT(axis);
403
403
404 if(!series) {
404 if(!series) {
405 qWarning() << "Series not found on the chart.";
405 qWarning() << "Series not found on the chart.";
406 return;
406 return;
407 }
407 }
408
408
409 Domain* domain = m_seriesDomainMap.value(series);
409 Domain* domain = m_seriesDomainMap.value(series);
410
410
411 if(!domain) {
411 if(!domain) {
412 qWarning() << "Series not found on the chart.";
412 qWarning() << "Series not found on the chart.";
413 return;
413 return;
414 }
414 }
415
415
416 if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) {
416 if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) {
417 qWarning()<<"Axis already defined as axis Y";
417 qWarning()<<"Axis already defined as axis Y";
418 return;
418 return;
419 }
419 }
420
420
421 if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) {
421 if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) {
422 qWarning()<<"Axis already defined as axis X";
422 qWarning()<<"Axis already defined as axis X";
423 return;
423 return;
424 }
424 }
425
425
426 axis->d_ptr->setOrientation(orientation);
426 axis->d_ptr->setOrientation(orientation);
427
427
428 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
428 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
429
429
430 if(orientation==Qt::Vertical) {
430 if(orientation==Qt::Vertical) {
431 seriesAxisMap= &m_seriesAxisYMap;
431 seriesAxisMap= &m_seriesAxisYMap;
432 }else{
432 }else{
433 seriesAxisMap= &m_seriesAxisXMap;
433 seriesAxisMap= &m_seriesAxisXMap;
434 }
434 }
435
435
436 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
436 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
437 QList<QAbstractAxis*> axes = seriesAxisMap->values();
437 QList<QAbstractAxis*> axes = seriesAxisMap->values();
438 if(oldAxis) {
438 if(oldAxis) {
439 if(axes.indexOf(oldAxis)==-1) {
439 if(axes.indexOf(oldAxis)==-1) {
440 emit axisRemoved(oldAxis);
440 emit axisRemoved(oldAxis);
441 oldAxis->disconnect();
441 oldAxis->disconnect();
442 QObject::disconnect(domain,0,oldAxis,0);
442 QObject::disconnect(domain,0,oldAxis,0);
443 oldAxis->d_ptr->m_dataset=0;
443 oldAxis->d_ptr->m_dataset=0;
444 oldAxis->deleteLater();
444 oldAxis->deleteLater();
445 }
445 }
446 }
446 }
447
447
448 if(axes.indexOf(axis)==-1) {
448 if(axes.indexOf(axis)==-1) {
449 initializeAxis(axis,series);
449 initializeAxis(axis,series);
450 emit axisAdded(axis,domain);
450 emit axisAdded(axis,domain);
451 }else{
451 }else{
452 initializeAxis(axis,series);
452 initializeAxis(axis,series);
453 }
453 }
454 }
454 }
455
455
456 Domain* ChartDataSet::domain(QAbstractSeries *series) const
456 Domain* ChartDataSet::domain(QAbstractSeries *series) const
457 {
457 {
458 return m_seriesDomainMap.value(series);
458 return m_seriesDomainMap.value(series);
459 }
459 }
460
460
461 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
461 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
462 {
462 {
463 blockAxisSignals(true);
463 blockAxisSignals(true);
464 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
464 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
465 while (i.hasNext()) {
465 while (i.hasNext()) {
466 i.next();
466 i.next();
467 i.value()->move(dx,dy,size);
467 i.value()->move(dx,dy,size);
468 }
468 }
469 blockAxisSignals(false);
469 blockAxisSignals(false);
470 }
470 }
471
471
472 QList<QAbstractSeries*> ChartDataSet::series() const
472 QList<QAbstractSeries*> ChartDataSet::series() const
473 {
473 {
474 return m_seriesDomainMap.keys();
474 return m_seriesDomainMap.keys();
475 }
475 }
476
476
477 void ChartDataSet::updateSeries(QAbstractSeries *series)
477 void ChartDataSet::updateSeries(QAbstractSeries *series)
478 {
478 {
479 emit seriesUpdated(series);
479 emit seriesUpdated(series);
480 }
480 }
481
481
482 #include "moc_chartdataset_p.cpp"
482 #include "moc_chartdataset_p.cpp"
483
483
484 QTCOMMERCIALCHART_END_NAMESPACE
484 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,30 +1,30
1 !include( ../tests.pri ) {
1 !include( ../tests.pri ) {
2 error( "Couldn't find the tests.pri file!" )
2 error( "Couldn't find the tests.pri file!" )
3 }
3 }
4
4
5 TEMPLATE = subdirs
5 TEMPLATE = subdirs
6 SUBDIRS += \
6 SUBDIRS += \
7 qchartview \
7 qchartview \
8 qchart \
8 qchart \
9 qlineseries \
9 qlineseries \
10 qbarset \
10 qbarset \
11 qbarseries \
11 qbarseries \
12 qstackedbarseries \
12 qstackedbarseries \
13 qpercentbarseries \
13 qpercentbarseries \
14 qpieslice qpieseries \
14 qpieslice qpieseries \
15 qpiemodelmapper \
15 qpiemodelmapper \
16 qsplineseries \
16 qsplineseries \
17 qscatterseries \
17 qscatterseries \
18 qxymodelmapper \
18 qxymodelmapper \
19 qbarmodelmapper \
19 qbarmodelmapper \
20 qhorizontalbarseries \
20 qhorizontalbarseries \
21 qhorizontalstackedbarseries \
21 qhorizontalstackedbarseries \
22 qhorizontalpercentbarseries \
22 qhorizontalpercentbarseries \
23 qvalueaxis \
23 qvalueaxis \
24 qintervalsaxis \
24 qintervalsaxis \
25 qdatetimeaxis \
25 qdatetimeaxis \
26 qbarcategoriesaxis
26 qbarcategoryaxis
27
27
28 test_private:{
28 test_private:{
29 SUBDIRS += domain chartdataset
29 SUBDIRS += domain chartdataset
30 }
30 }
@@ -1,623 +1,623
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qabstractaxis.h>
22 #include <qabstractaxis.h>
23 #include <qvalueaxis.h>
23 #include <qvalueaxis.h>
24 #include <qbarcategoriesaxis.h>
24 #include <qbarcategoryaxis.h>
25 #include <qlineseries.h>
25 #include <qlineseries.h>
26 #include <qareaseries.h>
26 #include <qareaseries.h>
27 #include <qscatterseries.h>
27 #include <qscatterseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qpieseries.h>
29 #include <qpieseries.h>
30 #include <qbarseries.h>
30 #include <qbarseries.h>
31 #include <qpercentbarseries.h>
31 #include <qpercentbarseries.h>
32 #include <qstackedbarseries.h>
32 #include <qstackedbarseries.h>
33 #include <private/chartdataset_p.h>
33 #include <private/chartdataset_p.h>
34 #include <private/domain_p.h>
34 #include <private/domain_p.h>
35 #include <tst_definitions.h>
35 #include <tst_definitions.h>
36
36
37 QTCOMMERCIALCHART_USE_NAMESPACE
37 QTCOMMERCIALCHART_USE_NAMESPACE
38
38
39 Q_DECLARE_METATYPE(Domain *)
39 Q_DECLARE_METATYPE(Domain *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
44 Q_DECLARE_METATYPE(QLineSeries *)
44 Q_DECLARE_METATYPE(QLineSeries *)
45
45
46 class tst_ChartDataSet: public QObject {
46 class tst_ChartDataSet: public QObject {
47
47
48 Q_OBJECT
48 Q_OBJECT
49
49
50 public Q_SLOTS:
50 public Q_SLOTS:
51 void initTestCase();
51 void initTestCase();
52 void cleanupTestCase();
52 void cleanupTestCase();
53 void init();
53 void init();
54 void cleanup();
54 void cleanup();
55
55
56 private Q_SLOTS:
56 private Q_SLOTS:
57 void chartdataset_data();
57 void chartdataset_data();
58 void chartdataset();
58 void chartdataset();
59 void addSeries_data();
59 void addSeries_data();
60 void addSeries();
60 void addSeries();
61 void setAxisX_data();
61 void setAxisX_data();
62 void setAxisX();
62 void setAxisX();
63 void setAxisY_data();
63 void setAxisY_data();
64 void setAxisY();
64 void setAxisY();
65 void removeSeries_data();
65 void removeSeries_data();
66 void removeSeries();
66 void removeSeries();
67 void removeAllSeries_data();
67 void removeAllSeries_data();
68 void removeAllSeries();
68 void removeAllSeries();
69 void seriesCount_data();
69 void seriesCount_data();
70 void seriesCount();
70 void seriesCount();
71 void seriesIndex_data();
71 void seriesIndex_data();
72 void seriesIndex();
72 void seriesIndex();
73 void domain_data();
73 void domain_data();
74 void domain();
74 void domain();
75 void zoomInDomain_data();
75 void zoomInDomain_data();
76 void zoomInDomain();
76 void zoomInDomain();
77 void zoomOutDomain_data();
77 void zoomOutDomain_data();
78 void zoomOutDomain();
78 void zoomOutDomain();
79 void scrollDomain_data();
79 void scrollDomain_data();
80 void scrollDomain();
80 void scrollDomain();
81
81
82 private:
82 private:
83 ChartDataSet* m_dataset;
83 ChartDataSet* m_dataset;
84 };
84 };
85
85
86 void tst_ChartDataSet::initTestCase()
86 void tst_ChartDataSet::initTestCase()
87 {
87 {
88 qRegisterMetaType<Domain*>();
88 qRegisterMetaType<Domain*>();
89 qRegisterMetaType<QAbstractAxis*>();
89 qRegisterMetaType<QAbstractAxis*>();
90 qRegisterMetaType<QAbstractSeries*>();
90 qRegisterMetaType<QAbstractSeries*>();
91 }
91 }
92
92
93 void tst_ChartDataSet::cleanupTestCase()
93 void tst_ChartDataSet::cleanupTestCase()
94 {
94 {
95 }
95 }
96
96
97 void tst_ChartDataSet::init()
97 void tst_ChartDataSet::init()
98 {
98 {
99 m_dataset = new ChartDataSet();
99 m_dataset = new ChartDataSet();
100 }
100 }
101
101
102
102
103 void tst_ChartDataSet::cleanup()
103 void tst_ChartDataSet::cleanup()
104 {
104 {
105 QList<QAbstractSeries*> series = m_dataset->series();
105 QList<QAbstractSeries*> series = m_dataset->series();
106 foreach(QAbstractSeries* serie, series)
106 foreach(QAbstractSeries* serie, series)
107 {
107 {
108 m_dataset->removeSeries(serie);
108 m_dataset->removeSeries(serie);
109 }
109 }
110 }
110 }
111
111
112 void tst_ChartDataSet::chartdataset_data()
112 void tst_ChartDataSet::chartdataset_data()
113 {
113 {
114 }
114 }
115
115
116 void tst_ChartDataSet::chartdataset()
116 void tst_ChartDataSet::chartdataset()
117 {
117 {
118 QVERIFY(m_dataset->axisX(0) == 0);
118 QVERIFY(m_dataset->axisX(0) == 0);
119 QVERIFY(m_dataset->axisY(0) == 0);
119 QVERIFY(m_dataset->axisY(0) == 0);
120 QLineSeries* series = new QLineSeries(this);
120 QLineSeries* series = new QLineSeries(this);
121 QCOMPARE(m_dataset->seriesIndex(series),-1);
121 QCOMPARE(m_dataset->seriesIndex(series),-1);
122 QVERIFY(m_dataset->domain(series) == 0);
122 QVERIFY(m_dataset->domain(series) == 0);
123 QVERIFY(m_dataset->axisX(series) == 0);
123 QVERIFY(m_dataset->axisX(series) == 0);
124 QVERIFY(m_dataset->axisY(series) == 0);
124 QVERIFY(m_dataset->axisY(series) == 0);
125 m_dataset->createDefaultAxes();
125 m_dataset->createDefaultAxes();
126 }
126 }
127
127
128
128
129 void tst_ChartDataSet::addSeries_data()
129 void tst_ChartDataSet::addSeries_data()
130 {
130 {
131 QTest::addColumn<QAbstractSeries*>("series");
131 QTest::addColumn<QAbstractSeries*>("series");
132
132
133 QAbstractSeries* line = new QLineSeries(this);
133 QAbstractSeries* line = new QLineSeries(this);
134 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
134 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
135 QAbstractSeries* scatter = new QScatterSeries(this);
135 QAbstractSeries* scatter = new QScatterSeries(this);
136 QAbstractSeries* spline = new QSplineSeries(this);
136 QAbstractSeries* spline = new QSplineSeries(this);
137 QAbstractSeries* pie = new QPieSeries(this);
137 QAbstractSeries* pie = new QPieSeries(this);
138 QAbstractSeries* bar = new QBarSeries(this);
138 QAbstractSeries* bar = new QBarSeries(this);
139 QAbstractSeries* percent = new QPercentBarSeries(this);
139 QAbstractSeries* percent = new QPercentBarSeries(this);
140 QAbstractSeries* stacked = new QStackedBarSeries(this);
140 QAbstractSeries* stacked = new QStackedBarSeries(this);
141
141
142 QTest::newRow("line") << line;
142 QTest::newRow("line") << line;
143 QTest::newRow("area") << area;
143 QTest::newRow("area") << area;
144 QTest::newRow("scatter") << scatter;
144 QTest::newRow("scatter") << scatter;
145 QTest::newRow("spline") << spline;
145 QTest::newRow("spline") << spline;
146 QTest::newRow("pie") << pie;
146 QTest::newRow("pie") << pie;
147 QTest::newRow("bar") << bar;
147 QTest::newRow("bar") << bar;
148 QTest::newRow("percent") << percent;
148 QTest::newRow("percent") << percent;
149 QTest::newRow("stacked") << stacked;
149 QTest::newRow("stacked") << stacked;
150 }
150 }
151
151
152 void tst_ChartDataSet::addSeries()
152 void tst_ChartDataSet::addSeries()
153 {
153 {
154
154
155 QFETCH(QAbstractSeries*, series);
155 QFETCH(QAbstractSeries*, series);
156
156
157 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
157 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
158 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
158 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
159 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
159 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
160 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
160 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
161
161
162 m_dataset->addSeries(series);
162 m_dataset->addSeries(series);
163 m_dataset->createDefaultAxes();
163 m_dataset->createDefaultAxes();
164 if(series->type()==QAbstractSeries::SeriesTypePie){
164 if(series->type()==QAbstractSeries::SeriesTypePie){
165 TRY_COMPARE(spy0.count(), 0);
165 TRY_COMPARE(spy0.count(), 0);
166 }else{
166 }else{
167 TRY_COMPARE(spy0.count(), 2);
167 TRY_COMPARE(spy0.count(), 2);
168 }
168 }
169 TRY_COMPARE(spy1.count(), 0);
169 TRY_COMPARE(spy1.count(), 0);
170 TRY_COMPARE(spy2.count(), 1);
170 TRY_COMPARE(spy2.count(), 1);
171 TRY_COMPARE(spy3.count(), 0);
171 TRY_COMPARE(spy3.count(), 0);
172 }
172 }
173
173
174
174
175 void tst_ChartDataSet::setAxisX_data()
175 void tst_ChartDataSet::setAxisX_data()
176 {
176 {
177 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
177 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
178 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
178 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
179 QTest::addColumn<int>("axisCount");
179 QTest::addColumn<int>("axisCount");
180
180
181 QAbstractSeries* line = new QLineSeries(this);
181 QAbstractSeries* line = new QLineSeries(this);
182 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
182 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
183 QAbstractSeries* scatter = new QScatterSeries(this);
183 QAbstractSeries* scatter = new QScatterSeries(this);
184 QAbstractSeries* spline = new QSplineSeries(this);
184 QAbstractSeries* spline = new QSplineSeries(this);
185 QAbstractSeries* pie = new QPieSeries(this);
185 QAbstractSeries* pie = new QPieSeries(this);
186 QAbstractSeries* bar = new QBarSeries(this);
186 QAbstractSeries* bar = new QBarSeries(this);
187 QAbstractSeries* percent = new QPercentBarSeries(this);
187 QAbstractSeries* percent = new QPercentBarSeries(this);
188 QAbstractSeries* stacked = new QStackedBarSeries(this);
188 QAbstractSeries* stacked = new QStackedBarSeries(this);
189
189
190 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
190 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
191 << (QList<QAbstractSeries*>() << line << spline << scatter)
191 << (QList<QAbstractSeries*>() << line << spline << scatter)
192 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3;
192 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3;
193
193
194 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
194 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
195 << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1;
195 << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1;
196
196
197 QList<QAbstractAxis*> axes0;
197 QList<QAbstractAxis*> axes0;
198 axes0 << new QValueAxis(this) << new QValueAxis(this);
198 axes0 << new QValueAxis(this) << new QValueAxis(this);
199 axes0 << axes0.last();
199 axes0 << axes0.last();
200 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
200 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
201 << (QList<QAbstractSeries*>() << line << spline << scatter)
201 << (QList<QAbstractSeries*>() << line << spline << scatter)
202 << axes0 << 2;
202 << axes0 << 2;
203 //TODO: add more test cases
203 //TODO: add more test cases
204 }
204 }
205
205
206 void tst_ChartDataSet::setAxisX()
206 void tst_ChartDataSet::setAxisX()
207 {
207 {
208 QFETCH(QList<QAbstractSeries*>, seriesList);
208 QFETCH(QList<QAbstractSeries*>, seriesList);
209 QFETCH(QList<QAbstractAxis*>, axisList);
209 QFETCH(QList<QAbstractAxis*>, axisList);
210 QFETCH(int, axisCount);
210 QFETCH(int, axisCount);
211
211
212 Q_ASSERT(seriesList.count() == axisList.count());
212 Q_ASSERT(seriesList.count() == axisList.count());
213
213
214 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
214 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
215 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
215 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
216 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
216 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
217 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
217 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
218
218
219 foreach(QAbstractSeries* series, seriesList){
219 foreach(QAbstractSeries* series, seriesList){
220 m_dataset->addSeries(series);
220 m_dataset->addSeries(series);
221 }
221 }
222
222
223 TRY_COMPARE(spy0.count(), 0);
223 TRY_COMPARE(spy0.count(), 0);
224 TRY_COMPARE(spy1.count(), 0);
224 TRY_COMPARE(spy1.count(), 0);
225 TRY_COMPARE(spy2.count(), seriesList.count());
225 TRY_COMPARE(spy2.count(), seriesList.count());
226 TRY_COMPARE(spy3.count(), 0);
226 TRY_COMPARE(spy3.count(), 0);
227
227
228 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
228 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
229 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
229 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
230 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
230 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
231 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
231 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
232
232
233 for(int i=0 ; i < seriesList.count(); i++){
233 for(int i=0 ; i < seriesList.count(); i++){
234 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal);
234 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal);
235 }
235 }
236
236
237 TRY_COMPARE(spy4.count(), axisCount);
237 TRY_COMPARE(spy4.count(), axisCount);
238 TRY_COMPARE(spy5.count(), 0);
238 TRY_COMPARE(spy5.count(), 0);
239 TRY_COMPARE(spy6.count(), 0);
239 TRY_COMPARE(spy6.count(), 0);
240 TRY_COMPARE(spy7.count(), 0);
240 TRY_COMPARE(spy7.count(), 0);
241
241
242 for(int i=0 ; i < seriesList.count(); i++){
242 for(int i=0 ; i < seriesList.count(); i++){
243 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
243 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
244 }
244 }
245 }
245 }
246
246
247 void tst_ChartDataSet::setAxisY_data()
247 void tst_ChartDataSet::setAxisY_data()
248 {
248 {
249 setAxisX_data();
249 setAxisX_data();
250 }
250 }
251
251
252 void tst_ChartDataSet::setAxisY()
252 void tst_ChartDataSet::setAxisY()
253 {
253 {
254 QFETCH(QList<QAbstractSeries*>, seriesList);
254 QFETCH(QList<QAbstractSeries*>, seriesList);
255 QFETCH(QList<QAbstractAxis*>, axisList);
255 QFETCH(QList<QAbstractAxis*>, axisList);
256 QFETCH(int, axisCount);
256 QFETCH(int, axisCount);
257
257
258 Q_ASSERT(seriesList.count() == axisList.count());
258 Q_ASSERT(seriesList.count() == axisList.count());
259
259
260 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
260 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
261 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
261 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
262 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
262 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
263 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
263 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
264
264
265 foreach(QAbstractSeries* series, seriesList){
265 foreach(QAbstractSeries* series, seriesList){
266 m_dataset->addSeries(series);
266 m_dataset->addSeries(series);
267 }
267 }
268
268
269 TRY_COMPARE(spy0.count(), 0);
269 TRY_COMPARE(spy0.count(), 0);
270 TRY_COMPARE(spy1.count(), 0);
270 TRY_COMPARE(spy1.count(), 0);
271 TRY_COMPARE(spy2.count(), seriesList.count());
271 TRY_COMPARE(spy2.count(), seriesList.count());
272 TRY_COMPARE(spy3.count(), 0);
272 TRY_COMPARE(spy3.count(), 0);
273
273
274 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
274 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
275 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
275 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
276 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
276 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
277 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
277 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
278
278
279 for(int i=0 ; i < seriesList.count(); i++){
279 for(int i=0 ; i < seriesList.count(); i++){
280 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical);
280 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical);
281 }
281 }
282
282
283 TRY_COMPARE(spy4.count(), axisCount);
283 TRY_COMPARE(spy4.count(), axisCount);
284 TRY_COMPARE(spy5.count(), 0);
284 TRY_COMPARE(spy5.count(), 0);
285 TRY_COMPARE(spy6.count(), 0);
285 TRY_COMPARE(spy6.count(), 0);
286 TRY_COMPARE(spy7.count(), 0);
286 TRY_COMPARE(spy7.count(), 0);
287
287
288 for(int i=0 ; i < seriesList.count(); i++){
288 for(int i=0 ; i < seriesList.count(); i++){
289 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
289 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
290 }
290 }
291 }
291 }
292
292
293 void tst_ChartDataSet::removeSeries_data()
293 void tst_ChartDataSet::removeSeries_data()
294 {
294 {
295 addSeries_data();
295 addSeries_data();
296 }
296 }
297
297
298 void tst_ChartDataSet::removeSeries()
298 void tst_ChartDataSet::removeSeries()
299 {
299 {
300 QFETCH(QAbstractSeries*, series);
300 QFETCH(QAbstractSeries*, series);
301
301
302 m_dataset->addSeries(series);
302 m_dataset->addSeries(series);
303 m_dataset->createDefaultAxes();
303 m_dataset->createDefaultAxes();
304
304
305 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
305 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
306 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
306 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
307 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
307 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
308 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
308 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
309
309
310 m_dataset->removeSeries(series);
310 m_dataset->removeSeries(series);
311
311
312 TRY_COMPARE(spy0.count(), 0);
312 TRY_COMPARE(spy0.count(), 0);
313 if (series->type() == QAbstractSeries::SeriesTypePie) {
313 if (series->type() == QAbstractSeries::SeriesTypePie) {
314 TRY_COMPARE(spy1.count(), 0);
314 TRY_COMPARE(spy1.count(), 0);
315 }
315 }
316 else {
316 else {
317 TRY_COMPARE(spy1.count(), 2);
317 TRY_COMPARE(spy1.count(), 2);
318 }
318 }
319 TRY_COMPARE(spy2.count(), 0);
319 TRY_COMPARE(spy2.count(), 0);
320 TRY_COMPARE(spy3.count(), 1);
320 TRY_COMPARE(spy3.count(), 1);
321 }
321 }
322
322
323 void tst_ChartDataSet::removeAllSeries_data()
323 void tst_ChartDataSet::removeAllSeries_data()
324 {
324 {
325 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
325 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
326 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
326 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
327 QTest::addColumn<int>("axisCount");
327 QTest::addColumn<int>("axisCount");
328
328
329 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
329 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
330 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
330 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
331 << new QScatterSeries(this))
331 << new QScatterSeries(this))
332 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this)
332 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this)
333 << new QValueAxis(this)) << 3;
333 << new QValueAxis(this)) << 3;
334 //TODO:
334 //TODO:
335 }
335 }
336
336
337 void tst_ChartDataSet::removeAllSeries()
337 void tst_ChartDataSet::removeAllSeries()
338 {
338 {
339 QFETCH(QList<QAbstractSeries*>, seriesList);
339 QFETCH(QList<QAbstractSeries*>, seriesList);
340 QFETCH(QList<QAbstractAxis*>, axisList);
340 QFETCH(QList<QAbstractAxis*>, axisList);
341 QFETCH(int, axisCount);
341 QFETCH(int, axisCount);
342
342
343 foreach(QAbstractSeries* series, seriesList) {
343 foreach(QAbstractSeries* series, seriesList) {
344 m_dataset->addSeries(series);
344 m_dataset->addSeries(series);
345 }
345 }
346
346
347 for (int i = 0; i < seriesList.count(); i++) {
347 for (int i = 0; i < seriesList.count(); i++) {
348 m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal);
348 m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal);
349 }
349 }
350
350
351 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
351 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
352 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
352 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
353 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
353 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
354 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
354 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
355
355
356 m_dataset->removeAllSeries();
356 m_dataset->removeAllSeries();
357
357
358 TRY_COMPARE(spy0.count(), 0);
358 TRY_COMPARE(spy0.count(), 0);
359 TRY_COMPARE(spy1.count(), axisCount);
359 TRY_COMPARE(spy1.count(), axisCount);
360 TRY_COMPARE(spy2.count(), 0);
360 TRY_COMPARE(spy2.count(), 0);
361 TRY_COMPARE(spy3.count(), seriesList.count());
361 TRY_COMPARE(spy3.count(), seriesList.count());
362 }
362 }
363
363
364
364
365 void tst_ChartDataSet::seriesCount_data()
365 void tst_ChartDataSet::seriesCount_data()
366 {
366 {
367 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
367 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
368 QTest::addColumn<int>("seriesCount");
368 QTest::addColumn<int>("seriesCount");
369
369
370 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
370 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
371 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
371 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
372 }
372 }
373
373
374 void tst_ChartDataSet::seriesCount()
374 void tst_ChartDataSet::seriesCount()
375 {
375 {
376 QFETCH(QList<QAbstractSeries*>, seriesList);
376 QFETCH(QList<QAbstractSeries*>, seriesList);
377 QFETCH(int, seriesCount);
377 QFETCH(int, seriesCount);
378
378
379 foreach(QAbstractSeries* series, seriesList){
379 foreach(QAbstractSeries* series, seriesList){
380 m_dataset->addSeries(series);
380 m_dataset->addSeries(series);
381 }
381 }
382
382
383 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
383 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
384 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
384 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
385 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
385 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
386 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
386 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
387
387
388 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
388 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
389 TRY_COMPARE(spy0.count(), 0);
389 TRY_COMPARE(spy0.count(), 0);
390 TRY_COMPARE(spy1.count(), 0);
390 TRY_COMPARE(spy1.count(), 0);
391 TRY_COMPARE(spy2.count(), 0);
391 TRY_COMPARE(spy2.count(), 0);
392 TRY_COMPARE(spy3.count(), 0);
392 TRY_COMPARE(spy3.count(), 0);
393 }
393 }
394
394
395 void tst_ChartDataSet::seriesIndex_data()
395 void tst_ChartDataSet::seriesIndex_data()
396 {
396 {
397 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
397 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
398
398
399 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
399 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
400 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
400 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
401 }
401 }
402
402
403 void tst_ChartDataSet::seriesIndex()
403 void tst_ChartDataSet::seriesIndex()
404 {
404 {
405
405
406 QFETCH(QList<QAbstractSeries*>, seriesList);
406 QFETCH(QList<QAbstractSeries*>, seriesList);
407
407
408 foreach(QAbstractSeries* series, seriesList) {
408 foreach(QAbstractSeries* series, seriesList) {
409 m_dataset->addSeries(series);
409 m_dataset->addSeries(series);
410 }
410 }
411
411
412 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
412 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
413 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
413 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
414 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
414 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
415 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
415 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
416
416
417 for (int i = 0; i < seriesList.count(); i++) {
417 for (int i = 0; i < seriesList.count(); i++) {
418 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
418 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
419 }
419 }
420
420
421 TRY_COMPARE(spy0.count(), 0);
421 TRY_COMPARE(spy0.count(), 0);
422 TRY_COMPARE(spy1.count(), 0);
422 TRY_COMPARE(spy1.count(), 0);
423 TRY_COMPARE(spy2.count(), 0);
423 TRY_COMPARE(spy2.count(), 0);
424 TRY_COMPARE(spy3.count(), 0);
424 TRY_COMPARE(spy3.count(), 0);
425
425
426 foreach(QAbstractSeries* series, seriesList) {
426 foreach(QAbstractSeries* series, seriesList) {
427 m_dataset->removeSeries(series);
427 m_dataset->removeSeries(series);
428 }
428 }
429
429
430 for (int i = 0; i < seriesList.count(); i++) {
430 for (int i = 0; i < seriesList.count(); i++) {
431 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
431 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
432 }
432 }
433
433
434 foreach(QAbstractSeries* series, seriesList) {
434 foreach(QAbstractSeries* series, seriesList) {
435 m_dataset->addSeries(series);
435 m_dataset->addSeries(series);
436 }
436 }
437
437
438 for (int i = 0; i < seriesList.count(); i++) {
438 for (int i = 0; i < seriesList.count(); i++) {
439 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
439 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
440 }
440 }
441
441
442 m_dataset->removeSeries(seriesList.at(1));
442 m_dataset->removeSeries(seriesList.at(1));
443
443
444 for (int i = 0; i < seriesList.count(); i++) {
444 for (int i = 0; i < seriesList.count(); i++) {
445 if (i != 1)
445 if (i != 1)
446 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
446 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
447 else
447 else
448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
449 }
449 }
450
450
451 m_dataset->addSeries(seriesList.at(1));
451 m_dataset->addSeries(seriesList.at(1));
452
452
453 for (int i = 0; i < seriesList.count(); i++) {
453 for (int i = 0; i < seriesList.count(); i++) {
454 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
454 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
455 }
455 }
456
456
457 m_dataset->removeSeries(seriesList.at(2));
457 m_dataset->removeSeries(seriesList.at(2));
458
458
459 for (int i = 0; i < seriesList.count(); i++) {
459 for (int i = 0; i < seriesList.count(); i++) {
460 if (i != 2)
460 if (i != 2)
461 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
461 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
462 else
462 else
463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
464 }
464 }
465
465
466 m_dataset->removeSeries(seriesList.at(0));
466 m_dataset->removeSeries(seriesList.at(0));
467
467
468 for (int i = 0; i < seriesList.count(); i++) {
468 for (int i = 0; i < seriesList.count(); i++) {
469 if (i != 2 && i != 0)
469 if (i != 2 && i != 0)
470 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
470 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
471 else
471 else
472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
473 }
473 }
474
474
475 m_dataset->addSeries(seriesList.at(2));
475 m_dataset->addSeries(seriesList.at(2));
476 m_dataset->addSeries(seriesList.at(0));
476 m_dataset->addSeries(seriesList.at(0));
477
477
478 for (int i = 0; i < seriesList.count(); i++) {
478 for (int i = 0; i < seriesList.count(); i++) {
479 if (i == 2)
479 if (i == 2)
480 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
480 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
481 else if (i == 0)
481 else if (i == 0)
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
483 else
483 else
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
485 }
485 }
486
486
487 }
487 }
488
488
489 void tst_ChartDataSet::domain_data()
489 void tst_ChartDataSet::domain_data()
490 {
490 {
491 addSeries_data();
491 addSeries_data();
492 }
492 }
493
493
494 void tst_ChartDataSet::domain()
494 void tst_ChartDataSet::domain()
495 {
495 {
496 QFETCH(QAbstractSeries*, series);
496 QFETCH(QAbstractSeries*, series);
497
497
498 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
498 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
499 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
499 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
500 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
500 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
501 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
501 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
502
502
503 m_dataset->addSeries(series);
503 m_dataset->addSeries(series);
504 QVERIFY(m_dataset->domain(series));
504 QVERIFY(m_dataset->domain(series));
505
505
506
506
507 TRY_COMPARE(spy0.count(), 0);
507 TRY_COMPARE(spy0.count(), 0);
508 TRY_COMPARE(spy1.count(), 0);
508 TRY_COMPARE(spy1.count(), 0);
509 TRY_COMPARE(spy2.count(), 1);
509 TRY_COMPARE(spy2.count(), 1);
510
510
511 QList<QVariant> arguments = spy2.takeFirst();
511 QList<QVariant> arguments = spy2.takeFirst();
512 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
512 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
513 QVERIFY(m_dataset->domain(series) == domain);
513 QVERIFY(m_dataset->domain(series) == domain);
514
514
515 TRY_COMPARE(spy3.count(), 0);
515 TRY_COMPARE(spy3.count(), 0);
516
516
517 }
517 }
518
518
519 void tst_ChartDataSet::zoomInDomain_data()
519 void tst_ChartDataSet::zoomInDomain_data()
520 {
520 {
521 QTest::addColumn<bool >("sameAxis");
521 QTest::addColumn<bool >("sameAxis");
522 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
522 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
523 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
523 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
524 QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
524 QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
525 }
525 }
526
526
527 void tst_ChartDataSet::zoomInDomain()
527 void tst_ChartDataSet::zoomInDomain()
528 {
528 {
529 QFETCH(bool, sameAxis);
529 QFETCH(bool, sameAxis);
530 QFETCH(QList<QAbstractSeries*>, seriesList);
530 QFETCH(QList<QAbstractSeries*>, seriesList);
531
531
532 foreach(QAbstractSeries* series, seriesList) {
532 foreach(QAbstractSeries* series, seriesList) {
533 m_dataset->addSeries(series);
533 m_dataset->addSeries(series);
534 }
534 }
535
535
536 if(sameAxis) m_dataset->createDefaultAxes();
536 if(sameAxis) m_dataset->createDefaultAxes();
537
537
538 QList<QSignalSpy*> spyList;
538 QList<QSignalSpy*> spyList;
539
539
540 foreach(QAbstractSeries* series, seriesList) {
540 foreach(QAbstractSeries* series, seriesList) {
541 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated()));
541 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated()));
542 }
542 }
543
543
544 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
544 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
545
545
546 foreach(QSignalSpy* spy, spyList) {
546 foreach(QSignalSpy* spy, spyList) {
547 TRY_COMPARE(spy->count(), 1);
547 TRY_COMPARE(spy->count(), 1);
548 }
548 }
549
549
550 qDeleteAll(spyList);
550 qDeleteAll(spyList);
551 }
551 }
552
552
553
553
554
554
555 void tst_ChartDataSet::zoomOutDomain_data()
555 void tst_ChartDataSet::zoomOutDomain_data()
556 {
556 {
557 zoomInDomain_data();
557 zoomInDomain_data();
558 }
558 }
559
559
560 void tst_ChartDataSet::zoomOutDomain()
560 void tst_ChartDataSet::zoomOutDomain()
561 {
561 {
562 QFETCH(bool, sameAxis);
562 QFETCH(bool, sameAxis);
563 QFETCH(QList<QAbstractSeries*>, seriesList);
563 QFETCH(QList<QAbstractSeries*>, seriesList);
564
564
565 foreach(QAbstractSeries* series, seriesList) {
565 foreach(QAbstractSeries* series, seriesList) {
566 m_dataset->addSeries(series);
566 m_dataset->addSeries(series);
567 }
567 }
568
568
569 if (sameAxis)
569 if (sameAxis)
570 m_dataset->createDefaultAxes();
570 m_dataset->createDefaultAxes();
571
571
572 QList<QSignalSpy*> spyList;
572 QList<QSignalSpy*> spyList;
573
573
574 foreach(QAbstractSeries* series, seriesList) {
574 foreach(QAbstractSeries* series, seriesList) {
575 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated()));
575 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated()));
576 }
576 }
577
577
578 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
578 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
579
579
580 foreach(QSignalSpy* spy, spyList) {
580 foreach(QSignalSpy* spy, spyList) {
581 TRY_COMPARE(spy->count(), 1);
581 TRY_COMPARE(spy->count(), 1);
582 }
582 }
583
583
584 qDeleteAll (spyList);
584 qDeleteAll (spyList);
585 }
585 }
586
586
587 void tst_ChartDataSet::scrollDomain_data()
587 void tst_ChartDataSet::scrollDomain_data()
588 {
588 {
589 zoomInDomain_data();
589 zoomInDomain_data();
590 }
590 }
591
591
592 void tst_ChartDataSet::scrollDomain()
592 void tst_ChartDataSet::scrollDomain()
593 {
593 {
594 QFETCH(bool, sameAxis);
594 QFETCH(bool, sameAxis);
595 QFETCH(QList<QAbstractSeries*>, seriesList);
595 QFETCH(QList<QAbstractSeries*>, seriesList);
596
596
597 foreach(QAbstractSeries* series, seriesList) {
597 foreach(QAbstractSeries* series, seriesList) {
598 m_dataset->addSeries(series);
598 m_dataset->addSeries(series);
599 }
599 }
600
600
601 if (sameAxis)
601 if (sameAxis)
602 m_dataset->createDefaultAxes();
602 m_dataset->createDefaultAxes();
603
603
604 QList<QSignalSpy*> spyList;
604 QList<QSignalSpy*> spyList;
605
605
606 foreach(QAbstractSeries* series, seriesList) {
606 foreach(QAbstractSeries* series, seriesList) {
607 spyList
607 spyList
608 << new QSignalSpy(m_dataset->domain(series),
608 << new QSignalSpy(m_dataset->domain(series),
609 SIGNAL(updated()));
609 SIGNAL(updated()));
610 }
610 }
611
611
612 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
612 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
613
613
614 foreach(QSignalSpy* spy, spyList) {
614 foreach(QSignalSpy* spy, spyList) {
615 TRY_COMPARE(spy->count(), 1);
615 TRY_COMPARE(spy->count(), 1);
616 }
616 }
617
617
618 qDeleteAll(spyList);
618 qDeleteAll(spyList);
619 }
619 }
620
620
621 QTEST_MAIN(tst_ChartDataSet)
621 QTEST_MAIN(tst_ChartDataSet)
622 #include "tst_chartdataset.moc"
622 #include "tst_chartdataset.moc"
623
623
@@ -1,5 +1,5
1 !include( ../auto.pri ) {
1 !include( ../auto.pri ) {
2 error( "Couldn't find the auto.pri file!" )
2 error( "Couldn't find the auto.pri file!" )
3 }
3 }
4 HEADERS += ../qabstractaxis/tst_qabstractaxis.h
4 HEADERS += ../qabstractaxis/tst_qabstractaxis.h
5 SOURCES += tst_qbarcategoriesaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp
5 SOURCES += tst_qbarcategoryaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp
@@ -1,649 +1,649
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "../qabstractaxis/tst_qabstractaxis.h"
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include <qbarseries.h>
22 #include <qbarseries.h>
23 #include <qbarset.h>
23 #include <qbarset.h>
24 #include <qbarcategoriesaxis.h>
24 #include <qbarcategoryaxis.h>
25
25
26 class tst_QBarCategoriesAxis: public tst_QAbstractAxis
26 class tst_QBarCategoriesAxis: public tst_QAbstractAxis
27 {
27 {
28 Q_OBJECT
28 Q_OBJECT
29
29
30 public slots:
30 public slots:
31 void initTestCase();
31 void initTestCase();
32 void cleanupTestCase();
32 void cleanupTestCase();
33 void init();
33 void init();
34 void cleanup();
34 void cleanup();
35
35
36 private slots:
36 private slots:
37 void qbarcategoriesaxis_data();
37 void qbarcategoryaxis_data();
38 void qbarcategoriesaxis();
38 void qbarcategoryaxis();
39
39
40 void append_data();
40 void append_data();
41 void append();
41 void append();
42 void at_data();
42 void at_data();
43 void at();
43 void at();
44 void categories_data();
44 void categories_data();
45 void categories();
45 void categories();
46 void clear_data();
46 void clear_data();
47 void clear();
47 void clear();
48 void count_data();
48 void count_data();
49 void count();
49 void count();
50 void insert_data();
50 void insert_data();
51 void insert();
51 void insert();
52 void remove_data();
52 void remove_data();
53 void remove();
53 void remove();
54 void max_raw_data();
54 void max_raw_data();
55 void max_raw();
55 void max_raw();
56 void max_data();
56 void max_data();
57 void max();
57 void max();
58 void max_animation_data();
58 void max_animation_data();
59 void max_animation();
59 void max_animation();
60 void min_raw_data();
60 void min_raw_data();
61 void min_raw();
61 void min_raw();
62 void min_data();
62 void min_data();
63 void min();
63 void min();
64 void min_animation_data();
64 void min_animation_data();
65 void min_animation();
65 void min_animation();
66 void range_raw_data();
66 void range_raw_data();
67 void range_raw();
67 void range_raw();
68 void range_data();
68 void range_data();
69 void range();
69 void range();
70 void range_animation_data();
70 void range_animation_data();
71 void range_animation();
71 void range_animation();
72 void noautoscale_data();
72 void noautoscale_data();
73 void noautoscale();
73 void noautoscale();
74 void autoscale_data();
74 void autoscale_data();
75 void autoscale();
75 void autoscale();
76
76
77 private:
77 private:
78 QBarCategoryAxis* m_baraxis;
78 QBarCategoryAxis* m_baraxis;
79 QBarSeries* m_series;
79 QBarSeries* m_series;
80 };
80 };
81
81
82 void tst_QBarCategoriesAxis::initTestCase()
82 void tst_QBarCategoriesAxis::initTestCase()
83 {
83 {
84 }
84 }
85
85
86 void tst_QBarCategoriesAxis::cleanupTestCase()
86 void tst_QBarCategoriesAxis::cleanupTestCase()
87 {
87 {
88 }
88 }
89
89
90 void tst_QBarCategoriesAxis::init()
90 void tst_QBarCategoriesAxis::init()
91 {
91 {
92 m_baraxis = new QBarCategoryAxis();
92 m_baraxis = new QBarCategoryAxis();
93 m_series = new QBarSeries();
93 m_series = new QBarSeries();
94
94
95 QBarSet *set0 = new QBarSet("Jane");
95 QBarSet *set0 = new QBarSet("Jane");
96 QBarSet *set1 = new QBarSet("John");
96 QBarSet *set1 = new QBarSet("John");
97 QBarSet *set2 = new QBarSet("Axel");
97 QBarSet *set2 = new QBarSet("Axel");
98 QBarSet *set3 = new QBarSet("Mary");
98 QBarSet *set3 = new QBarSet("Mary");
99 QBarSet *set4 = new QBarSet("Samantha");
99 QBarSet *set4 = new QBarSet("Samantha");
100
100
101 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
101 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
102 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
102 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
103 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
103 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
104 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
104 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
105 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
105 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
106
106
107 m_series->append(set0);
107 m_series->append(set0);
108 m_series->append(set1);
108 m_series->append(set1);
109 m_series->append(set2);
109 m_series->append(set2);
110 m_series->append(set3);
110 m_series->append(set3);
111 m_series->append(set4);
111 m_series->append(set4);
112
112
113 QStringList categories;
113 QStringList categories;
114 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
114 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
115
115
116 m_baraxis->append(categories);
116 m_baraxis->append(categories);
117
117
118 tst_QAbstractAxis::init(m_baraxis, m_series);
118 tst_QAbstractAxis::init(m_baraxis, m_series);
119 m_chart->addSeries(m_series);
119 m_chart->addSeries(m_series);
120 m_chart->createDefaultAxes();
120 m_chart->createDefaultAxes();
121 }
121 }
122
122
123 void tst_QBarCategoriesAxis::cleanup()
123 void tst_QBarCategoriesAxis::cleanup()
124 {
124 {
125 delete m_series;
125 delete m_series;
126 delete m_baraxis;
126 delete m_baraxis;
127 m_series = 0;
127 m_series = 0;
128 m_baraxis = 0;
128 m_baraxis = 0;
129 tst_QAbstractAxis::cleanup();
129 tst_QAbstractAxis::cleanup();
130 }
130 }
131
131
132 void tst_QBarCategoriesAxis::qbarcategoriesaxis_data()
132 void tst_QBarCategoriesAxis::qbarcategoryaxis_data()
133 {
133 {
134 }
134 }
135
135
136 void tst_QBarCategoriesAxis::qbarcategoriesaxis()
136 void tst_QBarCategoriesAxis::qbarcategoryaxis()
137 {
137 {
138 qabstractaxis();
138 qabstractaxis();
139 QBarCategoryAxis axis;
139 QBarCategoryAxis axis;
140 axis.append(QStringList());
140 axis.append(QStringList());
141 axis.append(QString());
141 axis.append(QString());
142 QCOMPARE(axis.at(0), QString());
142 QCOMPARE(axis.at(0), QString());
143 QStringList test;
143 QStringList test;
144 test.append(QString());
144 test.append(QString());
145 QCOMPARE(axis.categories(),test);
145 QCOMPARE(axis.categories(),test);
146 axis.clear();
146 axis.clear();
147 QCOMPARE(axis.count(), 0);
147 QCOMPARE(axis.count(), 0);
148 axis.insert(-1, QString());
148 axis.insert(-1, QString());
149 QCOMPARE(axis.max(), QString());
149 QCOMPARE(axis.max(), QString());
150 QCOMPARE(axis.min(), QString());
150 QCOMPARE(axis.min(), QString());
151 axis.remove(QString());
151 axis.remove(QString());
152 axis.setCategories(QStringList());
152 axis.setCategories(QStringList());
153 axis.setMax(QString());
153 axis.setMax(QString());
154 axis.setMin(QString());
154 axis.setMin(QString());
155 axis.setRange(QString(), QString());
155 axis.setRange(QString(), QString());
156 QCOMPARE(axis.type(), QAbstractAxis::AxisTypeCategories);
156 QCOMPARE(axis.type(), QAbstractAxis::AxisTypeCategories);
157 }
157 }
158
158
159 void tst_QBarCategoriesAxis::append_data()
159 void tst_QBarCategoriesAxis::append_data()
160 {
160 {
161 QTest::addColumn<QStringList>("categories");
161 QTest::addColumn<QStringList>("categories");
162 QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr");
162 QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr");
163 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
163 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
164 }
164 }
165
165
166 void tst_QBarCategoriesAxis::append()
166 void tst_QBarCategoriesAxis::append()
167 {
167 {
168 QFETCH(QStringList, categories);
168 QFETCH(QStringList, categories);
169
169
170 QBarCategoryAxis axis;
170 QBarCategoryAxis axis;
171
171
172 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
172 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
173 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
173 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
174 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
174 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
175 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
175 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
176
176
177 axis.append(categories);
177 axis.append(categories);
178
178
179 QCOMPARE(spy0.count(), 1);
179 QCOMPARE(spy0.count(), 1);
180 QCOMPARE(spy1.count(), 1);
180 QCOMPARE(spy1.count(), 1);
181 QCOMPARE(spy2.count(), 1);
181 QCOMPARE(spy2.count(), 1);
182 QCOMPARE(spy3.count(), 1);
182 QCOMPARE(spy3.count(), 1);
183
183
184 m_chart->setAxisX(&axis, m_series);
184 m_chart->setAxisX(&axis, m_series);
185 m_view->show();
185 m_view->show();
186 QTest::qWaitForWindowShown(m_view);
186 QTest::qWaitForWindowShown(m_view);
187 QCOMPARE(axis.categories(), categories);
187 QCOMPARE(axis.categories(), categories);
188
188
189 QCOMPARE(spy0.count(), 1);
189 QCOMPARE(spy0.count(), 1);
190 QCOMPARE(spy1.count(), 1);
190 QCOMPARE(spy1.count(), 1);
191 QCOMPARE(spy2.count(), 1);
191 QCOMPARE(spy2.count(), 1);
192 QCOMPARE(spy3.count(), 1);
192 QCOMPARE(spy3.count(), 1);
193 }
193 }
194
194
195 void tst_QBarCategoriesAxis::at_data()
195 void tst_QBarCategoriesAxis::at_data()
196 {
196 {
197 QTest::addColumn<QStringList>("categories");
197 QTest::addColumn<QStringList>("categories");
198 QTest::addColumn<int>("index");
198 QTest::addColumn<int>("index");
199 QTest::addColumn<QString>("string");
199 QTest::addColumn<QString>("string");
200 QTest::newRow("Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul";
200 QTest::newRow("Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul";
201 QTest::newRow("Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep";
201 QTest::newRow("Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep";
202 QTest::newRow("Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug";
202 QTest::newRow("Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug";
203 }
203 }
204
204
205 void tst_QBarCategoriesAxis::at()
205 void tst_QBarCategoriesAxis::at()
206 {
206 {
207 QFETCH(int, index);
207 QFETCH(int, index);
208 QFETCH(QString, string);
208 QFETCH(QString, string);
209 QFETCH(QStringList, categories);
209 QFETCH(QStringList, categories);
210
210
211 QBarCategoryAxis axis;
211 QBarCategoryAxis axis;
212 axis.append(categories);
212 axis.append(categories);
213
213
214 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
214 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
215 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
215 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
216 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
216 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
217 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
217 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
218
218
219 QCOMPARE(axis.at(index), string);
219 QCOMPARE(axis.at(index), string);
220
220
221 QCOMPARE(spy0.count(), 0);
221 QCOMPARE(spy0.count(), 0);
222 QCOMPARE(spy1.count(), 0);
222 QCOMPARE(spy1.count(), 0);
223 QCOMPARE(spy2.count(), 0);
223 QCOMPARE(spy2.count(), 0);
224 QCOMPARE(spy3.count(), 0);
224 QCOMPARE(spy3.count(), 0);
225
225
226 m_chart->setAxisX(&axis, m_series);
226 m_chart->setAxisX(&axis, m_series);
227 m_view->show();
227 m_view->show();
228 QTest::qWaitForWindowShown(m_view);
228 QTest::qWaitForWindowShown(m_view);
229 QCOMPARE(axis.at(index), string);
229 QCOMPARE(axis.at(index), string);
230
230
231 QCOMPARE(spy0.count(), 0);
231 QCOMPARE(spy0.count(), 0);
232 QCOMPARE(spy1.count(), 0);
232 QCOMPARE(spy1.count(), 0);
233 QCOMPARE(spy2.count(), 0);
233 QCOMPARE(spy2.count(), 0);
234 QCOMPARE(spy3.count(), 0);
234 QCOMPARE(spy3.count(), 0);
235 }
235 }
236
236
237 void tst_QBarCategoriesAxis::categories_data()
237 void tst_QBarCategoriesAxis::categories_data()
238 {
238 {
239 QTest::addColumn<QStringList>("categories");
239 QTest::addColumn<QStringList>("categories");
240 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
240 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
241 }
241 }
242
242
243 void tst_QBarCategoriesAxis::categories()
243 void tst_QBarCategoriesAxis::categories()
244 {
244 {
245 QFETCH(QStringList, categories);
245 QFETCH(QStringList, categories);
246
246
247 QBarCategoryAxis axis;
247 QBarCategoryAxis axis;
248
248
249 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
249 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
250 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
250 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
251 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
251 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
252 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
252 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
253
253
254 axis.setCategories(categories);
254 axis.setCategories(categories);
255 QCOMPARE(axis.categories(), categories);
255 QCOMPARE(axis.categories(), categories);
256
256
257 QCOMPARE(spy0.count(), 1);
257 QCOMPARE(spy0.count(), 1);
258 QCOMPARE(spy1.count(), 1);
258 QCOMPARE(spy1.count(), 1);
259 QCOMPARE(spy2.count(), 1);
259 QCOMPARE(spy2.count(), 1);
260 QCOMPARE(spy3.count(), 1);
260 QCOMPARE(spy3.count(), 1);
261
261
262 m_chart->setAxisX(&axis, m_series);
262 m_chart->setAxisX(&axis, m_series);
263 m_view->show();
263 m_view->show();
264 QTest::qWaitForWindowShown(m_view);
264 QTest::qWaitForWindowShown(m_view);
265 QCOMPARE(axis.categories(), categories);
265 QCOMPARE(axis.categories(), categories);
266
266
267 QCOMPARE(spy0.count(), 1);
267 QCOMPARE(spy0.count(), 1);
268 QCOMPARE(spy1.count(), 1);
268 QCOMPARE(spy1.count(), 1);
269 QCOMPARE(spy2.count(), 1);
269 QCOMPARE(spy2.count(), 1);
270 QCOMPARE(spy3.count(), 1);
270 QCOMPARE(spy3.count(), 1);
271
271
272 }
272 }
273
273
274 void tst_QBarCategoriesAxis::clear_data()
274 void tst_QBarCategoriesAxis::clear_data()
275 {
275 {
276 QTest::addColumn<QStringList>("categories");
276 QTest::addColumn<QStringList>("categories");
277 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
277 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
278 }
278 }
279
279
280 void tst_QBarCategoriesAxis::clear()
280 void tst_QBarCategoriesAxis::clear()
281 {
281 {
282 QFETCH(QStringList, categories);
282 QFETCH(QStringList, categories);
283
283
284 QBarCategoryAxis axis;
284 QBarCategoryAxis axis;
285
285
286 axis.setCategories(categories);
286 axis.setCategories(categories);
287 QCOMPARE(axis.categories(), categories);
287 QCOMPARE(axis.categories(), categories);
288
288
289 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
289 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
290 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
290 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
291 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
291 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
292 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
292 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
293
293
294 axis.clear();
294 axis.clear();
295 QCOMPARE(axis.categories(), QStringList());
295 QCOMPARE(axis.categories(), QStringList());
296
296
297 QCOMPARE(spy0.count(), 1);
297 QCOMPARE(spy0.count(), 1);
298 QCOMPARE(spy1.count(), 1);
298 QCOMPARE(spy1.count(), 1);
299 QCOMPARE(spy2.count(), 1);
299 QCOMPARE(spy2.count(), 1);
300 QCOMPARE(spy3.count(), 1);
300 QCOMPARE(spy3.count(), 1);
301
301
302 m_chart->setAxisX(&axis, m_series);
302 m_chart->setAxisX(&axis, m_series);
303 m_view->show();
303 m_view->show();
304 QTest::qWaitForWindowShown(m_view);
304 QTest::qWaitForWindowShown(m_view);
305
305
306 QCOMPARE(spy0.count(), 2);
306 QCOMPARE(spy0.count(), 2);
307 QCOMPARE(spy1.count(), 2);
307 QCOMPARE(spy1.count(), 2);
308 QCOMPARE(spy2.count(), 2);
308 QCOMPARE(spy2.count(), 2);
309 QCOMPARE(spy3.count(), 2);
309 QCOMPARE(spy3.count(), 2);
310
310
311 axis.clear();
311 axis.clear();
312 QCOMPARE(axis.categories().count(),0);
312 QCOMPARE(axis.categories().count(),0);
313 QCOMPARE(spy0.count(), 3);
313 QCOMPARE(spy0.count(), 3);
314 QCOMPARE(spy1.count(), 3);
314 QCOMPARE(spy1.count(), 3);
315 QCOMPARE(spy2.count(), 3);
315 QCOMPARE(spy2.count(), 3);
316 QCOMPARE(spy3.count(), 3);
316 QCOMPARE(spy3.count(), 3);
317 }
317 }
318
318
319 void tst_QBarCategoriesAxis::count_data()
319 void tst_QBarCategoriesAxis::count_data()
320 {
320 {
321 QTest::addColumn<QStringList>("categories");
321 QTest::addColumn<QStringList>("categories");
322 QTest::addColumn<int>("count");
322 QTest::addColumn<int>("count");
323 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3;
323 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3;
324 QTest::newRow("Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2;
324 QTest::newRow("Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2;
325 }
325 }
326
326
327 void tst_QBarCategoriesAxis::count()
327 void tst_QBarCategoriesAxis::count()
328 {
328 {
329 QFETCH(QStringList, categories);
329 QFETCH(QStringList, categories);
330 QFETCH(int, count);
330 QFETCH(int, count);
331
331
332 QBarCategoryAxis axis;
332 QBarCategoryAxis axis;
333 axis.setCategories(categories);
333 axis.setCategories(categories);
334
334
335 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
335 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
336 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
336 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
337 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
337 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
338 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
338 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
339
339
340 QCOMPARE(axis.count(), count);
340 QCOMPARE(axis.count(), count);
341
341
342 QCOMPARE(spy0.count(), 0);
342 QCOMPARE(spy0.count(), 0);
343 QCOMPARE(spy1.count(), 0);
343 QCOMPARE(spy1.count(), 0);
344 QCOMPARE(spy2.count(), 0);
344 QCOMPARE(spy2.count(), 0);
345 QCOMPARE(spy3.count(), 0);
345 QCOMPARE(spy3.count(), 0);
346
346
347 m_chart->setAxisX(&axis, m_series);
347 m_chart->setAxisX(&axis, m_series);
348 m_view->show();
348 m_view->show();
349 QTest::qWaitForWindowShown(m_view);
349 QTest::qWaitForWindowShown(m_view);
350 QCOMPARE(axis.count(), count);
350 QCOMPARE(axis.count(), count);
351 }
351 }
352
352
353 void tst_QBarCategoriesAxis::insert_data()
353 void tst_QBarCategoriesAxis::insert_data()
354 {
354 {
355 QTest::addColumn<QStringList>("categories");
355 QTest::addColumn<QStringList>("categories");
356 QTest::addColumn<int>("index");
356 QTest::addColumn<int>("index");
357 QTest::addColumn<QString>("category");
357 QTest::addColumn<QString>("category");
358 QTest::newRow("Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jun";
358 QTest::newRow("Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jun";
359 QTest::newRow("Jul Aug Sep 3 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3 << "Sep";
359 QTest::newRow("Jul Aug Sep 3 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3 << "Sep";
360 QTest::newRow("Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer";
360 QTest::newRow("Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer";
361 }
361 }
362
362
363 void tst_QBarCategoriesAxis::insert()
363 void tst_QBarCategoriesAxis::insert()
364 {
364 {
365 QFETCH(QStringList, categories);
365 QFETCH(QStringList, categories);
366 QFETCH(int, index);
366 QFETCH(int, index);
367 QFETCH(QString, category);
367 QFETCH(QString, category);
368
368
369 QBarCategoryAxis axis;
369 QBarCategoryAxis axis;
370 axis.append(categories);
370 axis.append(categories);
371
371
372 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
372 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
373 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
373 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
374 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
374 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
375 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
375 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
376
376
377 axis.insert(index, category);
377 axis.insert(index, category);
378 QCOMPARE(axis.at(index),category);
378 QCOMPARE(axis.at(index),category);
379
379
380 QCOMPARE(spy0.count(), 1);
380 QCOMPARE(spy0.count(), 1);
381 QCOMPARE(spy1.count(), 0);
381 QCOMPARE(spy1.count(), 0);
382 QCOMPARE(spy2.count(), 0);
382 QCOMPARE(spy2.count(), 0);
383 QCOMPARE(spy3.count(), 0);
383 QCOMPARE(spy3.count(), 0);
384
384
385 m_chart->setAxisX(&axis, m_series);
385 m_chart->setAxisX(&axis, m_series);
386 m_view->show();
386 m_view->show();
387 QTest::qWaitForWindowShown(m_view);
387 QTest::qWaitForWindowShown(m_view);
388 }
388 }
389
389
390 void tst_QBarCategoriesAxis::remove_data()
390 void tst_QBarCategoriesAxis::remove_data()
391 {
391 {
392 QTest::addColumn<QStringList>("categories");
392 QTest::addColumn<QStringList>("categories");
393 QTest::addColumn<QString>("category");
393 QTest::addColumn<QString>("category");
394 QTest::addColumn<QStringList>("result");
394 QTest::addColumn<QStringList>("result");
395 QTest::newRow("Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep");
395 QTest::newRow("Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep");
396 QTest::newRow("Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep");
396 QTest::newRow("Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep");
397 }
397 }
398
398
399 void tst_QBarCategoriesAxis::remove()
399 void tst_QBarCategoriesAxis::remove()
400 {
400 {
401 QFETCH(QStringList, categories);
401 QFETCH(QStringList, categories);
402 QFETCH(QString, category);
402 QFETCH(QString, category);
403 QFETCH(QStringList, result);
403 QFETCH(QStringList, result);
404
404
405 QBarCategoryAxis axis;
405 QBarCategoryAxis axis;
406 axis.append(categories);
406 axis.append(categories);
407
407
408 int maxCount = axis.max() == category;
408 int maxCount = axis.max() == category;
409 int minCount = axis.min() == category;
409 int minCount = axis.min() == category;
410 int rangeCount = maxCount + minCount;
410 int rangeCount = maxCount + minCount;
411
411
412 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
412 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
413 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
413 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
414 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
414 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
415 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
415 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
416
416
417 axis.remove(category);
417 axis.remove(category);
418 QCOMPARE(axis.categories(),result);
418 QCOMPARE(axis.categories(),result);
419
419
420 QCOMPARE(spy0.count(), 1);
420 QCOMPARE(spy0.count(), 1);
421 QCOMPARE(spy1.count(), maxCount);
421 QCOMPARE(spy1.count(), maxCount);
422 QCOMPARE(spy2.count(), minCount);
422 QCOMPARE(spy2.count(), minCount);
423 QCOMPARE(spy3.count(), rangeCount);
423 QCOMPARE(spy3.count(), rangeCount);
424 }
424 }
425
425
426 void tst_QBarCategoriesAxis::max_raw_data()
426 void tst_QBarCategoriesAxis::max_raw_data()
427 {
427 {
428 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
428 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
429 QTest::addColumn<QString>("max");
429 QTest::addColumn<QString>("max");
430 QTest::newRow("Feb") << "Feb";
430 QTest::newRow("Feb") << "Feb";
431 QTest::newRow("Apr") << "Apr";
431 QTest::newRow("Apr") << "Apr";
432 QTest::newRow("May") << "May";
432 QTest::newRow("May") << "May";
433 }
433 }
434
434
435 void tst_QBarCategoriesAxis::max_raw()
435 void tst_QBarCategoriesAxis::max_raw()
436 {
436 {
437 QFETCH(QString, max);
437 QFETCH(QString, max);
438
438
439 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
439 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
440 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&)));
440 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&)));
441 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&)));
441 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&)));
442 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&)));
442 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&)));
443
443
444 m_baraxis->setMax(max);
444 m_baraxis->setMax(max);
445 QCOMPARE(m_baraxis->max(), max);
445 QCOMPARE(m_baraxis->max(), max);
446
446
447 QCOMPARE(spy0.count(), 0);
447 QCOMPARE(spy0.count(), 0);
448 QCOMPARE(spy1.count(), 1);
448 QCOMPARE(spy1.count(), 1);
449 QCOMPARE(spy2.count(), 0);
449 QCOMPARE(spy2.count(), 0);
450 QCOMPARE(spy3.count(), 1);
450 QCOMPARE(spy3.count(), 1);
451 }
451 }
452
452
453 void tst_QBarCategoriesAxis::max_data()
453 void tst_QBarCategoriesAxis::max_data()
454 {
454 {
455 max_raw_data();
455 max_raw_data();
456 }
456 }
457
457
458 void tst_QBarCategoriesAxis::max()
458 void tst_QBarCategoriesAxis::max()
459 {
459 {
460 m_chart->setAxisX(m_baraxis, m_series);
460 m_chart->setAxisX(m_baraxis, m_series);
461 m_view->show();
461 m_view->show();
462 QTest::qWaitForWindowShown(m_view);
462 QTest::qWaitForWindowShown(m_view);
463 max_raw();
463 max_raw();
464 }
464 }
465
465
466 void tst_QBarCategoriesAxis::max_animation_data()
466 void tst_QBarCategoriesAxis::max_animation_data()
467 {
467 {
468 max_data();
468 max_data();
469 }
469 }
470
470
471 void tst_QBarCategoriesAxis::max_animation()
471 void tst_QBarCategoriesAxis::max_animation()
472 {
472 {
473 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
473 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
474 max();
474 max();
475 }
475 }
476
476
477 void tst_QBarCategoriesAxis::min_raw_data()
477 void tst_QBarCategoriesAxis::min_raw_data()
478 {
478 {
479 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
479 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
480 QTest::addColumn<QString>("min");
480 QTest::addColumn<QString>("min");
481 QTest::newRow("Feb") << "Feb";
481 QTest::newRow("Feb") << "Feb";
482 QTest::newRow("Apr") << "Apr";
482 QTest::newRow("Apr") << "Apr";
483 QTest::newRow("May") << "May";
483 QTest::newRow("May") << "May";
484 }
484 }
485
485
486 void tst_QBarCategoriesAxis::min_raw()
486 void tst_QBarCategoriesAxis::min_raw()
487 {
487 {
488 QFETCH(QString, min);
488 QFETCH(QString, min);
489
489
490 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
490 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
491 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&)));
491 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&)));
492 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&)));
492 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&)));
493 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&)));
493 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&)));
494
494
495 m_baraxis->setMin(min);
495 m_baraxis->setMin(min);
496 QCOMPARE(m_baraxis->min(), min);
496 QCOMPARE(m_baraxis->min(), min);
497
497
498 QCOMPARE(spy0.count(), 0);
498 QCOMPARE(spy0.count(), 0);
499 QCOMPARE(spy1.count(), 0);
499 QCOMPARE(spy1.count(), 0);
500 QCOMPARE(spy2.count(), 1);
500 QCOMPARE(spy2.count(), 1);
501 QCOMPARE(spy3.count(), 1);
501 QCOMPARE(spy3.count(), 1);
502
502
503 }
503 }
504
504
505 void tst_QBarCategoriesAxis::min_data()
505 void tst_QBarCategoriesAxis::min_data()
506 {
506 {
507 min_raw_data();
507 min_raw_data();
508 }
508 }
509
509
510 void tst_QBarCategoriesAxis::min()
510 void tst_QBarCategoriesAxis::min()
511 {
511 {
512 m_chart->setAxisX(m_baraxis, m_series);
512 m_chart->setAxisX(m_baraxis, m_series);
513 m_view->show();
513 m_view->show();
514 QTest::qWaitForWindowShown(m_view);
514 QTest::qWaitForWindowShown(m_view);
515 min_raw();
515 min_raw();
516 }
516 }
517
517
518 void tst_QBarCategoriesAxis::min_animation_data()
518 void tst_QBarCategoriesAxis::min_animation_data()
519 {
519 {
520 min_data();
520 min_data();
521 }
521 }
522
522
523 void tst_QBarCategoriesAxis::min_animation()
523 void tst_QBarCategoriesAxis::min_animation()
524 {
524 {
525 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
525 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
526 min();
526 min();
527 }
527 }
528
528
529
529
530 void tst_QBarCategoriesAxis::range_raw_data()
530 void tst_QBarCategoriesAxis::range_raw_data()
531 {
531 {
532 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
532 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
533 QTest::addColumn<QString>("min");
533 QTest::addColumn<QString>("min");
534 QTest::addColumn<QString>("max");
534 QTest::addColumn<QString>("max");
535 QTest::newRow("Feb - Apr") << "Feb" << "Apr";
535 QTest::newRow("Feb - Apr") << "Feb" << "Apr";
536 QTest::newRow("Feb - May") << "Feb" << "May";
536 QTest::newRow("Feb - May") << "Feb" << "May";
537 QTest::newRow("Mar - Apr") << "Mar" << "Apr";
537 QTest::newRow("Mar - Apr") << "Mar" << "Apr";
538 }
538 }
539
539
540 void tst_QBarCategoriesAxis::range_raw()
540 void tst_QBarCategoriesAxis::range_raw()
541 {
541 {
542 QFETCH(QString, min);
542 QFETCH(QString, min);
543 QFETCH(QString, max);
543 QFETCH(QString, max);
544
544
545 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
545 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
546 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&)));
546 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&)));
547 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&)));
547 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&)));
548 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&)));
548 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&)));
549
549
550 m_baraxis->setRange(min, max);
550 m_baraxis->setRange(min, max);
551 QCOMPARE(m_baraxis->min(), min);
551 QCOMPARE(m_baraxis->min(), min);
552 QCOMPARE(m_baraxis->max(), max);
552 QCOMPARE(m_baraxis->max(), max);
553
553
554 QCOMPARE(spy0.count(), 0);
554 QCOMPARE(spy0.count(), 0);
555 QCOMPARE(spy1.count(), 1);
555 QCOMPARE(spy1.count(), 1);
556 QCOMPARE(spy2.count(), 1);
556 QCOMPARE(spy2.count(), 1);
557 QCOMPARE(spy3.count(), 1);
557 QCOMPARE(spy3.count(), 1);
558 }
558 }
559
559
560 void tst_QBarCategoriesAxis::range_data()
560 void tst_QBarCategoriesAxis::range_data()
561 {
561 {
562 range_raw_data();
562 range_raw_data();
563 }
563 }
564
564
565 void tst_QBarCategoriesAxis::range()
565 void tst_QBarCategoriesAxis::range()
566 {
566 {
567 m_chart->setAxisX(m_baraxis, m_series);
567 m_chart->setAxisX(m_baraxis, m_series);
568 m_view->show();
568 m_view->show();
569 QTest::qWaitForWindowShown(m_view);
569 QTest::qWaitForWindowShown(m_view);
570 range_raw();
570 range_raw();
571 }
571 }
572
572
573 void tst_QBarCategoriesAxis::range_animation_data()
573 void tst_QBarCategoriesAxis::range_animation_data()
574 {
574 {
575 range_data();
575 range_data();
576 }
576 }
577
577
578 void tst_QBarCategoriesAxis::range_animation()
578 void tst_QBarCategoriesAxis::range_animation()
579 {
579 {
580 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
580 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
581 range();
581 range();
582 }
582 }
583
583
584
584
585 void tst_QBarCategoriesAxis::noautoscale_data()
585 void tst_QBarCategoriesAxis::noautoscale_data()
586 {
586 {
587 QTest::addColumn<QString>("min");
587 QTest::addColumn<QString>("min");
588 QTest::addColumn<QString>("max");
588 QTest::addColumn<QString>("max");
589 QTest::newRow("Feb - Mar") << "Feb" << "Mar";
589 QTest::newRow("Feb - Mar") << "Feb" << "Mar";
590 QTest::newRow("Feb - May") << "Feb" << "May";
590 QTest::newRow("Feb - May") << "Feb" << "May";
591 QTest::newRow("Apr - May") << "Apr" << "May";
591 QTest::newRow("Apr - May") << "Apr" << "May";
592 }
592 }
593
593
594 void tst_QBarCategoriesAxis::noautoscale()
594 void tst_QBarCategoriesAxis::noautoscale()
595 {
595 {
596 QFETCH(QString, min);
596 QFETCH(QString, min);
597 QFETCH(QString, max);
597 QFETCH(QString, max);
598
598
599 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
599 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
600 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
600 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
601 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString)));
601 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString)));
602
602
603 m_baraxis->setRange(min, max);
603 m_baraxis->setRange(min, max);
604 QCOMPARE(m_baraxis->min(),min);
604 QCOMPARE(m_baraxis->min(),min);
605 QCOMPARE(m_baraxis->max(),max);
605 QCOMPARE(m_baraxis->max(),max);
606
606
607 QCOMPARE(spy0.count(), 1);
607 QCOMPARE(spy0.count(), 1);
608 QCOMPARE(spy1.count(), 1);
608 QCOMPARE(spy1.count(), 1);
609 QCOMPARE(spy2.count(), 1);
609 QCOMPARE(spy2.count(), 1);
610
610
611 m_chart->setAxisX(m_baraxis, m_series);
611 m_chart->setAxisX(m_baraxis, m_series);
612 m_view->show();
612 m_view->show();
613 QTest::qWaitForWindowShown(m_view);
613 QTest::qWaitForWindowShown(m_view);
614 QCOMPARE(m_baraxis->min(),min);
614 QCOMPARE(m_baraxis->min(),min);
615 QCOMPARE(m_baraxis->max(),max);
615 QCOMPARE(m_baraxis->max(),max);
616 }
616 }
617
617
618 void tst_QBarCategoriesAxis::autoscale_data()
618 void tst_QBarCategoriesAxis::autoscale_data()
619 {
619 {
620
620
621 }
621 }
622
622
623 void tst_QBarCategoriesAxis::autoscale()
623 void tst_QBarCategoriesAxis::autoscale()
624 {
624 {
625 delete m_baraxis;
625 delete m_baraxis;
626 m_baraxis = new QBarCategoryAxis();
626 m_baraxis = new QBarCategoryAxis();
627
627
628 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
628 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
629 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
629 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
630 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString)));
630 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString)));
631
631
632 QCOMPARE(m_baraxis->min(),QString());
632 QCOMPARE(m_baraxis->min(),QString());
633 QCOMPARE(m_baraxis->max(),QString());
633 QCOMPARE(m_baraxis->max(),QString());
634 m_chart->setAxisX(m_baraxis, m_series);
634 m_chart->setAxisX(m_baraxis, m_series);
635
635
636 QCOMPARE(spy0.count(), 1);
636 QCOMPARE(spy0.count(), 1);
637 QCOMPARE(spy1.count(), 1);
637 QCOMPARE(spy1.count(), 1);
638 QCOMPARE(spy2.count(), 1);
638 QCOMPARE(spy2.count(), 1);
639
639
640 m_view->show();
640 m_view->show();
641 QTest::qWaitForWindowShown(m_view);
641 QTest::qWaitForWindowShown(m_view);
642 QCOMPARE(m_baraxis->min(),QString("1"));
642 QCOMPARE(m_baraxis->min(),QString("1"));
643 QCOMPARE(m_baraxis->max(),QString("6"));
643 QCOMPARE(m_baraxis->max(),QString("6"));
644 }
644 }
645
645
646
646
647 QTEST_MAIN(tst_QBarCategoriesAxis)
647 QTEST_MAIN(tst_QBarCategoriesAxis)
648 #include "tst_qbarcategoriesaxis.moc"
648 #include "tst_qbarcategoryaxis.moc"
649
649
@@ -1,788 +1,788
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qchartview.h>
22 #include <qchartview.h>
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24 #include <qareaseries.h>
24 #include <qareaseries.h>
25 #include <qscatterseries.h>
25 #include <qscatterseries.h>
26 #include <qsplineseries.h>
26 #include <qsplineseries.h>
27 #include <qpieseries.h>
27 #include <qpieseries.h>
28 #include <qabstractbarseries.h>
28 #include <qabstractbarseries.h>
29 #include <qbarseries.h>
29 #include <qbarseries.h>
30 #include <qpercentbarseries.h>
30 #include <qpercentbarseries.h>
31 #include <qstackedbarseries.h>
31 #include <qstackedbarseries.h>
32 #include <qvalueaxis.h>
32 #include <qvalueaxis.h>
33 #include <qbarcategoriesaxis.h>
33 #include <qbarcategoryaxis.h>
34
34
35 QTCOMMERCIALCHART_USE_NAMESPACE
35 QTCOMMERCIALCHART_USE_NAMESPACE
36
36
37 Q_DECLARE_METATYPE(QAbstractAxis *)
37 Q_DECLARE_METATYPE(QAbstractAxis *)
38 Q_DECLARE_METATYPE(QValueAxis *)
38 Q_DECLARE_METATYPE(QValueAxis *)
39 Q_DECLARE_METATYPE(QBarCategoryAxis *)
39 Q_DECLARE_METATYPE(QBarCategoryAxis *)
40 Q_DECLARE_METATYPE(QAbstractSeries *)
40 Q_DECLARE_METATYPE(QAbstractSeries *)
41 Q_DECLARE_METATYPE(QChart::AnimationOption)
41 Q_DECLARE_METATYPE(QChart::AnimationOption)
42 Q_DECLARE_METATYPE(QBrush)
42 Q_DECLARE_METATYPE(QBrush)
43 Q_DECLARE_METATYPE(QPen)
43 Q_DECLARE_METATYPE(QPen)
44 Q_DECLARE_METATYPE(QChart::ChartTheme)
44 Q_DECLARE_METATYPE(QChart::ChartTheme)
45
45
46 class tst_QChart : public QObject
46 class tst_QChart : public QObject
47 {
47 {
48 Q_OBJECT
48 Q_OBJECT
49
49
50 public slots:
50 public slots:
51 void initTestCase();
51 void initTestCase();
52 void cleanupTestCase();
52 void cleanupTestCase();
53 void init();
53 void init();
54 void cleanup();
54 void cleanup();
55
55
56 private slots:
56 private slots:
57 void qchart_data();
57 void qchart_data();
58 void qchart();
58 void qchart();
59 void addSeries_data();
59 void addSeries_data();
60 void addSeries();
60 void addSeries();
61 void animationOptions_data();
61 void animationOptions_data();
62 void animationOptions();
62 void animationOptions();
63 void axisX_data();
63 void axisX_data();
64 void axisX();
64 void axisX();
65 void axisY_data();
65 void axisY_data();
66 void axisY();
66 void axisY();
67 void backgroundBrush_data();
67 void backgroundBrush_data();
68 void backgroundBrush();
68 void backgroundBrush();
69 void backgroundPen_data();
69 void backgroundPen_data();
70 void backgroundPen();
70 void backgroundPen();
71 void isBackgroundVisible_data();
71 void isBackgroundVisible_data();
72 void isBackgroundVisible();
72 void isBackgroundVisible();
73 void legend_data();
73 void legend_data();
74 void legend();
74 void legend();
75 void margins_data();
75 void margins_data();
76 void margins();
76 void margins();
77 void removeAllSeries_data();
77 void removeAllSeries_data();
78 void removeAllSeries();
78 void removeAllSeries();
79 void removeSeries_data();
79 void removeSeries_data();
80 void removeSeries();
80 void removeSeries();
81 void scroll_right_data();
81 void scroll_right_data();
82 void scroll_right();
82 void scroll_right();
83 void scroll_left_data();
83 void scroll_left_data();
84 void scroll_left();
84 void scroll_left();
85 void scroll_up_data();
85 void scroll_up_data();
86 void scroll_up();
86 void scroll_up();
87 void scroll_down_data();
87 void scroll_down_data();
88 void scroll_down();
88 void scroll_down();
89 void theme_data();
89 void theme_data();
90 void theme();
90 void theme();
91 void title_data();
91 void title_data();
92 void title();
92 void title();
93 void titleBrush_data();
93 void titleBrush_data();
94 void titleBrush();
94 void titleBrush();
95 void titleFont_data();
95 void titleFont_data();
96 void titleFont();
96 void titleFont();
97 void zoomIn_data();
97 void zoomIn_data();
98 void zoomIn();
98 void zoomIn();
99 void zoomOut_data();
99 void zoomOut_data();
100 void zoomOut();
100 void zoomOut();
101
101
102 private:
102 private:
103 void createTestData();
103 void createTestData();
104
104
105 private:
105 private:
106 QChartView* m_view;
106 QChartView* m_view;
107 QChart* m_chart;
107 QChart* m_chart;
108 };
108 };
109
109
110 void tst_QChart::initTestCase()
110 void tst_QChart::initTestCase()
111 {
111 {
112
112
113 }
113 }
114
114
115 void tst_QChart::cleanupTestCase()
115 void tst_QChart::cleanupTestCase()
116 {
116 {
117
117
118 }
118 }
119
119
120 void tst_QChart::init()
120 void tst_QChart::init()
121 {
121 {
122 m_view = new QChartView(new QChart());
122 m_view = new QChartView(new QChart());
123 m_chart = m_view->chart();
123 m_chart = m_view->chart();
124 }
124 }
125
125
126 void tst_QChart::cleanup()
126 void tst_QChart::cleanup()
127 {
127 {
128 delete m_view;
128 delete m_view;
129 m_view = 0;
129 m_view = 0;
130 m_chart = 0;
130 m_chart = 0;
131 }
131 }
132
132
133
133
134 void tst_QChart::createTestData()
134 void tst_QChart::createTestData()
135 {
135 {
136 QLineSeries* series0 = new QLineSeries(this);
136 QLineSeries* series0 = new QLineSeries(this);
137 *series0 << QPointF(0, 0) << QPointF(100, 100);
137 *series0 << QPointF(0, 0) << QPointF(100, 100);
138 m_chart->addSeries(series0);
138 m_chart->addSeries(series0);
139 m_view->show();
139 m_view->show();
140 QTest::qWaitForWindowShown(m_view);
140 QTest::qWaitForWindowShown(m_view);
141 }
141 }
142
142
143 void tst_QChart::qchart_data()
143 void tst_QChart::qchart_data()
144 {
144 {
145 }
145 }
146
146
147 void tst_QChart::qchart()
147 void tst_QChart::qchart()
148 {
148 {
149 QVERIFY(m_chart);
149 QVERIFY(m_chart);
150 QVERIFY(m_chart->legend());
150 QVERIFY(m_chart->legend());
151 QVERIFY(m_chart->legend()->isVisible());
151 QVERIFY(m_chart->legend()->isVisible());
152
152
153 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
153 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
154 QVERIFY(!m_chart->axisX());
154 QVERIFY(!m_chart->axisX());
155 QVERIFY(!m_chart->axisY());
155 QVERIFY(!m_chart->axisY());
156 QVERIFY(m_chart->backgroundBrush()!=QBrush());
156 QVERIFY(m_chart->backgroundBrush()!=QBrush());
157 QVERIFY(m_chart->backgroundPen()!=QPen());
157 QVERIFY(m_chart->backgroundPen()!=QPen());
158 QCOMPARE(m_chart->isBackgroundVisible(), true);
158 QCOMPARE(m_chart->isBackgroundVisible(), true);
159
159
160 QVERIFY(m_chart->margins().top()>0);
160 QVERIFY(m_chart->margins().top()>0);
161 QVERIFY(m_chart->margins().left()>0);
161 QVERIFY(m_chart->margins().left()>0);
162 QVERIFY(m_chart->margins().right()>0);
162 QVERIFY(m_chart->margins().right()>0);
163 QVERIFY(m_chart->margins().bottom()>0);
163 QVERIFY(m_chart->margins().bottom()>0);
164
164
165 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
165 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
166 QCOMPARE(m_chart->title(), QString());
166 QCOMPARE(m_chart->title(), QString());
167
167
168 //QCOMPARE(m_chart->titleBrush(),QBrush());
168 //QCOMPARE(m_chart->titleBrush(),QBrush());
169 //QCOMPARE(m_chart->titleFont(),QFont());
169 //QCOMPARE(m_chart->titleFont(),QFont());
170
170
171 m_chart->removeAllSeries();
171 m_chart->removeAllSeries();
172 m_chart->scroll(0,0);
172 m_chart->scroll(0,0);
173
173
174 m_chart->zoomIn();
174 m_chart->zoomIn();
175 m_chart->zoomIn(QRectF());
175 m_chart->zoomIn(QRectF());
176 m_chart->zoomOut();
176 m_chart->zoomOut();
177 }
177 }
178
178
179 void tst_QChart::addSeries_data()
179 void tst_QChart::addSeries_data()
180 {
180 {
181 QTest::addColumn<QAbstractSeries *>("series");
181 QTest::addColumn<QAbstractSeries *>("series");
182
182
183 QAbstractSeries* line = new QLineSeries(this);
183 QAbstractSeries* line = new QLineSeries(this);
184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
185 QAbstractSeries* scatter = new QScatterSeries(this);
185 QAbstractSeries* scatter = new QScatterSeries(this);
186 QAbstractSeries* spline = new QSplineSeries(this);
186 QAbstractSeries* spline = new QSplineSeries(this);
187 QAbstractSeries* pie = new QPieSeries(this);
187 QAbstractSeries* pie = new QPieSeries(this);
188 QAbstractSeries* bar = new QBarSeries(this);
188 QAbstractSeries* bar = new QBarSeries(this);
189 QAbstractSeries* percent = new QPercentBarSeries(this);
189 QAbstractSeries* percent = new QPercentBarSeries(this);
190 QAbstractSeries* stacked = new QStackedBarSeries(this);
190 QAbstractSeries* stacked = new QStackedBarSeries(this);
191
191
192 QTest::newRow("lineSeries") << line;
192 QTest::newRow("lineSeries") << line;
193 QTest::newRow("areaSeries") << area;
193 QTest::newRow("areaSeries") << area;
194 QTest::newRow("scatterSeries") << scatter;
194 QTest::newRow("scatterSeries") << scatter;
195 QTest::newRow("splineSeries") << spline;
195 QTest::newRow("splineSeries") << spline;
196 QTest::newRow("pieSeries") << pie;
196 QTest::newRow("pieSeries") << pie;
197 QTest::newRow("barSeries") << bar;
197 QTest::newRow("barSeries") << bar;
198 QTest::newRow("percentBarSeries") << percent;
198 QTest::newRow("percentBarSeries") << percent;
199 QTest::newRow("stackedBarSeries") << stacked;
199 QTest::newRow("stackedBarSeries") << stacked;
200
200
201 }
201 }
202
202
203 void tst_QChart::addSeries()
203 void tst_QChart::addSeries()
204 {
204 {
205 QFETCH(QAbstractSeries *, series);
205 QFETCH(QAbstractSeries *, series);
206 m_view->show();
206 m_view->show();
207 QTest::qWaitForWindowShown(m_view);
207 QTest::qWaitForWindowShown(m_view);
208 QVERIFY(!series->chart());
208 QVERIFY(!series->chart());
209 QCOMPARE(m_chart->series().count(), 0);
209 QCOMPARE(m_chart->series().count(), 0);
210 m_chart->addSeries(series);
210 m_chart->addSeries(series);
211 QCOMPARE(m_chart->series().count(), 1);
211 QCOMPARE(m_chart->series().count(), 1);
212 QCOMPARE(m_chart->series().first(), series);
212 QCOMPARE(m_chart->series().first(), series);
213 QVERIFY(series->chart() == m_chart);
213 QVERIFY(series->chart() == m_chart);
214 m_chart->createDefaultAxes();
214 m_chart->createDefaultAxes();
215 if(series->type()!=QAbstractSeries::SeriesTypePie){
215 if(series->type()!=QAbstractSeries::SeriesTypePie){
216 QVERIFY(m_chart->axisY(series));
216 QVERIFY(m_chart->axisY(series));
217 QVERIFY(m_chart->axisX(series));
217 QVERIFY(m_chart->axisX(series));
218 }else{
218 }else{
219 QVERIFY(!m_chart->axisY(series));
219 QVERIFY(!m_chart->axisY(series));
220 QVERIFY(!m_chart->axisX(series));
220 QVERIFY(!m_chart->axisX(series));
221 }
221 }
222 m_chart->removeSeries(series);
222 m_chart->removeSeries(series);
223 QVERIFY(!series->chart());
223 QVERIFY(!series->chart());
224 QCOMPARE(m_chart->series().count(), 0);
224 QCOMPARE(m_chart->series().count(), 0);
225 }
225 }
226
226
227 void tst_QChart::animationOptions_data()
227 void tst_QChart::animationOptions_data()
228 {
228 {
229 QTest::addColumn<QChart::AnimationOption>("animationOptions");
229 QTest::addColumn<QChart::AnimationOption>("animationOptions");
230 QTest::newRow("AllAnimations") << QChart::AllAnimations;
230 QTest::newRow("AllAnimations") << QChart::AllAnimations;
231 QTest::newRow("NoAnimation") << QChart::NoAnimation;
231 QTest::newRow("NoAnimation") << QChart::NoAnimation;
232 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
232 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
233 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
233 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
234 }
234 }
235
235
236 void tst_QChart::animationOptions()
236 void tst_QChart::animationOptions()
237 {
237 {
238 createTestData();
238 createTestData();
239 QFETCH(QChart::AnimationOption, animationOptions);
239 QFETCH(QChart::AnimationOption, animationOptions);
240 m_chart->setAnimationOptions(animationOptions);
240 m_chart->setAnimationOptions(animationOptions);
241 QCOMPARE(m_chart->animationOptions(), animationOptions);
241 QCOMPARE(m_chart->animationOptions(), animationOptions);
242 }
242 }
243
243
244 void tst_QChart::axisX_data()
244 void tst_QChart::axisX_data()
245 {
245 {
246
246
247 QTest::addColumn<QAbstractAxis*>("axis");
247 QTest::addColumn<QAbstractAxis*>("axis");
248 QTest::addColumn<QAbstractSeries *>("series");
248 QTest::addColumn<QAbstractSeries *>("series");
249
249
250 QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this);
250 QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this);
251 QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
251 QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
252 QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this);
252 QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this);
253 QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this);
253 QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this);
254 QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this);
254 QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this);
255 QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this);
255 QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this);
256 QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
256 QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
257 QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
257 QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
258
258
259 QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this);
259 QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this);
260 QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
260 QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
261 QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this);
261 QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this);
262 QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this);
262 QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this);
263 QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this);
263 QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this);
264 QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this);
264 QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this);
265 QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
265 QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
266 QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
266 QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
267
267
268 }
268 }
269
269
270 void tst_QChart::axisX()
270 void tst_QChart::axisX()
271 {
271 {
272 QFETCH(QAbstractAxis*, axis);
272 QFETCH(QAbstractAxis*, axis);
273 QFETCH(QAbstractSeries*, series);
273 QFETCH(QAbstractSeries*, series);
274 QVERIFY(!m_chart->axisX());
274 QVERIFY(!m_chart->axisX());
275 m_view->show();
275 m_view->show();
276 QTest::qWaitForWindowShown(m_view);
276 QTest::qWaitForWindowShown(m_view);
277 m_chart->addSeries(series);
277 m_chart->addSeries(series);
278 m_chart->setAxisX(axis,series);
278 m_chart->setAxisX(axis,series);
279 QVERIFY(m_chart->axisX(series)==axis);
279 QVERIFY(m_chart->axisX(series)==axis);
280 }
280 }
281
281
282 void tst_QChart::axisY_data()
282 void tst_QChart::axisY_data()
283 {
283 {
284 axisX_data();
284 axisX_data();
285 }
285 }
286
286
287
287
288 void tst_QChart::axisY()
288 void tst_QChart::axisY()
289 {
289 {
290 QFETCH(QAbstractAxis*, axis);
290 QFETCH(QAbstractAxis*, axis);
291 QFETCH(QAbstractSeries*, series);
291 QFETCH(QAbstractSeries*, series);
292 QVERIFY(!m_chart->axisY());
292 QVERIFY(!m_chart->axisY());
293 m_view->show();
293 m_view->show();
294 QTest::qWaitForWindowShown(m_view);
294 QTest::qWaitForWindowShown(m_view);
295 m_chart->addSeries(series);
295 m_chart->addSeries(series);
296 m_chart->setAxisY(axis,series);
296 m_chart->setAxisY(axis,series);
297 QVERIFY(m_chart->axisY(series)==axis);
297 QVERIFY(m_chart->axisY(series)==axis);
298 }
298 }
299
299
300 void tst_QChart::backgroundBrush_data()
300 void tst_QChart::backgroundBrush_data()
301 {
301 {
302 QTest::addColumn<QBrush>("backgroundBrush");
302 QTest::addColumn<QBrush>("backgroundBrush");
303 QTest::newRow("null") << QBrush();
303 QTest::newRow("null") << QBrush();
304 QTest::newRow("blue") << QBrush(Qt::blue);
304 QTest::newRow("blue") << QBrush(Qt::blue);
305 QTest::newRow("white") << QBrush(Qt::white);
305 QTest::newRow("white") << QBrush(Qt::white);
306 QTest::newRow("black") << QBrush(Qt::black);
306 QTest::newRow("black") << QBrush(Qt::black);
307 }
307 }
308
308
309 void tst_QChart::backgroundBrush()
309 void tst_QChart::backgroundBrush()
310 {
310 {
311 QFETCH(QBrush, backgroundBrush);
311 QFETCH(QBrush, backgroundBrush);
312 m_chart->setBackgroundBrush(backgroundBrush);
312 m_chart->setBackgroundBrush(backgroundBrush);
313 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
313 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
314 }
314 }
315
315
316 void tst_QChart::backgroundPen_data()
316 void tst_QChart::backgroundPen_data()
317 {
317 {
318 QTest::addColumn<QPen>("backgroundPen");
318 QTest::addColumn<QPen>("backgroundPen");
319 QTest::newRow("null") << QPen();
319 QTest::newRow("null") << QPen();
320 QTest::newRow("blue") << QPen(Qt::blue);
320 QTest::newRow("blue") << QPen(Qt::blue);
321 QTest::newRow("white") << QPen(Qt::white);
321 QTest::newRow("white") << QPen(Qt::white);
322 QTest::newRow("black") << QPen(Qt::black);
322 QTest::newRow("black") << QPen(Qt::black);
323 }
323 }
324
324
325
325
326 void tst_QChart::backgroundPen()
326 void tst_QChart::backgroundPen()
327 {
327 {
328 QFETCH(QPen, backgroundPen);
328 QFETCH(QPen, backgroundPen);
329 m_chart->setBackgroundPen(backgroundPen);
329 m_chart->setBackgroundPen(backgroundPen);
330 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
330 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
331 }
331 }
332
332
333 void tst_QChart::isBackgroundVisible_data()
333 void tst_QChart::isBackgroundVisible_data()
334 {
334 {
335 QTest::addColumn<bool>("isBackgroundVisible");
335 QTest::addColumn<bool>("isBackgroundVisible");
336 QTest::newRow("true") << true;
336 QTest::newRow("true") << true;
337 QTest::newRow("false") << false;
337 QTest::newRow("false") << false;
338 }
338 }
339
339
340 void tst_QChart::isBackgroundVisible()
340 void tst_QChart::isBackgroundVisible()
341 {
341 {
342 QFETCH(bool, isBackgroundVisible);
342 QFETCH(bool, isBackgroundVisible);
343 m_chart->setBackgroundVisible(isBackgroundVisible);
343 m_chart->setBackgroundVisible(isBackgroundVisible);
344 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
344 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
345 }
345 }
346
346
347 void tst_QChart::legend_data()
347 void tst_QChart::legend_data()
348 {
348 {
349
349
350 }
350 }
351
351
352 void tst_QChart::legend()
352 void tst_QChart::legend()
353 {
353 {
354 QLegend *legend = m_chart->legend();
354 QLegend *legend = m_chart->legend();
355 QVERIFY(legend);
355 QVERIFY(legend);
356
356
357 // Colors related signals
357 // Colors related signals
358 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
358 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
359 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
359 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
360 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
360 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
361
361
362 // colorChanged
362 // colorChanged
363 legend->setColor(QColor("aliceblue"));
363 legend->setColor(QColor("aliceblue"));
364 QCOMPARE(colorSpy.count(), 1);
364 QCOMPARE(colorSpy.count(), 1);
365 QBrush b = legend->brush();
365 QBrush b = legend->brush();
366 b.setColor(QColor("aqua"));
366 b.setColor(QColor("aqua"));
367 legend->setBrush(b);
367 legend->setBrush(b);
368 QCOMPARE(colorSpy.count(), 2);
368 QCOMPARE(colorSpy.count(), 2);
369
369
370 // borderColorChanged
370 // borderColorChanged
371 legend->setBorderColor(QColor("aliceblue"));
371 legend->setBorderColor(QColor("aliceblue"));
372 QCOMPARE(borderColorSpy.count(), 1);
372 QCOMPARE(borderColorSpy.count(), 1);
373 QPen p = legend->pen();
373 QPen p = legend->pen();
374 p.setColor(QColor("aqua"));
374 p.setColor(QColor("aqua"));
375 legend->setPen(p);
375 legend->setPen(p);
376 QCOMPARE(borderColorSpy.count(), 2);
376 QCOMPARE(borderColorSpy.count(), 2);
377
377
378 // labelColorChanged
378 // labelColorChanged
379 legend->setLabelColor(QColor("lightsalmon"));
379 legend->setLabelColor(QColor("lightsalmon"));
380 QCOMPARE(labelColorSpy.count(), 1);
380 QCOMPARE(labelColorSpy.count(), 1);
381 b = legend->labelBrush();
381 b = legend->labelBrush();
382 b.setColor(QColor("lightseagreen"));
382 b.setColor(QColor("lightseagreen"));
383 legend->setLabelBrush(b);
383 legend->setLabelBrush(b);
384 QCOMPARE(labelColorSpy.count(), 2);
384 QCOMPARE(labelColorSpy.count(), 2);
385
385
386 // fontChanged
386 // fontChanged
387 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
387 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
388 QFont f = legend->font();
388 QFont f = legend->font();
389 f.setBold(!f.bold());
389 f.setBold(!f.bold());
390 legend->setFont(f);
390 legend->setFont(f);
391 QCOMPARE(fontSpy.count(), 1);
391 QCOMPARE(fontSpy.count(), 1);
392 }
392 }
393
393
394 void tst_QChart::margins_data()
394 void tst_QChart::margins_data()
395 {
395 {
396
396
397 }
397 }
398
398
399 void tst_QChart::margins()
399 void tst_QChart::margins()
400 {
400 {
401 createTestData();
401 createTestData();
402 QRectF rect = m_chart->geometry();
402 QRectF rect = m_chart->geometry();
403 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
403 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
404 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
404 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
405 }
405 }
406
406
407 void tst_QChart::removeAllSeries_data()
407 void tst_QChart::removeAllSeries_data()
408 {
408 {
409
409
410 }
410 }
411
411
412 void tst_QChart::removeAllSeries()
412 void tst_QChart::removeAllSeries()
413 {
413 {
414 QLineSeries* series0 = new QLineSeries(this);
414 QLineSeries* series0 = new QLineSeries(this);
415 QLineSeries* series1 = new QLineSeries(this);
415 QLineSeries* series1 = new QLineSeries(this);
416 QLineSeries* series2 = new QLineSeries(this);
416 QLineSeries* series2 = new QLineSeries(this);
417 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
417 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
418 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
418 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
419 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
419 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
420
420
421 m_chart->addSeries(series0);
421 m_chart->addSeries(series0);
422 m_chart->addSeries(series1);
422 m_chart->addSeries(series1);
423 m_chart->addSeries(series2);
423 m_chart->addSeries(series2);
424 m_view->show();
424 m_view->show();
425 QTest::qWaitForWindowShown(m_view);
425 QTest::qWaitForWindowShown(m_view);
426 m_chart->createDefaultAxes();
426 m_chart->createDefaultAxes();
427 QVERIFY(m_chart->axisY(series0)!=0);
427 QVERIFY(m_chart->axisY(series0)!=0);
428 QVERIFY(m_chart->axisY(series1)!=0);
428 QVERIFY(m_chart->axisY(series1)!=0);
429 QVERIFY(m_chart->axisY(series2)!=0);
429 QVERIFY(m_chart->axisY(series2)!=0);
430
430
431 m_chart->removeAllSeries();
431 m_chart->removeAllSeries();
432 QVERIFY(m_chart->axisY(series0)==0);
432 QVERIFY(m_chart->axisY(series0)==0);
433 QVERIFY(m_chart->axisY(series1)==0);
433 QVERIFY(m_chart->axisY(series1)==0);
434 QVERIFY(m_chart->axisY(series2)==0);
434 QVERIFY(m_chart->axisY(series2)==0);
435 QCOMPARE(deleteSpy1.count(), 1);
435 QCOMPARE(deleteSpy1.count(), 1);
436 QCOMPARE(deleteSpy2.count(), 1);
436 QCOMPARE(deleteSpy2.count(), 1);
437 QCOMPARE(deleteSpy3.count(), 1);
437 QCOMPARE(deleteSpy3.count(), 1);
438 }
438 }
439
439
440 void tst_QChart::removeSeries_data()
440 void tst_QChart::removeSeries_data()
441 {
441 {
442 axisX_data();
442 axisX_data();
443 }
443 }
444
444
445 void tst_QChart::removeSeries()
445 void tst_QChart::removeSeries()
446 {
446 {
447 QFETCH(QAbstractAxis *, axis);
447 QFETCH(QAbstractAxis *, axis);
448 QFETCH(QAbstractSeries *, series);
448 QFETCH(QAbstractSeries *, series);
449 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
449 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
450 m_view->show();
450 m_view->show();
451 QTest::qWaitForWindowShown(m_view);
451 QTest::qWaitForWindowShown(m_view);
452 if(!axis) axis = m_chart->axisY();
452 if(!axis) axis = m_chart->axisY();
453 m_chart->addSeries(series);
453 m_chart->addSeries(series);
454 m_chart->setAxisY(axis,series);
454 m_chart->setAxisY(axis,series);
455 QCOMPARE(m_chart->axisY(series),axis);
455 QCOMPARE(m_chart->axisY(series),axis);
456 m_chart->removeSeries(series);
456 m_chart->removeSeries(series);
457 QVERIFY(m_chart->axisY(series)==0);
457 QVERIFY(m_chart->axisY(series)==0);
458 QCOMPARE(deleteSpy.count(), 0);
458 QCOMPARE(deleteSpy.count(), 0);
459 }
459 }
460
460
461 void tst_QChart::scroll_right_data()
461 void tst_QChart::scroll_right_data()
462 {
462 {
463 QTest::addColumn<QAbstractSeries *>("series");
463 QTest::addColumn<QAbstractSeries *>("series");
464
464
465 QLineSeries* series0 = new QLineSeries(this);
465 QLineSeries* series0 = new QLineSeries(this);
466 *series0 << QPointF(0, 0) << QPointF(100, 100);
466 *series0 << QPointF(0, 0) << QPointF(100, 100);
467
467
468 QTest::newRow("lineSeries") << (QAbstractSeries*) series0;
468 QTest::newRow("lineSeries") << (QAbstractSeries*) series0;
469
469
470
470
471 }
471 }
472
472
473 void tst_QChart::scroll_right()
473 void tst_QChart::scroll_right()
474 {
474 {
475 QFETCH(QAbstractSeries *, series);
475 QFETCH(QAbstractSeries *, series);
476 m_chart->addSeries(series);
476 m_chart->addSeries(series);
477 m_chart->createDefaultAxes();
477 m_chart->createDefaultAxes();
478 m_view->show();
478 m_view->show();
479 QTest::qWaitForWindowShown(m_view);
479 QTest::qWaitForWindowShown(m_view);
480 QAbstractAxis * axis = m_chart->axisX();
480 QAbstractAxis * axis = m_chart->axisX();
481 QVERIFY(axis!=0);
481 QVERIFY(axis!=0);
482
482
483 switch(axis->type())
483 switch(axis->type())
484 {
484 {
485 case QAbstractAxis::AxisTypeValues:{
485 case QAbstractAxis::AxisTypeValues:{
486 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
486 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
487 QVERIFY(vaxis!=0);
487 QVERIFY(vaxis!=0);
488 qreal min = vaxis->min();
488 qreal min = vaxis->min();
489 qreal max = vaxis->max();
489 qreal max = vaxis->max();
490 QVERIFY(max>min);
490 QVERIFY(max>min);
491 m_chart->scroll(50, 0);
491 m_chart->scroll(50, 0);
492 QVERIFY(min<vaxis->min());
492 QVERIFY(min<vaxis->min());
493 QVERIFY(max<vaxis->max());
493 QVERIFY(max<vaxis->max());
494 break;
494 break;
495 }
495 }
496 case QAbstractAxis::AxisTypeCategories:{
496 case QAbstractAxis::AxisTypeCategories:{
497 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
497 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
498 QVERIFY(caxis!=0);
498 QVERIFY(caxis!=0);
499 qreal min = caxis->min().toDouble();
499 qreal min = caxis->min().toDouble();
500 qreal max = caxis->max().toDouble();
500 qreal max = caxis->max().toDouble();
501 m_chart->scroll(50, 0);
501 m_chart->scroll(50, 0);
502 QVERIFY(min<caxis->min().toDouble());
502 QVERIFY(min<caxis->min().toDouble());
503 QVERIFY(max<caxis->max().toDouble());
503 QVERIFY(max<caxis->max().toDouble());
504 break;
504 break;
505 }
505 }
506 default:
506 default:
507 qFatal("Unsupported type");
507 qFatal("Unsupported type");
508 break;
508 break;
509 }
509 }
510 }
510 }
511
511
512 void tst_QChart::scroll_left_data()
512 void tst_QChart::scroll_left_data()
513 {
513 {
514 scroll_right_data();
514 scroll_right_data();
515 }
515 }
516
516
517 void tst_QChart::scroll_left()
517 void tst_QChart::scroll_left()
518 {
518 {
519 QFETCH(QAbstractSeries *, series);
519 QFETCH(QAbstractSeries *, series);
520 m_chart->addSeries(series);
520 m_chart->addSeries(series);
521 m_chart->createDefaultAxes();
521 m_chart->createDefaultAxes();
522 m_view->show();
522 m_view->show();
523 QTest::qWaitForWindowShown(m_view);
523 QTest::qWaitForWindowShown(m_view);
524 QAbstractAxis * axis = m_chart->axisX();
524 QAbstractAxis * axis = m_chart->axisX();
525 QVERIFY(axis!=0);
525 QVERIFY(axis!=0);
526
526
527 switch(axis->type())
527 switch(axis->type())
528 {
528 {
529 case QAbstractAxis::AxisTypeValues:{
529 case QAbstractAxis::AxisTypeValues:{
530 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
530 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
531 QVERIFY(vaxis!=0);
531 QVERIFY(vaxis!=0);
532 qreal min = vaxis->min();
532 qreal min = vaxis->min();
533 qreal max = vaxis->max();
533 qreal max = vaxis->max();
534 m_chart->scroll(-50, 0);
534 m_chart->scroll(-50, 0);
535 QVERIFY(min>vaxis->min());
535 QVERIFY(min>vaxis->min());
536 QVERIFY(max>vaxis->max());
536 QVERIFY(max>vaxis->max());
537 break;
537 break;
538 }
538 }
539 case QAbstractAxis::AxisTypeCategories:{
539 case QAbstractAxis::AxisTypeCategories:{
540 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
540 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
541 QVERIFY(caxis!=0);
541 QVERIFY(caxis!=0);
542 qreal min = caxis->min().toDouble();
542 qreal min = caxis->min().toDouble();
543 qreal max = caxis->max().toDouble();
543 qreal max = caxis->max().toDouble();
544 m_chart->scroll(-50, 0);
544 m_chart->scroll(-50, 0);
545 QVERIFY(min>caxis->min().toDouble());
545 QVERIFY(min>caxis->min().toDouble());
546 QVERIFY(max>caxis->max().toDouble());
546 QVERIFY(max>caxis->max().toDouble());
547 break;
547 break;
548 }
548 }
549 default:
549 default:
550 qFatal("Unsupported type");
550 qFatal("Unsupported type");
551 break;
551 break;
552 }
552 }
553 }
553 }
554
554
555 void tst_QChart::scroll_up_data()
555 void tst_QChart::scroll_up_data()
556 {
556 {
557 scroll_right_data();
557 scroll_right_data();
558 }
558 }
559
559
560 void tst_QChart::scroll_up()
560 void tst_QChart::scroll_up()
561 {
561 {
562 QFETCH(QAbstractSeries *, series);
562 QFETCH(QAbstractSeries *, series);
563 m_chart->addSeries(series);
563 m_chart->addSeries(series);
564 m_chart->createDefaultAxes();
564 m_chart->createDefaultAxes();
565 m_view->show();
565 m_view->show();
566 QTest::qWaitForWindowShown(m_view);
566 QTest::qWaitForWindowShown(m_view);
567 QAbstractAxis * axis = m_chart->axisY();
567 QAbstractAxis * axis = m_chart->axisY();
568 QVERIFY(axis!=0);
568 QVERIFY(axis!=0);
569
569
570 switch(axis->type())
570 switch(axis->type())
571 {
571 {
572 case QAbstractAxis::AxisTypeValues:{
572 case QAbstractAxis::AxisTypeValues:{
573 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
573 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
574 QVERIFY(vaxis!=0);
574 QVERIFY(vaxis!=0);
575 qreal min = vaxis->min();
575 qreal min = vaxis->min();
576 qreal max = vaxis->max();
576 qreal max = vaxis->max();
577 m_chart->scroll(0, 50);
577 m_chart->scroll(0, 50);
578 QVERIFY(min<vaxis->min());
578 QVERIFY(min<vaxis->min());
579 QVERIFY(max<vaxis->max());
579 QVERIFY(max<vaxis->max());
580 break;
580 break;
581 }
581 }
582 case QAbstractAxis::AxisTypeCategories:{
582 case QAbstractAxis::AxisTypeCategories:{
583 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
583 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
584 QVERIFY(caxis!=0);
584 QVERIFY(caxis!=0);
585 qreal min = caxis->min().toDouble();
585 qreal min = caxis->min().toDouble();
586 qreal max = caxis->max().toDouble();
586 qreal max = caxis->max().toDouble();
587 m_chart->scroll(0, 50);
587 m_chart->scroll(0, 50);
588 QVERIFY(min<caxis->min().toDouble());
588 QVERIFY(min<caxis->min().toDouble());
589 QVERIFY(max<caxis->max().toDouble());
589 QVERIFY(max<caxis->max().toDouble());
590 break;
590 break;
591 }
591 }
592 default:
592 default:
593 qFatal("Unsupported type");
593 qFatal("Unsupported type");
594 break;
594 break;
595 }
595 }
596 }
596 }
597
597
598 void tst_QChart::scroll_down_data()
598 void tst_QChart::scroll_down_data()
599 {
599 {
600 scroll_right_data();
600 scroll_right_data();
601 }
601 }
602
602
603 void tst_QChart::scroll_down()
603 void tst_QChart::scroll_down()
604 {
604 {
605 QFETCH(QAbstractSeries *, series);
605 QFETCH(QAbstractSeries *, series);
606 m_chart->addSeries(series);
606 m_chart->addSeries(series);
607 m_chart->createDefaultAxes();
607 m_chart->createDefaultAxes();
608 m_view->show();
608 m_view->show();
609 QTest::qWaitForWindowShown(m_view);
609 QTest::qWaitForWindowShown(m_view);
610 QAbstractAxis * axis = m_chart->axisY();
610 QAbstractAxis * axis = m_chart->axisY();
611 QVERIFY(axis!=0);
611 QVERIFY(axis!=0);
612
612
613 switch(axis->type())
613 switch(axis->type())
614 {
614 {
615 case QAbstractAxis::AxisTypeValues:{
615 case QAbstractAxis::AxisTypeValues:{
616 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
616 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
617 QVERIFY(vaxis!=0);
617 QVERIFY(vaxis!=0);
618 qreal min = vaxis->min();
618 qreal min = vaxis->min();
619 qreal max = vaxis->max();
619 qreal max = vaxis->max();
620 m_chart->scroll(0, -50);
620 m_chart->scroll(0, -50);
621 QVERIFY(min>vaxis->min());
621 QVERIFY(min>vaxis->min());
622 QVERIFY(max>vaxis->max());
622 QVERIFY(max>vaxis->max());
623 break;
623 break;
624 }
624 }
625 case QAbstractAxis::AxisTypeCategories:{
625 case QAbstractAxis::AxisTypeCategories:{
626 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
626 QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis);
627 QVERIFY(caxis!=0);
627 QVERIFY(caxis!=0);
628 qreal min = caxis->min().toDouble();
628 qreal min = caxis->min().toDouble();
629 qreal max = caxis->max().toDouble();
629 qreal max = caxis->max().toDouble();
630 m_chart->scroll(0, -50);
630 m_chart->scroll(0, -50);
631 QVERIFY(min>caxis->min().toDouble());
631 QVERIFY(min>caxis->min().toDouble());
632 QVERIFY(max>caxis->max().toDouble());
632 QVERIFY(max>caxis->max().toDouble());
633 break;
633 break;
634 }
634 }
635 default:
635 default:
636 qFatal("Unsupported type");
636 qFatal("Unsupported type");
637 break;
637 break;
638 }
638 }
639 }
639 }
640
640
641 void tst_QChart::theme_data()
641 void tst_QChart::theme_data()
642 {
642 {
643 QTest::addColumn<QChart::ChartTheme>("theme");
643 QTest::addColumn<QChart::ChartTheme>("theme");
644 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
644 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
645 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
645 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
646 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
646 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
647 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
647 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
648 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
648 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
649 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
649 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
650 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
650 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
651 }
651 }
652
652
653 void tst_QChart::theme()
653 void tst_QChart::theme()
654 {
654 {
655 QFETCH(QChart::ChartTheme, theme);
655 QFETCH(QChart::ChartTheme, theme);
656 createTestData();
656 createTestData();
657 m_chart->setTheme(theme);
657 m_chart->setTheme(theme);
658 QVERIFY(m_chart->theme()==theme);
658 QVERIFY(m_chart->theme()==theme);
659 }
659 }
660
660
661 void tst_QChart::title_data()
661 void tst_QChart::title_data()
662 {
662 {
663 QTest::addColumn<QString>("title");
663 QTest::addColumn<QString>("title");
664 QTest::newRow("null") << QString();
664 QTest::newRow("null") << QString();
665 QTest::newRow("foo") << QString("foo");
665 QTest::newRow("foo") << QString("foo");
666 }
666 }
667
667
668 void tst_QChart::title()
668 void tst_QChart::title()
669 {
669 {
670 QFETCH(QString, title);
670 QFETCH(QString, title);
671 m_chart->setTitle(title);
671 m_chart->setTitle(title);
672 QCOMPARE(m_chart->title(), title);
672 QCOMPARE(m_chart->title(), title);
673 }
673 }
674
674
675 void tst_QChart::titleBrush_data()
675 void tst_QChart::titleBrush_data()
676 {
676 {
677 QTest::addColumn<QBrush>("titleBrush");
677 QTest::addColumn<QBrush>("titleBrush");
678 QTest::newRow("null") << QBrush();
678 QTest::newRow("null") << QBrush();
679 QTest::newRow("blue") << QBrush(Qt::blue);
679 QTest::newRow("blue") << QBrush(Qt::blue);
680 QTest::newRow("white") << QBrush(Qt::white);
680 QTest::newRow("white") << QBrush(Qt::white);
681 QTest::newRow("black") << QBrush(Qt::black);
681 QTest::newRow("black") << QBrush(Qt::black);
682 }
682 }
683
683
684 void tst_QChart::titleBrush()
684 void tst_QChart::titleBrush()
685 {
685 {
686 QFETCH(QBrush, titleBrush);
686 QFETCH(QBrush, titleBrush);
687 m_chart->setTitleBrush(titleBrush);
687 m_chart->setTitleBrush(titleBrush);
688 QCOMPARE(m_chart->titleBrush(), titleBrush);
688 QCOMPARE(m_chart->titleBrush(), titleBrush);
689 }
689 }
690
690
691 void tst_QChart::titleFont_data()
691 void tst_QChart::titleFont_data()
692 {
692 {
693 QTest::addColumn<QFont>("titleFont");
693 QTest::addColumn<QFont>("titleFont");
694 QTest::newRow("null") << QFont();
694 QTest::newRow("null") << QFont();
695 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
695 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
696 }
696 }
697
697
698 void tst_QChart::titleFont()
698 void tst_QChart::titleFont()
699 {
699 {
700 QFETCH(QFont, titleFont);
700 QFETCH(QFont, titleFont);
701 m_chart->setTitleFont(titleFont);
701 m_chart->setTitleFont(titleFont);
702 QCOMPARE(m_chart->titleFont(), titleFont);
702 QCOMPARE(m_chart->titleFont(), titleFont);
703 }
703 }
704
704
705 void tst_QChart::zoomIn_data()
705 void tst_QChart::zoomIn_data()
706 {
706 {
707 QTest::addColumn<QRectF>("rect");
707 QTest::addColumn<QRectF>("rect");
708 QTest::newRow("null") << QRectF();
708 QTest::newRow("null") << QRectF();
709 QTest::newRow("100x100") << QRectF(10,10,100,100);
709 QTest::newRow("100x100") << QRectF(10,10,100,100);
710 QTest::newRow("200x200") << QRectF(10,10,200,200);
710 QTest::newRow("200x200") << QRectF(10,10,200,200);
711 }
711 }
712
712
713
713
714 void tst_QChart::zoomIn()
714 void tst_QChart::zoomIn()
715 {
715 {
716
716
717 QFETCH(QRectF, rect);
717 QFETCH(QRectF, rect);
718 createTestData();
718 createTestData();
719 m_chart->createDefaultAxes();
719 m_chart->createDefaultAxes();
720 QRectF marigns = m_chart->margins();
720 QRectF marigns = m_chart->margins();
721 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
721 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
722 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
722 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
723 QVERIFY(axisX!=0);
723 QVERIFY(axisX!=0);
724 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
724 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
725 QVERIFY(axisY!=0);
725 QVERIFY(axisY!=0);
726 qreal minX = axisX->min();
726 qreal minX = axisX->min();
727 qreal minY = axisY->min();
727 qreal minY = axisY->min();
728 qreal maxX = axisX->max();
728 qreal maxX = axisX->max();
729 qreal maxY = axisY->max();
729 qreal maxY = axisY->max();
730 m_chart->zoomIn(rect);
730 m_chart->zoomIn(rect);
731 if(rect.isValid()){
731 if(rect.isValid()){
732 QVERIFY(minX<axisX->min());
732 QVERIFY(minX<axisX->min());
733 QVERIFY(maxX>axisX->max());
733 QVERIFY(maxX>axisX->max());
734 QVERIFY(minY<axisY->min());
734 QVERIFY(minY<axisY->min());
735 QVERIFY(maxY>axisY->max());
735 QVERIFY(maxY>axisY->max());
736 }
736 }
737
737
738 }
738 }
739
739
740 void tst_QChart::zoomOut_data()
740 void tst_QChart::zoomOut_data()
741 {
741 {
742
742
743 }
743 }
744
744
745 void tst_QChart::zoomOut()
745 void tst_QChart::zoomOut()
746 {
746 {
747 createTestData();
747 createTestData();
748 m_chart->createDefaultAxes();
748 m_chart->createDefaultAxes();
749
749
750 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
750 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
751 QVERIFY(axisX!=0);
751 QVERIFY(axisX!=0);
752 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
752 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
753 QVERIFY(axisY!=0);
753 QVERIFY(axisY!=0);
754
754
755 qreal minX = axisX->min();
755 qreal minX = axisX->min();
756 qreal minY = axisY->min();
756 qreal minY = axisY->min();
757 qreal maxX = axisX->max();
757 qreal maxX = axisX->max();
758 qreal maxY = axisY->max();
758 qreal maxY = axisY->max();
759
759
760 m_chart->zoomIn();
760 m_chart->zoomIn();
761
761
762 QVERIFY(minX < axisX->min());
762 QVERIFY(minX < axisX->min());
763 QVERIFY(maxX > axisX->max());
763 QVERIFY(maxX > axisX->max());
764 QVERIFY(minY < axisY->min());
764 QVERIFY(minY < axisY->min());
765 QVERIFY(maxY > axisY->max());
765 QVERIFY(maxY > axisY->max());
766
766
767 m_chart->zoomOut();
767 m_chart->zoomOut();
768
768
769 // min x may be a zero value
769 // min x may be a zero value
770 if (qFuzzyIsNull(minX))
770 if (qFuzzyIsNull(minX))
771 QVERIFY(qFuzzyIsNull(axisX->min()));
771 QVERIFY(qFuzzyIsNull(axisX->min()));
772 else
772 else
773 QCOMPARE(minX, axisX->min());
773 QCOMPARE(minX, axisX->min());
774
774
775 // min y may be a zero value
775 // min y may be a zero value
776 if (qFuzzyIsNull(minY))
776 if (qFuzzyIsNull(minY))
777 QVERIFY(qFuzzyIsNull(axisY->min()));
777 QVERIFY(qFuzzyIsNull(axisY->min()));
778 else
778 else
779 QCOMPARE(minY, axisY->min());
779 QCOMPARE(minY, axisY->min());
780
780
781 QVERIFY(maxX == axisX->max());
781 QVERIFY(maxX == axisX->max());
782 QVERIFY(maxY == axisY->max());
782 QVERIFY(maxY == axisY->max());
783
783
784 }
784 }
785
785
786 QTEST_MAIN(tst_QChart)
786 QTEST_MAIN(tst_QChart)
787 #include "tst_qchart.moc"
787 #include "tst_qchart.moc"
788
788
General Comments 0
You need to be logged in to leave comments. Login now