##// END OF EJS Templates
Refactor animator...
Michal Klocek -
r1735:0a19606ca1b1
parent child
Show More
@@ -3,7 +3,6 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/axisanimation.cpp \
5 $$PWD/axisanimation.cpp \
6 $$PWD/chartanimator.cpp \
7 $$PWD/xyanimation.cpp \
6 $$PWD/xyanimation.cpp \
8 $$PWD/pieanimation.cpp \
7 $$PWD/pieanimation.cpp \
9 $$PWD/piesliceanimation.cpp \
8 $$PWD/piesliceanimation.cpp \
@@ -18,7 +17,6 SOURCES += \
18
17
19 PRIVATE_HEADERS += \
18 PRIVATE_HEADERS += \
20 $$PWD/axisanimation_p.h \
19 $$PWD/axisanimation_p.h \
21 $$PWD/chartanimator_p.h \
22 $$PWD/chartanimation_p.h \
20 $$PWD/chartanimation_p.h \
23 $$PWD/xyanimation_p.h \
21 $$PWD/xyanimation_p.h \
24 $$PWD/pieanimation_p.h \
22 $$PWD/pieanimation_p.h \
@@ -35,7 +35,7 PieAnimation::~PieAnimation()
35 {
35 {
36 }
36 }
37
37
38 void PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &sliceData)
38 ChartAnimation* PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &sliceData)
39 {
39 {
40 PieSliceAnimation *animation = m_animations.value(sliceItem);
40 PieSliceAnimation *animation = m_animations.value(sliceItem);
41 Q_ASSERT(animation);
41 Q_ASSERT(animation);
@@ -45,10 +45,10 void PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &slic
45 animation->setDuration(ChartAnimationDuration);
45 animation->setDuration(ChartAnimationDuration);
46 animation->setEasingCurve(QEasingCurve::OutQuart);
46 animation->setEasingCurve(QEasingCurve::OutQuart);
47
47
48 QTimer::singleShot(0, animation, SLOT(start()));
48 return animation;
49 }
49 }
50
50
51 void PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation)
51 ChartAnimation* PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation)
52 {
52 {
53 PieSliceAnimation *animation = new PieSliceAnimation(sliceItem);
53 PieSliceAnimation *animation = new PieSliceAnimation(sliceItem);
54 m_animations.insert(sliceItem, animation);
54 m_animations.insert(sliceItem, animation);
@@ -64,10 +64,11 void PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceDa
64
64
65 animation->setDuration(ChartAnimationDuration);
65 animation->setDuration(ChartAnimationDuration);
66 animation->setEasingCurve(QEasingCurve::OutQuart);
66 animation->setEasingCurve(QEasingCurve::OutQuart);
67 QTimer::singleShot(0, animation, SLOT(start()));
67
68 return animation;
68 }
69 }
69
70
70 void PieAnimation::removeSlice(PieSliceItem *sliceItem)
71 ChartAnimation* PieAnimation::removeSlice(PieSliceItem *sliceItem)
71 {
72 {
72 PieSliceAnimation *animation = m_animations.value(sliceItem);
73 PieSliceAnimation *animation = m_animations.value(sliceItem);
73 Q_ASSERT(animation);
74 Q_ASSERT(animation);
@@ -87,7 +88,7 void PieAnimation::removeSlice(PieSliceItem *sliceItem)
87 connect(animation, SIGNAL(finished()), sliceItem, SLOT(deleteLater()));
88 connect(animation, SIGNAL(finished()), sliceItem, SLOT(deleteLater()));
88 m_animations.remove(sliceItem);
89 m_animations.remove(sliceItem);
89
90
90 QTimer::singleShot(0, animation, SLOT(start()));
91 return animation;
91 }
92 }
92
93
93 void PieAnimation::updateCurrentValue(const QVariant &)
94 void PieAnimation::updateCurrentValue(const QVariant &)
@@ -45,9 +45,9 class PieAnimation : public ChartAnimation
45 public:
45 public:
46 PieAnimation(PieChartItem *item);
46 PieAnimation(PieChartItem *item);
47 ~PieAnimation();
47 ~PieAnimation();
48 void updateValue(PieSliceItem *sliceItem, const PieSliceData &newValue);
48 ChartAnimation* updateValue(PieSliceItem *sliceItem, const PieSliceData &newValue);
49 void addSlice(PieSliceItem *sliceItem, const PieSliceData &endValue, bool startupAnimation);
49 ChartAnimation* addSlice(PieSliceItem *sliceItem, const PieSliceData &endValue, bool startupAnimation);
50 void removeSlice(PieSliceItem *sliceItem);
50 ChartAnimation* removeSlice(PieSliceItem *sliceItem);
51
51
52 public: // from QVariantAnimation
52 public: // from QVariantAnimation
53 void updateCurrentValue(const QVariant &value);
53 void updateCurrentValue(const QVariant &value);
@@ -58,7 +58,7 QBrush linearPos(QBrush start, QBrush end, qreal pos)
58 }
58 }
59
59
60 PieSliceAnimation::PieSliceAnimation(PieSliceItem *sliceItem)
60 PieSliceAnimation::PieSliceAnimation(PieSliceItem *sliceItem)
61 :QVariantAnimation(sliceItem),
61 :ChartAnimation(sliceItem),
62 m_sliceItem(sliceItem)
62 m_sliceItem(sliceItem)
63 {
63 {
64 }
64 }
@@ -30,14 +30,14
30 #ifndef PIESLICEANIMATION_P_H
30 #ifndef PIESLICEANIMATION_P_H
31 #define PIESLICEANIMATION_P_H
31 #define PIESLICEANIMATION_P_H
32
32
33 #include <QVariantAnimation>
33 #include "chartanimation_p.h"
34 #include "piesliceitem_p.h"
34 #include "piesliceitem_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class PieChartItem;
38 class PieChartItem;
39
39
40 class PieSliceAnimation : public QVariantAnimation
40 class PieSliceAnimation : public ChartAnimation
41 {
41 {
42 public:
42 public:
43 PieSliceAnimation(PieSliceItem *sliceItem);
43 PieSliceAnimation(PieSliceItem *sliceItem);
@@ -26,7 +26,6
26 #include "domain_p.h"
26 #include "domain_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
30 #include "qvaluesaxis.h"
29 #include "qvaluesaxis.h"
31
30
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -363,10 +362,8 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
363
362
364 AreaChartItem* area = new AreaChartItem(q,presenter);
363 AreaChartItem* area = new AreaChartItem(q,presenter);
365 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
364 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
366 area->upperLineItem()->setAnimator(presenter->animator());
367 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
365 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
368 if(q->lowerSeries()) {
366 if(q->lowerSeries()) {
369 area->lowerLineItem()->setAnimator(presenter->animator());
370 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
367 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
371 }
368 }
372 }
369 }
@@ -22,7 +22,6
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "qabstractaxis_p.h"
23 #include "qabstractaxis_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "chartanimator_p.h"
26 #include "domain_p.h"
25 #include "domain_p.h"
27 #include <qmath.h>
26 #include <qmath.h>
28 #include <QDateTime>
27 #include <QDateTime>
@@ -19,15 +19,13
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdatetimeaxisx_p.h"
21 #include "chartdatetimeaxisx_p.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
25 #include "qdatetimeaxis.h"
23 #include "qdatetimeaxis.h"
26 #include <QGraphicsLayout>
24 #include <QGraphicsLayout>
27 #include <QDebug>
28 #include <QFontMetrics>
29 #include <cmath>
30 #include <QDateTime>
25 #include <QDateTime>
26 #include <QFontMetrics>
27 #include <qmath.h>
28
31
29
32 static int label_padding = 5;
30 static int label_padding = 5;
33
31
@@ -19,15 +19,13
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdatetimeaxisy_p.h"
21 #include "chartdatetimeaxisy_p.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
25 #include "qdatetimeaxis.h"
23 #include "qdatetimeaxis.h"
26 #include <QGraphicsLayout>
24 #include <QGraphicsLayout>
27 #include <QDebug>
28 #include <QFontMetrics>
25 #include <QFontMetrics>
29 #include <cmath>
30 #include <QDateTime>
26 #include <QDateTime>
27 #include <qmath.h>
28
31
29
32 static int label_padding = 5;
30 static int label_padding = 5;
33
31
@@ -19,14 +19,12
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartintervalsaxisx_p.h"
21 #include "chartintervalsaxisx_p.h"
22 #include "qintervalsaxis.h"
22 #include "qabstractaxis.h"
23 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
27 #include <QFontMetrics>
26 #include <QFontMetrics>
28 #include <cmath>
27 #include <qmath.h>
29 #include <QIntervalsAxis>
30
28
31 static int label_padding = 5;
29 static int label_padding = 5;
32
30
@@ -19,14 +19,13
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartintervalsaxisy_p.h"
21 #include "chartintervalsaxisy_p.h"
22 #include "qintervalsaxis.h"
22 #include "qabstractaxis.h"
23 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
27 #include <QFontMetrics>
26 #include <QFontMetrics>
28 #include <cmath>
27 #include <qmath.h>
29 #include <QIntervalsAxis>
28
30
29
31 static int label_padding = 5;
30 static int label_padding = 5;
32
31
@@ -21,12 +21,10
21 #include "chartvaluesaxisx_p.h"
21 #include "chartvaluesaxisx_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
25 #include "qvaluesaxis.h"
24 #include "qvaluesaxis.h"
26 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
27 #include <QDebug>
28 #include <QFontMetrics>
26 #include <QFontMetrics>
29 #include <cmath>
27 #include <qmath.h>
30
28
31 static int label_padding = 5;
29 static int label_padding = 5;
32
30
@@ -21,12 +21,10
21 #include "chartvaluesaxisy_p.h"
21 #include "chartvaluesaxisy_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
25 #include "qvaluesaxis.h"
24 #include "qvaluesaxis.h"
26 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
27 #include <QDebug>
28 #include <QFontMetrics>
26 #include <QFontMetrics>
29 #include <cmath>
27 #include <qmath.h>
30
28
31 static int label_padding = 5;
29 static int label_padding = 5;
32
30
@@ -26,7 +26,7
26 #include "qabstractbarseries_p.h"
26 #include "qabstractbarseries_p.h"
27 #include "qchart.h"
27 #include "qchart.h"
28 #include "chartpresenter_p.h"
28 #include "chartpresenter_p.h"
29 #include "chartanimator_p.h"
29 #include "charttheme_p.h"
30 #include "abstractbaranimation_p.h"
30 #include "abstractbaranimation_p.h"
31 #include "chartdataset_p.h"
31 #include "chartdataset_p.h"
32 #include <QPainter>
32 #include <QPainter>
@@ -107,7 +107,6 Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
107
107
108 HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter);
108 HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter);
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
110 bar->setAnimator(presenter->animator());
111 bar->setAnimation(new HorizontalBarAnimation(bar));
110 bar->setAnimation(new HorizontalBarAnimation(bar));
112 }
111 }
113 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
@@ -55,7 +55,6 Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presen
55
55
56 HorizontalPercentBarChartItem* bar = new HorizontalPercentBarChartItem(q,presenter);
56 HorizontalPercentBarChartItem* bar = new HorizontalPercentBarChartItem(q,presenter);
57 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
57 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
58 bar->setAnimator(presenter->animator());
59 bar->setAnimation(new HorizontalPercentBarAnimation(bar));
58 bar->setAnimation(new HorizontalPercentBarAnimation(bar));
60 }
59 }
61 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
60 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
@@ -56,7 +56,6 Chart* QHorizontalStackedBarSeriesPrivate::createGraphics(ChartPresenter* presen
56
56
57 HorizontalStackedBarChartItem* bar = new HorizontalStackedBarChartItem(q,presenter);
57 HorizontalStackedBarChartItem* bar = new HorizontalStackedBarChartItem(q,presenter);
58 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
58 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
59 bar->setAnimator(presenter->animator());
60 bar->setAnimation(new HorizontalStackedBarAnimation(bar));
59 bar->setAnimation(new HorizontalStackedBarAnimation(bar));
61 }
60 }
62 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
61 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
@@ -23,7 +23,6
23 #include "barchartitem_p.h"
23 #include "barchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
27 #include "baranimation_p.h"
26 #include "baranimation_p.h"
28 #include "qvaluesaxis.h"
27 #include "qvaluesaxis.h"
29 #include "qbarcategoriesaxis.h"
28 #include "qbarcategoriesaxis.h"
@@ -111,7 +110,6 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
111
110
112 BarChartItem* bar = new BarChartItem(q,presenter);
111 BarChartItem* bar = new BarChartItem(q,presenter);
113 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
112 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
114 bar->setAnimator(presenter->animator());
115 bar->setAnimation(new BarAnimation(bar));
113 bar->setAnimation(new BarAnimation(bar));
116 }
114 }
117 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
115 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
@@ -22,7 +22,6
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qabstractbarseries_p.h"
23 #include "qabstractbarseries_p.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25 #include "chartanimator_p.h"
26 #include "qbarset_p.h"
25 #include "qbarset_p.h"
27
26
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -23,7 +23,6
23 #include "percentbarchartitem_p.h"
23 #include "percentbarchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
27 #include "qvaluesaxis.h"
26 #include "qvaluesaxis.h"
28 #include "percentbaranimation_p.h"
27 #include "percentbaranimation_p.h"
29
28
@@ -110,7 +109,6 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
110
109
111 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
110 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
112 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
111 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
113 bar->setAnimator(presenter->animator());
114 bar->setAnimation(new PercentBarAnimation(bar));
112 bar->setAnimation(new PercentBarAnimation(bar));
115 }
113 }
116 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
114 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
@@ -23,7 +23,6
23 #include "stackedbarchartitem_p.h"
23 #include "stackedbarchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
27 #include "qvaluesaxis.h"
26 #include "qvaluesaxis.h"
28 #include "stackedbaranimation_p.h"
27 #include "stackedbaranimation_p.h"
29
28
@@ -111,7 +110,6 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
111
110
112 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
111 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
113 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
112 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
114 bar->setAnimator(presenter->animator());
115 bar->setAnimation(new StackedBarAnimation(bar));
113 bar->setAnimation(new StackedBarAnimation(bar));
116 }
114 }
117 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
115 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
@@ -23,7 +23,6
23 #include "qbarset_p.h"
23 #include "qbarset_p.h"
24 #include "qabstractbarseries_p.h"
24 #include "qabstractbarseries_p.h"
25 #include "qbarset.h"
25 #include "qbarset.h"
26 #include "chartanimator_p.h"
27
26
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
28
@@ -25,23 +25,11
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 Chart::Chart(ChartPresenter *presenter):QObject(presenter),
27 Chart::Chart(ChartPresenter *presenter):QObject(presenter),
28 m_animator(0),
29 m_presenter(presenter),
28 m_presenter(presenter),
30 m_domain(0)
29 m_domain(0)
31 {
30 {
32 }
31 }
33
32
34 void Chart::setAnimator(ChartAnimator* animator)
35 {
36 m_animator=animator;
37 }
38
39 ChartAnimator* Chart::animator() const
40 {
41 return m_animator;
42 }
43
44
45 void Chart::setPresenter(ChartPresenter *presenter)
33 void Chart::setPresenter(ChartPresenter *presenter)
46 {
34 {
47 m_presenter=presenter;
35 m_presenter=presenter;
@@ -51,17 +51,15 public Q_SLOTS:
51 virtual void handleGeometryChanged(const QRectF& rect);
51 virtual void handleGeometryChanged(const QRectF& rect);
52 virtual void handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY);
52 virtual void handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY);
53 virtual void handleDomainUpdated();
53 virtual void handleDomainUpdated();
54 virtual ChartAnimation* animation() const { return 0; };
54
55
55 void setAnimator(ChartAnimator* animator);
56 ChartAnimator* animator() const;
57 void setPresenter(ChartPresenter *presenter);
56 void setPresenter(ChartPresenter *presenter);
58 ChartPresenter* presenter() const;
57 ChartPresenter* presenter() const;
59 void setDomain(Domain *domain);
58 void setDomain(Domain *domain);
60 Domain* domain() const;
59 Domain* domain() const;
61 virtual ChartAnimation* animation() const { return 0; };
60
62
61
63 private:
62 private:
64 ChartAnimator* m_animator;
65 ChartPresenter* m_presenter;
63 ChartPresenter* m_presenter;
66 Domain* m_domain;
64 Domain* m_domain;
67 };
65 };
@@ -24,7 +24,6
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 "chartanimator_p.h"
28 #include "chartanimation_p.h"
27 #include "chartanimation_p.h"
29 #include "qabstractseries_p.h"
28 #include "qabstractseries_p.h"
30 #include "qareaseries.h"
29 #include "qareaseries.h"
@@ -40,7 +39,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
39
41 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
40 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
42 m_chart(chart),
41 m_chart(chart),
43 m_animator(0),
44 m_dataset(dataset),
42 m_dataset(dataset),
45 m_chartTheme(0),
43 m_chartTheme(0),
46 m_options(QChart::NoAnimation),
44 m_options(QChart::NoAnimation),
@@ -74,7 +72,6 void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain)
74 item->setDomain(domain);
72 item->setDomain(domain);
75
73
76 if(m_options.testFlag(QChart::GridAxisAnimations)){
74 if(m_options.testFlag(QChart::GridAxisAnimations)){
77 item->setAnimator(m_animator);
78 item->setAnimation(new AxisAnimation(item));
75 item->setAnimation(new AxisAnimation(item));
79 }
76 }
80
77
@@ -98,7 +95,6 void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis)
98 ChartAxis* item = m_axisItems.take(axis);
95 ChartAxis* item = m_axisItems.take(axis);
99 Q_ASSERT(item);
96 Q_ASSERT(item);
100 selectVisibleAxis();
97 selectVisibleAxis();
101 if(m_animator) m_animator->removeAnimation(item);
102 item->hide();
98 item->hide();
103 item->disconnect();
99 item->disconnect();
104 QObject::disconnect(this,0,item,0);
100 QObject::disconnect(this,0,item,0);
@@ -125,16 +121,6 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
125 {
121 {
126 Chart* item = m_chartItems.take(series);
122 Chart* item = m_chartItems.take(series);
127 Q_ASSERT(item);
123 Q_ASSERT(item);
128 if(m_animator) {
129 //small hack to handle area animations
130 if(series->type() == QAbstractSeries::SeriesTypeArea){
131 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
132 AreaChartItem* area = static_cast<AreaChartItem*>(item);
133 m_animator->removeAnimation(area->upperLineItem());
134 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
135 }else
136 m_animator->removeAnimation(item);
137 }
138 item->deleteLater();
124 item->deleteLater();
139 }
125 }
140
126
@@ -211,12 +197,7 QChart::ChartTheme ChartPresenter::theme()
211 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
197 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
212 {
198 {
213 if(m_options!=options) {
199 if(m_options!=options) {
214
215 m_options=options;
200 m_options=options;
216
217 if(m_options!=QChart::NoAnimation && !m_animator) {
218 m_animator= new ChartAnimator(this);
219 }
220 resetAllElements();
201 resetAllElements();
221 }
202 }
222
203
@@ -77,7 +77,6 public:
77 ChartPresenter(QChart* chart,ChartDataSet *dataset);
77 ChartPresenter(QChart* chart,ChartDataSet *dataset);
78 virtual ~ChartPresenter();
78 virtual ~ChartPresenter();
79
79
80 ChartAnimator* animator() const { return m_animator; }
81 ChartTheme *chartTheme() const { return m_chartTheme; }
80 ChartTheme *chartTheme() const { return m_chartTheme; }
82 ChartDataSet *dataSet() const { return m_dataset; }
81 ChartDataSet *dataSet() const { return m_dataset; }
83 QGraphicsItem* rootItem() const { return m_chart; }
82 QGraphicsItem* rootItem() const { return m_chart; }
@@ -156,7 +155,6 Q_SIGNALS:
156
155
157 private:
156 private:
158 QChart* m_chart;
157 QChart* m_chart;
159 ChartAnimator* m_animator;
160 ChartDataSet* m_dataset;
158 ChartDataSet* m_dataset;
161 ChartTheme *m_chartTheme;
159 ChartTheme *m_chartTheme;
162 QMap<QAbstractSeries*, Chart*> m_chartItems;
160 QMap<QAbstractSeries*, Chart*> m_chartItems;
@@ -23,7 +23,6
23 #include "linechartitem_p.h"
23 #include "linechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
27
26
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
28
@@ -122,7 +121,6 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
122 Q_Q(QLineSeries);
121 Q_Q(QLineSeries);
123 LineChartItem* line = new LineChartItem(q,presenter);
122 LineChartItem* line = new LineChartItem(q,presenter);
124 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
123 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
125 line->setAnimator(presenter->animator());
126 line->setAnimation(new XYAnimation(line));
124 line->setAnimation(new XYAnimation(line));
127 }
125 }
128 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
126 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
@@ -26,7 +26,7
26 #include "qpieseries_p.h"
26 #include "qpieseries_p.h"
27 #include "chartpresenter_p.h"
27 #include "chartpresenter_p.h"
28 #include "chartdataset_p.h"
28 #include "chartdataset_p.h"
29 #include "chartanimator_p.h"
29 #include "pieanimation_p.h"
30 #include <QPainter>
30 #include <QPainter>
31 #include <QTimer>
31 #include <QTimer>
32
32
@@ -34,7 +34,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
35 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
36 :ChartItem(presenter),
36 :ChartItem(presenter),
37 m_series(series)
37 m_series(series),
38 m_animation(0)
38 {
39 {
39 Q_ASSERT(series);
40 Q_ASSERT(series);
40
41
@@ -58,6 +59,16 PieChartItem::~PieChartItem()
58 // slices deleted automatically through QGraphicsItem
59 // slices deleted automatically through QGraphicsItem
59 }
60 }
60
61
62 void PieChartItem::setAnimation(PieAnimation* animation)
63 {
64 m_animation=animation;
65 }
66
67 ChartAnimation* PieChartItem::animation() const
68 {
69 return m_animation;
70 }
71
61 void PieChartItem::handleGeometryChanged(const QRectF& rect)
72 void PieChartItem::handleGeometryChanged(const QRectF& rect)
62 {
73 {
63 prepareGeometryChange();
74 prepareGeometryChange();
@@ -116,8 +127,9 void PieChartItem::updateLayout()
116 PieSliceItem *sliceItem = m_sliceItems.value(slice);
127 PieSliceItem *sliceItem = m_sliceItems.value(slice);
117 if (sliceItem) {
128 if (sliceItem) {
118 PieSliceData sliceData = updateSliceGeometry(slice);
129 PieSliceData sliceData = updateSliceGeometry(slice);
119 if (animator())
130 if (m_animation){
120 animator()->updateAnimation(this, sliceItem, sliceData);
131 presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData));
132 }
121 else
133 else
122 sliceItem->setLayout(sliceData);
134 sliceItem->setLayout(sliceData);
123 }
135 }
@@ -159,8 +171,8 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
159 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
171 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
160
172
161 PieSliceData sliceData = updateSliceGeometry(slice);
173 PieSliceData sliceData = updateSliceGeometry(slice);
162 if (animator())
174 if (m_animation)
163 animator()->addAnimation(this, sliceItem, sliceData, startupAnimation);
175 presenter()->startAnimation(m_animation->addSlice(sliceItem, sliceData, startupAnimation));
164 else
176 else
165 sliceItem->setLayout(sliceData);
177 sliceItem->setLayout(sliceData);
166 }
178 }
@@ -180,8 +192,8 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
180
192
181 m_sliceItems.remove(slice);
193 m_sliceItems.remove(slice);
182
194
183 if (animator())
195 if (m_animation)
184 animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem
196 presenter()->startAnimation(m_animation->removeSlice(sliceItem)); // animator deletes the PieSliceItem
185 else
197 else
186 delete sliceItem;
198 delete sliceItem;
187 }
199 }
@@ -198,8 +210,8 void PieChartItem::handleSliceChanged()
198
210
199 PieSliceItem *sliceItem = m_sliceItems.value(slice);
211 PieSliceItem *sliceItem = m_sliceItems.value(slice);
200 PieSliceData sliceData = updateSliceGeometry(slice);
212 PieSliceData sliceData = updateSliceGeometry(slice);
201 if (animator())
213 if (m_animation)
202 animator()->updateAnimation(this, sliceItem, sliceData);
214 presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData));
203 else
215 else
204 sliceItem->setLayout(sliceData);
216 sliceItem->setLayout(sliceData);
205
217
@@ -38,6 +38,7 class QGraphicsItem;
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 class QPieSlice;
39 class QPieSlice;
40 class ChartPresenter;
40 class ChartPresenter;
41 class PieAnimation;
41
42
42 class PieChartItem : public ChartItem
43 class PieChartItem : public ChartItem
43 {
44 {
@@ -64,6 +65,9 public Q_SLOTS:
64 void handleSliceChanged();
65 void handleSliceChanged();
65 void handleSeriesVisibleChanged();
66 void handleSeriesVisibleChanged();
66
67
68 void setAnimation(PieAnimation* animation);
69 ChartAnimation* animation() const;
70
67 private:
71 private:
68 PieSliceData updateSliceGeometry(QPieSlice *slice);
72 PieSliceData updateSliceGeometry(QPieSlice *slice);
69
73
@@ -74,6 +78,8 private:
74 QPointF m_pieCenter;
78 QPointF m_pieCenter;
75 qreal m_pieRadius;
79 qreal m_pieRadius;
76 qreal m_donutInnerRadius;
80 qreal m_donutInnerRadius;
81 PieAnimation* m_animation;
82
77 };
83 };
78
84
79 QTCOMMERCIALCHART_END_NAMESPACE
85 QTCOMMERCIALCHART_END_NAMESPACE
@@ -25,9 +25,9
25 #include "pieslicedata_p.h"
25 #include "pieslicedata_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "chartanimator_p.h"
29 #include "legendmarker_p.h"
28 #include "legendmarker_p.h"
30 #include "qabstractaxis.h"
29 #include "qabstractaxis.h"
30 #include "pieanimation_p.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
@@ -823,7 +823,7 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
823 Q_Q(QPieSeries);
823 Q_Q(QPieSeries);
824 PieChartItem* pie = new PieChartItem(q,presenter);
824 PieChartItem* pie = new PieChartItem(q,presenter);
825 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
825 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
826 presenter->animator()->addAnimation(pie);
826 pie->setAnimation(new PieAnimation(pie));
827 }
827 }
828 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
828 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
829 return pie;
829 return pie;
@@ -23,7 +23,6
23 #include "scatterchartitem_p.h"
23 #include "scatterchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
27
26
28 /*!
27 /*!
29 \class QScatterSeries
28 \class QScatterSeries
@@ -252,7 +251,6 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
252 Q_Q(QScatterSeries);
251 Q_Q(QScatterSeries);
253 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
252 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
254 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
253 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
255 scatter->setAnimator(presenter->animator());
256 scatter->setAnimation(new XYAnimation(scatter));
254 scatter->setAnimation(new XYAnimation(scatter));
257 }
255 }
258 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
256 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
@@ -23,7 +23,7
23 #include "splinechartitem_p.h"
23 #include "splinechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "splineanimation_p.h"
27
27
28 /*!
28 /*!
29 \class QSplineSeries
29 \class QSplineSeries
@@ -222,7 +222,6 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
222 Q_Q(QSplineSeries);
222 Q_Q(QSplineSeries);
223 SplineChartItem* spline = new SplineChartItem(q,presenter);
223 SplineChartItem* spline = new SplineChartItem(q,presenter);
224 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
224 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
225 spline->setAnimator(presenter->animator());
226 spline->setAnimation(new SplineAnimation(spline));
225 spline->setAnimation(new SplineAnimation(spline));
227 }
226 }
228
227
@@ -21,7 +21,7
21 #include "splinechartitem_p.h"
21 #include "splinechartitem_p.h"
22 #include "qsplineseries_p.h"
22 #include "qsplineseries_p.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "splineanimation_p.h"
25 #include <QPainter>
25 #include <QPainter>
26 #include <QGraphicsSceneMouseEvent>
26 #include <QGraphicsSceneMouseEvent>
27
27
@@ -56,6 +56,11 void SplineChartItem::setAnimation(SplineAnimation* animation)
56 XYChart::setAnimation(animation);
56 XYChart::setAnimation(animation);
57 }
57 }
58
58
59 ChartAnimation* SplineChartItem::animation() const
60 {
61 return m_animation;
62 }
63
59 void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points)
64 void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points)
60 {
65 {
61 m_controlPoints=points;
66 m_controlPoints=points;
@@ -32,10 +32,11
32
32
33 #include "qsplineseries.h"
33 #include "qsplineseries.h"
34 #include "xychart_p.h"
34 #include "xychart_p.h"
35 #include "splineanimation_p.h"
36
35
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
37
38 class SplineAnimation;
39
39 class SplineChartItem : public XYChart, public QGraphicsItem
40 class SplineChartItem : public XYChart, public QGraphicsItem
40 {
41 {
41 Q_OBJECT
42 Q_OBJECT
@@ -52,7 +53,7 public:
52 QVector<QPointF> controlGeometryPoints() const;
53 QVector<QPointF> controlGeometryPoints() const;
53
54
54 void setAnimation(SplineAnimation* animation);
55 void setAnimation(SplineAnimation* animation);
55 ChartAnimation* animation() const { return m_animation; }
56 ChartAnimation* animation() const;
56
57
57 public Q_SLOTS:
58 public Q_SLOTS:
58 void handleUpdated();
59 void handleUpdated();
@@ -22,12 +22,11
22 #include "qxyseries.h"
22 #include "qxyseries.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "chartanimator_p.h"
26 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "qxymodelmapper.h"
27 #include <QPainter>
27 #include <QPainter>
28 #include <QAbstractItemModel>
28 #include <QAbstractItemModel>
29 #include "qxymodelmapper.h"
29
30 #include <QDebug>
31
30
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
32
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now