##// END OF EJS Templates
Remove cryptic/obsolete TODOs
Miikka Heikkinen -
r2439:8946feb2c29e
parent child
Show More
@@ -1,90 +1,88
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "qchartsplugin.h"
22 22 #include "qchartview.h"
23 23 #include <QtPlugin>
24 24
25 25 QTCOMMERCIALCHART_USE_NAMESPACE
26 26
27 27 QChartsPlugin::QChartsPlugin(QObject *parent) :
28 28 QObject(parent)
29 29 {
30 // TODO Auto-generated constructor stub
31 30 }
32 31
33 32 QChartsPlugin::~QChartsPlugin()
34 33 {
35 // TODO Auto-generated destructor stub
36 34 }
37 35
38 36 QString QChartsPlugin::name() const
39 37 {
40 38 return "QChartView";
41 39 }
42 40
43 41 QString QChartsPlugin::includeFile() const
44 42 {
45 43 #ifdef linux
46 44 QString myNewLine = "\n";
47 45 #endif
48 46 #ifdef WIN32
49 47 QString myNewLine = "\n\r";
50 48 #endif
51 49 #ifdef __APPLE__
52 50 QString myNewLine = "\n";
53 51 #endif
54 52 return "<qchartview.h>" + myNewLine + "#include <chartsnamespace.h>";
55 53 }
56 54
57 55 QString QChartsPlugin::group() const
58 56 {
59 57 return tr("QCharts Widgets");
60 58 }
61 59
62 60 QIcon QChartsPlugin::icon() const
63 61 {
64 62 return QIcon(":/images/qcharts.png");
65 63 }
66 64
67 65 QString QChartsPlugin::toolTip() const
68 66 {
69 67 return tr("An qcharts view widget");
70 68 }
71 69
72 70 QString QChartsPlugin::whatsThis() const
73 71 {
74 72 return tr("This widget is presents QChartView widget");
75 73 }
76 74
77 75 bool QChartsPlugin::isContainer() const
78 76 {
79 77 return false;
80 78 }
81 79
82 80 QWidget *QChartsPlugin::createWidget(QWidget *parent)
83 81 {
84 82 return new QChartView(new QChart(), parent);
85 83 }
86 84
87 85 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
88 86 Q_EXPORT_PLUGIN2(qtcommercialchart, QChartsPlugin)
89 87 #endif
90 88
@@ -1,173 +1,173
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "areachartitem_p.h"
22 22 #include "qareaseries.h"
23 23 #include "qareaseries_p.h"
24 24 #include "qlineseries.h"
25 25 #include "chartpresenter_p.h"
26 26 #include "abstractdomain_p.h"
27 27 #include <QPainter>
28 28 #include <QGraphicsSceneMouseEvent>
29 29 #include <QDebug>
30 30
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 //TODO: optimize : remove points which are not visible
35 35
36 36 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
37 : ChartItem(areaSeries->d_func(),item), //TODO: fix me
37 : ChartItem(areaSeries->d_func(),item),
38 38 m_series(areaSeries),
39 39 m_upper(0),
40 40 m_lower(0),
41 41 m_pointsVisible(false)
42 42 {
43 43 setAcceptHoverEvents(true);
44 44 setZValue(ChartPresenter::LineChartZValue);
45 45 m_upper = new AreaBoundItem(this, m_series->upperSeries());
46 46 if (m_series->lowerSeries())
47 47 m_lower = new AreaBoundItem(this, m_series->lowerSeries());
48 48
49 49 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
50 50 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
51 51 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
52 52 QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF)));
53 53 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool)));
54 54
55 55 handleUpdated();
56 56 }
57 57
58 58 AreaChartItem::~AreaChartItem()
59 59 {
60 60 delete m_upper;
61 61 delete m_lower;
62 62 }
63 63
64 64 void AreaChartItem::setPresenter(ChartPresenter *presenter)
65 65 {
66 66 m_upper->setPresenter(presenter);
67 67 if (m_lower) {
68 68 m_lower->setPresenter(presenter);
69 69 }
70 70 ChartItem::setPresenter(presenter);
71 71 }
72 72
73 73 QRectF AreaChartItem::boundingRect() const
74 74 {
75 75 return m_rect;
76 76 }
77 77
78 78 QPainterPath AreaChartItem::shape() const
79 79 {
80 80 return m_path;
81 81 }
82 82
83 83 void AreaChartItem::updatePath()
84 84 {
85 85 QPainterPath path;
86 86 QRectF rect(QPointF(0,0),domain()->size());
87 87
88 88 path = m_upper->path();
89 89
90 90 if (m_lower) {
91 91 path.connectPath(m_lower->path().toReversed());
92 92 } else {
93 93 QPointF first = path.pointAtPercent(0);
94 94 QPointF last = path.pointAtPercent(1);
95 95 path.lineTo(last.x(), rect.bottom());
96 96 path.lineTo(first.x(), rect.bottom());
97 97 }
98 98 path.closeSubpath();
99 99 prepareGeometryChange();
100 100 m_path = path;
101 101 m_rect = path.boundingRect();
102 102 update();
103 103 }
104 104
105 105 void AreaChartItem::handleUpdated()
106 106 {
107 107 setVisible(m_series->isVisible());
108 108 m_pointsVisible = m_series->pointsVisible();
109 109 m_linePen = m_series->pen();
110 110 m_brush = m_series->brush();
111 111 m_pointPen = m_series->pen();
112 112 m_pointPen.setWidthF(2 * m_pointPen.width());
113 113 setOpacity(m_series->opacity());
114 114 update();
115 115 }
116 116
117 117 void AreaChartItem::handleDomainUpdated()
118 118 {
119 119 AbstractDomain* d = m_upper->domain();
120 120
121 121 d->setSize(domain()->size());
122 122 d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY());
123 123 m_upper->handleDomainUpdated();
124 124
125 125 if (m_lower) {
126 126 AbstractDomain* d = m_lower->domain();
127 127 d->setSize(domain()->size());
128 128 d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY());
129 129 m_lower->handleDomainUpdated();
130 130 }
131 131 }
132 132
133 133 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
134 134 {
135 135 Q_UNUSED(widget)
136 136 Q_UNUSED(option)
137 137 painter->save();
138 138 painter->setPen(m_linePen);
139 139 painter->setBrush(m_brush);
140 140 painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
141 141 painter->drawPath(m_path);
142 142 if (m_pointsVisible) {
143 143 painter->setPen(m_pointPen);
144 144 painter->drawPoints(m_upper->geometryPoints());
145 145 if (m_lower)
146 146 painter->drawPoints(m_lower->geometryPoints());
147 147 }
148 148 painter->restore();
149 149 }
150 150
151 151 void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
152 152 {
153 153 emit clicked(m_upper->domain()->calculateDomainPoint(event->pos()));
154 154 ChartItem::mousePressEvent(event);
155 155 }
156 156
157 157 void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
158 158 {
159 159 emit hovered(domain()->calculateDomainPoint(event->pos()), true);
160 160 event->accept();
161 161 // QGraphicsItem::hoverEnterEvent(event);
162 162 }
163 163
164 164 void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
165 165 {
166 166 emit hovered(domain()->calculateDomainPoint(event->pos()), false);
167 167 event->accept();
168 168 // QGraphicsItem::hoverEnterEvent(event);
169 169 }
170 170
171 171 #include "moc_areachartitem_p.cpp"
172 172
173 173 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,454 +1,452
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "abstractdomain_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "qvalueaxis.h"
29 29 #include "qarealegendmarker.h"
30 30 #include "qchart_p.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QAreaSeries
36 36 \brief The QAreaSeries class is used for making area charts.
37 37
38 38 \mainclass
39 39
40 40 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
41 41 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
42 42 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.
43 43 In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases
44 44 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
45 45
46 46 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
47 47 \image examples_areachart.png
48 48 */
49 49 /*!
50 50 \qmlclass AreaSeries QAreaSeries
51 51
52 52 The following QML shows how to create a simple area chart:
53 53 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
54 54 \beginfloatleft
55 55 \image demos_qmlchart4.png
56 56 \endfloat
57 57 \clearfloat
58 58 */
59 59
60 60 /*!
61 61 \property QAreaSeries::upperSeries
62 62 \brief The upper one of the two line series used to define area series boundaries.
63 63 */
64 64 /*!
65 65 \qmlproperty LineSeries AreaSeries::upperSeries
66 66 The upper one of the two line series used to define area series boundaries.
67 67 */
68 68
69 69 /*!
70 70 \property QAreaSeries::lowerSeries
71 71 The lower one of the two line series used to define are series boundaries. Note if
72 72 QAreaSeries was counstucted wihtout a\ lowerSeries this is null.
73 73 */
74 74 /*!
75 75 \qmlproperty LineSeries AreaSeries::lowerSeries
76 76 The lower one of the two line series used to define are series boundaries. Note if
77 77 AreaSeries was counstucted wihtout a\ lowerSeries this is null.
78 78 */
79 79
80 80 /*!
81 81 \property QAreaSeries::color
82 82 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
83 83 \sa QAreaSeries::brush()
84 84 */
85 85 /*!
86 86 \qmlproperty color AreaSeries::color
87 87 Fill (brush) color of the series.
88 88 */
89 89
90 90 /*!
91 91 \property QAreaSeries::borderColor
92 92 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
93 93 \sa QAreaSeries::pen()
94 94 */
95 95 /*!
96 96 \qmlproperty color AreaSeries::borderColor
97 97 Line (pen) color of the series.
98 98 */
99 99
100 100 /*!
101 101 \qmlproperty real AreaSeries::borderWidth
102 102 The width of the border line. By default the width is 2.0.
103 103 */
104 104
105 105 /*!
106 106 \fn QPen QAreaSeries::pen() const
107 107 \brief Returns the pen used to draw line for this series.
108 108 \sa setPen()
109 109 */
110 110
111 111 /*!
112 112 \fn QPen QAreaSeries::brush() const
113 113 \brief Returns the brush used to draw line for this series.
114 114 \sa setBrush()
115 115 */
116 116
117 117 /*!
118 118 \fn void QAreaSeries::colorChanged(QColor color)
119 119 \brief Signal is emitted when the fill (brush) color has changed to \a color.
120 120 */
121 121 /*!
122 122 \qmlsignal AreaSeries::onColorChanged(color color)
123 123 Signal is emitted when the fill (brush) color has changed to \a color.
124 124 */
125 125
126 126 /*!
127 127 \fn void QAreaSeries::borderColorChanged(QColor color)
128 128 \brief Signal is emitted when the line (pen) color has changed to \a color.
129 129 */
130 130 /*!
131 131 \qmlsignal AreaSeries::onBorderColorChanged(color color)
132 132 Signal is emitted when the line (pen) color has changed to \a color.
133 133 */
134 134
135 135 /*!
136 136 \fn void QAreaSeries::clicked(const QPointF& point)
137 137 \brief Signal is emitted when user clicks the \a point on area chart.
138 138 */
139 139 /*!
140 140 \qmlsignal AreaSeries::onClicked(QPointF point)
141 141 Signal is emitted when user clicks the \a point on area chart.
142 142 */
143 143
144 144 /*!
145 145 \fn void QAreaSeries::hovered(const QPointF &point, bool state)
146 146 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
147 147 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
148 148 the series.
149 149 */
150 150 /*!
151 151 \qmlsignal AreaSeries::onHovered(point point, bool state)
152 152 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
153 153 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
154 154 the series.
155 155 */
156 156
157 157 /*!
158 158 \fn void QAreaSeries::selected()
159 159 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
160 160 implemented by the user of QAreaSeries API.
161 161 */
162 162 /*!
163 163 \qmlsignal AreaSeries::onSelected()
164 164 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
165 165 implemented by the user of AreaSeries API.
166 166 */
167 167
168 168 /*!
169 169 \fn void QAreaSeriesPrivate::updated()
170 170 \brief \internal
171 171 */
172 172
173 173 /*!
174 174 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
175 175 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
176 176 When series object is added to QChartView or QChart instance ownerships is transferred.
177 177 */
178 178 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
179 179 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries)
180 180 {
181 181 }
182 182
183 183 /*!
184 184 Constructs area series object without upper or lower series with \a parent object.
185 185 */
186 186 QAreaSeries::QAreaSeries(QObject *parent)
187 187 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
188 188 {
189 189 }
190 190
191 191 /*!
192 192 Destroys the object.
193 193 */
194 194 QAreaSeries::~QAreaSeries()
195 195 {
196 196 Q_D(QAreaSeries);
197 197 if (d->m_chart)
198 198 d->m_chart->removeSeries(this);
199 199 }
200 200
201 201 /*!
202 202 Returns QChartSeries::SeriesTypeArea.
203 203 */
204 204 QAbstractSeries::SeriesType QAreaSeries::type() const
205 205 {
206 206 return QAbstractSeries::SeriesTypeArea;
207 207 }
208 208
209 209 /*!
210 210 Sets the \a series that is to be used as the area chart upper series.
211 211 */
212 212 void QAreaSeries::setUpperSeries(QLineSeries *series)
213 213 {
214 214 Q_D(QAreaSeries);
215 if(d->m_upperSeries!=series){
215 if (d->m_upperSeries != series)
216 216 d->m_upperSeries = series;
217 //TODO:
218 }
219 217 }
220 218
221 219 QLineSeries *QAreaSeries::upperSeries() const
222 220 {
223 221 Q_D(const QAreaSeries);
224 222 return d->m_upperSeries;
225 223 }
226 224
227 225 /*!
228 226 Sets the \a series that is to be used as the area chart lower series.
229 227 */
230 228 void QAreaSeries::setLowerSeries(QLineSeries *series)
231 229 {
232 230 Q_D(QAreaSeries);
233 231 d->m_lowerSeries = series;
234 232 }
235 233
236 234 QLineSeries *QAreaSeries::lowerSeries() const
237 235 {
238 236 Q_D(const QAreaSeries);
239 237 return d->m_lowerSeries;
240 238 }
241 239
242 240 /*!
243 241 Sets \a pen used for drawing area outline.
244 242 */
245 243 void QAreaSeries::setPen(const QPen &pen)
246 244 {
247 245 Q_D(QAreaSeries);
248 246 if (d->m_pen != pen) {
249 247 d->m_pen = pen;
250 248 emit d->updated();
251 249 }
252 250 }
253 251
254 252 QPen QAreaSeries::pen() const
255 253 {
256 254 Q_D(const QAreaSeries);
257 255 return d->m_pen;
258 256 }
259 257
260 258 /*!
261 259 Sets \a brush used for filling the area.
262 260 */
263 261 void QAreaSeries::setBrush(const QBrush &brush)
264 262 {
265 263 Q_D(QAreaSeries);
266 264 if (d->m_brush != brush) {
267 265 bool emitColorChanged = brush.color() != d->m_brush.color();
268 266 d->m_brush = brush;
269 267 emit d->updated();
270 268 if (emitColorChanged)
271 269 emit colorChanged(brush.color());
272 270 }
273 271 }
274 272
275 273 QBrush QAreaSeries::brush() const
276 274 {
277 275 Q_D(const QAreaSeries);
278 276 return d->m_brush;
279 277 }
280 278
281 279 void QAreaSeries::setColor(const QColor &color)
282 280 {
283 281 QBrush b = brush();
284 282 if (b == QBrush())
285 283 b.setStyle(Qt::SolidPattern);
286 284 b.setColor(color);
287 285 setBrush(b);
288 286 }
289 287
290 288 QColor QAreaSeries::color() const
291 289 {
292 290 return brush().color();
293 291 }
294 292
295 293 void QAreaSeries::setBorderColor(const QColor &color)
296 294 {
297 295 QPen p = pen();
298 296 if (p.color() != color) {
299 297 p.setColor(color);
300 298 setPen(p);
301 299 emit borderColorChanged(color);
302 300 }
303 301 }
304 302
305 303 QColor QAreaSeries::borderColor() const
306 304 {
307 305 return pen().color();
308 306 }
309 307
310 308 /*!
311 309 Sets if data points are \a visible and should be drawn on line.
312 310 */
313 311 void QAreaSeries::setPointsVisible(bool visible)
314 312 {
315 313 Q_D(QAreaSeries);
316 314 if (d->m_pointsVisible != visible) {
317 315 d->m_pointsVisible = visible;
318 316 emit d->updated();
319 317 }
320 318 }
321 319
322 320 /*!
323 321 Returns if the points are drawn for this series.
324 322 \sa setPointsVisible()
325 323 */
326 324 bool QAreaSeries::pointsVisible() const
327 325 {
328 326 Q_D(const QAreaSeries);
329 327 return d->m_pointsVisible;
330 328 }
331 329
332 330 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
333 331
334 332 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
335 333 : QAbstractSeriesPrivate(q),
336 334 m_upperSeries(upperSeries),
337 335 m_lowerSeries(lowerSeries),
338 336 m_pointsVisible(false)
339 337 {
340 338 }
341 339
342 340 void QAreaSeriesPrivate::initializeDomain()
343 341 {
344 342 Q_Q(QAreaSeries);
345 343
346 344 qreal minX(domain()->minX());
347 345 qreal minY(domain()->minY());
348 346 qreal maxX(domain()->maxX());
349 347 qreal maxY(domain()->maxY());
350 348
351 349 QLineSeries *upperSeries = q->upperSeries();
352 350 QLineSeries *lowerSeries = q->lowerSeries();
353 351
354 352 const QList<QPointF>& points = upperSeries->points();
355 353
356 354 for (int i = 0; i < points.count(); i++) {
357 355 qreal x = points[i].x();
358 356 qreal y = points[i].y();
359 357 minX = qMin(minX, x);
360 358 minY = qMin(minY, y);
361 359 maxX = qMax(maxX, x);
362 360 maxY = qMax(maxY, y);
363 361 }
364 362 if (lowerSeries) {
365 363
366 364 const QList<QPointF>& points = lowerSeries->points();
367 365
368 366 for (int i = 0; i < points.count(); i++) {
369 367 qreal x = points[i].x();
370 368 qreal y = points[i].y();
371 369 minX = qMin(minX, x);
372 370 minY = qMin(minY, y);
373 371 maxX = qMax(maxX, x);
374 372 maxY = qMax(maxY, y);
375 373 }
376 374 }
377 375
378 376 domain()->setRange(minX, maxX, minY, maxY);
379 377 }
380 378
381 379 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
382 380 {
383 381 Q_Q(QAreaSeries);
384 382 AreaChartItem *area = new AreaChartItem(q,parent);
385 383 m_item.reset(area);
386 384 QAbstractSeriesPrivate::initializeGraphics(parent);
387 385 }
388 386 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
389 387 {
390 388 Q_Q(QAreaSeries);
391 389 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
392 390 if (options.testFlag(QChart::SeriesAnimations)) {
393 391 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
394 392 if (q->lowerSeries())
395 393 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
396 394 }else{
397 395 area->upperLineItem()->setAnimation(0);
398 396 if (q->lowerSeries())
399 397 area->lowerLineItem()->setAnimation(0);
400 398 }
401 399 QAbstractSeriesPrivate::initializeAnimations(options);
402 400 }
403 401
404 402 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
405 403 {
406 404 Q_Q(QAreaSeries);
407 405 QList<QLegendMarker*> list;
408 406 return list << new QAreaLegendMarker(q,legend);
409 407 }
410 408
411 409
412 410 void QAreaSeriesPrivate::initializeAxes()
413 411 {
414 412
415 413 }
416 414
417 415 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
418 416 {
419 417 Q_UNUSED(orientation);
420 418 return QAbstractAxis::AxisTypeValue;
421 419 }
422 420
423 421 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
424 422 {
425 423 Q_UNUSED(orientation);
426 424 return 0;
427 425 }
428 426
429 427 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
430 428 {
431 429 Q_Q(QAreaSeries);
432 430 QPen pen;
433 431 QBrush brush;
434 432
435 433 const QList<QGradient> gradients = theme->seriesGradients();
436 434 const QList<QColor> colors = theme->seriesColors();
437 435
438 436 if (forced || pen == m_pen) {
439 437 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
440 438 pen.setWidthF(2);
441 439 q->setPen(pen);
442 440 }
443 441
444 442 if (forced || brush == m_brush) {
445 443 QBrush brush(colors.at(index % colors.size()));
446 444 q->setBrush(brush);
447 445 }
448 446 }
449 447
450 448
451 449 #include "moc_qareaseries.cpp"
452 450 #include "moc_qareaseries_p.cpp"
453 451
454 452 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,121 +1,120
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "chartcategoryaxisx_p.h"
22 22 #include "qcategoryaxis.h"
23 23 #include "qabstractaxis.h"
24 24 #include "chartpresenter_p.h"
25 25 #include <QGraphicsLayout>
26 26 #include <QFontMetrics>
27 27 #include <qmath.h>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item)
32 32 : HorizontalAxis(axis, item, true),
33 33 m_axis(axis)
34 34 {
35 35 }
36 36
37 37 ChartCategoryAxisX::~ChartCategoryAxisX()
38 38 {
39 39 }
40 40
41 41 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
42 42 {
43 43 int tickCount = m_axis->categoriesLabels().count() + 1;
44 44 QVector<qreal> points;
45 45
46 46 if (tickCount < 2)
47 47 return points;
48 48
49 49 const QRectF &gridRect = gridGeometry();
50 50 qreal range = max() - min();
51 51 if (range > 0) {
52 52 points.resize(tickCount);
53 53 qreal scale = gridRect.width() / range;
54 54 for (int i = 0; i < tickCount; ++i) {
55 55 if (i < tickCount - 1) {
56 56 qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left();
57 57 points[i] = x;
58 58 } else {
59 59 qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left();
60 60 points[i] = x;
61 61 }
62 62 }
63 63 }
64 64
65 65 return points;
66 66 }
67 67
68 68 void ChartCategoryAxisX::updateGeometry()
69 69 {
70 70 //TODO: this is not optimal when many categories :( , create only visible lables
71 71 setLabels(m_axis->categoriesLabels() << "");
72 72 HorizontalAxis::updateGeometry();
73 73 }
74 74
75 75 void ChartCategoryAxisX::handleAxisUpdated()
76 76 {
77 77 updateGeometry();
78 //TODO :: ChartAxis::handleAxisUpdated();
79 78 }
80 79
81 80 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
82 81 {
83 82 Q_UNUSED(constraint)
84 83
85 84 QFontMetrics fn(font());
86 85 QSizeF sh;
87 86 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
88 87 QStringList ticksList = m_axis->categoriesLabels();
89 88 qreal width = 0;
90 89 qreal height = 0;
91 90
92 91 switch (which) {
93 92 case Qt::MinimumSize: {
94 93 QRectF boundingRect = labelBoundingRect(fn, "...");
95 94 width = qMax(boundingRect.width(), base.width());
96 95 height = boundingRect.height() + labelPadding();
97 96 height += base.height();
98 97 sh = QSizeF(width, height);
99 98 break;
100 99 }
101 100 case Qt::PreferredSize: {
102 101 int labelHeight = 0;
103 102 foreach (const QString& s, ticksList) {
104 103 QRect rect = labelBoundingRect(fn, s);
105 104 labelHeight = qMax(rect.height(), labelHeight);
106 105 width += rect.width();
107 106 }
108 107 height = labelHeight + labelPadding();
109 108 height += base.height();
110 109 width = qMax(width, base.width());
111 110 sh = QSizeF(width, height);
112 111 break;
113 112 }
114 113 default:
115 114 break;
116 115 }
117 116
118 117 return sh;
119 118 }
120 119
121 120 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,120 +1,119
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "chartcategoryaxisy_p.h"
22 22 #include "qcategoryaxis.h"
23 23 #include "qabstractaxis.h"
24 24 #include "chartpresenter_p.h"
25 25 #include <QGraphicsLayout>
26 26 #include <QFontMetrics>
27 27 #include <qmath.h>
28 28 #include <QDebug>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item)
33 33 : VerticalAxis(axis, item, true),
34 34 m_axis(axis)
35 35 {
36 36 }
37 37
38 38 ChartCategoryAxisY::~ChartCategoryAxisY()
39 39 {
40 40 }
41 41
42 42 QVector<qreal> ChartCategoryAxisY::calculateLayout() const
43 43 {
44 44 int tickCount = m_axis->categoriesLabels().count() + 1;
45 45 QVector<qreal> points;
46 46
47 47 if (tickCount < 2)
48 48 return points;
49 49
50 50 const QRectF &gridRect = gridGeometry();
51 51 qreal range = max() - min();
52 52 if (range > 0) {
53 53 points.resize(tickCount);
54 54 qreal scale = gridRect.height() / range;
55 55 for (int i = 0; i < tickCount; ++i) {
56 56 if (i < tickCount - 1) {
57 57 qreal y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.bottom();
58 58 points[i] = y;
59 59 } else {
60 60 qreal y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.bottom();
61 61 points[i] = y;
62 62 }
63 63 }
64 64 }
65 65
66 66 return points;
67 67 }
68 68
69 69 void ChartCategoryAxisY::updateGeometry()
70 70 {
71 71 setLabels(m_axis->categoriesLabels() << "");
72 72 VerticalAxis::updateGeometry();
73 73 }
74 74
75 75 void ChartCategoryAxisY::handleAxisUpdated()
76 76 {
77 77 updateGeometry();
78 //TODO:: ChartAxis::handleAxisUpdated();
79 78 }
80 79
81 80 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
82 81 {
83 82 Q_UNUSED(constraint)
84 83
85 84 QFontMetrics fn(font());
86 85 QSizeF sh;
87 86 QSizeF base = VerticalAxis::sizeHint(which, constraint);
88 87 QStringList ticksList = m_axis->categoriesLabels();
89 88 qreal width = 0;
90 89 qreal height = 0;
91 90
92 91 switch (which) {
93 92 case Qt::MinimumSize: {
94 93 QRectF boundingRect = labelBoundingRect(fn, "...");
95 94 width = boundingRect.width() + labelPadding();
96 95 width += base.width();
97 96 height = qMax(boundingRect.height(), base.height());
98 97 sh = QSizeF(width, height);
99 98 break;
100 99 }
101 100 case Qt::PreferredSize: {
102 101 int labelWidth = 0;
103 102 foreach (const QString& s, ticksList) {
104 103 QRect rect = labelBoundingRect(fn, s);
105 104 labelWidth = qMax(rect.width(), labelWidth);
106 105 height += rect.height();
107 106 }
108 107 width = labelWidth + labelPadding() + 1;
109 108 width += base.width();
110 109 height = qMax(height, base.height());
111 110 sh = QSizeF(width, height);
112 111 break;
113 112 }
114 113 default:
115 114 break;
116 115 }
117 116 return sh;
118 117 }
119 118
120 119 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,553 +1,547
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "chartaxis_p.h"
22 22 #include "qabstractaxis.h"
23 23 #include "qabstractaxis_p.h"
24 24 #include "chartpresenter_p.h"
25 25 #include "chartlayout_p.h"
26 26 #include "abstractdomain_p.h"
27 27 #include <qmath.h>
28 28 #include <QDateTime>
29 29 #include <QValueAxis>
30 30 #include <QLogValueAxis>
31 31 #include <QGraphicsLayout>
32 32 #include <QFontMetrics>
33 33
34 34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 35
36 36 ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis)
37 37 : ChartElement(item),
38 38 m_axis(axis),
39 39 m_labelsAngle(axis->labelsAngle()),
40 40 m_grid(new QGraphicsItemGroup(item)),
41 41 m_arrow(new QGraphicsItemGroup(item)),
42 42 m_shades(new QGraphicsItemGroup(item)),
43 43 m_labels(new QGraphicsItemGroup(item)),
44 44 m_title(new QGraphicsSimpleTextItem(item)),
45 45 m_animation(0),
46 46 m_labelPadding(5),
47 47 m_intervalAxis(intervalAxis),
48 48 m_titlePadding(3)
49 49 {
50 50 Q_ASSERT(item);
51 51 //initial initialization
52 52 m_arrow->setHandlesChildEvents(false);
53 53 m_arrow->setZValue(ChartPresenter::AxisZValue);
54 54 m_labels->setZValue(ChartPresenter::AxisZValue);
55 55 m_shades->setZValue(ChartPresenter::ShadesZValue);
56 56 m_grid->setZValue(ChartPresenter::GridZValue);
57 57 m_title->setZValue(ChartPresenter::GridZValue);
58 58 handleVisibleChanged(m_axis->isVisible());
59 59 connectSlots();
60 60
61 61 setFlag(QGraphicsItem::ItemHasNoContents,true);
62 62 }
63 63
64 64 void ChartAxis::connectSlots()
65 65 {
66 66 QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool)));
67 67 QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool)));
68 68 QObject::connect(m_axis,SIGNAL(gridVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool)));
69 69 QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool)));
70 70 QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool)));
71 71 QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int)));
72 72 QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&)));
73 73 QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&)));
74 74 QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&)));
75 75 QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&)));
76 76 QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&)));
77 77 QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&)));
78 78 QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&)));
79 79 QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&)));
80 80 QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&)));
81 81 QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&)));
82 82 QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&)));
83 83 QObject::connect(m_axis,SIGNAL(titleVisibleChanged(bool)),this,SLOT(handleTitleVisibleChanged(bool)));
84 84 QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal)));
85 85 }
86 86
87 87 ChartAxis::~ChartAxis()
88 88 {
89 89 }
90 90
91 91 void ChartAxis::setAnimation(AxisAnimation *animation)
92 92 {
93 93 m_animation = animation;
94 94 }
95 95
96 96 void ChartAxis::setLayout(QVector<qreal> &layout)
97 97 {
98 98 m_layoutVector = layout;
99 99 }
100 100
101 101 void ChartAxis::createItems(int count)
102 102 {
103 103 if (m_arrow->childItems().size() == 0){
104 104 QGraphicsLineItem* arrow = new ArrowItem(this, this);
105 105 arrow->setPen(m_axis->linePen());
106 106 m_arrow->addToGroup(arrow);
107 107 }
108 108
109 109 if (m_intervalAxis && m_grid->childItems().size() == 0) {
110 110 for (int i = 0 ; i < 2 ; i ++){
111 111 QGraphicsLineItem* item = new QGraphicsLineItem(this);
112 112 item->setPen(m_axis->gridLinePen());
113 113 m_grid->addToGroup(item);
114 114 }
115 115 }
116 116
117 117 for (int i = 0; i < count; ++i) {
118 118 QGraphicsLineItem* arrow = new QGraphicsLineItem(this);
119 119 arrow->setPen(m_axis->linePen());
120 120 QGraphicsLineItem* grid = new QGraphicsLineItem(this);
121 121 grid->setPen(m_axis->gridLinePen());
122 122 QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this);
123 123 label->setFont(m_axis->labelsFont());
124 124 label->setPen(m_axis->labelsPen());
125 125 label->setBrush(m_axis->labelsBrush());
126 126 label->setRotation(m_labelsAngle);
127 127 m_arrow->addToGroup(arrow);
128 128 m_grid->addToGroup(grid);
129 129 m_labels->addToGroup(label);
130 130
131 131 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){
132 132 QGraphicsRectItem* shades = new QGraphicsRectItem(this);
133 133 shades->setPen(m_axis->shadesPen());
134 134 shades->setBrush(m_axis->shadesBrush());
135 135 m_shades->addToGroup(shades);
136 136 }
137 137 }
138 138
139 139 }
140 140
141 141 void ChartAxis::deleteItems(int count)
142 142 {
143 143 QList<QGraphicsItem *> lines = m_grid->childItems();
144 144 QList<QGraphicsItem *> labels = m_labels->childItems();
145 145 QList<QGraphicsItem *> shades = m_shades->childItems();
146 146 QList<QGraphicsItem *> axis = m_arrow->childItems();
147 147
148 148 for (int i = 0; i < count; ++i) {
149 149 if (lines.size() % 2 && lines.size() > 1)
150 150 delete(shades.takeLast());
151 151 delete(lines.takeLast());
152 152 delete(labels.takeLast());
153 153 delete(axis.takeLast());
154 154 }
155 155 }
156 156
157 157 void ChartAxis::updateLayout(QVector<qreal> &layout)
158 158 {
159 159 int diff = m_layoutVector.size() - layout.size();
160 160
161 161 if (diff > 0)
162 162 deleteItems(diff);
163 163 else if (diff < 0)
164 164 createItems(-diff);
165 165
166 166 if (m_animation) {
167 167 switch (presenter()->state()) {
168 168 case ChartPresenter::ZoomInState:
169 169 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
170 170 m_animation->setAnimationPoint(presenter()->statePoint());
171 171 break;
172 172 case ChartPresenter::ZoomOutState:
173 173 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
174 174 m_animation->setAnimationPoint(presenter()->statePoint());
175 175 break;
176 176 case ChartPresenter::ScrollUpState:
177 177 case ChartPresenter::ScrollLeftState:
178 178 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
179 179 break;
180 180 case ChartPresenter::ScrollDownState:
181 181 case ChartPresenter::ScrollRightState:
182 182 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
183 183 break;
184 184 case ChartPresenter::ShowState:
185 185 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
186 186 break;
187 187 }
188 188 m_animation->setValues(m_layoutVector, layout);
189 189 presenter()->startAnimation(m_animation);
190 190 } else {
191 191 setLayout(layout);
192 192 updateGeometry();
193 193 }
194 194 }
195 195
196 196 void ChartAxis::setLabelPadding(int padding)
197 197 {
198 198 m_labelPadding = padding;
199 199 }
200 200
201 201 void ChartAxis::setTitlePadding(int padding)
202 202 {
203 203 m_titlePadding = padding;
204 204 }
205 205
206 206 bool ChartAxis::isEmpty()
207 207 {
208 208 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max());
209 209 }
210 210
211 211 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
212 212 {
213 213 m_gridRect = grid;
214 214 m_axisRect = axis;
215 215
216 216 if (isEmpty())
217 217 return;
218 218
219 219 QVector<qreal> layout = calculateLayout();
220 220 updateLayout(layout);
221 221 }
222 222
223 223 qreal ChartAxis::min() const
224 224 {
225 225 return m_axis->d_ptr->min();
226 226 }
227 227
228 228 qreal ChartAxis::max() const
229 229 {
230 230 return m_axis->d_ptr->max();
231 231 }
232 232
233 233 QFont ChartAxis::font() const
234 234 {
235 235 return m_axis->labelsFont();
236 236 }
237 237
238 238 QFont ChartAxis::titleFont() const
239 239 {
240 240 return m_axis->titleFont();
241 241 }
242 242
243 243 QString ChartAxis::titleText() const
244 244 {
245 245 return m_axis->titleText();
246 246 }
247 247
248 248 void ChartAxis::axisSelected()
249 249 {
250 250 emit clicked();
251 251 }
252 252
253 253 Qt::Orientation ChartAxis::orientation() const
254 254 {
255 255 return m_axis->orientation();
256 256 }
257 257
258 258 Qt::Alignment ChartAxis::alignment() const
259 259 {
260 260 return m_axis->alignment();
261 261 }
262 262
263 263 void ChartAxis::setLabels(const QStringList &labels)
264 264 {
265 265 m_labelsList = labels;
266 266 }
267 267
268 268 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
269 269 {
270 270 Q_UNUSED(which);
271 271 Q_UNUSED(constraint);
272 272 return QSizeF();
273 273 }
274 274
275 275 //handlers
276 276
277 277 void ChartAxis::handleArrowVisibleChanged(bool visible)
278 278 {
279 279 m_arrow->setVisible(visible);
280 280 }
281 281
282 282 void ChartAxis::handleGridVisibleChanged(bool visible)
283 283 {
284 284 m_grid->setVisible(visible);
285 285 }
286 286
287 287 void ChartAxis::handleLabelsVisibleChanged(bool visible)
288 288 {
289 289 m_labels->setVisible(visible);
290 290 }
291 291
292 292 void ChartAxis::handleShadesVisibleChanged(bool visible)
293 293 {
294 294 m_shades->setVisible(visible);
295 295 }
296 296
297 297 void ChartAxis::handleTitleVisibleChanged(bool visible)
298 298 {
299 299 QGraphicsLayoutItem::updateGeometry();
300 300 presenter()->layout()->invalidate();
301 301 m_title->setVisible(visible);
302 302 }
303 303
304 304 void ChartAxis::handleLabelsAngleChanged(int angle)
305 305 {
306 306 foreach (QGraphicsItem *item, m_labels->childItems())
307 307 item->setRotation(angle);
308 308
309 309 m_labelsAngle = angle;
310 310 }
311 311
312 312 void ChartAxis::handleLabelsPenChanged(const QPen &pen)
313 313 {
314 314 foreach (QGraphicsItem *item , m_labels->childItems())
315 315 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
316 316 }
317 317
318 318 void ChartAxis::handleLabelsBrushChanged(const QBrush &brush)
319 319 {
320 320 foreach (QGraphicsItem *item , m_labels->childItems())
321 321 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
322 322 }
323 323
324 324 void ChartAxis::handleLabelsFontChanged(const QFont &font)
325 325 {
326 326 foreach (QGraphicsItem *item , m_labels->childItems())
327 327 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
328 328 QGraphicsLayoutItem::updateGeometry();
329 329 presenter()->layout()->invalidate();
330 330 }
331 331
332 332 void ChartAxis::handleShadesBrushChanged(const QBrush &brush)
333 333 {
334 334 foreach (QGraphicsItem *item , m_shades->childItems())
335 335 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
336 336 }
337 337
338 338 void ChartAxis::handleShadesPenChanged(const QPen &pen)
339 339 {
340 340 foreach (QGraphicsItem *item , m_shades->childItems())
341 341 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
342 342 }
343 343
344 344 void ChartAxis::handleArrowPenChanged(const QPen &pen)
345 345 {
346 346 foreach (QGraphicsItem *item , m_arrow->childItems())
347 347 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
348 348 }
349 349
350 350 void ChartAxis::handleGridPenChanged(const QPen &pen)
351 351 {
352 352 foreach (QGraphicsItem *item , m_grid->childItems())
353 353 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
354 354 }
355 355
356 356 void ChartAxis::handleTitleTextChanged(const QString &title)
357 357 {
358 358 QGraphicsLayoutItem::updateGeometry();
359 359 presenter()->layout()->invalidate();
360 360 m_title->setText(title);
361 361 }
362 362
363 363
364 364 void ChartAxis::handleTitlePenChanged(const QPen &pen)
365 365 {
366 366 m_title->setPen(pen);
367 367 }
368 368
369 369 void ChartAxis::handleTitleBrushChanged(const QBrush &brush)
370 370 {
371 371 m_title->setBrush(brush);
372 372 }
373 373
374 374 void ChartAxis::handleTitleFontChanged(const QFont &font)
375 375 {
376 376 if(m_title->font() != font){
377 377 m_title->setFont(font);
378 378 QGraphicsLayoutItem::updateGeometry();
379 379 presenter()->layout()->invalidate();
380 380 }
381 381 }
382 382
383 383 void ChartAxis::handleVisibleChanged(bool visible)
384 384 {
385 385 setVisible(visible);
386 386 if(!visible) {
387 387 m_grid->setVisible(visible);
388 388 m_arrow->setVisible(visible);
389 389 m_shades->setVisible(visible);
390 390 m_labels->setVisible(visible);
391 391 m_title->setVisible(visible);
392 392 }else {
393 393 m_grid->setVisible(m_axis->isGridLineVisible());
394 394 m_arrow->setVisible(m_axis->isLineVisible());
395 395 m_shades->setVisible(m_axis->shadesVisible());
396 396 m_labels->setVisible(m_axis->labelsVisible());
397 397 m_title->setVisible(m_axis->isTitleVisible());
398 398 }
399 399
400 400 if(presenter()) presenter()->layout()->invalidate();
401 401 }
402 402
403 403 void ChartAxis::handleRangeChanged(qreal min, qreal max)
404 404 {
405 405 Q_UNUSED(min);
406 406 Q_UNUSED(max);
407 407
408 408 if (!isEmpty()) {
409 409
410 410 QVector<qreal> layout = calculateLayout();
411 411 updateLayout(layout);
412 412 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
413 413 QSizeF after = sizeHint(Qt::PreferredSize);
414 414
415 415 if (before != after) {
416 416 QGraphicsLayoutItem::updateGeometry();
417 417 //we don't want to call invalidate on layout, since it will change minimum size of component,
418 418 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
419 419 //instead recalculate layout and use plotArea for extra space.
420 420 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
421 421 }
422 422 }
423 423
424 424 }
425 425
426 426 //helpers
427 427
428 428 QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format)
429 429 {
430 //TODO: Q_ASSERT(m_max > m_min);
431 //TODO: Q_ASSERT(ticks > 1);
432
433 430 QStringList labels;
434 431
435 if(max <= min || ticks < 1){
432 if (max <= min || ticks < 1)
436 433 return labels;
437 }
438 434
439 435 int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
440 436 n++;
441 437
442 438 if (format.isNull()) {
443 439 for (int i = 0; i < ticks; i++) {
444 440 qreal value = min + (i * (max - min) / (ticks - 1));
445 441 labels << QString::number(value, 'f', n);
446 442 }
447 443 } else {
448 444 QByteArray array = format.toLatin1();
449 445 for (int i = 0; i < ticks; i++) {
450 446 qreal value = min + (i * (max - min) / (ticks - 1));
451 447 if (format.contains("d")
452 448 || format.contains("i")
453 449 || format.contains("c"))
454 450 labels << QString().sprintf(array, (qint64)value);
455 451 else if (format.contains("u")
456 452 || format.contains("o")
457 453 || format.contains("x", Qt::CaseInsensitive))
458 454 labels << QString().sprintf(array, (quint64)value);
459 455 else if (format.contains("f", Qt::CaseInsensitive)
460 456 || format.contains("e", Qt::CaseInsensitive)
461 457 || format.contains("g", Qt::CaseInsensitive))
462 458 labels << QString().sprintf(array, value);
463 459 else
464 460 labels << QString();
465 461 }
466 462 }
467 463
468 464 return labels;
469 465 }
470 466
471 467 QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format)
472 468 {
473 469 // Q_ASSERT(m_max > m_min);
474 470 // Q_ASSERT(ticks > 1);
475 471
476 472 QStringList labels;
477 473
478 474 int n = 0;
479 475 if (ticks > 1)
480 476 n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
481 477 n++;
482 478
483 479 int firstTick;
484 480 if (base > 1)
485 481 firstTick = ceil(log10(min) / log10(base));
486 482 else
487 483 firstTick = ceil(log10(max) / log10(base));
488 484
489 485 if (format.isNull()) {
490 486 for (int i = firstTick; i < ticks + firstTick; i++) {
491 487 qreal value = qPow(base, i);
492 488 labels << QString::number(value, 'f', n);
493 489 }
494 490 } else {
495 491 QByteArray array = format.toLatin1();
496 492 for (int i = firstTick; i < ticks + firstTick; i++) {
497 493 qreal value = qPow(base, i);
498 494 if (format.contains("d")
499 495 || format.contains("i")
500 496 || format.contains("c"))
501 497 labels << QString().sprintf(array, (qint64)value);
502 498 else if (format.contains("u")
503 499 || format.contains("o")
504 500 || format.contains("x", Qt::CaseInsensitive))
505 501 labels << QString().sprintf(array, (quint64)value);
506 502 else if (format.contains("f", Qt::CaseInsensitive)
507 503 || format.contains("e", Qt::CaseInsensitive)
508 504 || format.contains("g", Qt::CaseInsensitive))
509 505 labels << QString().sprintf(array, value);
510 506 else
511 507 labels << QString();
512 508 }
513 509 }
514 510
515 511 return labels;
516 512 }
517 513
518 514 QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format)
519 515 {
520 //TODO: Q_ASSERT(m_max > m_min);
521 //TODO: Q_ASSERT(ticks > 1);
522 516 QStringList labels;
523 517
524 if(max <= min || ticks < 1) {
518 if (max <= min || ticks < 1) {
525 519 return labels;
526 520 }
527 521
528 522 int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0);
529 523 n++;
530 524 for (int i = 0; i < ticks; i++) {
531 525 qreal value = min + (i * (max - min) / (ticks - 1));
532 526 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
533 527 }
534 528 return labels;
535 529 }
536 530
537 531 QRect ChartAxis::labelBoundingRect(const QFontMetrics &fn, const QString &label) const
538 532 {
539 533 QRect boundingRect = fn.boundingRect(label);
540 534
541 535 // Take label rotation into account
542 536 if (m_labelsAngle) {
543 537 QTransform transform;
544 538 transform.rotate(m_labelsAngle);
545 539 boundingRect = transform.mapRect(boundingRect);
546 540 }
547 541
548 542 return boundingRect;
549 543 }
550 544
551 545 #include "moc_chartaxis_p.cpp"
552 546
553 547 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,1008 +1,1007
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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.h"
22 22 #include "qabstractaxis_p.h"
23 23 #include "chartdataset_p.h"
24 24 #include "charttheme_p.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 /*!
29 29 \class QAbstractAxis
30 30 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 31 \mainclass
32 32
33 33 There is only one x Axis visible at the time, however there can be multiple y axes.
34 34 Each chart series can be bound to exactly one Y axis and the shared common X axis.
35 35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 36 */
37 37
38 38 /*!
39 39 \qmlclass AbstractAxis QAbstractAxis
40 40 \brief The Axis element is used for manipulating chart's axes
41 41
42 42 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
43 43 Each chart series can be bound to exactly one Y axis and the shared common X axis.
44 44 Axis can be setup to show axis line with tick marks, grid lines and shades.
45 45
46 46 To access Axes you can use ChartView API. For example:
47 47 \code
48 48 ChartView {
49 49 axisX.min: 0
50 50 axisX.max: 3
51 51 axisX.ticksCount: 4
52 52 axisY.min: 0
53 53 axisY.max: 4
54 54 // Add a few series...
55 55 }
56 56 \endcode
57 57 */
58 58
59 59 /*!
60 60 \enum QAbstractAxis::AxisType
61 61
62 62 The type of the series object.
63 63
64 64 \value AxisTypeNoAxis
65 65 \value AxisTypeValue
66 66 \value AxisTypeBarCategory
67 67 \value AxisTypeCategory
68 68 \value AxisTypeDateTime
69 69 \value AxisTypeLogValue
70 70 */
71 71
72 72 /*!
73 73 *\fn void QAbstractAxis::type() const
74 74 Returns the type of the axis
75 75 */
76 76
77 77 /*!
78 78 \property QAbstractAxis::lineVisible
79 79 The visibility of the axis line
80 80 */
81 81 /*!
82 82 \qmlproperty bool AbstractAxis::lineVisible
83 83 The visibility of the axis line
84 84 */
85 85
86 86 /*!
87 87 \property QAbstractAxis::linePen
88 88 The pen of the line.
89 89 */
90 90
91 91 /*!
92 92 \property QAbstractAxis::labelsVisible
93 93 Defines if axis labels are visible.
94 94 */
95 95 /*!
96 96 \qmlproperty bool AbstractAxis::labelsVisible
97 97 Defines if axis labels are visible.
98 98 */
99 99
100 100 /*!
101 101 \property QAbstractAxis::labelsPen
102 102 The pen of the labels.
103 103 */
104 104
105 105 /*!
106 106 \property QAbstractAxis::labelsBrush
107 107 The brush of the labels.
108 108 */
109 109
110 110 /*!
111 111 \property QAbstractAxis::visible
112 112 The visibility of the axis.
113 113 */
114 114 /*!
115 115 \qmlproperty bool AbstractAxis::visible
116 116 The visibility of the axis.
117 117 */
118 118
119 119 /*!
120 120 \property QAbstractAxis::gridVisible
121 121 The visibility of the grid lines.
122 122 */
123 123 /*!
124 124 \qmlproperty bool AbstractAxis::gridVisible
125 125 The visibility of the grid lines.
126 126 */
127 127
128 128 /*!
129 129 \property QAbstractAxis::color
130 130 The color of the axis and ticks.
131 131 */
132 132 /*!
133 133 \qmlproperty color AbstractAxis::color
134 134 The color of the axis and ticks.
135 135 */
136 136
137 137 /*!
138 138 \property QAbstractAxis::gridLinePen
139 139 The pen of the grid line.
140 140 */
141 141
142 142 /*!
143 143 \property QAbstractAxis::labelsFont
144 144 The font of the axis labels.
145 145 */
146 146
147 147 /*!
148 148 \qmlproperty Font AbstractAxis::labelsFont
149 149 The font of the axis labels.
150 150
151 151 See the \l {Font} {QML Font Element} for detailed documentation.
152 152 */
153 153
154 154 /*!
155 155 \property QAbstractAxis::labelsColor
156 156 The color of the axis labels.
157 157 */
158 158 /*!
159 159 \qmlproperty color AbstractAxis::labelsColor
160 160 The color of the axis labels.
161 161 */
162 162
163 163 /*!
164 164 \property QAbstractAxis::labelsAngle
165 165 The angle of the axis labels in degrees.
166 166 */
167 167 /*!
168 168 \qmlproperty int AbstractAxis::labelsAngle
169 169 The angle of the axis labels in degrees.
170 170 */
171 171
172 172 /*!
173 173 \property QAbstractAxis::shadesVisible
174 174 The visibility of the axis shades.
175 175 */
176 176 /*!
177 177 \qmlproperty bool AbstractAxis::shadesVisible
178 178 The visibility of the axis shades.
179 179 */
180 180
181 181 /*!
182 182 \property QAbstractAxis::shadesColor
183 183 The fill (brush) color of the axis shades.
184 184 */
185 185 /*!
186 186 \qmlproperty color AbstractAxis::shadesColor
187 187 The fill (brush) color of the axis shades.
188 188 */
189 189
190 190 /*!
191 191 \property QAbstractAxis::shadesBorderColor
192 192 The border (pen) color of the axis shades.
193 193 */
194 194 /*!
195 195 \qmlproperty color AbstractAxis::shadesBorderColor
196 196 The border (pen) color of the axis shades.
197 197 */
198 198
199 199 /*!
200 200 \property QAbstractAxis::shadesPen
201 201 The pen of the axis shades (area between grid lines).
202 202 */
203 203
204 204 /*!
205 205 \property QAbstractAxis::shadesBrush
206 206 The brush of the axis shades (area between grid lines).
207 207 */
208 208
209 209 /*!
210 210 \property QAbstractAxis::titleVisible
211 211 The visibility of the axis title. By default the value is true.
212 212 */
213 213 /*!
214 214 \qmlproperty bool AbstractAxis::titleVisible
215 215 The visibility of the axis title. By default the value is true.
216 216 */
217 217
218 218 /*!
219 219 \property QAbstractAxis::titleText
220 220 The title of the axis. Empty by default.
221 221 */
222 222 /*!
223 223 \qmlproperty String AbstractAxis::titleText
224 224 The title of the axis. Empty by default.
225 225 */
226 226
227 227 /*!
228 228 \property QAbstractAxis::titlePen
229 229 The pen of the title text.
230 230 */
231 231
232 232 /*!
233 233 \property QAbstractAxis::titleBrush
234 234 The brush of the title text.
235 235 */
236 236
237 237 /*!
238 238 \property QAbstractAxis::titleFont
239 239 The font of the title of the axis.
240 240 */
241 241 /*!
242 242 \qmlproperty Font AbstractAxis::titleFont
243 243 The font of the title of the axis.
244 244 */
245 245
246 246 /*!
247 247 \property QAbstractAxis::orientation
248 248 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
249 249 */
250 250 /*!
251 251 \qmlproperty Qt.Orientation AbstractAxis::orientation
252 252 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a Chart/Series.
253 253 */
254 254
255 255 /*!
256 256 \property QAbstractAxis::alignment
257 257 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
258 258 */
259 259 /*!
260 260 \qmlproperty alignment AbstractAxis::alignment
261 261 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
262 262 */
263 263
264 264 /*!
265 265 \fn void QAbstractAxis::visibleChanged(bool visible)
266 266 Visibility of the axis has changed to \a visible.
267 267 */
268 268 /*!
269 269 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
270 270 Visibility of the axis has changed to \a visible.
271 271 */
272 272
273 273 /*!
274 274 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
275 275 The pen of the line of the axis has changed to \a pen.
276 276 */
277 277
278 278 /*!
279 279 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
280 280 Visibility of the axis line has changed to \a visible.
281 281 */
282 282 /*!
283 283 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
284 284 Visibility of the axis line has changed to \a visible.
285 285 */
286 286
287 287 /*!
288 288 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
289 289 Visibility of the labels of the axis has changed to \a visible.
290 290 */
291 291 /*!
292 292 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
293 293 Visibility of the labels of the axis has changed to \a visible.
294 294 */
295 295
296 296 /*!
297 297 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
298 298 The font of the axis labels has changed to \a font.
299 299 */
300 300 /*!
301 301 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
302 302 The font of the axis labels has changed to \a font.
303 303 */
304 304
305 305 /*!
306 306 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
307 307 The pen of the axis labels has changed to \a pen.
308 308 */
309 309
310 310 /*!
311 311 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
312 312 The brush of the axis labels has changed to \a brush.
313 313 */
314 314
315 315 /*!
316 316 \fn void QAbstractAxis::labelsAngleChanged(int angle)
317 317 The angle of the axis labels has changed to \a angle.
318 318 */
319 319 /*!
320 320 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
321 321 The angle of the axis labels has changed to \a angle.
322 322 */
323 323
324 324 /*!
325 325 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
326 326 Visibility of the grid lines of the axis has changed to \a visible.
327 327 */
328 328 /*!
329 329 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
330 330 Visibility of the grid lines of the axis has changed to \a visible.
331 331 */
332 332
333 333 /*!
334 334 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
335 335 The pen of the grid line has changed to \a pen.
336 336 */
337 337
338 338 /*!
339 339 \fn void QAbstractAxis::colorChanged(QColor color)
340 340 Emitted if the \a color of the axis is changed.
341 341 */
342 342 /*!
343 343 \qmlsignal AbstractAxis::onColorChanged(QColor color)
344 344 Emitted if the \a color of the axis is changed.
345 345 */
346 346
347 347 /*!
348 348 \fn void QAbstractAxis::labelsColorChanged(QColor color)
349 349 Emitted if the \a color of the axis labels is changed.
350 350 */
351 351 /*!
352 352 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
353 353 Emitted if the \a color of the axis labels is changed.
354 354 */
355 355
356 356 /*!
357 357 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
358 358 Visibility of the title text of the axis has changed to \a visible.
359 359 */
360 360 /*!
361 361 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
362 362 Visibility of the title text of the axis has changed to \a visible.
363 363 */
364 364
365 365 /*!
366 366 \fn void QAbstractAxis::titleTextChanged(const QString& text)
367 367 The text of the axis title has changed to \a text.
368 368 */
369 369 /*!
370 370 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
371 371 The text of the axis title has changed to \a text.
372 372 */
373 373
374 374 /*!
375 375 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
376 376 The pen of the axis shades has changed to \a pen.
377 377 */
378 378
379 379 /*!
380 380 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
381 381 The brush of the axis title has changed to \a brush.
382 382 */
383 383
384 384 /*!
385 385 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
386 386 The font of the axis title has changed to \a font.
387 387 */
388 388 /*!
389 389 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
390 390 The font of the axis title has changed to \a font.
391 391 */
392 392
393 393 /*!
394 394 \fn void QAbstractAxis::shadesVisibleChanged(bool)
395 395 Emitted if the visibility of the axis shades is changed to \a visible.
396 396 */
397 397 /*!
398 398 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
399 399 Emitted if the visibility of the axis shades is changed to \a visible.
400 400 */
401 401
402 402 /*!
403 403 \fn void QAbstractAxis::shadesColorChanged(QColor color)
404 404 Emitted if the \a color of the axis shades is changed.
405 405 */
406 406 /*!
407 407 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
408 408 Emitted if the \a color of the axis shades is changed.
409 409 */
410 410
411 411 /*!
412 412 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
413 413 Emitted if the border \a color of the axis shades is changed.
414 414 */
415 415 /*!
416 416 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
417 417 Emitted if the border \a color of the axis shades is changed.
418 418 */
419 419
420 420 /*!
421 421 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
422 422 The brush of the axis shades has changed to \a brush.
423 423 */
424 424
425 425 /*!
426 426 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
427 427 The pen of the axis shades has changed to \a pen.
428 428 */
429 429
430 430 /*!
431 431 \internal
432 432 Constructs new axis object which is a child of \a parent. Ownership is taken by
433 433 QChart when axis added.
434 434 */
435 435
436 436 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
437 437 : QObject(parent),
438 438 d_ptr(&d)
439 439 {
440 440 }
441 441
442 442 /*!
443 443 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
444 444 */
445 445
446 446 QAbstractAxis::~QAbstractAxis()
447 447 {
448 448 if (d_ptr->m_chart)
449 449 qFatal("Still binded axis detected !");
450 450 }
451 451
452 452 /*!
453 453 Sets \a pen used to draw axis line and ticks.
454 454 */
455 455 void QAbstractAxis::setLinePen(const QPen &pen)
456 456 {
457 457 if (d_ptr->m_axisPen != pen) {
458 458 d_ptr->m_axisPen = pen;
459 459 emit linePenChanged(pen);
460 460 }
461 461 }
462 462
463 463 /*!
464 464 Returns pen used to draw axis and ticks.
465 465 */
466 466 QPen QAbstractAxis::linePen() const
467 467 {
468 468 return d_ptr->m_axisPen;
469 469 }
470 470
471 //TODO: remove me
471 //TODO: remove me 2.0
472 472 void QAbstractAxis::setLinePenColor(QColor color)
473 473 {
474 474 QPen p = d_ptr->m_axisPen;
475 475 if (p.color() != color) {
476 476 p.setColor(color);
477 477 setLinePen(p);
478 478 emit colorChanged(color);
479 479 }
480 480 }
481 481
482 482 QColor QAbstractAxis::linePenColor() const
483 483 {
484 484 return d_ptr->m_axisPen.color();
485 485 }
486 486
487 487 /*!
488 488 Sets if axis and ticks are \a visible.
489 489 */
490 490 void QAbstractAxis::setLineVisible(bool visible)
491 491 {
492 492 if (d_ptr->m_arrowVisible != visible) {
493 493 d_ptr->m_arrowVisible = visible;
494 494 emit lineVisibleChanged(visible);
495 495 }
496 496 }
497 497
498 498 bool QAbstractAxis::isLineVisible() const
499 499 {
500 500 return d_ptr->m_arrowVisible;
501 501 }
502 502
503 503 void QAbstractAxis::setGridLineVisible(bool visible)
504 504 {
505 505 if (d_ptr->m_gridLineVisible != visible) {
506 506 d_ptr->m_gridLineVisible = visible;
507 507 emit gridVisibleChanged(visible);
508 508 }
509 509 }
510 510
511 511 bool QAbstractAxis::isGridLineVisible() const
512 512 {
513 513 return d_ptr->m_gridLineVisible;
514 514 }
515 515
516 516 /*!
517 517 Sets \a pen used to draw grid line.
518 518 */
519 519 void QAbstractAxis::setGridLinePen(const QPen &pen)
520 520 {
521 521 if (d_ptr->m_gridLinePen != pen) {
522 522 d_ptr->m_gridLinePen = pen;
523 523 emit gridLinePenChanged(pen);
524 524 }
525 525 }
526 526
527 527 /*!
528 528 Returns pen used to draw grid.
529 529 */
530 530 QPen QAbstractAxis::gridLinePen() const
531 531 {
532 532 return d_ptr->m_gridLinePen;
533 533 }
534 534
535 535 void QAbstractAxis::setLabelsVisible(bool visible)
536 536 {
537 537 if (d_ptr->m_labelsVisible != visible) {
538 538 d_ptr->m_labelsVisible = visible;
539 539 emit labelsVisibleChanged(visible);
540 540 }
541 541 }
542 542
543 543 bool QAbstractAxis::labelsVisible() const
544 544 {
545 545 return d_ptr->m_labelsVisible;
546 546 }
547 547
548 548 /*!
549 549 Sets \a pen used to draw labels.
550 550 */
551 551 void QAbstractAxis::setLabelsPen(const QPen &pen)
552 552 {
553 553 if (d_ptr->m_labelsPen != pen) {
554 554 d_ptr->m_labelsPen = pen;
555 555 emit labelsPenChanged(pen);
556 556 }
557 557 }
558 558
559 559 /*!
560 560 Returns the pen used to labels.
561 561 */
562 562 QPen QAbstractAxis::labelsPen() const
563 563 {
564 564 return d_ptr->m_labelsPen;
565 565 }
566 566
567 567 /*!
568 568 Sets \a brush used to draw labels.
569 569 */
570 570 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
571 571 {
572 572 if (d_ptr->m_labelsBrush != brush) {
573 573 d_ptr->m_labelsBrush = brush;
574 574 emit labelsBrushChanged(brush);
575 575 }
576 576 }
577 577
578 578 /*!
579 579 Returns brush used to draw labels.
580 580 */
581 581 QBrush QAbstractAxis::labelsBrush() const
582 582 {
583 583 return d_ptr->m_labelsBrush;
584 584 }
585 585
586 586 /*!
587 587 Sets \a font used to draw labels.
588 588 */
589 589 void QAbstractAxis::setLabelsFont(const QFont &font)
590 590 {
591 591 if (d_ptr->m_labelsFont != font) {
592 592 d_ptr->m_labelsFont = font;
593 593 emit labelsFontChanged(font);
594 594 }
595 595 }
596 596
597 597 /*!
598 598 Returns font used to draw labels.
599 599 */
600 600 QFont QAbstractAxis::labelsFont() const
601 601 {
602 602 return d_ptr->m_labelsFont;
603 603 }
604 604
605 605 void QAbstractAxis::setLabelsAngle(int angle)
606 606 {
607 607 if (d_ptr->m_labelsAngle != angle) {
608 608 d_ptr->m_labelsAngle = angle;
609 609 emit labelsAngleChanged(angle);
610 610 }
611 611 }
612 612
613 613 int QAbstractAxis::labelsAngle() const
614 614 {
615 615 return d_ptr->m_labelsAngle;
616 616 }
617 //TODO: remove me
617 //TODO: remove me 2.0
618 618 void QAbstractAxis::setLabelsColor(QColor color)
619 619 {
620 620 QBrush b = d_ptr->m_labelsBrush;
621 621 if (b.color() != color) {
622 622 b.setColor(color);
623 623 setLabelsBrush(b);
624 624 emit labelsColorChanged(color);
625 625 }
626 626 }
627 627
628 628 QColor QAbstractAxis::labelsColor() const
629 629 {
630 630 return d_ptr->m_labelsBrush.color();
631 631 }
632 632
633 633 void QAbstractAxis::setTitleVisible(bool visible)
634 634 {
635 635 if (d_ptr->m_titleVisible != visible) {
636 636 d_ptr->m_titleVisible = visible;
637 637 emit titleVisibleChanged(visible);
638 638 }
639 639 }
640 640
641 641 bool QAbstractAxis::isTitleVisible() const
642 642 {
643 643 return d_ptr->m_titleVisible;
644 644 }
645 645
646 646 /*!
647 647 Sets \a pen used to draw title.
648 648 */
649 649 void QAbstractAxis::setTitlePen(const QPen &pen)
650 650 {
651 651 if (d_ptr->m_titlePen != pen) {
652 652 d_ptr->m_titlePen = pen;
653 653 emit titlePenChanged(pen);
654 654 }
655 655 }
656 656
657 657 /*!
658 658 Returns the pen used to title.
659 659 */
660 660 QPen QAbstractAxis::titlePen() const
661 661 {
662 662 return d_ptr->m_titlePen;
663 663 }
664 664
665 665 /*!
666 666 Sets \a brush used to draw title.
667 667 */
668 668 void QAbstractAxis::setTitleBrush(const QBrush &brush)
669 669 {
670 670 if (d_ptr->m_titleBrush != brush) {
671 671 d_ptr->m_titleBrush = brush;
672 672 emit titleBrushChanged(brush);
673 673 }
674 674 }
675 675
676 676 /*!
677 677 Returns brush used to draw title.
678 678 */
679 679 QBrush QAbstractAxis::titleBrush() const
680 680 {
681 681 return d_ptr->m_titleBrush;
682 682 }
683 683
684 684 /*!
685 685 Sets \a font used to draw title.
686 686 */
687 687 void QAbstractAxis::setTitleFont(const QFont &font)
688 688 {
689 689 if (d_ptr->m_titleFont != font) {
690 690 d_ptr->m_titleFont = font;
691 691 emit titleFontChanged(font);
692 692 }
693 693 }
694 694
695 695 /*!
696 696 Returns font used to draw title.
697 697 */
698 698 QFont QAbstractAxis::titleFont() const
699 699 {
700 700 return d_ptr->m_titleFont;
701 701 }
702 702
703 703 void QAbstractAxis::setTitleText(const QString &title)
704 704 {
705 705 if (d_ptr->m_title != title) {
706 706 d_ptr->m_title = title;
707 707 emit titleTextChanged(title);
708 708 }
709 709 }
710 710
711 711 QString QAbstractAxis::titleText() const
712 712 {
713 713 return d_ptr->m_title;
714 714 }
715 715
716 716
717 717 void QAbstractAxis::setShadesVisible(bool visible)
718 718 {
719 719 if (d_ptr->m_shadesVisible != visible) {
720 720 d_ptr->m_shadesVisible = visible;
721 721 emit shadesVisibleChanged(visible);
722 722 }
723 723 }
724 724
725 725 bool QAbstractAxis::shadesVisible() const
726 726 {
727 727 return d_ptr->m_shadesVisible;
728 728 }
729 729
730 730 /*!
731 731 Sets \a pen used to draw shades.
732 732 */
733 733 void QAbstractAxis::setShadesPen(const QPen &pen)
734 734 {
735 735 if (d_ptr->m_shadesPen != pen) {
736 736 d_ptr->m_shadesPen = pen;
737 737 emit shadesPenChanged(pen);
738 738 }
739 739 }
740 740
741 741 /*!
742 742 Returns pen used to draw shades.
743 743 */
744 744 QPen QAbstractAxis::shadesPen() const
745 745 {
746 746 return d_ptr->m_shadesPen;
747 747 }
748 748
749 749 /*!
750 750 Sets \a brush used to draw shades.
751 751 */
752 752 void QAbstractAxis::setShadesBrush(const QBrush &brush)
753 753 {
754 754 if (d_ptr->m_shadesBrush != brush) {
755 755 d_ptr->m_shadesBrush = brush;
756 756 emit shadesBrushChanged(brush);
757 757 }
758 758 }
759 759
760 760 /*!
761 761 Returns brush used to draw shades.
762 762 */
763 763 QBrush QAbstractAxis::shadesBrush() const
764 764 {
765 765 return d_ptr->m_shadesBrush;
766 766 }
767 767
768 768 void QAbstractAxis::setShadesColor(QColor color)
769 769 {
770 770 QBrush b = d_ptr->m_shadesBrush;
771 771 if (b.color() != color) {
772 772 b.setColor(color);
773 773 setShadesBrush(b);
774 774 emit shadesColorChanged(color);
775 775 }
776 776 }
777 777
778 778 QColor QAbstractAxis::shadesColor() const
779 779 {
780 780 return d_ptr->m_shadesBrush.color();
781 781 }
782 782
783 783 void QAbstractAxis::setShadesBorderColor(QColor color)
784 784 {
785 785 QPen p = d_ptr->m_shadesPen;
786 786 if (p.color() != color) {
787 787 p.setColor(color);
788 788 setShadesPen(p);
789 789 emit shadesColorChanged(color);
790 790 }
791 791 }
792 792
793 793 QColor QAbstractAxis::shadesBorderColor() const
794 794 {
795 795 return d_ptr->m_shadesPen.color();
796 796 }
797 797
798 798
799 799 bool QAbstractAxis::isVisible() const
800 800 {
801 801 return d_ptr->m_visible;
802 802 }
803 803
804 804 /*!
805 805 Sets axis, shades, labels and grid lines to be visible.
806 806 */
807 807 void QAbstractAxis::setVisible(bool visible)
808 808 {
809 809 if (d_ptr->m_visible != visible) {
810 810 d_ptr->m_visible = visible;
811 811 emit visibleChanged(visible);
812 812 }
813 813 }
814 814
815 815
816 816 /*!
817 817 Sets axis, shades, labels and grid lines to be visible.
818 818 */
819 819 void QAbstractAxis::show()
820 820 {
821 821 setVisible(true);
822 822 }
823 823
824 824 /*!
825 825 Sets axis, shades, labels and grid lines to not be visible.
826 826 */
827 827 void QAbstractAxis::hide()
828 828 {
829 829 setVisible(false);
830 830 }
831 831
832 832 /*!
833 833 Sets the minimum value shown on the axis.
834 834 Depending on the actual axis type the \a min parameter is converted to appropriate type.
835 835 If the conversion is impossible then the function call does nothing
836 836 */
837 837 void QAbstractAxis::setMin(const QVariant &min)
838 838 {
839 839 d_ptr->setMin(min);
840 840 }
841 841
842 842 /*!
843 843 Sets the maximum value shown on the axis.
844 844 Depending on the actual axis type the \a max parameter is converted to appropriate type.
845 845 If the conversion is impossible then the function call does nothing
846 846 */
847 847 void QAbstractAxis::setMax(const QVariant &max)
848 848 {
849 849 d_ptr->setMax(max);
850 850 }
851 851
852 852 /*!
853 853 Sets the range shown on the axis.
854 854 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
855 855 If the conversion is impossible then the function call does nothing.
856 856 */
857 857 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
858 858 {
859 859 d_ptr->setRange(min, max);
860 860 }
861 861
862 862
863 863 /*!
864 864 Returns the orientation in which the axis is being used (Vertical or Horizontal)
865 865 */
866 866 // NOTE: should have const but it breaks BC:
867 867 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
868 868 Qt::Orientation QAbstractAxis::orientation()
869 869 {
870 870 return d_ptr->orientation();
871 871 }
872 872
873 873 Qt::Alignment QAbstractAxis::alignment() const
874 874 {
875 875 return d_ptr->alignment();
876 876 }
877 877
878 878 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
879 879
880 880 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
881 881 : q_ptr(q),
882 882 m_chart(0),
883 883 m_alignment(0),
884 884 m_orientation(Qt::Orientation(0)),
885 885 m_visible(true),
886 886 m_arrowVisible(true),
887 887 m_gridLineVisible(true),
888 888 m_labelsVisible(true),
889 889 m_labelsAngle(0),
890 890 m_titleVisible(true),
891 891 m_shadesVisible(false),
892 892 m_shadesBrush(Qt::SolidPattern),
893 893 m_shadesOpacity(1.0),
894 894 m_dirty(false)
895 895 {
896 896
897 897 }
898 898
899 899 QAbstractAxisPrivate::~QAbstractAxisPrivate()
900 900 {
901 901 }
902 902
903 903 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
904 904 {
905 905 switch(alignment) {
906 906 case Qt::AlignTop:
907 907 case Qt::AlignBottom:
908 908 m_orientation = Qt::Horizontal;
909 909 break;
910 910 case Qt::AlignLeft:
911 911 case Qt::AlignRight:
912 912 m_orientation = Qt::Vertical;
913 913 break;
914 914 default:
915 915 qWarning()<<"No alignment specified !";
916 916 break;
917 917 };
918 918 m_alignment=alignment;
919 919 }
920 920
921 921 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
922 922 {
923 923 QPen pen;
924 924 QBrush brush;
925 925 QFont font;
926 926
927 927 bool axisX = m_orientation == Qt::Horizontal;
928 928
929 929 //TODO: introduce axis brush
930 930 if (m_visible) {
931 931 if (m_arrowVisible) {
932 932 if (forced || pen == m_axisPen) {
933 933 q_ptr->setLinePen(theme->axisLinePen());
934 934 }
935 935 }
936 936 if (m_gridLineVisible) {
937 937 if (forced || pen == m_gridLinePen) {
938 938 q_ptr->setGridLinePen(theme->girdLinePen());
939 939 }
940 940 }
941 941 if (m_labelsVisible) {
942 942 if (forced || brush == m_labelsBrush){
943 943 q_ptr->setLabelsBrush(theme->labelBrush());
944 944 }
945 945 if (forced || pen == m_labelsPen){
946 946 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
947 947 }
948 948 if (forced || font == m_labelsFont){
949 949 q_ptr->setLabelsFont(theme->labelFont());
950 950 }
951 951 }
952 952 if (m_titleVisible) {
953 953 if (forced || brush == m_titleBrush){
954 954 q_ptr->setTitleBrush(theme->labelBrush());
955 955 }
956 956 if (forced || pen == m_titlePen){
957 957 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
958 958 }
959 //TODO: discuss with Tero
960 959 if (forced || font == m_titleFont){
961 960 QFont font(m_labelsFont);
962 961 font.setBold(true);
963 962 q_ptr->setTitleFont(font);
964 963 }
965 964 }
966 965 if (forced || m_shadesVisible) {
967 966 if (forced || brush == m_shadesBrush){
968 967 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
969 968 }
970 969 if (forced || pen == m_shadesPen){
971 970 q_ptr->setShadesPen(theme->backgroundShadesPen());
972 971 }
973 972 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
974 973 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
975 974 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
976 975 q_ptr->setShadesVisible(true);
977 976 }
978 977 }
979 978 }
980 979 }
981 980
982 981 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
983 982 {
984 983 setRange(min,max);
985 984 }
986 985
987 986 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
988 987 {
989 988 Q_UNUSED(parent);
990 989 }
991 990
992 991 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
993 992 {
994 993 ChartAxis* axis = m_item.data();
995 994 Q_ASSERT(axis);
996 995 if(options.testFlag(QChart::GridAxisAnimations)) {
997 996 axis->setAnimation(new AxisAnimation(axis));
998 997 }else{
999 998 axis->setAnimation(0);
1000 999 }
1001 1000 }
1002 1001
1003 1002
1004 1003
1005 1004 #include "moc_qabstractaxis.cpp"
1006 1005 #include "moc_qabstractaxis_p.cpp"
1007 1006
1008 1007 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,193 +1,192
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 QABSTRACTAXIS_H
22 22 #define QABSTRACTAXIS_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QPen>
26 26 #include <QFont>
27 27 #include <QVariant>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QAbstractAxisPrivate;
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 34 {
35 35 Q_OBJECT
36 36 //visibility
37 37 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
38 38 //arrow
39 39 Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged)
40 40 Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged)
41 41 Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged)
42 42 //labels
43 43 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
44 44 Q_PROPERTY(QPen labelsPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged)
45 45 Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged)
46 //TODO: fix labels angles to work with layout
47 46 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged)
48 47 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged)
49 48 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
50 49 //grid
51 50 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
52 51 Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged)
53 52 //shades
54 53 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
55 54 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
56 55 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
57 56 Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged)
58 57 Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged)
59 58 //title
60 59 Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged)
61 60 Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged)
62 61 Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged)
63 62 Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged)
64 63 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged)
65 64 //orientation
66 65 Q_PROPERTY(Qt::Orientation orientation READ orientation)
67 66 //aligment
68 67 Q_PROPERTY(Qt::Alignment alignment READ alignment)
69 68
70 69 public:
71 70
72 71 enum AxisType {
73 72 AxisTypeNoAxis = 0x0,
74 73 AxisTypeValue = 0x1,
75 74 AxisTypeBarCategory = 0x2,
76 75 AxisTypeCategory = 0x3,
77 76 AxisTypeDateTime = 0x4,
78 77 AxisTypeLogValue = 0x5
79 78 };
80 79
81 80 Q_DECLARE_FLAGS(AxisTypes, AxisType)
82 81
83 82 protected:
84 83 explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0);
85 84
86 85 public:
87 86 ~QAbstractAxis();
88 87
89 88 virtual AxisType type() const = 0;
90 89
91 90 //visibility handling
92 91 bool isVisible() const;
93 92 void setVisible(bool visible = true);
94 93 void show();
95 94 void hide();
96 95
97 96 //arrow handling
98 97 bool isLineVisible() const;
99 98 void setLineVisible(bool visible = true);
100 99 void setLinePen(const QPen &pen);
101 100 QPen linePen() const;
102 101 void setLinePenColor(QColor color);
103 102 QColor linePenColor() const;
104 103
105 104 //grid handling
106 105 bool isGridLineVisible() const;
107 106 void setGridLineVisible(bool visible = true);
108 107 void setGridLinePen(const QPen &pen);
109 108 QPen gridLinePen() const;
110 109
111 110 //labels handling
112 111 bool labelsVisible() const;
113 112 void setLabelsVisible(bool visible = true);
114 113 void setLabelsPen(const QPen &pen);
115 114 QPen labelsPen() const;
116 115 void setLabelsBrush(const QBrush &brush);
117 116 QBrush labelsBrush() const;
118 117 void setLabelsFont(const QFont &font);
119 118 QFont labelsFont() const;
120 119 void setLabelsAngle(int angle);
121 120 int labelsAngle() const;
122 121 void setLabelsColor(QColor color);
123 122 QColor labelsColor() const;
124 123
125 124 //title handling
126 125 bool isTitleVisible() const;
127 126 void setTitleVisible(bool visible = true);
128 127 void setTitlePen(const QPen &pen);
129 128 QPen titlePen() const;
130 129 void setTitleBrush(const QBrush &brush);
131 130 QBrush titleBrush() const;
132 131 void setTitleFont(const QFont &font);
133 132 QFont titleFont() const;
134 133 void setTitleText(const QString &title);
135 134 QString titleText() const;
136 135
137 136 //shades handling
138 137 bool shadesVisible() const;
139 138 void setShadesVisible(bool visible = true);
140 139 void setShadesPen(const QPen &pen);
141 140 QPen shadesPen() const;
142 141 void setShadesBrush(const QBrush &brush);
143 142 QBrush shadesBrush() const;
144 143 void setShadesColor(QColor color);
145 144 QColor shadesColor() const;
146 145 void setShadesBorderColor(QColor color);
147 146 QColor shadesBorderColor() const;
148 147
149 Qt::Orientation orientation(); //TODO: missing const <- BC
148 Qt::Orientation orientation(); //TODO: missing const <- BC (2.0)
150 149 Qt::Alignment alignment() const;
151 150
152 151 //range handling
153 152 void setMin(const QVariant &min);
154 153 void setMax(const QVariant &max);
155 154 void setRange(const QVariant &min, const QVariant &max);
156 155
157 156 Q_SIGNALS:
158 157 void visibleChanged(bool visible);
159 158 void linePenChanged(const QPen& pen);
160 159 void lineVisibleChanged(bool visible);
161 160 void labelsVisibleChanged(bool visible);
162 161 void labelsPenChanged(const QPen& pen);
163 162 void labelsBrushChanged(const QBrush& brush);
164 163 void labelsFontChanged(const QFont& pen);
165 164 void labelsAngleChanged(int angle);
166 165 void gridLinePenChanged(const QPen& pen);
167 166 void gridVisibleChanged(bool visible);
168 167 void colorChanged(QColor color);
169 168 void labelsColorChanged(QColor color);
170 169 void titleTextChanged(const QString& title);
171 170 void titlePenChanged(const QPen& pen);
172 171 void titleBrushChanged(const QBrush& brush);
173 172 void titleVisibleChanged(bool visible);
174 173 void titleFontChanged(const QFont& font);
175 174 void shadesVisibleChanged(bool visible);
176 175 void shadesColorChanged(QColor color);
177 176 void shadesBorderColorChanged(QColor color);
178 177 void shadesPenChanged(const QPen& pen);
179 178 void shadesBrushChanged(const QBrush& brush);
180 179
181 180 protected:
182 181 QScopedPointer<QAbstractAxisPrivate> d_ptr;
183 182 Q_DISABLE_COPY(QAbstractAxis)
184 183 friend class ChartDataSet;
185 184 friend class ChartAxis;
186 185 friend class ChartPresenter;
187 186 friend class ChartThemeManager;
188 187 friend class AbstractDomain;
189 188 };
190 189
191 190 QTCOMMERCIALCHART_END_NAMESPACE
192 191
193 192 #endif // QABSTRACTAXIS_H
@@ -1,84 +1,84
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 QVALUEAXIS_H
22 22 #define QVALUEAXIS_H
23 23
24 24 #include "qabstractaxis.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 class QValueAxisPrivate;
29 29
30 30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
31 31 {
32 32 Q_OBJECT
33 33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged)
34 34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
35 35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
36 36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
37 37 Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged)
38 38
39 39 public:
40 40 explicit QValueAxis(QObject *parent = 0);
41 41 ~QValueAxis();
42 42
43 43 protected:
44 44 QValueAxis(QValueAxisPrivate &d, QObject *parent = 0);
45 45
46 46 public:
47 47 AxisType type() const;
48 48
49 49 //range handling
50 50 void setMin(qreal min);
51 51 qreal min() const;
52 52 void setMax(qreal max);
53 53 qreal max() const;
54 54 void setRange(qreal min, qreal max);
55 55
56 56 //ticks handling
57 57 void setTickCount(int count);
58 58 int tickCount() const;
59 59
60 60 void setLabelFormat(const QString &format);
61 61 QString labelFormat() const;
62 62
63 //TODO: depreciated !
63 //TODO: deprecated! (2.0)
64 64 void setNiceNumbersEnabled(bool enable = true);
65 65 bool niceNumbersEnabled() const;
66 66
67 67 public Q_SLOTS:
68 68 void applyNiceNumbers();
69 69
70 70 Q_SIGNALS:
71 71 void minChanged(qreal min);
72 72 void maxChanged(qreal max);
73 73 void rangeChanged(qreal min, qreal max);
74 74 void tickCountChanged(int tickCount);
75 75 void labelFormatChanged(const QString &format);
76 76
77 77 private:
78 78 Q_DECLARE_PRIVATE(QValueAxis)
79 79 Q_DISABLE_COPY(QValueAxis)
80 80 };
81 81
82 82 QTCOMMERCIALCHART_END_NAMESPACE
83 83
84 84 #endif // QVALUEAXIS_H
@@ -1,70 +1,70
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 QVALUEAXIS_P_H
31 31 #define QVALUEAXIS_P_H
32 32
33 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 void initializeGraphics(QGraphicsItem* parent);
47 47 void initializeDomain(AbstractDomain *domain);
48 48
49 49 qreal min() { return m_min; };
50 50 qreal max() { return m_max; };
51 51 void setRange(qreal min,qreal max);
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 qreal m_min;
60 60 qreal m_max;
61 61 int m_tickCount;
62 62 QString m_format;
63 63 bool m_applying;
64 bool m_niceNumbersEnabled; //TODO: this depreciated
64 bool m_niceNumbersEnabled; //TODO: this deprecated (2.0)
65 65 Q_DECLARE_PUBLIC(QValueAxis)
66 66 };
67 67
68 68 QTCOMMERCIALCHART_END_NAMESPACE
69 69
70 70 #endif // QVALUEAXIS_P_H
@@ -1,394 +1,392
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "chartlayout_p.h"
22 22 #include "chartpresenter_p.h"
23 23 #include "qlegend_p.h"
24 24 #include "chartaxis_p.h"
25 25 #include "charttitle_p.h"
26 26 #include "chartbackground_p.h"
27 27 #include <QDebug>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 static const qreal maxAxisPortion = 0.4;
32 32
33 33 ChartLayout::ChartLayout(ChartPresenter *presenter)
34 34 : m_presenter(presenter),
35 35 m_margins(20, 20, 20, 20),
36 36 m_minChartRect(0, 0, 200, 200)
37 37 {
38 38
39 39 }
40 40
41 41 ChartLayout::~ChartLayout()
42 42 {
43 43
44 44 }
45 45
46 46 void ChartLayout::setGeometry(const QRectF &rect)
47 47 {
48 48 if (!rect.isValid())
49 49 return;
50 50
51 51 QList<ChartAxis *> axes = m_presenter->axisItems();
52 52 ChartTitle *title = m_presenter->titleElement();
53 53 QLegend *legend = m_presenter->legend();
54 54 ChartBackground *background = m_presenter->backgroundElement();
55 55
56 56 QRectF contentGeometry = calculateBackgroundGeometry(rect, background);
57 57
58 58 contentGeometry = calculateContentGeometry(contentGeometry);
59 59
60 60 if (title && title->isVisible())
61 61 contentGeometry = calculateTitleGeometry(contentGeometry, title);
62 62
63 63 if (legend->isAttachedToChart() && legend->isVisible())
64 64 contentGeometry = calculateLegendGeometry(contentGeometry, legend);
65 65
66 66 contentGeometry = calculateAxisGeometry(contentGeometry, axes);
67 67
68 68 m_presenter->setGeometry(contentGeometry);
69 69
70 70 QGraphicsLayout::setGeometry(rect);
71 71 }
72 72
73 73 QRectF ChartLayout::calculateContentGeometry(const QRectF &geometry) const
74 74 {
75 75 return geometry.adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom());
76 76 }
77 77
78 78 QRectF ChartLayout::calculateContentMinimum(const QRectF &minimum) const
79 79 {
80 80 return minimum.adjusted(0, 0, m_margins.left() + m_margins.right(), m_margins.top() + m_margins.bottom());
81 81 }
82 82
83 83
84 84 QRectF ChartLayout::calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const
85 85 {
86 86 qreal left, top, right, bottom;
87 87 getContentsMargins(&left, &top, &right, &bottom);
88 88 QRectF backgroundGeometry = geometry.adjusted(left, top, -right, -bottom);
89 89 if (background)
90 90 background->setRect(backgroundGeometry);
91 91 return backgroundGeometry;
92 92 }
93 93
94 94 QRectF ChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const
95 95 {
96 96 qreal left, top, right, bottom;
97 97 getContentsMargins(&left, &top, &right, &bottom);
98 98 return minimum.adjusted(0, 0, left + right, top + bottom);
99 99 }
100 100
101 101
102 102 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const
103 103 {
104 104 QSizeF left(0,0);
105 105 QSizeF minLeft(0,0);
106 106 QSizeF right(0,0);
107 107 QSizeF minRight(0,0);
108 108 QSizeF bottom(0,0);
109 109 QSizeF minBottom(0,0);
110 110 QSizeF top(0,0);
111 111 QSizeF minTop(0,0);
112 112 int leftCount = 0;
113 113 int rightCount = 0;
114 114 int topCount = 0;
115 115 int bottomCount = 0;
116 116
117 117 foreach (ChartAxis *axis , axes) {
118 118
119 119 if (!axis->isVisible())
120 120 continue;
121 121
122 122
123 123 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
124 124 //this is used to get single thick font size
125 125 QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize);
126 126
127 127 switch (axis->alignment()) {
128 128 case Qt::AlignLeft:
129 129 left.setWidth(left.width()+size.width());
130 130 left.setHeight(qMax(left.height(),size.height()));
131 131 minLeft.setWidth(minLeft.width()+minSize.width());
132 132 minLeft.setHeight(qMax(minLeft.height(),minSize.height()));
133 133 leftCount++;
134 134 break;
135 135 case Qt::AlignRight:
136 136 right.setWidth(right.width()+size.width());
137 137 right.setHeight(qMax(right.height(),size.height()));
138 138 minRight.setWidth(minRight.width()+minSize.width());
139 139 minRight.setHeight(qMax(minRight.height(),minSize.height()));
140 140 rightCount++;
141 141 break;
142 142 case Qt::AlignTop:
143 143 top.setWidth(qMax(top.width(),size.width()));
144 144 top.setHeight(top.height()+size.height());
145 145 minTop.setWidth(qMax(minTop.width(),minSize.width()));
146 146 minTop.setHeight(minTop.height()+minSize.height());
147 147 topCount++;
148 148 break;
149 149 case Qt::AlignBottom:
150 150 bottom.setWidth(qMax(bottom.width(), size.width()));
151 151 bottom.setHeight(bottom.height() + size.height());
152 152 minBottom.setWidth(qMax(minBottom.width(),minSize.width()));
153 153 minBottom.setHeight(minBottom.height() + minSize.height());
154 154 bottomCount++;
155 155 break;
156 156 default:
157 157 qWarning()<<"Axis is without alignment !";
158 158 break;
159 159 }
160 160 }
161 161
162 162 int totalVerticalAxes = leftCount + rightCount;
163 163 qreal leftSqueezeRatio = 1.0;
164 164 qreal rightSqueezeRatio = 1.0;
165 165 qreal vratio = 0;
166 166
167 167 if (totalVerticalAxes > 0)
168 168 vratio = (maxAxisPortion * geometry.width()) / totalVerticalAxes;
169 169
170 170 if (leftCount > 0) {
171 171 int maxWidth = vratio * leftCount;
172 172 if (left.width() > maxWidth) {
173 173 leftSqueezeRatio = maxWidth / left.width();
174 174 left.setWidth(maxWidth);
175 175 }
176 176 }
177 177 if (rightCount > 0) {
178 178 int maxWidth = vratio * rightCount;
179 179 if (right.width() > maxWidth) {
180 180 rightSqueezeRatio = maxWidth / right.width();
181 181 right.setWidth(maxWidth);
182 182 }
183 183 }
184 184
185 185 int totalHorizontalAxes = topCount + bottomCount;
186 186 qreal topSqueezeRatio = 1.0;
187 187 qreal bottomSqueezeRatio = 1.0;
188 188 qreal hratio = 0;
189 189
190 190 if (totalHorizontalAxes > 0)
191 191 hratio = (maxAxisPortion * geometry.height()) / totalHorizontalAxes;
192 192
193 193 if (topCount > 0) {
194 194 int maxHeight = hratio * topCount;
195 195 if (top.height() > maxHeight) {
196 196 topSqueezeRatio = maxHeight / top.height();
197 197 top.setHeight(maxHeight);
198 198 }
199 199 }
200 200 if (bottomCount > 0) {
201 201 int maxHeight = hratio * bottomCount;
202 202 if (bottom.height() > maxHeight) {
203 203 bottomSqueezeRatio = maxHeight / bottom.height();
204 204 bottom.setHeight(maxHeight);
205 205 }
206 206 }
207 207
208 208 qreal minHeight = qMax(minLeft.height(),minRight.height()) + 1;
209 209 qreal minWidth = qMax(minTop.width(),minBottom.width()) + 1;
210 210
211 211 QRectF chartRect = geometry.adjusted(qMax(left.width(),minWidth/2), qMax(top.height(), minHeight/2),-qMax(right.width(),minWidth/2),-qMax(bottom.height(),minHeight/2));
212 212
213 213 qreal leftOffset = 0;
214 214 qreal rightOffset = 0;
215 215 qreal topOffset = 0;
216 216 qreal bottomOffset = 0;
217 217
218 218 foreach(ChartElement *axisElement , axes) {
219
220 //TODO fixme
221 219 ChartAxis* axis = qobject_cast<ChartAxis*>(axisElement);
222 220
223 221 if (!axis->isVisible())
224 222 continue;
225 223
226 224 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
227 225
228 226 switch(axis->alignment()){
229 227 case Qt::AlignLeft:{
230 228 qreal width = size.width();
231 229 if (leftSqueezeRatio < 1.0)
232 230 width *= leftSqueezeRatio;
233 231 leftOffset+=width;
234 232 axis->setGeometry(QRect(chartRect.left()-leftOffset, geometry.top(),width, geometry.bottom()),chartRect);
235 233 break;
236 234 }
237 235 case Qt::AlignRight:{
238 236 qreal width = size.width();
239 237 if (rightSqueezeRatio < 1.0)
240 238 width *= rightSqueezeRatio;
241 239 axis->setGeometry(QRect(chartRect.right()+rightOffset,geometry.top(),width,geometry.bottom()),chartRect);
242 240 rightOffset+=width;
243 241 break;
244 242 }
245 243 case Qt::AlignTop: {
246 244 qreal height = size.height();
247 245 if (topSqueezeRatio < 1.0)
248 246 height *= topSqueezeRatio;
249 247 axis->setGeometry(QRect(geometry.left(), chartRect.top() - topOffset - height, geometry.width(), height), chartRect);
250 248 topOffset += height;
251 249 break;
252 250 }
253 251 case Qt::AlignBottom:
254 252 qreal height = size.height();
255 253 if (bottomSqueezeRatio < 1.0)
256 254 height *= bottomSqueezeRatio;
257 255 axis->setGeometry(QRect(geometry.left(), chartRect.bottom() + bottomOffset, geometry.width(), height), chartRect);
258 256 bottomOffset += height;
259 257 break;
260 258 }
261 259 }
262 260
263 261 return chartRect;
264 262 }
265 263
266 264 QRectF ChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const
267 265 {
268 266 QSizeF left;
269 267 QSizeF right;
270 268 QSizeF bottom;
271 269 QSizeF top;
272 270
273 271 foreach (ChartAxis *axis, axes) {
274 272
275 273 QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize);
276 274
277 275 if (!axis->isVisible())
278 276 continue;
279 277
280 278 switch (axis->alignment()) {
281 279 case Qt::AlignLeft:
282 280 left.setWidth(left.width() + size.width());
283 281 left.setHeight(qMax(left.height() * 2, size.height()));
284 282 break;
285 283 case Qt::AlignRight:
286 284 right.setWidth(right.width() + size.width());
287 285 right.setHeight(qMax(right.height() * 2, size.height()));
288 286 break;
289 287 case Qt::AlignTop:
290 288 top.setWidth(qMax(top.width(), size.width()));
291 289 top.setHeight(top.height() + size.height());
292 290 break;
293 291 case Qt::AlignBottom:
294 292 bottom.setWidth(qMax(bottom.width(), size.width()));
295 293 bottom.setHeight(bottom.height() + size.height());
296 294 break;
297 295 }
298 296 }
299 297 return minimum.adjusted(0, 0, left.width() + right.width() + qMax(top.width(), bottom.width()), top.height() + bottom.height() + qMax(left.height(), right.height()));
300 298 }
301 299
302 300 QRectF ChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const
303 301 {
304 302 QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1));
305 303 QRectF legendRect;
306 304 QRectF result;
307 305
308 306 switch (legend->alignment()) {
309 307 case Qt::AlignTop: {
310 308 legendRect = QRectF(geometry.topLeft(), QSizeF(geometry.width(), size.height()));
311 309 result = geometry.adjusted(0, legendRect.height(), 0, 0);
312 310 break;
313 311 }
314 312 case Qt::AlignBottom: {
315 313 legendRect = QRectF(QPointF(geometry.left(), geometry.bottom() - size.height()), QSizeF(geometry.width(), size.height()));
316 314 result = geometry.adjusted(0, 0, 0, -legendRect.height());
317 315 break;
318 316 }
319 317 case Qt::AlignLeft: {
320 318 qreal width = qMin(size.width(), geometry.width() * maxAxisPortion);
321 319 legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height()));
322 320 result = geometry.adjusted(width, 0, 0, 0);
323 321 break;
324 322 }
325 323 case Qt::AlignRight: {
326 324 qreal width = qMin(size.width(), geometry.width() * maxAxisPortion);
327 325 legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height()));
328 326 result = geometry.adjusted(0, 0, -width, 0);
329 327 break;
330 328 }
331 329 default: {
332 330 legendRect = QRectF(0, 0, 0, 0);
333 331 result = geometry;
334 332 break;
335 333 }
336 334 }
337 335
338 336 legend->setGeometry(legendRect);
339 337
340 338 return result;
341 339 }
342 340
343 341 QRectF ChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const
344 342 {
345 343 QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1));
346 344 return geometry.adjusted(0, 0, minSize.width(), minSize.height());
347 345 }
348 346
349 347 QRectF ChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const
350 348 {
351 349 title->setGeometry(geometry);
352 350 QPointF center = geometry.center() - title->boundingRect().center();
353 351 title->setPos(center.x(),title->pos().y());
354 352 return geometry.adjusted(0,title->boundingRect().height()+1,0,0);
355 353 }
356 354
357 355 QRectF ChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const
358 356 {
359 357 QSizeF min = title->sizeHint(Qt::MinimumSize);
360 358 return minimum.adjusted(0, 0, min.width(), min.height());
361 359 }
362 360
363 361 QSizeF ChartLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
364 362 {
365 363 Q_UNUSED(constraint);
366 364 if (which == Qt::MinimumSize) {
367 365 QList<ChartAxis *> axes = m_presenter->axisItems();
368 366 ChartTitle *title = m_presenter->titleElement();
369 367 QLegend *legend = m_presenter->legend();
370 368 QRectF minimumRect(0, 0, 0, 0);
371 369 minimumRect = calculateBackgroundMinimum(minimumRect);
372 370 minimumRect = calculateContentMinimum(minimumRect);
373 371 minimumRect = calculateTitleMinimum(minimumRect, title);
374 372 minimumRect = calculateLegendMinimum(minimumRect, legend);
375 373 minimumRect = calculateAxisMinimum(minimumRect, axes);
376 374 return minimumRect.united(m_minChartRect).size().toSize();
377 375 }
378 376 return QSize(-1, -1);
379 377 }
380 378
381 379 void ChartLayout::setMargins(const QMargins &margins)
382 380 {
383 381 if (m_margins != margins) {
384 382 m_margins = margins;
385 383 updateGeometry();
386 384 }
387 385 }
388 386
389 387 QMargins ChartLayout::margins() const
390 388 {
391 389 return m_margins;
392 390 }
393 391
394 392 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,167 +1,167
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 CHARTPRESENTER_H
31 31 #define CHARTPRESENTER_H
32 32
33 33 #include "qchartglobal.h"
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
34 #include "qchart.h" //because of QChart::ChartThemeId
35 35 #include <QRectF>
36 36 #include <QMargins>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class ChartItem;
41 41 class AxisItem;
42 42 class QAbstractSeries;
43 43 class ChartDataSet;
44 44 class AbstractDomain;
45 45 class ChartAxis;
46 46 class ChartAnimator;
47 47 class ChartBackground;
48 48 class ChartTitle;
49 49 class ChartAnimation;
50 50 class ChartLayout;
51 51
52 52 class ChartPresenter: public QObject
53 53 {
54 54 Q_OBJECT
55 55 public:
56 56 enum ZValues {
57 57 BackgroundZValue = -1,
58 58 ShadesZValue ,
59 59 GridZValue,
60 60 AxisZValue,
61 61 SeriesZValue,
62 62 LineChartZValue = SeriesZValue,
63 63 SplineChartZValue = SeriesZValue,
64 64 BarSeriesZValue = SeriesZValue,
65 65 ScatterSeriesZValue = SeriesZValue,
66 66 PieSeriesZValue = SeriesZValue,
67 67 LegendZValue,
68 68 TopMostZValue
69 69 };
70 70
71 71 enum State {
72 72 ShowState,
73 73 ScrollUpState,
74 74 ScrollDownState,
75 75 ScrollLeftState,
76 76 ScrollRightState,
77 77 ZoomInState,
78 78 ZoomOutState
79 79 };
80 80
81 81 ChartPresenter(QChart *chart);
82 82 virtual ~ChartPresenter();
83 83
84 84
85 85 void setGeometry(QRectF rect);
86 86 QRectF geometry() const;
87 87
88 88 QGraphicsItem *rootItem(){ return m_chart; }
89 89 ChartBackground *backgroundElement();
90 90 ChartTitle *titleElement();
91 91 QList<ChartAxis *> axisItems() const;
92 92 QList<ChartItem *> chartItems() const;
93 93
94 94 ChartItem* chartElement(QAbstractSeries* series) const;
95 95 ChartAxis* chartElement(QAbstractAxis* axis) const;
96 96
97 97 QLegend *legend();
98 98
99 99 void setBackgroundBrush(const QBrush &brush);
100 100 QBrush backgroundBrush() const;
101 101
102 102 void setBackgroundPen(const QPen &pen);
103 103 QPen backgroundPen() const;
104 104
105 105 void setTitle(const QString &title);
106 106 QString title() const;
107 107
108 108 void setTitleFont(const QFont &font);
109 109 QFont titleFont() const;
110 110
111 111 void setTitleBrush(const QBrush &brush);
112 112 QBrush titleBrush() const;
113 113
114 114 void setBackgroundVisible(bool visible);
115 115 bool isBackgroundVisible() const;
116 116
117 117 void setBackgroundDropShadowEnabled(bool enabled);
118 118 bool isBackgroundDropShadowEnabled() const;
119 119
120 120 void setVisible(bool visible);
121 121
122 122 void setAnimationOptions(QChart::AnimationOptions options);
123 123 QChart::AnimationOptions animationOptions() const;
124 124
125 125 void startAnimation(ChartAnimation *animation);
126 126
127 127 //TODO refactor
128 128 void setState(State state,QPointF point);
129 129 State state() const { return m_state; }
130 130 QPointF statePoint() const { return m_statePoint; }
131 131 ChartLayout *layout();
132 132
133 133 private:
134 134 void createBackgroundItem();
135 135 void createTitleItem();
136 136
137 137 public Q_SLOTS:
138 138 void handleSeriesAdded(QAbstractSeries *series);
139 139 void handleSeriesRemoved(QAbstractSeries *series);
140 140 void handleAxisAdded(QAbstractAxis *axis);
141 141 void handleAxisRemoved(QAbstractAxis *axis);
142 142
143 143 private Q_SLOTS:
144 144 void handleAnimationFinished();
145 145
146 146 Q_SIGNALS:
147 147 void animationsFinished();
148 148
149 149 private:
150 150 QChart *m_chart;
151 151 QList<ChartItem *> m_chartItems;
152 152 QList<ChartAxis *> m_axisItems;
153 153 QList<QAbstractSeries *> m_series;
154 154 QList<QAbstractAxis *> m_axes;
155 155 QChart::AnimationOptions m_options;
156 156 State m_state;
157 157 QPointF m_statePoint;
158 158 QList<ChartAnimation *> m_animations;
159 159 ChartLayout *m_layout;
160 160 ChartBackground *m_background;
161 161 ChartTitle *m_title;
162 162 QRectF m_rect;
163 163 };
164 164
165 165 QTCOMMERCIALCHART_END_NAMESPACE
166 166
167 167 #endif /* CHARTPRESENTER_H */
@@ -1,319 +1,314
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "qabstractseries.h"
22 22 #include "qabstractseries_p.h"
23 23 #include "chartdataset_p.h"
24 24 #include "qchart.h"
25 25 #include "qchart_p.h"
26 26 #include "chartitem_p.h"
27 27 #include "xydomain_p.h"
28 28 #include "xlogydomain_p.h"
29 29 #include "logxydomain_p.h"
30 30 #include "logxlogydomain_p.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QAbstractSeries
36 36 \brief Base class for all QtCommercial Chart series.
37 37 \mainclass
38 38
39 39 Usually you use the series type specific inherited classes instead of the base class.
40 40 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
41 41 QPercentBarSeries, QPieSeries
42 42 */
43 43 /*!
44 44 \qmlclass AbstractSeries
45 45 AbstractSeries is the base class for all series.
46 46 The class cannot be instantiated by the user.
47 47 */
48 48
49 49 /*!
50 50 \enum QAbstractSeries::SeriesType
51 51
52 52 The type of the series object.
53 53
54 54 \value SeriesTypeLine
55 55 \value SeriesTypeArea
56 56 \value SeriesTypeBar
57 57 \value SeriesTypeStackedBar
58 58 \value SeriesTypePercentBar
59 59 \value SeriesTypePie
60 60 \value SeriesTypeScatter
61 61 \value SeriesTypeSpline
62 62 \value SeriesTypeHorizontalBar
63 63 \value SeriesTypeHorizontalStackedBar
64 64 \value SeriesTypeHorizontalPercentBar
65 65 */
66 66
67 67 /*!
68 68 \property QAbstractSeries::type
69 69 The type of the series.
70 70 */
71 71 /*!
72 72 \qmlproperty ChartView.SeriesType AbstractSeries::type
73 73 The type of the series.
74 74 */
75 75
76 76 /*!
77 77 \property QAbstractSeries::name
78 78 \brief name of the series property. The name is shown in legend for QXYSeries.
79 79 */
80 80 /*!
81 81 \qmlproperty string AbstractSeries::name
82 82 Name of the series. The name is shown in legend for QXYSeries.
83 83 */
84 84
85 85 /*!
86 86 \fn void QAbstractSeries::nameChanged()
87 87 This signal is emitted when the series name changes.
88 88 */
89 89 /*!
90 90 \qmlsignal AbstractSeries::onNameChanged()
91 91 This signal is emitted when the series name changes.
92 92 */
93 93
94 94 /*!
95 95 \property QAbstractSeries::visible
96 96 \brief whether the series is visible or not; true by default.
97 97 */
98 98 /*!
99 99 \qmlproperty bool AbstractSeries::visible
100 100 Visibility of the series. True by default.
101 101 */
102 102
103 103 /*!
104 104 \fn void QAbstractSeries::visibleChanged()
105 105 Emitted when the series visibility changes.
106 106 */
107 107 /*!
108 108 \qmlsignal AbstractSeries::onVisibleChanged()
109 109 Emitted when the series visibility changes.
110 110 */
111 111
112 112 /*!
113 113 \property QAbstractSeries::opacity
114 114 \brief The opacity of the series.
115 115 By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque).
116 116 */
117 117 /*!
118 118 \qmlproperty real AbstractSeries::opacity
119 119 The opacity of the series. By default the opacity is 1.0.
120 120 The valid values range from 0.0 (transparent) to 1.0 (opaque).
121 121 */
122 122
123 123 /*!
124 124 \fn void QAbstractSeries::opacityChanged()
125 125 Emitted when the opacity of the series changes.
126 126 */
127 127 /*!
128 128 \qmlsignal AbstractSeries::onOpacityChanged()
129 129 Emitted when the opacity of the series changes.
130 130 */
131 131
132 132 /*!
133 133 \internal
134 134 \brief Constructs ChartSeries object with \a parent.
135 135 */
136 136 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
137 137 QObject(parent),
138 138 d_ptr(&d)
139 139 {
140 140 }
141 141
142 142 /*!
143 143 \brief Virtual destructor for the chart series.
144 144 */
145 145 QAbstractSeries::~QAbstractSeries()
146 146 {
147 147 if (d_ptr->m_chart)
148 148 qFatal("Still binded series detected !");
149 149 }
150 150
151 151 void QAbstractSeries::setName(const QString &name)
152 152 {
153 153 if (name != d_ptr->m_name) {
154 154 d_ptr->m_name = name;
155 155 emit nameChanged();
156 156 }
157 157 }
158 158
159 159 QString QAbstractSeries::name() const
160 160 {
161 161 return d_ptr->m_name;
162 162 }
163 163
164 164 /*!
165 165 Sets the visibility of series to \a visible
166 166 */
167 167 void QAbstractSeries::setVisible(bool visible)
168 168 {
169 169 if (visible != d_ptr->m_visible) {
170 170 d_ptr->m_visible = visible;
171 171 emit visibleChanged();
172 172 }
173 173 }
174 174
175 175 /*!
176 176 Returns the visibility of series
177 177 */
178 178 bool QAbstractSeries::isVisible() const
179 179 {
180 180 return d_ptr->m_visible;
181 181 }
182 182
183 183 qreal QAbstractSeries::opacity() const
184 184 {
185 185 return d_ptr->m_opacity;
186 186 }
187 187
188 188 void QAbstractSeries::setOpacity(qreal opacity)
189 189 {
190 190 if (opacity != d_ptr->m_opacity) {
191 191 d_ptr->m_opacity = opacity;
192 192 emit opacityChanged();
193 193 }
194 194 }
195 195
196 196 /*!
197 197 \brief Returns the chart where series belongs to.
198 198
199 199 Set automatically when the series is added to the chart
200 200 and unset when the series is removed from the chart.
201 201 */
202 202 QChart *QAbstractSeries::chart() const
203 203 {
204 204 return d_ptr->m_chart;
205 205 }
206 206
207 //void QAbstractSeries::adjustView()
208 //{
209 // //TODO:
210 //}
211
212 207 /*!
213 208 \brief Sets the visibility of the series to true
214 209
215 210 \sa setVisible(), isVisible()
216 211 */
217 212 void QAbstractSeries::show()
218 213 {
219 214 setVisible(true);
220 215 }
221 216
222 217 /*!
223 218 \brief Sets the visibility of the series to false
224 219
225 220 \sa setVisible(), isVisible()
226 221 */
227 222 void QAbstractSeries::hide()
228 223 {
229 224 setVisible(false);
230 225 }
231 226
232 227 /*!
233 228 Attach \a axis to the series.
234 229 \return true if the axis was attached successfully, false otherwise.
235 230 \sa QChart::addAxis(), QChart::createDefaultAxes()
236 231 */
237 232 bool QAbstractSeries::attachAxis(QAbstractAxis* axis)
238 233 {
239 234 if(d_ptr->m_chart) {
240 235 return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis);
241 236 } else {
242 237 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
243 238 return false;
244 239 }
245 240 }
246 241
247 242 /*!
248 243 Detach \a axis from the series.
249 244 \return true if the axis was detached successfully, false otherwise.
250 245 \sa QChart::removeAxis()
251 246 */
252 247 bool QAbstractSeries::detachAxis(QAbstractAxis* axis)
253 248 {
254 249 if(d_ptr->m_chart) {
255 250 return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis);
256 251 }
257 252 else {
258 253 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
259 254 return false;
260 255 }
261 256 }
262 257
263 258 /*!
264 259 Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except
265 260 in case of a QPieSeries, which does not have any axes attached.
266 261 \sa attachAxis(), detachAxis()
267 262 */
268 263 QList<QAbstractAxis*> QAbstractSeries::attachedAxes()
269 264 {
270 265 return d_ptr->m_axes;
271 266 }
272 267
273 268 ///////////////////////////////////////////////////////////////////////////////////////////////////
274 269
275 270 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q)
276 271 : q_ptr(q),
277 272 m_chart(0),
278 273 m_item(0),
279 274 m_domain(new XYDomain()),
280 275 m_visible(true),
281 276 m_opacity(1.0)
282 277 {
283 278 }
284 279
285 280 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
286 281 {
287 282 }
288 283
289 284 void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain)
290 285 {
291 286 Q_ASSERT(domain);
292 287 if(m_domain.data()!=domain) {
293 288 if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated()));
294 289 m_domain.reset(domain);
295 290 if(!m_item.isNull()) {
296 291 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
297 292 m_item->handleDomainUpdated();
298 293 }
299 294 }
300 295 }
301 296
302 297 void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
303 298 {
304 299 Q_ASSERT(!m_item.isNull());
305 300 Q_UNUSED(parent);
306 301 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
307 302 }
308 303
309 304 void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
310 305 {
311 306 Q_UNUSED(options);
312 307 }
313 308
314 309 #include "moc_qabstractseries.cpp"
315 310 #include "moc_qabstractseries_p.cpp"
316 311
317 312 QTCOMMERCIALCHART_END_NAMESPACE
318 313
319 314
@@ -1,665 +1,663
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "qchart.h"
22 22 #include "qchart_p.h"
23 23 #include "legendscroller_p.h"
24 24 #include "qlegend_p.h"
25 25 #include "chartbackground_p.h"
26 26 #include "qabstractaxis.h"
27 27 #include "chartlayout_p.h"
28 28 #include "charttheme_p.h"
29 29 #include "chartpresenter_p.h"
30 30 #include "chartdataset_p.h"
31 31 #include <QGraphicsScene>
32 32 #include <QGraphicsSceneResizeEvent>
33 33
34 34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 35
36 36 /*!
37 37 \enum QChart::ChartTheme
38 38
39 39 This enum describes the theme used by the chart.
40 40
41 41 \value ChartThemeLight The default theme
42 42 \value ChartThemeBlueCerulean
43 43 \value ChartThemeDark
44 44 \value ChartThemeBrownSand
45 45 \value ChartThemeBlueNcs
46 46 \value ChartThemeHighContrast
47 47 \value ChartThemeBlueIcy
48 48 */
49 49
50 50 /*!
51 51 \enum QChart::AnimationOption
52 52
53 53 For enabling/disabling animations. Defaults to NoAnimation.
54 54
55 55 \value NoAnimation
56 56 \value GridAxisAnimations
57 57 \value SeriesAnimations
58 58 \value AllAnimations
59 59 */
60 60
61 61 /*!
62 62 \class QChart
63 63 \brief QtCommercial chart API.
64 64
65 65 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
66 66 representation of different types of series and other chart related objects like
67 67 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
68 68 convenience class QChartView instead of QChart.
69 69 \sa QChartView
70 70 */
71 71
72 72 /*!
73 73 \property QChart::animationOptions
74 74 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
75 75 */
76 76
77 77 /*!
78 78 \property QChart::backgroundVisible
79 79 Whether the chart background is visible or not.
80 80 \sa setBackgroundBrush(), setBackgroundPen()
81 81 */
82 82
83 83 /*!
84 84 \property QChart::dropShadowEnabled
85 85 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
86 86 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
87 87 */
88 88
89 89 /*!
90 90 \property QChart::minimumMargins
91 91 Minimum margins between the plot area (axes) and the edge of the chart widget.
92 92 */
93 93
94 94 /*!
95 95 \property QChart::margins
96 96 Minimum between the plot area (axes) and the edge of the chart widget.
97 97 */
98 98
99 99 /*!
100 100 \property QChart::theme
101 101 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
102 102 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
103 103 different themes.
104 104 Note: changing the theme will overwrite all customizations previously applied to the series.
105 105 */
106 106
107 107 /*!
108 108 \property QChart::title
109 109 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
110 110 */
111 111
112 112 /*!
113 113 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
114 114 */
115 115 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
116 116 : QGraphicsWidget(parent, wFlags),
117 117 d_ptr(new QChartPrivate(this))
118 118 {
119 119 d_ptr->m_legend = new LegendScroller(this);
120 120 setTheme(QChart::ChartThemeLight);
121 //TODO: what is that ?
122 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
123 121 setLayout(d_ptr->m_presenter->layout());
124 122 }
125 123
126 124 /*!
127 125 Destroys the object and it's children, like series and axis objects added to it.
128 126 */
129 127 QChart::~QChart()
130 128 {
131 129 //start by deleting dataset, it will remove all series and axes
132 130 delete d_ptr->m_dataset;
133 131 d_ptr->m_dataset = 0;
134 132 }
135 133
136 134 /*!
137 135 Adds the \a series onto the chart and takes the ownership of the object.
138 136 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 137 the y axis).
140 138
141 139 \sa removeSeries(), removeAllSeries()
142 140 */
143 141 void QChart::addSeries(QAbstractSeries *series)
144 142 {
145 143 Q_ASSERT(series);
146 144 d_ptr->m_dataset->addSeries(series);
147 145 }
148 146
149 147 /*!
150 148 Removes the \a series specified in a perameter from the QChartView.
151 149 It releses its ownership of the specified QChartSeries object.
152 150 It does not delete the pointed QChartSeries data object
153 151 \sa addSeries(), removeAllSeries()
154 152 */
155 153 void QChart::removeSeries(QAbstractSeries *series)
156 154 {
157 155 Q_ASSERT(series);
158 156 d_ptr->m_dataset->removeSeries(series);
159 157 }
160 158
161 159 /*!
162 160 Removes all the QChartSeries that have been added to the QChartView
163 161 It also deletes the pointed QChartSeries data objects
164 162 \sa addSeries(), removeSeries()
165 163 */
166 164 void QChart::removeAllSeries()
167 165 {
168 166 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
169 167 removeSeries(s);
170 168 delete s;
171 169 }
172 170 }
173 171
174 172 /*!
175 173 Sets the \a brush that is used for painting the background of the chart area.
176 174 */
177 175 void QChart::setBackgroundBrush(const QBrush &brush)
178 176 {
179 177 d_ptr->m_presenter->setBackgroundBrush(brush);
180 178 }
181 179
182 180 /*!
183 181 Gets the brush that is used for painting the background of the chart area.
184 182 */
185 183 QBrush QChart::backgroundBrush() const
186 184 {
187 185 return d_ptr->m_presenter->backgroundBrush();
188 186 }
189 187
190 188 /*!
191 189 Sets the \a pen that is used for painting the background of the chart area.
192 190 */
193 191 void QChart::setBackgroundPen(const QPen &pen)
194 192 {
195 193 d_ptr->m_presenter->setBackgroundPen(pen);
196 194 }
197 195
198 196 /*!
199 197 Gets the pen that is used for painting the background of the chart area.
200 198 */
201 199 QPen QChart::backgroundPen() const
202 200 {
203 201 return d_ptr->m_presenter->backgroundPen();
204 202 }
205 203
206 204 /*!
207 205 Sets the chart \a title. The description text that is drawn above the chart.
208 206 */
209 207 void QChart::setTitle(const QString &title)
210 208 {
211 209 d_ptr->m_presenter->setTitle(title);
212 210 }
213 211
214 212 /*!
215 213 Returns the chart title. The description text that is drawn above the chart.
216 214 */
217 215 QString QChart::title() const
218 216 {
219 217 return d_ptr->m_presenter->title();
220 218 }
221 219
222 220 /*!
223 221 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
224 222 */
225 223 void QChart::setTitleFont(const QFont &font)
226 224 {
227 225 d_ptr->m_presenter->setTitleFont(font);
228 226 }
229 227
230 228 /*!
231 229 Gets the font that is used for drawing the chart description text that is rendered above the chart.
232 230 */
233 231 QFont QChart::titleFont() const
234 232 {
235 233 return d_ptr->m_presenter->titleFont();
236 234 }
237 235
238 236 /*!
239 237 Sets the \a brush used for rendering the title text.
240 238 */
241 239 void QChart::setTitleBrush(const QBrush &brush)
242 240 {
243 241 d_ptr->m_presenter->setTitleBrush(brush);
244 242 }
245 243
246 244 /*!
247 245 Returns the brush used for rendering the title text.
248 246 */
249 247 QBrush QChart::titleBrush() const
250 248 {
251 249 return d_ptr->m_presenter->titleBrush();
252 250 }
253 251
254 252 void QChart::setTheme(QChart::ChartTheme theme)
255 253 {
256 254 d_ptr->m_themeManager->setTheme(theme);
257 255 }
258 256
259 257 QChart::ChartTheme QChart::theme() const
260 258 {
261 259 return d_ptr->m_themeManager->theme()->id();
262 260 }
263 261
264 262 /*!
265 263 Zooms in the view by a factor of 2
266 264 */
267 265 void QChart::zoomIn()
268 266 {
269 267 d_ptr->zoomIn(2.0);
270 268 }
271 269
272 270 /*!
273 271 Zooms in the view to a maximum level at which \a rect is still fully visible.
274 272 */
275 273 void QChart::zoomIn(const QRectF &rect)
276 274 {
277 275 d_ptr->zoomIn(rect);
278 276 }
279 277
280 278 /*!
281 279 Restores the view zoom level to the previous one.
282 280 */
283 281 void QChart::zoomOut()
284 282 {
285 283 d_ptr->zoomOut(2.0);
286 284 }
287 285
288 286 /*!
289 287 Zooms in the view by a \a factor.
290 288
291 289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
292 290 */
293 291 void QChart::zoom(qreal factor)
294 292 {
295 293 if (qFuzzyCompare(factor, 0))
296 294 return;
297 295
298 296 if (qFuzzyCompare(factor, (qreal)1.0))
299 297 return;
300 298
301 299 if (factor < 0)
302 300 return;
303 301
304 302 if (factor > 1.0)
305 303 d_ptr->zoomIn(factor);
306 304 else
307 305 d_ptr->zoomOut(1.0 / factor);
308 306 }
309 307
310 308 /*!
311 309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
312 310 If no series is provided then pointer to currently visible axis is provided
313 311 */
314 312 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
315 313 {
316 314 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
317 315 if (axisList.count())
318 316 return axisList[0];
319 317 return 0;
320 318 }
321 319
322 320 /*!
323 321 Returns the pointer to the y axis object of the chart asociated with the specified \a series
324 322 If no series is provided then pointer to currently visible axis is provided
325 323 */
326 324 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
327 325 {
328 326 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
329 327 if (axisList.count())
330 328 return axisList[0];
331 329 return 0;
332 330 }
333 331
334 332 /*!
335 333 Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the
336 334 specified orientation are returned.
337 335 \sa addAxis(), createDefaultAxes()
338 336 */
339 337 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
340 338 {
341 339 QList<QAbstractAxis *> result ;
342 340
343 341 if (series) {
344 342 foreach (QAbstractAxis *axis, series->attachedAxes()){
345 343 if (orientation.testFlag(axis->orientation()))
346 344 result << axis;
347 345 }
348 346 } else {
349 347 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
350 348 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
351 349 result << axis;
352 350 }
353 351 }
354 352
355 353 return result;
356 354 }
357 355
358 356 /*!
359 357 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
360 358
361 359 Creates the axes for the chart based on the series that has already been added to the chart.
362 360
363 361 \table
364 362 \header
365 363 \o Series type
366 364 \o X-axis
367 365 \o Y-axis
368 366 \row
369 367 \o QXYSeries
370 368 \o QValueAxis
371 369 \o QValueAxis
372 370 \row
373 371 \o QBarSeries
374 372 \o QBarCategoryAxis
375 373 \o QValueAxis
376 374 \row
377 375 \o QPieSeries
378 376 \o None
379 377 \o None
380 378 \endtable
381 379
382 380 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
383 381 If there are sevaral series added of different types then each series gets its own axes pair.
384 382
385 383 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
386 384
387 385 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
388 386 QPieSeries does not create any axes.
389 387
390 388 \sa axisX(), axisY(), setAxisX(), setAxisY()
391 389 */
392 390 void QChart::createDefaultAxes()
393 391 {
394 392 d_ptr->m_dataset->createDefaultAxes();
395 393 }
396 394
397 395 /*!
398 396 Returns the legend object of the chart. Ownership stays in chart.
399 397 */
400 398 QLegend *QChart::legend() const
401 399 {
402 400 return d_ptr->m_legend;
403 401 }
404 402
405 403 /*!
406 404 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
407 405 Deprecated. Use setMargins().
408 406 */
409 407 void QChart::setMinimumMargins(const QMargins &margins)
410 408 {
411 409 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
412 410 d_ptr->m_presenter->layout()->setMargins(margins);
413 411 }
414 412
415 413 /*!
416 414 Returns the rect that contains information about margins (distance between chart widget edge and axes).
417 415 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
418 416 Deprecated. Use margins().
419 417 */
420 418 QMargins QChart::minimumMargins() const
421 419 {
422 420 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
423 421 return d_ptr->m_presenter->layout()->margins();
424 422 }
425 423
426 424 /*!
427 425 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
428 426 */
429 427 void QChart::setMargins(const QMargins &margins)
430 428 {
431 429 d_ptr->m_presenter->layout()->setMargins(margins);
432 430 }
433 431
434 432 /*!
435 433 Returns the rect that contains information about margins (distance between chart widget edge and axes).
436 434 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
437 435 */
438 436 QMargins QChart::margins() const
439 437 {
440 438 return d_ptr->m_presenter->layout()->margins();
441 439 }
442 440
443 441 /*!
444 442 Returns the the rect within which the drawing of the chart is done.
445 443 It does not include the area defines by margins.
446 444 */
447 445 QRectF QChart::plotArea() const
448 446 {
449 447 return d_ptr->m_presenter->geometry();
450 448 }
451 449
452 450 ///*!
453 451 // TODO: Dummy.
454 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
452 // Adjust the ranges of the axes so that all the data of the specified \a series is visible
455 453 // */
456 454 //void QChart::adjustViewToSeries(QAbstractSeries* series)
457 455 //{
458 456 // //
459 457 //}
460 458
461 459 /*!
462 460 Sets animation \a options for the chart
463 461 */
464 462 void QChart::setAnimationOptions(AnimationOptions options)
465 463 {
466 464 d_ptr->m_presenter->setAnimationOptions(options);
467 465 }
468 466
469 467 QChart::AnimationOptions QChart::animationOptions() const
470 468 {
471 469 return d_ptr->m_presenter->animationOptions();
472 470 }
473 471
474 472 /*!
475 473 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
476 474 */
477 475 void QChart::scroll(qreal dx, qreal dy)
478 476 {
479 477 d_ptr->scroll(dx,dy);
480 478 }
481 479
482 480 void QChart::setBackgroundVisible(bool visible)
483 481 {
484 482 d_ptr->m_presenter->setBackgroundVisible(visible);
485 483 }
486 484
487 485 bool QChart::isBackgroundVisible() const
488 486 {
489 487 return d_ptr->m_presenter->isBackgroundVisible();
490 488 }
491 489
492 490 void QChart::setDropShadowEnabled(bool enabled)
493 491 {
494 492 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
495 493 }
496 494
497 495 bool QChart::isDropShadowEnabled() const
498 496 {
499 497 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
500 498 }
501 499
502 500 /*!
503 501 Returns all the series that are added to the chart.
504 502
505 503 \sa addSeries(), removeSeries(), removeAllSeries()
506 504 */
507 505 QList<QAbstractSeries *> QChart::series() const
508 506 {
509 507 return d_ptr->m_dataset->series();
510 508 }
511 509
512 510 /*!
513 511 Sets \a axis to the chart, which will control the presentation of the \a series
514 512
515 513 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
516 514 */
517 515 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
518 516 {
519 517 QList<QAbstractAxis*> list = axes(Qt::Horizontal,series);
520 518
521 519 foreach(QAbstractAxis* a, list){
522 520 d_ptr->m_dataset->removeAxis(a);
523 521 delete a;
524 522 }
525 523
526 524 if(!d_ptr->m_dataset->axes().contains(axis))
527 525 d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom);
528 526 d_ptr->m_dataset->attachAxis(series,axis);
529 527 }
530 528
531 529 /*!
532 530 Sets \a axis to the chart, which will control the presentation of the \a series
533 531
534 532 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
535 533 */
536 534 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
537 535 {
538 536 QList<QAbstractAxis*> list = axes(Qt::Vertical,series);
539 537
540 538 foreach(QAbstractAxis* a, list) {
541 539 d_ptr->m_dataset->removeAxis(a);
542 540 delete a;
543 541 }
544 542
545 543 if(!d_ptr->m_dataset->axes().contains(axis))
546 544 d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft);
547 545 d_ptr->m_dataset->attachAxis(series,axis);
548 546 }
549 547
550 548 /*!
551 549 Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
552 550 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
553 551 */
554 552 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
555 553 {
556 554 d_ptr->m_dataset->addAxis(axis, alignment);
557 555 }
558 556
559 557 /*!
560 558 Removes \a axis from the chart. The ownership is returned to the caller.
561 559 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
562 560 */
563 561 void QChart::removeAxis(QAbstractAxis *axis)
564 562 {
565 563 d_ptr->m_dataset->removeAxis(axis);
566 564 }
567 565
568 566 /*!
569 567 Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position.
570 568 */
571 569 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
572 570 {
573 571 return d_ptr->m_dataset->mapToValue(position, series);
574 572 }
575 573
576 574 /*!
577 575 Returns the position on the charts widget that coresponds to the \a value in the \a series domain.
578 576 */
579 577 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
580 578 {
581 579 return d_ptr->m_dataset->mapToPosition(value, series);
582 580 }
583 581
584 582 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
585 583
586 584 QChartPrivate::QChartPrivate(QChart *q):
587 585 q_ptr(q),
588 586 m_legend(0),
589 587 m_dataset(new ChartDataSet(q)),
590 588 m_presenter(new ChartPresenter(q)),
591 589 m_themeManager(new ChartThemeManager(q))
592 590 {
593 591 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
594 592 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
595 593 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
596 594 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
597 595 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
598 596 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
599 597 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
600 598 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
601 599 }
602 600
603 601 QChartPrivate::~QChartPrivate()
604 602 {
605 603
606 604 }
607 605
608 606 void QChartPrivate::zoomIn(qreal factor)
609 607 {
610 608 QRectF rect = m_presenter->geometry();
611 609 rect.setWidth(rect.width() / factor);
612 610 rect.setHeight(rect.height() / factor);
613 611 rect.moveCenter(m_presenter->geometry().center());
614 612 zoomIn(rect);
615 613 }
616 614
617 615 void QChartPrivate::zoomIn(const QRectF &rect)
618 616 {
619 617 if (!rect.isValid())
620 618 return;
621 619
622 620 QRectF r = rect.normalized();
623 621 const QRectF geometry = m_presenter->geometry();
624 622 r.translate(-geometry.topLeft());
625 623
626 624 if (!r.isValid())
627 625 return;
628 626
629 627 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
630 628 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
631 629 m_dataset->zoomInDomain(r);
632 630 m_presenter->setState(ChartPresenter::ShowState,QPointF());
633 631
634 632 }
635 633
636 634 void QChartPrivate::zoomOut(qreal factor)
637 635 {
638 636 const QRectF geometry = m_presenter->geometry();
639 637
640 638 QRectF r;
641 639 r.setSize(geometry.size() / factor);
642 640 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
643 641 if (!r.isValid())
644 642 return;
645 643
646 644 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
647 645 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
648 646 m_dataset->zoomOutDomain(r);
649 647 m_presenter->setState(ChartPresenter::ShowState,QPointF());
650 648 }
651 649
652 650 void QChartPrivate::scroll(qreal dx, qreal dy)
653 651 {
654 652 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
655 653 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
656 654 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
657 655 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
658 656
659 657 m_dataset->scrollDomain(dx, dy);
660 658 m_presenter->setState(ChartPresenter::ShowState,QPointF());
661 659 }
662 660
663 661 #include "moc_qchart.cpp"
664 662
665 663 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,863 +1,859
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "tst_qabstractaxis.h"
22 22
23 23 Q_DECLARE_METATYPE(QPen)
24 24 Q_DECLARE_METATYPE(Qt::Orientation)
25 25
26 26 void tst_QAbstractAxis::initTestCase()
27 27 {
28 28 }
29 29
30 30 void tst_QAbstractAxis::cleanupTestCase()
31 31 {
32 32 }
33 33
34 34 void tst_QAbstractAxis::init(QAbstractAxis* axis, QAbstractSeries* series)
35 35 {
36 36 m_axis = axis;
37 37 m_series = series;
38 38 m_view = new QChartView(new QChart());
39 39 m_chart = m_view->chart();
40 40 }
41 41
42 42 void tst_QAbstractAxis::cleanup()
43 43 {
44 44 delete m_view;
45 45 m_view = 0;
46 46 m_chart = 0;
47 47 m_axis = 0;
48 48 }
49 49
50 50 void tst_QAbstractAxis::qabstractaxis()
51 51 {
52 52 QCOMPARE(m_axis->linePen(), QPen());
53 //TODO QCOMPARE(m_axis->axisPenColor(), QColor());
54 53 QCOMPARE(m_axis->gridLinePen(), QPen());
55 54 QCOMPARE(m_axis->isLineVisible(), true);
56 55 QCOMPARE(m_axis->isGridLineVisible(), true);
57 56 QCOMPARE(m_axis->isVisible(), true);
58 57 QCOMPARE(m_axis->labelsAngle(), 0);
59 58 QCOMPARE(m_axis->labelsBrush(), QBrush());
60 //TODO QCOMPARE(m_axis->labelsColor(), QColor());
61 59 QCOMPARE(m_axis->labelsFont(), QFont());
62 60 QCOMPARE(m_axis->labelsPen(), QPen());
63 61 QCOMPARE(m_axis->labelsVisible(), true);
64 62 QCOMPARE(m_axis->orientation(), Qt::Orientation(0));
65 63 m_axis->setLineVisible(false);
66 64 m_axis->setLinePen(QPen());
67 65 m_axis->setLinePenColor(QColor());
68 66 m_axis->setGridLinePen(QPen());
69 67 m_axis->setGridLineVisible(false);
70 68 m_axis->setLabelsAngle(-1);
71 69 m_axis->setLabelsBrush(QBrush());
72 70 m_axis->setLabelsColor(QColor());
73 71 m_axis->setLabelsFont(QFont());
74 72 m_axis->setLabelsPen(QPen());
75 73 m_axis->setLabelsVisible(false);
76 74 m_axis->setMax(QVariant());
77 75 m_axis->setMin(QVariant());
78 76 m_axis->setRange(QVariant(), QVariant());
79 77 m_axis->setShadesBorderColor(QColor());
80 78 m_axis->setShadesBrush(QBrush());
81 79 m_axis->setShadesColor(QColor());
82 80 m_axis->setShadesPen(QPen());
83 81 m_axis->setShadesVisible(false);
84 82 m_axis->setVisible(false);
85 //TODO QCOMPARE(m_axis->shadesBorderColor(), QColor());
86 83 //TODO QCOMPARE(m_axis->shadesBrush(), QBrush());
87 //TODO QCOMPARE(m_axis->shadesColor(), QColor());
88 84 QCOMPARE(m_axis->shadesPen(), QPen());
89 85 QCOMPARE(m_axis->shadesVisible(), false);
90 86 m_axis->show();
91 87 m_axis->hide();
92 88 }
93 89
94 90 void tst_QAbstractAxis::axisPen_data()
95 91 {
96 92 QTest::addColumn<QPen>("axisPen");
97 93 QTest::newRow("null") << QPen();
98 94 QTest::newRow("blue") << QPen(Qt::blue);
99 95 QTest::newRow("black") << QPen(Qt::black);
100 96 QTest::newRow("red") << QPen(Qt::red);
101 97 }
102 98
103 99 void tst_QAbstractAxis::axisPen()
104 100 {
105 101 QFETCH(QPen, axisPen);
106 102
107 103 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
108 104 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
109 105 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
110 106 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
111 107 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
112 108 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
113 109 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
114 110 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
115 111 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
116 112
117 113 m_axis->setLinePen(axisPen);
118 114 QCOMPARE(m_axis->linePen(), axisPen);
119 115
120 116 QCOMPARE(spy0.count(), 0);
121 117 QCOMPARE(spy1.count(), 0);
122 118 QCOMPARE(spy2.count(), 0);
123 119 QCOMPARE(spy3.count(), 0);
124 120 QCOMPARE(spy4.count(), 0);
125 121 QCOMPARE(spy5.count(), 0);
126 122 QCOMPARE(spy6.count(), 0);
127 123 QCOMPARE(spy7.count(), 0);
128 124 QCOMPARE(spy8.count(), 0);
129 125
130 126 m_chart->setAxisX(m_axis, m_series);
131 127 m_view->show();
132 128 QTest::qWaitForWindowShown(m_view);
133 129 //TODO QCOMPARE(m_axis->axisPen(), axisPen);
134 130 }
135 131
136 132 void tst_QAbstractAxis::axisPenColor_data()
137 133 {
138 134 }
139 135
140 136 void tst_QAbstractAxis::axisPenColor()
141 137 {
142 138 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
143 139 QSKIP("Test is not implemented. This is deprecated function");
144 140 #else
145 141 QSKIP("Test is not implemented. This is deprecated function", SkipAll);
146 142 #endif
147 143 }
148 144
149 145 void tst_QAbstractAxis::gridLinePen_data()
150 146 {
151 147
152 148 QTest::addColumn<QPen>("gridLinePen");
153 149 QTest::newRow("null") << QPen();
154 150 QTest::newRow("blue") << QPen(Qt::blue);
155 151 QTest::newRow("black") << QPen(Qt::black);
156 152 QTest::newRow("red") << QPen(Qt::red);
157 153
158 154 }
159 155
160 156 void tst_QAbstractAxis::gridLinePen()
161 157 {
162 158 QFETCH(QPen, gridLinePen);
163 159
164 160 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
165 161 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
166 162 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
167 163 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
168 164 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
169 165 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
170 166 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
171 167 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
172 168 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
173 169
174 170 m_axis->setGridLinePen(gridLinePen);
175 171 QCOMPARE(m_axis->gridLinePen(), gridLinePen);
176 172
177 173 QCOMPARE(spy0.count(), 0);
178 174 QCOMPARE(spy1.count(), 0);
179 175 QCOMPARE(spy2.count(), 0);
180 176 QCOMPARE(spy3.count(), 0);
181 177 QCOMPARE(spy4.count(), 0);
182 178 QCOMPARE(spy5.count(), 0);
183 179 QCOMPARE(spy6.count(), 0);
184 180 QCOMPARE(spy7.count(), 0);
185 181 QCOMPARE(spy8.count(), 0);
186 182
187 183 m_chart->setAxisX(m_axis, m_series);
188 184 m_view->show();
189 185 QTest::qWaitForWindowShown(m_view);
190 186 //TODO QCOMPARE(m_axis->gridLinePen(), gridLinePen);
191 187 }
192 188
193 189 void tst_QAbstractAxis::lineVisible_data()
194 190 {
195 191 QTest::addColumn<bool>("lineVisible");
196 192 QTest::newRow("true") << true;
197 193 QTest::newRow("false") << false;
198 194 }
199 195
200 196 void tst_QAbstractAxis::lineVisible()
201 197 {
202 198 QFETCH(bool, lineVisible);
203 199
204 200 m_axis->setLineVisible(!lineVisible);
205 201
206 202 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
207 203 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
208 204 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
209 205 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
210 206 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
211 207 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
212 208 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
213 209 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
214 210 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
215 211
216 212 m_axis->setLineVisible(lineVisible);
217 213 QCOMPARE(m_axis->isLineVisible(), lineVisible);
218 214
219 215 QCOMPARE(spy0.count(), 1);
220 216 QCOMPARE(spy1.count(), 0);
221 217 QCOMPARE(spy2.count(), 0);
222 218 QCOMPARE(spy3.count(), 0);
223 219 QCOMPARE(spy4.count(), 0);
224 220 QCOMPARE(spy5.count(), 0);
225 221 QCOMPARE(spy6.count(), 0);
226 222 QCOMPARE(spy7.count(), 0);
227 223 QCOMPARE(spy8.count(), 0);
228 224
229 225 m_chart->setAxisX(m_axis, m_series);
230 226 m_view->show();
231 227 QTest::qWaitForWindowShown(m_view);
232 228 QCOMPARE(m_axis->isLineVisible(), lineVisible);
233 229 }
234 230
235 231 void tst_QAbstractAxis::gridLineVisible_data()
236 232 {
237 233 QTest::addColumn<bool>("gridLineVisible");
238 234 QTest::newRow("true") << true;
239 235 QTest::newRow("false") << false;
240 236 }
241 237
242 238 void tst_QAbstractAxis::gridLineVisible()
243 239 {
244 240 QFETCH(bool, gridLineVisible);
245 241
246 242 m_axis->setGridLineVisible(!gridLineVisible);
247 243
248 244 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
249 245 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
250 246 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
251 247 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
252 248 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
253 249 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
254 250 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
255 251 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
256 252 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
257 253
258 254 m_axis->setGridLineVisible(gridLineVisible);
259 255 QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible);
260 256
261 257 QCOMPARE(spy0.count(), 0);
262 258 QCOMPARE(spy1.count(), 0);
263 259 QCOMPARE(spy2.count(), 1);
264 260 QCOMPARE(spy3.count(), 0);
265 261 QCOMPARE(spy4.count(), 0);
266 262 QCOMPARE(spy5.count(), 0);
267 263 QCOMPARE(spy6.count(), 0);
268 264 QCOMPARE(spy7.count(), 0);
269 265 QCOMPARE(spy8.count(), 0);
270 266
271 267 m_chart->setAxisX(m_axis, m_series);
272 268 m_view->show();
273 269 QTest::qWaitForWindowShown(m_view);
274 270 QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible);
275 271
276 272 }
277 273
278 274 void tst_QAbstractAxis::visible_data()
279 275 {
280 276 QTest::addColumn<bool>("visible");
281 277 QTest::newRow("true") << true;
282 278 QTest::newRow("false") << false;
283 279 }
284 280
285 281 void tst_QAbstractAxis::visible()
286 282 {
287 283 QFETCH(bool, visible);
288 284
289 285 m_axis->setVisible(!visible);
290 286
291 287 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
292 288 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
293 289 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
294 290 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
295 291 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
296 292 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
297 293 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
298 294 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
299 295 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
300 296
301 297 m_axis->setVisible(visible);
302 298 QCOMPARE(m_axis->isVisible(), visible);
303 299
304 300 QCOMPARE(spy0.count(), 0);
305 301 QCOMPARE(spy1.count(), 0);
306 302 QCOMPARE(spy2.count(), 0);
307 303 QCOMPARE(spy3.count(), 0);
308 304 QCOMPARE(spy4.count(), 0);
309 305 QCOMPARE(spy5.count(), 0);
310 306 QCOMPARE(spy6.count(), 0);
311 307 QCOMPARE(spy7.count(), 0);
312 308 QCOMPARE(spy8.count(), 1);
313 309
314 310 m_chart->setAxisX(m_axis, m_series);
315 311 m_view->show();
316 312 QTest::qWaitForWindowShown(m_view);
317 313 QCOMPARE(m_axis->isVisible(), visible);
318 314 }
319 315
320 316 void tst_QAbstractAxis::labelsAngle_data()
321 317 {
322 318 QTest::addColumn<int>("labelsAngle");
323 319 QTest::newRow("0") << 0;
324 320 QTest::newRow("45") << 45;
325 321 QTest::newRow("90") << 90;
326 322 }
327 323
328 324 void tst_QAbstractAxis::labelsAngle()
329 325 {
330 326 QFETCH(int, labelsAngle);
331 327
332 328 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
333 329 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
334 330 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
335 331 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
336 332 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
337 333 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
338 334 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
339 335 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
340 336 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
341 337
342 338 m_axis->setLabelsAngle(labelsAngle);
343 339 QCOMPARE(m_axis->labelsAngle(), labelsAngle);
344 340
345 341 QCOMPARE(spy0.count(), 0);
346 342 QCOMPARE(spy1.count(), 0);
347 343 QCOMPARE(spy2.count(), 0);
348 344 QCOMPARE(spy3.count(), 0);
349 345 QCOMPARE(spy4.count(), 0);
350 346 QCOMPARE(spy5.count(), 0);
351 347 QCOMPARE(spy6.count(), 0);
352 348 QCOMPARE(spy7.count(), 0);
353 349 QCOMPARE(spy8.count(), 0);
354 350
355 351 m_chart->setAxisX(m_axis, m_series);
356 352 m_view->show();
357 353 QTest::qWaitForWindowShown(m_view);
358 354 QCOMPARE(m_axis->labelsAngle(), labelsAngle);
359 355 }
360 356
361 357 void tst_QAbstractAxis::labelsBrush_data()
362 358 {
363 359 QTest::addColumn<QBrush>("labelsBrush");
364 360 QTest::newRow("null") << QBrush();
365 361 QTest::newRow("blue") << QBrush(Qt::blue);
366 362 QTest::newRow("black") << QBrush(Qt::black);
367 363
368 364 }
369 365
370 366 void tst_QAbstractAxis::labelsBrush()
371 367 {
372 368
373 369 QFETCH(QBrush, labelsBrush);
374 370
375 371 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
376 372 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
377 373 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
378 374 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
379 375 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
380 376 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
381 377 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
382 378 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
383 379 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
384 380
385 381 m_axis->setLabelsBrush(labelsBrush);
386 382 QCOMPARE(m_axis->labelsBrush(), labelsBrush);
387 383
388 384 QCOMPARE(spy0.count(), 0);
389 385 QCOMPARE(spy1.count(), 0);
390 386 QCOMPARE(spy2.count(), 0);
391 387 QCOMPARE(spy3.count(), 0);
392 388 QCOMPARE(spy4.count(), 0);
393 389 QCOMPARE(spy5.count(), 0);
394 390 //TODO QCOMPARE(spy6.count(), 0);
395 391 QCOMPARE(spy7.count(), 0);
396 392 QCOMPARE(spy8.count(), 0);
397 393
398 394 m_view->show();
399 395 QTest::qWaitForWindowShown(m_view);
400 396 QCOMPARE(m_axis->labelsBrush(), labelsBrush);
401 397
402 398 }
403 399
404 400 void tst_QAbstractAxis::labelsColor_data()
405 401 {
406 402
407 403 }
408 404
409 405 void tst_QAbstractAxis::labelsColor()
410 406 {
411 407 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
412 408 QSKIP("Test is not implemented. This is deprecated function");
413 409 #else
414 410 QSKIP("Test is not implemented. This is deprecated function", SkipAll);
415 411 #endif
416 412 }
417 413
418 414 void tst_QAbstractAxis::labelsFont_data()
419 415 {
420 416 QTest::addColumn<QFont>("labelsFont");
421 417 QTest::newRow("null") << QFont();
422 418 QTest::newRow("serif") << QFont("SansSerif");
423 419 }
424 420
425 421 void tst_QAbstractAxis::labelsFont()
426 422 {
427 423
428 424 QFETCH(QFont, labelsFont);
429 425
430 426 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
431 427 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
432 428 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
433 429 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
434 430 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
435 431 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
436 432 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
437 433 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
438 434 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
439 435
440 436 m_axis->setLabelsFont(labelsFont);
441 437 QCOMPARE(m_axis->labelsFont(), labelsFont);
442 438
443 439 QCOMPARE(spy0.count(), 0);
444 440 QCOMPARE(spy1.count(), 0);
445 441 QCOMPARE(spy2.count(), 0);
446 442 QCOMPARE(spy3.count(), 0);
447 443 QCOMPARE(spy4.count(), 0);
448 444 QCOMPARE(spy5.count(), 0);
449 445 QCOMPARE(spy6.count(), 0);
450 446 QCOMPARE(spy7.count(), 0);
451 447 QCOMPARE(spy8.count(), 0);
452 448
453 449 m_view->show();
454 450 QTest::qWaitForWindowShown(m_view);
455 451 QCOMPARE(m_axis->labelsFont(), labelsFont);
456 452
457 453 }
458 454
459 455 void tst_QAbstractAxis::labelsPen_data()
460 456 {
461 457 QTest::addColumn<QPen>("labelsPen");
462 458 QTest::newRow("null") << QPen();
463 459 QTest::newRow("blue") << QPen(Qt::blue);
464 460 QTest::newRow("black") << QPen(Qt::black);
465 461 QTest::newRow("red") << QPen(Qt::red);
466 462 }
467 463
468 464 void tst_QAbstractAxis::labelsPen()
469 465 {
470 466 QFETCH(QPen, labelsPen);
471 467
472 468 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
473 469 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
474 470 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
475 471 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
476 472 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
477 473 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
478 474 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
479 475 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
480 476 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
481 477
482 478 m_axis->setLabelsPen(labelsPen);
483 479 QCOMPARE(m_axis->labelsPen(), labelsPen);
484 480
485 481 QCOMPARE(spy0.count(), 0);
486 482 QCOMPARE(spy1.count(), 0);
487 483 QCOMPARE(spy2.count(), 0);
488 484 QCOMPARE(spy3.count(), 0);
489 485 QCOMPARE(spy4.count(), 0);
490 486 QCOMPARE(spy5.count(), 0);
491 487 QCOMPARE(spy6.count(), 0);
492 488 QCOMPARE(spy7.count(), 0);
493 489 QCOMPARE(spy8.count(), 0);
494 490
495 491 m_chart->setAxisX(m_axis, m_series);
496 492 m_view->show();
497 493 QTest::qWaitForWindowShown(m_view);
498 494 //TODO QCOMPARE(m_axis->labelsPen(), labelsPen);
499 495 }
500 496
501 497 void tst_QAbstractAxis::labelsVisible_data()
502 498 {
503 499 QTest::addColumn<bool>("labelsVisible");
504 500 QTest::newRow("true") << true;
505 501 QTest::newRow("false") << false;
506 502 }
507 503
508 504 void tst_QAbstractAxis::labelsVisible()
509 505 {
510 506 QFETCH(bool, labelsVisible);
511 507
512 508 m_axis->setLabelsVisible(!labelsVisible);
513 509
514 510 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
515 511 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
516 512 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
517 513 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
518 514 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
519 515 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
520 516 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
521 517 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
522 518 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
523 519
524 520 m_axis->setLabelsVisible(labelsVisible);
525 521 QCOMPARE(m_axis->labelsVisible(), labelsVisible);
526 522
527 523 QCOMPARE(spy0.count(), 0);
528 524 QCOMPARE(spy1.count(), 0);
529 525 QCOMPARE(spy2.count(), 0);
530 526 QCOMPARE(spy3.count(), 0);
531 527 QCOMPARE(spy4.count(), 1);
532 528 QCOMPARE(spy5.count(), 0);
533 529 QCOMPARE(spy6.count(), 0);
534 530 QCOMPARE(spy7.count(), 0);
535 531 QCOMPARE(spy8.count(), 0);
536 532
537 533 m_chart->setAxisX(m_axis, m_series);
538 534 m_view->show();
539 535 QTest::qWaitForWindowShown(m_view);
540 536 QCOMPARE(m_axis->labelsVisible(), labelsVisible);
541 537 }
542 538
543 539 void tst_QAbstractAxis::orientation_data()
544 540 {
545 541 QTest::addColumn<Qt::Orientation>("orientation");
546 542 QTest::newRow("Vertical") << Qt::Vertical;
547 543 QTest::newRow("Horizontal") << Qt::Horizontal;
548 544 }
549 545
550 546 void tst_QAbstractAxis::orientation()
551 547 {
552 548 QFETCH(Qt::Orientation, orientation);
553 549
554 550 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
555 551 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
556 552 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
557 553 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
558 554 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
559 555 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
560 556 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
561 557 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
562 558 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
563 559
564 560 if(orientation==Qt::Vertical){
565 561 m_chart->setAxisY(m_axis,m_series);
566 562 }else{
567 563 m_chart->setAxisX(m_axis,m_series);
568 564 }
569 565 QCOMPARE(m_axis->orientation(), orientation);
570 566
571 567 QCOMPARE(spy0.count(), 0);
572 568 QCOMPARE(spy1.count(), 0);
573 569 QCOMPARE(spy2.count(), 0);
574 570 QCOMPARE(spy3.count(), 0);
575 571 QCOMPARE(spy4.count(), 0);
576 572 QCOMPARE(spy5.count(), 0);
577 573 QCOMPARE(spy6.count(), 0);
578 574 QCOMPARE(spy7.count(), 0);
579 575 QCOMPARE(spy8.count(), 0);
580 576
581 577 m_view->show();
582 578 QTest::qWaitForWindowShown(m_view);
583 579 QCOMPARE(m_axis->orientation(), orientation);
584 580 }
585 581
586 582 void tst_QAbstractAxis::setMax_data()
587 583 {
588 584 //just check if it does not crash
589 585 QTest::addColumn<QVariant>("max");
590 586 QTest::newRow("something") << QVariant("something");
591 587 QTest::newRow("1.0") << QVariant(1.0);
592 588 }
593 589
594 590 void tst_QAbstractAxis::setMax()
595 591 {
596 592 QFETCH(QVariant, max);
597 593 m_axis->setMax(max);
598 594 }
599 595
600 596 void tst_QAbstractAxis::setMin_data()
601 597 {
602 598 //just check if it does not crash
603 599 QTest::addColumn<QVariant>("min");
604 600 QTest::newRow("something") << QVariant("something");
605 601 QTest::newRow("1.0") << QVariant(1.0);
606 602 }
607 603
608 604 // public void setMin(QVariant const& min)
609 605 void tst_QAbstractAxis::setMin()
610 606 {
611 607 QFETCH(QVariant, min);
612 608 m_axis->setMin(min);
613 609 }
614 610
615 611 void tst_QAbstractAxis::setRange_data()
616 612 {
617 613 //just check if it does not crash
618 614 QTest::addColumn<QVariant>("min");
619 615 QTest::addColumn<QVariant>("max");
620 616 QTest::newRow("something") << QVariant("something0") << QVariant("something1");
621 617 QTest::newRow("-1 1") << QVariant(-1.0) << QVariant(1.0);
622 618 }
623 619
624 620 // public void setRange(QVariant const& min, QVariant const& max)
625 621 void tst_QAbstractAxis::setRange()
626 622 {
627 623
628 624 QFETCH(QVariant, min);
629 625 QFETCH(QVariant, max);
630 626 m_axis->setRange(min,max);
631 627 }
632 628
633 629 void tst_QAbstractAxis::shadesBorderColor_data()
634 630 {
635 631
636 632 }
637 633
638 634 void tst_QAbstractAxis::shadesBorderColor()
639 635 {
640 636 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
641 637 QSKIP("Test is not implemented. This is deprecated function");
642 638 #else
643 639 QSKIP("Test is not implemented. This is deprecated function", SkipAll);
644 640 #endif
645 641 }
646 642
647 643 void tst_QAbstractAxis::shadesBrush_data()
648 644 {
649 645 QTest::addColumn<QBrush>("shadesBrush");
650 646 QTest::newRow("null") << QBrush();
651 647 QTest::newRow("blue") << QBrush(Qt::blue);
652 648 QTest::newRow("black") << QBrush(Qt::black);
653 649 }
654 650
655 651 void tst_QAbstractAxis::shadesBrush()
656 652 {
657 653 QFETCH(QBrush, shadesBrush);
658 654
659 655 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
660 656 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
661 657 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
662 658 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
663 659 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
664 660 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
665 661 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
666 662 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
667 663 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
668 664
669 665 m_axis->setShadesBrush(shadesBrush);
670 666 QCOMPARE(m_axis->shadesBrush(), shadesBrush);
671 667
672 668 QCOMPARE(spy0.count(), 0);
673 669 QCOMPARE(spy1.count(), 0);
674 670 QCOMPARE(spy2.count(), 0);
675 671 QCOMPARE(spy3.count(), 0);
676 672 QCOMPARE(spy4.count(), 0);
677 673 QCOMPARE(spy5.count(), 0);
678 674 //TODO QCOMPARE(spy6.count(), 0);
679 675 QCOMPARE(spy7.count(), 0);
680 676 QCOMPARE(spy8.count(), 0);
681 677
682 678 m_view->show();
683 679 QTest::qWaitForWindowShown(m_view);
684 680 QCOMPARE(m_axis->shadesBrush(), shadesBrush);
685 681 }
686 682
687 683 void tst_QAbstractAxis::shadesColor_data()
688 684 {
689 685 }
690 686
691 687 // public QColor shadesColor() const
692 688 void tst_QAbstractAxis::shadesColor()
693 689 {
694 690 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
695 691 QSKIP("Test is not implemented. This is deprecated function");
696 692 #else
697 693 QSKIP("Test is not implemented. This is deprecated function", SkipAll);
698 694 #endif
699 695 }
700 696
701 697 void tst_QAbstractAxis::shadesPen_data()
702 698 {
703 699 QTest::addColumn<QPen>("shadesPen");
704 700 QTest::newRow("null") << QPen();
705 701 QTest::newRow("blue") << QPen(Qt::blue);
706 702 QTest::newRow("black") << QPen(Qt::black);
707 703 QTest::newRow("red") << QPen(Qt::red);
708 704 }
709 705
710 706 void tst_QAbstractAxis::shadesPen()
711 707 {
712 708 QFETCH(QPen, shadesPen);
713 709
714 710 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
715 711 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
716 712 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
717 713 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
718 714 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
719 715 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
720 716 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
721 717 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
722 718 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
723 719
724 720 m_axis->setShadesPen(shadesPen);
725 721 QCOMPARE(m_axis->shadesPen(), shadesPen);
726 722
727 723 QCOMPARE(spy0.count(), 0);
728 724 QCOMPARE(spy1.count(), 0);
729 725 QCOMPARE(spy2.count(), 0);
730 726 QCOMPARE(spy3.count(), 0);
731 727 QCOMPARE(spy4.count(), 0);
732 728 QCOMPARE(spy5.count(), 0);
733 729 QCOMPARE(spy6.count(), 0);
734 730 QCOMPARE(spy7.count(), 0);
735 731 QCOMPARE(spy8.count(), 0);
736 732
737 733 m_chart->setAxisX(m_axis, m_series);
738 734 m_view->show();
739 735 QTest::qWaitForWindowShown(m_view);
740 736 QCOMPARE(m_axis->shadesPen(), shadesPen);
741 737 }
742 738
743 739 void tst_QAbstractAxis::shadesVisible_data()
744 740 {
745 741 QTest::addColumn<bool>("shadesVisible");
746 742 QTest::newRow("true") << true;
747 743 QTest::newRow("false") << false;
748 744 }
749 745
750 746 void tst_QAbstractAxis::shadesVisible()
751 747 {
752 748 QFETCH(bool, shadesVisible);
753 749
754 750 m_axis->setShadesVisible(!shadesVisible);
755 751
756 752 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
757 753 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
758 754 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
759 755 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
760 756 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
761 757 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
762 758 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
763 759 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
764 760 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
765 761
766 762 m_axis->setShadesVisible(shadesVisible);
767 763 QCOMPARE(m_axis->shadesVisible(), shadesVisible);
768 764
769 765 QCOMPARE(spy0.count(), 0);
770 766 QCOMPARE(spy1.count(), 0);
771 767 QCOMPARE(spy2.count(), 0);
772 768 QCOMPARE(spy3.count(), 0);
773 769 QCOMPARE(spy4.count(), 0);
774 770 QCOMPARE(spy5.count(), 0);
775 771 QCOMPARE(spy6.count(), 0);
776 772 QCOMPARE(spy7.count(), 1);
777 773 QCOMPARE(spy8.count(), 0);
778 774
779 775 m_chart->setAxisX(m_axis, m_series);
780 776 m_view->show();
781 777 QTest::qWaitForWindowShown(m_view);
782 778 QCOMPARE(m_axis->shadesVisible(), shadesVisible);
783 779 }
784 780
785 781 void tst_QAbstractAxis::show_data()
786 782 {
787 783
788 784 }
789 785
790 786 void tst_QAbstractAxis::show()
791 787 {
792 788 m_axis->hide();
793 789 QCOMPARE(m_axis->isVisible(), false);
794 790
795 791 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
796 792 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
797 793 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
798 794 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
799 795 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
800 796 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
801 797 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
802 798 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
803 799 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
804 800
805 801 m_axis->show();
806 802
807 803 QCOMPARE(spy0.count(), 0);
808 804 QCOMPARE(spy1.count(), 0);
809 805 QCOMPARE(spy2.count(), 0);
810 806 QCOMPARE(spy3.count(), 0);
811 807 QCOMPARE(spy4.count(), 0);
812 808 QCOMPARE(spy5.count(), 0);
813 809 QCOMPARE(spy6.count(), 0);
814 810 QCOMPARE(spy7.count(), 0);
815 811 QCOMPARE(spy8.count(), 1);
816 812 QCOMPARE(m_axis->isVisible(), true);
817 813 }
818 814
819 815 void tst_QAbstractAxis::hide_data()
820 816 {
821 817
822 818 }
823 819
824 820 void tst_QAbstractAxis::hide()
825 821 {
826 822 m_axis->show();
827 823 QCOMPARE(m_axis->isVisible(),true);
828 824
829 825 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
830 826 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
831 827 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
832 828 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
833 829 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
834 830 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
835 831 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
836 832 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
837 833 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
838 834
839 835 m_axis->hide();
840 836
841 837 QCOMPARE(spy0.count(), 0);
842 838 QCOMPARE(spy1.count(), 0);
843 839 QCOMPARE(spy2.count(), 0);
844 840 QCOMPARE(spy3.count(), 0);
845 841 QCOMPARE(spy4.count(), 0);
846 842 QCOMPARE(spy5.count(), 0);
847 843 QCOMPARE(spy6.count(), 0);
848 844 QCOMPARE(spy7.count(), 0);
849 845 QCOMPARE(spy8.count(), 1);
850 846 QCOMPARE(m_axis->isVisible(),false);
851 847 }
852 848
853 849
854 850
855 851
856 852
857 853
858 854
859 855
860 856
861 857
862 858
863 859
@@ -1,344 +1,343
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "engine.h"
22 22 #include <QItemSelectionModel>
23 23 #include <QStandardItemModel>
24 24 #include <QVXYModelMapper>
25 25 #include <QHBarModelMapper>
26 26 #include <QVPieModelMapper>
27 27 #include <QLineSeries>
28 28 #include <QSplineSeries>
29 29 #include <QScatterSeries>
30 30 #include <QBarSeries>
31 31 #include <QPercentBarSeries>
32 32 #include <QStackedBarSeries>
33 33 #include <QAreaSeries>
34 34 #include <QPieSeries>
35 35 #include <QChart>
36 36 #include <QBarSet>
37 37
38 38
39 39 const qint32 MAGIC_NUMBER = 0x66666666;
40 40
41 41 Engine::Engine(QObject* parent) :
42 42 QObject(parent), m_count(10), m_chart(new QChart()), m_model(0), m_selection(0)
43 43 {
44 44 createModels();
45 45 }
46 46
47 47 Engine::~Engine()
48 48 {
49 49 delete m_chart;
50 50 delete m_selection;
51 51 delete m_model;
52 52 }
53 53
54 54 void Engine::createModels()
55 55 {
56 56 m_model = new QStandardItemModel(m_count, m_count);
57 57 m_model->setHorizontalHeaderLabels(
58 58 QStringList() << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H" << "I" << "J");
59 59 m_model->setVerticalHeaderLabels(
60 60 QStringList() << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "10");
61 61 m_selection = new QItemSelectionModel(m_model);
62 62
63 63 }
64 64
65 65 QList<QAbstractSeries*> Engine::addSeries(QAbstractSeries::SeriesType type)
66 66 {
67 67 const QModelIndexList& list = m_selection->selectedIndexes();
68 68
69 69 QMap<int, QModelIndex> columns;
70 70
71 71 foreach (const QModelIndex& index, list) {
72 72 columns.insertMulti(index.column(), index);
73 73 }
74 74
75 75 QList<int> keys = columns.uniqueKeys();
76 76
77 77 QModelIndexList rows = columns.values(keys.first());
78 78
79 79 int minRow = m_count + 1;
80 80 int maxRow = -1;
81 81
82 82 foreach (const QModelIndex& index, rows) {
83 83 minRow = qMin(index.row(), minRow);
84 84 maxRow = qMax(index.row(), maxRow);
85 85 }
86 86
87 87 QList<QAbstractSeries*> result;
88 88 QColor color;
89 89
90 90 switch (type) {
91 91
92 92 case QAbstractSeries::SeriesTypeLine:
93 93 {
94 94 for (int i = 1; i < keys.count(); ++i) {
95 95 QLineSeries *line = new QLineSeries();
96 96 setupXYSeries(line, keys, i, minRow, maxRow);
97 97 result << line;
98 98 }
99 99 break;
100 100 }
101 101 case QAbstractSeries::SeriesTypeSpline:
102 102 {
103 103 for (int i = 1; i < keys.count(); ++i) {
104 104 QSplineSeries *line = new QSplineSeries();
105 105 setupXYSeries(line, keys, i, minRow, maxRow);
106 106 result << line;
107 107 }
108 108 break;
109 109 }
110 110 case QAbstractSeries::SeriesTypeScatter:
111 111 {
112 112 for (int i = 1; i < keys.count(); ++i) {
113 113 QScatterSeries *line = new QScatterSeries();
114 114 setupXYSeries(line, keys, i, minRow, maxRow);
115 115 result << line;
116 116 }
117 117 break;
118 118 }
119 119 case QAbstractSeries::SeriesTypeBar:
120 120 {
121 //TODO: fix me
122 121 QBarSeries *bar = new QBarSeries();
123 122 setupBarSeries(bar,keys,minRow,maxRow);
124 123 result << bar;
125 124 break;
126 125 }
127 126 case QAbstractSeries::SeriesTypePercentBar:
128 127 {
129 128 QPercentBarSeries *bar = new QPercentBarSeries();
130 129 setupBarSeries(bar,keys,minRow,maxRow);
131 130 result << bar;
132 131 break;
133 132 }
134 133 case QAbstractSeries::SeriesTypeStackedBar:
135 134 {
136 135 QStackedBarSeries *bar = new QStackedBarSeries();
137 136 setupBarSeries(bar,keys,minRow,maxRow);
138 137 result << bar;
139 138 break;
140 139 }
141 140 case QAbstractSeries::SeriesTypePie:
142 141 {
143 142
144 143 QPieSeries *pie = new QPieSeries();
145 144 setupPieSeries(pie,keys,minRow,maxRow);
146 145 result << pie;
147 146 break;
148 147 }
149 148 case QAbstractSeries::SeriesTypeArea:
150 149 {
151 150 QAreaSeries *area = new QAreaSeries( new QLineSeries(), new QLineSeries());
152 151 setupAreaSeries(area,keys,minRow,maxRow);
153 152 result << area;
154 153 break;
155 154 }
156 155 }
157 156
158 157 m_chart->createDefaultAxes();
159 158 return result;
160 159 }
161 160
162 161 void Engine::removeSeries(QAbstractSeries* series)
163 162 {
164 163 m_chart->removeSeries(series);
165 164
166 165 foreach (const QModelIndex& index, m_seriesModelIndex.value(series)) {
167 166 m_model->setData(index, Qt::white, Qt::BackgroundRole);
168 167 }
169 168 }
170 169
171 170 void Engine::clearModels()
172 171 {
173 172 delete m_selection;
174 173 m_selection = 0;
175 174 delete m_model;
176 175 m_model = 0;
177 176 createModels();
178 177 }
179 178
180 179 bool Engine::save(const QString &filename) const
181 180 {
182 181 if (filename.isEmpty())
183 182 return false;
184 183
185 184 QFile file(filename);
186 185
187 186 if (!file.open(QIODevice::WriteOnly)) {
188 187 return false;
189 188 }
190 189
191 190 QDataStream out(&file);
192 191 out << MAGIC_NUMBER;
193 192 out.setVersion(QDataStream::Qt_4_8);
194 193 out << m_model->rowCount();
195 194 out << m_model->columnCount();
196 195
197 196 for (int row = 0; row < m_model->rowCount(); ++row) {
198 197 for (int column = 0; column < m_model->columnCount(); ++column) {
199 198 QStandardItem *item = m_model->item(row, column);
200 199 if (item) {
201 200 out << row;
202 201 out << column;
203 202 out << item->data(Qt::EditRole).toString();
204 203 }
205 204 }
206 205 }
207 206 return true;
208 207 }
209 208
210 209 bool Engine::load(const QString &filename)
211 210 {
212 211 clearModels();
213 212
214 213 if (filename.isEmpty())
215 214 return false;
216 215
217 216 QFile file(filename);
218 217
219 218 if (!file.open(QIODevice::ReadOnly)) {
220 219 return false;
221 220 }
222 221
223 222 QDataStream in(&file);
224 223
225 224 qint32 magicNumber;
226 225 in >> magicNumber;
227 226
228 227 if (magicNumber != MAGIC_NUMBER)
229 228 return false;
230 229
231 230 in.setVersion(QDataStream::Qt_4_8);
232 231
233 232 int rowCount;
234 233 in >> rowCount;
235 234
236 235 int columnCount;
237 236 in >> columnCount;
238 237
239 238 while (!in.atEnd()) {
240 239 int row;
241 240 int column;
242 241 QString value;
243 242 in >> row >> column >> value;
244 243 QStandardItem *item = new QStandardItem();
245 244 bool ok;
246 245 double result = value.toDouble(&ok);
247 246 if(ok)
248 247 item->setData(result, Qt::EditRole);
249 248 else
250 249 item->setData(value, Qt::EditRole);
251 250 m_model->setItem(row, column, item);
252 251 }
253 252
254 253 return true;
255 254 }
256 255
257 256 void Engine::setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow)
258 257 {
259 258 QVXYModelMapper* mapper = new QVXYModelMapper(xyseries);
260 259 mapper->setSeries(xyseries);
261 260 mapper->setModel(m_model);
262 261 mapper->setXColumn(columns.first());
263 262 mapper->setYColumn(columns.at(column));
264 263 mapper->setFirstRow(minRow);
265 264 mapper->setRowCount(maxRow - minRow + 1);
266 265 m_chart->addSeries(xyseries);
267 266 xyseries->setName(QString("Series %1").arg(m_chart->series().count()));
268 267 QObject::connect(xyseries,SIGNAL(clicked(QPointF)),this,SIGNAL(selected()));
269 268 const QModelIndexList& list = m_selection->selectedIndexes();
270 269 QModelIndexList result;
271 270 foreach (const QModelIndex& index, list) {
272 271 if (index.column() ==columns.at(column)){
273 272 m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole);
274 273 result << index;
275 274 }
276 275 }
277 276 m_seriesModelIndex.insert(xyseries,result);
278 277 }
279 278
280 279 void Engine::setupBarSeries(QAbstractBarSeries *bar, const QList<int>& columns, int minRow, int maxRow)
281 280 {
282 281 QHBarModelMapper* mapper = new QHBarModelMapper(bar);
283 282 mapper->setSeries(bar);
284 283 mapper->setModel(m_model);
285 284 mapper->setFirstColumn(minRow);
286 285 mapper->setColumnCount(maxRow - minRow + 1);
287 286 mapper->setFirstBarSetRow(columns.at(1));
288 287 mapper->setLastBarSetRow(columns.last());
289 288 m_chart->addSeries(bar);
290 289 bar->setName(QString("Series %1").arg(m_chart->series().count()));
291 290
292 291 const QModelIndexList& list = m_selection->selectedIndexes();
293 292 foreach (const QModelIndex& index, list) {
294 293 if (index.column() >= columns.at(1) && index.column()<= columns.last()) {
295 294 //m_model->setData(index, bar->barSets().at(index.column())->brush().color(), Qt::BackgroundRole);
296 295 }
297 296 }
298 297 }
299 298
300 299 void Engine::setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow)
301 300 {
302 301 QVPieModelMapper* mapper = new QVPieModelMapper(pie);
303 302 mapper->setSeries(pie);
304 303 mapper->setModel(m_model);
305 304 mapper->setValuesColumn(columns.at(1));
306 305 mapper->setLabelsColumn(columns.first());
307 306 mapper->setFirstRow(minRow);
308 307 mapper->setRowCount(maxRow - minRow + 1);
309 308 m_chart->addSeries(pie);
310 309 pie->setName(QString("Series %1").arg(m_chart->series().count()));
311 310
312 311 const QModelIndexList& list = m_selection->selectedIndexes();
313 312 foreach (const QModelIndex& index, list) {
314 313 // m_model->setData(index, bar->barSets()pen().color(), Qt::BackgroundRole);
315 314 }
316 315 }
317 316
318 317 void Engine::setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow)
319 318 {
320 319 QVXYModelMapper* umapper = new QVXYModelMapper(series);
321 320 umapper->setSeries(series->upperSeries());
322 321 umapper->setModel(m_model);
323 322 umapper->setXColumn(columns.first());
324 323 umapper->setYColumn(columns.at(1));
325 324 umapper->setFirstRow(minRow);
326 325 umapper->setRowCount(maxRow - minRow + 1);
327 326
328 327 QVXYModelMapper* lmapper = new QVXYModelMapper(series);
329 328 lmapper->setSeries(series->lowerSeries());
330 329 lmapper->setModel(m_model);
331 330 lmapper->setXColumn(columns.first());
332 331 lmapper->setYColumn(columns.at(2));
333 332 lmapper->setFirstRow(minRow);
334 333 lmapper->setRowCount(maxRow - minRow + 1);
335 334
336 335 m_chart->addSeries(series);
337 336 series->setName(QString("Series %1").arg(m_chart->series().count()));
338 337
339 338 const QModelIndexList& list = m_selection->selectedIndexes();
340 339 foreach (const QModelIndex& index, list) {
341 340 //if (index.column() ==columns.at(column))
342 341 // m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole);
343 342 }
344 343 }
@@ -1,376 +1,375
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt 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 "mainwidget.h"
22 22 #include "dataseriedialog.h"
23 23 #include "qchartview.h"
24 24 #include "qpieseries.h"
25 25 #include "qscatterseries.h"
26 26 #include "qlineseries.h"
27 27 #include <qareaseries.h>
28 28 #include <qsplineseries.h>
29 29 #include <qbarset.h>
30 30 #include <qbarseries.h>
31 31 #include <qstackedbarseries.h>
32 32 #include <qpercentbarseries.h>
33 33 #include <QPushButton>
34 34 #include <QComboBox>
35 35 #include <QSpinBox>
36 36 #include <QCheckBox>
37 37 #include <QGridLayout>
38 38 #include <QHBoxLayout>
39 39 #include <QLabel>
40 40 #include <QSpacerItem>
41 41 #include <QMessageBox>
42 42 #include <cmath>
43 43 #include <QDebug>
44 44 #include <QStandardItemModel>
45 45 #include <QBarCategoryAxis>
46 46 #include <QGLWidget>
47 47
48 48 QTCOMMERCIALCHART_USE_NAMESPACE
49 49
50 50 MainWidget::MainWidget(QWidget *parent) :
51 51 QWidget(parent),
52 52 m_addSerieDialog(0),
53 53 m_chart(0)
54 54 {
55 55 m_chart = new QChart();
56 56
57 57 // Grid layout for the controls for configuring the chart widget
58 58 QGridLayout *grid = new QGridLayout();
59 59 QPushButton *addSeriesButton = new QPushButton("Add series");
60 60 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
61 61 grid->addWidget(addSeriesButton, 0, 1);
62 62 initBackroundCombo(grid);
63 63 initScaleControls(grid);
64 64 initThemeCombo(grid);
65 65 initCheckboxes(grid);
66 66
67 67 // add row with empty label to make all the other rows static
68 68 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
69 69 grid->setRowStretch(grid->rowCount() - 1, 1);
70 70
71 71 // Create chart view with the chart
72 72 m_chartView = new QChartView(m_chart, this);
73 73 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
74 74
75 75 // Another grid layout as a main layout
76 76 QGridLayout *mainLayout = new QGridLayout();
77 77 mainLayout->addLayout(grid, 0, 0);
78 78 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
79 79 setLayout(mainLayout);
80 80 }
81 81
82 82 // Combo box for selecting the chart's background
83 83 void MainWidget::initBackroundCombo(QGridLayout *grid)
84 84 {
85 85 QComboBox *backgroundCombo = new QComboBox(this);
86 86 backgroundCombo->addItem("Color");
87 87 backgroundCombo->addItem("Gradient");
88 88 backgroundCombo->addItem("Image");
89 89 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
90 90 this, SLOT(backgroundChanged(int)));
91 91
92 92 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
93 93 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
94 94 }
95 95
96 96 // Scale related controls (auto-scale vs. manual min-max values)
97 97 void MainWidget::initScaleControls(QGridLayout *grid)
98 98 {
99 99 m_autoScaleCheck = new QCheckBox("Automatic scaling");
100 100 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
101 101 // Allow setting also non-sense values (like -2147483648 and 2147483647)
102 102 m_xMinSpin = new QSpinBox();
103 103 m_xMinSpin->setMinimum(INT_MIN);
104 104 m_xMinSpin->setMaximum(INT_MAX);
105 105 m_xMinSpin->setValue(0);
106 106 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
107 107 m_xMaxSpin = new QSpinBox();
108 108 m_xMaxSpin->setMinimum(INT_MIN);
109 109 m_xMaxSpin->setMaximum(INT_MAX);
110 110 m_xMaxSpin->setValue(10);
111 111 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
112 112 m_yMinSpin = new QSpinBox();
113 113 m_yMinSpin->setMinimum(INT_MIN);
114 114 m_yMinSpin->setMaximum(INT_MAX);
115 115 m_yMinSpin->setValue(0);
116 116 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
117 117 m_yMaxSpin = new QSpinBox();
118 118 m_yMaxSpin->setMinimum(INT_MIN);
119 119 m_yMaxSpin->setMaximum(INT_MAX);
120 120 m_yMaxSpin->setValue(10);
121 121 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
122 122
123 123 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
124 124 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
125 125 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
126 126 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
127 127 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
128 128 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
129 129 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
130 130 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
131 131 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
132 132
133 133 m_autoScaleCheck->setChecked(true);
134 134 }
135 135
136 136 // Combo box for selecting theme
137 137 void MainWidget::initThemeCombo(QGridLayout *grid)
138 138 {
139 139 QComboBox *chartTheme = new QComboBox();
140 140 chartTheme->addItem("Default");
141 141 chartTheme->addItem("Light");
142 142 chartTheme->addItem("Blue Cerulean");
143 143 chartTheme->addItem("Dark");
144 144 chartTheme->addItem("Brown Sand");
145 145 chartTheme->addItem("Blue NCS");
146 146 chartTheme->addItem("High Contrast");
147 147 chartTheme->addItem("Blue Icy");
148 148 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
149 149 this, SLOT(changeChartTheme(int)));
150 150 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
151 151 grid->addWidget(chartTheme, 8, 1);
152 152 }
153 153
154 154 // Different check boxes for customizing chart
155 155 void MainWidget::initCheckboxes(QGridLayout *grid)
156 156 {
157 157 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
158 158 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
159 159 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
160 160 zoomCheckBox->setChecked(true);
161 161 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
162 162
163 163 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
164 164 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
165 165 aliasCheckBox->setChecked(false);
166 166 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
167 167
168 168 QCheckBox *openGLCheckBox = new QCheckBox("Use QGLWidget");
169 169 connect(openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(openGLToggled(bool)));
170 170 openGLCheckBox->setChecked(false);
171 171 grid->addWidget(openGLCheckBox, grid->rowCount(), 0);
172 172 }
173 173
174 174 void MainWidget::antiAliasToggled(bool enabled)
175 175 {
176 176 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
177 177 }
178 178
179 179 void MainWidget::openGLToggled(bool enabled)
180 180 {
181 181 if (enabled) {
182 182 QGLFormat f = QGLFormat::defaultFormat();
183 183 f.setSampleBuffers(true);
184 184 f.setSamples(4);
185 185 QGLFormat::setDefaultFormat(f);
186 186 QGLWidget *g = new QGLWidget();
187 187 m_chartView->setViewport(g);
188 188 } else {
189 189 m_chartView->setViewport(0);
190 190 }
191 191 }
192 192
193 193 void MainWidget::addSeries()
194 194 {
195 195 if (!m_addSerieDialog) {
196 196 m_addSerieDialog = new DataSerieDialog(this);
197 197 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
198 198 this, SLOT(addSeries(QString,int,int,QString,bool)));
199 199 }
200 200 m_addSerieDialog->exec();
201 201 }
202 202
203 203 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
204 204 {
205 // TODO: dataCharacteristics
206 205 QList<RealList> testData;
207 206 for (int j(0); j < columnCount; j++) {
208 207 QList <qreal> newColumn;
209 208 for (int i(0); i < rowCount; i++) {
210 209 if (dataCharacteristics == "Sin") {
211 210 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
212 211 } else if (dataCharacteristics == "Sin + random") {
213 212 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
214 213 } else if (dataCharacteristics == "Random") {
215 214 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
216 215 } else if (dataCharacteristics == "Linear") {
217 216 //newColumn.append(i * (j + 1.0));
218 217 // TODO: temporary hack to make pie work; prevent zero values:
219 218 newColumn.append(i * (j + 1.0) + 0.1);
220 219 } else { // "constant"
221 220 newColumn.append((j + 1.0));
222 221 }
223 222 }
224 223 testData.append(newColumn);
225 224 }
226 225 return testData;
227 226 }
228 227
229 228 QStringList MainWidget::generateLabels(int count)
230 229 {
231 230 QStringList result;
232 231 for (int i(0); i < count; i++)
233 232 result.append("label" + QString::number(i));
234 233 return result;
235 234 }
236 235
237 236 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
238 237 {
239 238 qDebug() << "addSeries: " << seriesName
240 239 << " columnCount: " << columnCount
241 240 << " rowCount: " << rowCount
242 241 << " dataCharacteristics: " << dataCharacteristics
243 242 << " labels enabled: " << labelsEnabled;
244 243 m_defaultSeriesName = seriesName;
245 244
246 245 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
247 246
248 247 // Line series and scatter series use similar data
249 248 if (seriesName == "Line") {
250 249 for (int j(0); j < data.count(); j ++) {
251 250 QList<qreal> column = data.at(j);
252 251 QLineSeries *series = new QLineSeries();
253 252 series->setName("line" + QString::number(j));
254 253 for (int i(0); i < column.count(); i++)
255 254 series->append(i, column.at(i));
256 255 m_chart->addSeries(series);
257 256 }
258 257 } else if (seriesName == "Area") {
259 258 // TODO: lower series for the area?
260 259 for (int j(0); j < data.count(); j ++) {
261 260 QList<qreal> column = data.at(j);
262 261 QLineSeries *lineSeries = new QLineSeries();
263 262 for (int i(0); i < column.count(); i++)
264 263 lineSeries->append(i, column.at(i));
265 264 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
266 265 areaSeries->setName("area" + QString::number(j));
267 266 m_chart->addSeries(areaSeries);
268 267 }
269 268 } else if (seriesName == "Scatter") {
270 269 for (int j(0); j < data.count(); j++) {
271 270 QList<qreal> column = data.at(j);
272 271 QScatterSeries *series = new QScatterSeries();
273 272 series->setName("scatter" + QString::number(j));
274 273 for (int i(0); i < column.count(); i++)
275 274 series->append(i, column.at(i));
276 275 m_chart->addSeries(series);
277 276 }
278 277 } else if (seriesName == "Pie") {
279 278 QStringList labels = generateLabels(rowCount);
280 279 for (int j(0); j < data.count(); j++) {
281 280 QPieSeries *series = new QPieSeries();
282 281 QList<qreal> column = data.at(j);
283 282 for (int i(0); i < column.count(); i++)
284 283 series->append(labels.at(i), column.at(i));
285 284 m_chart->addSeries(series);
286 285 }
287 286 } else if (seriesName == "Bar"
288 287 || seriesName == "Stacked bar"
289 288 || seriesName == "Percent bar") {
290 289 QStringList category;
291 290 QStringList labels = generateLabels(rowCount);
292 291 foreach (QString label, labels)
293 292 category << label;
294 293 QAbstractBarSeries* series = 0;
295 294 if (seriesName == "Bar") {
296 295 series = new QBarSeries(this);
297 296 QBarCategoryAxis* axis = new QBarCategoryAxis();
298 297 axis->append(category);
299 298 m_chart->setAxisX(axis,series);
300 299 } else if (seriesName == "Stacked bar") {
301 300 series = new QStackedBarSeries(this);
302 301 QBarCategoryAxis* axis = new QBarCategoryAxis();
303 302 axis->append(category);
304 303 m_chart->setAxisX(axis,series);
305 304 } else {
306 305 series = new QPercentBarSeries(this);
307 306 QBarCategoryAxis* axis = new QBarCategoryAxis();
308 307 axis->append(category);
309 308 m_chart->setAxisX(axis,series);
310 309 }
311 310
312 311 for (int j(0); j < data.count(); j++) {
313 312 QList<qreal> column = data.at(j);
314 313 QBarSet *set = new QBarSet("set" + QString::number(j));
315 314 for (int i(0); i < column.count(); i++)
316 315 *set << column.at(i);
317 316 series->append(set);
318 317 }
319 318
320 319 m_chart->addSeries(series);
321 320 } else if (seriesName == "Spline") {
322 321 for (int j(0); j < data.count(); j ++) {
323 322 QList<qreal> column = data.at(j);
324 323 QSplineSeries *series = new QSplineSeries();
325 324 for (int i(0); i < column.count(); i++)
326 325 series->append(i, column.at(i));
327 326 m_chart->addSeries(series);
328 327 }
329 328 }
330 329 m_chart->createDefaultAxes();
331 330 }
332 331
333 332 void MainWidget::backgroundChanged(int itemIndex)
334 333 {
335 334 qDebug() << "backgroundChanged: " << itemIndex;
336 335 }
337 336
338 337 void MainWidget::autoScaleChanged(int value)
339 338 {
340 339 if (value) {
341 340 // TODO: enable auto scaling
342 341 } else {
343 342 // TODO: set scaling manually (and disable auto scaling)
344 343 }
345 344
346 345 m_xMinSpin->setEnabled(!value);
347 346 m_xMaxSpin->setEnabled(!value);
348 347 m_yMinSpin->setEnabled(!value);
349 348 m_yMaxSpin->setEnabled(!value);
350 349 }
351 350
352 351 void MainWidget::xMinChanged(int value)
353 352 {
354 353 qDebug() << "xMinChanged: " << value;
355 354 }
356 355
357 356 void MainWidget::xMaxChanged(int value)
358 357 {
359 358 qDebug() << "xMaxChanged: " << value;
360 359 }
361 360
362 361 void MainWidget::yMinChanged(int value)
363 362 {
364 363 qDebug() << "yMinChanged: " << value;
365 364 }
366 365
367 366 void MainWidget::yMaxChanged(int value)
368 367 {
369 368 qDebug() << "yMaxChanged: " << value;
370 369 }
371 370
372 371 void MainWidget::changeChartTheme(int themeIndex)
373 372 {
374 373 qDebug() << "changeChartTheme: " << themeIndex;
375 374 m_chart->setTheme((QChart::ChartTheme) themeIndex);
376 375 }
General Comments 0
You need to be logged in to leave comments. Login now