chartanimator.cpp
168 lines
| 5.1 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" | ||||
sauimone
|
r1426 | #include "stackedbaranimation_p.h" | ||
#include "stackedbarchartitem_p.h" | ||||
#include "percentbaranimation_p.h" | ||||
#include "percentbarchartitem_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 | { | ||
sauimone
|
r1426 | // This can handle also GroupedBarChartItem because bars are side by side | ||
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); | ||||
} | ||||
sauimone
|
r1426 | void ChartAnimator::addAnimation(StackedBarChartItem *item) | ||
{ | ||||
ChartAnimation *animation = m_animations.value(item); | ||||
if (!animation) { | ||||
animation = new StackedBarAnimation(item); | ||||
m_animations.insert(item, animation); | ||||
} | ||||
item->setAnimator(this); | ||||
} | ||||
void ChartAnimator::addAnimation(PercentBarChartItem *item) | ||||
{ | ||||
ChartAnimation *animation = m_animations.value(item); | ||||
if (!animation) { | ||||
animation = new PercentBarAnimation(item); | ||||
m_animations.insert(item, animation); | ||||
} | ||||
item->setAnimator(this); | ||||
} | ||||
sauimone
|
r671 | |||
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 | if (animation) { | ||
sauimone
|
r1426 | m_animations.remove(item); | ||
Marek Rosa
|
r1418 | animation->deleteLater(); | ||
animation = 0; | ||||
sauimone
|
r1426 | addAnimation(item); | ||
Marek Rosa
|
r1418 | } | ||
animation = static_cast<BarAnimation *>(m_animations.value(item)); | ||||
sauimone
|
r1426 | animation->updateLayout(oldLayout,newLayout); | ||
} | ||||
void ChartAnimator::updateLayout(StackedBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | ||||
{ | ||||
StackedBarAnimation *animation = static_cast<StackedBarAnimation *>(m_animations.value(item)); | ||||
if (animation) { | ||||
m_animations.remove(item); | ||||
animation->deleteLater(); | ||||
animation = 0; | ||||
addAnimation(item); | ||||
} | ||||
animation = static_cast<StackedBarAnimation *>(m_animations.value(item)); | ||||
animation->updateLayout(oldLayout,newLayout); | ||||
sauimone
|
r671 | } | ||
sauimone
|
r1426 | void ChartAnimator::updateLayout(PercentBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | ||
{ | ||||
PercentBarAnimation *animation = static_cast<PercentBarAnimation *>(m_animations.value(item)); | ||||
if (animation) { | ||||
m_animations.remove(item); | ||||
animation->deleteLater(); | ||||
animation = 0; | ||||
addAnimation(item); | ||||
} | ||||
animation = static_cast<PercentBarAnimation *>(m_animations.value(item)); | ||||
animation->updateLayout(oldLayout,newLayout); | ||||
} | ||||
Michal Klocek
|
r974 | #include "moc_chartanimator_p.cpp" | ||
Michal Klocek
|
r530 | QTCOMMERCIALCHART_END_NAMESPACE | ||