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

File last commit:

r513:c1d8fdd92b71
r521:1e41568aab09
Show More
axisanimationitem.cpp
107 lines | 2.8 KiB | text/x-c | CppLexer
/ src / axis / axisanimationitem.cpp
Michal Klocek
Refactors axis layout managment...
r291 #include "axisanimationitem_p.h"
Michal Klocek
Clean up axis animation code
r393 #include <QTimer>
Michal Klocek
Refactors axis layout managment...
r291
Q_DECLARE_METATYPE(QVector<qreal>)
QTCOMMERCIALCHART_BEGIN_NAMESPACE
const static int duration = 500;
Michal Klocek
Refactor domain model...
r439 AxisAnimationItem::AxisAnimationItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) :
AxisItem(axis,type,parent),
Michal Klocek
Clean up axis animation code
r393 m_animation(new AxisAnimator(this,this))
Michal Klocek
Refactors axis layout managment...
r291 {
}
AxisAnimationItem::~AxisAnimationItem()
{
}
Michal Klocek
Axis refactoring to support better barcharts
r502 void AxisAnimationItem::updateLayout(QVector<qreal>& newLayout)
Michal Klocek
Refactors axis layout managment...
r291 {
Michal Klocek
Fix grid animation to do not go out of bound
r504
Michal Klocek
Refacotr axisitem to handle ticks changes
r452 QVector<qreal> oldLayout = layout();
Michal Klocek
Clean up axis animation code
r393 if(newLayout.count()==0) return;
Michal Klocek
Fix grid animation to do not go out of bound
r504
Michal Klocek
Adding zoom in out animation support
r513 if(zoomFactor()<0) {
Michal Klocek
Fix grid animation to do not go out of bound
r504
Michal Klocek
Adding zoom in out animation support
r513 QRectF rect = geometry();
oldLayout.resize(newLayout.count());
Michal Klocek
Clean up axis animation code
r393
Michal Klocek
Adding zoom in out animation support
r513 for(int i=0,j=oldLayout.count()-1;i<(oldLayout.count()+1)/2;i++,j--)
{
oldLayout[i]= axisType()==X_AXIS?rect.left():rect.bottom();
oldLayout[j]= axisType()==X_AXIS?rect.right():rect.top();
}
}
else {
int index = qMin(oldLayout.count()*zoomFactor(),newLayout.count()-1.0);
oldLayout.resize(newLayout.count());
for(int i=0;i<oldLayout.count();i++)
{
oldLayout[i]= oldLayout[index]; //axisType()==X_AXIS?rect.center.x():rect.center().y();
}
Michal Klocek
Fix grid animation to do not go out of bound
r504 }
Michal Klocek
Adding zoom in out animation support
r513 if(m_animation->state()!=QAbstractAnimation::Stopped) {
m_animation->stop();
Michal Klocek
Clean up axis animation code
r393 }
m_animation->setDuration(duration);
Michal Klocek
Fix grid animation to do not go out of bound
r504 m_animation->setEasingCurve(QEasingCurve::OutQuart);
Michal Klocek
Adding zoom in out animation support
r513 QVariantAnimation::KeyValues value;
m_animation->setKeyValues(value); //workaround for wrong interpolation call
Michal Klocek
Clean up axis animation code
r393 m_animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout));
m_animation->setKeyValueAt(1.0, qVariantFromValue(newLayout));
Michal Klocek
Adding zoom in out animation support
r513
Michal Klocek
Clean up axis animation code
r393 QTimer::singleShot(0,m_animation,SLOT(start()));
Michal Klocek
Refactors axis layout managment...
r291 }
void AxisAnimationItem::setLabelsAngle(int angle)
{
AxisItem::setLabelsAngle(angle);
}
Michal Klocek
Bugfix missing parent intialization in axis animations
r303 AxisAnimator::AxisAnimator(AxisItem *axis,QObject *parent): QVariantAnimation(parent),
m_axis(axis)
Michal Klocek
Refactors axis layout managment...
r291 {
}
AxisAnimator::~AxisAnimator()
{
}
QVariant AxisAnimator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const
{
QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start);
QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end);
QVector<qreal> result;
Michal Klocek
Adding zoom in out animation support
r513
Michal Klocek
Refactors axis layout managment...
r291 Q_ASSERT(startVector.count() == endVecotr.count());
for(int i =0 ;i< startVector.count();i++){
qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0));
result << value;
}
return qVariantFromValue(result);
}
void AxisAnimator::updateCurrentValue (const QVariant & value )
{
Michal Klocek
Adding zoom in out animation support
r513 //Q_ASSERT(state()!=QAbstractAnimation::Stopped);
if(state()!=QAbstractAnimation::Stopped)//workaround
{
QVector<qreal> vector = qVariantValue<QVector<qreal> >(value);
m_axis->setLayout(vector);
}
Michal Klocek
Refactors axis layout managment...
r291 }
#include "moc_axisanimationitem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE