##// END OF EJS Templates
Now using percent bar series in theme demo
Now using percent bar series in theme demo

File last commit:

r476:b6fb05e4e56f
r521:1e41568aab09
Show More
linechartanimationitem.cpp
111 lines | 3.0 KiB | text/x-c | CppLexer
/ src / linechart / linechartanimationitem.cpp
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "linechartanimationitem_p.h"
Michal Klocek
Fix previous broken commit
r145 #include "linechartitem_p.h"
Michal Klocek
Refactors qchart , adds line animation...
r131 #include <QPropertyAnimation>
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 #include <QTimer>
Q_DECLARE_METATYPE(QVector<QPointF>)
Michal Klocek
Refactors qchart , adds line animation...
r131
QTCOMMERCIALCHART_BEGIN_NAMESPACE
const static int duration = 500;
Michal Klocek
Refactor domain model...
r439 LineChartAnimationItem::LineChartAnimationItem(QLineSeries* series,QGraphicsItem *parent):
LineChartItem(series,parent),
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 m_animation(new LineChartAnimatator(this,this)),
m_dirty(false)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
}
LineChartAnimationItem::~LineChartAnimationItem()
{
}
Michal Klocek
Refactor line spline to common xyline...
r465 void LineChartAnimationItem::updatePoints(QVector<QPointF>& newPoints)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactors linechart update calls
r464 QVector<QPointF> oldPoints = points();
Michal Klocek
Refactor line spline to common xyline...
r465 LineChartItem::updatePoints(newPoints);
Michal Klocek
Refactors linechart update calls
r464
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 if(newPoints.count()==0) return;
oldPoints.resize(newPoints.size());
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 if(m_animation->state()!=QAbstractAnimation::Stopped){
m_animation->stop();
}
m_animation->setDuration(duration);
m_animation->setEasingCurve(QEasingCurve::InOutBack);
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;
Michal Klocek
Refactors linechart update calls
r464
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Refactors linechart update calls
r464 void LineChartAnimationItem::updatePoint(int index,QPointF& newPoint)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactors linechart update calls
r464
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 if(m_animation->state()!=QAbstractAnimation::Stopped){
m_animation->stop();
m_dirty=true;
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391
if(m_dirty){
Michal Klocek
Refactors linechart update calls
r464 m_points=points();
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 m_dirty=false;
}
Michal Klocek
Refactors linechart update calls
r464 LineChartItem::updatePoint(index,newPoint);
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391
m_animation->setDuration(duration);
m_animation->setEasingCurve(QEasingCurve::InOutBack);
m_animation->setKeyValueAt(0.0, qVariantFromValue(m_points));
Michal Klocek
Refactors linechart update calls
r464 m_animation->setKeyValueAt(1.0, qVariantFromValue( points()));
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QTimer::singleShot(0,this,SLOT(startAnimation()));
Michal Klocek
Refactors linechart update calls
r464
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 void LineChartAnimationItem::startAnimation()
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 m_dirty=true;
m_animation->start();
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 LineChartAnimatator::LineChartAnimatator(LineChartAnimationItem *item , QObject *parent):QVariantAnimation(parent),
m_item(item)
Michal Klocek
Rewrite animation hadnling in line series...
r389 {
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 }
Michal Klocek
Rewrite animation hadnling in line series...
r389
LineChartAnimatator::~LineChartAnimatator()
{
}
QVariant LineChartAnimatator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const
{
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start);
QVector<QPointF> endVecotr = qVariantValue<QVector<QPointF> >(end);
QVector<QPointF> result;
Michal Klocek
Rewrite animation hadnling in line series...
r389 Q_ASSERT(startVector.count() == endVecotr.count());
for(int i =0 ;i< startVector.count();i++){
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 qreal x = startVector[i].x() + ((endVecotr[i].x()- startVector[i].x()) * progress);//qBound(0.0, progress, 1.0));
qreal y = startVector[i].y() + ((endVecotr[i].y()- startVector[i].y()) * progress);//qBound(0.0, progress, 1.0));
result << QPointF(x,y);
Michal Klocek
Rewrite animation hadnling in line series...
r389 }
return qVariantFromValue(result);
}
void LineChartAnimatator::updateCurrentValue (const QVariant & value )
{
Michal Klocek
Fix commit 7b90ec69ce9a3353820d295c222ef3f79537484d
r391 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
Michal Klocek
Refactors linechart update calls
r464 if(state()!=QAbstractAnimation::Stopped){ //workaround
m_item->setGeometry(vector);
}
Michal Klocek
Rewrite animation hadnling in line series...
r389 }
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "moc_linechartanimationitem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE