##// END OF EJS Templates
Named all series in example applications
Named all series in example applications

File last commit:

r1220:8dbddb2db883
r1226:bae2376cbfec
Show More
xyanimation.cpp
120 lines | 3.5 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 "xyanimation_p.h"
Michal Klocek
Refactor xychartitem -> xychart
r1218 #include "xychart_p.h"
Michal Klocek
Improves build configuration...
r996 #include <QDebug>
Michal Klocek
Animation refactor...
r530
Q_DECLARE_METATYPE(QVector<QPointF>)
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactor xychartitem -> xychart
r1218 XYAnimation::XYAnimation(XYChart *item):ChartAnimation(item),
Michal Klocek
Animation refactor...
r530 m_item(item),
Michal Klocek
Refactors animation handling for xyseries
r1217 m_dirty(false),
m_type(MoveDownAnimation)
Michal Klocek
Animation refactor...
r530 {
}
XYAnimation::~XYAnimation()
{
}
Michal Klocek
Refactors animation handling for xyseries
r1217 void XYAnimation::setAnimationType(Animation type)
{
Michal Klocek
prevents flipping in xyseries animation
r1220 if (state() != QAbstractAnimation::Stopped) stop();
Michal Klocek
Refactors animation handling for xyseries
r1217 m_type=type;
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void XYAnimation::setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
Michal Klocek
Animation refactor...
r530 {
Michal Klocek
prevents flipping in xyseries animation
r1220 if (state() != QAbstractAnimation::Stopped) stop();
Michal Klocek
Improves spline interpolation...
r622 int x = oldPoints.count();
int y = newPoints.count();
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (x != y && abs(x - y) != 1) {
Michal Klocek
Improves spline interpolation...
r622 m_oldPoints = newPoints;
oldPoints.resize(newPoints.size());
setKeyValueAt(0.0, qVariantFromValue(oldPoints));
setKeyValueAt(1.0, qVariantFromValue(newPoints));
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_dirty = false;
Michal Klocek
Animation refactor...
r530 }
Michal Klocek
Improves spline interpolation...
r622 else {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (m_dirty) {
Michal Klocek
Improves spline interpolation...
r622 m_oldPoints = oldPoints;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_dirty = false;
Michal Klocek
Improves spline interpolation...
r622 }
oldPoints = newPoints;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (y < x)
m_oldPoints.remove(index); //remove
if (y > x)
m_oldPoints.insert(index, x > 0 ? m_oldPoints[index-1] : newPoints[index]); //add
Michal Klocek
Improves spline interpolation...
r622 setKeyValueAt(0.0, qVariantFromValue(m_oldPoints));
setKeyValueAt(1.0, qVariantFromValue(newPoints));
Q_ASSERT(m_oldPoints.count() == newPoints.count());
}
Michal Klocek
Animation refactor...
r530 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress ) const
Michal Klocek
Animation refactor...
r530 {
QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start);
QVector<QPointF> endVector = qVariantValue<QVector<QPointF> >(end);
QVector<QPointF> result;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 switch (m_type) {
Michal Klocek
Bugfix wrong index when points added to xychart
r602
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 case MoveDownAnimation: {
Michal Klocek
Animation refactor...
r530
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 if (startVector.count() != endVector.count())
Michal Klocek
Animation refactor...
r530 break;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738
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);
Michal Klocek
Animation refactor...
r530 }
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738
}
break;
case LineDrawAnimation: {
Michal Klocek
Krazy reported errors...
r974 for(int i = 0; i < endVector.count() * qBound(qreal(0), progress, qreal(1)); i++)
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 result << endVector[i];
}
break;
default:
qWarning() << "Unknown type of animation";
break;
Michal Klocek
Animation refactor...
r530 }
return qVariantFromValue(result);
}
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 void XYAnimation::updateCurrentValue (const QVariant &value)
Michal Klocek
Animation refactor...
r530 {
if(state()!=QAbstractAnimation::Stopped){ //workaround
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 m_dirty = true;
Michal Klocek
Animation refactor...
r530 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
Michal Klocek
Refactors animation handling for xyseries
r1217 m_item->setGeometryPoints(vector);
m_item->updateGeometry();
Michal Klocek
Animation refactor...
r530 }
}
QTCOMMERCIALCHART_END_NAMESPACE