From ce991d3dee2664daf4976a7e9a3c9abb493be8ef 2012-03-27 10:55:49 From: Marek Rosa Date: 2012-03-27 10:55:49 Subject: [PATCH] Animation folder formating: white spaces, brackets, etc fixed --- diff --git a/src/animations/axisanimation.cpp b/src/animations/axisanimation.cpp index 1e0b6dc..178f4eb 100644 --- a/src/animations/axisanimation.cpp +++ b/src/animations/axisanimation.cpp @@ -15,7 +15,7 @@ AxisAnimation::~AxisAnimation() { } -QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const +QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const { QVector startVector = qVariantValue >(start); QVector endVecotr = qVariantValue >(end); @@ -23,7 +23,7 @@ QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant & end Q_ASSERT(startVector.count() == endVecotr.count()) ; - for(int i =0 ;i< startVector.count();i++){ + 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; } @@ -31,12 +31,12 @@ QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant & end } -void AxisAnimation::updateCurrentValue (const QVariant & value ) +void AxisAnimation::updateCurrentValue (const QVariant &value ) { - if(state()!=QAbstractAnimation::Stopped)//workaround + if (state() != QAbstractAnimation::Stopped)//workaround { QVector vector = qVariantValue >(value); - Q_ASSERT(vector.count()!=0); + Q_ASSERT(vector.count() != 0); m_axis->setLayout(vector); } diff --git a/src/animations/axisanimation_p.h b/src/animations/axisanimation_p.h index 2728db2..cf538d8 100644 --- a/src/animations/axisanimation_p.h +++ b/src/animations/axisanimation_p.h @@ -13,10 +13,10 @@ public: AxisAnimation(Axis *axis); ~AxisAnimation(); protected: - virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; - virtual void updateCurrentValue (const QVariant & value ); + virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress ) const; + virtual void updateCurrentValue(const QVariant &value ); private: - Axis* m_axis; + Axis *m_axis; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/baranimation.cpp b/src/animations/baranimation.cpp index d1dea67..3590332 100644 --- a/src/animations/baranimation.cpp +++ b/src/animations/baranimation.cpp @@ -21,13 +21,13 @@ BarAnimation::~BarAnimation() QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const { - QVector startVector = qVariantValue > (from); - QVector endVector = qVariantValue > (to); + QVector startVector = qVariantValue >(from); + QVector endVector = qVariantValue >(to); QVector result; Q_ASSERT(startVector.count() == endVector.count()) ; - for(int i =0 ;i< startVector.count();i++){ + for(int i = 0; i < startVector.count(); i++) { qreal w = endVector[i].width(); qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); qreal x = endVector[i].topLeft().x(); diff --git a/src/animations/baranimation_p.h b/src/animations/baranimation_p.h index 9823557..7054390 100644 --- a/src/animations/baranimation_p.h +++ b/src/animations/baranimation_p.h @@ -19,14 +19,14 @@ public: ~BarAnimation(); public: // from QVariantAnimation - virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; - virtual void updateCurrentValue (const QVariant & value ); + virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; + virtual void updateCurrentValue(const QVariant &value); public Q_SLOTS: private: BarChartItem *m_item; - QHash m_animations; + QHash m_animations; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/chartanimation_p.h b/src/animations/chartanimation_p.h index 4599f60..44c4e11 100644 --- a/src/animations/chartanimation_p.h +++ b/src/animations/chartanimation_p.h @@ -10,7 +10,7 @@ class ChartAnimation: public QVariantAnimation { public: enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; - ChartAnimation(QObject* parent=0):QVariantAnimation(parent),m_type(MoveDownAnimation){}; + ChartAnimation(QObject* parent=0):QVariantAnimation(parent), m_type(MoveDownAnimation){} void setAnimationType(Animation type){ m_type=type; } diff --git a/src/animations/chartanimator.cpp b/src/animations/chartanimator.cpp index bf21756..176d668 100644 --- a/src/animations/chartanimator.cpp +++ b/src/animations/chartanimator.cpp @@ -19,7 +19,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE const static int duration = 1000; -ChartAnimator::ChartAnimator(QObject *parent):QObject(parent),m_state(ShowState) +ChartAnimator::ChartAnimator(QObject *parent):QObject(parent), + m_state(ShowState) { } @@ -27,153 +28,143 @@ ChartAnimator::~ChartAnimator() { } -void ChartAnimator::addAnimation(Axis* item) +void ChartAnimator::addAnimation(Axis *item) { - ChartAnimation* animation = m_animations.value(item); + ChartAnimation *animation = m_animations.value(item); - if(!animation) { + if (!animation) { animation = new AxisAnimation(item); - m_animations.insert(item,animation); + m_animations.insert(item, animation); } item->setAnimator(this); } -void ChartAnimator::addAnimation(SplineChartItem* item) +void ChartAnimator::addAnimation(SplineChartItem *item) { - ChartAnimation* animation = m_animations.value(item); + ChartAnimation *animation = m_animations.value(item); - if(!animation) { + if (!animation) { animation = new SplineAnimation(item); - m_animations.insert(item,animation); + m_animations.insert(item, animation); } item->setAnimator(this); } -void ChartAnimator::addAnimation(ScatterChartItem* item) +void ChartAnimator::addAnimation(ScatterChartItem *item) { - ChartAnimation* animation = m_animations.value(item); + ChartAnimation *animation = m_animations.value(item); - if(!animation) { + if (!animation) { animation = new XYAnimation(item); - m_animations.insert(item,animation); + m_animations.insert(item, animation); } item->setAnimator(this); } -void ChartAnimator::addAnimation(LineChartItem* item) +void ChartAnimator::addAnimation(LineChartItem *item) { - ChartAnimation* animation = m_animations.value(item); + ChartAnimation *animation = m_animations.value(item); - if(!animation) { + if (!animation) { animation = new XYAnimation(item); - m_animations.insert(item,animation); + m_animations.insert(item, animation); } item->setAnimator(this); } -void ChartAnimator::addAnimation(PieChartItem* item) +void ChartAnimator::addAnimation(PieChartItem *item) { - ChartAnimation* animation = m_animations.value(item); + ChartAnimation *animation = m_animations.value(item); - if(!animation) { + if (!animation) { animation = new PieAnimation(item); - m_animations.insert(item,animation); + m_animations.insert(item, animation); } item->setAnimator(this); } -void ChartAnimator::addAnimation(BarChartItem* item) +void ChartAnimator::addAnimation(BarChartItem *item) { - ChartAnimation* animation = m_animations.value(item); + ChartAnimation *animation = m_animations.value(item); - if(!animation) { + if (!animation) { animation = new BarAnimation(item); - m_animations.insert(item,animation); + m_animations.insert(item, animation); } item->setAnimator(this); } -void ChartAnimator::removeAnimation(Chart* item) +void ChartAnimator::removeAnimation(Chart *item) { item->setAnimator(0); m_animations.remove(item); } -void ChartAnimator::updateLayout(Axis* item , QVector& newLayout) +void ChartAnimator::updateLayout(Axis *item , QVector &newLayout) { - AxisAnimation* animation = static_cast(m_animations.value(item)); + AxisAnimation *animation = static_cast(m_animations.value(item)); Q_ASSERT(animation); QVector oldLayout = item->layout(); - if(newLayout.count()==0) return; - - switch(m_state) - { - case ZoomOutState: { - QRectF rect = item->geometry(); - oldLayout.resize(newLayout.count()); - - for(int i=0,j=oldLayout.count()-1;i<(oldLayout.count()+1)/2;i++,j--) - { - oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.bottom(); - oldLayout[j]= item->axisType()==Axis::X_AXIS?rect.right():rect.top(); - } - } - break; - case ZoomInState: { - int index = qMin(oldLayout.count()*(item->axisType()==Axis::X_AXIS?m_point.x():(1 -m_point.y())),newLayout.count()-1.0); - oldLayout.resize(newLayout.count()); - - for(int i=0;i0;i--,j--) - { - oldLayout[i]= oldLayout[j]; - } - } - break; - default: { - oldLayout.resize(newLayout.count()); - QRectF rect = item->geometry(); - for(int i=0, j=oldLayout.count()-1;iaxisType()==Axis::X_AXIS?rect.left():rect.top(); - } - } - break; - } - - - if(animation->state()!=QAbstractAnimation::Stopped) { - animation->stop(); + if (newLayout.count() == 0) + return; + + switch (m_state) { + case ZoomOutState: { + QRectF rect = item->geometry(); + oldLayout.resize(newLayout.count()); + + for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; i++, j--) { + oldLayout[i] = item->axisType() == Axis::X_AXIS ? rect.left() : rect.bottom(); + oldLayout[j] = item->axisType() == Axis::X_AXIS ? rect.right() : rect.top(); + } + } + break; + case ZoomInState: { + int index = qMin(oldLayout.count() * (item->axisType() == Axis::X_AXIS ? m_point.x() : (1 - m_point.y())), newLayout.count() - 1.0); + oldLayout.resize(newLayout.count()); + + for(int i = 0; i < oldLayout.count(); i++) + oldLayout[i]= oldLayout[index]; } + break; + case ScrollDownState: + case ScrollRightState: { + oldLayout.resize(newLayout.count()); + + for(int i = 0, j = i + 1; i < oldLayout.count() - 1; i++, j++) + oldLayout[i]= oldLayout[j]; + } + break; + case ScrollUpState: + case ScrollLeftState: { + oldLayout.resize(newLayout.count()); + + for(int i = oldLayout.count() - 1, j = i - 1; i > 0; i--, j--) + oldLayout[i]= oldLayout[j]; + } + break; + default: { + oldLayout.resize(newLayout.count()); + QRectF rect = item->geometry(); + for(int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); i++, j--) + oldLayout[i] = item->axisType() == Axis::X_AXIS ? rect.left() : rect.top(); + } + break; + } + + + if (animation->state() != QAbstractAnimation::Stopped) + animation->stop(); animation->setDuration(duration); animation->setEasingCurve(QEasingCurve::OutQuart); @@ -182,107 +173,107 @@ void ChartAnimator::updateLayout(Axis* item , QVector& newLayout) animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); - QTimer::singleShot(0,animation,SLOT(start())); + QTimer::singleShot(0, animation, SLOT(start())); } -void ChartAnimator::updateLayout(SplineChartItem* item, QVector& oldPoints ,QVector& newPoints, QVector& oldControlPoints, QVector& newControlPoints,int index) +void ChartAnimator::updateLayout(SplineChartItem *item, QVector &oldPoints, QVector &newPoints, QVector &oldControlPoints, QVector &newControlPoints, int index) { - SplineAnimation* animation = static_cast(m_animations.value(item)); + SplineAnimation *animation = static_cast(m_animations.value(item)); Q_ASSERT(animation); - if(newPoints.count()<2 || newControlPoints.count()<2) return; + if (newPoints.count() < 2 || newControlPoints.count() < 2) + return; - bool empty = oldPoints.count()==0; + bool empty = oldPoints.count() == 0; - if(animation->state()!=QAbstractAnimation::Stopped) { - animation->stop(); - } + if (animation->state() != QAbstractAnimation::Stopped) + animation->stop(); animation->setDuration(duration); - if(!empty) - animation->setAnimationType(ChartAnimation::MoveDownAnimation); + if (!empty) + animation->setAnimationType(ChartAnimation::MoveDownAnimation); else - animation->setAnimationType(ChartAnimation::LineDrawAnimation); + animation->setAnimationType(ChartAnimation::LineDrawAnimation); animation->setEasingCurve(QEasingCurve::OutQuart); - animation->setValues(oldPoints,newPoints,oldControlPoints,newControlPoints,index); + animation->setValues(oldPoints, newPoints, oldControlPoints, newControlPoints, index); - QTimer::singleShot(0,animation,SLOT(start())); + QTimer::singleShot(0, animation, SLOT(start())); } -void ChartAnimator::updateLayout(XYChartItem* item, QVector& oldPoints , QVector& newPoints, int index) +void ChartAnimator::updateLayout(XYChartItem *item, QVector &oldPoints, QVector &newPoints, int index) { - XYAnimation* animation = static_cast(m_animations.value(item)); + XYAnimation *animation = static_cast(m_animations.value(item)); Q_ASSERT(animation); - if(newPoints.count()==0) return; + if (newPoints.count() == 0) + return; - bool empty = oldPoints.count()==0; + bool empty = oldPoints.count() == 0; - if(animation->state()!=QAbstractAnimation::Stopped) { + if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); - } animation->setDuration(duration); - if(!empty) - animation->setAnimationType(ChartAnimation::MoveDownAnimation); + if (!empty) + animation->setAnimationType(ChartAnimation::MoveDownAnimation); else - animation->setAnimationType(ChartAnimation::LineDrawAnimation); + animation->setAnimationType(ChartAnimation::LineDrawAnimation); animation->setEasingCurve(QEasingCurve::OutQuart); - animation->setValues(oldPoints,newPoints,index); + animation->setValues(oldPoints, newPoints, index); - QTimer::singleShot(0,animation,SLOT(start())); + QTimer::singleShot(0, animation, SLOT(start())); } -void ChartAnimator::addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) +void ChartAnimator::addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) { - PieAnimation* animation = static_cast(m_animations.value(item)); + PieAnimation *animation = static_cast(m_animations.value(item)); Q_ASSERT(animation); animation->addSlice(slice, sliceData, isEmpty); } -void ChartAnimator::removeAnimation(PieChartItem* item, QPieSlice *slice) +void ChartAnimator::removeAnimation(PieChartItem *item, QPieSlice *slice) { - PieAnimation* animation = static_cast(m_animations.value(item)); + PieAnimation *animation = static_cast(m_animations.value(item)); Q_ASSERT(animation); animation->removeSlice(slice); } -void ChartAnimator::updateLayout(PieChartItem* item, const PieLayout &layout) +void ChartAnimator::updateLayout(PieChartItem *item, const PieLayout &layout) { - PieAnimation* animation = static_cast(m_animations.value(item)); + PieAnimation *animation = static_cast(m_animations.value(item)); Q_ASSERT(animation); animation->updateValues(layout); } -void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData) +void ChartAnimator::updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData) { - PieAnimation* animation = static_cast(m_animations.value(item)); + PieAnimation *animation = static_cast(m_animations.value(item)); Q_ASSERT(animation); animation->updateValue(slice, sliceData); } -void ChartAnimator::updateLayout(BarChartItem* item, const QVector &oldLayout, const QVector &newLayout) +void ChartAnimator::updateLayout(BarChartItem *item, const QVector &oldLayout, const QVector &newLayout) { - BarAnimation* animation = static_cast(m_animations.value(item)); + BarAnimation *animation = static_cast(m_animations.value(item)); Q_ASSERT(animation); animation->setDuration(duration); animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); - QTimer::singleShot(0,animation,SLOT(start())); + QTimer::singleShot(0, animation, SLOT(start())); } -void ChartAnimator::setState(State state,const QPointF& point) +void ChartAnimator::setState(State state, const QPointF &point) { - m_state=state; - m_point=point; + m_state = state; + m_point = point; } QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/chartanimator_p.h b/src/animations/chartanimator_p.h index dd10cfd..8f2990e 100644 --- a/src/animations/chartanimator_p.h +++ b/src/animations/chartanimator_p.h @@ -19,35 +19,35 @@ class XYChartItem; class ChartAnimator : public QObject { public: - enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState,ScrollRightState,ZoomInState,ZoomOutState}; + enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState, ScrollRightState, ZoomInState, ZoomOutState}; ChartAnimator(QObject *parent = 0); virtual ~ChartAnimator(); - void addAnimation(Axis* item); - void addAnimation(PieChartItem* item); - void addAnimation(ScatterChartItem* item); - void addAnimation(LineChartItem* item); - void addAnimation(SplineChartItem* item); - void addAnimation(BarChartItem* item); - void removeAnimation(Chart* item); + void addAnimation(Axis *item); + void addAnimation(PieChartItem *item); + void addAnimation(ScatterChartItem *item); + void addAnimation(LineChartItem *item); + void addAnimation(SplineChartItem *item); + void addAnimation(BarChartItem *item); + void removeAnimation(Chart *item); void animationStarted(); - void updateLayout(XYChartItem* item, QVector& oldLayout,QVector& newLayout,int index); - void updateLayout(SplineChartItem* item, QVector& oldPoints , QVector& newPoints, QVector& oldControlPoints, QVector& newContorlPoints,int index); - void updateLayout(Axis* item, QVector& layout); + void updateLayout(XYChartItem *item, QVector &oldLayout, QVector &newLayout, int index); + void updateLayout(SplineChartItem *item, QVector &oldPoints, QVector &newPoints, QVector &oldControlPoints, QVector &newContorlPoints, int index); + void updateLayout(Axis *item, QVector &layout); - void addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty); - void removeAnimation(PieChartItem* item, QPieSlice *slice); - void updateLayout(PieChartItem* item, const PieLayout &layout); - void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData); + void addAnimation(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty); + void removeAnimation(PieChartItem *item, QPieSlice *slice); + void updateLayout(PieChartItem *item, const PieLayout &layout); + void updateLayout(PieChartItem *item, QPieSlice *slice, const PieSliceData &sliceData); - void updateLayout(BarChartItem* item, const QVector &oldLayout, const QVector &newLayout); + void updateLayout(BarChartItem *item, const QVector &oldLayout, const QVector &newLayout); - void setState(State state,const QPointF& point = QPointF()); + void setState(State state,const QPointF &point = QPointF()); private: - QMap m_animations; + QMap m_animations; State m_state; QPointF m_point; }; diff --git a/src/animations/pieanimation.cpp b/src/animations/pieanimation.cpp index 7e09615..33c0041 100644 --- a/src/animations/pieanimation.cpp +++ b/src/animations/pieanimation.cpp @@ -18,7 +18,7 @@ PieAnimation::~PieAnimation() void PieAnimation::updateValues(const PieLayout &newValues) { - foreach (QPieSlice* s, newValues.keys()) + foreach (QPieSlice *s, newValues.keys()) updateValue(s, newValues.value(s)); } @@ -45,7 +45,7 @@ void PieAnimation::addSlice(QPieSlice *slice, const PieSliceData &sliceData, boo if (isEmpty) startValue.m_startAngle = 0; else - startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan/2); + startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan / 2); startValue.m_angleSpan = 0; animation->setValue(startValue, sliceData); @@ -81,7 +81,7 @@ void PieAnimation::updateCurrentValue(const QVariant &) void PieAnimation::destroySliceAnimationComplete() { - PieSliceAnimation *animation = static_cast(sender()); + PieSliceAnimation *animation = static_cast(sender()); QPieSlice *slice = m_animations.key(animation); m_item->destroySlice(slice); delete m_animations.take(slice); diff --git a/src/animations/pieanimation_p.h b/src/animations/pieanimation_p.h index 600b27a..ac9666d 100644 --- a/src/animations/pieanimation_p.h +++ b/src/animations/pieanimation_p.h @@ -29,7 +29,7 @@ public Q_SLOTS: private: PieChartItem *m_item; - QHash m_animations; + QHash m_animations; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/splineanimation.cpp b/src/animations/splineanimation.cpp index 99e15a9..25f8467 100644 --- a/src/animations/splineanimation.cpp +++ b/src/animations/splineanimation.cpp @@ -7,8 +7,8 @@ Q_DECLARE_METATYPE(SplineVector) QTCOMMERCIALCHART_BEGIN_NAMESPACE SplineAnimation::SplineAnimation(SplineChartItem* item):ChartAnimation(item), -m_item(item), -m_dirty(true) + m_item(item), + m_dirty(true) { } @@ -16,45 +16,45 @@ SplineAnimation::~SplineAnimation() { } -void SplineAnimation::setValues(QVector& oldPoints,QVector& newPoints,QVector& oldControlPoints,QVector& newControlPoints,int index) +void SplineAnimation::setValues(QVector &oldPoints, QVector &newPoints, QVector &oldControlPoints, QVector &newControlPoints, int index) { int x = oldPoints.count(); int y = newPoints.count(); - Q_ASSERT(newPoints.count()*2-2 == newControlPoints.count()); + Q_ASSERT(newPoints.count() * 2 - 2 == newControlPoints.count()); - if(x!=y && abs(x-y)!=1) { - m_oldSpline.first= newPoints; - m_oldSpline.second= newControlPoints; + if (x != y && abs(x - y) != 1) { + m_oldSpline.first = newPoints; + m_oldSpline.second = newControlPoints; oldPoints.resize(newPoints.size()); oldControlPoints.resize(newControlPoints.size()); SplineVector oldPair; - oldPair.first=oldPoints; - oldPair.second=oldControlPoints; + oldPair.first = oldPoints; + oldPair.second = oldControlPoints; SplineVector newPair; - newPair.first=newPoints; - newPair.second=newControlPoints; + newPair.first = newPoints; + newPair.second = newControlPoints; setKeyValueAt(0.0, qVariantFromValue(oldPair)); setKeyValueAt(1.0, qVariantFromValue(newPair)); - m_dirty=false; + m_dirty = false; } else { if(m_dirty) { m_oldSpline.first = oldPoints; m_oldSpline.second = oldControlPoints; - m_dirty=false; + m_dirty = false; } oldPoints = newPoints; oldControlPoints = newControlPoints; - if (yx) { - m_oldSpline.first.insert(index,x>0?m_oldSpline.first[index-1]:newPoints[index]); //add - m_oldSpline.second.insert((index-1)*2,x>1?m_oldSpline.second[(index-2)*2]:newControlPoints[(index-1)*2]); //add - m_oldSpline.second.insert((index-1)*2+1,x>1?m_oldSpline.second[(index-2)*2+1]:newControlPoints[(index-1)*2+1]); //add + if (y > x) { + m_oldSpline.first.insert(index, x > 0 ? m_oldSpline.first[index-1] : newPoints[index]); //add + m_oldSpline.second.insert((index - 1) * 2, x > 1 ? m_oldSpline.second[(index-2)*2] : newControlPoints[(index - 1) * 2]); //add + m_oldSpline.second.insert((index - 1) * 2 + 1, x > 1 ? m_oldSpline.second[(index - 2) * 2 + 1] : newControlPoints[(index - 1) * 2 + 1]); //add } SplineVector newPair; newPair.first=newPoints; @@ -65,7 +65,7 @@ void SplineAnimation::setValues(QVector& oldPoints,QVector& ne } } -QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const +QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const { SplineVector startPair = qVariantValue< SplineVector >(start); @@ -73,53 +73,55 @@ QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant & e SplineVector result; - switch(m_type) { - - case MoveDownAnimation: { + switch (m_type) { - if(startPair.first.count() != endPair.first.count()) break; - Q_ASSERT(startPair.first.count()*2-2 == startPair.second.count()); - Q_ASSERT(endPair.first.count()*2-2 == endPair.second.count()); - for(int i =0;i< endPair.first.count();i++) { - qreal x = startPair.first[i].x() + ((endPair.first[i].x()- startPair.first[i].x()) * progress); - qreal y = startPair.first[i].y() + ((endPair.first[i].y()- startPair.first[i].y()) * progress); - result.first << QPointF(x,y); - if(i +1 >= endPair.first.count()) continue; - x = startPair.second[i*2].x() + ((endPair.second[i*2].x()- startPair.second[i*2].x()) * progress); - y = startPair.second[i*2].y() + ((endPair.second[i*2].y()- startPair.second[i*2].y()) * progress); - result.second << QPoint(x,y); - x = startPair.second[i*2+1].x() + ((endPair.second[i*2+1].x()- startPair.second[i*2+1].x()) * progress); - y = startPair.second[i*2+1].y() + ((endPair.second[i*2+1].y()- startPair.second[i*2+1].y()) * progress); - result.second << QPoint(x,y); - } - - } + case MoveDownAnimation: { + if (startPair.first.count() != endPair.first.count()) break; - case LineDrawAnimation:{ - Q_ASSERT(endPair.first.count()*2-2 == endPair.second.count()); - int count = endPair.first.count()* qBound(0.0, progress, 1.0); - for(int i =0;i= endPair.first.count()) + continue; + x = startPair.second[i * 2].x() + ((endPair.second[i * 2].x() - startPair.second[i * 2].x()) * progress); + y = startPair.second[i * 2].y() + ((endPair.second[i * 2].y() - startPair.second[i * 2].y()) * progress); + result.second << QPoint(x,y); + x = startPair.second[i * 2 + 1].x() + ((endPair.second[i * 2 + 1].x() - startPair.second[i * 2 + 1].x()) * progress); + y = startPair.second[i * 2 + 1].y() + ((endPair.second[i * 2 + 1].y() - startPair.second[i * 2 + 1].y()) * progress); + result.second << QPoint(x,y); } - break; - default: - qWarning()<<"Unknow type of animation"; - break; + + } + break; + case LineDrawAnimation:{ + Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count()); + int count = endPair.first.count()* qBound(0.0, progress, 1.0); + for(int i = 0; i < count; i++) { + result.first << endPair.first[i]; + if(i + 1 == count) + break; + result.second << endPair.second[2 * i]; + result.second << endPair.second[2 * i + 1]; + } + } + break; + default: + qWarning() << "Unknow type of animation"; + break; } return qVariantFromValue(result); } -void SplineAnimation::updateCurrentValue (const QVariant & value ) +void SplineAnimation::updateCurrentValue (const QVariant &value ) { - if(state()!=QAbstractAnimation::Stopped){ //workaround - m_dirty=true; + if (state() != QAbstractAnimation::Stopped) { //workaround + m_dirty = true; QPair, QVector > pair = qVariantValue< QPair< QVector, QVector > >(value); - m_item->setLayout(pair.first,pair.second); + m_item->setLayout(pair.first, pair.second); } } diff --git a/src/animations/splineanimation_p.h b/src/animations/splineanimation_p.h index 33b2f64..2434d0a 100644 --- a/src/animations/splineanimation_p.h +++ b/src/animations/splineanimation_p.h @@ -7,7 +7,6 @@ typedef QPair, QVector > SplineVector; QTCOMMERCIALCHART_BEGIN_NAMESPACE - class SplineChartItem; class SplineAnimation : public ChartAnimation @@ -16,15 +15,15 @@ public: SplineAnimation(SplineChartItem* item); ~SplineAnimation(); - void setValues(QVector& oldPoints,QVector& newPoints,QVector& oldContorlPoints,QVector& newControlPoints,int index); + void setValues(QVector &oldPoints, QVector &newPoints, QVector &oldContorlPoints, QVector &newControlPoints, int index); protected: - QVariant interpolated(const QVariant &start, const QVariant & end, qreal progress ) const; - void updateCurrentValue (const QVariant & value ); + QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const; + void updateCurrentValue(const QVariant &value); private: SplineVector m_oldSpline; - SplineChartItem* m_item; + SplineChartItem *m_item; bool m_dirty; }; diff --git a/src/animations/xyanimation.cpp b/src/animations/xyanimation.cpp index 56b5fc5..1254180 100644 --- a/src/animations/xyanimation.cpp +++ b/src/animations/xyanimation.cpp @@ -15,71 +15,72 @@ XYAnimation::~XYAnimation() { } -void XYAnimation::setValues(QVector& oldPoints,QVector& newPoints,int index) +void XYAnimation::setValues(QVector &oldPoints, QVector &newPoints, int index) { - int x = oldPoints.count(); int y = newPoints.count(); - if(x!=y && abs(x-y)!=1) { + if (x != y && abs(x - y) != 1) { m_oldPoints = newPoints; oldPoints.resize(newPoints.size()); setKeyValueAt(0.0, qVariantFromValue(oldPoints)); setKeyValueAt(1.0, qVariantFromValue(newPoints)); - m_dirty=false; + m_dirty = false; } else { - if(m_dirty) { + if (m_dirty) { m_oldPoints = oldPoints; - m_dirty=false; + m_dirty = false; } oldPoints = newPoints; - if (yx) (m_oldPoints.insert(index,x>0?m_oldPoints[index-1]:newPoints[index])); //add + if (y < x) + m_oldPoints.remove(index); //remove + if (y > x) + m_oldPoints.insert(index, x > 0 ? m_oldPoints[index-1] : newPoints[index]); //add setKeyValueAt(0.0, qVariantFromValue(m_oldPoints)); setKeyValueAt(1.0, qVariantFromValue(newPoints)); Q_ASSERT(m_oldPoints.count() == newPoints.count()); } } -QVariant XYAnimation::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const +QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const { QVector startVector = qVariantValue >(start); QVector endVector = qVariantValue >(end); QVector result; - switch(m_type) { - - case MoveDownAnimation: { - - if(startVector.count() != endVector.count()) break; + switch (m_type) { - for(int i =0;i< startVector.count();i++) { - qreal x = startVector[i].x() + ((endVector[i].x()- startVector[i].x()) * progress); - qreal y = startVector[i].y() + ((endVector[i].y()- startVector[i].y()) * progress); - result << QPointF(x,y); - } + case MoveDownAnimation: { - } + if (startVector.count() != endVector.count()) break; - case LineDrawAnimation:{ - for(int i =0;i< endVector.count()* qBound(0.0, progress, 1.0);i++) { - result << endVector[i]; - } + + for(int i = 0; i < startVector.count(); i++) { + qreal x = startVector[i].x() + ((endVector[i].x() - startVector[i].x()) * progress); + qreal y = startVector[i].y() + ((endVector[i].y() - startVector[i].y()) * progress); + result << QPointF(x, y); } - break; - default: - qWarning()<<"Unknown type of animation"; - break; + + } + break; + case LineDrawAnimation: { + for(int i = 0; i < endVector.count() * qBound(0.0, progress, 1.0); i++) + result << endVector[i]; + } + break; + default: + qWarning() << "Unknown type of animation"; + break; } return qVariantFromValue(result); } -void XYAnimation::updateCurrentValue (const QVariant & value ) +void XYAnimation::updateCurrentValue (const QVariant &value) { if(state()!=QAbstractAnimation::Stopped){ //workaround - m_dirty=true; + m_dirty = true; QVector vector = qVariantValue >(value); m_item->setLayout(vector); } diff --git a/src/animations/xyanimation_p.h b/src/animations/xyanimation_p.h index 8f575af..04b289a 100644 --- a/src/animations/xyanimation_p.h +++ b/src/animations/xyanimation_p.h @@ -10,14 +10,14 @@ class XYChartItem; class XYAnimation : public ChartAnimation { public: - enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; + enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; XYAnimation(XYChartItem *item); ~XYAnimation(); - void setValues(QVector& oldPoints,QVector& newPoints,int index); + void setValues(QVector &oldPoints, QVector &newPoints,int index); protected: - QVariant interpolated(const QVariant &start, const QVariant & end, qreal progress ) const; - void updateCurrentValue (const QVariant & value ); + QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress ) const; + void updateCurrentValue (const QVariant &value ); private: XYChartItem *m_item;