##// END OF EJS Templates
Fix falling unit test
Fix falling unit test

File last commit:

r1006:a8ef6d6db8bf
r1048:91742fa35f1c
Show More
chartanimator.cpp
301 lines | 8.6 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
**
** 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$
**
****************************************************************************/
Michal Klocek
Animation refactor...
r530 #include "chartanimator_p.h"
#include "axisanimation_p.h"
#include "xyanimation_p.h"
Michal Klocek
Improves spline interpolation...
r622 #include "splineanimation_p.h"
Michal Klocek
Animation refactor...
r530 #include "xychartitem_p.h"
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 #include "pieanimation_p.h"
sauimone
Animation framework for barchart.
r671 #include "baranimation_p.h"
#include "barchartitem_p.h"
Michal Klocek
Adds area chart animations...
r560 #include "areachartitem_p.h"
Michal Klocek
Improves spline interpolation...
r622 #include "splinechartitem_p.h"
#include "scatterchartitem_p.h"
Michal Klocek
Animation refactor...
r530 #include <QTimer>
Q_DECLARE_METATYPE(QVector<QPointF>)
Q_DECLARE_METATYPE(QVector<qreal>)
sauimone
barchart animation mechanics working. still some todo
r681 Q_DECLARE_METATYPE(QVector<QRectF>)
Michal Klocek
Animation refactor...
r530
QTCOMMERCIALCHART_BEGIN_NAMESPACE
const static int duration = 1000;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 ChartAnimator::ChartAnimator(QObject *parent):QObject(parent),
m_state(ShowState)
Michal Klocek
Animation refactor...
r530 {
}
ChartAnimator::~ChartAnimator()
{
}
Michal Klocek
Changes QChartAxis -> QAxis
r1006 void ChartAnimator::addAnimation(ChartAxis *item)
Michal Klocek
Animation refactor...
r530 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 ChartAnimation *animation = m_animations.value(item);
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (!animation) {
Michal Klocek
Animation refactor...
r530 animation = new AxisAnimation(item);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_animations.insert(item, animation);
Michal Klocek
Animation refactor...
r530 }
item->setAnimator(this);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::addAnimation(SplineChartItem *item)
Michal Klocek
Improves spline interpolation...
r622 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 ChartAnimation *animation = m_animations.value(item);
Michal Klocek
Improves spline interpolation...
r622
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (!animation) {
Michal Klocek
Improves spline interpolation...
r622 animation = new SplineAnimation(item);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_animations.insert(item, animation);
Michal Klocek
Improves spline interpolation...
r622 }
item->setAnimator(this);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::addAnimation(ScatterChartItem *item)
Michal Klocek
Improves spline interpolation...
r622 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 ChartAnimation *animation = m_animations.value(item);
Michal Klocek
Improves spline interpolation...
r622
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (!animation) {
Michal Klocek
Improves spline interpolation...
r622 animation = new XYAnimation(item);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_animations.insert(item, animation);
Michal Klocek
Improves spline interpolation...
r622 }
item->setAnimator(this);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::addAnimation(LineChartItem *item)
Michal Klocek
Animation refactor...
r530 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 ChartAnimation *animation = m_animations.value(item);
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (!animation) {
Michal Klocek
Animation refactor...
r530 animation = new XYAnimation(item);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_animations.insert(item, animation);
Michal Klocek
Animation refactor...
r530 }
item->setAnimator(this);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::addAnimation(PieChartItem *item)
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 ChartAnimation *animation = m_animations.value(item);
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (!animation) {
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 animation = new PieAnimation(item);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_animations.insert(item, animation);
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 }
item->setAnimator(this);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::addAnimation(BarChartItem *item)
sauimone
Animation framework for barchart.
r671 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 ChartAnimation *animation = m_animations.value(item);
sauimone
Animation framework for barchart.
r671
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (!animation) {
sauimone
Animation framework for barchart.
r671 animation = new BarAnimation(item);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_animations.insert(item, animation);
sauimone
Animation framework for barchart.
r671 }
item->setAnimator(this);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::removeAnimation(Chart *item)
Michal Klocek
Animation refactor...
r530 {
item->setAnimator(0);
m_animations.remove(item);
}
Michal Klocek
Changes QChartAxis -> QAxis
r1006 void ChartAnimator::updateLayout(ChartAxis *item , QVector<qreal> &newLayout)
Michal Klocek
Animation refactor...
r530 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 AxisAnimation *animation = static_cast<AxisAnimation*>(m_animations.value(item));
Michal Klocek
Animation refactor...
r530
Michal Klocek
Adds area chart animations...
r560 Q_ASSERT(animation);
Michal Klocek
Animation refactor...
r530
QVector<qreal> oldLayout = item->layout();
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (newLayout.count() == 0)
return;
switch (m_state) {
case ZoomOutState: {
QRectF rect = item->geometry();
oldLayout.resize(newLayout.count());
Michal Klocek
Krazy reported errors...
r974 for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
Michal Klocek
Changes QChartAxis -> QAxis
r1006 oldLayout[i] = item->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.bottom();
oldLayout[j] = item->axisType() == ChartAxis::X_AXIS ? rect.right() : rect.top();
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 }
}
break;
case ZoomInState: {
Michal Klocek
Changes QChartAxis -> QAxis
r1006 int index = qMin(oldLayout.count() * (item->axisType() == ChartAxis::X_AXIS ? m_point.x() : (1 - m_point.y())), newLayout.count() - 1.0);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 oldLayout.resize(newLayout.count());
for(int i = 0; i < oldLayout.count(); i++)
oldLayout[i]= oldLayout[index];
Michal Klocek
Animation refactor...
r530 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 break;
case ScrollDownState:
case ScrollRightState: {
oldLayout.resize(newLayout.count());
Michal Klocek
Krazy reported errors...
r974 for(int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j)
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 oldLayout[i]= oldLayout[j];
}
break;
case ScrollUpState:
case ScrollLeftState: {
oldLayout.resize(newLayout.count());
Michal Klocek
Krazy reported errors...
r974 for(int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j)
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 oldLayout[i]= oldLayout[j];
}
break;
default: {
oldLayout.resize(newLayout.count());
QRectF rect = item->geometry();
Michal Klocek
Krazy reported errors...
r974 for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
Michal Klocek
Changes QChartAxis -> QAxis
r1006 oldLayout[i] = item->axisType() == ChartAxis::X_AXIS ? rect.left() : rect.top();
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 }
break;
}
if (animation->state() != QAbstractAnimation::Stopped)
animation->stop();
Michal Klocek
Animation refactor...
r530
animation->setDuration(duration);
animation->setEasingCurve(QEasingCurve::OutQuart);
QVariantAnimation::KeyValues value;
animation->setKeyValues(value); //workaround for wrong interpolation call
animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout));
animation->setKeyValueAt(1.0, qVariantFromValue(newLayout));
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 QTimer::singleShot(0, animation, SLOT(start()));
Michal Klocek
Animation refactor...
r530 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::updateLayout(SplineChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldControlPoints, QVector<QPointF> &newControlPoints, int index)
Michal Klocek
Animation refactor...
r530 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 SplineAnimation *animation = static_cast<SplineAnimation *>(m_animations.value(item));
Michal Klocek
Animation refactor...
r530
Michal Klocek
Adds area chart animations...
r560 Q_ASSERT(animation);
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (newPoints.count() < 2 || newControlPoints.count() < 2)
return;
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 bool empty = oldPoints.count() == 0;
Michal Klocek
Improves spline interpolation...
r622
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (animation->state() != QAbstractAnimation::Stopped)
animation->stop();
Michal Klocek
Animation refactor...
r530
animation->setDuration(duration);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (!empty)
animation->setAnimationType(ChartAnimation::MoveDownAnimation);
Michal Klocek
Animation refactor...
r530 else
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 animation->setAnimationType(ChartAnimation::LineDrawAnimation);
Michal Klocek
Improves spline interpolation...
r622
Michal Klocek
Animation refactor...
r530 animation->setEasingCurve(QEasingCurve::OutQuart);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 animation->setValues(oldPoints, newPoints, oldControlPoints, newControlPoints, index);
Michal Klocek
Improves spline interpolation...
r622
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 QTimer::singleShot(0, animation, SLOT(start()));
Michal Klocek
Animation refactor...
r530 }
Michal Klocek
Improves spline interpolation...
r622
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::updateLayout(XYChartItem *item, QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
Michal Klocek
Animation refactor...
r530 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 XYAnimation *animation = static_cast<XYAnimation *>(m_animations.value(item));
Michal Klocek
Animation refactor...
r530
Michal Klocek
Adds area chart animations...
r560 Q_ASSERT(animation);
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (newPoints.count() == 0)
return;
Michal Klocek
Improves spline interpolation...
r622
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 bool empty = oldPoints.count() == 0;
Michal Klocek
Improves spline interpolation...
r622
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (animation->state() != QAbstractAnimation::Stopped)
Michal Klocek
Improves spline interpolation...
r622 animation->stop();
Michal Klocek
Animation refactor...
r530 animation->setDuration(duration);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (!empty)
animation->setAnimationType(ChartAnimation::MoveDownAnimation);
Michal Klocek
Improves spline interpolation...
r622 else
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 animation->setAnimationType(ChartAnimation::LineDrawAnimation);
Michal Klocek
Improves spline interpolation...
r622
Michal Klocek
Animation refactor...
r530 animation->setEasingCurve(QEasingCurve::OutQuart);
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 animation->setValues(oldPoints, newPoints, index);
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 QTimer::singleShot(0, animation, SLOT(start()));
Michal Klocek
Animation refactor...
r530 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty)
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item));
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 Q_ASSERT(animation);
Jani Honkonen
Rename PieSliceLayout -> PieSliceData. A "layout" is a bad name for this.
r668 animation->addSlice(slice, sliceData, isEmpty);
Jani Honkonen
Refactoring pie series and animations.
r621 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::removeAnimation(PieChartItem *item, QPieSlice *slice)
Jani Honkonen
Refactoring pie series and animations.
r621 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item));
Jani Honkonen
Refactoring pie series and animations.
r621 Q_ASSERT(animation);
animation->removeSlice(slice);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::updateLayout(PieChartItem *item, const PieLayout &layout)
Jani Honkonen
Refactoring pie series and animations.
r621 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item));
Jani Honkonen
Refactoring pie series and animations.
r621 Q_ASSERT(animation);
animation->updateValues(layout);
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData)
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item));
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 Q_ASSERT(animation);
Jani Honkonen
Rename PieSliceLayout -> PieSliceData. A "layout" is a bad name for this.
r668 animation->updateValue(slice, sliceData);
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout)
sauimone
Animation framework for barchart.
r671 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item));
sauimone
Animation framework for barchart.
r671 Q_ASSERT(animation);
sauimone
barchart animation mechanics working. still some todo
r681 animation->setDuration(duration);
animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout));
animation->setKeyValueAt(1.0, qVariantFromValue(newLayout));
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 QTimer::singleShot(0, animation, SLOT(start()));
sauimone
Animation framework for barchart.
r671 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void ChartAnimator::setState(State state, const QPointF &point)
Michal Klocek
Adds scroll support...
r531 {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_state = state;
m_point = point;
Michal Klocek
Adds scroll support...
r531 }
Michal Klocek
Krazy reported errors...
r974 #include "moc_chartanimator_p.cpp"
Michal Klocek
Animation refactor...
r530 QTCOMMERCIALCHART_END_NAMESPACE