chartanimator.cpp
118 lines
| 3.5 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
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
|
r530 | #include "chartanimator_p.h" | ||
#include "axisanimation_p.h" | ||||
#include "xyanimation_p.h" | ||||
Michal Klocek
|
r622 | #include "splineanimation_p.h" | ||
Michal Klocek
|
r1218 | #include "xychart_p.h" | ||
Jani Honkonen
|
r618 | #include "pieanimation_p.h" | ||
sauimone
|
r671 | #include "baranimation_p.h" | ||
#include "barchartitem_p.h" | ||||
Michal Klocek
|
r560 | #include "areachartitem_p.h" | ||
Michal Klocek
|
r622 | #include "splinechartitem_p.h" | ||
#include "scatterchartitem_p.h" | ||||
Michal Klocek
|
r1241 | #include "chartaxis_p.h" | ||
Michal Klocek
|
r530 | #include <QTimer> | ||
Q_DECLARE_METATYPE(QVector<QPointF>) | ||||
Q_DECLARE_METATYPE(QVector<qreal>) | ||||
sauimone
|
r681 | Q_DECLARE_METATYPE(QVector<QRectF>) | ||
Michal Klocek
|
r530 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Michal Klocek
|
r1241 | ChartAnimator::ChartAnimator(QObject *parent):QObject(parent) | ||
Michal Klocek
|
r530 | { | ||
} | ||||
ChartAnimator::~ChartAnimator() | ||||
{ | ||||
} | ||||
Marek Rosa
|
r738 | void ChartAnimator::addAnimation(PieChartItem *item) | ||
Jani Honkonen
|
r618 | { | ||
Marek Rosa
|
r738 | ChartAnimation *animation = m_animations.value(item); | ||
Jani Honkonen
|
r618 | |||
Marek Rosa
|
r738 | if (!animation) { | ||
Jani Honkonen
|
r618 | animation = new PieAnimation(item); | ||
Marek Rosa
|
r738 | m_animations.insert(item, animation); | ||
Jani Honkonen
|
r618 | } | ||
item->setAnimator(this); | ||||
} | ||||
Marek Rosa
|
r738 | void ChartAnimator::addAnimation(BarChartItem *item) | ||
sauimone
|
r671 | { | ||
Marek Rosa
|
r738 | ChartAnimation *animation = m_animations.value(item); | ||
sauimone
|
r671 | |||
Marek Rosa
|
r738 | if (!animation) { | ||
sauimone
|
r671 | animation = new BarAnimation(item); | ||
Marek Rosa
|
r738 | m_animations.insert(item, animation); | ||
sauimone
|
r671 | } | ||
item->setAnimator(this); | ||||
} | ||||
Marek Rosa
|
r738 | void ChartAnimator::removeAnimation(Chart *item) | ||
Michal Klocek
|
r530 | { | ||
item->setAnimator(0); | ||||
m_animations.remove(item); | ||||
} | ||||
Jani Honkonen
|
r1074 | void ChartAnimator::addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) | ||
Jani Honkonen
|
r618 | { | ||
Marek Rosa
|
r738 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | ||
Jani Honkonen
|
r618 | Q_ASSERT(animation); | ||
Jani Honkonen
|
r1074 | animation->addSlice(sliceItem, sliceData, startupAnimation); | ||
Jani Honkonen
|
r621 | } | ||
Jani Honkonen
|
r1053 | void ChartAnimator::removeAnimation(PieChartItem *item, PieSliceItem *sliceItem) | ||
Jani Honkonen
|
r621 | { | ||
Marek Rosa
|
r738 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | ||
Jani Honkonen
|
r621 | Q_ASSERT(animation); | ||
Jani Honkonen
|
r1053 | animation->removeSlice(sliceItem); | ||
Jani Honkonen
|
r621 | } | ||
Jani Honkonen
|
r1074 | void ChartAnimator::updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData) | ||
Jani Honkonen
|
r618 | { | ||
Marek Rosa
|
r738 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | ||
Jani Honkonen
|
r618 | Q_ASSERT(animation); | ||
Jani Honkonen
|
r1053 | animation->updateValue(sliceItem, sliceData); | ||
Jani Honkonen
|
r618 | } | ||
Marek Rosa
|
r738 | void ChartAnimator::updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | ||
sauimone
|
r671 | { | ||
Marek Rosa
|
r738 | BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item)); | ||
Marek Rosa
|
r1418 | m_animations.remove(item); | ||
if (animation) { | ||||
animation->deleteLater(); | ||||
animation = 0; | ||||
} | ||||
addAnimation(item); | ||||
animation = static_cast<BarAnimation *>(m_animations.value(item)); | ||||
Jani Honkonen
|
r1079 | animation->setDuration(ChartAnimationDuration); | ||
sauimone
|
r681 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | ||
animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | ||||
Marek Rosa
|
r738 | QTimer::singleShot(0, animation, SLOT(start())); | ||
sauimone
|
r671 | } | ||
Michal Klocek
|
r974 | #include "moc_chartanimator_p.cpp" | ||
Michal Klocek
|
r530 | QTCOMMERCIALCHART_END_NAMESPACE | ||