##// END OF EJS Templates
Fixed initial bounding rect issue with bar series
Fixed initial bounding rect issue with bar series

File last commit:

r513:c1d8fdd92b71
r518:1db754feb986
Show More
xychartanimationitem_p.h
107 lines | 2.6 KiB | text/x-c | CLexer
/ src / xychart / xychartanimationitem_p.h
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 #ifndef XYCHARTANIMATIONITEM_P_H_
#define XYCHARTANIMATIONITEM_P_H_
#include "qchartglobal.h"
#include "xychartanimator_p.h"
#include <QPointF>
#include <QTimer>
#include <QGraphicsItem>
Q_DECLARE_METATYPE(QVector<QPointF>)
QTCOMMERCIALCHART_BEGIN_NAMESPACE
const static int duration = 1000;
template <class T , class U>
class XYChartAnimationItem : public T {
public:
XYChartAnimationItem(U *series, QGraphicsItem *parent = 0);
virtual ~XYChartAnimationItem();
void animationStarted();
protected:
virtual void updatePoints(QVector<QPointF>& newPoints);
virtual void updatePoint(QVector<QPointF>& newPoints);
private:
XYChartAnimator<T,U> *m_animation;
QVector<QPointF> m_points;
bool m_dirty;
};
template <class T, class U>
XYChartAnimationItem<T,U>::XYChartAnimationItem(U *series,QGraphicsItem *parent):
T(series,parent),
m_animation(new XYChartAnimator<T,U>(this,this)),
m_dirty(false)
{
}
template <class T, class U>
XYChartAnimationItem<T,U>::~XYChartAnimationItem()
{
}
template <class T, class U>
void XYChartAnimationItem<T,U>::updatePoints(QVector<QPointF>& newPoints)
{
QVector<QPointF> oldPoints = T::points();
if(newPoints.count()==0) return;
Michal Klocek
Adding zoom in out animation support
r513
bool empty = oldPoints.count()==0;
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 oldPoints.resize(newPoints.size());
if(m_animation->state()!=QAbstractAnimation::Stopped){
m_animation->stop();
}
m_animation->setDuration(duration);
Michal Klocek
Adding zoom in out animation support
r513 if(!empty)
m_animation->setAnimationType(XYChartAnimator<T,U>::MoveDownAnimation);
else
m_animation->setAnimationType(XYChartAnimator<T,U>::LineDrawAnimation);
m_animation->setEasingCurve(QEasingCurve::OutQuart);
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 m_animation->setKeyValueAt(0.0, qVariantFromValue(oldPoints));
m_animation->setKeyValueAt(1.0, qVariantFromValue(newPoints));
QTimer::singleShot(0,m_animation,SLOT(start()));
m_points = newPoints;
m_dirty=false;
}
template <class T, class U>
void XYChartAnimationItem<T,U>::updatePoint(QVector<QPointF>& newPoints)
{
if(m_animation->state()!=QAbstractAnimation::Stopped) {
m_animation->stop();
m_dirty=true;
}
if(m_dirty) {
m_points=newPoints;
m_dirty=false;
}
m_animation->setDuration(duration);
Michal Klocek
Sets drawline animation for all points update
r503 m_animation->setAnimationType(XYChartAnimator<T,U>::MoveDownAnimation);
Michal Klocek
Adding zoom in out animation support
r513 m_animation->setEasingCurve(QEasingCurve::OutQuart);
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 m_animation->setKeyValueAt(0.0, qVariantFromValue(m_points));
m_animation->setKeyValueAt(1.0, qVariantFromValue(newPoints));
QTimer::singleShot(0,m_animation,SLOT(start()));
}
template <class T, class U>
void XYChartAnimationItem<T,U>::animationStarted()
{
m_dirty=true;
}
QTCOMMERCIALCHART_END_NAMESPACE
#endif