From 97642714ab1ee0484993593ad2de67a2053a9a57 Mon Sep 17 00:00:00 2001 From: Titta Heikkala Date: Fri, 11 Sep 2015 08:50:08 +0300 Subject: Added possibility to set duration and easing curve for chart animation Changed the animation API so that it's possible to change the duration and easing curve of the chart animation. Change-Id: I2ab3e0664a7f30bc2bb7085daa1d97181edb90ba Task-number: QTRD-3496 Reviewed-by: Miikka Heikkinen --- src/charts/animations/axisanimation.cpp | 6 ++-- src/charts/animations/axisanimation_p.h | 2 +- src/charts/animations/baranimation.cpp | 6 ++-- src/charts/animations/baranimation_p.h | 2 +- src/charts/animations/boxplotanimation.cpp | 9 ++++-- src/charts/animations/boxplotanimation_p.h | 4 ++- src/charts/animations/boxwhiskersanimation.cpp | 7 +++-- src/charts/animations/boxwhiskersanimation_p.h | 3 +- src/charts/animations/pieanimation.cpp | 16 +++++----- src/charts/animations/pieanimation_p.h | 4 ++- src/charts/animations/scatteranimation.cpp | 4 +-- src/charts/animations/scatteranimation_p.h | 2 +- src/charts/animations/splineanimation.cpp | 4 +-- src/charts/animations/splineanimation_p.h | 2 +- src/charts/animations/xyanimation.cpp | 6 ++-- src/charts/animations/xyanimation_p.h | 2 +- src/charts/areachart/qareaseries.cpp | 11 ++++--- src/charts/areachart/qareaseries_p.h | 3 +- src/charts/axis/qabstractaxis.cpp | 5 ++-- src/charts/axis/qabstractaxis_p.h | 3 +- src/charts/barchart/qabstractbarseries.cpp | 7 +++-- src/charts/barchart/qabstractbarseries_p.h | 2 +- src/charts/boxplotchart/qboxplotseries.cpp | 10 +++++-- src/charts/boxplotchart/qboxplotseries_p.h | 2 +- src/charts/chartpresenter.cpp | 35 +++++++++++++++++++--- src/charts/chartpresenter_p.h | 6 ++++ src/charts/piechart/qpieseries.cpp | 7 +++-- src/charts/piechart/qpieseries_p.h | 3 +- src/charts/qabstractseries.cpp | 5 +++- src/charts/qabstractseries_p.h | 3 +- src/charts/qchart.cpp | 30 +++++++++++++++++++ src/charts/qchart.h | 7 +++++ src/charts/scatterchart/qscatterseries.cpp | 7 +++-- src/charts/scatterchart/qscatterseries_p.h | 3 +- src/charts/splinechart/qsplineseries.cpp | 7 +++-- src/charts/splinechart/qsplineseries_p.h | 3 +- src/charts/xychart/qxyseries.cpp | 7 +++-- src/charts/xychart/qxyseries_p.h | 3 +- src/chartsqml2/declarativechart.cpp | 35 ++++++++++++++++++++++ src/chartsqml2/declarativechart.h | 8 +++++ src/chartsqml2/plugins.qmltypes | 12 ++++++++ tests/auto/qchart/tst_qchart.cpp | 29 ++++++++++++++++++ tests/auto/qml-qtquicktest/tst_chartview.qml | 2 ++ .../qml/qmlchartproperties/Chart.qml | 8 +++-- .../qmlchartproperties/ChartEditorProperties.qml | 20 +++++++++++++ 45 files changed, 287 insertions(+), 75 deletions(-) diff --git a/src/charts/animations/axisanimation.cpp b/src/charts/animations/axisanimation.cpp index 1be6becd..a9900aa6 100644 --- a/src/charts/animations/axisanimation.cpp +++ b/src/charts/animations/axisanimation.cpp @@ -25,13 +25,13 @@ Q_DECLARE_METATYPE(QVector) QT_CHARTS_BEGIN_NAMESPACE -AxisAnimation::AxisAnimation(ChartAxisElement *axis) +AxisAnimation::AxisAnimation(ChartAxisElement *axis, int duration, QEasingCurve &curve) : ChartAnimation(axis), m_axis(axis), m_type(DefaultAnimation) { - setDuration(ChartAnimationDuration); - setEasingCurve(QEasingCurve::OutQuart); + setDuration(duration); + setEasingCurve(curve); } AxisAnimation::~AxisAnimation() diff --git a/src/charts/animations/axisanimation_p.h b/src/charts/animations/axisanimation_p.h index 263de3a4..54b7346f 100644 --- a/src/charts/animations/axisanimation_p.h +++ b/src/charts/animations/axisanimation_p.h @@ -39,7 +39,7 @@ class AxisAnimation: public ChartAnimation { public: enum Animation { DefaultAnimation, ZoomOutAnimation, ZoomInAnimation, MoveForwardAnimation, MoveBackwordAnimation}; - AxisAnimation(ChartAxisElement *axis); + AxisAnimation(ChartAxisElement *axis, int duration, QEasingCurve &curve); ~AxisAnimation(); void setAnimationType(Animation type); void setAnimationPoint(const QPointF &point); diff --git a/src/charts/animations/baranimation.cpp b/src/charts/animations/baranimation.cpp index cd5764c6..a49210ce 100644 --- a/src/charts/animations/baranimation.cpp +++ b/src/charts/animations/baranimation.cpp @@ -23,12 +23,12 @@ Q_DECLARE_METATYPE(QVector) QT_CHARTS_BEGIN_NAMESPACE -BarAnimation::BarAnimation(AbstractBarChartItem *item) +BarAnimation::BarAnimation(AbstractBarChartItem *item, int duration, QEasingCurve &curve) : ChartAnimation(item), m_item(item) { - setDuration(ChartAnimationDuration); - setEasingCurve(QEasingCurve::OutQuart); + setDuration(duration); + setEasingCurve(curve); } BarAnimation::~BarAnimation() diff --git a/src/charts/animations/baranimation_p.h b/src/charts/animations/baranimation_p.h index 9fd79911..3b054165 100644 --- a/src/charts/animations/baranimation_p.h +++ b/src/charts/animations/baranimation_p.h @@ -39,7 +39,7 @@ class BarAnimation : public ChartAnimation Q_OBJECT public: - BarAnimation(AbstractBarChartItem *item); + BarAnimation(AbstractBarChartItem *item, int duration, QEasingCurve &curve); ~BarAnimation(); public: // from QVariantAnimation diff --git a/src/charts/animations/boxplotanimation.cpp b/src/charts/animations/boxplotanimation.cpp index 7d8e692d..c68ad029 100644 --- a/src/charts/animations/boxplotanimation.cpp +++ b/src/charts/animations/boxplotanimation.cpp @@ -23,9 +23,11 @@ QT_CHARTS_BEGIN_NAMESPACE -BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item) +BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item, int duration, QEasingCurve &curve) : QObject(item), - m_item(item) + m_item(item), + m_animationDuration(duration), + m_animationCurve(curve) { } @@ -37,7 +39,7 @@ void BoxPlotAnimation::addBox(BoxWhiskers *box) { BoxWhiskersAnimation *animation = m_animations.value(box); if (!animation) { - animation = new BoxWhiskersAnimation(box, this); + animation = new BoxWhiskersAnimation(box, this, m_animationDuration, m_animationCurve); m_animations.insert(box, animation); BoxWhiskersData start; start.m_lowerExtreme = box->m_data.m_median; @@ -46,6 +48,7 @@ void BoxPlotAnimation::addBox(BoxWhiskers *box) start.m_upperQuartile = box->m_data.m_median; start.m_upperExtreme = box->m_data.m_median; animation->setup(start, box->m_data); + } else { animation->stop(); animation->setEndData(box->m_data); diff --git a/src/charts/animations/boxplotanimation_p.h b/src/charts/animations/boxplotanimation_p.h index f2866f8d..b9630f3f 100644 --- a/src/charts/animations/boxplotanimation_p.h +++ b/src/charts/animations/boxplotanimation_p.h @@ -41,7 +41,7 @@ class BoxPlotAnimation : public QObject { Q_OBJECT public: - BoxPlotAnimation(BoxPlotChartItem *item); + BoxPlotAnimation(BoxPlotChartItem *item, int duration, QEasingCurve &curve); ~BoxPlotAnimation(); void addBox(BoxWhiskers *box); @@ -55,6 +55,8 @@ public: protected: BoxPlotChartItem *m_item; QHash m_animations; + int m_animationDuration; + QEasingCurve m_animationCurve; }; QT_CHARTS_END_NAMESPACE diff --git a/src/charts/animations/boxwhiskersanimation.cpp b/src/charts/animations/boxwhiskersanimation.cpp index 24369d8d..d1774671 100644 --- a/src/charts/animations/boxwhiskersanimation.cpp +++ b/src/charts/animations/boxwhiskersanimation.cpp @@ -27,14 +27,15 @@ Q_DECLARE_METATYPE(qreal) QT_CHARTS_BEGIN_NAMESPACE -BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation) +BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation, + int duration, QEasingCurve &curve) : ChartAnimation(box), m_box(box), m_changeAnimation(false), m_boxPlotAnimation(boxPlotAnimation) { - setDuration(ChartAnimationDuration); - setEasingCurve(QEasingCurve::OutQuart); + setDuration(duration); + setEasingCurve(curve); } BoxWhiskersAnimation::~BoxWhiskersAnimation() diff --git a/src/charts/animations/boxwhiskersanimation_p.h b/src/charts/animations/boxwhiskersanimation_p.h index 9cebe20e..4231afde 100644 --- a/src/charts/animations/boxwhiskersanimation_p.h +++ b/src/charts/animations/boxwhiskersanimation_p.h @@ -42,7 +42,8 @@ class BoxWhiskersAnimation : public ChartAnimation Q_OBJECT public: - BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation); + BoxWhiskersAnimation(BoxWhiskers *box, BoxPlotAnimation *boxPlotAnimation, int duration, + QEasingCurve &curve); ~BoxWhiskersAnimation(); public: // from QVariantAnimation diff --git a/src/charts/animations/pieanimation.cpp b/src/charts/animations/pieanimation.cpp index c513a663..5b974d88 100644 --- a/src/charts/animations/pieanimation.cpp +++ b/src/charts/animations/pieanimation.cpp @@ -22,9 +22,11 @@ QT_CHARTS_BEGIN_NAMESPACE -PieAnimation::PieAnimation(PieChartItem *item) +PieAnimation::PieAnimation(PieChartItem *item, int duration, QEasingCurve &curve) : ChartAnimation(item), - m_item(item) + m_item(item), + m_animationDuration(duration), + m_animationCurve(curve) { } @@ -37,14 +39,14 @@ ChartAnimation *PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSlic PieSliceAnimation *animation = m_animations.value(sliceItem); if (!animation) { animation = new PieSliceAnimation(sliceItem); + animation->setDuration(m_animationDuration); + animation->setEasingCurve(m_animationCurve); m_animations.insert(sliceItem, animation); } else { animation->stop(); } animation->updateValue(sliceData); - animation->setDuration(ChartAnimationDuration); - animation->setEasingCurve(QEasingCurve::OutQuart); return animation; } @@ -52,6 +54,8 @@ ChartAnimation *PieAnimation::updateValue(PieSliceItem *sliceItem, const PieSlic ChartAnimation *PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) { PieSliceAnimation *animation = new PieSliceAnimation(sliceItem); + animation->setDuration(m_animationDuration); + animation->setEasingCurve(m_animationCurve); m_animations.insert(sliceItem, animation); PieSliceData startValue = sliceData; @@ -66,8 +70,6 @@ ChartAnimation *PieAnimation::addSlice(PieSliceItem *sliceItem, const PieSliceDa startValue.m_radius = sliceData.m_holeRadius; animation->setValue(startValue, sliceData); - animation->setDuration(ChartAnimationDuration); - animation->setEasingCurve(QEasingCurve::OutQuart); return animation; } @@ -88,8 +90,6 @@ ChartAnimation *PieAnimation::removeSlice(PieSliceItem *sliceItem) endValue.m_isLabelVisible = false; animation->updateValue(endValue); - animation->setDuration(ChartAnimationDuration); - animation->setEasingCurve(QEasingCurve::OutQuart); // PieSliceItem is the parent of PieSliceAnimation so the animation will be deleted as well.. connect(animation, SIGNAL(finished()), sliceItem, SLOT(deleteLater())); diff --git a/src/charts/animations/pieanimation_p.h b/src/charts/animations/pieanimation_p.h index e0da8f1e..02ea881f 100644 --- a/src/charts/animations/pieanimation_p.h +++ b/src/charts/animations/pieanimation_p.h @@ -41,7 +41,7 @@ class PieAnimation : public ChartAnimation Q_OBJECT public: - PieAnimation(PieChartItem *item); + PieAnimation(PieChartItem *item, int duration, QEasingCurve &curve); ~PieAnimation(); ChartAnimation *updateValue(PieSliceItem *sliceItem, const PieSliceData &newValue); ChartAnimation *addSlice(PieSliceItem *sliceItem, const PieSliceData &endValue, bool startupAnimation); @@ -53,6 +53,8 @@ public: // from QVariantAnimation private: PieChartItem *m_item; QHash m_animations; + int m_animationDuration; + QEasingCurve m_animationCurve; }; QT_CHARTS_END_NAMESPACE diff --git a/src/charts/animations/scatteranimation.cpp b/src/charts/animations/scatteranimation.cpp index 134ef1ef..3a9dc445 100644 --- a/src/charts/animations/scatteranimation.cpp +++ b/src/charts/animations/scatteranimation.cpp @@ -22,8 +22,8 @@ QT_CHARTS_BEGIN_NAMESPACE -ScatterAnimation::ScatterAnimation(ScatterChartItem *item) - : XYAnimation(item) +ScatterAnimation::ScatterAnimation(ScatterChartItem *item, int duration, QEasingCurve &curve) + : XYAnimation(item, duration, curve) { } diff --git a/src/charts/animations/scatteranimation_p.h b/src/charts/animations/scatteranimation_p.h index d6edebbd..4d19c9fd 100644 --- a/src/charts/animations/scatteranimation_p.h +++ b/src/charts/animations/scatteranimation_p.h @@ -36,7 +36,7 @@ class ScatterChartItem; class ScatterAnimation : public XYAnimation { public: - ScatterAnimation(ScatterChartItem *item); + ScatterAnimation(ScatterChartItem *item, int duration, QEasingCurve &curve); ~ScatterAnimation(); protected: diff --git a/src/charts/animations/splineanimation.cpp b/src/charts/animations/splineanimation.cpp index 30cc4388..298d926a 100644 --- a/src/charts/animations/splineanimation.cpp +++ b/src/charts/animations/splineanimation.cpp @@ -25,8 +25,8 @@ Q_DECLARE_METATYPE(SplineVector) QT_CHARTS_BEGIN_NAMESPACE -SplineAnimation::SplineAnimation(SplineChartItem *item) - : XYAnimation(item), +SplineAnimation::SplineAnimation(SplineChartItem *item, int duration, QEasingCurve &curve) + : XYAnimation(item, duration, curve), m_item(item), m_valid(false) { diff --git a/src/charts/animations/splineanimation_p.h b/src/charts/animations/splineanimation_p.h index 26aacb8a..7ea3492b 100644 --- a/src/charts/animations/splineanimation_p.h +++ b/src/charts/animations/splineanimation_p.h @@ -39,7 +39,7 @@ class SplineChartItem; class SplineAnimation : public XYAnimation { public: - SplineAnimation(SplineChartItem *item); + SplineAnimation(SplineChartItem *item, int duration, QEasingCurve &curve); ~SplineAnimation(); void setup(QVector &oldPoints, QVector &newPoints, QVector &oldContorlPoints, QVector &newControlPoints, int index = -1); diff --git a/src/charts/animations/xyanimation.cpp b/src/charts/animations/xyanimation.cpp index f7399567..6f422d19 100644 --- a/src/charts/animations/xyanimation.cpp +++ b/src/charts/animations/xyanimation.cpp @@ -24,15 +24,15 @@ Q_DECLARE_METATYPE(QVector) QT_CHARTS_BEGIN_NAMESPACE -XYAnimation::XYAnimation(XYChart *item) +XYAnimation::XYAnimation(XYChart *item, int duration, QEasingCurve &curve) : ChartAnimation(item), m_type(NewAnimation), m_dirty(false), m_index(-1), m_item(item) { - setDuration(ChartAnimationDuration); - setEasingCurve(QEasingCurve::OutQuart); + setDuration(duration); + setEasingCurve(curve); } XYAnimation::~XYAnimation() diff --git a/src/charts/animations/xyanimation_p.h b/src/charts/animations/xyanimation_p.h index dd93bd97..09006e0a 100644 --- a/src/charts/animations/xyanimation_p.h +++ b/src/charts/animations/xyanimation_p.h @@ -40,7 +40,7 @@ class XYAnimation : public ChartAnimation protected: enum Animation { AddPointAnimation, RemovePointAnimation, ReplacePointAnimation, NewAnimation }; public: - XYAnimation(XYChart *item); + XYAnimation(XYChart *item, int duration, QEasingCurve &curve); ~XYAnimation(); void setup(const QVector &oldPoints, const QVector &newPoints, int index = -1); Animation animationType() const { return m_type; }; diff --git a/src/charts/areachart/qareaseries.cpp b/src/charts/areachart/qareaseries.cpp index 9684ceaa..4d08087f 100644 --- a/src/charts/areachart/qareaseries.cpp +++ b/src/charts/areachart/qareaseries.cpp @@ -620,7 +620,8 @@ void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent) m_item.reset(area); QAbstractSeriesPrivate::initializeGraphics(parent); } -void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) +void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve) { Q_Q(QAreaSeries); AreaChartItem *area = static_cast(m_item.data()); @@ -631,16 +632,18 @@ void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) area->lowerLineItem()->animation()->stopAndDestroyLater(); if (options.testFlag(QChart::SeriesAnimations)) { - area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); + area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem(), duration, + curve)); if (q->lowerSeries()) - area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); + area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem(), duration, + curve)); } else { if (q->upperSeries()) area->upperLineItem()->setAnimation(0); if (q->lowerSeries()) area->lowerLineItem()->setAnimation(0); } - QAbstractSeriesPrivate::initializeAnimations(options); + QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); } QList QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) diff --git a/src/charts/areachart/qareaseries_p.h b/src/charts/areachart/qareaseries_p.h index edfde51f..185267d7 100644 --- a/src/charts/areachart/qareaseries_p.h +++ b/src/charts/areachart/qareaseries_p.h @@ -46,7 +46,8 @@ public: void initializeAxes(); void initializeGraphics(QGraphicsItem* parent); void initializeTheme(int index, ChartTheme* theme, bool forced = false); - void initializeAnimations(QChart::AnimationOptions options); + void initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve); QList createLegendMarkers(QLegend *legend); diff --git a/src/charts/axis/qabstractaxis.cpp b/src/charts/axis/qabstractaxis.cpp index 17cdfa94..eab95cd5 100644 --- a/src/charts/axis/qabstractaxis.cpp +++ b/src/charts/axis/qabstractaxis.cpp @@ -1018,7 +1018,8 @@ void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) Q_UNUSED(parent); } -void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) +void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve) { ChartAxisElement *axis = m_item.data(); Q_ASSERT(axis); @@ -1026,7 +1027,7 @@ void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options axis->animation()->stopAndDestroyLater(); if (options.testFlag(QChart::GridAxisAnimations)) - axis->setAnimation(new AxisAnimation(axis)); + axis->setAnimation(new AxisAnimation(axis, duration, curve)); else axis->setAnimation(0); } diff --git a/src/charts/axis/qabstractaxis_p.h b/src/charts/axis/qabstractaxis_p.h index 208b467e..41188fe3 100644 --- a/src/charts/axis/qabstractaxis_p.h +++ b/src/charts/axis/qabstractaxis_p.h @@ -61,7 +61,8 @@ public: virtual void initializeDomain(AbstractDomain *domain) = 0; virtual void initializeGraphics(QGraphicsItem *parent) = 0; virtual void initializeTheme(ChartTheme* theme, bool forced = false); - virtual void initializeAnimations(QChart::AnimationOptions options); + virtual void initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve); //interface for manipulating range form base class virtual void setMin(const QVariant &min) = 0; diff --git a/src/charts/barchart/qabstractbarseries.cpp b/src/charts/barchart/qabstractbarseries.cpp index 26674e13..c914e2d7 100644 --- a/src/charts/barchart/qabstractbarseries.cpp +++ b/src/charts/barchart/qabstractbarseries.cpp @@ -1072,7 +1072,8 @@ void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bo emit updatedBars(); } -void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) +void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve) { AbstractBarChartItem *bar = static_cast(m_item.data()); Q_ASSERT(bar); @@ -1080,10 +1081,10 @@ void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions op bar->animation()->stopAndDestroyLater(); if (options.testFlag(QChart::SeriesAnimations)) - bar->setAnimation(new BarAnimation(bar)); + bar->setAnimation(new BarAnimation(bar, duration, curve)); else bar->setAnimation(0); - QAbstractSeriesPrivate::initializeAnimations(options); + QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); } #include "moc_qabstractbarseries.cpp" diff --git a/src/charts/barchart/qabstractbarseries_p.h b/src/charts/barchart/qabstractbarseries_p.h index 7e1e94e9..e1a7e253 100644 --- a/src/charts/barchart/qabstractbarseries_p.h +++ b/src/charts/barchart/qabstractbarseries_p.h @@ -54,7 +54,7 @@ public: void initializeDomain(); void initializeAxes(); - void initializeAnimations(QChart::AnimationOptions options); + void initializeAnimations(QChart::AnimationOptions options, int duration, QEasingCurve &curve); void initializeTheme(int index, ChartTheme* theme, bool forced = false); QList createLegendMarkers(QLegend *legend); diff --git a/src/charts/boxplotchart/qboxplotseries.cpp b/src/charts/boxplotchart/qboxplotseries.cpp index 8bf39c23..5e67130a 100644 --- a/src/charts/boxplotchart/qboxplotseries.cpp +++ b/src/charts/boxplotchart/qboxplotseries.cpp @@ -485,7 +485,8 @@ void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool f } } -void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) +void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve) { BoxPlotChartItem *item = static_cast(m_item.data()); Q_ASSERT(item); @@ -493,12 +494,15 @@ void QBoxPlotSeriesPrivate::initializeAnimations(QChart::AnimationOptions option item->animation()->stopAndDestroyLater(); if (options.testFlag(QChart::SeriesAnimations)) - m_animation = new BoxPlotAnimation(item); + m_animation = new BoxPlotAnimation(item, duration, curve); else m_animation = 0; item->setAnimation(m_animation); - QAbstractSeriesPrivate::initializeAnimations(options); + QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); + + // Make BoxPlotChartItem to instantiate box & whisker items + item->handleDataStructureChanged(); } QList QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend) diff --git a/src/charts/boxplotchart/qboxplotseries_p.h b/src/charts/boxplotchart/qboxplotseries_p.h index 2fcd473e..802ac1ed 100644 --- a/src/charts/boxplotchart/qboxplotseries_p.h +++ b/src/charts/boxplotchart/qboxplotseries_p.h @@ -48,7 +48,7 @@ public: void initializeGraphics(QGraphicsItem *parent); void initializeDomain(); void initializeAxes(); - void initializeAnimations(QChart::AnimationOptions options); + void initializeAnimations(QChart::AnimationOptions options, int duration, QEasingCurve &curve); void initializeTheme(int index, ChartTheme *theme, bool forced = false); QList createLegendMarkers(QLegend *legend); diff --git a/src/charts/chartpresenter.cpp b/src/charts/chartpresenter.cpp index 41fe1094..df66c01b 100644 --- a/src/charts/chartpresenter.cpp +++ b/src/charts/chartpresenter.cpp @@ -39,6 +39,8 @@ ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) : QObject(chart), m_chart(chart), m_options(QChart::NoAnimation), + m_animationDuration(ChartAnimationDuration), + m_animationCurve(QEasingCurve::OutQuart), m_state(ShowState), m_background(0), m_plotAreaBackground(0), @@ -77,7 +79,7 @@ QRectF ChartPresenter::geometry() const void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) { axis->d_ptr->initializeGraphics(rootItem()); - axis->d_ptr->initializeAnimations(m_options); + axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve); ChartAxisElement *item = axis->d_ptr->axisItem(); item->setPresenter(this); item->setThemeManager(m_chart->d_ptr->m_themeManager); @@ -101,7 +103,7 @@ void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) { series->d_ptr->initializeGraphics(rootItem()); - series->d_ptr->initializeAnimations(m_options); + series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve); series->d_ptr->setPresenter(this); ChartItem *chart = series->d_ptr->chartItem(); chart->setPresenter(this); @@ -134,16 +136,41 @@ void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) m_options = options; if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) { foreach (QAbstractSeries *series, m_series) - series->d_ptr->initializeAnimations(m_options); + series->d_ptr->initializeAnimations(m_options, m_animationDuration, + m_animationCurve); } if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) { foreach (QAbstractAxis *axis, m_axes) - axis->d_ptr->initializeAnimations(m_options); + axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve); } m_layout->invalidate(); // So that existing animations don't just stop halfway } } +void ChartPresenter::setAnimationDuration(int msecs) +{ + if (m_animationDuration != msecs) { + m_animationDuration = msecs; + foreach (QAbstractSeries *series, m_series) + series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve); + foreach (QAbstractAxis *axis, m_axes) + axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve); + m_layout->invalidate(); // So that existing animations don't just stop halfway + } +} + +void ChartPresenter::setAnimationEasingCurve(const QEasingCurve &curve) +{ + if (m_animationCurve != curve) { + m_animationCurve = curve; + foreach (QAbstractSeries *series, m_series) + series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve); + foreach (QAbstractAxis *axis, m_axes) + axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve); + m_layout->invalidate(); // So that existing animations don't just stop halfway + } +} + void ChartPresenter::setState(State state,QPointF point) { m_state=state; diff --git a/src/charts/chartpresenter_p.h b/src/charts/chartpresenter_p.h index 7ec5d656..db61d65c 100644 --- a/src/charts/chartpresenter_p.h +++ b/src/charts/chartpresenter_p.h @@ -137,6 +137,10 @@ public: void setAnimationOptions(QChart::AnimationOptions options); QChart::AnimationOptions animationOptions() const; + void setAnimationDuration(int msecs); + int animationDuration() const { return m_animationDuration; } + void setAnimationEasingCurve(const QEasingCurve &curve); + QEasingCurve animationEasingCurve() const { return m_animationCurve; } void startAnimation(ChartAnimation *animation); @@ -177,6 +181,8 @@ private: QList m_series; QList m_axes; QChart::AnimationOptions m_options; + int m_animationDuration; + QEasingCurve m_animationCurve; State m_state; QPointF m_statePoint; AbstractChartLayout *m_layout; diff --git a/src/charts/piechart/qpieseries.cpp b/src/charts/piechart/qpieseries.cpp index c680865a..08705254 100644 --- a/src/charts/piechart/qpieseries.cpp +++ b/src/charts/piechart/qpieseries.cpp @@ -932,7 +932,8 @@ void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) QAbstractSeriesPrivate::initializeGraphics(parent); } -void QPieSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options) +void QPieSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options, + int duration, QEasingCurve &curve) { PieChartItem *item = static_cast(m_item.data()); Q_ASSERT(item); @@ -940,10 +941,10 @@ void QPieSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions item->animation()->stopAndDestroyLater(); if (options.testFlag(QChart::SeriesAnimations)) - item->setAnimation(new PieAnimation(item)); + item->setAnimation(new PieAnimation(item, duration, curve)); else item->setAnimation(0); - QAbstractSeriesPrivate::initializeAnimations(options); + QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); } QList QPieSeriesPrivate::createLegendMarkers(QLegend* legend) diff --git a/src/charts/piechart/qpieseries_p.h b/src/charts/piechart/qpieseries_p.h index 9c113d0b..08eb7d04 100644 --- a/src/charts/piechart/qpieseries_p.h +++ b/src/charts/piechart/qpieseries_p.h @@ -45,7 +45,8 @@ public: void initializeDomain(); void initializeAxes(); void initializeGraphics(QGraphicsItem* parent); - void initializeAnimations(QtCharts::QChart::AnimationOptions options); + void initializeAnimations(QtCharts::QChart::AnimationOptions options, int duration, + QEasingCurve &curve); void initializeTheme(int index, ChartTheme* theme, bool forced = false); QList createLegendMarkers(QLegend *legend); diff --git a/src/charts/qabstractseries.cpp b/src/charts/qabstractseries.cpp index 220dfacd..cb3c7c5a 100644 --- a/src/charts/qabstractseries.cpp +++ b/src/charts/qabstractseries.cpp @@ -312,9 +312,12 @@ void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); } -void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) +void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve) { Q_UNUSED(options); + Q_UNUSED(duration); + Q_UNUSED(curve); } bool QAbstractSeriesPrivate::reverseXAxis() diff --git a/src/charts/qabstractseries_p.h b/src/charts/qabstractseries_p.h index 4394cb4d..6a5e1340 100644 --- a/src/charts/qabstractseries_p.h +++ b/src/charts/qabstractseries_p.h @@ -61,7 +61,8 @@ public: virtual void initializeAxes() = 0; virtual void initializeTheme(int index, ChartTheme* theme, bool forced = false) = 0; virtual void initializeGraphics(QGraphicsItem* parent) = 0; - virtual void initializeAnimations(QChart::AnimationOptions options) = 0; + virtual void initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve) = 0; virtual QList createLegendMarkers(QLegend* legend) = 0; diff --git a/src/charts/qchart.cpp b/src/charts/qchart.cpp index 7ac9d552..cca9b166 100644 --- a/src/charts/qchart.cpp +++ b/src/charts/qchart.cpp @@ -84,6 +84,16 @@ QT_CHARTS_BEGIN_NAMESPACE The animation \a options for the chart. Animations are enabled/disabled based on this setting. */ +/*! + \property QChart::animationDuration + The duration of the animation for the chart. + */ + +/*! + \property QChart::animationEasingCurve + The easing curve of the animation for the chart. + */ + /*! \property QChart::backgroundVisible Specifies whether the chart background is visible or not. @@ -595,6 +605,26 @@ QChart::AnimationOptions QChart::animationOptions() const return d_ptr->m_presenter->animationOptions(); } +void QChart::setAnimationDuration(int msecs) +{ + d_ptr->m_presenter->setAnimationDuration(msecs); +} + +int QChart::animationDuration() const +{ + return d_ptr->m_presenter->animationDuration(); +} + +void QChart::setAnimationEasingCurve(const QEasingCurve &curve) +{ + d_ptr->m_presenter->setAnimationEasingCurve(curve); +} + +QEasingCurve QChart::animationEasingCurve() const +{ + return d_ptr->m_presenter->animationEasingCurve(); +} + /*! Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. diff --git a/src/charts/qchart.h b/src/charts/qchart.h index e2d1171e..c95dfb2b 100644 --- a/src/charts/qchart.h +++ b/src/charts/qchart.h @@ -45,6 +45,8 @@ class QT_CHARTS_EXPORT QChart : public QGraphicsWidget Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness) Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) + Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration) + Q_PROPERTY(QEasingCurve animationEasingCurve READ animationEasingCurve WRITE setAnimationEasingCurve) Q_PROPERTY(QMargins margins READ margins WRITE setMargins) Q_PROPERTY(QChart::ChartType chartType READ chartType) Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible) @@ -125,8 +127,13 @@ public: bool isDropShadowEnabled() const; void setBackgroundRoundness(qreal diameter); qreal backgroundRoundness() const; + void setAnimationOptions(AnimationOptions options); AnimationOptions animationOptions() const; + void setAnimationDuration(int msecs); + int animationDuration() const; + void setAnimationEasingCurve(const QEasingCurve &curve); + QEasingCurve animationEasingCurve() const; void zoomIn(); void zoomOut(); diff --git a/src/charts/scatterchart/qscatterseries.cpp b/src/charts/scatterchart/qscatterseries.cpp index a3008f1b..25e685cc 100644 --- a/src/charts/scatterchart/qscatterseries.cpp +++ b/src/charts/scatterchart/qscatterseries.cpp @@ -311,7 +311,8 @@ void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool f } } -void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) +void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, + QEasingCurve &curve) { ScatterChartItem *item = static_cast(m_item.data()); Q_ASSERT(item); @@ -320,11 +321,11 @@ void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions option item->animation()->stopAndDestroyLater(); if (options.testFlag(QChart::SeriesAnimations)) - item->setAnimation(new ScatterAnimation(item)); + item->setAnimation(new ScatterAnimation(item, duration, curve)); else item->setAnimation(0); - QAbstractSeriesPrivate::initializeAnimations(options); + QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); } #include "moc_qscatterseries.cpp" diff --git a/src/charts/scatterchart/qscatterseries_p.h b/src/charts/scatterchart/qscatterseries_p.h index 6d3117a0..baa58620 100644 --- a/src/charts/scatterchart/qscatterseries_p.h +++ b/src/charts/scatterchart/qscatterseries_p.h @@ -38,7 +38,8 @@ public: QScatterSeriesPrivate(QScatterSeries *q); void initializeGraphics(QGraphicsItem* parent); void initializeTheme(int index, ChartTheme* theme, bool forced = false); - void initializeAnimations(QtCharts::QChart::AnimationOptions options); + void initializeAnimations(QtCharts::QChart::AnimationOptions options, int duration, + QEasingCurve &curve); private: QScatterSeries::MarkerShape m_shape; diff --git a/src/charts/splinechart/qsplineseries.cpp b/src/charts/splinechart/qsplineseries.cpp index 989139b6..b33864da 100644 --- a/src/charts/splinechart/qsplineseries.cpp +++ b/src/charts/splinechart/qsplineseries.cpp @@ -143,7 +143,8 @@ void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool fo } } -void QSplineSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options) +void QSplineSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options, + int duration, QEasingCurve &curve) { SplineChartItem *item = static_cast(m_item.data()); Q_ASSERT(item); @@ -151,10 +152,10 @@ void QSplineSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptio item->animation()->stopAndDestroyLater(); if (options.testFlag(QChart::SeriesAnimations)) - item->setAnimation(new SplineAnimation(item)); + item->setAnimation(new SplineAnimation(item, duration, curve)); else item->setAnimation(0); - QAbstractSeriesPrivate::initializeAnimations(options); + QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); } #include "moc_qsplineseries.cpp" diff --git a/src/charts/splinechart/qsplineseries_p.h b/src/charts/splinechart/qsplineseries_p.h index fed9e20f..628b5058 100644 --- a/src/charts/splinechart/qsplineseries_p.h +++ b/src/charts/splinechart/qsplineseries_p.h @@ -41,7 +41,8 @@ public: void initializeTheme(int index, ChartTheme* theme, bool forced = false); void initializeGraphics(QGraphicsItem* parent); - void initializeAnimations(QtCharts::QChart::AnimationOptions options); + void initializeAnimations(QtCharts::QChart::AnimationOptions options, int duration, + QEasingCurve &curve); private: Q_DECLARE_PUBLIC(QSplineSeries) diff --git a/src/charts/xychart/qxyseries.cpp b/src/charts/xychart/qxyseries.cpp index e97421c2..1ddaf859 100644 --- a/src/charts/xychart/qxyseries.cpp +++ b/src/charts/xychart/qxyseries.cpp @@ -830,7 +830,8 @@ QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) return new QValueAxis; } -void QXYSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options) +void QXYSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options, + int duration, QEasingCurve &curve) { XYChart *item = static_cast(m_item.data()); Q_ASSERT(item); @@ -838,10 +839,10 @@ void QXYSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions o item->animation()->stopAndDestroyLater(); if (options.testFlag(QChart::SeriesAnimations)) - item->setAnimation(new XYAnimation(item)); + item->setAnimation(new XYAnimation(item, duration, curve)); else item->setAnimation(0); - QAbstractSeriesPrivate::initializeAnimations(options); + QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); } void QXYSeriesPrivate::drawSeriesPointLabels(QPainter *painter, const QVector &points, diff --git a/src/charts/xychart/qxyseries_p.h b/src/charts/xychart/qxyseries_p.h index 2803a8e9..d11da9c3 100644 --- a/src/charts/xychart/qxyseries_p.h +++ b/src/charts/xychart/qxyseries_p.h @@ -44,7 +44,8 @@ public: void initializeDomain(); void initializeAxes(); - void initializeAnimations(QtCharts::QChart::AnimationOptions options); + void initializeAnimations(QtCharts::QChart::AnimationOptions options, int duration, + QEasingCurve &curve); QList createLegendMarkers(QLegend* legend); diff --git a/src/chartsqml2/declarativechart.cpp b/src/chartsqml2/declarativechart.cpp index 44af74fd..51cdba37 100644 --- a/src/chartsqml2/declarativechart.cpp +++ b/src/chartsqml2/declarativechart.cpp @@ -80,6 +80,15 @@ QT_CHARTS_BEGIN_NAMESPACE ChartView.SeriesAnimations or ChartView.AllAnimations. */ +/*! + \qmlproperty int ChartView::animationDuration + The duration of the animation for the chart. + */ + +/*! + \qmlproperty easing ChartView::animationEasingCurve + The easing curve of the animation for the chart. + /*! \qmlproperty Font ChartView::titleFont The title font of the chart. @@ -673,6 +682,32 @@ DeclarativeChart::Animation DeclarativeChart::animationOptions() return DeclarativeChart::NoAnimation; } +void DeclarativeChart::setAnimationDuration(int msecs) +{ + if (msecs != m_chart->animationDuration()) { + m_chart->setAnimationDuration(msecs); + emit animationDurationChanged(msecs); + } +} + +int DeclarativeChart::animationDuration() const +{ + return m_chart->animationDuration(); +} + +void DeclarativeChart::setAnimationEasingCurve(const QEasingCurve &curve) +{ + if (curve != m_chart->animationEasingCurve()) { + m_chart->setAnimationEasingCurve(curve); + emit animationEasingCurveChanged(curve); + } +} + +QEasingCurve DeclarativeChart::animationEasingCurve() const +{ + return m_chart->animationEasingCurve(); +} + void DeclarativeChart::setTitle(QString title) { if (title != m_chart->title()) diff --git a/src/chartsqml2/declarativechart.h b/src/chartsqml2/declarativechart.h index c57386fe..397061a4 100644 --- a/src/chartsqml2/declarativechart.h +++ b/src/chartsqml2/declarativechart.h @@ -39,6 +39,8 @@ class DeclarativeChart : public QQuickPaintedItem Q_OBJECT Q_PROPERTY(Theme theme READ theme WRITE setTheme) Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) + Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration NOTIFY animationDurationChanged REVISION 5) + Q_PROPERTY(QEasingCurve animationEasingCurve READ animationEasingCurve WRITE setAnimationEasingCurve NOTIFY animationEasingCurveChanged REVISION 5) Q_PROPERTY(QString title READ title WRITE setTitle) Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) @@ -116,6 +118,10 @@ public: DeclarativeChart::Theme theme(); void setAnimationOptions(DeclarativeChart::Animation animations); DeclarativeChart::Animation animationOptions(); + void setAnimationDuration(int msecs); + int animationDuration() const; + void setAnimationEasingCurve(const QEasingCurve &curve); + QEasingCurve animationEasingCurve() const; void setTitle(QString title); QString title(); QLegend *legend(); @@ -190,6 +196,8 @@ Q_SIGNALS: Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter); Q_REVISION(4) void localizeNumbersChanged(); Q_REVISION(4) void localeChanged(); + Q_REVISION(5) void animationDurationChanged(int msecs); + Q_REVISION(5) void animationEasingCurveChanged(QEasingCurve curve); private Q_SLOTS: void changeMargins(int top, int bottom, int left, int right); diff --git a/src/chartsqml2/plugins.qmltypes b/src/chartsqml2/plugins.qmltypes index d361739e..de666968 100644 --- a/src/chartsqml2/plugins.qmltypes +++ b/src/chartsqml2/plugins.qmltypes @@ -994,6 +994,8 @@ Module { Property { name: "axes"; revision: 2; type: "QAbstractAxis"; isList: true; isReadonly: true } Property { name: "localizeNumbers"; revision: 4; type: "bool" } Property { name: "locale"; revision: 4; type: "QLocale" } + Property { name: "animationDuration"; revision: 5; type: "int" } + Property { name: "animationEasingCurve"; revision: 5; type: "QEasingCurve" } Signal { name: "axisLabelsChanged" } Signal { name: "titleColorChanged" @@ -1024,6 +1026,16 @@ Module { } Signal { name: "localizeNumbersChanged"; revision: 4 } Signal { name: "localeChanged"; revision: 4 } + Signal { + name: "animationDurationChanged" + revision: 5 + Parameter { name: "msecs"; type: "int" } + } + Signal { + name: "animationEasingCurveChanged" + revision: 5 + Parameter { name: "curve"; type: "QEasingCurve" } + } Method { name: "series" type: "QAbstractSeries*" diff --git a/tests/auto/qchart/tst_qchart.cpp b/tests/auto/qchart/tst_qchart.cpp index e0c5a49a..1e502d5a 100644 --- a/tests/auto/qchart/tst_qchart.cpp +++ b/tests/auto/qchart/tst_qchart.cpp @@ -59,6 +59,9 @@ private slots: void addSeries(); void animationOptions_data(); void animationOptions(); + void animationDuration(); + void animationCurve_data(); + void animationCurve(); void axisX_data(); void axisX(); void axisY_data(); @@ -160,6 +163,8 @@ void tst_QChart::qchart() QVERIFY(m_chart->legend()->isVisible()); QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); + QCOMPARE(m_chart->animationDuration(), 1000); + QCOMPARE(m_chart->animationEasingCurve(), QEasingCurve(QEasingCurve::OutQuart)); QVERIFY(!m_chart->axisX()); QVERIFY(!m_chart->axisY()); QVERIFY(m_chart->backgroundBrush()!=QBrush()); @@ -258,6 +263,30 @@ void tst_QChart::animationOptions() QCOMPARE(m_chart->animationOptions(), animationOptions); } +void tst_QChart::animationDuration() +{ + createTestData(); + m_chart->setAnimationDuration(2000); + QVERIFY(m_chart->animationDuration() == 2000); +} + +void tst_QChart::animationCurve_data() +{ + QTest::addColumn("animationCurve"); + QTest::newRow("Linear") << QEasingCurve(QEasingCurve::Linear); + QTest::newRow("InCubic") << QEasingCurve(QEasingCurve::InCubic); + QTest::newRow("OutSine") << QEasingCurve(QEasingCurve::OutSine); + QTest::newRow("OutInBack") << QEasingCurve(QEasingCurve::OutInBack); +} + +void tst_QChart::animationCurve() +{ + createTestData(); + QFETCH(QEasingCurve, animationCurve); + m_chart->setAnimationEasingCurve(animationCurve); + QCOMPARE(m_chart->animationEasingCurve(), animationCurve); +} + void tst_QChart::axisX_data() { diff --git a/tests/auto/qml-qtquicktest/tst_chartview.qml b/tests/auto/qml-qtquicktest/tst_chartview.qml index 67b9155a..a80b1d3f 100644 --- a/tests/auto/qml-qtquicktest/tst_chartview.qml +++ b/tests/auto/qml-qtquicktest/tst_chartview.qml @@ -31,6 +31,8 @@ Rectangle { function test_chartViewProperties() { compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions"); + compare(chartView.animationDuration, 1000, "ChartView.animationDuration"); + compare(chartView.animationEasingCurve.type, Easing.OutQuart, "ChartView.animationEasingCurve"); verify(chartView.backgroundColor != undefined); verify(chartView.margins.bottom > 0, "ChartView.margins.bottom"); verify(chartView.margins.top > 0, "ChartView.margins.top"); diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml index d813e1cb..5d103467 100644 --- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/Chart.qml @@ -17,7 +17,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtCharts 2.0 +import QtCharts 2.1 ChartView { id: chartView @@ -45,7 +45,11 @@ ChartView { onBackgroundRoundnessChanged: console.log("chart.onBackgroundRoundnessChanged: " + diameter); onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name); onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name); - onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor); + onPlotAreaColorChanged: console.log("chart.onPlotAreaColorChanged: " + chart.plotAreaColor); + onAnimationDurationChanged: console.log("chart.onAnimationDurationChanged: " + + chart.animationDuration); + onAnimationEasingCurveChanged: console.log("chart.onAnimationEasingCurveChanged: " + + chart.animationEasingCurve.type); legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible); legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorProperties.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorProperties.qml index 9b0633c5..49fd4bd7 100644 --- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorProperties.qml +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorProperties.qml @@ -21,8 +21,16 @@ import QtQuick 2.0 Flow { anchors.fill: parent property variant chart + property variant easingTypes: [Easing.Linear, Easing.InCubic, Easing.OutSine, Easing.OutInBack] + property int easingTypeIndex: 0 flow: Flow.TopToBottom spacing: 5 + + function nextEasingType() { + easingTypeIndex++; + return easingTypes[easingTypeIndex % easingTypes.length]; + } + Button { text: "visible" onClicked: chart.visible = !chart.visible; @@ -43,6 +51,18 @@ Flow { text: "animation opt -" onClicked: chart.animationOptions--; } + Button { + text: "animation duration +" + onClicked: chart.animationDuration = chart.animationDuration + 1000; + } + Button { + text: "animation duration -" + onClicked: chart.animationDuration = chart.animationDuration - 1000; + } + Button { + text: "animation curve" + onClicked: chart.animationEasingCurve.type = nextEasingType(); + } Button { text: "background color" onClicked: chart.backgroundColor = main.nextColor(); -- cgit v1.2.3