##// END OF EJS Templates
Clear chart image to transparent when necessary....
Clear chart image to transparent when necessary. If there is any transparency in the background, image clear should be done every time chart is rendered to avoid artifacts from previous render. Background shape change also triggers the clear, but that is needed only once. Change-Id: If0a762d2e2e01cf3a94a5d2f6845613deb619bdd Reviewed-by: Titta Heikkala <titta.heikkala@theqtcompany.com>

File last commit:

r2845:ae12522d475c
r2850:57e4c71e5532
Show More
xyanimation.cpp
156 lines | 4.6 KiB | text/x-c | CppLexer
Titta Heikkala
Updated license headers...
r2845 /******************************************************************************
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2740 ** This file is part of the Qt Charts module.
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_BEGIN_LICENSE:COMM$
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_END_LICENSE$
**
******************************************************************************/
Jani Honkonen
Add license headers
r794
Titta Heikkala
Fix include syntax...
r2714 #include <private/xyanimation_p.h>
#include <private/xychart_p.h>
#include <QtCore/QDebug>
Michal Klocek
Animation refactor...
r530
Q_DECLARE_METATYPE(QVector<QPointF>)
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_BEGIN_NAMESPACE
Michal Klocek
Animation refactor...
r530
Titta Heikkala
Added possibility to set duration and easing curve for chart animation...
r2804 XYAnimation::XYAnimation(XYChart *item, int duration, QEasingCurve &curve)
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 : ChartAnimation(item),
m_type(NewAnimation),
m_dirty(false),
m_index(-1),
m_item(item)
Michal Klocek
Animation refactor...
r530 {
Titta Heikkala
Added possibility to set duration and easing curve for chart animation...
r2804 setDuration(duration);
setEasingCurve(curve);
Michal Klocek
Animation refactor...
r530 }
XYAnimation::~XYAnimation()
{
}
Michal Klocek
adds QLineAnimation fixes
r1271 void XYAnimation::setup(const QVector<QPointF> &oldPoints, const QVector<QPointF> &newPoints, int index)
Michal Klocek
Refactors animation handling for xyseries
r1217 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_type = NewAnimation;
if (state() != QAbstractAnimation::Stopped) {
stop();
m_dirty = false;
}
if (!m_dirty) {
m_dirty = true;
m_oldPoints = oldPoints;
}
m_newPoints = newPoints;
int x = m_oldPoints.count();
int y = m_newPoints.count();
Miikka Heikkinen
Fix crash when adding/removing points during animation...
r2489 int diff = x - y;
int requestedDiff = oldPoints.count() - y;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097
Miikka Heikkinen
Fix crash when adding/removing points during animation...
r2489 // m_oldPoints can be whatever between 0 and actual points count if new animation setup
// interrupts a previous animation, so only do remove and add animations if both
// stored diff and requested diff indicate add or remove. Also ensure that index is not
// invalid.
if (diff == 1 && requestedDiff == 1 && index >= 0 && y > 0 && index <= y) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 //remove point
m_newPoints.insert(index, index > 0 ? newPoints[index - 1] : newPoints[index]);
m_index = index;
m_type = RemovePointAnimation;
}
Miikka Heikkinen
Fix crash when adding/removing points during animation...
r2489 if (diff == -1 && requestedDiff == -1 && index >= 0 && index <= x) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 //add point
m_oldPoints.insert(index, index > 0 ? newPoints[index - 1] : newPoints[index]);
m_index = index;
m_type = AddPointAnimation;
}
x = m_oldPoints.count();
y = m_newPoints.count();
if (x != y)
m_type = NewAnimation;
else if (m_type == NewAnimation)
m_type = ReplacePointAnimation;
Michal Klocek
Refactors axis animation, line animations
r1241
setKeyValueAt(0.0, qVariantFromValue(m_oldPoints));
setKeyValueAt(1.0, qVariantFromValue(m_newPoints));
Michal Klocek
Animation refactor...
r530 }
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
Michal Klocek
Animation refactor...
r530 {
Jani Honkonen
Fix deprecation errors from Qt5
r2241 QVector<QPointF> startVector = qvariant_cast<QVector<QPointF> >(start);
QVector<QPointF> endVector = qvariant_cast<QVector<QPointF> >(end);
Michal Klocek
Animation refactor...
r530 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
Michal Klocek
Refactors axis animation, line animations
r1241 case ReplacePointAnimation:
case AddPointAnimation:
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case RemovePointAnimation: {
if (startVector.count() != endVector.count())
Michal Klocek
Animation refactor...
r530 break;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 for (int i = 0; i < startVector.count(); i++) {
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 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
}
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 break;
Michal Klocek
Refactors axis animation, line animations
r1241 case NewAnimation: {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 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];
}
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 break;
Marek Rosa
Animation folder formating: white spaces, brackets, etc fixed
r738 default:
qWarning() << "Unknown type of animation";
break;
Michal Klocek
Animation refactor...
r530 }
return qVariantFromValue(result);
}
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 void XYAnimation::updateCurrentValue(const QVariant &value)
Michal Klocek
Animation refactor...
r530 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (state() != QAbstractAnimation::Stopped) { //workaround
Michal Klocek
adds QLineAnimation fixes
r1271
Jani Honkonen
Fix deprecation errors from Qt5
r2241 QVector<QPointF> vector = qvariant_cast<QVector<QPointF> >(value);
Michal Klocek
Refactors animation handling for xyseries
r1217 m_item->setGeometryPoints(vector);
m_item->updateGeometry();
Michal Klocek
Refactors axis animation, line animations
r1241 m_item->setDirty(true);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_dirty = false;
Michal Klocek
adds QLineAnimation fixes
r1271
Michal Klocek
Animation refactor...
r530 }
}
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 void XYAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
Michal Klocek
Refactors axis animation, line animations
r1241 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (oldState == QAbstractAnimation::Running && newState == QAbstractAnimation::Stopped) {
if (m_item->isDirty() && m_type == RemovePointAnimation) {
if (!m_newPoints.isEmpty())
m_newPoints.remove(m_index);
m_item->setGeometryPoints(m_newPoints);
}
}
Michal Klocek
Refactors axis animation, line animations
r1241 }
#include "moc_chartanimation_p.cpp"
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_END_NAMESPACE