From 0a19606ca1b107080e247a6d5054844d77597ba6 2012-07-24 12:11:12 From: Michal Klocek Date: 2012-07-24 12:11:12 Subject: [PATCH] Refactor animator * refactors pie animation handling from animator to animation class * removes animator class and files --- diff --git a/src/animations/animations.pri b/src/animations/animations.pri index 263aa04..bb09727 100644 --- a/src/animations/animations.pri +++ b/src/animations/animations.pri @@ -3,7 +3,6 @@ DEPENDPATH += $$PWD SOURCES += \ $$PWD/axisanimation.cpp \ - $$PWD/chartanimator.cpp \ $$PWD/xyanimation.cpp \ $$PWD/pieanimation.cpp \ $$PWD/piesliceanimation.cpp \ @@ -18,7 +17,6 @@ SOURCES += \ PRIVATE_HEADERS += \ $$PWD/axisanimation_p.h \ - $$PWD/chartanimator_p.h \ $$PWD/chartanimation_p.h \ $$PWD/xyanimation_p.h \ $$PWD/pieanimation_p.h \ diff --git a/src/animations/chartanimator.cpp b/src/animations/chartanimator.cpp deleted file mode 100644 index def9292..0000000 --- a/src/animations/chartanimator.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the Qt Commercial Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "chartanimator_p.h" -#include "axisanimation_p.h" -#include "xyanimation_p.h" -#include "splineanimation_p.h" -#include "xychart_p.h" -#include "pieanimation_p.h" -#include "baranimation_p.h" -#include "abstractbarchartitem_p.h" -#include "stackedbaranimation_p.h" -#include "stackedbarchartitem_p.h" -#include "percentbaranimation_p.h" -#include "percentbarchartitem_p.h" -#include "areachartitem_p.h" -#include "splinechartitem_p.h" -#include "scatterchartitem_p.h" -#include "chartaxis_p.h" -#include - -Q_DECLARE_METATYPE(QVector) -Q_DECLARE_METATYPE(QVector) -Q_DECLARE_METATYPE(QVector) - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -ChartAnimator::ChartAnimator(QObject *parent):QObject(parent) -{ -} - -ChartAnimator::~ChartAnimator() -{ -} -void ChartAnimator::addAnimation(PieChartItem *item) -{ - ChartAnimation *animation = m_animations.value(item); - - if (!animation) { - animation = new PieAnimation(item); - m_animations.insert(item, animation); - } - - item->setAnimator(this); -} - -void ChartAnimator::removeAnimation(Chart *item) -{ - item->setAnimator(0); - m_animations.remove(item); -} - -void ChartAnimator::addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) -{ - PieAnimation *animation = static_cast(m_animations.value(item)); - Q_ASSERT(animation); - animation->addSlice(sliceItem, sliceData, startupAnimation); -} - -void ChartAnimator::removeAnimation(PieChartItem *item, PieSliceItem *sliceItem) -{ - PieAnimation *animation = static_cast(m_animations.value(item)); - Q_ASSERT(animation); - animation->removeSlice(sliceItem); -} - -void ChartAnimator::updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData) -{ - PieAnimation *animation = static_cast(m_animations.value(item)); - Q_ASSERT(animation); - animation->updateValue(sliceItem, sliceData); -} - -#include "moc_chartanimator_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/chartanimator_p.h b/src/animations/chartanimator_p.h deleted file mode 100644 index a8fbc42..0000000 --- a/src/animations/chartanimator_p.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the Qt Commercial Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// W A R N I N G -// ------------- -// -// This file is not part of the QtCommercial Chart API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#ifndef CHARTANIMATOR_P_H -#define CHARTANIMATOR_P_H - -#include "qchartglobal.h" -#include "chartanimation_p.h" -#include "piechartitem_p.h" -#include "abstractbarchartitem_p.h" -#include - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class ChartItem; -class ChartAxis; -class AreaChartItem; -class SplineChartItem; -class ScatterChartItem; -class LineChartItem; -class XYChartItem; -class XYAnimation; - -class ChartAnimator : public QObject -{ - Q_OBJECT -public: - ChartAnimator(QObject *parent = 0); - virtual ~ChartAnimator(); - - void addAnimation(PieChartItem *item); - void removeAnimation(Chart *item); - - void addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool isEmpty); - void removeAnimation(PieChartItem *item, PieSliceItem *sliceItem); - void updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData); - -private: - QMap m_animations; -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif diff --git a/src/animations/pieanimation.cpp b/src/animations/pieanimation.cpp index fbe855b..15d5e44 100644 --- a/src/animations/pieanimation.cpp +++ b/src/animations/pieanimation.cpp @@ -35,7 +35,7 @@ PieAnimation::~PieAnimation() { } -void PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &sliceData) +ChartAnimation* PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &sliceData) { PieSliceAnimation *animation = m_animations.value(sliceItem); Q_ASSERT(animation); @@ -45,10 +45,10 @@ void PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSliceData &slic animation->setDuration(ChartAnimationDuration); animation->setEasingCurve(QEasingCurve::OutQuart); - QTimer::singleShot(0, animation, SLOT(start())); + return animation; } -void PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) +ChartAnimation* PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) { PieSliceAnimation *animation = new PieSliceAnimation(sliceItem); m_animations.insert(sliceItem, animation); @@ -64,10 +64,11 @@ void PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceDa animation->setDuration(ChartAnimationDuration); animation->setEasingCurve(QEasingCurve::OutQuart); - QTimer::singleShot(0, animation, SLOT(start())); + + return animation; } -void PieAnimation::removeSlice(PieSliceItem *sliceItem) +ChartAnimation* PieAnimation::removeSlice(PieSliceItem *sliceItem) { PieSliceAnimation *animation = m_animations.value(sliceItem); Q_ASSERT(animation); @@ -87,7 +88,7 @@ void PieAnimation::removeSlice(PieSliceItem *sliceItem) connect(animation, SIGNAL(finished()), sliceItem, SLOT(deleteLater())); m_animations.remove(sliceItem); - QTimer::singleShot(0, animation, SLOT(start())); + return animation; } void PieAnimation::updateCurrentValue(const QVariant &) diff --git a/src/animations/pieanimation_p.h b/src/animations/pieanimation_p.h index 62cd9e1..c0d5a80 100644 --- a/src/animations/pieanimation_p.h +++ b/src/animations/pieanimation_p.h @@ -45,9 +45,9 @@ class PieAnimation : public ChartAnimation public: PieAnimation(PieChartItem *item); ~PieAnimation(); - void updateValue(PieSliceItem *sliceItem, const PieSliceData &newValue); - void addSlice(PieSliceItem *sliceItem, const PieSliceData &endValue, bool startupAnimation); - void removeSlice(PieSliceItem *sliceItem); + ChartAnimation* updateValue(PieSliceItem *sliceItem, const PieSliceData &newValue); + ChartAnimation* addSlice(PieSliceItem *sliceItem, const PieSliceData &endValue, bool startupAnimation); + ChartAnimation* removeSlice(PieSliceItem *sliceItem); public: // from QVariantAnimation void updateCurrentValue(const QVariant &value); diff --git a/src/animations/piesliceanimation.cpp b/src/animations/piesliceanimation.cpp index 618e5d9..10c770e 100644 --- a/src/animations/piesliceanimation.cpp +++ b/src/animations/piesliceanimation.cpp @@ -58,7 +58,7 @@ QBrush linearPos(QBrush start, QBrush end, qreal pos) } PieSliceAnimation::PieSliceAnimation(PieSliceItem *sliceItem) - :QVariantAnimation(sliceItem), + :ChartAnimation(sliceItem), m_sliceItem(sliceItem) { } diff --git a/src/animations/piesliceanimation_p.h b/src/animations/piesliceanimation_p.h index 2c3b84a..c68023a 100644 --- a/src/animations/piesliceanimation_p.h +++ b/src/animations/piesliceanimation_p.h @@ -30,14 +30,14 @@ #ifndef PIESLICEANIMATION_P_H #define PIESLICEANIMATION_P_H -#include +#include "chartanimation_p.h" #include "piesliceitem_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE class PieChartItem; -class PieSliceAnimation : public QVariantAnimation +class PieSliceAnimation : public ChartAnimation { public: PieSliceAnimation(PieSliceItem *sliceItem); diff --git a/src/areachart/qareaseries.cpp b/src/areachart/qareaseries.cpp index 479d88f..28970f4 100644 --- a/src/areachart/qareaseries.cpp +++ b/src/areachart/qareaseries.cpp @@ -26,7 +26,6 @@ #include "domain_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" #include "qvaluesaxis.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -363,10 +362,8 @@ Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) AreaChartItem* area = new AreaChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - area->upperLineItem()->setAnimator(presenter->animator()); area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); if(q->lowerSeries()) { - area->lowerLineItem()->setAnimator(presenter->animator()); area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); } } diff --git a/src/axis/chartaxis.cpp b/src/axis/chartaxis.cpp index e8aa6ba..60356ec 100644 --- a/src/axis/chartaxis.cpp +++ b/src/axis/chartaxis.cpp @@ -22,7 +22,6 @@ #include "qabstractaxis.h" #include "qabstractaxis_p.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" #include "domain_p.h" #include #include diff --git a/src/axis/datetimeaxis/chartdatetimeaxisx.cpp b/src/axis/datetimeaxis/chartdatetimeaxisx.cpp index 95865e5..fab4c00 100644 --- a/src/axis/datetimeaxis/chartdatetimeaxisx.cpp +++ b/src/axis/datetimeaxis/chartdatetimeaxisx.cpp @@ -19,15 +19,13 @@ ****************************************************************************/ #include "chartdatetimeaxisx_p.h" -#include "qabstractaxis.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" #include "qdatetimeaxis.h" #include -#include -#include -#include #include +#include +#include + static int label_padding = 5; diff --git a/src/axis/datetimeaxis/chartdatetimeaxisy.cpp b/src/axis/datetimeaxis/chartdatetimeaxisy.cpp index 439c501..be72e28 100644 --- a/src/axis/datetimeaxis/chartdatetimeaxisy.cpp +++ b/src/axis/datetimeaxis/chartdatetimeaxisy.cpp @@ -19,15 +19,13 @@ ****************************************************************************/ #include "chartdatetimeaxisy_p.h" -#include "qabstractaxis.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" #include "qdatetimeaxis.h" #include -#include #include -#include #include +#include + static int label_padding = 5; diff --git a/src/axis/intervalsaxis/chartintervalsaxisx.cpp b/src/axis/intervalsaxis/chartintervalsaxisx.cpp index a041ab6..b0794f0 100644 --- a/src/axis/intervalsaxis/chartintervalsaxisx.cpp +++ b/src/axis/intervalsaxis/chartintervalsaxisx.cpp @@ -19,14 +19,12 @@ ****************************************************************************/ #include "chartintervalsaxisx_p.h" +#include "qintervalsaxis.h" #include "qabstractaxis.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" #include -#include #include -#include -#include +#include static int label_padding = 5; diff --git a/src/axis/intervalsaxis/chartintervalsaxisy.cpp b/src/axis/intervalsaxis/chartintervalsaxisy.cpp index 0a952b8..8c31406 100644 --- a/src/axis/intervalsaxis/chartintervalsaxisy.cpp +++ b/src/axis/intervalsaxis/chartintervalsaxisy.cpp @@ -19,14 +19,13 @@ ****************************************************************************/ #include "chartintervalsaxisy_p.h" +#include "qintervalsaxis.h" #include "qabstractaxis.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" #include -#include #include -#include -#include +#include + static int label_padding = 5; diff --git a/src/axis/valuesaxis/chartvaluesaxisx.cpp b/src/axis/valuesaxis/chartvaluesaxisx.cpp index 77bc5fa..6a4d3fc 100644 --- a/src/axis/valuesaxis/chartvaluesaxisx.cpp +++ b/src/axis/valuesaxis/chartvaluesaxisx.cpp @@ -21,12 +21,10 @@ #include "chartvaluesaxisx_p.h" #include "qabstractaxis.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" #include "qvaluesaxis.h" #include -#include #include -#include +#include static int label_padding = 5; diff --git a/src/axis/valuesaxis/chartvaluesaxisy.cpp b/src/axis/valuesaxis/chartvaluesaxisy.cpp index a3be892..2a623e8 100644 --- a/src/axis/valuesaxis/chartvaluesaxisy.cpp +++ b/src/axis/valuesaxis/chartvaluesaxisy.cpp @@ -21,12 +21,10 @@ #include "chartvaluesaxisy_p.h" #include "qabstractaxis.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" #include "qvaluesaxis.h" #include -#include #include -#include +#include static int label_padding = 5; diff --git a/src/barchart/abstractbarchartitem.cpp b/src/barchart/abstractbarchartitem.cpp index 3ce5e82..1e22d26 100644 --- a/src/barchart/abstractbarchartitem.cpp +++ b/src/barchart/abstractbarchartitem.cpp @@ -26,7 +26,7 @@ #include "qabstractbarseries_p.h" #include "qchart.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" +#include "charttheme_p.h" #include "abstractbaranimation_p.h" #include "chartdataset_p.h" #include diff --git a/src/barchart/horizontal/bar/qhorizontalbarseries.cpp b/src/barchart/horizontal/bar/qhorizontalbarseries.cpp index 2e5a68f..26cf632 100644 --- a/src/barchart/horizontal/bar/qhorizontalbarseries.cpp +++ b/src/barchart/horizontal/bar/qhorizontalbarseries.cpp @@ -107,7 +107,6 @@ Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter) HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - bar->setAnimator(presenter->animator()); bar->setAnimation(new HorizontalBarAnimation(bar)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); diff --git a/src/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp b/src/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp index 489502a..5d95f5c 100644 --- a/src/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp +++ b/src/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp @@ -55,7 +55,6 @@ Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presen HorizontalPercentBarChartItem* bar = new HorizontalPercentBarChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - bar->setAnimator(presenter->animator()); bar->setAnimation(new HorizontalPercentBarAnimation(bar)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); diff --git a/src/barchart/horizontal/stacked/qhorizontalstackedbarseries.cpp b/src/barchart/horizontal/stacked/qhorizontalstackedbarseries.cpp index 7bd1dce..acd5a0c 100644 --- a/src/barchart/horizontal/stacked/qhorizontalstackedbarseries.cpp +++ b/src/barchart/horizontal/stacked/qhorizontalstackedbarseries.cpp @@ -56,7 +56,6 @@ Chart* QHorizontalStackedBarSeriesPrivate::createGraphics(ChartPresenter* presen HorizontalStackedBarChartItem* bar = new HorizontalStackedBarChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - bar->setAnimator(presenter->animator()); bar->setAnimation(new HorizontalStackedBarAnimation(bar)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); diff --git a/src/barchart/vertical/bar/qbarseries.cpp b/src/barchart/vertical/bar/qbarseries.cpp index 82b8159..061a002 100644 --- a/src/barchart/vertical/bar/qbarseries.cpp +++ b/src/barchart/vertical/bar/qbarseries.cpp @@ -23,7 +23,6 @@ #include "barchartitem_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" #include "baranimation_p.h" #include "qvaluesaxis.h" #include "qbarcategoriesaxis.h" @@ -111,7 +110,6 @@ Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) BarChartItem* bar = new BarChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - bar->setAnimator(presenter->animator()); bar->setAnimation(new BarAnimation(bar)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); diff --git a/src/barchart/vertical/percent/percentbarchartitem.cpp b/src/barchart/vertical/percent/percentbarchartitem.cpp index ad26814..d1a0c6a 100644 --- a/src/barchart/vertical/percent/percentbarchartitem.cpp +++ b/src/barchart/vertical/percent/percentbarchartitem.cpp @@ -22,7 +22,6 @@ #include "bar_p.h" #include "qabstractbarseries_p.h" #include "qbarset.h" -#include "chartanimator_p.h" #include "qbarset_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE diff --git a/src/barchart/vertical/percent/qpercentbarseries.cpp b/src/barchart/vertical/percent/qpercentbarseries.cpp index 5e6ce59..c72a319 100644 --- a/src/barchart/vertical/percent/qpercentbarseries.cpp +++ b/src/barchart/vertical/percent/qpercentbarseries.cpp @@ -23,7 +23,6 @@ #include "percentbarchartitem_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" #include "qvaluesaxis.h" #include "percentbaranimation_p.h" @@ -110,7 +109,6 @@ Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - bar->setAnimator(presenter->animator()); bar->setAnimation(new PercentBarAnimation(bar)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); diff --git a/src/barchart/vertical/stacked/qstackedbarseries.cpp b/src/barchart/vertical/stacked/qstackedbarseries.cpp index 1e9e417..ab8f051 100644 --- a/src/barchart/vertical/stacked/qstackedbarseries.cpp +++ b/src/barchart/vertical/stacked/qstackedbarseries.cpp @@ -23,7 +23,6 @@ #include "stackedbarchartitem_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" #include "qvaluesaxis.h" #include "stackedbaranimation_p.h" @@ -111,7 +110,6 @@ Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - bar->setAnimator(presenter->animator()); bar->setAnimation(new StackedBarAnimation(bar)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); diff --git a/src/barchart/vertical/stacked/stackedbarchartitem.cpp b/src/barchart/vertical/stacked/stackedbarchartitem.cpp index ab1095f..111b668 100644 --- a/src/barchart/vertical/stacked/stackedbarchartitem.cpp +++ b/src/barchart/vertical/stacked/stackedbarchartitem.cpp @@ -23,7 +23,6 @@ #include "qbarset_p.h" #include "qabstractbarseries_p.h" #include "qbarset.h" -#include "chartanimator_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE diff --git a/src/chart.cpp b/src/chart.cpp index 89b3a47..9e06e76 100644 --- a/src/chart.cpp +++ b/src/chart.cpp @@ -25,23 +25,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Chart::Chart(ChartPresenter *presenter):QObject(presenter), - m_animator(0), m_presenter(presenter), m_domain(0) { } -void Chart::setAnimator(ChartAnimator* animator) -{ - m_animator=animator; -} - -ChartAnimator* Chart::animator() const -{ - return m_animator; -} - - void Chart::setPresenter(ChartPresenter *presenter) { m_presenter=presenter; diff --git a/src/chart_p.h b/src/chart_p.h index 40bbaf0..5a2fae3 100644 --- a/src/chart_p.h +++ b/src/chart_p.h @@ -51,17 +51,15 @@ public Q_SLOTS: virtual void handleGeometryChanged(const QRectF& rect); virtual void handleDomainChanged(qreal minX,qreal maxX,qreal minY,qreal maxY); virtual void handleDomainUpdated(); + virtual ChartAnimation* animation() const { return 0; }; - void setAnimator(ChartAnimator* animator); - ChartAnimator* animator() const; void setPresenter(ChartPresenter *presenter); ChartPresenter* presenter() const; void setDomain(Domain *domain); Domain* domain() const; - virtual ChartAnimation* animation() const { return 0; }; + private: - ChartAnimator* m_animator; ChartPresenter* m_presenter; Domain* m_domain; }; diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index d231769..cca7e21 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -24,7 +24,6 @@ #include "qabstractaxis_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" #include "chartanimation_p.h" #include "qabstractseries_p.h" #include "qareaseries.h" @@ -40,7 +39,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), m_chart(chart), -m_animator(0), m_dataset(dataset), m_chartTheme(0), m_options(QChart::NoAnimation), @@ -74,7 +72,6 @@ void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) item->setDomain(domain); if(m_options.testFlag(QChart::GridAxisAnimations)){ - item->setAnimator(m_animator); item->setAnimation(new AxisAnimation(item)); } @@ -98,7 +95,6 @@ void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) ChartAxis* item = m_axisItems.take(axis); Q_ASSERT(item); selectVisibleAxis(); - if(m_animator) m_animator->removeAnimation(item); item->hide(); item->disconnect(); QObject::disconnect(this,0,item,0); @@ -125,16 +121,6 @@ void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) { Chart* item = m_chartItems.take(series); Q_ASSERT(item); - if(m_animator) { - //small hack to handle area animations - if(series->type() == QAbstractSeries::SeriesTypeArea){ - QAreaSeries* areaSeries = static_cast(series); - AreaChartItem* area = static_cast(item); - m_animator->removeAnimation(area->upperLineItem()); - if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); - }else - m_animator->removeAnimation(item); - } item->deleteLater(); } @@ -211,12 +197,7 @@ QChart::ChartTheme ChartPresenter::theme() void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) { if(m_options!=options) { - m_options=options; - - if(m_options!=QChart::NoAnimation && !m_animator) { - m_animator= new ChartAnimator(this); - } resetAllElements(); } diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h index 283f7a0..058ea7d 100644 --- a/src/chartpresenter_p.h +++ b/src/chartpresenter_p.h @@ -77,7 +77,6 @@ public: ChartPresenter(QChart* chart,ChartDataSet *dataset); virtual ~ChartPresenter(); - ChartAnimator* animator() const { return m_animator; } ChartTheme *chartTheme() const { return m_chartTheme; } ChartDataSet *dataSet() const { return m_dataset; } QGraphicsItem* rootItem() const { return m_chart; } @@ -156,7 +155,6 @@ Q_SIGNALS: private: QChart* m_chart; - ChartAnimator* m_animator; ChartDataSet* m_dataset; ChartTheme *m_chartTheme; QMap m_chartItems; diff --git a/src/linechart/qlineseries.cpp b/src/linechart/qlineseries.cpp index 70f52dd..20d8747 100644 --- a/src/linechart/qlineseries.cpp +++ b/src/linechart/qlineseries.cpp @@ -23,7 +23,6 @@ #include "linechartitem_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -122,7 +121,6 @@ Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter) Q_Q(QLineSeries); LineChartItem* line = new LineChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - line->setAnimator(presenter->animator()); line->setAnimation(new XYAnimation(line)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); diff --git a/src/piechart/piechartitem.cpp b/src/piechart/piechartitem.cpp index f324a13..fd13cc6 100644 --- a/src/piechart/piechartitem.cpp +++ b/src/piechart/piechartitem.cpp @@ -26,7 +26,7 @@ #include "qpieseries_p.h" #include "chartpresenter_p.h" #include "chartdataset_p.h" -#include "chartanimator_p.h" +#include "pieanimation_p.h" #include #include @@ -34,7 +34,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter) :ChartItem(presenter), - m_series(series) + m_series(series), + m_animation(0) { Q_ASSERT(series); @@ -58,6 +59,16 @@ PieChartItem::~PieChartItem() // slices deleted automatically through QGraphicsItem } +void PieChartItem::setAnimation(PieAnimation* animation) +{ + m_animation=animation; +} + +ChartAnimation* PieChartItem::animation() const +{ + return m_animation; +} + void PieChartItem::handleGeometryChanged(const QRectF& rect) { prepareGeometryChange(); @@ -116,8 +127,9 @@ void PieChartItem::updateLayout() PieSliceItem *sliceItem = m_sliceItems.value(slice); if (sliceItem) { PieSliceData sliceData = updateSliceGeometry(slice); - if (animator()) - animator()->updateAnimation(this, sliceItem, sliceData); + if (m_animation){ + presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); + } else sliceItem->setLayout(sliceData); } @@ -159,8 +171,8 @@ void PieChartItem::handleSlicesAdded(QList slices) connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool))); PieSliceData sliceData = updateSliceGeometry(slice); - if (animator()) - animator()->addAnimation(this, sliceItem, sliceData, startupAnimation); + if (m_animation) + presenter()->startAnimation(m_animation->addSlice(sliceItem, sliceData, startupAnimation)); else sliceItem->setLayout(sliceData); } @@ -180,8 +192,8 @@ void PieChartItem::handleSlicesRemoved(QList slices) m_sliceItems.remove(slice); - if (animator()) - animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem + if (m_animation) + presenter()->startAnimation(m_animation->removeSlice(sliceItem)); // animator deletes the PieSliceItem else delete sliceItem; } @@ -198,8 +210,8 @@ void PieChartItem::handleSliceChanged() PieSliceItem *sliceItem = m_sliceItems.value(slice); PieSliceData sliceData = updateSliceGeometry(slice); - if (animator()) - animator()->updateAnimation(this, sliceItem, sliceData); + if (m_animation) + presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); else sliceItem->setLayout(sliceData); diff --git a/src/piechart/piechartitem_p.h b/src/piechart/piechartitem_p.h index 3552f38..fc2766b 100644 --- a/src/piechart/piechartitem_p.h +++ b/src/piechart/piechartitem_p.h @@ -38,6 +38,7 @@ class QGraphicsItem; QTCOMMERCIALCHART_BEGIN_NAMESPACE class QPieSlice; class ChartPresenter; +class PieAnimation; class PieChartItem : public ChartItem { @@ -64,6 +65,9 @@ public Q_SLOTS: void handleSliceChanged(); void handleSeriesVisibleChanged(); + void setAnimation(PieAnimation* animation); + ChartAnimation* animation() const; + private: PieSliceData updateSliceGeometry(QPieSlice *slice); @@ -74,6 +78,8 @@ private: QPointF m_pieCenter; qreal m_pieRadius; qreal m_donutInnerRadius; + PieAnimation* m_animation; + }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index a428bf9..4d8250b 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -25,9 +25,9 @@ #include "pieslicedata_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" #include "legendmarker_p.h" #include "qabstractaxis.h" +#include "pieanimation_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -823,7 +823,7 @@ Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) Q_Q(QPieSeries); PieChartItem* pie = new PieChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - presenter->animator()->addAnimation(pie); + pie->setAnimation(new PieAnimation(pie)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); return pie; diff --git a/src/scatterchart/qscatterseries.cpp b/src/scatterchart/qscatterseries.cpp index c00f7cb..b45fe07 100644 --- a/src/scatterchart/qscatterseries.cpp +++ b/src/scatterchart/qscatterseries.cpp @@ -23,7 +23,6 @@ #include "scatterchartitem_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" /*! \class QScatterSeries @@ -252,7 +251,6 @@ Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) Q_Q(QScatterSeries); ScatterChartItem *scatter = new ScatterChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - scatter->setAnimator(presenter->animator()); scatter->setAnimation(new XYAnimation(scatter)); } presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); diff --git a/src/splinechart/qsplineseries.cpp b/src/splinechart/qsplineseries.cpp index fd90712..0459678 100644 --- a/src/splinechart/qsplineseries.cpp +++ b/src/splinechart/qsplineseries.cpp @@ -23,7 +23,7 @@ #include "splinechartitem_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "chartanimator_p.h" +#include "splineanimation_p.h" /*! \class QSplineSeries @@ -222,7 +222,6 @@ Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter) Q_Q(QSplineSeries); SplineChartItem* spline = new SplineChartItem(q,presenter); if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { - spline->setAnimator(presenter->animator()); spline->setAnimation(new SplineAnimation(spline)); } diff --git a/src/splinechart/splinechartitem.cpp b/src/splinechart/splinechartitem.cpp index 458c136..436ec84 100644 --- a/src/splinechart/splinechartitem.cpp +++ b/src/splinechart/splinechartitem.cpp @@ -21,7 +21,7 @@ #include "splinechartitem_p.h" #include "qsplineseries_p.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" +#include "splineanimation_p.h" #include #include @@ -56,6 +56,11 @@ void SplineChartItem::setAnimation(SplineAnimation* animation) XYChart::setAnimation(animation); } +ChartAnimation* SplineChartItem::animation() const +{ + return m_animation; +} + void SplineChartItem::setControlGeometryPoints(QVector& points) { m_controlPoints=points; diff --git a/src/splinechart/splinechartitem_p.h b/src/splinechart/splinechartitem_p.h index a3fa387..e588025 100644 --- a/src/splinechart/splinechartitem_p.h +++ b/src/splinechart/splinechartitem_p.h @@ -32,10 +32,11 @@ #include "qsplineseries.h" #include "xychart_p.h" -#include "splineanimation_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE +class SplineAnimation; + class SplineChartItem : public XYChart, public QGraphicsItem { Q_OBJECT @@ -52,7 +53,7 @@ public: QVector controlGeometryPoints() const; void setAnimation(SplineAnimation* animation); - ChartAnimation* animation() const { return m_animation; } + ChartAnimation* animation() const; public Q_SLOTS: void handleUpdated(); diff --git a/src/xychart/xychart.cpp b/src/xychart/xychart.cpp index 2c2ae1f..dc8b365 100644 --- a/src/xychart/xychart.cpp +++ b/src/xychart/xychart.cpp @@ -22,12 +22,11 @@ #include "qxyseries.h" #include "qxyseries_p.h" #include "chartpresenter_p.h" -#include "chartanimator_p.h" #include "domain_p.h" +#include "qxymodelmapper.h" #include #include -#include "qxymodelmapper.h" -#include + QTCOMMERCIALCHART_BEGIN_NAMESPACE