##// END OF EJS Templates
renamed QValueAxis related files
Marek Rosa -
r1805:3a0e948c9274
parent child
Show More
@@ -1,101 +1,101
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 22 #include <QtDeclarative/qdeclarative.h>
23 23 #include "qchart.h"
24 24 #include "qabstractaxis.h"
25 #include "qvaluesaxis.h"
25 #include "qvalueaxis.h"
26 26 #include "qbarcategoriesaxis.h"
27 27 #include "declarativechart.h"
28 28 #include "declarativexypoint.h"
29 29 #include "declarativelineseries.h"
30 30 #include "declarativesplineseries.h"
31 31 #include "declarativeareaseries.h"
32 32 #include "declarativescatterseries.h"
33 33 #include "declarativebarseries.h"
34 34 #include "declarativepieseries.h"
35 35 #include "qvxymodelmapper.h"
36 36 #include "qhxymodelmapper.h"
37 37 #include "qhpiemodelmapper.h"
38 38 #include "qvpiemodelmapper.h"
39 39 #include "qhbarmodelmapper.h"
40 40 #include "qvbarmodelmapper.h"
41 41 #include <QAbstractItemModel>
42 42
43 43 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44 44
45 45 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
46 46 {
47 47 Q_OBJECT
48 48 public:
49 49 virtual void registerTypes(const char *uri)
50 50 {
51 51 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
52 52
53 53 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
54 54 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
55 55 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
56 56 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
57 57 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
58 58 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
59 59 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
60 60 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
61 61 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
62 62 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
63 63 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
64 64 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
65 65 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
66 66 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
67 67 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
68 68 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
69 69 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
70 70 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
71 71 qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis");
72 72 qmlRegisterType<QBarCategoriesAxis>(uri, 1, 0, "BarCategoriesAxis");
73 73
74 74 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
75 75 QLatin1String("Trying to create uncreatable: Legend."));
76 76 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
77 77 QLatin1String("Trying to create uncreatable: XYSeries."));
78 78 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
79 79 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
80 80 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
81 81 QLatin1String("Trying to create uncreatable: XYModelMapper."));
82 82 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
83 83 QLatin1String("Trying to create uncreatable: PieModelMapper."));
84 84 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
85 85 QLatin1String("Trying to create uncreatable: BarModelMapper."));
86 86 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
87 87 QLatin1String("Trying to create uncreatable: AbstractSeries."));
88 88 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
89 89 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
90 90 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
91 91 QLatin1String("Trying to create uncreatable: AbstractAxis."));
92 92 }
93 93 };
94 94
95 95 #include "plugin.moc"
96 96
97 97 QTCOMMERCIALCHART_END_NAMESPACE
98 98
99 99 QTCOMMERCIALCHART_USE_NAMESPACE
100 100
101 101 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,396 +1,396
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qareaseries.h"
22 22 #include "qareaseries_p.h"
23 23 #include "qlineseries.h"
24 24 #include "areachartitem_p.h"
25 25 #include "legendmarker_p.h"
26 26 #include "domain_p.h"
27 27 #include "chartdataset_p.h"
28 28 #include "charttheme_p.h"
29 #include "qvaluesaxis.h"
29 #include "qvalueaxis.h"
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \class QAreaSeries
35 35 \brief The QAreaSeries class is used for making area charts.
36 36
37 37 \mainclass
38 38
39 39 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
40 40 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
41 41 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
42 42 In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases
43 43 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
44 44
45 45 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
46 46 \image examples_areachart.png
47 47 */
48 48 /*!
49 49 \qmlclass AreaSeries QAreaSeries
50 50
51 51 The following QML shows how to create a simple area chart:
52 52 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
53 53 \beginfloatleft
54 54 \image demos_qmlchart4.png
55 55 \endfloat
56 56 \clearfloat
57 57 */
58 58
59 59 /*!
60 60 \property QAreaSeries::upperSeries
61 61 \brief The upper one of the two line series used to define area series boundaries.
62 62 */
63 63 /*!
64 64 \qmlproperty LineSeries AreaSeries::upperSeries
65 65 The upper one of the two line series used to define area series boundaries.
66 66 */
67 67
68 68 /*!
69 69 \property QAreaSeries::lowerSeries
70 70 The lower one of the two line series used to define are series boundaries. Note if
71 71 QAreaSeries was counstucted wihtout a\ lowerSeries this is null.
72 72 */
73 73 /*!
74 74 \qmlproperty LineSeries AreaSeries::lowerSeries
75 75 The lower one of the two line series used to define are series boundaries. Note if
76 76 AreaSeries was counstucted wihtout a\ lowerSeries this is null.
77 77 */
78 78
79 79 /*!
80 80 \property QAreaSeries::color
81 81 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
82 82 \sa QAreaSeries::brush()
83 83 */
84 84 /*!
85 85 \qmlproperty color AreaSeries::color
86 86 Fill (brush) color of the series.
87 87 */
88 88
89 89 /*!
90 90 \property QAreaSeries::borderColor
91 91 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
92 92 \sa QAreaSeries::pen()
93 93 */
94 94 /*!
95 95 \qmlproperty color AreaSeries::borderColor
96 96 Line (pen) color of the series.
97 97 */
98 98
99 99 /*!
100 100 \fn QPen QAreaSeries::pen() const
101 101 \brief Returns the pen used to draw line for this series.
102 102 \sa setPen()
103 103 */
104 104
105 105 /*!
106 106 \fn QPen QAreaSeries::brush() const
107 107 \brief Returns the brush used to draw line for this series.
108 108 \sa setBrush()
109 109 */
110 110
111 111 /*!
112 112 \fn void QAreaSeries::colorChanged(QColor color)
113 113 \brief Signal is emitted when the fill (brush) color has changed to \a color.
114 114 */
115 115 /*!
116 116 \qmlsignal AreaSeries::onColorChanged(color color)
117 117 Signal is emitted when the fill (brush) color has changed to \a color.
118 118 */
119 119
120 120 /*!
121 121 \fn void QAreaSeries::borderColorChanged(QColor color)
122 122 \brief Signal is emitted when the line (pen) color has changed to \a color.
123 123 */
124 124 /*!
125 125 \qmlsignal AreaSeries::onBorderColorChanged(color color)
126 126 Signal is emitted when the line (pen) color has changed to \a color.
127 127 */
128 128
129 129 /*!
130 130 \fn void QAreaSeries::clicked(const QPointF& point)
131 131 \brief Signal is emitted when user clicks the \a point on area chart.
132 132 */
133 133 /*!
134 134 \qmlsignal AreaSeries::onClicked(QPointF point)
135 135 Signal is emitted when user clicks the \a point on area chart.
136 136 */
137 137
138 138 /*!
139 139 \fn void QAreaSeries::selected()
140 140 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
141 141 implemented by the user of QAreaSeries API.
142 142 */
143 143 /*!
144 144 \qmlsignal AreaSeries::onSelected()
145 145 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
146 146 implemented by the user of AreaSeries API.
147 147 */
148 148
149 149 /*!
150 150 \fn void QAreaSeriesPrivate::updated()
151 151 \brief \internal
152 152 */
153 153
154 154 /*!
155 155 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
156 156 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
157 157 When series object is added to QChartView or QChart instance ownerships is transferred.
158 158 */
159 159 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
160 160 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
161 161 {
162 162 }
163 163
164 164 /*!
165 165 Constructs area series object without upper or lower series with \a parent object.
166 166 */
167 167 QAreaSeries::QAreaSeries(QObject *parent)
168 168 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
169 169 {
170 170 }
171 171
172 172 /*!
173 173 Destroys the object.
174 174 */
175 175 QAreaSeries::~QAreaSeries()
176 176 {
177 177 Q_D(QAreaSeries);
178 178 if(d->m_dataset){
179 179 d->m_dataset->removeSeries(this);
180 180 }
181 181 }
182 182
183 183 /*!
184 184 Returns QChartSeries::SeriesTypeArea.
185 185 */
186 186 QAbstractSeries::SeriesType QAreaSeries::type() const
187 187 {
188 188 return QAbstractSeries::SeriesTypeArea;
189 189 }
190 190
191 191 /*!
192 192 Sets the \a series that is to be used as the area chart upper series.
193 193 */
194 194 void QAreaSeries::setUpperSeries(QLineSeries* series)
195 195 {
196 196 Q_D(QAreaSeries);
197 197 d->m_upperSeries = series;
198 198 }
199 199
200 200 QLineSeries* QAreaSeries::upperSeries() const
201 201 {
202 202 Q_D(const QAreaSeries);
203 203 return d->m_upperSeries;
204 204 }
205 205
206 206 /*!
207 207 Sets the \a series that is to be used as the area chart lower series.
208 208 */
209 209 void QAreaSeries::setLowerSeries(QLineSeries* series)
210 210 {
211 211 Q_D(QAreaSeries);
212 212 d->m_lowerSeries = series;
213 213 }
214 214
215 215 QLineSeries* QAreaSeries::lowerSeries() const
216 216 {
217 217 Q_D(const QAreaSeries);
218 218 return d->m_lowerSeries;
219 219 }
220 220
221 221 /*!
222 222 Sets \a pen used for drawing area outline.
223 223 */
224 224 void QAreaSeries::setPen(const QPen &pen)
225 225 {
226 226 Q_D(QAreaSeries);
227 227 if (d->m_pen != pen) {
228 228 d->m_pen = pen;
229 229 emit d->updated();
230 230 }
231 231 }
232 232
233 233 QPen QAreaSeries::pen() const
234 234 {
235 235 Q_D(const QAreaSeries);
236 236 return d->m_pen;
237 237 }
238 238
239 239 /*!
240 240 Sets \a brush used for filling the area.
241 241 */
242 242 void QAreaSeries::setBrush(const QBrush &brush)
243 243 {
244 244 Q_D(QAreaSeries);
245 245 if (d->m_brush != brush) {
246 246 d->m_brush = brush;
247 247 emit d->updated();
248 248 }
249 249 }
250 250
251 251 QBrush QAreaSeries::brush() const
252 252 {
253 253 Q_D(const QAreaSeries);
254 254 return d->m_brush;
255 255 }
256 256
257 257 void QAreaSeries::setColor(const QColor &color)
258 258 {
259 259 QBrush b = brush();
260 260 if (b.color() != color) {
261 261 b.setColor(color);
262 262 setBrush(b);
263 263 emit colorChanged(color);
264 264 }
265 265 }
266 266
267 267 QColor QAreaSeries::color() const
268 268 {
269 269 return brush().color();
270 270 }
271 271
272 272 void QAreaSeries::setBorderColor(const QColor &color)
273 273 {
274 274 QPen p = pen();
275 275 if (p.color() != color) {
276 276 p.setColor(color);
277 277 setPen(p);
278 278 emit borderColorChanged(color);
279 279 }
280 280 }
281 281
282 282 QColor QAreaSeries::borderColor() const
283 283 {
284 284 return pen().color();
285 285 }
286 286
287 287 /*!
288 288 Sets if data points are \a visible and should be drawn on line.
289 289 */
290 290 void QAreaSeries::setPointsVisible(bool visible)
291 291 {
292 292 Q_D(QAreaSeries);
293 293 if (d->m_pointsVisible != visible) {
294 294 d->m_pointsVisible = visible;
295 295 emit d->updated();
296 296 }
297 297 }
298 298
299 299 /*!
300 300 Returns if the points are drawn for this series.
301 301 \sa setPointsVisible()
302 302 */
303 303 bool QAreaSeries::pointsVisible() const
304 304 {
305 305 Q_D(const QAreaSeries);
306 306 return d->m_pointsVisible;
307 307 }
308 308
309 309 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
310 310
311 311 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
312 312 QAbstractSeriesPrivate(q),
313 313 m_upperSeries(upperSeries),
314 314 m_lowerSeries(lowerSeries),
315 315 m_pointsVisible(false)
316 316 {
317 317 }
318 318
319 319 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
320 320 {
321 321 Q_Q(QAreaSeries);
322 322
323 323 qreal minX(domain.minX());
324 324 qreal minY(domain.minY());
325 325 qreal maxX(domain.maxX());
326 326 qreal maxY(domain.maxY());
327 327
328 328 QLineSeries* upperSeries = q->upperSeries();
329 329 QLineSeries* lowerSeries = q->lowerSeries();
330 330
331 331 const QList<QPointF>& points = upperSeries->points();
332 332
333 333 for (int i = 0; i < points.count(); i++)
334 334 {
335 335 qreal x = points[i].x();
336 336 qreal y = points[i].y();
337 337 minX = qMin(minX, x);
338 338 minY = qMin(minY, y);
339 339 maxX = qMax(maxX, x);
340 340 maxY = qMax(maxY, y);
341 341 }
342 342 if(lowerSeries) {
343 343
344 344 const QList<QPointF>& points = lowerSeries->points();
345 345
346 346 for (int i = 0; i < points.count(); i++)
347 347 {
348 348 qreal x = points[i].x();
349 349 qreal y = points[i].y();
350 350 minX = qMin(minX, x);
351 351 minY = qMin(minY, y);
352 352 maxX = qMax(maxX, x);
353 353 maxY = qMax(maxY, y);
354 354 }}
355 355
356 356 domain.setRange(minX,maxX,minY,maxY);
357 357 }
358 358
359 359 ChartElement* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
360 360 {
361 361 Q_Q(QAreaSeries);
362 362
363 363 AreaChartItem* area = new AreaChartItem(q,presenter);
364 364 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
365 365 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
366 366 if(q->lowerSeries()) {
367 367 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
368 368 }
369 369 }
370 370 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
371 371 return area;
372 372 }
373 373
374 374 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
375 375 {
376 376 Q_Q(QAreaSeries);
377 377 QList<LegendMarker*> list;
378 378 return list << new AreaLegendMarker(q,legend);
379 379 }
380 380
381 381
382 382 void QAreaSeriesPrivate::initializeAxis(QAbstractAxis* axis)
383 383 {
384 384 Q_UNUSED(axis);
385 385 }
386 386
387 387 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
388 388 {
389 389 Q_UNUSED(orientation);
390 390 return QAbstractAxis::AxisTypeValues;
391 391 }
392 392
393 393 #include "moc_qareaseries.cpp"
394 394 #include "moc_qareaseries_p.cpp"
395 395
396 396 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,52
1 1 #Subdirectiores are defined here, because qt creator doesn't handle nested include(foo.pri) chains very well.
2 2
3 3 INCLUDEPATH += $$PWD \
4 $$PWD/valuesaxis \
4 $$PWD/valueaxis \
5 5 $$PWD/categoriesaxis \
6 6 $$PWD/intervalsaxis \
7 7 $$PWD/datetimeaxis
8 8
9 9 DEPENDPATH += $$PWD \
10 $$PWD/valuesaxis \
10 $$PWD/valueaxis \
11 11 $$PWD/categoriesaxis \
12 12 $$PWD/intervalsaxis \
13 13 $$PWD/datetimeaxis
14 14
15 15 SOURCES += \
16 16 $$PWD/chartaxis.cpp \
17 17 $$PWD/qabstractaxis.cpp \
18 $$PWD/valuesaxis/chartvaluesaxisx.cpp \
19 $$PWD/valuesaxis/chartvaluesaxisy.cpp \
20 $$PWD/valuesaxis/qvaluesaxis.cpp \
18 $$PWD/valueaxis/chartvalueaxisx.cpp \
19 $$PWD/valueaxis/chartvalueaxisy.cpp \
20 $$PWD/valueaxis/qvalueaxis.cpp \
21 21 $$PWD/categoriesaxis/chartcategoriesaxisx.cpp \
22 22 $$PWD/categoriesaxis/chartcategoriesaxisy.cpp \
23 23 $$PWD/categoriesaxis/qbarcategoriesaxis.cpp \
24 24 $$PWD/intervalsaxis/chartintervalsaxisx.cpp \
25 25 $$PWD/intervalsaxis/chartintervalsaxisy.cpp \
26 26 $$PWD/intervalsaxis/qintervalsaxis.cpp \
27 27 $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \
28 28 $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \
29 29 $$PWD/datetimeaxis/qdatetimeaxis.cpp
30 30
31 31 PRIVATE_HEADERS += \
32 32 $$PWD/chartaxis_p.h \
33 33 $$PWD/qabstractaxis_p.h \
34 $$PWD/valuesaxis/chartvaluesaxisx_p.h \
35 $$PWD/valuesaxis/chartvaluesaxisy_p.h \
36 $$PWD/valuesaxis/qvaluesaxis_p.h \
34 $$PWD/valueaxis/chartvalueaxisx_p.h \
35 $$PWD/valueaxis/chartvalueaxisy_p.h \
36 $$PWD/valueaxis/qvalueaxis_p.h \
37 37 $$PWD/categoriesaxis/chartcategoriesaxisx_p.h \
38 38 $$PWD/categoriesaxis/chartcategoriesaxisy_p.h \
39 39 $$PWD/categoriesaxis/qbarcategoriesaxis_p.h \
40 40 $$PWD/intervalsaxis/chartintervalsaxisx_p.h \
41 41 $$PWD/intervalsaxis/chartintervalsaxisy_p.h \
42 42 $$PWD/intervalsaxis/qintervalsaxis_p.h \
43 43 $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \
44 44 $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \
45 45 $$PWD/datetimeaxis/qdatetimeaxis_p.h
46 46
47 47 PUBLIC_HEADERS += \
48 48 $$PWD/qabstractaxis.h \
49 $$PWD/valuesaxis/qvaluesaxis.h \
49 $$PWD/valueaxis/qvalueaxis.h \
50 50 $$PWD/categoriesaxis/qbarcategoriesaxis.h \
51 51 $$PWD/intervalsaxis/qintervalsaxis.h \
52 52 $$PWD/datetimeaxis/qdatetimeaxis.h
@@ -1,65 +1,65
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QCATEGORIESAXIS_H
22 22 #define QCATEGORIESAXIS_H
23 23
24 24 #include "qabstractaxis.h"
25 #include "qvaluesaxis.h"
25 #include "qvalueaxis.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 class QIntervalsAxisPrivate;
30 30
31 31 class QTCOMMERCIALCHART_EXPORT QIntervalsAxis : public QValueAxis
32 32 {
33 33 Q_OBJECT
34 34
35 35 public:
36 36 explicit QIntervalsAxis(QObject *parent = 0);
37 37 ~QIntervalsAxis();
38 38
39 39 protected:
40 40 QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent = 0);
41 41
42 42 public:
43 43 AxisType type() const;
44 44
45 45 void append(const QString& label, qreal intervalEnd);
46 46 void remove(const QString& label);
47 47 void replaceLabel(const QString& oldLabel, const QString& newLabel);
48 48
49 49 void setFisrtIntervalMinimum(qreal min);
50 50
51 51 qreal intervalMin(const QString& intervalLabel) const;
52 52 qreal intervalMax(const QString& intervalLabel) const;
53 53
54 54 QStringList intervalsLabels();
55 55 int count() const;
56 56
57 57
58 58 private:
59 59 Q_DECLARE_PRIVATE(QIntervalsAxis)
60 60 Q_DISABLE_COPY(QIntervalsAxis)
61 61 };
62 62
63 63 QTCOMMERCIALCHART_END_NAMESPACE
64 64
65 65 #endif // QCATEGORIESAXIS_H
@@ -1,70 +1,70
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QIntervalsAxis_P_H
31 31 #define QIntervalsAxis_P_H
32 32
33 33 #include "qintervalsaxis.h"
34 #include "qvaluesaxis_p.h"
34 #include "qvalueaxis_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 typedef QPair<qreal, qreal> Range;
39 39
40 40 class QIntervalsAxisPrivate : public QValueAxisPrivate
41 41 {
42 42 Q_OBJECT
43 43
44 44 public:
45 45 QIntervalsAxisPrivate(QIntervalsAxis *q);
46 46 ~QIntervalsAxisPrivate();
47 47
48 48
49 49 public:
50 50 ChartAxis* createGraphics(ChartPresenter* presenter);
51 51 int ticksCount() const;
52 52
53 53 Q_SIGNALS:
54 54 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
55 55
56 56 public Q_SLOTS:
57 57 void handleAxisRangeChanged(qreal min, qreal max,int count);
58 58
59 59 private:
60 60 QMap<QString , Range> m_intervalsMap;
61 61 QStringList m_intervals;
62 62 qreal m_categoryMinimum;
63 63
64 64 private:
65 65 Q_DECLARE_PUBLIC(QIntervalsAxis)
66 66 };
67 67
68 68 QTCOMMERCIALCHART_END_NAMESPACE
69 69
70 70 #endif // QCATEGORIESAXIS_P_H
@@ -1,120 +1,120
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 #include "chartvaluesaxisx_p.h"
21 #include "chartvalueaxisx_p.h"
22 22 #include "qabstractaxis.h"
23 23 #include "chartpresenter_p.h"
24 #include "qvaluesaxis.h"
24 #include "qvalueaxis.h"
25 25 #include <QGraphicsLayout>
26 26 #include <QFontMetrics>
27 27 #include <qmath.h>
28 28
29 29 static int label_padding = 5;
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 ChartValuesAxisX::ChartValuesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
33 ChartValueAxisX::ChartValueAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
34 34 m_tickCount(0)
35 35 {
36 36 }
37 37
38 ChartValuesAxisX::~ChartValuesAxisX()
38 ChartValueAxisX::~ChartValueAxisX()
39 39 {
40 40 }
41 41
42 QVector<qreal> ChartValuesAxisX::calculateLayout() const
42 QVector<qreal> ChartValueAxisX::calculateLayout() const
43 43 {
44 44 Q_ASSERT(m_tickCount>=2);
45 45
46 46 QVector<qreal> points;
47 47 points.resize(m_tickCount);
48 48
49 49 const qreal deltaX = m_rect.width()/(m_tickCount-1);
50 50 for (int i = 0; i < m_tickCount; ++i) {
51 51 int x = i * deltaX + m_rect.left();
52 52 points[i] = x;
53 53 }
54 54 return points;
55 55 }
56 56
57 void ChartValuesAxisX::updateGeometry()
57 void ChartValueAxisX::updateGeometry()
58 58 {
59 59 const QVector<qreal>& layout = ChartAxis::layout();
60 60
61 61 m_minWidth = 0;
62 62 m_minHeight = 0;
63 63
64 64 if(layout.isEmpty()) return;
65 65
66 66 QStringList ticksList;
67 67
68 68 createNumberLabels(ticksList,m_min,m_max,layout.size());
69 69
70 70 QList<QGraphicsItem *> lines = m_grid->childItems();
71 71 QList<QGraphicsItem *> labels = m_labels->childItems();
72 72 QList<QGraphicsItem *> shades = m_shades->childItems();
73 73 QList<QGraphicsItem *> axis = m_arrow->childItems();
74 74
75 75 Q_ASSERT(labels.size() == ticksList.size());
76 76 Q_ASSERT(layout.size() == ticksList.size());
77 77
78 78 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
79 79 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
80 80
81 81 qreal width = 0;
82 82 for (int i = 0; i < layout.size(); ++i) {
83 83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
84 84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
85 85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
86 86 labelItem->setText(ticksList.at(i));
87 87 const QRectF& rect = labelItem->boundingRect();
88 88 QPointF center = rect.center();
89 89 labelItem->setTransformOriginPoint(center.x(), center.y());
90 90 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
91 91
92 92 if(labelItem->pos().x()<=width){
93 93 labelItem->setVisible(false);
94 94 lineItem->setVisible(false);
95 95 }else{
96 96 labelItem->setVisible(true);
97 97 lineItem->setVisible(true);
98 98 width=rect.width()+labelItem->pos().x();
99 99 }
100 100 m_minWidth+=rect.width();
101 101 m_minHeight=qMax(rect.height(),m_minHeight);
102 102
103 103 if ((i+1)%2 && i>1) {
104 104 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
105 105 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
106 106 }
107 107 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
108 108 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
109 109 }
110 110 }
111 111
112 void ChartValuesAxisX::handleAxisUpdated()
112 void ChartValueAxisX::handleAxisUpdated()
113 113 {
114 114 //TODO:: fix this
115 115 QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis);
116 116 m_tickCount = axis->ticksCount();
117 117 ChartAxis::handleAxisUpdated();
118 118 }
119 119
120 120 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,60 +1,60
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTVALUESAXISX_H
31 31 #define CHARTVALUESAXISX_H
32 32
33 33 #include "chartaxis_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QAbstractAxis;
38 38 class ChartPresenter;
39 39
40 class ChartValuesAxisX : public ChartAxis
40 class ChartValueAxisX : public ChartAxis
41 41 {
42 42 public:
43 ChartValuesAxisX(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartValuesAxisX();
43 ChartValueAxisX(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartValueAxisX();
45 45
46 46 AxisType axisType() const { return X_AXIS;}
47 47
48 48 protected:
49 49 void handleAxisUpdated();
50 50 QVector<qreal> calculateLayout() const;
51 51 void updateGeometry();
52 52
53 53 private:
54 54 int m_tickCount;
55 55
56 56 };
57 57
58 58 QTCOMMERCIALCHART_END_NAMESPACE
59 59
60 60 #endif /* CHARTVALUESAXISX_H */
@@ -1,126 +1,126
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 #include "chartvaluesaxisy_p.h"
21 #include "chartvalueaxisy_p.h"
22 22 #include "qabstractaxis.h"
23 23 #include "chartpresenter_p.h"
24 #include "qvaluesaxis.h"
24 #include "qvalueaxis.h"
25 25 #include <QGraphicsLayout>
26 26 #include <QFontMetrics>
27 27 #include <qmath.h>
28 28
29 29 static int label_padding = 5;
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 ChartValuesAxisY::ChartValuesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
33 ChartValueAxisY::ChartValueAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
34 34 m_tickCount(0)
35 35 {
36 36 }
37 37
38 ChartValuesAxisY::~ChartValuesAxisY()
38 ChartValueAxisY::~ChartValueAxisY()
39 39 {
40 40 }
41 41
42 QVector<qreal> ChartValuesAxisY::calculateLayout() const
42 QVector<qreal> ChartValueAxisY::calculateLayout() const
43 43 {
44 44 Q_ASSERT(m_tickCount>=2);
45 45
46 46 QVector<qreal> points;
47 47 points.resize(m_tickCount);
48 48
49 49 const qreal deltaY = m_rect.height()/(m_tickCount-1);
50 50 for (int i = 0; i < m_tickCount; ++i) {
51 51 int y = i * -deltaY + m_rect.bottom();
52 52 points[i] = y;
53 53 }
54 54
55 55 return points;
56 56 }
57 57
58 void ChartValuesAxisY::updateGeometry()
58 void ChartValueAxisY::updateGeometry()
59 59 {
60 60 const QVector<qreal> &layout = ChartAxis::layout();
61 61 m_minWidth = 0;
62 62 m_minHeight = 0;
63 63
64 64 if(layout.isEmpty()) return;
65 65
66 66 QStringList ticksList;
67 67
68 68 createNumberLabels(ticksList,m_min,m_max,layout.size());
69 69
70 70 QList<QGraphicsItem *> lines = m_grid->childItems();
71 71 QList<QGraphicsItem *> labels = m_labels->childItems();
72 72 QList<QGraphicsItem *> shades = m_shades->childItems();
73 73 QList<QGraphicsItem *> axis = m_arrow->childItems();
74 74
75 75 Q_ASSERT(labels.size() == ticksList.size());
76 76 Q_ASSERT(layout.size() == ticksList.size());
77 77
78 78 qreal height = 2*m_rect.bottom();
79 79
80 80 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
81 81 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
82 82
83 83 for (int i = 0; i < layout.size(); ++i) {
84 84 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
85 85 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
86 86 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
87 87
88 88 labelItem->setText(ticksList.at(i));
89 89 const QRectF& rect = labelItem->boundingRect();
90 90
91 91 QPointF center = rect.center();
92 92 labelItem->setTransformOriginPoint(center.x(), center.y());
93 93 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
94 94
95 95 if(labelItem->pos().y()+rect.height()>height) {
96 96 labelItem->setVisible(false);
97 97 lineItem->setVisible(false);
98 98 }
99 99 else {
100 100 labelItem->setVisible(true);
101 101 lineItem->setVisible(true);
102 102 height=labelItem->pos().y();
103 103 }
104 104
105 105 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
106 106 m_minHeight+=rect.height();
107 107
108 108 if ((i+1)%2 && i>1) {
109 109 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
110 110 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
111 111 }
112 112 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
113 113 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
114 114 }
115 115 }
116 116
117 void ChartValuesAxisY::handleAxisUpdated()
117 void ChartValueAxisY::handleAxisUpdated()
118 118 {
119 119 //TODO:: fix this
120 120 QValueAxis* axis = qobject_cast<QValueAxis*>(m_chartAxis);
121 121 m_tickCount = axis->ticksCount();
122 122 ChartAxis::handleAxisUpdated();
123 123 }
124 124
125 125
126 126 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,58 +1,58
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTVALUESAXISY_H
31 31 #define CHARTVALUESAXISY_H
32 32
33 33 #include "chartaxis_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QAbstractAxis;
38 38 class ChartPresenter;
39 39
40 class ChartValuesAxisY : public ChartAxis
40 class ChartValueAxisY : public ChartAxis
41 41 {
42 42 public:
43 ChartValuesAxisY(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartValuesAxisY();
43 ChartValueAxisY(QAbstractAxis *axis, ChartPresenter *presenter);
44 ~ChartValueAxisY();
45 45
46 46 AxisType axisType() const { return Y_AXIS;}
47 47
48 48 protected:
49 49 QVector<qreal> calculateLayout() const;
50 50 void updateGeometry();
51 51 void handleAxisUpdated();
52 52 private:
53 53 int m_tickCount;
54 54 };
55 55
56 56 QTCOMMERCIALCHART_END_NAMESPACE
57 57
58 58 #endif /* CHARTVALUESAXISY_H */
@@ -1,384 +1,384
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
21 #include "qvalueaxis.h"
22 #include "qvalueaxis_p.h"
23 #include "chartvalueaxisx_p.h"
24 #include "chartvalueaxisy_p.h"
25 25 #include "domain_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include <qmath.h>
28 28
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31 /*!
32 32 \class QValueAxis
33 33 \brief The QValueAxis class is used for manipulating chart's axis.
34 34 \mainclass
35 35
36 36 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
37 37 Values of axis are drawn to position of ticks
38 38 */
39 39
40 40 /*!
41 41 \qmlclass ValuesAxis QValueAxis
42 42 \brief The ValuesAxis element is used for manipulating chart's axes
43 43
44 44 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
45 45 Values of axis are drawn to position of ticks
46 46
47 47 To access Axes you can use ChartView API. For example:
48 48 \code
49 49 ChartView {
50 50 ValuesAxis {
51 51 id: xAxis
52 52 min: 0
53 53 max: 10
54 54 }
55 55 // Add a few series...
56 56 }
57 57 \endcode
58 58 */
59 59
60 60 /*!
61 61 \property QValueAxis::min
62 62 Defines the minimum value on the axis.
63 63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
64 64 */
65 65 /*!
66 66 \qmlproperty real ValuesAxis::min
67 67 Defines the minimum value on the axis.
68 68 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
69 69 */
70 70
71 71 /*!
72 72 \property QValueAxis::max
73 73 Defines the maximum value on the axis.
74 74 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
75 75 */
76 76 /*!
77 77 \qmlproperty real ValuesAxis::max
78 78 Defines the maximum value on the axis.
79 79 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
80 80 */
81 81
82 82 /*!
83 83 \fn void QValueAxis::minChanged(qreal min)
84 84 Axis emits signal when \a min of axis has changed.
85 85 */
86 86 /*!
87 87 \qmlsignal ValuesAxis::onMinChanged(real min)
88 88 Axis emits signal when \a min of axis has changed.
89 89 */
90 90
91 91 /*!
92 92 \fn void QValueAxis::maxChanged(qreal max)
93 93 Axis emits signal when \a max of axis has changed.
94 94 */
95 95 /*!
96 96 \qmlsignal ValuesAxis::onMaxChanged(real max)
97 97 Axis emits signal when \a max of axis has changed.
98 98 */
99 99
100 100 /*!
101 101 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
102 102 Axis emits signal when \a min or \a max of axis has changed.
103 103 */
104 104
105 105 /*!
106 106 \property QValueAxis::ticksCount
107 107 The number of tick marks for the axis.
108 108 */
109 109
110 110 /*!
111 111 \qmlproperty int ValuesAxis::ticksCount
112 112 The number of tick marks for the axis.
113 113 */
114 114
115 115 /*!
116 116 \property QValueAxis::niceNumbersEnabled
117 117 Whether the nice numbers algorithm is enabled or not for the axis.
118 118 */
119 119
120 120 /*!
121 121 \qmlproperty bool ValuesAxis::niceNumbersEnabled
122 122 Whether the nice numbers algorithm is enabled or not for the axis.
123 123 */
124 124
125 125 /*!
126 126 Constructs an axis object which is a child of \a parent.
127 127 */
128 128 QValueAxis::QValueAxis(QObject *parent) :
129 129 QAbstractAxis(*new QValueAxisPrivate(this),parent)
130 130 {
131 131
132 132 }
133 133
134 134 /*!
135 135 \internal
136 136 */
137 137 QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
138 138 {
139 139
140 140 }
141 141
142 142 /*!
143 143 Destroys the object
144 144 */
145 145 QValueAxis::~QValueAxis()
146 146 {
147 147 Q_D(QValueAxis);
148 148 if(d->m_dataset) {
149 149 d->m_dataset->removeAxis(this);
150 150 }
151 151 }
152 152
153 153 void QValueAxis::setMin(qreal min)
154 154 {
155 155 Q_D(QValueAxis);
156 156 setRange(min, qMax(d->m_max, min));
157 157 }
158 158
159 159 qreal QValueAxis::min() const
160 160 {
161 161 Q_D(const QValueAxis);
162 162 return d->m_min;
163 163 }
164 164
165 165 void QValueAxis::setMax(qreal max)
166 166 {
167 167 Q_D(QValueAxis);
168 168 setRange(qMin(d->m_min, max), max);
169 169 }
170 170
171 171 qreal QValueAxis::max() const
172 172 {
173 173 Q_D(const QValueAxis);
174 174 return d->m_max;
175 175 }
176 176
177 177 /*!
178 178 Sets range from \a min to \a max on the axis.
179 179 If min is greater than max then this function returns without making any changes.
180 180 */
181 181 void QValueAxis::setRange(qreal min, qreal max)
182 182 {
183 183 Q_D(QValueAxis);
184 184 bool changed = false;
185 185
186 186 if (min > max) return;
187 187
188 188 if(d->m_niceNumbers) {
189 189 int ticks = d->m_tickCount;
190 190 d->looseNiceNumbers(min, max, ticks);
191 191 if(ticks!=d->m_tickCount) setTicksCount(ticks);
192 192 }
193 193
194 194 if (!qFuzzyIsNull(d->m_min - min)) {
195 195 d->m_min = min;
196 196 changed = true;
197 197 emit minChanged(min);
198 198 }
199 199
200 200 if (!qFuzzyIsNull(d->m_max - max)) {
201 201 d->m_max = max;
202 202 changed = true;
203 203 emit maxChanged(max);
204 204 }
205 205
206 206 if (changed) {
207 207 emit rangeChanged(min,max);
208 208 d->emitUpdated();
209 209 }
210 210 }
211 211
212 212 /*!
213 213 Sets \a count for ticks on the axis.
214 214 */
215 215 void QValueAxis::setTicksCount(int count)
216 216 {
217 217 Q_D(QValueAxis);
218 218 if (d->m_tickCount != count && count >=2) {
219 219 d->m_tickCount = count;
220 220 d->emitUpdated();
221 221 }
222 222 }
223 223
224 224 /*!
225 225 \fn int QValueAxis::ticksCount() const
226 226 Return number of ticks on the axis
227 227 */
228 228 int QValueAxis::ticksCount() const
229 229 {
230 230 Q_D(const QValueAxis);
231 231 return d->m_tickCount;
232 232 }
233 233
234 234 void QValueAxis::setNiceNumbersEnabled(bool enable)
235 235 {
236 236 Q_D(QValueAxis);
237 237 if (d->m_niceNumbers != enable){
238 238 d->m_niceNumbers = enable;
239 239 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) {
240 240 setRange(d->m_min,d->m_max);
241 241 }
242 242 }
243 243 }
244 244
245 245 bool QValueAxis::niceNumbersEnabled() const
246 246 {
247 247 Q_D(const QValueAxis);
248 248 return d->m_niceNumbers;
249 249 }
250 250
251 251 /*!
252 252 Returns the type of the axis
253 253 */
254 254 QAbstractAxis::AxisType QValueAxis::type() const
255 255 {
256 256 return AxisTypeValues;
257 257 }
258 258
259 259 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
260 260
261 261 QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q):
262 262 QAbstractAxisPrivate(q),
263 263 m_min(0),
264 264 m_max(0),
265 265 m_tickCount(5),
266 266 m_niceNumbers(false)
267 267 {
268 268
269 269 }
270 270
271 271 QValueAxisPrivate::~QValueAxisPrivate()
272 272 {
273 273
274 274 }
275 275
276 276 void QValueAxisPrivate::handleDomainUpdated()
277 277 {
278 278 Q_Q(QValueAxis);
279 279 Domain* domain = qobject_cast<Domain*>(sender());
280 280 Q_ASSERT(domain);
281 281
282 282 if(orientation()==Qt::Horizontal){
283 283 q->setRange(domain->minX(),domain->maxX());
284 284 }else if(orientation()==Qt::Vertical){
285 285 q->setRange(domain->minY(),domain->maxY());
286 286 }
287 287 }
288 288
289 289
290 290 void QValueAxisPrivate::setMin(const QVariant &min)
291 291 {
292 292 Q_Q(QValueAxis);
293 293 bool ok;
294 294 qreal value = min.toReal(&ok);
295 295 if(ok) q->setMin(value);
296 296 }
297 297
298 298 void QValueAxisPrivate::setMax(const QVariant &max)
299 299 {
300 300
301 301 Q_Q(QValueAxis);
302 302 bool ok;
303 303 qreal value = max.toReal(&ok);
304 304 if(ok) q->setMax(value);
305 305 }
306 306
307 307 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
308 308 {
309 309 Q_Q(QValueAxis);
310 310 bool ok1;
311 311 bool ok2;
312 312 qreal value1 = min.toReal(&ok1);
313 313 qreal value2 = max.toReal(&ok2);
314 314 if(ok1&&ok2) q->setRange(value1,value2);
315 315 }
316 316
317 317 ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter)
318 318 {
319 319 Q_Q(QValueAxis);
320 320 if(m_orientation == Qt::Vertical){
321 return new ChartValuesAxisY(q,presenter);
321 return new ChartValueAxisY(q,presenter);
322 322 }else{
323 return new ChartValuesAxisX(q,presenter);
323 return new ChartValueAxisX(q,presenter);
324 324 }
325 325
326 326 }
327 327
328 328 void QValueAxisPrivate::intializeDomain(Domain* domain)
329 329 {
330 330 Q_Q(QValueAxis);
331 331 if(qFuzzyCompare(m_max,m_min)) {
332 332 if(m_orientation==Qt::Vertical){
333 333 q->setRange(domain->minY(),domain->maxY());
334 334 }else{
335 335 q->setRange(domain->minX(), domain->maxX());
336 336 }
337 337 } else {
338 338 if(m_orientation==Qt::Vertical){
339 339 domain->setRangeY(m_min, m_max);
340 340 }else{
341 341 domain->setRangeX(m_min, m_max);
342 342 }
343 343 }
344 344 }
345 345
346 346 //algorithm defined by Paul S.Heckbert GraphicalGems I
347 347
348 348 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
349 349 {
350 350 qreal range = niceNumber(max-min,true); //range with ceiling
351 351 qreal step = niceNumber(range/(ticksCount-1),false);
352 352 min = qFloor(min/step);
353 353 max = qCeil(max/step);
354 354 ticksCount = int(max-min) +1;
355 355 min*=step;
356 356 max*=step;
357 357 }
358 358
359 359 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
360 360
361 361 qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const
362 362 {
363 363 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
364 364 qreal q = x/z;//q<10 && q>=1;
365 365
366 366 if(ceiling) {
367 367 if(q <= 1.0) q=1;
368 368 else if(q <= 2.0) q=2;
369 369 else if(q <= 5.0) q=5;
370 370 else q=10;
371 371 }
372 372 else {
373 373 if(q < 1.5) q=1;
374 374 else if(q < 3.0) q=2;
375 375 else if(q < 7.0) q=5;
376 376 else q=10;
377 377 }
378 378 return q*z;
379 379 }
380 380
381 #include "moc_qvaluesaxis.cpp"
382 #include "moc_qvaluesaxis_p.cpp"
381 #include "moc_qvalueaxis.cpp"
382 #include "moc_qvalueaxis_p.cpp"
383 383
384 384 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file renamed from src/axis/valuesaxis/qvaluesaxis.h to src/axis/valueaxis/qvalueaxis.h
@@ -1,72 +1,72
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QVALUESAXIS_P_H
31 31 #define QVALUESAXIS_P_H
32 32
33 #include "qvaluesaxis.h"
33 #include "qvalueaxis.h"
34 34 #include "qabstractaxis_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QValueAxisPrivate : public QAbstractAxisPrivate
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 QValueAxisPrivate(QValueAxis *q);
43 43 ~QValueAxisPrivate();
44 44
45 45 public:
46 46 ChartAxis* createGraphics(ChartPresenter* presenter);
47 47 void intializeDomain(Domain* domain);
48 48 void handleDomainUpdated();
49 49 qreal min(){ return m_min; };
50 50 qreal max(){ return m_max; };
51 51 int count() const { return m_tickCount;}
52 52
53 53 protected:
54 54 void setMin(const QVariant &min);
55 55 void setMax(const QVariant &max);
56 56 void setRange(const QVariant &min, const QVariant &max);
57 57
58 58 private:
59 59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
60 60 qreal niceNumber(qreal x,bool ceiling) const;
61 61
62 62 private:
63 63 qreal m_min;
64 64 qreal m_max;
65 65 int m_tickCount;
66 66 bool m_niceNumbers;
67 67 Q_DECLARE_PUBLIC(QValueAxis)
68 68 };
69 69
70 70 QTCOMMERCIALCHART_END_NAMESPACE
71 71
72 72 #endif // QVALUESAXIS_P_H
@@ -1,828 +1,828
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qabstractbarseries.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "domain_p.h"
26 26 #include "legendmarker_p.h"
27 27 #include "chartdataset_p.h"
28 28 #include "charttheme_p.h"
29 #include "qvaluesaxis.h"
29 #include "qvalueaxis.h"
30 30 #include "qbarcategoriesaxis.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QAbstractBarSeries
36 36 \brief Series for creating a bar chart
37 37 \mainclass
38 38
39 39 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 42 shows the x-values.
43 43
44 44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 45 \image examples_barchart.png
46 46
47 47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 48 */
49 49 /*!
50 50 \qmlclass AbstractBarSeries QAbstractBarSeries
51 51 \inherits QAbstractSeries
52 52
53 53 The following QML shows how to create a simple bar chart:
54 54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55 55
56 56 \beginfloatleft
57 57 \image demos_qmlchart6.png
58 58 \endfloat
59 59 \clearfloat
60 60 */
61 61
62 62 /*!
63 63 \property QAbstractBarSeries::barWidth
64 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 65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 67 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
68 68 \sa QBarSeries
69 69 */
70 70 /*!
71 71 \qmlproperty real AbstractBarSeries::barWidth
72 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 73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 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 79 \property QAbstractBarSeries::count
80 80 Holds the number of sets in series.
81 81 */
82 82 /*!
83 83 \qmlproperty int AbstractBarSeries::count
84 84 Holds the number of sets in series.
85 85 */
86 86
87 87 /*!
88 88 \property QAbstractBarSeries::labelsVisible
89 89 Defines the visibility of the labels in series
90 90 */
91 91 /*!
92 92 \qmlproperty bool AbstractBarSeries::labelsVisible
93 93 Defines the visibility of the labels in series
94 94 */
95 95
96 96 /*!
97 97 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 99 Clicked bar inside set is indexed by \a index
100 100 */
101 101 /*!
102 102 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
103 103 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 104 Clicked bar inside set is indexed by \a index
105 105 */
106 106
107 107 /*!
108 108 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109 109
110 110 The signal is emitted if mouse is hovered on top of series.
111 111 Parameter \a barset is the pointer of barset, where hover happened.
112 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 115 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
116 116
117 117 The signal is emitted if mouse is hovered on top of series.
118 118 Parameter \a barset is the pointer of barset, where hover happened.
119 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 123 \fn void QAbstractBarSeries::countChanged()
124 124 This signal is emitted when barset count has been changed, for example by append or remove.
125 125 */
126 126 /*!
127 127 \qmlsignal AbstractBarSeries::onCountChanged()
128 128 This signal is emitted when barset count has been changed, for example by append or remove.
129 129 */
130 130
131 131 /*!
132 132 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 133 This signal is emitted when labels visibility have changed.
134 134 \sa isLabelsVisible(), setLabelsVisible()
135 135 */
136 136
137 137 /*!
138 138 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 139 This signal is emitted when \a sets have been added to the series.
140 140 \sa append(), insert()
141 141 */
142 142 /*!
143 143 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
144 144 Emitted when \a barset has been added to the series.
145 145 */
146 146
147 147 /*!
148 148 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 149 This signal is emitted when \a sets have been removed from the series.
150 150 \sa remove()
151 151 */
152 152 /*!
153 153 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
154 154 Emitted when \a barset has been removed from the series.
155 155 */
156 156
157 157 /*!
158 158 \qmlmethod BarSet AbstractBarSeries::at(int index)
159 159 Returns bar set at \a index. Returns null if the index is not valid.
160 160 */
161 161
162 162 /*!
163 163 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
164 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 165 For example:
166 166 \code
167 167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 169 \endcode
170 170 */
171 171
172 172 /*!
173 173 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
174 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 175 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 176 appended.
177 177 \sa AbstractBarSeries::append()
178 178 */
179 179
180 180 /*!
181 181 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
182 182 Removes the barset from the series. Returns true if successfull, false otherwise.
183 183 */
184 184
185 185 /*!
186 186 \qmlmethod AbstractBarSeries::clear()
187 187 Removes all barsets from the series.
188 188 */
189 189
190 190 /*!
191 191 This is depreciated constructor.
192 192 */
193 193 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
194 194 QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent)
195 195 {
196 196 }
197 197
198 198 /*!
199 199 Destructs abstractbarseries and owned barsets.
200 200 */
201 201 QAbstractBarSeries::~QAbstractBarSeries()
202 202 {
203 203
204 204 }
205 205
206 206 /*!
207 207 \internal
208 208 */
209 209 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
210 210 QAbstractSeries(d,parent)
211 211 {
212 212 }
213 213
214 214 /*!
215 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 216 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
217 217 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
218 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 220 void QAbstractBarSeries::setBarWidth(qreal width)
221 221 {
222 222 Q_D(QAbstractBarSeries);
223 223 d->setBarWidth(width);
224 224 }
225 225
226 226 /*!
227 227 Returns the width of the bars of the series.
228 228 \sa setBarWidth()
229 229 */
230 230 qreal QAbstractBarSeries::barWidth() const
231 231 {
232 232 Q_D(const QAbstractBarSeries);
233 233 return d->barWidth();
234 234 }
235 235
236 236 /*!
237 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 238 Returns true, if appending succeeded.
239 239 */
240 240 bool QAbstractBarSeries::append(QBarSet *set)
241 241 {
242 242 Q_D(QAbstractBarSeries);
243 243 bool success = d->append(set);
244 244 if (success) {
245 245 QList<QBarSet*> sets;
246 246 sets.append(set);
247 247 set->setParent(this);
248 248 emit barsetsAdded(sets);
249 249 emit countChanged();
250 250 }
251 251 return success;
252 252 }
253 253
254 254 /*!
255 255 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
256 256 was successful.
257 257 Returns true, if set was removed.
258 258 */
259 259 bool QAbstractBarSeries::remove(QBarSet *set)
260 260 {
261 261 Q_D(QAbstractBarSeries);
262 262 bool success = d->remove(set);
263 263 if (success) {
264 264 QList<QBarSet*> sets;
265 265 sets.append(set);
266 266 set->setParent(0);
267 267 emit barsetsRemoved(sets);
268 268 emit countChanged();
269 269 delete set;
270 270 set = 0;
271 271 }
272 272 return success;
273 273 }
274 274
275 275 /*!
276 276 Takes a single \a set from the series. Does not delete the barset object.
277 277
278 278 NOTE: The series remains as the barset's parent object. You must set the
279 279 parent object to take full ownership.
280 280
281 281 Returns true if take was successfull.
282 282 */
283 283 bool QAbstractBarSeries::take(QBarSet *set)
284 284 {
285 285 Q_D(QAbstractBarSeries);
286 286 bool success = d->remove(set);
287 287 if (success) {
288 288 QList<QBarSet*> sets;
289 289 sets.append(set);
290 290 emit barsetsRemoved(sets);
291 291 emit countChanged();
292 292 }
293 293 return success;
294 294 }
295 295
296 296 /*!
297 297 Adds a list of barsets to series. Takes ownership of \a sets.
298 298 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
299 299 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
300 300 and function returns false.
301 301 */
302 302 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
303 303 {
304 304 Q_D(QAbstractBarSeries);
305 305 bool success = d->append(sets);
306 306 if (success) {
307 307 emit barsetsAdded(sets);
308 308 emit countChanged();
309 309 }
310 310 return success;
311 311 }
312 312
313 313 /*!
314 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 315 Returns true, if inserting succeeded.
316 316
317 317 */
318 318 bool QAbstractBarSeries::insert(int index, QBarSet *set)
319 319 {
320 320 Q_D(QAbstractBarSeries);
321 321 bool success = d->insert(index, set);
322 322 if (success) {
323 323 QList<QBarSet*> sets;
324 324 sets.append(set);
325 325 emit barsetsAdded(sets);
326 326 emit countChanged();
327 327 }
328 328 return success;
329 329 }
330 330
331 331 /*!
332 332 Removes all barsets from the series. Deletes removed sets.
333 333 */
334 334 void QAbstractBarSeries::clear()
335 335 {
336 336 Q_D(QAbstractBarSeries);
337 337 QList<QBarSet *> sets = barSets();
338 338 bool success = d->remove(sets);
339 339 if (success) {
340 340 emit barsetsRemoved(sets);
341 341 emit countChanged();
342 342 foreach (QBarSet* set, sets) {
343 343 delete set;
344 344 }
345 345 }
346 346 }
347 347
348 348 /*!
349 349 Returns number of sets in series.
350 350 */
351 351 int QAbstractBarSeries::count() const
352 352 {
353 353 Q_D(const QAbstractBarSeries);
354 354 return d->m_barSets.count();
355 355 }
356 356
357 357 /*!
358 358 Returns a list of sets in series. Keeps ownership of sets.
359 359 */
360 360 QList<QBarSet*> QAbstractBarSeries::barSets() const
361 361 {
362 362 Q_D(const QAbstractBarSeries);
363 363 return d->m_barSets;
364 364 }
365 365
366 366 /*!
367 367 Sets the visibility of labels in series to \a visible
368 368 */
369 369 void QAbstractBarSeries::setLabelsVisible(bool visible)
370 370 {
371 371 Q_D(QAbstractBarSeries);
372 372 if (d->m_labelsVisible != visible) {
373 373 d->setLabelsVisible(visible);
374 374 emit labelsVisibleChanged();
375 375 }
376 376 }
377 377
378 378 /*!
379 379 Returns the visibility of labels
380 380 */
381 381 bool QAbstractBarSeries::isLabelsVisible() const
382 382 {
383 383 Q_D(const QAbstractBarSeries);
384 384 return d->m_labelsVisible;
385 385 }
386 386
387 387 void QAbstractBarSeries::setGrouping(bool grouping)
388 388 {
389 389 Q_D(QAbstractBarSeries);
390 390 d->setGrouping(grouping);
391 391 }
392 392
393 393
394 394
395 395 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
396 396
397 397 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
398 398 QAbstractSeriesPrivate(q),
399 399 m_barWidth(0.5), // Default value is 50% of category width
400 400 m_labelsVisible(false),
401 401 m_visible(true),
402 402 m_grouping(true)
403 403 {
404 404 }
405 405
406 406 int QAbstractBarSeriesPrivate::categoryCount() const
407 407 {
408 408 // No categories defined. return count of longest set.
409 409 int count = 0;
410 410 for (int i=0; i<m_barSets.count(); i++) {
411 411 if (m_barSets.at(i)->count() > count) {
412 412 count = m_barSets.at(i)->count();
413 413 }
414 414 }
415 415
416 416 return count;
417 417 }
418 418
419 419 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
420 420 {
421 421 if (width < 0.0) {
422 422 width = 0.0;
423 423 }
424 424 m_barWidth = width;
425 425 emit updatedBars();
426 426 }
427 427
428 428 qreal QAbstractBarSeriesPrivate::barWidth() const
429 429 {
430 430 return m_barWidth;
431 431 }
432 432
433 433 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
434 434 {
435 435 return m_barSets.at(index);
436 436 }
437 437
438 438 void QAbstractBarSeriesPrivate::setVisible(bool visible)
439 439 {
440 440 m_visible = visible;
441 441 emit updatedBars();
442 442 }
443 443
444 444 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
445 445 {
446 446 m_labelsVisible = visible;
447 447 emit labelsVisibleChanged(visible);
448 448 }
449 449
450 450 void QAbstractBarSeriesPrivate::setGrouping(bool grouping)
451 451 {
452 452 if (m_grouping != grouping) {
453 453 m_grouping = grouping;
454 454 emit updatedBars();
455 455 }
456 456 }
457 457
458 458 qreal QAbstractBarSeriesPrivate::min()
459 459 {
460 460 if (m_barSets.count() <= 0) {
461 461 return 0;
462 462 }
463 463 qreal min = INT_MAX;
464 464
465 465 for (int i = 0; i < m_barSets.count(); i++) {
466 466 int categoryCount = m_barSets.at(i)->count();
467 467 for (int j = 0; j < categoryCount; j++) {
468 468 qreal temp = m_barSets.at(i)->at(j);
469 469 if (temp < min)
470 470 min = temp;
471 471 }
472 472 }
473 473 return min;
474 474 }
475 475
476 476 qreal QAbstractBarSeriesPrivate::max()
477 477 {
478 478 if (m_barSets.count() <= 0) {
479 479 return 0;
480 480 }
481 481 qreal max = INT_MIN;
482 482
483 483 for (int i = 0; i < m_barSets.count(); i++) {
484 484 int categoryCount = m_barSets.at(i)->count();
485 485 for (int j = 0; j < categoryCount; j++) {
486 486 qreal temp = m_barSets.at(i)->at(j);
487 487 if (temp > max)
488 488 max = temp;
489 489 }
490 490 }
491 491
492 492 return max;
493 493 }
494 494
495 495 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
496 496 {
497 497 if ((set < 0) || (set >= m_barSets.count())) {
498 498 // No set, no value.
499 499 return 0;
500 500 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
501 501 // No category, no value.
502 502 return 0;
503 503 }
504 504
505 505 return m_barSets.at(set)->at(category);
506 506 }
507 507
508 508 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
509 509 {
510 510 if ((set < 0) || (set >= m_barSets.count())) {
511 511 // No set, no value.
512 512 return 0;
513 513 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
514 514 // No category, no value.
515 515 return 0;
516 516 }
517 517
518 518 qreal value = m_barSets.at(set)->at(category);
519 519 qreal sum = categorySum(category);
520 520 if ( qFuzzyIsNull(sum) ) {
521 521 return 0;
522 522 }
523 523
524 524 return value / sum;
525 525 }
526 526
527 527 qreal QAbstractBarSeriesPrivate::categorySum(int category)
528 528 {
529 529 qreal sum(0);
530 530 int count = m_barSets.count(); // Count sets
531 531 for (int set = 0; set < count; set++) {
532 532 if (category < m_barSets.at(set)->count())
533 533 sum += m_barSets.at(set)->at(category);
534 534 }
535 535 return sum;
536 536 }
537 537
538 538 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
539 539 {
540 540 qreal sum(0);
541 541 int count = m_barSets.count(); // Count sets
542 542 for (int set = 0; set < count; set++) {
543 543 if (category < m_barSets.at(set)->count())
544 544 sum += qAbs(m_barSets.at(set)->at(category));
545 545 }
546 546 return sum;
547 547 }
548 548
549 549 qreal QAbstractBarSeriesPrivate::maxCategorySum()
550 550 {
551 551 qreal max = INT_MIN;
552 552 int count = categoryCount();
553 553 for (int i = 0; i < count; i++) {
554 554 qreal sum = categorySum(i);
555 555 if (sum > max)
556 556 max = sum;
557 557 }
558 558 return max;
559 559 }
560 560
561 561 qreal QAbstractBarSeriesPrivate::minX()
562 562 {
563 563 if (m_barSets.count() <= 0) {
564 564 return 0;
565 565 }
566 566 qreal min = INT_MAX;
567 567
568 568 for (int i = 0; i < m_barSets.count(); i++) {
569 569 int categoryCount = m_barSets.at(i)->count();
570 570 for (int j = 0; j < categoryCount; j++) {
571 571 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
572 572 if (temp < min)
573 573 min = temp;
574 574 }
575 575 }
576 576 return min;
577 577 }
578 578
579 579 qreal QAbstractBarSeriesPrivate::maxX()
580 580 {
581 581 if (m_barSets.count() <= 0) {
582 582 return 0;
583 583 }
584 584 qreal max = INT_MIN;
585 585
586 586 for (int i = 0; i < m_barSets.count(); i++) {
587 587 int categoryCount = m_barSets.at(i)->count();
588 588 for (int j = 0; j < categoryCount; j++) {
589 589 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
590 590 if (temp > max)
591 591 max = temp;
592 592 }
593 593 }
594 594
595 595 return max;
596 596 }
597 597
598 598
599 599 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
600 600 {
601 601 qreal minX(domain.minX());
602 602 qreal minY(domain.minY());
603 603 qreal maxX(domain.maxX());
604 604 qreal maxY(domain.maxY());
605 605
606 606 qreal seriesMinX = this->minX();
607 607 qreal seriesMaxX = this->maxX();
608 608 qreal y = max();
609 609 minX = qMin(minX, seriesMinX - (qreal)0.5);
610 610 minY = qMin(minY, y);
611 611 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
612 612 maxY = qMax(maxY, y);
613 613
614 614 domain.setRange(minX,maxX,minY,maxY);
615 615 }
616 616
617 617 ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
618 618 {
619 619 Q_UNUSED(presenter);
620 620 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
621 621 return 0;
622 622 }
623 623
624 624 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
625 625 {
626 626 Q_Q(QAbstractBarSeries);
627 627 QList<LegendMarker*> markers;
628 628 foreach(QBarSet* set, q->barSets()) {
629 629 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
630 630 markers << marker;
631 631 }
632 632
633 633 return markers;
634 634 }
635 635
636 636 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
637 637 {
638 638 Q_Q(QAbstractBarSeries);
639 639 if ((m_barSets.contains(set)) || (set == 0)) {
640 640 // Fail if set is already in list or set is null.
641 641 return false;
642 642 }
643 643 m_barSets.append(set);
644 644 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
645 645 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
646 646 emit restructuredBars(); // this notifies barchartitem
647 647 if (m_dataset) {
648 648 m_dataset->updateSeries(q); // this notifies legend
649 649 }
650 650 return true;
651 651 }
652 652
653 653 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
654 654 {
655 655 Q_Q(QAbstractBarSeries);
656 656 if (!m_barSets.contains(set)) {
657 657 // Fail if set is not in list
658 658 return false;
659 659 }
660 660 m_barSets.removeOne(set);
661 661 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
662 662 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
663 663 emit restructuredBars(); // this notifies barchartitem
664 664 if (m_dataset) {
665 665 m_dataset->updateSeries(q); // this notifies legend
666 666 }
667 667 return true;
668 668 }
669 669
670 670 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
671 671 {
672 672 Q_Q(QAbstractBarSeries);
673 673 foreach (QBarSet* set, sets) {
674 674 if ((set == 0) || (m_barSets.contains(set))) {
675 675 // Fail if any of the sets is null or is already appended.
676 676 return false;
677 677 }
678 678 if (sets.count(set) != 1) {
679 679 // Also fail if same set is more than once in given list.
680 680 return false;
681 681 }
682 682 }
683 683
684 684 foreach (QBarSet* set, sets) {
685 685 m_barSets.append(set);
686 686 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
687 687 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
688 688 }
689 689 emit restructuredBars(); // this notifies barchartitem
690 690 if (m_dataset) {
691 691 m_dataset->updateSeries(q); // this notifies legend
692 692 }
693 693 return true;
694 694 }
695 695
696 696 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
697 697 {
698 698 Q_Q(QAbstractBarSeries);
699 699 if (sets.count() == 0) {
700 700 return false;
701 701 }
702 702 foreach (QBarSet* set, sets) {
703 703 if ((set == 0) || (!m_barSets.contains(set))) {
704 704 // Fail if any of the sets is null or is not in series
705 705 return false;
706 706 }
707 707 if (sets.count(set) != 1) {
708 708 // Also fail if same set is more than once in given list.
709 709 return false;
710 710 }
711 711 }
712 712
713 713 foreach (QBarSet* set, sets) {
714 714 m_barSets.removeOne(set);
715 715 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
716 716 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
717 717 }
718 718
719 719 emit restructuredBars(); // this notifies barchartitem
720 720 if (m_dataset) {
721 721 m_dataset->updateSeries(q); // this notifies legend
722 722 }
723 723 return true;
724 724 }
725 725
726 726 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
727 727 {
728 728 Q_Q(QAbstractBarSeries);
729 729 if ((m_barSets.contains(set)) || (set == 0)) {
730 730 // Fail if set is already in list or set is null.
731 731 return false;
732 732 }
733 733 m_barSets.insert(index, set);
734 734 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
735 735 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
736 736 emit restructuredBars(); // this notifies barchartitem
737 737 if (m_dataset) {
738 738 m_dataset->updateSeries(q); // this notifies legend
739 739 }
740 740 return true;
741 741 }
742 742
743 743 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
744 744 {
745 745 Q_Q(QAbstractBarSeries);
746 746
747 747 if(axis->type()==QAbstractAxis::AxisTypeCategories) {
748 748
749 749 switch(q->type()) {
750 750
751 751 case QAbstractSeries::SeriesTypeHorizontalBar:
752 752 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
753 753 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
754 754
755 755 if(axis->orientation()==Qt::Vertical)
756 756 {
757 757 populateCategories(qobject_cast<QBarCategoriesAxis*>(axis));
758 758 }
759 759 break;
760 760 }
761 761 case QAbstractSeries::SeriesTypeBar:
762 762 case QAbstractSeries::SeriesTypePercentBar:
763 763 case QAbstractSeries::SeriesTypeStackedBar: {
764 764
765 765 if(axis->orientation()==Qt::Horizontal)
766 766 {
767 767 populateCategories(qobject_cast<QBarCategoriesAxis*>(axis));
768 768 }
769 769 break;
770 770 }
771 771 default:
772 772 qWarning()<<"Unexpected series type";
773 773 break;
774 774
775 775 }
776 776 }
777 777 }
778 778
779 779 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
780 780 {
781 781 Q_Q(const QAbstractBarSeries);
782 782
783 783 switch(q->type()) {
784 784
785 785 case QAbstractSeries::SeriesTypeHorizontalBar:
786 786 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
787 787 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
788 788
789 789 if(orientation==Qt::Vertical)
790 790 {
791 791 return QAbstractAxis::AxisTypeCategories;
792 792 }
793 793 break;
794 794 }
795 795 case QAbstractSeries::SeriesTypeBar:
796 796 case QAbstractSeries::SeriesTypePercentBar:
797 797 case QAbstractSeries::SeriesTypeStackedBar: {
798 798
799 799 if(orientation==Qt::Horizontal)
800 800 {
801 801 return QAbstractAxis::AxisTypeCategories;
802 802 }
803 803 break;
804 804 }
805 805 default:
806 806 qWarning()<<"Unexpected series type";
807 807 break;
808 808
809 809 }
810 810 return QAbstractAxis::AxisTypeValues;
811 811
812 812 }
813 813
814 814 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoriesAxis* axis)
815 815 {
816 816 QStringList categories;
817 817 if(axis->categories().isEmpty()) {
818 818 for (int i(1); i < categoryCount()+1; i++)
819 819 categories << QString::number(i);
820 820 axis->append(categories);
821 821 }
822 822 }
823 823
824 824 #include "moc_qabstractbarseries.cpp"
825 825 #include "moc_qabstractbarseries_p.cpp"
826 826
827 827
828 828 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,121 +1,121
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarseries.h"
22 22 #include "qbarseries_p.h"
23 23 #include "barchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "baranimation_p.h"
27 #include "qvaluesaxis.h"
27 #include "qvalueaxis.h"
28 28 #include "qbarcategoriesaxis.h"
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 /*!
33 33 \class QBarSeries
34 34 \brief Series for creating bar chart
35 35 \mainclass
36 36
37 37 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 38 as groups, where bars in same category are grouped next to each other. QBarSeries groups the data
39 39 from sets to categories, which are defined by a QStringList.
40 40
41 41 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
42 42 \image examples_barchart.png
43 43
44 44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
45 45 */
46 46 /*!
47 47 \qmlclass BarSeries QBarSeries
48 48 \inherits AbstractBarSeries
49 49
50 50 The following QML shows how to create a simple grouped bar chart:
51 51 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
52 52 \beginfloatleft
53 53 \image demos_qmlchart6.png
54 54 \endfloat
55 55 \clearfloat
56 56 */
57 57
58 58 /*!
59 59 Constructs empty QBarSeries.
60 60 QBarSeries is QObject which is a child of a \a parent.
61 61 */
62 62 QBarSeries::QBarSeries(QObject *parent)
63 63 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
64 64 {
65 65 }
66 66
67 67 /*!
68 68 Returns QChartSeries::SeriesTypeBar.
69 69 */
70 70 QAbstractSeries::SeriesType QBarSeries::type() const
71 71 {
72 72 return QAbstractSeries::SeriesTypeBar;
73 73 }
74 74
75 75 QBarSeries::~QBarSeries()
76 76 {
77 77 Q_D(QBarSeries);
78 78 if(d->m_dataset) {
79 79 d->m_dataset->removeSeries(this);
80 80 }
81 81 }
82 82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 83
84 84 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
85 85 {
86 86
87 87 }
88 88
89 89 void QBarSeriesPrivate::scaleDomain(Domain& domain)
90 90 {
91 91 qreal minX(domain.minX());
92 92 qreal minY(domain.minY());
93 93 qreal maxX(domain.maxX());
94 94 qreal maxY(domain.maxY());
95 95
96 96 qreal x = categoryCount();
97 97 minX = qMin(minX, - (qreal)0.5);
98 98 minY = qMin(minY, min());
99 99 maxX = qMax(maxX, x - (qreal)0.5);
100 100 maxY = qMax(maxY, max());
101 101
102 102 domain.setRange(minX,maxX,minY,maxY);
103 103 }
104 104
105 105
106 106 ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
107 107 {
108 108 Q_Q(QBarSeries);
109 109
110 110 BarChartItem* bar = new BarChartItem(q,presenter);
111 111 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
112 112 bar->setAnimation(new BarAnimation(bar));
113 113 }
114 114 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
115 115 return bar;
116 116 }
117 117
118 118 #include "moc_qbarseries.cpp"
119 119
120 120 QTCOMMERCIALCHART_END_NAMESPACE
121 121
@@ -1,121 +1,121
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpercentbarseries.h"
22 22 #include "qpercentbarseries_p.h"
23 23 #include "percentbarchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 #include "qvaluesaxis.h"
26 #include "qvalueaxis.h"
27 27 #include "percentbaranimation_p.h"
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 /*!
32 32 \class QPercentBarSeries
33 33 \brief Series for creating percent bar chart
34 34 \mainclass
35 35
36 36 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 37 as stacks, where each bar is shown as percentage of all bars in that category.
38 38 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
39 39
40 40 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
41 41 \image examples_percentbarchart.png
42 42
43 43 \sa QBarSet, QStackedBarSeries, QAbstractBarSeries
44 44 */
45 45 /*!
46 46 \qmlclass PercentBarSeries QPercentBarSeries
47 47 \inherits QAbstractBarSeries
48 48
49 49 The following QML shows how to create a simple percent bar chart:
50 50 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
51 51 \beginfloatleft
52 52 \image demos_qmlchart8.png
53 53 \endfloat
54 54 \clearfloat
55 55 */
56 56
57 57 /*!
58 58 Constructs empty QPercentBarSeries.
59 59 QPercentBarSeries is QObject which is a child of a \a parent.
60 60 */
61 61 QPercentBarSeries::QPercentBarSeries(QObject *parent)
62 62 : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent)
63 63 {
64 64 }
65 65
66 66 QPercentBarSeries::~QPercentBarSeries()
67 67 {
68 68 Q_D(QPercentBarSeries);
69 69 if(d->m_dataset) {
70 70 d->m_dataset->removeSeries(this);
71 71 }
72 72 }
73 73
74 74 /*!
75 75 Returns QChartSeries::SeriesTypePercentBar.
76 76 */
77 77 QAbstractSeries::SeriesType QPercentBarSeries::type() const
78 78 {
79 79 return QAbstractSeries::SeriesTypePercentBar;
80 80 }
81 81
82 82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 83
84 84 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
85 85 {
86 86
87 87 }
88 88
89 89 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
90 90 {
91 91 qreal minX(domain.minX());
92 92 qreal minY(domain.minY());
93 93 qreal maxX(domain.maxX());
94 94 qreal maxY(domain.maxY());
95 95
96 96 qreal x = categoryCount();
97 97 minX = qMin(minX, - (qreal)0.5);
98 98 maxX = qMax(maxX, x - (qreal)0.5);
99 99 minY = 0;
100 100 maxY = 100;
101 101
102 102 domain.setRange(minX,maxX,minY,maxY);
103 103 }
104 104
105 105
106 106 ChartElement* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
107 107 {
108 108 Q_Q(QPercentBarSeries);
109 109
110 110 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
111 111 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
112 112 bar->setAnimation(new PercentBarAnimation(bar));
113 113 }
114 114 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
115 115 return bar;
116 116 }
117 117
118 118 #include "moc_qpercentbarseries.cpp"
119 119
120 120 QTCOMMERCIALCHART_END_NAMESPACE
121 121
@@ -1,122 +1,122
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qstackedbarseries.h"
22 22 #include "qstackedbarseries_p.h"
23 23 #include "stackedbarchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 #include "qvaluesaxis.h"
26 #include "qvalueaxis.h"
27 27 #include "stackedbaranimation_p.h"
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 /*!
32 32 \class QStackedBarSeries
33 33 \brief Series for creating stacked bar chart
34 34 \mainclass
35 35
36 36 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 37 as stacks, where bars in same category are stacked on top of each other.
38 38 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
39 39
40 40 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
41 41 \image examples_stackedbarchart.png
42 42
43 43 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries
44 44 */
45 45
46 46 /*!
47 47 \qmlclass StackedBarSeries QStackedBarSeries
48 48 \inherits AbstractBarSeries
49 49
50 50 The following QML shows how to create a simple stacked bar chart:
51 51 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
52 52 \beginfloatleft
53 53 \image demos_qmlchart7.png
54 54 \endfloat
55 55 \clearfloat
56 56 */
57 57
58 58 /*!
59 59 Constructs empty QStackedBarSeries.
60 60 QStackedBarSeries is QObject which is a child of a \a parent.
61 61 */
62 62 QStackedBarSeries::QStackedBarSeries(QObject *parent)
63 63 : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent)
64 64 {
65 65 }
66 66
67 67 QStackedBarSeries::~QStackedBarSeries()
68 68 {
69 69 Q_D(QStackedBarSeries);
70 70 if(d->m_dataset) {
71 71 d->m_dataset->removeSeries(this);
72 72 }
73 73 }
74 74 /*!
75 75 Returns QChartSeries::SeriesTypeStackedBar.
76 76 */
77 77 QAbstractSeries::SeriesType QStackedBarSeries::type() const
78 78 {
79 79 return QAbstractSeries::SeriesTypeStackedBar;
80 80 }
81 81
82 82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 83
84 84 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
85 85 {
86 86
87 87 }
88 88
89 89 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
90 90 {
91 91 qreal minX(domain.minX());
92 92 qreal minY(domain.minY());
93 93 qreal maxX(domain.maxX());
94 94 qreal maxY(domain.maxY());
95 95
96 96 qreal x = categoryCount();
97 97 qreal y = maxCategorySum();
98 98 minX = qMin(minX, - (qreal)0.5);
99 99 minY = qMin(minY, y);
100 100 maxX = qMax(maxX, x - (qreal)0.5);
101 101 maxY = qMax(maxY, y);
102 102
103 103 domain.setRange(minX,maxX,minY,maxY);
104 104 }
105 105
106 106
107 107 ChartElement* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
108 108 {
109 109 Q_Q(QStackedBarSeries);
110 110
111 111 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
112 112 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
113 113 bar->setAnimation(new StackedBarAnimation(bar));
114 114 }
115 115 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
116 116 return bar;
117 117 }
118 118
119 119 #include "moc_qstackedbarseries.cpp"
120 120
121 121 QTCOMMERCIALCHART_END_NAMESPACE
122 122
@@ -1,484 +1,484
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartdataset_p.h"
22 22 #include "qchart.h"
23 #include "qvaluesaxis.h"
23 #include "qvalueaxis.h"
24 24 #include "qbarcategoriesaxis.h"
25 #include "qvaluesaxis_p.h"
25 #include "qvalueaxis_p.h"
26 26 #include "qintervalsaxis.h"
27 27 #include "qdatetimeaxis.h"
28 28 #include "qabstractseries_p.h"
29 29 #include "qabstractbarseries.h"
30 30 #include "qstackedbarseries.h"
31 31 #include "qpercentbarseries.h"
32 32 #include "qpieseries.h"
33 33
34 34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 35
36 36 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent)
37 37 {
38 38
39 39 }
40 40
41 41 ChartDataSet::~ChartDataSet()
42 42 {
43 43 removeAllSeries();
44 44 }
45 45
46 46 void ChartDataSet::addSeries(QAbstractSeries* series)
47 47 {
48 48 Domain* domain = m_seriesDomainMap.value(series);
49 49
50 50 if(domain) {
51 51 qWarning() << "Can not add series. Series already on the chart";
52 52 return;
53 53 }
54 54
55 55 domain = new Domain(series);
56 56 m_seriesDomainMap.insert(series,domain);
57 57 series->d_ptr->scaleDomain(*domain);
58 58
59 59 createSeriesIndex(series);
60 60
61 61 series->setParent(this); // take ownership
62 62 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
63 63 series->d_ptr->m_dataset = this;
64 64
65 65 emit seriesAdded(series,domain);
66 66
67 67 }
68 68
69 69 void ChartDataSet::removeSeries(QAbstractSeries* series)
70 70 {
71 71
72 72 if(!m_seriesDomainMap.contains(series)) {
73 73 qWarning()<<"Can not remove series. Series not found on the chart.";
74 74 return;
75 75 }
76 76
77 77 emit seriesRemoved(series);
78 78
79 79 Domain* domain = m_seriesDomainMap.take(series);
80 80 delete domain;
81 81 domain = 0;
82 82
83 83 removeSeriesIndex(series);
84 84
85 85 series->setParent(0);
86 86 series->d_ptr->m_chart = 0;
87 87 series->d_ptr->m_dataset = 0;
88 88
89 89 removeAxes(series);
90 90 }
91 91
92 92
93 93
94 94 void ChartDataSet::createSeriesIndex(QAbstractSeries* series)
95 95 {
96 96 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
97 97
98 98 int key=0;
99 99 while (i.hasNext()) {
100 100 i.next();
101 101 if(i.key()!=key) {
102 102 break;
103 103 }
104 104 key++;
105 105 }
106 106
107 107 m_indexSeriesMap.insert(key,series);
108 108 }
109 109
110 110 void ChartDataSet::removeSeriesIndex(QAbstractSeries* series)
111 111 {
112 112 int key = seriesIndex(series);
113 113 Q_ASSERT(key!=-1);
114 114 m_indexSeriesMap.remove(key);
115 115 }
116 116
117 117 void ChartDataSet::createDefaultAxes()
118 118 {
119 119
120 120 if(m_seriesDomainMap.isEmpty()) return;
121 121
122 122 QAbstractAxis::AxisTypes typeX(0);
123 123 QAbstractAxis::AxisTypes typeY(0);
124 124
125 125 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
126 126 while (i.hasNext()) {
127 127 i.next();
128 128 removeAxes(i.key());
129 129 }
130 130
131 131 i.toFront();
132 132
133 133 while (i.hasNext()) {
134 134 i.next();
135 135 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
136 136 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
137 137 if(axisX) typeX&=axisX->type();
138 138 else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal);
139 139 if(axisY) typeY&=axisY->type();
140 140 else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical);
141 141 }
142 142
143 143 createAxes(typeX,Qt::Horizontal);
144 144 createAxes(typeY,Qt::Vertical);
145 145 }
146 146
147 147 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation)
148 148 {
149 149 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
150 150
151 151 if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories))
152 152 {
153 153 while (i.hasNext()) {
154 154 i.next();
155 155 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation);
156 156 if(!axis) continue;
157 157 initializeAxis(axis,i.key());
158 158 emit axisAdded(axis,i.value());
159 159 }
160 160
161 161 }
162 162 else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
163 163 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation);
164 164 i.toFront();
165 165 while (i.hasNext()) {
166 166 i.next();
167 167 initializeAxis(axis,i.key());
168 168 }
169 169 emit axisAdded(axis,i.value());
170 170 }
171 171 }
172 172
173 173
174 174 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation)
175 175 {
176 176 QAbstractAxis* axis =0;
177 177
178 178 switch(type) {
179 179 case QAbstractAxis::AxisTypeValues:
180 180 axis = new QValueAxis(this);
181 181 break;
182 182 case QAbstractAxis::AxisTypeCategories:
183 183 axis = new QBarCategoriesAxis(this);
184 184 break;
185 185 case QAbstractAxis::AxisTypeIntervals:
186 186 axis = new QIntervalsAxis(this);
187 187 break;
188 188 case QAbstractAxis::AxisTypeDateTime:
189 189 axis = new QDateTimeAxis(this);
190 190 break;
191 191 default:
192 192 axis = 0;
193 193 break;
194 194 }
195 195
196 196 if(axis)
197 197 axis->d_ptr->setOrientation(orientation);
198 198
199 199 return axis;
200 200 }
201 201
202 202 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
203 203 {
204 204 Domain* domain = m_seriesDomainMap.value(series);
205 205 axis->d_ptr->m_dataset = this;
206 206 series->d_ptr->initializeAxis(axis);
207 207 axis->d_ptr->intializeDomain(domain);
208 208 if(axis->orientation()==Qt::Horizontal) {
209 209 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
210 210 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
211 211 m_seriesAxisXMap.insert(series,axis);
212 212 }
213 213 else {
214 214 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
215 215 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
216 216 m_seriesAxisYMap.insert(series,axis);
217 217 }
218 218 axis->d_ptr->emitUpdated();
219 219 }
220 220
221 221 void ChartDataSet::removeAxes(QAbstractSeries* series)
222 222 {
223 223 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
224 224
225 225 if(axisX) {
226 226 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
227 227 int x = axesX.indexOf(axisX);
228 228
229 229 if(x==-1) {
230 230 emit axisRemoved(axisX);
231 231 axisX->d_ptr->m_dataset=0;
232 232 axisX->deleteLater();
233 233 }
234 234 }
235 235
236 236 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
237 237
238 238 if(axisY) {
239 239 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
240 240
241 241 int y = axesY.indexOf(axisY);
242 242
243 243 if(y==-1) {
244 244 emit axisRemoved(axisY);
245 245 axisY->d_ptr->m_dataset=0;
246 246 axisY->deleteLater();
247 247 }
248 248 }
249 249 }
250 250
251 251 void ChartDataSet::removeAxis(QAbstractAxis* axis)
252 252 {
253 253 if(!axis->d_ptr->m_dataset) {
254 254 qWarning()<<"UnBound axis found !";
255 255 return;
256 256 }
257 257
258 258 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
259 259
260 260 if(axis->orientation()==Qt::Vertical) {
261 261 seriesAxisMap= &m_seriesAxisYMap;
262 262 }
263 263 else {
264 264 seriesAxisMap= &m_seriesAxisXMap;
265 265 }
266 266
267 267 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap);
268 268
269 269 while (i.hasNext()) {
270 270 i.next();
271 271 if(i.value()==axis) {
272 272 removeSeries(i.key());
273 273 }
274 274 }
275 275 }
276 276
277 277 void ChartDataSet::removeAllSeries()
278 278 {
279 279 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
280 280 foreach(QAbstractSeries *s , series) {
281 281 removeSeries(s);
282 282 }
283 283
284 284 Q_ASSERT(m_seriesAxisXMap.count()==0);
285 285 Q_ASSERT(m_seriesAxisXMap.count()==0);
286 286 Q_ASSERT(m_seriesDomainMap.count()==0);
287 287
288 288 qDeleteAll(series);
289 289 }
290 290
291 291 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
292 292 {
293 293 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
294 294
295 295
296 296 blockAxisSignals(true);
297 297
298 298 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
299 299
300 300 while (i.hasNext()) {
301 301 i.next();
302 302 i.value()->zoomIn(rect,size);
303 303 }
304 304
305 305 blockAxisSignals(false);
306 306
307 307 }
308 308
309 309 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
310 310 {
311 311 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
312 312
313 313 blockAxisSignals(true);
314 314
315 315 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
316 316
317 317 while (i.hasNext()) {
318 318 i.next();
319 319 i.value()->zoomOut(rect,size);
320 320 }
321 321
322 322 blockAxisSignals(false);
323 323 }
324 324
325 325 void ChartDataSet::blockAxisSignals(bool enabled)
326 326 {
327 327 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
328 328 while (i.hasNext()) {
329 329 i.next();
330 330 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
331 331 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
332 332 if(axisX) {
333 333 axisX->d_ptr->blockSignals(enabled);
334 334 if(!enabled) {
335 335 axisX->d_ptr->setDirty(false);
336 336 axisX->d_ptr->emitUpdated();
337 337 }
338 338 }
339 339 if(axisY) {
340 340 axisY->d_ptr->blockSignals(enabled);
341 341 if(!enabled) {
342 342 axisY->d_ptr->setDirty(false);
343 343 axisY->d_ptr->emitUpdated();
344 344 }
345 345 }
346 346 }
347 347 }
348 348
349 349 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
350 350 {
351 351 int count=0;
352 352 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
353 353 while (i.hasNext()) {
354 354 i.next();
355 355 if(i.key()->type()==type) count++;
356 356 }
357 357 return count;
358 358 }
359 359
360 360 int ChartDataSet::seriesIndex(QAbstractSeries *series)
361 361 {
362 362 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
363 363 while (i.hasNext()) {
364 364 i.next();
365 365 if (i.value() == series)
366 366 return i.key();
367 367 }
368 368 return -1;
369 369 }
370 370
371 371 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
372 372 {
373 373 if(series == 0) {
374 374
375 375 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap);
376 376
377 377 while (i.hasNext()) {
378 378 i.next();
379 379 if(i.value()->isVisible()) return i.value();
380 380 }
381 381 return 0;
382 382 }
383 383 return m_seriesAxisXMap.value(series);
384 384 }
385 385
386 386 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
387 387 {
388 388 if(series == 0) {
389 389 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap);
390 390
391 391 while (i.hasNext()) {
392 392 i.next();
393 393 if(i.value()->isVisible()) return i.value();
394 394 }
395 395 return 0;
396 396 }
397 397 return m_seriesAxisYMap.value(series);
398 398 }
399 399
400 400 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation)
401 401 {
402 402 Q_ASSERT(axis);
403 403
404 404 if(!series) {
405 405 qWarning() << "Series not found on the chart.";
406 406 return;
407 407 }
408 408
409 409 Domain* domain = m_seriesDomainMap.value(series);
410 410
411 411 if(!domain) {
412 412 qWarning() << "Series not found on the chart.";
413 413 return;
414 414 }
415 415
416 416 if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) {
417 417 qWarning()<<"Axis already defined as axis Y";
418 418 return;
419 419 }
420 420
421 421 if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) {
422 422 qWarning()<<"Axis already defined as axis X";
423 423 return;
424 424 }
425 425
426 426 axis->d_ptr->setOrientation(orientation);
427 427
428 428 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
429 429
430 430 if(orientation==Qt::Vertical) {
431 431 seriesAxisMap= &m_seriesAxisYMap;
432 432 }else{
433 433 seriesAxisMap= &m_seriesAxisXMap;
434 434 }
435 435
436 436 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
437 437 QList<QAbstractAxis*> axes = seriesAxisMap->values();
438 438 if(oldAxis) {
439 439 if(axes.indexOf(oldAxis)==-1) {
440 440 emit axisRemoved(oldAxis);
441 441 oldAxis->disconnect();
442 442 QObject::disconnect(domain,0,oldAxis,0);
443 443 oldAxis->d_ptr->m_dataset=0;
444 444 oldAxis->deleteLater();
445 445 }
446 446 }
447 447
448 448 if(axes.indexOf(axis)==-1) {
449 449 initializeAxis(axis,series);
450 450 emit axisAdded(axis,domain);
451 451 }else{
452 452 initializeAxis(axis,series);
453 453 }
454 454 }
455 455
456 456 Domain* ChartDataSet::domain(QAbstractSeries *series) const
457 457 {
458 458 return m_seriesDomainMap.value(series);
459 459 }
460 460
461 461 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
462 462 {
463 463 blockAxisSignals(true);
464 464 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
465 465 while (i.hasNext()) {
466 466 i.next();
467 467 i.value()->move(dx,dy,size);
468 468 }
469 469 blockAxisSignals(false);
470 470 }
471 471
472 472 QList<QAbstractSeries*> ChartDataSet::series() const
473 473 {
474 474 return m_seriesDomainMap.keys();
475 475 }
476 476
477 477 void ChartDataSet::updateSeries(QAbstractSeries *series)
478 478 {
479 479 emit seriesUpdated(series);
480 480 }
481 481
482 482 #include "moc_chartdataset_p.cpp"
483 483
484 484 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,469 +1,469
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qxyseries.h"
22 22 #include "qxyseries_p.h"
23 23 #include "domain_p.h"
24 24 #include "legendmarker_p.h"
25 #include "qvaluesaxis.h"
25 #include "qvalueaxis.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 /*!
30 30 \class QXYSeries
31 31 \brief The QXYSeries class is a base class for line, spline and scatter series.
32 32 */
33 33 /*!
34 34 \qmlclass XYSeries
35 35 \inherits AbstractSeries
36 36 The XYSeries class is a base class for line, spline and scatter series.
37 37
38 38 The class cannot be instantiated directly.
39 39 */
40 40
41 41 /*!
42 42 \property QXYSeries::pointsVisible
43 43 Controls if the data points are visible and should be drawn.
44 44 */
45 45 /*!
46 46 \qmlproperty bool XYSeries::pointsVisible
47 47 Controls if the data points are visible and should be drawn.
48 48 */
49 49
50 50 /*!
51 51 \fn QPen QXYSeries::pen() const
52 52 \brief Returns pen used to draw points for series.
53 53 \sa setPen()
54 54 */
55 55
56 56 /*!
57 57 \fn QBrush QXYSeries::brush() const
58 58 \brief Returns brush used to draw points for series.
59 59 \sa setBrush()
60 60 */
61 61
62 62 /*!
63 63 \property QXYSeries::color
64 64 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
65 65 fill (brush) color in case of QScatterSeries or QAreaSeries.
66 66 \sa QXYSeries::pen(), QXYSeries::brush()
67 67 */
68 68 /*!
69 69 \qmlproperty color XYSeries::color
70 70 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
71 71 fill (brush) color in case of ScatterSeries or AreaSeries.
72 72 */
73 73
74 74 /*!
75 75 \fn void QXYSeries::clicked(const QPointF& point)
76 76 \brief Signal is emitted when user clicks the \a point on chart.
77 77 */
78 78 /*!
79 79 \qmlsignal XYSeries::onClicked(QPointF point)
80 80 Signal is emitted when user clicks the \a point on chart. For example:
81 81 \code
82 82 LineSeries {
83 83 XYPoint { x: 0; y: 0 }
84 84 XYPoint { x: 1.1; y: 2.1 }
85 85 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
86 86 }
87 87 \endcode
88 88 */
89 89
90 90 /*!
91 91 \fn void QXYSeries::pointReplaced(int index)
92 92 Signal is emitted when a point has been replaced at \a index.
93 93 \sa replace()
94 94 */
95 95 /*!
96 96 \qmlsignal XYSeries::onPointReplaced(int index)
97 97 Signal is emitted when a point has been replaced at \a index.
98 98 */
99 99
100 100 /*!
101 101 \fn void QXYSeries::pointsReplaced()
102 102 Signal is emitted when all points have been replaced with another points.
103 103 \sa replace()
104 104 */
105 105 /*!
106 106 \qmlsignal XYSeries::onPointsReplaced()
107 107 */
108 108
109 109 /*!
110 110 \fn void QXYSeries::pointAdded(int index)
111 111 Signal is emitted when a point has been added at \a index.
112 112 \sa append(), insert()
113 113 */
114 114 /*!
115 115 \qmlsignal XYSeries::onPointAdded(int index)
116 116 Signal is emitted when a point has been added at \a index.
117 117 */
118 118
119 119 /*!
120 120 \fn void QXYSeries::pointRemoved(int index)
121 121 Signal is emitted when a point has been removed from \a index.
122 122 \sa remove()
123 123 */
124 124 /*!
125 125 \qmlsignal XYSeries::onPointRemoved(int index)
126 126 Signal is emitted when a point has been removed from \a index.
127 127 */
128 128
129 129 /*!
130 130 \fn void QXYSeries::colorChanged(QColor color)
131 131 \brief Signal is emitted when the line (pen) color has changed to \a color.
132 132 */
133 133 /*!
134 134 \qmlsignal XYSeries::onColorChanged(color color)
135 135 Signal is emitted when the line (pen) color has changed to \a color.
136 136 */
137 137
138 138 /*!
139 139 \fn void QXYSeriesPrivate::updated()
140 140 \brief \internal
141 141 */
142 142
143 143 /*!
144 144 \qmlmethod XYSeries::append(real x, real y)
145 145 Append point (\a x, \a y) to the series
146 146 */
147 147
148 148 /*!
149 149 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
150 150 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
151 151 exist.
152 152 */
153 153
154 154 /*!
155 155 \qmlmethod XYSeries::remove(real x, real y)
156 156 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
157 157 */
158 158
159 159 /*!
160 160 \qmlmethod XYSeries::insert(int index, real x, real y)
161 161 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
162 162 points. If index is the same as or bigger than count, the point is appended to the list of points.
163 163 */
164 164
165 165 /*!
166 166 \qmlmethod QPointF XYSeries::at(int index)
167 167 Returns point at \a index. Returns (0, 0) if the index is not valid.
168 168 */
169 169
170 170 /*!
171 171 \internal
172 172
173 173 Constructs empty series object which is a child of \a parent.
174 174 When series object is added to QChartView or QChart instance ownerships is transferred.
175 175 */
176 176 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
177 177 {
178 178 }
179 179
180 180 /*!
181 181 Destroys the object. Series added to QChartView or QChart instances are owned by those,
182 182 and are deleted when mentioned object are destroyed.
183 183 */
184 184 QXYSeries::~QXYSeries()
185 185 {
186 186 }
187 187
188 188 /*!
189 189 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
190 190 */
191 191 void QXYSeries::append(qreal x,qreal y)
192 192 {
193 193 append(QPointF(x,y));
194 194 }
195 195
196 196 /*!
197 197 This is an overloaded function.
198 198 Adds data \a point to the series. Points are connected with lines on the chart.
199 199 */
200 200 void QXYSeries::append(const QPointF &point)
201 201 {
202 202 Q_D(QXYSeries);
203 203 d->m_points<<point;
204 204 emit pointAdded(d->m_points.count()-1);
205 205 }
206 206
207 207 /*!
208 208 This is an overloaded function.
209 209 Adds list of data \a points to the series. Points are connected with lines on the chart.
210 210 */
211 211 void QXYSeries::append(const QList<QPointF> &points)
212 212 {
213 213 foreach(const QPointF& point , points) {
214 214 append(point);
215 215 }
216 216 }
217 217
218 218 /*!
219 219 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
220 220 \sa QXYSeries::pointReplaced()
221 221 */
222 222 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
223 223 {
224 224 replace(QPointF(oldX,oldY),QPointF(newX,newY));
225 225 }
226 226
227 227 /*!
228 228 Replaces \a oldPoint with \a newPoint.
229 229 \sa QXYSeries::pointReplaced()
230 230 */
231 231 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
232 232 {
233 233 Q_D(QXYSeries);
234 234 int index = d->m_points.indexOf(oldPoint);
235 235 if(index==-1) return;
236 236 d->m_points[index] = newPoint;
237 237 emit pointReplaced(index);
238 238 }
239 239
240 240 /*!
241 241 Replaces the current points with \a points. This is faster than replacing data points one by one,
242 242 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
243 243 when the points have been replaced.
244 244 \sa QXYSeries::pointsReplaced()
245 245 */
246 246 void QXYSeries::replace(QList<QPointF> points)
247 247 {
248 248 Q_D(QXYSeries);
249 249 d->m_points = points.toVector();
250 250 emit pointsReplaced();
251 251 }
252 252
253 253 /*!
254 254 Removes current \a x and \a y value.
255 255 */
256 256 void QXYSeries::remove(qreal x,qreal y)
257 257 {
258 258 remove(QPointF(x,y));
259 259 }
260 260
261 261 /*!
262 262 Removes current \a point x value.
263 263
264 264 Note: point y value is ignored.
265 265 */
266 266 void QXYSeries::remove(const QPointF &point)
267 267 {
268 268 Q_D(QXYSeries);
269 269 int index = d->m_points.indexOf(point);
270 270 if(index==-1) return;
271 271 d->m_points.remove(index);
272 272 emit pointRemoved(index);
273 273 }
274 274
275 275 /*!
276 276 Inserts a \a point in the series at \a index position.
277 277 */
278 278 void QXYSeries::insert(int index, const QPointF &point)
279 279 {
280 280 Q_D(QXYSeries);
281 281 d->m_points.insert(index, point);
282 282 emit pointAdded(index);
283 283 }
284 284
285 285 /*!
286 286 Removes all points from the series.
287 287 */
288 288 void QXYSeries::clear()
289 289 {
290 290 Q_D(QXYSeries);
291 291 for (int i = d->m_points.size() - 1; i >= 0; i--)
292 292 remove(d->m_points.at(i));
293 293 }
294 294
295 295 /*!
296 296 Returns list of points in the series.
297 297 */
298 298 QList<QPointF> QXYSeries::points() const
299 299 {
300 300 Q_D(const QXYSeries);
301 301 return d->m_points.toList();
302 302 }
303 303
304 304 /*!
305 305 Returns number of data points within series.
306 306 */
307 307 int QXYSeries::count() const
308 308 {
309 309 Q_D(const QXYSeries);
310 310 return d->m_points.count();
311 311 }
312 312
313 313
314 314 /*!
315 315 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
316 316 pen from chart theme is used.
317 317 \sa QChart::setTheme()
318 318 */
319 319 void QXYSeries::setPen(const QPen &pen)
320 320 {
321 321 Q_D(QXYSeries);
322 322 if (d->m_pen != pen) {
323 323 bool emitColorChanged = d->m_pen.color() != pen.color();
324 324 d->m_pen = pen;
325 325 emit d->updated();
326 326 if (emitColorChanged)
327 327 emit colorChanged(pen.color());
328 328 }
329 329 }
330 330
331 331 QPen QXYSeries::pen() const
332 332 {
333 333 Q_D(const QXYSeries);
334 334 return d->m_pen;
335 335 }
336 336
337 337 /*!
338 338 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
339 339 from chart theme setting is used.
340 340 \sa QChart::setTheme()
341 341 */
342 342 void QXYSeries::setBrush(const QBrush &brush)
343 343 {
344 344 Q_D(QXYSeries);
345 345 if (d->m_brush!=brush) {
346 346 d->m_brush = brush;
347 347 emit d->updated();
348 348 }
349 349 }
350 350
351 351 QBrush QXYSeries::brush() const
352 352 {
353 353 Q_D(const QXYSeries);
354 354 return d->m_brush;
355 355 }
356 356
357 357 void QXYSeries::setColor(const QColor &color)
358 358 {
359 359 QPen p = pen();
360 360 if (p.color() != color) {
361 361 p.setColor(color);
362 362 setPen(p);
363 363 }
364 364 }
365 365
366 366 QColor QXYSeries::color() const
367 367 {
368 368 return pen().color();
369 369 }
370 370
371 371 void QXYSeries::setPointsVisible(bool visible)
372 372 {
373 373 Q_D(QXYSeries);
374 374 if (d->m_pointsVisible != visible){
375 375 d->m_pointsVisible = visible;
376 376 emit d->updated();
377 377 }
378 378 }
379 379
380 380 bool QXYSeries::pointsVisible() const
381 381 {
382 382 Q_D(const QXYSeries);
383 383 return d->m_pointsVisible;
384 384 }
385 385
386 386
387 387 /*!
388 388 Stream operator for adding a data \a point to the series.
389 389 \sa append()
390 390 */
391 391 QXYSeries& QXYSeries::operator<< (const QPointF &point)
392 392 {
393 393 append(point);
394 394 return *this;
395 395 }
396 396
397 397
398 398 /*!
399 399 Stream operator for adding a list of \a points to the series.
400 400 \sa append()
401 401 */
402 402
403 403 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
404 404 {
405 405 append(points);
406 406 return *this;
407 407 }
408 408
409 409 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
410 410
411 411
412 412 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
413 413 QAbstractSeriesPrivate(q),
414 414 m_pointsVisible(false)
415 415 {
416 416 }
417 417
418 418 void QXYSeriesPrivate::scaleDomain(Domain& domain)
419 419 {
420 420 qreal minX(0);
421 421 qreal minY(0);
422 422 qreal maxX(1);
423 423 qreal maxY(1);
424 424
425 425 Q_Q(QXYSeries);
426 426
427 427 const QList<QPointF>& points = q->points();
428 428
429 429 if (!points.isEmpty()){
430 430 minX = points[0].x();
431 431 minY = points[0].y();
432 432 maxX = minX;
433 433 maxY = minY;
434 434
435 435 for (int i = 0; i < points.count(); i++) {
436 436 qreal x = points[i].x();
437 437 qreal y = points[i].y();
438 438 minX = qMin(minX, x);
439 439 minY = qMin(minY, y);
440 440 maxX = qMax(maxX, x);
441 441 maxY = qMax(maxY, y);
442 442 }
443 443 }
444 444
445 445 domain.setRange(minX,maxX,minY,maxY);
446 446 }
447 447
448 448 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
449 449 {
450 450 Q_Q(QXYSeries);
451 451 QList<LegendMarker*> list;
452 452 return list << new XYLegendMarker(q,legend);
453 453 }
454 454
455 455 void QXYSeriesPrivate::initializeAxis(QAbstractAxis* axis)
456 456 {
457 457 Q_UNUSED(axis);
458 458 }
459 459
460 460 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
461 461 {
462 462 Q_UNUSED(orientation);
463 463 return QAbstractAxis::AxisTypeValues;
464 464 }
465 465
466 466 #include "moc_qxyseries.cpp"
467 467 #include "moc_qxyseries_p.cpp"
468 468
469 469 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,107 +1,107
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef XYCHARTITEM_H
31 31 #define XYCHARTITEM_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "chartitem_p.h"
35 35 #include "xyanimation_p.h"
36 #include "qvaluesaxis.h"
36 #include "qvalueaxis.h"
37 37 #include <QPen>
38 38
39 39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 40
41 41 class ChartPresenter;
42 42 class QXYSeries;
43 43
44 44 class XYChart : public ChartElement
45 45 {
46 46 Q_OBJECT
47 47 public:
48 48 explicit XYChart(QXYSeries *series, ChartPresenter *presenter);
49 49 ~XYChart() {}
50 50
51 51 void setGeometryPoints(const QVector<QPointF>& points);
52 52 QVector<QPointF> geometryPoints() const { return m_points; }
53 53
54 54 void setClipRect(const QRectF &rect);
55 55 QRectF clipRect() const { return m_clipRect; }
56 56
57 57 QSizeF size() const { return m_size; }
58 58 QPointF origin() const { return m_origin; }
59 59
60 60 void setAnimation(XYAnimation* animation);
61 61 ChartAnimation* animation() const { return m_animation; }
62 62 virtual void updateGeometry() = 0;
63 63
64 64 bool isDirty() const { return m_dirty; }
65 65 void setDirty(bool dirty);
66 66
67 67 public Q_SLOTS:
68 68 void handlePointAdded(int index);
69 69 void handlePointRemoved(int index);
70 70 void handlePointReplaced(int index);
71 71 void handlePointsReplaced();
72 72 void handleDomainUpdated();
73 73 void handleGeometryChanged(const QRectF &size);
74 74
75 75 Q_SIGNALS:
76 76 void clicked(const QPointF& point);
77 77
78 78 protected:
79 79 virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1);
80 80 QPointF calculateGeometryPoint(const QPointF &point) const;
81 81 QPointF calculateGeometryPoint(int index) const;
82 82 QPointF calculateDomainPoint(const QPointF &point) const;
83 83 QVector<QPointF> calculateGeometryPoints() const;
84 84
85 85 private:
86 86 inline bool isEmpty();
87 87
88 88 protected:
89 89 qreal m_minX;
90 90 qreal m_maxX;
91 91 qreal m_minY;
92 92 qreal m_maxY;
93 93 QXYSeries* m_series;
94 94 QSizeF m_size;
95 95 QPointF m_origin;
96 96 QRectF m_clipRect;
97 97 QVector<QPointF> m_points;
98 98 XYAnimation* m_animation;
99 99 bool m_dirty;
100 100
101 101 friend class AreaChartItem;
102 102
103 103 };
104 104
105 105 QTCOMMERCIALCHART_END_NAMESPACE
106 106
107 107 #endif
@@ -1,30 +1,30
1 1 !include( ../tests.pri ) {
2 2 error( "Couldn't find the tests.pri file!" )
3 3 }
4 4
5 5 TEMPLATE = subdirs
6 6 SUBDIRS += \
7 7 qchartview \
8 8 qchart \
9 9 qlineseries \
10 10 qbarset \
11 11 qbarseries \
12 12 qstackedbarseries \
13 13 qpercentbarseries \
14 14 qpieslice qpieseries \
15 15 qpiemodelmapper \
16 16 qsplineseries \
17 17 qscatterseries \
18 18 qxymodelmapper \
19 19 qbarmodelmapper \
20 20 qhorizontalbarseries \
21 21 qhorizontalstackedbarseries \
22 22 qhorizontalpercentbarseries \
23 qvaluesaxis \
23 qvalueaxis \
24 24 qintervalsaxis \
25 25 qdatetimeaxis \
26 26 qbarcategoriesaxis
27 27
28 28 test_private:{
29 29 SUBDIRS += domain chartdataset
30 30 }
@@ -1,623 +1,623
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtTest/QtTest>
22 22 #include <qabstractaxis.h>
23 #include <qvaluesaxis.h>
23 #include <qvalueaxis.h>
24 24 #include <qbarcategoriesaxis.h>
25 25 #include <qlineseries.h>
26 26 #include <qareaseries.h>
27 27 #include <qscatterseries.h>
28 28 #include <qsplineseries.h>
29 29 #include <qpieseries.h>
30 30 #include <qbarseries.h>
31 31 #include <qpercentbarseries.h>
32 32 #include <qstackedbarseries.h>
33 33 #include <private/chartdataset_p.h>
34 34 #include <private/domain_p.h>
35 35 #include <tst_definitions.h>
36 36
37 37 QTCOMMERCIALCHART_USE_NAMESPACE
38 38
39 39 Q_DECLARE_METATYPE(Domain *)
40 40 Q_DECLARE_METATYPE(QAbstractAxis *)
41 41 Q_DECLARE_METATYPE(QAbstractSeries *)
42 42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
43 43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
44 44 Q_DECLARE_METATYPE(QLineSeries *)
45 45
46 46 class tst_ChartDataSet: public QObject {
47 47
48 48 Q_OBJECT
49 49
50 50 public Q_SLOTS:
51 51 void initTestCase();
52 52 void cleanupTestCase();
53 53 void init();
54 54 void cleanup();
55 55
56 56 private Q_SLOTS:
57 57 void chartdataset_data();
58 58 void chartdataset();
59 59 void addSeries_data();
60 60 void addSeries();
61 61 void setAxisX_data();
62 62 void setAxisX();
63 63 void setAxisY_data();
64 64 void setAxisY();
65 65 void removeSeries_data();
66 66 void removeSeries();
67 67 void removeAllSeries_data();
68 68 void removeAllSeries();
69 69 void seriesCount_data();
70 70 void seriesCount();
71 71 void seriesIndex_data();
72 72 void seriesIndex();
73 73 void domain_data();
74 74 void domain();
75 75 void zoomInDomain_data();
76 76 void zoomInDomain();
77 77 void zoomOutDomain_data();
78 78 void zoomOutDomain();
79 79 void scrollDomain_data();
80 80 void scrollDomain();
81 81
82 82 private:
83 83 ChartDataSet* m_dataset;
84 84 };
85 85
86 86 void tst_ChartDataSet::initTestCase()
87 87 {
88 88 qRegisterMetaType<Domain*>();
89 89 qRegisterMetaType<QAbstractAxis*>();
90 90 qRegisterMetaType<QAbstractSeries*>();
91 91 }
92 92
93 93 void tst_ChartDataSet::cleanupTestCase()
94 94 {
95 95 }
96 96
97 97 void tst_ChartDataSet::init()
98 98 {
99 99 m_dataset = new ChartDataSet();
100 100 }
101 101
102 102
103 103 void tst_ChartDataSet::cleanup()
104 104 {
105 105 QList<QAbstractSeries*> series = m_dataset->series();
106 106 foreach(QAbstractSeries* serie, series)
107 107 {
108 108 m_dataset->removeSeries(serie);
109 109 }
110 110 }
111 111
112 112 void tst_ChartDataSet::chartdataset_data()
113 113 {
114 114 }
115 115
116 116 void tst_ChartDataSet::chartdataset()
117 117 {
118 118 QVERIFY(m_dataset->axisX(0) == 0);
119 119 QVERIFY(m_dataset->axisY(0) == 0);
120 120 QLineSeries* series = new QLineSeries(this);
121 121 QCOMPARE(m_dataset->seriesIndex(series),-1);
122 122 QVERIFY(m_dataset->domain(series) == 0);
123 123 QVERIFY(m_dataset->axisX(series) == 0);
124 124 QVERIFY(m_dataset->axisY(series) == 0);
125 125 m_dataset->createDefaultAxes();
126 126 }
127 127
128 128
129 129 void tst_ChartDataSet::addSeries_data()
130 130 {
131 131 QTest::addColumn<QAbstractSeries*>("series");
132 132
133 133 QAbstractSeries* line = new QLineSeries(this);
134 134 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
135 135 QAbstractSeries* scatter = new QScatterSeries(this);
136 136 QAbstractSeries* spline = new QSplineSeries(this);
137 137 QAbstractSeries* pie = new QPieSeries(this);
138 138 QAbstractSeries* bar = new QBarSeries(this);
139 139 QAbstractSeries* percent = new QPercentBarSeries(this);
140 140 QAbstractSeries* stacked = new QStackedBarSeries(this);
141 141
142 142 QTest::newRow("line") << line;
143 143 QTest::newRow("area") << area;
144 144 QTest::newRow("scatter") << scatter;
145 145 QTest::newRow("spline") << spline;
146 146 QTest::newRow("pie") << pie;
147 147 QTest::newRow("bar") << bar;
148 148 QTest::newRow("percent") << percent;
149 149 QTest::newRow("stacked") << stacked;
150 150 }
151 151
152 152 void tst_ChartDataSet::addSeries()
153 153 {
154 154
155 155 QFETCH(QAbstractSeries*, series);
156 156
157 157 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
158 158 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
159 159 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
160 160 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
161 161
162 162 m_dataset->addSeries(series);
163 163 m_dataset->createDefaultAxes();
164 164 if(series->type()==QAbstractSeries::SeriesTypePie){
165 165 TRY_COMPARE(spy0.count(), 0);
166 166 }else{
167 167 TRY_COMPARE(spy0.count(), 2);
168 168 }
169 169 TRY_COMPARE(spy1.count(), 0);
170 170 TRY_COMPARE(spy2.count(), 1);
171 171 TRY_COMPARE(spy3.count(), 0);
172 172 }
173 173
174 174
175 175 void tst_ChartDataSet::setAxisX_data()
176 176 {
177 177 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
178 178 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
179 179 QTest::addColumn<int>("axisCount");
180 180
181 181 QAbstractSeries* line = new QLineSeries(this);
182 182 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
183 183 QAbstractSeries* scatter = new QScatterSeries(this);
184 184 QAbstractSeries* spline = new QSplineSeries(this);
185 185 QAbstractSeries* pie = new QPieSeries(this);
186 186 QAbstractSeries* bar = new QBarSeries(this);
187 187 QAbstractSeries* percent = new QPercentBarSeries(this);
188 188 QAbstractSeries* stacked = new QStackedBarSeries(this);
189 189
190 190 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
191 191 << (QList<QAbstractSeries*>() << line << spline << scatter)
192 192 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3;
193 193
194 194 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
195 195 << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1;
196 196
197 197 QList<QAbstractAxis*> axes0;
198 198 axes0 << new QValueAxis(this) << new QValueAxis(this);
199 199 axes0 << axes0.last();
200 200 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
201 201 << (QList<QAbstractSeries*>() << line << spline << scatter)
202 202 << axes0 << 2;
203 203 //TODO: add more test cases
204 204 }
205 205
206 206 void tst_ChartDataSet::setAxisX()
207 207 {
208 208 QFETCH(QList<QAbstractSeries*>, seriesList);
209 209 QFETCH(QList<QAbstractAxis*>, axisList);
210 210 QFETCH(int, axisCount);
211 211
212 212 Q_ASSERT(seriesList.count() == axisList.count());
213 213
214 214 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
215 215 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
216 216 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
217 217 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
218 218
219 219 foreach(QAbstractSeries* series, seriesList){
220 220 m_dataset->addSeries(series);
221 221 }
222 222
223 223 TRY_COMPARE(spy0.count(), 0);
224 224 TRY_COMPARE(spy1.count(), 0);
225 225 TRY_COMPARE(spy2.count(), seriesList.count());
226 226 TRY_COMPARE(spy3.count(), 0);
227 227
228 228 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
229 229 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
230 230 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
231 231 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
232 232
233 233 for(int i=0 ; i < seriesList.count(); i++){
234 234 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal);
235 235 }
236 236
237 237 TRY_COMPARE(spy4.count(), axisCount);
238 238 TRY_COMPARE(spy5.count(), 0);
239 239 TRY_COMPARE(spy6.count(), 0);
240 240 TRY_COMPARE(spy7.count(), 0);
241 241
242 242 for(int i=0 ; i < seriesList.count(); i++){
243 243 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
244 244 }
245 245 }
246 246
247 247 void tst_ChartDataSet::setAxisY_data()
248 248 {
249 249 setAxisX_data();
250 250 }
251 251
252 252 void tst_ChartDataSet::setAxisY()
253 253 {
254 254 QFETCH(QList<QAbstractSeries*>, seriesList);
255 255 QFETCH(QList<QAbstractAxis*>, axisList);
256 256 QFETCH(int, axisCount);
257 257
258 258 Q_ASSERT(seriesList.count() == axisList.count());
259 259
260 260 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
261 261 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
262 262 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
263 263 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
264 264
265 265 foreach(QAbstractSeries* series, seriesList){
266 266 m_dataset->addSeries(series);
267 267 }
268 268
269 269 TRY_COMPARE(spy0.count(), 0);
270 270 TRY_COMPARE(spy1.count(), 0);
271 271 TRY_COMPARE(spy2.count(), seriesList.count());
272 272 TRY_COMPARE(spy3.count(), 0);
273 273
274 274 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
275 275 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
276 276 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
277 277 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
278 278
279 279 for(int i=0 ; i < seriesList.count(); i++){
280 280 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical);
281 281 }
282 282
283 283 TRY_COMPARE(spy4.count(), axisCount);
284 284 TRY_COMPARE(spy5.count(), 0);
285 285 TRY_COMPARE(spy6.count(), 0);
286 286 TRY_COMPARE(spy7.count(), 0);
287 287
288 288 for(int i=0 ; i < seriesList.count(); i++){
289 289 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
290 290 }
291 291 }
292 292
293 293 void tst_ChartDataSet::removeSeries_data()
294 294 {
295 295 addSeries_data();
296 296 }
297 297
298 298 void tst_ChartDataSet::removeSeries()
299 299 {
300 300 QFETCH(QAbstractSeries*, series);
301 301
302 302 m_dataset->addSeries(series);
303 303 m_dataset->createDefaultAxes();
304 304
305 305 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
306 306 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
307 307 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
308 308 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
309 309
310 310 m_dataset->removeSeries(series);
311 311
312 312 TRY_COMPARE(spy0.count(), 0);
313 313 if (series->type() == QAbstractSeries::SeriesTypePie) {
314 314 TRY_COMPARE(spy1.count(), 0);
315 315 }
316 316 else {
317 317 TRY_COMPARE(spy1.count(), 2);
318 318 }
319 319 TRY_COMPARE(spy2.count(), 0);
320 320 TRY_COMPARE(spy3.count(), 1);
321 321 }
322 322
323 323 void tst_ChartDataSet::removeAllSeries_data()
324 324 {
325 325 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
326 326 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
327 327 QTest::addColumn<int>("axisCount");
328 328
329 329 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
330 330 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
331 331 << new QScatterSeries(this))
332 332 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this)
333 333 << new QValueAxis(this)) << 3;
334 334 //TODO:
335 335 }
336 336
337 337 void tst_ChartDataSet::removeAllSeries()
338 338 {
339 339 QFETCH(QList<QAbstractSeries*>, seriesList);
340 340 QFETCH(QList<QAbstractAxis*>, axisList);
341 341 QFETCH(int, axisCount);
342 342
343 343 foreach(QAbstractSeries* series, seriesList) {
344 344 m_dataset->addSeries(series);
345 345 }
346 346
347 347 for (int i = 0; i < seriesList.count(); i++) {
348 348 m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal);
349 349 }
350 350
351 351 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
352 352 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
353 353 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
354 354 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
355 355
356 356 m_dataset->removeAllSeries();
357 357
358 358 TRY_COMPARE(spy0.count(), 0);
359 359 TRY_COMPARE(spy1.count(), axisCount);
360 360 TRY_COMPARE(spy2.count(), 0);
361 361 TRY_COMPARE(spy3.count(), seriesList.count());
362 362 }
363 363
364 364
365 365 void tst_ChartDataSet::seriesCount_data()
366 366 {
367 367 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
368 368 QTest::addColumn<int>("seriesCount");
369 369
370 370 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
371 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 374 void tst_ChartDataSet::seriesCount()
375 375 {
376 376 QFETCH(QList<QAbstractSeries*>, seriesList);
377 377 QFETCH(int, seriesCount);
378 378
379 379 foreach(QAbstractSeries* series, seriesList){
380 380 m_dataset->addSeries(series);
381 381 }
382 382
383 383 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
384 384 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
385 385 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
386 386 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
387 387
388 388 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
389 389 TRY_COMPARE(spy0.count(), 0);
390 390 TRY_COMPARE(spy1.count(), 0);
391 391 TRY_COMPARE(spy2.count(), 0);
392 392 TRY_COMPARE(spy3.count(), 0);
393 393 }
394 394
395 395 void tst_ChartDataSet::seriesIndex_data()
396 396 {
397 397 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
398 398
399 399 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
400 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 403 void tst_ChartDataSet::seriesIndex()
404 404 {
405 405
406 406 QFETCH(QList<QAbstractSeries*>, seriesList);
407 407
408 408 foreach(QAbstractSeries* series, seriesList) {
409 409 m_dataset->addSeries(series);
410 410 }
411 411
412 412 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
413 413 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
414 414 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
415 415 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
416 416
417 417 for (int i = 0; i < seriesList.count(); i++) {
418 418 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
419 419 }
420 420
421 421 TRY_COMPARE(spy0.count(), 0);
422 422 TRY_COMPARE(spy1.count(), 0);
423 423 TRY_COMPARE(spy2.count(), 0);
424 424 TRY_COMPARE(spy3.count(), 0);
425 425
426 426 foreach(QAbstractSeries* series, seriesList) {
427 427 m_dataset->removeSeries(series);
428 428 }
429 429
430 430 for (int i = 0; i < seriesList.count(); i++) {
431 431 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
432 432 }
433 433
434 434 foreach(QAbstractSeries* series, seriesList) {
435 435 m_dataset->addSeries(series);
436 436 }
437 437
438 438 for (int i = 0; i < seriesList.count(); i++) {
439 439 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
440 440 }
441 441
442 442 m_dataset->removeSeries(seriesList.at(1));
443 443
444 444 for (int i = 0; i < seriesList.count(); i++) {
445 445 if (i != 1)
446 446 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
447 447 else
448 448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
449 449 }
450 450
451 451 m_dataset->addSeries(seriesList.at(1));
452 452
453 453 for (int i = 0; i < seriesList.count(); i++) {
454 454 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
455 455 }
456 456
457 457 m_dataset->removeSeries(seriesList.at(2));
458 458
459 459 for (int i = 0; i < seriesList.count(); i++) {
460 460 if (i != 2)
461 461 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
462 462 else
463 463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
464 464 }
465 465
466 466 m_dataset->removeSeries(seriesList.at(0));
467 467
468 468 for (int i = 0; i < seriesList.count(); i++) {
469 469 if (i != 2 && i != 0)
470 470 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
471 471 else
472 472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
473 473 }
474 474
475 475 m_dataset->addSeries(seriesList.at(2));
476 476 m_dataset->addSeries(seriesList.at(0));
477 477
478 478 for (int i = 0; i < seriesList.count(); i++) {
479 479 if (i == 2)
480 480 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
481 481 else if (i == 0)
482 482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
483 483 else
484 484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
485 485 }
486 486
487 487 }
488 488
489 489 void tst_ChartDataSet::domain_data()
490 490 {
491 491 addSeries_data();
492 492 }
493 493
494 494 void tst_ChartDataSet::domain()
495 495 {
496 496 QFETCH(QAbstractSeries*, series);
497 497
498 498 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
499 499 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
500 500 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
501 501 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
502 502
503 503 m_dataset->addSeries(series);
504 504 QVERIFY(m_dataset->domain(series));
505 505
506 506
507 507 TRY_COMPARE(spy0.count(), 0);
508 508 TRY_COMPARE(spy1.count(), 0);
509 509 TRY_COMPARE(spy2.count(), 1);
510 510
511 511 QList<QVariant> arguments = spy2.takeFirst();
512 512 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
513 513 QVERIFY(m_dataset->domain(series) == domain);
514 514
515 515 TRY_COMPARE(spy3.count(), 0);
516 516
517 517 }
518 518
519 519 void tst_ChartDataSet::zoomInDomain_data()
520 520 {
521 521 QTest::addColumn<bool >("sameAxis");
522 522 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
523 523 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
524 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 527 void tst_ChartDataSet::zoomInDomain()
528 528 {
529 529 QFETCH(bool, sameAxis);
530 530 QFETCH(QList<QAbstractSeries*>, seriesList);
531 531
532 532 foreach(QAbstractSeries* series, seriesList) {
533 533 m_dataset->addSeries(series);
534 534 }
535 535
536 536 if(sameAxis) m_dataset->createDefaultAxes();
537 537
538 538 QList<QSignalSpy*> spyList;
539 539
540 540 foreach(QAbstractSeries* series, seriesList) {
541 541 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated()));
542 542 }
543 543
544 544 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
545 545
546 546 foreach(QSignalSpy* spy, spyList) {
547 547 TRY_COMPARE(spy->count(), 1);
548 548 }
549 549
550 550 qDeleteAll(spyList);
551 551 }
552 552
553 553
554 554
555 555 void tst_ChartDataSet::zoomOutDomain_data()
556 556 {
557 557 zoomInDomain_data();
558 558 }
559 559
560 560 void tst_ChartDataSet::zoomOutDomain()
561 561 {
562 562 QFETCH(bool, sameAxis);
563 563 QFETCH(QList<QAbstractSeries*>, seriesList);
564 564
565 565 foreach(QAbstractSeries* series, seriesList) {
566 566 m_dataset->addSeries(series);
567 567 }
568 568
569 569 if (sameAxis)
570 570 m_dataset->createDefaultAxes();
571 571
572 572 QList<QSignalSpy*> spyList;
573 573
574 574 foreach(QAbstractSeries* series, seriesList) {
575 575 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated()));
576 576 }
577 577
578 578 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
579 579
580 580 foreach(QSignalSpy* spy, spyList) {
581 581 TRY_COMPARE(spy->count(), 1);
582 582 }
583 583
584 584 qDeleteAll (spyList);
585 585 }
586 586
587 587 void tst_ChartDataSet::scrollDomain_data()
588 588 {
589 589 zoomInDomain_data();
590 590 }
591 591
592 592 void tst_ChartDataSet::scrollDomain()
593 593 {
594 594 QFETCH(bool, sameAxis);
595 595 QFETCH(QList<QAbstractSeries*>, seriesList);
596 596
597 597 foreach(QAbstractSeries* series, seriesList) {
598 598 m_dataset->addSeries(series);
599 599 }
600 600
601 601 if (sameAxis)
602 602 m_dataset->createDefaultAxes();
603 603
604 604 QList<QSignalSpy*> spyList;
605 605
606 606 foreach(QAbstractSeries* series, seriesList) {
607 607 spyList
608 608 << new QSignalSpy(m_dataset->domain(series),
609 609 SIGNAL(updated()));
610 610 }
611 611
612 612 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
613 613
614 614 foreach(QSignalSpy* spy, spyList) {
615 615 TRY_COMPARE(spy->count(), 1);
616 616 }
617 617
618 618 qDeleteAll(spyList);
619 619 }
620 620
621 621 QTEST_MAIN(tst_ChartDataSet)
622 622 #include "tst_chartdataset.moc"
623 623
@@ -1,788 +1,788
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtTest/QtTest>
22 22 #include <qchartview.h>
23 23 #include <qlineseries.h>
24 24 #include <qareaseries.h>
25 25 #include <qscatterseries.h>
26 26 #include <qsplineseries.h>
27 27 #include <qpieseries.h>
28 28 #include <qabstractbarseries.h>
29 29 #include <qbarseries.h>
30 30 #include <qpercentbarseries.h>
31 31 #include <qstackedbarseries.h>
32 #include <qvaluesaxis.h>
32 #include <qvalueaxis.h>
33 33 #include <qbarcategoriesaxis.h>
34 34
35 35 QTCOMMERCIALCHART_USE_NAMESPACE
36 36
37 37 Q_DECLARE_METATYPE(QAbstractAxis *)
38 38 Q_DECLARE_METATYPE(QValueAxis *)
39 39 Q_DECLARE_METATYPE(QBarCategoriesAxis *)
40 40 Q_DECLARE_METATYPE(QAbstractSeries *)
41 41 Q_DECLARE_METATYPE(QChart::AnimationOption)
42 42 Q_DECLARE_METATYPE(QBrush)
43 43 Q_DECLARE_METATYPE(QPen)
44 44 Q_DECLARE_METATYPE(QChart::ChartTheme)
45 45
46 46 class tst_QChart : public QObject
47 47 {
48 48 Q_OBJECT
49 49
50 50 public slots:
51 51 void initTestCase();
52 52 void cleanupTestCase();
53 53 void init();
54 54 void cleanup();
55 55
56 56 private slots:
57 57 void qchart_data();
58 58 void qchart();
59 59 void addSeries_data();
60 60 void addSeries();
61 61 void animationOptions_data();
62 62 void animationOptions();
63 63 void axisX_data();
64 64 void axisX();
65 65 void axisY_data();
66 66 void axisY();
67 67 void backgroundBrush_data();
68 68 void backgroundBrush();
69 69 void backgroundPen_data();
70 70 void backgroundPen();
71 71 void isBackgroundVisible_data();
72 72 void isBackgroundVisible();
73 73 void legend_data();
74 74 void legend();
75 75 void margins_data();
76 76 void margins();
77 77 void removeAllSeries_data();
78 78 void removeAllSeries();
79 79 void removeSeries_data();
80 80 void removeSeries();
81 81 void scroll_right_data();
82 82 void scroll_right();
83 83 void scroll_left_data();
84 84 void scroll_left();
85 85 void scroll_up_data();
86 86 void scroll_up();
87 87 void scroll_down_data();
88 88 void scroll_down();
89 89 void theme_data();
90 90 void theme();
91 91 void title_data();
92 92 void title();
93 93 void titleBrush_data();
94 94 void titleBrush();
95 95 void titleFont_data();
96 96 void titleFont();
97 97 void zoomIn_data();
98 98 void zoomIn();
99 99 void zoomOut_data();
100 100 void zoomOut();
101 101
102 102 private:
103 103 void createTestData();
104 104
105 105 private:
106 106 QChartView* m_view;
107 107 QChart* m_chart;
108 108 };
109 109
110 110 void tst_QChart::initTestCase()
111 111 {
112 112
113 113 }
114 114
115 115 void tst_QChart::cleanupTestCase()
116 116 {
117 117
118 118 }
119 119
120 120 void tst_QChart::init()
121 121 {
122 122 m_view = new QChartView(new QChart());
123 123 m_chart = m_view->chart();
124 124 }
125 125
126 126 void tst_QChart::cleanup()
127 127 {
128 128 delete m_view;
129 129 m_view = 0;
130 130 m_chart = 0;
131 131 }
132 132
133 133
134 134 void tst_QChart::createTestData()
135 135 {
136 136 QLineSeries* series0 = new QLineSeries(this);
137 137 *series0 << QPointF(0, 0) << QPointF(100, 100);
138 138 m_chart->addSeries(series0);
139 139 m_view->show();
140 140 QTest::qWaitForWindowShown(m_view);
141 141 }
142 142
143 143 void tst_QChart::qchart_data()
144 144 {
145 145 }
146 146
147 147 void tst_QChart::qchart()
148 148 {
149 149 QVERIFY(m_chart);
150 150 QVERIFY(m_chart->legend());
151 151 QVERIFY(m_chart->legend()->isVisible());
152 152
153 153 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
154 154 QVERIFY(!m_chart->axisX());
155 155 QVERIFY(!m_chart->axisY());
156 156 QVERIFY(m_chart->backgroundBrush()!=QBrush());
157 157 QVERIFY(m_chart->backgroundPen()!=QPen());
158 158 QCOMPARE(m_chart->isBackgroundVisible(), true);
159 159
160 160 QVERIFY(m_chart->margins().top()>0);
161 161 QVERIFY(m_chart->margins().left()>0);
162 162 QVERIFY(m_chart->margins().right()>0);
163 163 QVERIFY(m_chart->margins().bottom()>0);
164 164
165 165 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
166 166 QCOMPARE(m_chart->title(), QString());
167 167
168 168 //QCOMPARE(m_chart->titleBrush(),QBrush());
169 169 //QCOMPARE(m_chart->titleFont(),QFont());
170 170
171 171 m_chart->removeAllSeries();
172 172 m_chart->scroll(0,0);
173 173
174 174 m_chart->zoomIn();
175 175 m_chart->zoomIn(QRectF());
176 176 m_chart->zoomOut();
177 177 }
178 178
179 179 void tst_QChart::addSeries_data()
180 180 {
181 181 QTest::addColumn<QAbstractSeries *>("series");
182 182
183 183 QAbstractSeries* line = new QLineSeries(this);
184 184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
185 185 QAbstractSeries* scatter = new QScatterSeries(this);
186 186 QAbstractSeries* spline = new QSplineSeries(this);
187 187 QAbstractSeries* pie = new QPieSeries(this);
188 188 QAbstractSeries* bar = new QBarSeries(this);
189 189 QAbstractSeries* percent = new QPercentBarSeries(this);
190 190 QAbstractSeries* stacked = new QStackedBarSeries(this);
191 191
192 192 QTest::newRow("lineSeries") << line;
193 193 QTest::newRow("areaSeries") << area;
194 194 QTest::newRow("scatterSeries") << scatter;
195 195 QTest::newRow("splineSeries") << spline;
196 196 QTest::newRow("pieSeries") << pie;
197 197 QTest::newRow("barSeries") << bar;
198 198 QTest::newRow("percentBarSeries") << percent;
199 199 QTest::newRow("stackedBarSeries") << stacked;
200 200
201 201 }
202 202
203 203 void tst_QChart::addSeries()
204 204 {
205 205 QFETCH(QAbstractSeries *, series);
206 206 m_view->show();
207 207 QTest::qWaitForWindowShown(m_view);
208 208 QVERIFY(!series->chart());
209 209 QCOMPARE(m_chart->series().count(), 0);
210 210 m_chart->addSeries(series);
211 211 QCOMPARE(m_chart->series().count(), 1);
212 212 QCOMPARE(m_chart->series().first(), series);
213 213 QVERIFY(series->chart() == m_chart);
214 214 m_chart->createDefaultAxes();
215 215 if(series->type()!=QAbstractSeries::SeriesTypePie){
216 216 QVERIFY(m_chart->axisY(series));
217 217 QVERIFY(m_chart->axisX(series));
218 218 }else{
219 219 QVERIFY(!m_chart->axisY(series));
220 220 QVERIFY(!m_chart->axisX(series));
221 221 }
222 222 m_chart->removeSeries(series);
223 223 QVERIFY(!series->chart());
224 224 QCOMPARE(m_chart->series().count(), 0);
225 225 }
226 226
227 227 void tst_QChart::animationOptions_data()
228 228 {
229 229 QTest::addColumn<QChart::AnimationOption>("animationOptions");
230 230 QTest::newRow("AllAnimations") << QChart::AllAnimations;
231 231 QTest::newRow("NoAnimation") << QChart::NoAnimation;
232 232 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
233 233 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
234 234 }
235 235
236 236 void tst_QChart::animationOptions()
237 237 {
238 238 createTestData();
239 239 QFETCH(QChart::AnimationOption, animationOptions);
240 240 m_chart->setAnimationOptions(animationOptions);
241 241 QCOMPARE(m_chart->animationOptions(), animationOptions);
242 242 }
243 243
244 244 void tst_QChart::axisX_data()
245 245 {
246 246
247 247 QTest::addColumn<QAbstractAxis*>("axis");
248 248 QTest::addColumn<QAbstractSeries *>("series");
249 249
250 250 QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QLineSeries(this);
251 251 QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
252 252 QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QScatterSeries(this);
253 253 QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QSplineSeries(this);
254 254 QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QPieSeries(this);
255 255 QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QBarSeries(this);
256 256 QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
257 257 QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
258 258
259 259 QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this);
260 260 QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
261 261 QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this);
262 262 QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this);
263 263 QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this);
264 264 QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this);
265 265 QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
266 266 QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
267 267
268 268 }
269 269
270 270 void tst_QChart::axisX()
271 271 {
272 272 QFETCH(QAbstractAxis*, axis);
273 273 QFETCH(QAbstractSeries*, series);
274 274 QVERIFY(!m_chart->axisX());
275 275 m_view->show();
276 276 QTest::qWaitForWindowShown(m_view);
277 277 m_chart->addSeries(series);
278 278 m_chart->setAxisX(axis,series);
279 279 QVERIFY(m_chart->axisX(series)==axis);
280 280 }
281 281
282 282 void tst_QChart::axisY_data()
283 283 {
284 284 axisX_data();
285 285 }
286 286
287 287
288 288 void tst_QChart::axisY()
289 289 {
290 290 QFETCH(QAbstractAxis*, axis);
291 291 QFETCH(QAbstractSeries*, series);
292 292 QVERIFY(!m_chart->axisY());
293 293 m_view->show();
294 294 QTest::qWaitForWindowShown(m_view);
295 295 m_chart->addSeries(series);
296 296 m_chart->setAxisY(axis,series);
297 297 QVERIFY(m_chart->axisY(series)==axis);
298 298 }
299 299
300 300 void tst_QChart::backgroundBrush_data()
301 301 {
302 302 QTest::addColumn<QBrush>("backgroundBrush");
303 303 QTest::newRow("null") << QBrush();
304 304 QTest::newRow("blue") << QBrush(Qt::blue);
305 305 QTest::newRow("white") << QBrush(Qt::white);
306 306 QTest::newRow("black") << QBrush(Qt::black);
307 307 }
308 308
309 309 void tst_QChart::backgroundBrush()
310 310 {
311 311 QFETCH(QBrush, backgroundBrush);
312 312 m_chart->setBackgroundBrush(backgroundBrush);
313 313 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
314 314 }
315 315
316 316 void tst_QChart::backgroundPen_data()
317 317 {
318 318 QTest::addColumn<QPen>("backgroundPen");
319 319 QTest::newRow("null") << QPen();
320 320 QTest::newRow("blue") << QPen(Qt::blue);
321 321 QTest::newRow("white") << QPen(Qt::white);
322 322 QTest::newRow("black") << QPen(Qt::black);
323 323 }
324 324
325 325
326 326 void tst_QChart::backgroundPen()
327 327 {
328 328 QFETCH(QPen, backgroundPen);
329 329 m_chart->setBackgroundPen(backgroundPen);
330 330 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
331 331 }
332 332
333 333 void tst_QChart::isBackgroundVisible_data()
334 334 {
335 335 QTest::addColumn<bool>("isBackgroundVisible");
336 336 QTest::newRow("true") << true;
337 337 QTest::newRow("false") << false;
338 338 }
339 339
340 340 void tst_QChart::isBackgroundVisible()
341 341 {
342 342 QFETCH(bool, isBackgroundVisible);
343 343 m_chart->setBackgroundVisible(isBackgroundVisible);
344 344 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
345 345 }
346 346
347 347 void tst_QChart::legend_data()
348 348 {
349 349
350 350 }
351 351
352 352 void tst_QChart::legend()
353 353 {
354 354 QLegend *legend = m_chart->legend();
355 355 QVERIFY(legend);
356 356
357 357 // Colors related signals
358 358 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
359 359 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
360 360 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
361 361
362 362 // colorChanged
363 363 legend->setColor(QColor("aliceblue"));
364 364 QCOMPARE(colorSpy.count(), 1);
365 365 QBrush b = legend->brush();
366 366 b.setColor(QColor("aqua"));
367 367 legend->setBrush(b);
368 368 QCOMPARE(colorSpy.count(), 2);
369 369
370 370 // borderColorChanged
371 371 legend->setBorderColor(QColor("aliceblue"));
372 372 QCOMPARE(borderColorSpy.count(), 1);
373 373 QPen p = legend->pen();
374 374 p.setColor(QColor("aqua"));
375 375 legend->setPen(p);
376 376 QCOMPARE(borderColorSpy.count(), 2);
377 377
378 378 // labelColorChanged
379 379 legend->setLabelColor(QColor("lightsalmon"));
380 380 QCOMPARE(labelColorSpy.count(), 1);
381 381 b = legend->labelBrush();
382 382 b.setColor(QColor("lightseagreen"));
383 383 legend->setLabelBrush(b);
384 384 QCOMPARE(labelColorSpy.count(), 2);
385 385
386 386 // fontChanged
387 387 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
388 388 QFont f = legend->font();
389 389 f.setBold(!f.bold());
390 390 legend->setFont(f);
391 391 QCOMPARE(fontSpy.count(), 1);
392 392 }
393 393
394 394 void tst_QChart::margins_data()
395 395 {
396 396
397 397 }
398 398
399 399 void tst_QChart::margins()
400 400 {
401 401 createTestData();
402 402 QRectF rect = m_chart->geometry();
403 403 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
404 404 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
405 405 }
406 406
407 407 void tst_QChart::removeAllSeries_data()
408 408 {
409 409
410 410 }
411 411
412 412 void tst_QChart::removeAllSeries()
413 413 {
414 414 QLineSeries* series0 = new QLineSeries(this);
415 415 QLineSeries* series1 = new QLineSeries(this);
416 416 QLineSeries* series2 = new QLineSeries(this);
417 417 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
418 418 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
419 419 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
420 420
421 421 m_chart->addSeries(series0);
422 422 m_chart->addSeries(series1);
423 423 m_chart->addSeries(series2);
424 424 m_view->show();
425 425 QTest::qWaitForWindowShown(m_view);
426 426 m_chart->createDefaultAxes();
427 427 QVERIFY(m_chart->axisY(series0)!=0);
428 428 QVERIFY(m_chart->axisY(series1)!=0);
429 429 QVERIFY(m_chart->axisY(series2)!=0);
430 430
431 431 m_chart->removeAllSeries();
432 432 QVERIFY(m_chart->axisY(series0)==0);
433 433 QVERIFY(m_chart->axisY(series1)==0);
434 434 QVERIFY(m_chart->axisY(series2)==0);
435 435 QCOMPARE(deleteSpy1.count(), 1);
436 436 QCOMPARE(deleteSpy2.count(), 1);
437 437 QCOMPARE(deleteSpy3.count(), 1);
438 438 }
439 439
440 440 void tst_QChart::removeSeries_data()
441 441 {
442 442 axisX_data();
443 443 }
444 444
445 445 void tst_QChart::removeSeries()
446 446 {
447 447 QFETCH(QAbstractAxis *, axis);
448 448 QFETCH(QAbstractSeries *, series);
449 449 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
450 450 m_view->show();
451 451 QTest::qWaitForWindowShown(m_view);
452 452 if(!axis) axis = m_chart->axisY();
453 453 m_chart->addSeries(series);
454 454 m_chart->setAxisY(axis,series);
455 455 QCOMPARE(m_chart->axisY(series),axis);
456 456 m_chart->removeSeries(series);
457 457 QVERIFY(m_chart->axisY(series)==0);
458 458 QCOMPARE(deleteSpy.count(), 0);
459 459 }
460 460
461 461 void tst_QChart::scroll_right_data()
462 462 {
463 463 QTest::addColumn<QAbstractSeries *>("series");
464 464
465 465 QLineSeries* series0 = new QLineSeries(this);
466 466 *series0 << QPointF(0, 0) << QPointF(100, 100);
467 467
468 468 QTest::newRow("lineSeries") << (QAbstractSeries*) series0;
469 469
470 470
471 471 }
472 472
473 473 void tst_QChart::scroll_right()
474 474 {
475 475 QFETCH(QAbstractSeries *, series);
476 476 m_chart->addSeries(series);
477 477 m_chart->createDefaultAxes();
478 478 m_view->show();
479 479 QTest::qWaitForWindowShown(m_view);
480 480 QAbstractAxis * axis = m_chart->axisX();
481 481 QVERIFY(axis!=0);
482 482
483 483 switch(axis->type())
484 484 {
485 485 case QAbstractAxis::AxisTypeValues:{
486 486 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
487 487 QVERIFY(vaxis!=0);
488 488 qreal min = vaxis->min();
489 489 qreal max = vaxis->max();
490 490 QVERIFY(max>min);
491 491 m_chart->scroll(50, 0);
492 492 QVERIFY(min<vaxis->min());
493 493 QVERIFY(max<vaxis->max());
494 494 break;
495 495 }
496 496 case QAbstractAxis::AxisTypeCategories:{
497 497 QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis);
498 498 QVERIFY(caxis!=0);
499 499 qreal min = caxis->min().toDouble();
500 500 qreal max = caxis->max().toDouble();
501 501 m_chart->scroll(50, 0);
502 502 QVERIFY(min<caxis->min().toDouble());
503 503 QVERIFY(max<caxis->max().toDouble());
504 504 break;
505 505 }
506 506 default:
507 507 qFatal("Unsupported type");
508 508 break;
509 509 }
510 510 }
511 511
512 512 void tst_QChart::scroll_left_data()
513 513 {
514 514 scroll_right_data();
515 515 }
516 516
517 517 void tst_QChart::scroll_left()
518 518 {
519 519 QFETCH(QAbstractSeries *, series);
520 520 m_chart->addSeries(series);
521 521 m_chart->createDefaultAxes();
522 522 m_view->show();
523 523 QTest::qWaitForWindowShown(m_view);
524 524 QAbstractAxis * axis = m_chart->axisX();
525 525 QVERIFY(axis!=0);
526 526
527 527 switch(axis->type())
528 528 {
529 529 case QAbstractAxis::AxisTypeValues:{
530 530 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
531 531 QVERIFY(vaxis!=0);
532 532 qreal min = vaxis->min();
533 533 qreal max = vaxis->max();
534 534 m_chart->scroll(-50, 0);
535 535 QVERIFY(min>vaxis->min());
536 536 QVERIFY(max>vaxis->max());
537 537 break;
538 538 }
539 539 case QAbstractAxis::AxisTypeCategories:{
540 540 QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis);
541 541 QVERIFY(caxis!=0);
542 542 qreal min = caxis->min().toDouble();
543 543 qreal max = caxis->max().toDouble();
544 544 m_chart->scroll(-50, 0);
545 545 QVERIFY(min>caxis->min().toDouble());
546 546 QVERIFY(max>caxis->max().toDouble());
547 547 break;
548 548 }
549 549 default:
550 550 qFatal("Unsupported type");
551 551 break;
552 552 }
553 553 }
554 554
555 555 void tst_QChart::scroll_up_data()
556 556 {
557 557 scroll_right_data();
558 558 }
559 559
560 560 void tst_QChart::scroll_up()
561 561 {
562 562 QFETCH(QAbstractSeries *, series);
563 563 m_chart->addSeries(series);
564 564 m_chart->createDefaultAxes();
565 565 m_view->show();
566 566 QTest::qWaitForWindowShown(m_view);
567 567 QAbstractAxis * axis = m_chart->axisY();
568 568 QVERIFY(axis!=0);
569 569
570 570 switch(axis->type())
571 571 {
572 572 case QAbstractAxis::AxisTypeValues:{
573 573 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
574 574 QVERIFY(vaxis!=0);
575 575 qreal min = vaxis->min();
576 576 qreal max = vaxis->max();
577 577 m_chart->scroll(0, 50);
578 578 QVERIFY(min<vaxis->min());
579 579 QVERIFY(max<vaxis->max());
580 580 break;
581 581 }
582 582 case QAbstractAxis::AxisTypeCategories:{
583 583 QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis);
584 584 QVERIFY(caxis!=0);
585 585 qreal min = caxis->min().toDouble();
586 586 qreal max = caxis->max().toDouble();
587 587 m_chart->scroll(0, 50);
588 588 QVERIFY(min<caxis->min().toDouble());
589 589 QVERIFY(max<caxis->max().toDouble());
590 590 break;
591 591 }
592 592 default:
593 593 qFatal("Unsupported type");
594 594 break;
595 595 }
596 596 }
597 597
598 598 void tst_QChart::scroll_down_data()
599 599 {
600 600 scroll_right_data();
601 601 }
602 602
603 603 void tst_QChart::scroll_down()
604 604 {
605 605 QFETCH(QAbstractSeries *, series);
606 606 m_chart->addSeries(series);
607 607 m_chart->createDefaultAxes();
608 608 m_view->show();
609 609 QTest::qWaitForWindowShown(m_view);
610 610 QAbstractAxis * axis = m_chart->axisY();
611 611 QVERIFY(axis!=0);
612 612
613 613 switch(axis->type())
614 614 {
615 615 case QAbstractAxis::AxisTypeValues:{
616 616 QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis);
617 617 QVERIFY(vaxis!=0);
618 618 qreal min = vaxis->min();
619 619 qreal max = vaxis->max();
620 620 m_chart->scroll(0, -50);
621 621 QVERIFY(min>vaxis->min());
622 622 QVERIFY(max>vaxis->max());
623 623 break;
624 624 }
625 625 case QAbstractAxis::AxisTypeCategories:{
626 626 QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis);
627 627 QVERIFY(caxis!=0);
628 628 qreal min = caxis->min().toDouble();
629 629 qreal max = caxis->max().toDouble();
630 630 m_chart->scroll(0, -50);
631 631 QVERIFY(min>caxis->min().toDouble());
632 632 QVERIFY(max>caxis->max().toDouble());
633 633 break;
634 634 }
635 635 default:
636 636 qFatal("Unsupported type");
637 637 break;
638 638 }
639 639 }
640 640
641 641 void tst_QChart::theme_data()
642 642 {
643 643 QTest::addColumn<QChart::ChartTheme>("theme");
644 644 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
645 645 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
646 646 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
647 647 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
648 648 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
649 649 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
650 650 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
651 651 }
652 652
653 653 void tst_QChart::theme()
654 654 {
655 655 QFETCH(QChart::ChartTheme, theme);
656 656 createTestData();
657 657 m_chart->setTheme(theme);
658 658 QVERIFY(m_chart->theme()==theme);
659 659 }
660 660
661 661 void tst_QChart::title_data()
662 662 {
663 663 QTest::addColumn<QString>("title");
664 664 QTest::newRow("null") << QString();
665 665 QTest::newRow("foo") << QString("foo");
666 666 }
667 667
668 668 void tst_QChart::title()
669 669 {
670 670 QFETCH(QString, title);
671 671 m_chart->setTitle(title);
672 672 QCOMPARE(m_chart->title(), title);
673 673 }
674 674
675 675 void tst_QChart::titleBrush_data()
676 676 {
677 677 QTest::addColumn<QBrush>("titleBrush");
678 678 QTest::newRow("null") << QBrush();
679 679 QTest::newRow("blue") << QBrush(Qt::blue);
680 680 QTest::newRow("white") << QBrush(Qt::white);
681 681 QTest::newRow("black") << QBrush(Qt::black);
682 682 }
683 683
684 684 void tst_QChart::titleBrush()
685 685 {
686 686 QFETCH(QBrush, titleBrush);
687 687 m_chart->setTitleBrush(titleBrush);
688 688 QCOMPARE(m_chart->titleBrush(), titleBrush);
689 689 }
690 690
691 691 void tst_QChart::titleFont_data()
692 692 {
693 693 QTest::addColumn<QFont>("titleFont");
694 694 QTest::newRow("null") << QFont();
695 695 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
696 696 }
697 697
698 698 void tst_QChart::titleFont()
699 699 {
700 700 QFETCH(QFont, titleFont);
701 701 m_chart->setTitleFont(titleFont);
702 702 QCOMPARE(m_chart->titleFont(), titleFont);
703 703 }
704 704
705 705 void tst_QChart::zoomIn_data()
706 706 {
707 707 QTest::addColumn<QRectF>("rect");
708 708 QTest::newRow("null") << QRectF();
709 709 QTest::newRow("100x100") << QRectF(10,10,100,100);
710 710 QTest::newRow("200x200") << QRectF(10,10,200,200);
711 711 }
712 712
713 713
714 714 void tst_QChart::zoomIn()
715 715 {
716 716
717 717 QFETCH(QRectF, rect);
718 718 createTestData();
719 719 m_chart->createDefaultAxes();
720 720 QRectF marigns = m_chart->margins();
721 721 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
722 722 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
723 723 QVERIFY(axisX!=0);
724 724 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
725 725 QVERIFY(axisY!=0);
726 726 qreal minX = axisX->min();
727 727 qreal minY = axisY->min();
728 728 qreal maxX = axisX->max();
729 729 qreal maxY = axisY->max();
730 730 m_chart->zoomIn(rect);
731 731 if(rect.isValid()){
732 732 QVERIFY(minX<axisX->min());
733 733 QVERIFY(maxX>axisX->max());
734 734 QVERIFY(minY<axisY->min());
735 735 QVERIFY(maxY>axisY->max());
736 736 }
737 737
738 738 }
739 739
740 740 void tst_QChart::zoomOut_data()
741 741 {
742 742
743 743 }
744 744
745 745 void tst_QChart::zoomOut()
746 746 {
747 747 createTestData();
748 748 m_chart->createDefaultAxes();
749 749
750 750 QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX());
751 751 QVERIFY(axisX!=0);
752 752 QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY());
753 753 QVERIFY(axisY!=0);
754 754
755 755 qreal minX = axisX->min();
756 756 qreal minY = axisY->min();
757 757 qreal maxX = axisX->max();
758 758 qreal maxY = axisY->max();
759 759
760 760 m_chart->zoomIn();
761 761
762 762 QVERIFY(minX < axisX->min());
763 763 QVERIFY(maxX > axisX->max());
764 764 QVERIFY(minY < axisY->min());
765 765 QVERIFY(maxY > axisY->max());
766 766
767 767 m_chart->zoomOut();
768 768
769 769 // min x may be a zero value
770 770 if (qFuzzyIsNull(minX))
771 771 QVERIFY(qFuzzyIsNull(axisX->min()));
772 772 else
773 773 QCOMPARE(minX, axisX->min());
774 774
775 775 // min y may be a zero value
776 776 if (qFuzzyIsNull(minY))
777 777 QVERIFY(qFuzzyIsNull(axisY->min()));
778 778 else
779 779 QCOMPARE(minY, axisY->min());
780 780
781 781 QVERIFY(maxX == axisX->max());
782 782 QVERIFY(maxY == axisY->max());
783 783
784 784 }
785 785
786 786 QTEST_MAIN(tst_QChart)
787 787 #include "tst_qchart.moc"
788 788
@@ -1,183 +1,183
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtTest/QtTest>
22 22 #include <qchartview.h>
23 23 #include <qlineseries.h>
24 24 #include <cmath>
25 25 #include <tst_definitions.h>
26 #include <qvaluesaxis.h>
26 #include <qvalueaxis.h>
27 27
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30
31 31 Q_DECLARE_METATYPE(QChart*)
32 32 Q_DECLARE_METATYPE(QChartView::RubberBands)
33 33 Q_DECLARE_METATYPE(Qt::Key)
34 34
35 35 class tst_QChartView : public QObject
36 36 {
37 37 Q_OBJECT
38 38
39 39 public Q_SLOTS:
40 40 void initTestCase();
41 41 void cleanupTestCase();
42 42 void init();
43 43 void cleanup();
44 44
45 45 private Q_SLOTS:
46 46 void qchartview_data();
47 47 void qchartview();
48 48 void chart_data();
49 49 void chart();
50 50 void rubberBand_data();
51 51 void rubberBand();
52 52
53 53 private:
54 54 QChartView* m_view;
55 55 };
56 56
57 57 void tst_QChartView::initTestCase()
58 58 {
59 59 //test tracks mouse, give a while to user to relese it
60 60 QTest::qWait(1000);
61 61 }
62 62
63 63 void tst_QChartView::cleanupTestCase()
64 64 {
65 65 }
66 66
67 67 void tst_QChartView::init()
68 68 {
69 69 m_view = new QChartView(new QChart());
70 70 m_view->chart()->legend()->setVisible(false);
71 71 }
72 72
73 73 void tst_QChartView::cleanup()
74 74 {
75 75 delete m_view;
76 76 m_view =0;
77 77 }
78 78
79 79 void tst_QChartView::qchartview_data()
80 80 {
81 81
82 82 }
83 83
84 84 void tst_QChartView::qchartview()
85 85 {
86 86 QVERIFY(m_view->chart());
87 87 QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand);
88 88 m_view->show();
89 89 QTest::qWaitForWindowShown(m_view);
90 90
91 91 delete(new QChartView());
92 92
93 93 QChartView view;
94 94 QVERIFY(view.chart());
95 95
96 96 }
97 97
98 98 void tst_QChartView::chart_data()
99 99 {
100 100
101 101 QTest::addColumn<QChart*>("chart");
102 102 QTest::newRow("qchart") << new QChart();
103 103 }
104 104
105 105 void tst_QChartView::chart()
106 106 {
107 107 QFETCH(QChart*, chart);
108 108 QChartView* view = new QChartView(chart);
109 109 QCOMPARE(view->chart(), chart);
110 110 delete view;
111 111 }
112 112
113 113 void tst_QChartView::rubberBand_data()
114 114 {
115 115 QTest::addColumn<QChartView::RubberBands>("rubberBand");
116 116 QTest::addColumn<int>("Xcount");
117 117 QTest::addColumn<int>("Ycount");
118 118
119 119 QTest::addColumn<int>("minX");
120 120 QTest::addColumn<int>("maxX");
121 121 QTest::addColumn<int>("minY");
122 122 QTest::addColumn<int>("maxY");
123 123
124 124 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200;
125 125 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180;
126 126 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180;
127 127 }
128 128
129 129 void tst_QChartView::rubberBand()
130 130 {
131 131 QFETCH(QChartView::RubberBands, rubberBand);
132 132 QFETCH(int, Xcount);
133 133 QFETCH(int, Ycount);
134 134 QFETCH(int, minX);
135 135 QFETCH(int, maxX);
136 136 QFETCH(int, minY);
137 137 QFETCH(int, maxY);
138 138
139 139 m_view->setRubberBand(rubberBand);
140 140 QRectF padding = m_view->chart()->margins();
141 141 QCOMPARE(m_view->rubberBand(), rubberBand);
142 142
143 143 QLineSeries* line = new QLineSeries();
144 144 *line << QPointF(0, 0) << QPointF(200, 200);
145 145
146 146 m_view->chart()->addSeries(line);
147 147 m_view->chart()->createDefaultAxes();
148 148 m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom());
149 149 m_view->show();
150 150
151 151 //this is hack since view does not get events otherwise
152 152 m_view->setMouseTracking(true);
153 153
154 154 QAbstractAxis* axisY = m_view->chart()->axisY();
155 155 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal)));
156 156 QAbstractAxis* axisX = m_view->chart()->axisX();
157 157 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal)));
158 158
159 159 QTest::qWaitForWindowShown(m_view);
160 160 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint());
161 161 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint());
162 162 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint());
163 163 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint());
164 164
165 165 TRY_COMPARE(spy0.count(), Xcount);
166 166 TRY_COMPARE(spy1.count(), Ycount);
167 167
168 168 //this is hack since view does not get events otherwise
169 169 m_view->setMouseTracking(false);
170 170
171 171 QValueAxis* vaxisX = qobject_cast<QValueAxis*>(axisX);
172 172 QValueAxis* vaxisY = qobject_cast<QValueAxis*>(axisY);
173 173
174 174 QVERIFY(vaxisX->min() - minX < 1);
175 175 QVERIFY(vaxisX->max() - maxX < 1);
176 176 QVERIFY(vaxisY->min() - minY < 1);
177 177 QVERIFY(vaxisY->max() - maxY < 1);
178 178
179 179 }
180 180
181 181 QTEST_MAIN(tst_QChartView)
182 182 #include "tst_qchartview.moc"
183 183
@@ -1,5 +1,5
1 1 !include( ../auto.pri ) {
2 2 error( "Couldn't find the auto.pri file!" )
3 3 }
4 4 HEADERS += ../qabstractaxis/tst_qabstractaxis.h
5 SOURCES += tst_qvaluesaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp
5 SOURCES += tst_qvalueaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp
@@ -1,415 +1,415
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include "qvaluesaxis.h"
22 #include "qvalueaxis.h"
23 23 #include <qlineseries.h>
24 24
25 25 class tst_QValueAxis: public tst_QAbstractAxis
26 26 {
27 27 Q_OBJECT
28 28
29 29 public slots:
30 30 void initTestCase();
31 31 void cleanupTestCase();
32 32 void init();
33 33 void cleanup();
34 34
35 35 private slots:
36 void qvaluesaxis_data();
37 void qvaluesaxis();
36 void qvalueaxis_data();
37 void qvalueaxis();
38 38 void max_raw_data();
39 39 void max_raw();
40 40 void max_data();
41 41 void max();
42 42 void max_animation_data();
43 43 void max_animation();
44 44 void min_raw_data();
45 45 void min_raw();
46 46 void min_data();
47 47 void min();
48 48 void min_animation_data();
49 49 void min_animation();
50 50 void niceNumbersEnabled_data();
51 51 void niceNumbersEnabled();
52 52 void range_raw_data();
53 53 void range_raw();
54 54 void range_data();
55 55 void range();
56 56 void range_animation_data();
57 57 void range_animation();
58 58 void ticksCount_data();
59 59 void ticksCount();
60 60 void noautoscale_data();
61 61 void noautoscale();
62 62 void autoscale_data();
63 63 void autoscale();
64 64
65 65 private:
66 66 QValueAxis* m_valuesaxis;
67 67 QLineSeries* m_series;
68 68 };
69 69
70 70 void tst_QValueAxis::initTestCase()
71 71 {
72 72 }
73 73
74 74 void tst_QValueAxis::cleanupTestCase()
75 75 {
76 76 }
77 77
78 78 void tst_QValueAxis::init()
79 79 {
80 80 m_valuesaxis = new QValueAxis();
81 81 m_series = new QLineSeries();
82 82 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
83 83 tst_QAbstractAxis::init(m_valuesaxis,m_series);
84 84 m_chart->addSeries(m_series);
85 85 m_chart->createDefaultAxes();
86 86 }
87 87
88 88 void tst_QValueAxis::cleanup()
89 89 {
90 90 delete m_series;
91 91 delete m_valuesaxis;
92 92 m_series = 0;
93 93 m_valuesaxis = 0;
94 94 tst_QAbstractAxis::cleanup();
95 95 }
96 96
97 void tst_QValueAxis::qvaluesaxis_data()
97 void tst_QValueAxis::qvalueaxis_data()
98 98 {
99 99 }
100 100
101 void tst_QValueAxis::qvaluesaxis()
101 void tst_QValueAxis::qvalueaxis()
102 102 {
103 103 qabstractaxis();
104 104
105 105 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
106 106 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
107 107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
108 108 QCOMPARE(m_valuesaxis->ticksCount(), 5);
109 109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues);
110 110
111 111 m_chart->setAxisX(m_valuesaxis, m_series);
112 112 m_view->show();
113 113 QTest::qWaitForWindowShown(m_view);
114 114
115 115 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
116 116 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
117 117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
118 118 QCOMPARE(m_valuesaxis->ticksCount(), 5);
119 119 }
120 120
121 121 void tst_QValueAxis::max_raw_data()
122 122 {
123 123 QTest::addColumn<qreal>("max");
124 124 QTest::newRow("1.0") << 1.0;
125 125 QTest::newRow("50.0") << 50.0;
126 126 QTest::newRow("101.0") << 101.0;
127 127 }
128 128
129 129 void tst_QValueAxis::max_raw()
130 130 {
131 131 QFETCH(qreal, max);
132 132
133 133 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
134 134 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
135 135 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
136 136
137 137 m_valuesaxis->setMax(max);
138 138 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal");
139 139
140 140 QCOMPARE(spy0.count(), 1);
141 141 QCOMPARE(spy1.count(), 0);
142 142 QCOMPARE(spy2.count(), 1);
143 143
144 144 }
145 145
146 146 void tst_QValueAxis::max_data()
147 147 {
148 148 max_raw_data();
149 149 }
150 150
151 151 void tst_QValueAxis::max()
152 152 {
153 153 m_chart->setAxisX(m_valuesaxis, m_series);
154 154 m_view->show();
155 155 QTest::qWaitForWindowShown(m_view);
156 156 max_raw();
157 157 }
158 158
159 159 void tst_QValueAxis::max_animation_data()
160 160 {
161 161 max_data();
162 162 }
163 163
164 164 void tst_QValueAxis::max_animation()
165 165 {
166 166 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
167 167 max();
168 168 }
169 169
170 170 void tst_QValueAxis::min_raw_data()
171 171 {
172 172 QTest::addColumn<qreal>("min");
173 173 QTest::newRow("-1.0") << -1.0;
174 174 QTest::newRow("-50.0") << -50.0;
175 175 QTest::newRow("-101.0") << -101.0;
176 176 }
177 177
178 178 void tst_QValueAxis::min_raw()
179 179 {
180 180 QFETCH(qreal, min);
181 181
182 182 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
183 183 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
184 184 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
185 185
186 186 m_valuesaxis->setMin(min);
187 187 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal");
188 188
189 189 QCOMPARE(spy0.count(), 0);
190 190 QCOMPARE(spy1.count(), 1);
191 191 QCOMPARE(spy2.count(), 1);
192 192 }
193 193
194 194 void tst_QValueAxis::min_data()
195 195 {
196 196 min_raw_data();
197 197 }
198 198
199 199 void tst_QValueAxis::min()
200 200 {
201 201 m_chart->setAxisX(m_valuesaxis, m_series);
202 202 m_view->show();
203 203 QTest::qWaitForWindowShown(m_view);
204 204 min_raw();
205 205 }
206 206
207 207 void tst_QValueAxis::min_animation_data()
208 208 {
209 209 min_data();
210 210 }
211 211
212 212 void tst_QValueAxis::min_animation()
213 213 {
214 214 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
215 215 min();
216 216 }
217 217
218 218 void tst_QValueAxis::niceNumbersEnabled_data()
219 219 {
220 220 QTest::addColumn<bool>("niceNumbersEnabled");
221 221 QTest::addColumn<qreal>("min");
222 222 QTest::addColumn<qreal>("max");
223 223 QTest::addColumn<int>("ticks");
224 224 QTest::addColumn<qreal>("expectedMin");
225 225 QTest::addColumn<qreal>("expectedMax");
226 226 QTest::addColumn<int>("expectedTicks");
227 227 QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
228 228 QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6;
229 229 QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5;
230 230 QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5;
231 231 QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
232 232 QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6;
233 233 }
234 234
235 235 void tst_QValueAxis::niceNumbersEnabled()
236 236 {
237 237 QFETCH(bool, niceNumbersEnabled);
238 238 QFETCH(qreal, min);
239 239 QFETCH(qreal, max);
240 240 QFETCH(int, ticks);
241 241 QFETCH(qreal, expectedMin);
242 242 QFETCH(qreal, expectedMax);
243 243 QFETCH(int, expectedTicks);
244 244
245 245 m_valuesaxis->setRange(min, max);
246 246 m_valuesaxis->setTicksCount(ticks);
247 247
248 248 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
249 249 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
250 250
251 251 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
252 252 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
253 253 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
254 254
255 255 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
256 256 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
257 257
258 258 if(!qFuzzyIsNull(expectedMin - min))
259 259 QCOMPARE(spy1.count(), 1);
260 260 if(!qFuzzyIsNull(expectedMax - max))
261 261 QCOMPARE(spy0.count(), 1);
262 262 if((!qFuzzyIsNull(expectedMin - min)) || (!qFuzzyIsNull(expectedMax - max)))
263 263 QCOMPARE(spy2.count(), 1);
264 264
265 265 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal");
266 266 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal");
267 267 QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks);
268 268
269 269 }
270 270
271 271 void tst_QValueAxis::range_raw_data()
272 272 {
273 273 QTest::addColumn<qreal>("min");
274 274 QTest::addColumn<qreal>("max");
275 275 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
276 276 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
277 277 QTest::newRow("101.0") << 40.0 << 60.0;
278 278 }
279 279
280 280 void tst_QValueAxis::range_raw()
281 281 {
282 282 QFETCH(qreal, min);
283 283 QFETCH(qreal, max);
284 284
285 285 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
286 286 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
287 287 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
288 288
289 289 m_valuesaxis->setRange(min, max);
290 290 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
291 291 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
292 292
293 293 QCOMPARE(spy0.count(), 1);
294 294 QCOMPARE(spy1.count(), 1);
295 295 QCOMPARE(spy2.count(), 1);
296 296 }
297 297
298 298 void tst_QValueAxis::range_data()
299 299 {
300 300 range_raw_data();
301 301 }
302 302
303 303 void tst_QValueAxis::range()
304 304 {
305 305 m_chart->setAxisX(m_valuesaxis, m_series);
306 306 m_view->show();
307 307 QTest::qWaitForWindowShown(m_view);
308 308 range_raw();
309 309 }
310 310
311 311 void tst_QValueAxis::range_animation_data()
312 312 {
313 313 range_data();
314 314 }
315 315
316 316 void tst_QValueAxis::range_animation()
317 317 {
318 318 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
319 319 range();
320 320 }
321 321
322 322 void tst_QValueAxis::ticksCount_data()
323 323 {
324 324 QTest::addColumn<int>("ticksCount");
325 325 QTest::addColumn<int>("expectedCount");
326 326 QTest::newRow("0") << 2;
327 327 QTest::newRow("1") << 2;
328 328 QTest::newRow("2") << 2;
329 329 QTest::newRow("3") << 3;
330 330 QTest::newRow("-1") << 2;
331 331 }
332 332
333 333 void tst_QValueAxis::ticksCount()
334 334 {
335 335 QFETCH(int, ticksCount);
336 336
337 337 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
338 338 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
339 339 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
340 340
341 341 m_valuesaxis->setTicksCount(ticksCount);
342 342 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
343 343
344 344 QCOMPARE(spy0.count(), 0);
345 345 QCOMPARE(spy1.count(), 0);
346 346 QCOMPARE(spy2.count(), 0);
347 347
348 348 m_chart->setAxisX(m_valuesaxis, m_series);
349 349 m_view->show();
350 350 QTest::qWaitForWindowShown(m_view);
351 351
352 352 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
353 353 }
354 354
355 355 void tst_QValueAxis::noautoscale_data()
356 356 {
357 357 QTest::addColumn<qreal>("min");
358 358 QTest::addColumn<qreal>("max");
359 359 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
360 360 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
361 361 QTest::newRow("101.0") << 40.0 << 60.0;
362 362 }
363 363
364 364 void tst_QValueAxis::noautoscale()
365 365 {
366 366 QFETCH(qreal, min);
367 367 QFETCH(qreal, max);
368 368
369 369 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
370 370 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
371 371 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
372 372
373 373 m_valuesaxis->setRange(min, max);
374 374 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
375 375 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
376 376
377 377 QCOMPARE(spy0.count(), 1);
378 378 QCOMPARE(spy1.count(), 1);
379 379 QCOMPARE(spy2.count(), 1);
380 380
381 381 m_chart->setAxisX(m_valuesaxis, m_series);
382 382 m_view->show();
383 383 QTest::qWaitForWindowShown(m_view);
384 384 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
385 385 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
386 386 }
387 387
388 388 void tst_QValueAxis::autoscale_data()
389 389 {
390 390
391 391 }
392 392
393 393 void tst_QValueAxis::autoscale()
394 394 {
395 395 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
396 396 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
397 397 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
398 398
399 399 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal");
400 400 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal");
401 401 m_chart->setAxisX(m_valuesaxis, m_series);
402 402
403 403 QCOMPARE(spy0.count(), 1);
404 404 QCOMPARE(spy1.count(), 1);
405 405 QCOMPARE(spy2.count(), 1);
406 406
407 407 m_view->show();
408 408 QTest::qWaitForWindowShown(m_view);
409 409 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal");
410 410 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal");
411 411 }
412 412
413 413 QTEST_MAIN(tst_QValueAxis)
414 #include "tst_qvaluesaxis.moc"
414 #include "tst_qvalueaxis.moc"
415 415
General Comments 0
You need to be logged in to leave comments. Login now