From 5245fa8e4b1600944d3968db7fb0df06aab94b86 2013-04-10 10:32:29 From: Mika Salmela Date: 2013-04-10 10:32:29 Subject: [PATCH] Fixed animation to work when adding a new series. Change-Id: I698e4143213e49d07ef69c802eed051912af7532 Reviewed-by: Mika Salmela --- diff --git a/src/animations/boxplotanimation.cpp b/src/animations/boxplotanimation.cpp index 57add4d..f645f67 100644 --- a/src/animations/boxplotanimation.cpp +++ b/src/animations/boxplotanimation.cpp @@ -22,33 +22,32 @@ #include "boxplotchartitem_p.h" #include "boxwhiskersdata_p.h" #include "boxwhiskersanimation_p.h" +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item) - // : ChartAnimation(item), : m_item(item) { } -//BoxPlotAnimation::BoxPlotAnimation(BoxWhiskers *box) -// : ChartAnimation(box), -// m_box(box) -//{ -//} - BoxPlotAnimation::~BoxPlotAnimation() { } void BoxPlotAnimation::addBox(BoxWhiskers *box) { - BoxWhiskersAnimation *animation = new BoxWhiskersAnimation(box); - m_animations.insert(box, animation); - - BoxWhiskersData start; - start.m_median = box->m_data.m_median; - animation->setup(start, box->m_data); + BoxWhiskersAnimation *animation = m_animations.value(box); + if (!animation) { + animation = new BoxWhiskersAnimation(box); + m_animations.insert(box, animation); + BoxWhiskersData start; + start.m_median = box->m_data.m_median; + animation->setup(start, box->m_data); + } else { + animation->stop(); + animation->setEndData(box->m_data); + } } ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box) @@ -57,7 +56,6 @@ ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box) return m_animations.value(box); } - //#include "moc_boxplotanimation_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/boxwhiskersanimation.cpp b/src/animations/boxwhiskersanimation.cpp index 264f58b..d577082 100644 --- a/src/animations/boxwhiskersanimation.cpp +++ b/src/animations/boxwhiskersanimation.cpp @@ -22,6 +22,7 @@ #include "boxplotanimation_p.h" #include "boxplotchartitem_p.h" #include "boxwhiskersdata_p.h" +#include Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData) @@ -80,7 +81,8 @@ QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant result.m_minX = endData.m_minX; result.m_maxY = endData.m_maxY; result.m_minY = endData.m_minY; - //result.m_domainSize = endData.m_domainSize; + result.m_seriesIndex = endData.m_seriesIndex; + result.m_seriesCount = endData.m_seriesCount; return qVariantFromValue(result); } @@ -93,13 +95,18 @@ void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value) void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData) { - if (endData.m_index == 0) { - qDebug() << "BoxPlotAnimation::setup m_upperExtreme" << endData.m_upperExtreme; - } setKeyValueAt(0.0, qVariantFromValue(startData)); setKeyValueAt(1.0, qVariantFromValue(endData)); } +void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData) +{ + if (state() != QAbstractAnimation::Stopped) + stop(); + + setEndValue(qVariantFromValue(endData)); +} + #include "moc_boxwhiskersanimation_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/boxwhiskersanimation_p.h b/src/animations/boxwhiskersanimation_p.h index f2dc6dc..3b8979f 100644 --- a/src/animations/boxwhiskersanimation_p.h +++ b/src/animations/boxwhiskersanimation_p.h @@ -52,6 +52,7 @@ public: // from QVariantAnimation virtual void updateCurrentValue(const QVariant &value); void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData); + void setEndData(const BoxWhiskersData &endData); protected: BoxPlotChartItem *m_item; diff --git a/src/boxplotchart/boxwhiskers.cpp b/src/boxplotchart/boxwhiskers.cpp index b975ce1..aed2fcf 100644 --- a/src/boxplotchart/boxwhiskers.cpp +++ b/src/boxplotchart/boxwhiskers.cpp @@ -73,7 +73,6 @@ void BoxWhiskers::setLayout(const BoxWhiskersData &data) // if (m_data.m_index == 1) // qDebug() << "BoxWhiskers::setLayout"; updateGeometry(); - //update(0.0, 0.0, m_data.m_domainSize.width(), m_data.m_domainSize.height()); update(); } @@ -130,9 +129,6 @@ void BoxWhiskers::updateGeometry() QPainterPath path; - // TODO: Dirty hack - if (m_data.m_seriesCount == 0) m_data.m_seriesCount = 1; - qreal columnWidth = 1.0 / m_data.m_seriesCount; qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex; qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex;