@@ -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 | $$PWD/baranimation.cpp \ |
|
10 | $$PWD/baranimation.cpp \ | |
11 | $$PWD/scatteranimation.cpp \ |
|
11 | $$PWD/scatteranimation.cpp \ | |
12 | $$PWD/boxplotanimation.cpp \ |
|
12 | $$PWD/boxplotanimation.cpp \ | |
13 | $$PWD/boxwhiskersanimation.cpp |
|
13 | $$PWD/boxwhiskersanimation.cpp \ | |
|
14 | $$PWD/chartanimation.cpp | |||
14 |
|
15 | |||
15 | PRIVATE_HEADERS += \ |
|
16 | PRIVATE_HEADERS += \ | |
16 | $$PWD/axisanimation_p.h \ |
|
17 | $$PWD/axisanimation_p.h \ |
@@ -41,7 +41,15 class ChartAnimation: public QVariantAnimation | |||||
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | public: |
|
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 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -395,11 +395,17 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |||||
395 | { |
|
395 | { | |
396 | Q_Q(QAreaSeries); |
|
396 | Q_Q(QAreaSeries); | |
397 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); |
|
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 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
404 | if (options.testFlag(QChart::SeriesAnimations)) { | |
399 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
405 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
400 | if (q->lowerSeries()) |
|
406 | if (q->lowerSeries()) | |
401 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
407 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
402 | }else{ |
|
408 | } else { | |
403 | area->upperLineItem()->setAnimation(0); |
|
409 | area->upperLineItem()->setAnimation(0); | |
404 | if (q->lowerSeries()) |
|
410 | if (q->lowerSeries()) | |
405 | area->lowerLineItem()->setAnimation(0); |
|
411 | area->lowerLineItem()->setAnimation(0); |
@@ -997,11 +997,13 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options | |||||
997 | { |
|
997 | { | |
998 | ChartAxisElement *axis = m_item.data(); |
|
998 | ChartAxisElement *axis = m_item.data(); | |
999 | Q_ASSERT(axis); |
|
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 | axis->setAnimation(new AxisAnimation(axis)); |
|
1004 | axis->setAnimation(new AxisAnimation(axis)); | |
1002 |
|
|
1005 | else | |
1003 | axis->setAnimation(0); |
|
1006 | axis->setAnimation(0); | |
1004 | } |
|
|||
1005 | } |
|
1007 | } | |
1006 |
|
1008 | |||
1007 |
|
1009 |
@@ -887,11 +887,13 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions op | |||||
887 | { |
|
887 | { | |
888 | AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data()); |
|
888 | AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data()); | |
889 | Q_ASSERT(bar); |
|
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 | bar->setAnimation(new BarAnimation(bar)); |
|
894 | bar->setAnimation(new BarAnimation(bar)); | |
892 |
|
|
895 | else | |
893 | bar->setAnimation(0); |
|
896 | bar->setAnimation(0); | |
894 | } |
|
|||
895 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
897 | QAbstractSeriesPrivate::initializeAnimations(options); | |
896 | } |
|
898 | } | |
897 |
|
899 |
@@ -484,10 +484,13 void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions option | |||||
484 | { |
|
484 | { | |
485 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); |
|
485 | BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data()); | |
486 | Q_ASSERT(item); |
|
486 | Q_ASSERT(item); | |
|
487 | if (item->animation()) | |||
|
488 | item->animation()->stopAndDestroyLater(); | |||
|
489 | ||||
487 | if (options.testFlag(QChart::SeriesAnimations)) |
|
490 | if (options.testFlag(QChart::SeriesAnimations)) | |
488 | item->setAnimation(new BoxPlotAnimation(item)); |
|
491 | item->setAnimation(new BoxPlotAnimation(item)); | |
489 | else |
|
492 | else | |
490 |
item->setAnimation( |
|
493 | item->setAnimation(0); | |
491 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
494 | QAbstractSeriesPrivate::initializeAnimations(options); | |
492 | } |
|
495 | } | |
493 |
|
496 |
@@ -126,14 +126,17 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | |||||
126 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
126 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
127 | { |
|
127 | { | |
128 | if (m_options != options) { |
|
128 | if (m_options != options) { | |
|
129 | QChart::AnimationOptions oldOptions = m_options; | |||
129 | m_options = options; |
|
130 | m_options = options; | |
130 |
|
131 | if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) { | ||
131 |
foreach(QAbstractSeries* |
|
132 | foreach (QAbstractSeries *series, m_series) | |
132 | series->d_ptr->initializeAnimations(m_options); |
|
133 | series->d_ptr->initializeAnimations(m_options); | |
133 | } |
|
134 | } | |
134 | foreach(QAbstractAxis* axis, m_axes){ |
|
135 | if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) { | |
135 | axis->d_ptr->initializeAnimations(m_options); |
|
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 | void ChartPresenter::startAnimation(ChartAnimation *animation) |
|
188 | void ChartPresenter::startAnimation(ChartAnimation *animation) | |
194 | { |
|
189 | { | |
195 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
190 | animation->stop(); | |
196 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); |
|
191 | QTimer::singleShot(0, animation, SLOT(startChartAnimation())); | |
197 | if (!m_animations.isEmpty()) |
|
|||
198 | m_animations.append(animation); |
|
|||
199 | QTimer::singleShot(0, animation, SLOT(start())); |
|
|||
200 | } |
|
192 | } | |
201 |
|
193 | |||
202 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
|
194 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
@@ -159,12 +159,6 public Q_SLOTS: | |||||
159 | void handleAxisAdded(QAbstractAxis *axis); |
|
159 | void handleAxisAdded(QAbstractAxis *axis); | |
160 | void handleAxisRemoved(QAbstractAxis *axis); |
|
160 | void handleAxisRemoved(QAbstractAxis *axis); | |
161 |
|
161 | |||
162 | private Q_SLOTS: |
|
|||
163 | void handleAnimationFinished(); |
|
|||
164 |
|
||||
165 | Q_SIGNALS: |
|
|||
166 | void animationsFinished(); |
|
|||
167 |
|
||||
168 | private: |
|
162 | private: | |
169 | QChart *m_chart; |
|
163 | QChart *m_chart; | |
170 | QList<ChartItem *> m_chartItems; |
|
164 | QList<ChartItem *> m_chartItems; | |
@@ -174,7 +168,6 private: | |||||
174 | QChart::AnimationOptions m_options; |
|
168 | QChart::AnimationOptions m_options; | |
175 | State m_state; |
|
169 | State m_state; | |
176 | QPointF m_statePoint; |
|
170 | QPointF m_statePoint; | |
177 | QList<ChartAnimation *> m_animations; |
|
|||
178 | AbstractChartLayout *m_layout; |
|
171 | AbstractChartLayout *m_layout; | |
179 | ChartBackground *m_background; |
|
172 | ChartBackground *m_background; | |
180 | QAbstractGraphicsShapeItem *m_plotAreaBackground; |
|
173 | QAbstractGraphicsShapeItem *m_plotAreaBackground; |
@@ -863,11 +863,13 void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::Animatio | |||||
863 | { |
|
863 | { | |
864 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); |
|
864 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); | |
865 | Q_ASSERT(item); |
|
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 | item->setAnimation(new PieAnimation(item)); |
|
870 | item->setAnimation(new PieAnimation(item)); | |
868 |
|
|
871 | else | |
869 | item->setAnimation(0); |
|
872 | item->setAnimation(0); | |
870 | } |
|
|||
871 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
873 | QAbstractSeriesPrivate::initializeAnimations(options); | |
872 | } |
|
874 | } | |
873 |
|
875 |
@@ -288,6 +288,9 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions option | |||||
288 | ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data()); |
|
288 | ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data()); | |
289 | Q_ASSERT(item); |
|
289 | Q_ASSERT(item); | |
290 |
|
290 | |||
|
291 | if (item->animation()) | |||
|
292 | item->animation()->stopAndDestroyLater(); | |||
|
293 | ||||
291 | if (options.testFlag(QChart::SeriesAnimations)) |
|
294 | if (options.testFlag(QChart::SeriesAnimations)) | |
292 | item->setAnimation(new ScatterAnimation(item)); |
|
295 | item->setAnimation(new ScatterAnimation(item)); | |
293 | else |
|
296 | else |
@@ -139,11 +139,13 void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::Anima | |||||
139 | { |
|
139 | { | |
140 | SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); |
|
140 | SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); | |
141 | Q_ASSERT(item); |
|
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 | item->setAnimation(new SplineAnimation(item)); |
|
146 | item->setAnimation(new SplineAnimation(item)); | |
144 |
|
|
147 | else | |
145 | item->setAnimation(0); |
|
148 | item->setAnimation(0); | |
146 | } |
|
|||
147 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
149 | QAbstractSeriesPrivate::initializeAnimations(options); | |
148 | } |
|
150 | } | |
149 |
|
151 |
@@ -582,11 +582,13 void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::Animation | |||||
582 | { |
|
582 | { | |
583 | XYChart *item = static_cast<XYChart *>(m_item.data()); |
|
583 | XYChart *item = static_cast<XYChart *>(m_item.data()); | |
584 | Q_ASSERT(item); |
|
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 | item->setAnimation(new XYAnimation(item)); |
|
589 | item->setAnimation(new XYAnimation(item)); | |
587 |
|
|
590 | else | |
588 | item->setAnimation(0); |
|
591 | item->setAnimation(0); | |
589 | } |
|
|||
590 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
592 | QAbstractSeriesPrivate::initializeAnimations(options); | |
591 | } |
|
593 | } | |
592 |
|
594 |
General Comments 0
You need to be logged in to leave comments.
Login now