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