@@ -0,0 +1,46 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2013 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "chartanimation_p.h" | |
|
22 | ||
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
24 | ||
|
25 | ChartAnimation::ChartAnimation(QObject *parent) : | |
|
26 | QVariantAnimation(parent), | |
|
27 | m_destructing(false) | |
|
28 | { | |
|
29 | } | |
|
30 | ||
|
31 | void ChartAnimation::stopAndDestroyLater() | |
|
32 | { | |
|
33 | m_destructing = true; | |
|
34 | stop(); | |
|
35 | deleteLater(); | |
|
36 | } | |
|
37 | ||
|
38 | void ChartAnimation::startChartAnimation() | |
|
39 | { | |
|
40 | if (!m_destructing) | |
|
41 | start(); | |
|
42 | } | |
|
43 | ||
|
44 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
45 | ||
|
46 |
@@ -10,7 +10,8 SOURCES += \ | |||
|
10 | 10 | $$PWD/baranimation.cpp \ |
|
11 | 11 | $$PWD/scatteranimation.cpp \ |
|
12 | 12 | $$PWD/boxplotanimation.cpp \ |
|
13 | $$PWD/boxwhiskersanimation.cpp | |
|
13 | $$PWD/boxwhiskersanimation.cpp \ | |
|
14 | $$PWD/chartanimation.cpp | |
|
14 | 15 | |
|
15 | 16 | PRIVATE_HEADERS += \ |
|
16 | 17 | $$PWD/axisanimation_p.h \ |
@@ -41,7 +41,15 class ChartAnimation: public QVariantAnimation | |||
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | public: |
|
44 |
ChartAnimation(QObject *parent = 0) |
|
|
44 | ChartAnimation(QObject *parent = 0); | |
|
45 | ||
|
46 | void stopAndDestroyLater(); | |
|
47 | ||
|
48 | public Q_SLOTS: | |
|
49 | void startChartAnimation(); | |
|
50 | ||
|
51 | protected: | |
|
52 | bool m_destructing; | |
|
45 | 53 | }; |
|
46 | 54 | |
|
47 | 55 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -395,11 +395,17 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |||
|
395 | 395 | { |
|
396 | 396 | Q_Q(QAreaSeries); |
|
397 | 397 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); |
|
398 | ||
|
399 | if (area->upperLineItem()->animation()) | |
|
400 | area->upperLineItem()->animation()->stopAndDestroyLater(); | |
|
401 | if (q->lowerSeries() && area->lowerLineItem()->animation()) | |
|
402 | area->lowerLineItem()->animation()->stopAndDestroyLater(); | |
|
403 | ||
|
398 | 404 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
399 | 405 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
400 | 406 | if (q->lowerSeries()) |
|
401 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
|
402 | }else{ | |
|
407 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
|
408 | } else { | |
|
403 | 409 | area->upperLineItem()->setAnimation(0); |
|
404 | 410 | if (q->lowerSeries()) |
|
405 | 411 | area->lowerLineItem()->setAnimation(0); |
@@ -997,11 +997,13 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options | |||
|
997 | 997 | { |
|
998 | 998 | ChartAxisElement *axis = m_item.data(); |
|
999 | 999 | Q_ASSERT(axis); |
|
1000 | if (options.testFlag(QChart::GridAxisAnimations)) { | |
|
1000 | if (axis->animation()) | |
|
1001 | axis->animation()->stopAndDestroyLater(); | |
|
1002 | ||
|
1003 | if (options.testFlag(QChart::GridAxisAnimations)) | |
|
1001 | 1004 | axis->setAnimation(new AxisAnimation(axis)); |
|
1002 |
|
|
|
1005 | else | |
|
1003 | 1006 | axis->setAnimation(0); |
|
1004 | } | |
|
1005 | 1007 | } |
|
1006 | 1008 | |
|
1007 | 1009 |
@@ -887,11 +887,13 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions op | |||
|
887 | 887 | { |
|
888 | 888 | AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data()); |
|
889 | 889 | Q_ASSERT(bar); |
|
890 | if (options.testFlag(QChart::SeriesAnimations)) { | |
|
890 | if (bar->animation()) | |
|
891 | bar->animation()->stopAndDestroyLater(); | |
|
892 | ||
|
893 | if (options.testFlag(QChart::SeriesAnimations)) | |
|
891 | 894 | bar->setAnimation(new BarAnimation(bar)); |
|
892 |
|
|
|
895 | else | |
|
893 | 896 | bar->setAnimation(0); |
|
894 | } | |
|
895 | 897 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
896 | 898 | } |
|
897 | 899 |
@@ -484,10 +484,13 void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions option | |||
|
484 | 484 | { |
|
485 | 485 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
486 | 486 | Q_ASSERT(item); |
|
487 | if (item->animation()) | |
|
488 | item->animation()->stopAndDestroyLater(); | |
|
489 | ||
|
487 | 490 | if (options.testFlag(QChart::SeriesAnimations)) |
|
488 | 491 | item->setAnimation(new BoxPlotAnimation(item)); |
|
489 | 492 | else |
|
490 |
item->setAnimation( |
|
|
493 | item->setAnimation(0); | |
|
491 | 494 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
492 | 495 | } |
|
493 | 496 |
@@ -126,14 +126,17 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | |||
|
126 | 126 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
127 | 127 | { |
|
128 | 128 | if (m_options != options) { |
|
129 | QChart::AnimationOptions oldOptions = m_options; | |
|
129 | 130 | m_options = options; |
|
130 | ||
|
131 |
foreach(QAbstractSeries* |
|
|
132 | series->d_ptr->initializeAnimations(m_options); | |
|
131 | if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) { | |
|
132 | foreach (QAbstractSeries *series, m_series) | |
|
133 | series->d_ptr->initializeAnimations(m_options); | |
|
133 | 134 | } |
|
134 | foreach(QAbstractAxis* axis, m_axes){ | |
|
135 | axis->d_ptr->initializeAnimations(m_options); | |
|
135 | if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) { | |
|
136 | foreach (QAbstractAxis *axis, m_axes) | |
|
137 | axis->d_ptr->initializeAnimations(m_options); | |
|
136 | 138 | } |
|
139 | m_layout->invalidate(); // So that existing animations don't just stop halfway | |
|
137 | 140 | } |
|
138 | 141 | } |
|
139 | 142 | |
@@ -182,21 +185,10 void ChartPresenter::createTitleItem() | |||
|
182 | 185 | } |
|
183 | 186 | } |
|
184 | 187 | |
|
185 | ||
|
186 | void ChartPresenter::handleAnimationFinished() | |
|
187 | { | |
|
188 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); | |
|
189 | if (m_animations.empty()) | |
|
190 | emit animationsFinished(); | |
|
191 | } | |
|
192 | ||
|
193 | 188 | void ChartPresenter::startAnimation(ChartAnimation *animation) |
|
194 | 189 | { |
|
195 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | |
|
196 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); | |
|
197 | if (!m_animations.isEmpty()) | |
|
198 | m_animations.append(animation); | |
|
199 | QTimer::singleShot(0, animation, SLOT(start())); | |
|
190 | animation->stop(); | |
|
191 | QTimer::singleShot(0, animation, SLOT(startChartAnimation())); | |
|
200 | 192 | } |
|
201 | 193 | |
|
202 | 194 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
@@ -159,12 +159,6 public Q_SLOTS: | |||
|
159 | 159 | void handleAxisAdded(QAbstractAxis *axis); |
|
160 | 160 | void handleAxisRemoved(QAbstractAxis *axis); |
|
161 | 161 | |
|
162 | private Q_SLOTS: | |
|
163 | void handleAnimationFinished(); | |
|
164 | ||
|
165 | Q_SIGNALS: | |
|
166 | void animationsFinished(); | |
|
167 | ||
|
168 | 162 | private: |
|
169 | 163 | QChart *m_chart; |
|
170 | 164 | QList<ChartItem *> m_chartItems; |
@@ -174,7 +168,6 private: | |||
|
174 | 168 | QChart::AnimationOptions m_options; |
|
175 | 169 | State m_state; |
|
176 | 170 | QPointF m_statePoint; |
|
177 | QList<ChartAnimation *> m_animations; | |
|
178 | 171 | AbstractChartLayout *m_layout; |
|
179 | 172 | ChartBackground *m_background; |
|
180 | 173 | QAbstractGraphicsShapeItem *m_plotAreaBackground; |
@@ -863,11 +863,13 void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::Animatio | |||
|
863 | 863 | { |
|
864 | 864 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); |
|
865 | 865 | Q_ASSERT(item); |
|
866 | if (options.testFlag(QChart::SeriesAnimations)) { | |
|
866 | if (item->animation()) | |
|
867 | item->animation()->stopAndDestroyLater(); | |
|
868 | ||
|
869 | if (options.testFlag(QChart::SeriesAnimations)) | |
|
867 | 870 | item->setAnimation(new PieAnimation(item)); |
|
868 |
|
|
|
871 | else | |
|
869 | 872 | item->setAnimation(0); |
|
870 | } | |
|
871 | 873 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
872 | 874 | } |
|
873 | 875 |
@@ -288,6 +288,9 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions option | |||
|
288 | 288 | ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data()); |
|
289 | 289 | Q_ASSERT(item); |
|
290 | 290 | |
|
291 | if (item->animation()) | |
|
292 | item->animation()->stopAndDestroyLater(); | |
|
293 | ||
|
291 | 294 | if (options.testFlag(QChart::SeriesAnimations)) |
|
292 | 295 | item->setAnimation(new ScatterAnimation(item)); |
|
293 | 296 | else |
@@ -139,11 +139,13 void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::Anima | |||
|
139 | 139 | { |
|
140 | 140 | SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); |
|
141 | 141 | Q_ASSERT(item); |
|
142 | if (options.testFlag(QChart::SeriesAnimations)) { | |
|
142 | if (item->animation()) | |
|
143 | item->animation()->stopAndDestroyLater(); | |
|
144 | ||
|
145 | if (options.testFlag(QChart::SeriesAnimations)) | |
|
143 | 146 | item->setAnimation(new SplineAnimation(item)); |
|
144 |
|
|
|
147 | else | |
|
145 | 148 | item->setAnimation(0); |
|
146 | } | |
|
147 | 149 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
148 | 150 | } |
|
149 | 151 |
@@ -582,11 +582,13 void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::Animation | |||
|
582 | 582 | { |
|
583 | 583 | XYChart *item = static_cast<XYChart *>(m_item.data()); |
|
584 | 584 | Q_ASSERT(item); |
|
585 | if (options.testFlag(QChart::SeriesAnimations)) { | |
|
585 | if (item->animation()) | |
|
586 | item->animation()->stopAndDestroyLater(); | |
|
587 | ||
|
588 | if (options.testFlag(QChart::SeriesAnimations)) | |
|
586 | 589 | item->setAnimation(new XYAnimation(item)); |
|
587 |
|
|
|
590 | else | |
|
588 | 591 | item->setAnimation(0); |
|
589 | } | |
|
590 | 592 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
591 | 593 | } |
|
592 | 594 |
General Comments 0
You need to be logged in to leave comments.
Login now