##// END OF EJS Templates
Removes legacy code - selectVisibleAxis
Michal Klocek -
r2154:8f1d361d53c7
parent child
Show More
@@ -1,438 +1,388
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #include "chartpresenter_p.h"
20 #include "chartpresenter_p.h"
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qabstractaxis.h"
23 #include "qabstractaxis.h"
24 #include "qabstractaxis_p.h"
24 #include "qabstractaxis_p.h"
25 #include "chartdataset_p.h"
25 #include "chartdataset_p.h"
26 #include "charttheme_p.h"
26 #include "charttheme_p.h"
27 #include "chartanimation_p.h"
27 #include "chartanimation_p.h"
28 #include "qabstractseries_p.h"
28 #include "qabstractseries_p.h"
29 #include "qareaseries.h"
29 #include "qareaseries.h"
30 #include "chartaxis_p.h"
30 #include "chartaxis_p.h"
31 #include "chartbackground_p.h"
31 #include "chartbackground_p.h"
32 #include "chartlayout_p.h"
32 #include "chartlayout_p.h"
33 #include "charttitle_p.h"
33 #include "charttitle_p.h"
34 #include <QTimer>
34 #include <QTimer>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 ChartPresenter::ChartPresenter(QChart *chart, ChartDataSet *dataset)
38 ChartPresenter::ChartPresenter(QChart *chart, ChartDataSet *dataset)
39 : QObject(chart),
39 : QObject(chart),
40 m_chart(chart),
40 m_chart(chart),
41 m_dataset(dataset),
41 m_dataset(dataset),
42 m_chartTheme(0),
42 m_chartTheme(0),
43 m_options(QChart::NoAnimation),
43 m_options(QChart::NoAnimation),
44 m_state(ShowState),
44 m_state(ShowState),
45 m_layout(new ChartLayout(this)),
45 m_layout(new ChartLayout(this)),
46 m_background(0),
46 m_background(0),
47 m_title(0)
47 m_title(0)
48 {
48 {
49
49
50 }
50 }
51
51
52 ChartPresenter::~ChartPresenter()
52 ChartPresenter::~ChartPresenter()
53 {
53 {
54 delete m_chartTheme;
54 delete m_chartTheme;
55 }
55 }
56
56
57 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis, Domain *domain)
57 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis, Domain *domain)
58 {
58 {
59 ChartAxis *item = axis->d_ptr->createGraphics(this);
59 ChartAxis *item = axis->d_ptr->createGraphics(this);
60 item->setDomain(domain);
60 item->setDomain(domain);
61
61
62 if (m_options.testFlag(QChart::GridAxisAnimations))
62 if (m_options.testFlag(QChart::GridAxisAnimations))
63 item->setAnimation(new AxisAnimation(item));
63 item->setAnimation(new AxisAnimation(item));
64
64
65 QObject::connect(domain, SIGNAL(updated()), item, SLOT(handleDomainUpdated()));
65 QObject::connect(domain, SIGNAL(updated()), item, SLOT(handleDomainUpdated()));
66 QObject::connect(axis, SIGNAL(visibleChanged(bool)), this, SLOT(handleAxisVisibleChanged(bool)));
67
66
68 //initialize
67 //initialize
69 domain->emitUpdated();
68 domain->emitUpdated();
70 m_chartTheme->decorate(axis);
69 m_chartTheme->decorate(axis);
71 axis->d_ptr->setDirty(false);
70 axis->d_ptr->setDirty(false);
72 axis->d_ptr->emitUpdated();
71 axis->d_ptr->emitUpdated();
73
72
74 m_axisItems.insert(axis, item);
73 m_axisItems.insert(axis, item);
75 selectVisibleAxis();
76 m_layout->invalidate();
74 m_layout->invalidate();
77 }
75 }
78
76
79 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
77 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
80 {
78 {
81 ChartAxis *item = m_axisItems.take(axis);
79 ChartAxis *item = m_axisItems.take(axis);
82 Q_ASSERT(item);
80 Q_ASSERT(item);
83 selectVisibleAxis();
84 item->hide();
81 item->hide();
85 item->disconnect();
82 item->disconnect();
86 QObject::disconnect(this, 0, item, 0);
83 QObject::disconnect(this, 0, item, 0);
87 item->deleteLater();
84 item->deleteLater();
85 m_layout->invalidate();
88 }
86 }
89
87
90
88
91 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
89 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
92 {
90 {
93 ChartElement *item = series->d_ptr->createGraphics(this);
91 ChartElement *item = series->d_ptr->createGraphics(this);
94 Q_ASSERT(item);
92 Q_ASSERT(item);
95 item->setDomain(domain);
93 item->setDomain(domain);
96
94
97 QObject::connect(domain, SIGNAL(updated()), item, SLOT(handleDomainUpdated()));
95 QObject::connect(domain, SIGNAL(updated()), item, SLOT(handleDomainUpdated()));
98 //initialize
96 //initialize
99 item->handleDomainUpdated();
97 item->handleDomainUpdated();
100
98
101 m_chartItems.insert(series, item);
99 m_chartItems.insert(series, item);
102 m_layout->invalidate();
100 m_layout->invalidate();
103 }
101 }
104
102
105 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
103 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
106 {
104 {
107 ChartElement *item = m_chartItems.take(series);
105 ChartElement *item = m_chartItems.take(series);
108 Q_ASSERT(item);
106 Q_ASSERT(item);
109 item->deleteLater();
107 item->deleteLater();
110 }
108 }
111
109
112 void ChartPresenter::selectVisibleAxis()
113 {
114 QMapIterator<QAbstractAxis *, ChartAxis *> i(m_axisItems);
115
116 while (i.hasNext()) {
117 i.next();
118 // i.key()->hide();
119 i.key()->show();
120 }
121
122 // i.toFront();
123
124 // bool axisX=false;
125 // bool axisY=false;
126
127 // while (i.hasNext()) {
128 // i.next();
129 // if(i.key()->orientation()==Qt::Vertical && !axisY) {
130 // axisY=true;
131 // i.key()->show();
132 // }
133 // if(i.key()->orientation()==Qt::Horizontal && !axisX) {
134 // axisX=true;
135 // i.key()->show();
136 // }
137
138 // }
139 }
140
141
142 void ChartPresenter::handleAxisVisibleChanged(bool visible)
143 {
144 QAbstractAxis *axis = static_cast<QAbstractAxis *>(sender());
145 Q_ASSERT(axis);
146 if (visible) {
147
148 QMapIterator<QAbstractAxis *, ChartAxis *> i(m_axisItems);
149
150 while (i.hasNext()) {
151 i.next();
152 if (i.key() == axis)
153 continue;
154 if (i.key()->orientation() == axis->orientation())
155 i.key()->setVisible(false);
156 }
157 }
158 }
159
160 void ChartPresenter::setTheme(QChart::ChartTheme theme, bool force)
110 void ChartPresenter::setTheme(QChart::ChartTheme theme, bool force)
161 {
111 {
162 if (m_chartTheme && m_chartTheme->id() == theme)
112 if (m_chartTheme && m_chartTheme->id() == theme)
163 return;
113 return;
164 delete m_chartTheme;
114 delete m_chartTheme;
165 m_chartTheme = ChartTheme::createTheme(theme);
115 m_chartTheme = ChartTheme::createTheme(theme);
166 m_chartTheme->setForced(force);
116 m_chartTheme->setForced(force);
167 m_chartTheme->decorate(m_chart);
117 m_chartTheme->decorate(m_chart);
168 m_chartTheme->decorate(m_chart->legend());
118 m_chartTheme->decorate(m_chart->legend());
169 resetAllElements();
119 resetAllElements();
170
120
171 // We do not want "force" to stay on.
121 // We do not want "force" to stay on.
172 // Bar/pie are calling decorate when adding/removing slices/bars which means
122 // Bar/pie are calling decorate when adding/removing slices/bars which means
173 // that to preserve users colors "force" must not be on.
123 // that to preserve users colors "force" must not be on.
174 m_chartTheme->setForced(false);
124 m_chartTheme->setForced(false);
175 }
125 }
176
126
177 QChart::ChartTheme ChartPresenter::theme()
127 QChart::ChartTheme ChartPresenter::theme()
178 {
128 {
179 return m_chartTheme->id();
129 return m_chartTheme->id();
180 }
130 }
181
131
182 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
132 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
183 {
133 {
184 if (m_options != options) {
134 if (m_options != options) {
185 m_options = options;
135 m_options = options;
186 resetAllElements();
136 resetAllElements();
187 }
137 }
188
138
189 }
139 }
190
140
191 void ChartPresenter::resetAllElements()
141 void ChartPresenter::resetAllElements()
192 {
142 {
193 QMapIterator<QAbstractAxis *, ChartAxis *> i(m_axisItems);
143 QMapIterator<QAbstractAxis *, ChartAxis *> i(m_axisItems);
194 while (i.hasNext()) {
144 while (i.hasNext()) {
195 i.next();
145 i.next();
196 Domain *domain = i.value()->domain();
146 Domain *domain = i.value()->domain();
197 QAbstractAxis *axis = i.key();
147 QAbstractAxis *axis = i.key();
198 handleAxisRemoved(axis);
148 handleAxisRemoved(axis);
199 handleAxisAdded(axis, domain);
149 handleAxisAdded(axis, domain);
200 }
150 }
201
151
202 QMapIterator<QAbstractSeries *, ChartElement *> j(m_chartItems);
152 QMapIterator<QAbstractSeries *, ChartElement *> j(m_chartItems);
203 while (j.hasNext()) {
153 while (j.hasNext()) {
204 j.next();
154 j.next();
205 Domain *domain = j.value()->domain();
155 Domain *domain = j.value()->domain();
206 QAbstractSeries *series = j.key();
156 QAbstractSeries *series = j.key();
207 handleSeriesRemoved(series);
157 handleSeriesRemoved(series);
208 handleSeriesAdded(series, domain);
158 handleSeriesAdded(series, domain);
209 }
159 }
210
160
211 layout()->invalidate();
161 layout()->invalidate();
212 }
162 }
213
163
214 void ChartPresenter::zoomIn(qreal factor)
164 void ChartPresenter::zoomIn(qreal factor)
215 {
165 {
216 QRectF rect = m_layout->chartsGeometry();
166 QRectF rect = m_layout->chartsGeometry();
217 rect.setWidth(rect.width() / factor);
167 rect.setWidth(rect.width() / factor);
218 rect.setHeight(rect.height() / factor);
168 rect.setHeight(rect.height() / factor);
219 rect.moveCenter(m_layout->chartsGeometry().center());
169 rect.moveCenter(m_layout->chartsGeometry().center());
220 zoomIn(rect);
170 zoomIn(rect);
221 }
171 }
222
172
223 void ChartPresenter::zoomIn(const QRectF &rect)
173 void ChartPresenter::zoomIn(const QRectF &rect)
224 {
174 {
225 QRectF r = rect.normalized();
175 QRectF r = rect.normalized();
226 r.translate(-m_layout->chartsGeometry().topLeft());
176 r.translate(-m_layout->chartsGeometry().topLeft());
227 if (!r.isValid())
177 if (!r.isValid())
228 return;
178 return;
229
179
230 m_state = ZoomInState;
180 m_state = ZoomInState;
231 m_statePoint = QPointF(r.center().x() / m_layout->chartsGeometry().width(), r.center().y() / m_layout->chartsGeometry().height());
181 m_statePoint = QPointF(r.center().x() / m_layout->chartsGeometry().width(), r.center().y() / m_layout->chartsGeometry().height());
232 m_dataset->zoomInDomain(r, m_layout->chartsGeometry().size());
182 m_dataset->zoomInDomain(r, m_layout->chartsGeometry().size());
233 m_state = ShowState;
183 m_state = ShowState;
234 }
184 }
235
185
236 void ChartPresenter::zoomOut(qreal factor)
186 void ChartPresenter::zoomOut(qreal factor)
237 {
187 {
238 m_state = ZoomOutState;
188 m_state = ZoomOutState;
239
189
240 QRectF chartRect;
190 QRectF chartRect;
241 chartRect.setSize(m_layout->chartsGeometry().size());
191 chartRect.setSize(m_layout->chartsGeometry().size());
242
192
243 QRectF rect;
193 QRectF rect;
244 rect.setSize(chartRect.size() / factor);
194 rect.setSize(chartRect.size() / factor);
245 rect.moveCenter(chartRect.center());
195 rect.moveCenter(chartRect.center());
246 if (!rect.isValid())
196 if (!rect.isValid())
247 return;
197 return;
248 m_statePoint = QPointF(rect.center().x() / m_layout->chartsGeometry().width(), rect.center().y() / m_layout->chartsGeometry().height());
198 m_statePoint = QPointF(rect.center().x() / m_layout->chartsGeometry().width(), rect.center().y() / m_layout->chartsGeometry().height());
249 m_dataset->zoomOutDomain(rect, chartRect.size());
199 m_dataset->zoomOutDomain(rect, chartRect.size());
250 m_state = ShowState;
200 m_state = ShowState;
251 }
201 }
252
202
253 void ChartPresenter::scroll(qreal dx, qreal dy)
203 void ChartPresenter::scroll(qreal dx, qreal dy)
254 {
204 {
255 if (dx < 0) m_state = ScrollLeftState;
205 if (dx < 0) m_state = ScrollLeftState;
256 if (dx > 0) m_state = ScrollRightState;
206 if (dx > 0) m_state = ScrollRightState;
257 if (dy < 0) m_state = ScrollUpState;
207 if (dy < 0) m_state = ScrollUpState;
258 if (dy > 0) m_state = ScrollDownState;
208 if (dy > 0) m_state = ScrollDownState;
259
209
260 m_dataset->scrollDomain(dx, dy, m_layout->chartsGeometry().size());
210 m_dataset->scrollDomain(dx, dy, m_layout->chartsGeometry().size());
261 m_state = ShowState;
211 m_state = ShowState;
262 }
212 }
263
213
264 QChart::AnimationOptions ChartPresenter::animationOptions() const
214 QChart::AnimationOptions ChartPresenter::animationOptions() const
265 {
215 {
266 return m_options;
216 return m_options;
267 }
217 }
268
218
269 void ChartPresenter::createBackgroundItem()
219 void ChartPresenter::createBackgroundItem()
270 {
220 {
271 if (!m_background) {
221 if (!m_background) {
272 m_background = new ChartBackground(rootItem());
222 m_background = new ChartBackground(rootItem());
273 m_background->setPen(Qt::NoPen);
223 m_background->setPen(Qt::NoPen);
274 m_background->setZValue(ChartPresenter::BackgroundZValue);
224 m_background->setZValue(ChartPresenter::BackgroundZValue);
275 }
225 }
276 }
226 }
277
227
278 void ChartPresenter::createTitleItem()
228 void ChartPresenter::createTitleItem()
279 {
229 {
280 if (!m_title) {
230 if (!m_title) {
281 m_title = new ChartTitle(rootItem());
231 m_title = new ChartTitle(rootItem());
282 m_title->setZValue(ChartPresenter::BackgroundZValue);
232 m_title->setZValue(ChartPresenter::BackgroundZValue);
283 }
233 }
284 }
234 }
285
235
286
236
287 void ChartPresenter::handleAnimationFinished()
237 void ChartPresenter::handleAnimationFinished()
288 {
238 {
289 m_animations.removeAll(qobject_cast<ChartAnimation *>(sender()));
239 m_animations.removeAll(qobject_cast<ChartAnimation *>(sender()));
290 if (m_animations.empty())
240 if (m_animations.empty())
291 emit animationsFinished();
241 emit animationsFinished();
292 }
242 }
293
243
294 void ChartPresenter::startAnimation(ChartAnimation *animation)
244 void ChartPresenter::startAnimation(ChartAnimation *animation)
295 {
245 {
296 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
246 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
297 QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection);
247 QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection);
298 if (!m_animations.isEmpty())
248 if (!m_animations.isEmpty())
299 m_animations.append(animation);
249 m_animations.append(animation);
300 QTimer::singleShot(0, animation, SLOT(start()));
250 QTimer::singleShot(0, animation, SLOT(start()));
301 }
251 }
302
252
303 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
253 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
304 {
254 {
305 createBackgroundItem();
255 createBackgroundItem();
306 m_background->setBrush(brush);
256 m_background->setBrush(brush);
307 m_layout->invalidate();
257 m_layout->invalidate();
308 }
258 }
309
259
310 QBrush ChartPresenter::backgroundBrush() const
260 QBrush ChartPresenter::backgroundBrush() const
311 {
261 {
312 if (!m_background)
262 if (!m_background)
313 return QBrush();
263 return QBrush();
314 return m_background->brush();
264 return m_background->brush();
315 }
265 }
316
266
317 void ChartPresenter::setBackgroundPen(const QPen &pen)
267 void ChartPresenter::setBackgroundPen(const QPen &pen)
318 {
268 {
319 createBackgroundItem();
269 createBackgroundItem();
320 m_background->setPen(pen);
270 m_background->setPen(pen);
321 m_layout->invalidate();
271 m_layout->invalidate();
322 }
272 }
323
273
324 QPen ChartPresenter::backgroundPen() const
274 QPen ChartPresenter::backgroundPen() const
325 {
275 {
326 if (!m_background)
276 if (!m_background)
327 return QPen();
277 return QPen();
328 return m_background->pen();
278 return m_background->pen();
329 }
279 }
330
280
331 void ChartPresenter::setTitle(const QString &title)
281 void ChartPresenter::setTitle(const QString &title)
332 {
282 {
333 createTitleItem();
283 createTitleItem();
334 m_title->setText(title);
284 m_title->setText(title);
335 m_layout->invalidate();
285 m_layout->invalidate();
336 }
286 }
337
287
338 QString ChartPresenter::title() const
288 QString ChartPresenter::title() const
339 {
289 {
340 if (!m_title)
290 if (!m_title)
341 return QString();
291 return QString();
342 return m_title->text();
292 return m_title->text();
343 }
293 }
344
294
345 void ChartPresenter::setTitleFont(const QFont &font)
295 void ChartPresenter::setTitleFont(const QFont &font)
346 {
296 {
347 createTitleItem();
297 createTitleItem();
348 m_title->setFont(font);
298 m_title->setFont(font);
349 m_layout->invalidate();
299 m_layout->invalidate();
350 }
300 }
351
301
352 QFont ChartPresenter::titleFont() const
302 QFont ChartPresenter::titleFont() const
353 {
303 {
354 if (!m_title)
304 if (!m_title)
355 return QFont();
305 return QFont();
356 return m_title->font();
306 return m_title->font();
357 }
307 }
358
308
359 void ChartPresenter::setTitleBrush(const QBrush &brush)
309 void ChartPresenter::setTitleBrush(const QBrush &brush)
360 {
310 {
361 createTitleItem();
311 createTitleItem();
362 m_title->setBrush(brush);
312 m_title->setBrush(brush);
363 m_layout->invalidate();
313 m_layout->invalidate();
364 }
314 }
365
315
366 QBrush ChartPresenter::titleBrush() const
316 QBrush ChartPresenter::titleBrush() const
367 {
317 {
368 if (!m_title)
318 if (!m_title)
369 return QBrush();
319 return QBrush();
370 return m_title->brush();
320 return m_title->brush();
371 }
321 }
372
322
373 void ChartPresenter::setBackgroundVisible(bool visible)
323 void ChartPresenter::setBackgroundVisible(bool visible)
374 {
324 {
375 createBackgroundItem();
325 createBackgroundItem();
376 m_background->setVisible(visible);
326 m_background->setVisible(visible);
377 }
327 }
378
328
379
329
380 bool ChartPresenter::isBackgroundVisible() const
330 bool ChartPresenter::isBackgroundVisible() const
381 {
331 {
382 if (!m_background)
332 if (!m_background)
383 return false;
333 return false;
384 return m_background->isVisible();
334 return m_background->isVisible();
385 }
335 }
386
336
387 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
337 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
388 {
338 {
389 createBackgroundItem();
339 createBackgroundItem();
390 m_background->setDropShadowEnabled(enabled);
340 m_background->setDropShadowEnabled(enabled);
391 }
341 }
392
342
393 bool ChartPresenter::isBackgroundDropShadowEnabled() const
343 bool ChartPresenter::isBackgroundDropShadowEnabled() const
394 {
344 {
395 if (!m_background)
345 if (!m_background)
396 return false;
346 return false;
397 return m_background->isDropShadowEnabled();
347 return m_background->isDropShadowEnabled();
398 }
348 }
399
349
400
350
401 ChartLayout *ChartPresenter::layout()
351 ChartLayout *ChartPresenter::layout()
402 {
352 {
403 return m_layout;
353 return m_layout;
404 }
354 }
405
355
406 QLegend *ChartPresenter::legend()
356 QLegend *ChartPresenter::legend()
407 {
357 {
408 return m_chart->legend();
358 return m_chart->legend();
409 }
359 }
410
360
411 void ChartPresenter::setVisible(bool visible)
361 void ChartPresenter::setVisible(bool visible)
412 {
362 {
413 m_chart->setVisible(visible);
363 m_chart->setVisible(visible);
414 }
364 }
415
365
416 ChartBackground *ChartPresenter::backgroundElement()
366 ChartBackground *ChartPresenter::backgroundElement()
417 {
367 {
418 return m_background;
368 return m_background;
419 }
369 }
420
370
421 QList<ChartAxis *> ChartPresenter::axisItems() const
371 QList<ChartAxis *> ChartPresenter::axisItems() const
422 {
372 {
423 return m_axisItems.values();
373 return m_axisItems.values();
424 }
374 }
425
375
426 QList<ChartElement *> ChartPresenter::chartItems() const
376 QList<ChartElement *> ChartPresenter::chartItems() const
427 {
377 {
428 return m_chartItems.values();
378 return m_chartItems.values();
429 }
379 }
430
380
431 ChartTitle *ChartPresenter::titleElement()
381 ChartTitle *ChartPresenter::titleElement()
432 {
382 {
433 return m_title;
383 return m_title;
434 }
384 }
435
385
436 #include "moc_chartpresenter_p.cpp"
386 #include "moc_chartpresenter_p.cpp"
437
387
438 QTCOMMERCIALCHART_END_NAMESPACE
388 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,171 +1,169
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTPRESENTER_H
30 #ifndef CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
34 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
35 #include <QRectF>
35 #include <QRectF>
36 #include <QMargins>
36 #include <QMargins>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class ChartElement;
40 class ChartElement;
41 class QAbstractSeries;
41 class QAbstractSeries;
42 class ChartDataSet;
42 class ChartDataSet;
43 class Domain;
43 class Domain;
44 class ChartAxis;
44 class ChartAxis;
45 class ChartTheme;
45 class ChartTheme;
46 class ChartAnimator;
46 class ChartAnimator;
47 class ChartBackground;
47 class ChartBackground;
48 class ChartTitle;
48 class ChartTitle;
49 class ChartAnimation;
49 class ChartAnimation;
50 class ChartLayout;
50 class ChartLayout;
51
51
52 class ChartPresenter: public QObject
52 class ChartPresenter: public QObject
53 {
53 {
54 Q_OBJECT
54 Q_OBJECT
55 public:
55 public:
56 enum ZValues {
56 enum ZValues {
57 BackgroundZValue = -1,
57 BackgroundZValue = -1,
58 ShadesZValue ,
58 ShadesZValue ,
59 GridZValue,
59 GridZValue,
60 AxisZValue,
60 AxisZValue,
61 SeriesZValue,
61 SeriesZValue,
62 LineChartZValue = SeriesZValue,
62 LineChartZValue = SeriesZValue,
63 SplineChartZValue = SeriesZValue,
63 SplineChartZValue = SeriesZValue,
64 BarSeriesZValue = SeriesZValue,
64 BarSeriesZValue = SeriesZValue,
65 ScatterSeriesZValue = SeriesZValue,
65 ScatterSeriesZValue = SeriesZValue,
66 PieSeriesZValue = SeriesZValue,
66 PieSeriesZValue = SeriesZValue,
67 LegendZValue,
67 LegendZValue,
68 TopMostZValue
68 TopMostZValue
69 };
69 };
70
70
71 enum State {
71 enum State {
72 ShowState,
72 ShowState,
73 ScrollUpState,
73 ScrollUpState,
74 ScrollDownState,
74 ScrollDownState,
75 ScrollLeftState,
75 ScrollLeftState,
76 ScrollRightState,
76 ScrollRightState,
77 ZoomInState,
77 ZoomInState,
78 ZoomOutState
78 ZoomOutState
79 };
79 };
80
80
81 ChartPresenter(QChart *chart, ChartDataSet *dataset);
81 ChartPresenter(QChart *chart, ChartDataSet *dataset);
82 virtual ~ChartPresenter();
82 virtual ~ChartPresenter();
83
83
84 ChartTheme *chartTheme() const { return m_chartTheme; }
84 ChartTheme *chartTheme() const { return m_chartTheme; }
85 ChartDataSet *dataSet() const { return m_dataset; }
85 ChartDataSet *dataSet() const { return m_dataset; }
86 QGraphicsItem *rootItem() const { return m_chart; }
86 QGraphicsItem *rootItem() const { return m_chart; }
87 ChartBackground *backgroundElement();
87 ChartBackground *backgroundElement();
88 ChartTitle *titleElement();
88 ChartTitle *titleElement();
89 QList<ChartAxis *> axisItems() const;
89 QList<ChartAxis *> axisItems() const;
90 QList<ChartElement *> chartItems() const;
90 QList<ChartElement *> chartItems() const;
91
91
92 QLegend *legend();
92 QLegend *legend();
93
93
94 void setBackgroundBrush(const QBrush &brush);
94 void setBackgroundBrush(const QBrush &brush);
95 QBrush backgroundBrush() const;
95 QBrush backgroundBrush() const;
96
96
97 void setBackgroundPen(const QPen &pen);
97 void setBackgroundPen(const QPen &pen);
98 QPen backgroundPen() const;
98 QPen backgroundPen() const;
99
99
100 void setTitle(const QString &title);
100 void setTitle(const QString &title);
101 QString title() const;
101 QString title() const;
102
102
103 void setTitleFont(const QFont &font);
103 void setTitleFont(const QFont &font);
104 QFont titleFont() const;
104 QFont titleFont() const;
105
105
106 void setTitleBrush(const QBrush &brush);
106 void setTitleBrush(const QBrush &brush);
107 QBrush titleBrush() const;
107 QBrush titleBrush() const;
108
108
109 void setBackgroundVisible(bool visible);
109 void setBackgroundVisible(bool visible);
110 bool isBackgroundVisible() const;
110 bool isBackgroundVisible() const;
111
111
112 void setBackgroundDropShadowEnabled(bool enabled);
112 void setBackgroundDropShadowEnabled(bool enabled);
113 bool isBackgroundDropShadowEnabled() const;
113 bool isBackgroundDropShadowEnabled() const;
114
114
115 void setVisible(bool visible);
115 void setVisible(bool visible);
116
116
117 void setTheme(QChart::ChartTheme theme, bool force = true);
117 void setTheme(QChart::ChartTheme theme, bool force = true);
118 QChart::ChartTheme theme();
118 QChart::ChartTheme theme();
119
119
120 void setAnimationOptions(QChart::AnimationOptions options);
120 void setAnimationOptions(QChart::AnimationOptions options);
121 QChart::AnimationOptions animationOptions() const;
121 QChart::AnimationOptions animationOptions() const;
122
122
123 void zoomIn(qreal factor);
123 void zoomIn(qreal factor);
124 void zoomIn(const QRectF &rect);
124 void zoomIn(const QRectF &rect);
125 void zoomOut(qreal factor);
125 void zoomOut(qreal factor);
126 void scroll(qreal dx, qreal dy);
126 void scroll(qreal dx, qreal dy);
127
127
128 void startAnimation(ChartAnimation *animation);
128 void startAnimation(ChartAnimation *animation);
129 State state() const { return m_state; }
129 State state() const { return m_state; }
130 QPointF statePoint() const { return m_statePoint; }
130 QPointF statePoint() const { return m_statePoint; }
131
131
132 void resetAllElements();
132 void resetAllElements();
133
133
134 ChartLayout *layout();
134 ChartLayout *layout();
135
135
136 private:
136 private:
137 void createBackgroundItem();
137 void createBackgroundItem();
138 void createTitleItem();
138 void createTitleItem();
139 void selectVisibleAxis();
140
139
141 public Q_SLOTS:
140 public Q_SLOTS:
142 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
141 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
143 void handleSeriesRemoved(QAbstractSeries *series);
142 void handleSeriesRemoved(QAbstractSeries *series);
144 void handleAxisAdded(QAbstractAxis *axis, Domain *domain);
143 void handleAxisAdded(QAbstractAxis *axis, Domain *domain);
145 void handleAxisRemoved(QAbstractAxis *axis);
144 void handleAxisRemoved(QAbstractAxis *axis);
146 void handleAxisVisibleChanged(bool visible);
147
145
148 private Q_SLOTS:
146 private Q_SLOTS:
149 void handleAnimationFinished();
147 void handleAnimationFinished();
150
148
151 Q_SIGNALS:
149 Q_SIGNALS:
152 void animationsFinished();
150 void animationsFinished();
153
151
154 private:
152 private:
155 QChart *m_chart;
153 QChart *m_chart;
156 ChartDataSet *m_dataset;
154 ChartDataSet *m_dataset;
157 ChartTheme *m_chartTheme;
155 ChartTheme *m_chartTheme;
158 QMap<QAbstractSeries *, ChartElement *> m_chartItems;
156 QMap<QAbstractSeries *, ChartElement *> m_chartItems;
159 QMap<QAbstractAxis *, ChartAxis *> m_axisItems;
157 QMap<QAbstractAxis *, ChartAxis *> m_axisItems;
160 QChart::AnimationOptions m_options;
158 QChart::AnimationOptions m_options;
161 State m_state;
159 State m_state;
162 QPointF m_statePoint;
160 QPointF m_statePoint;
163 QList<ChartAnimation *> m_animations;
161 QList<ChartAnimation *> m_animations;
164 ChartLayout *m_layout;
162 ChartLayout *m_layout;
165 ChartBackground *m_background;
163 ChartBackground *m_background;
166 ChartTitle *m_title;
164 ChartTitle *m_title;
167 };
165 };
168
166
169 QTCOMMERCIALCHART_END_NAMESPACE
167 QTCOMMERCIALCHART_END_NAMESPACE
170
168
171 #endif /* CHARTPRESENTER_H */
169 #endif /* CHARTPRESENTER_H */
General Comments 0
You need to be logged in to leave comments. Login now