diff --git a/src/animations/animations.pri b/src/animations/animations.pri index f3f7907..3fa82ec 100644 --- a/src/animations/animations.pri +++ b/src/animations/animations.pri @@ -7,7 +7,9 @@ SOURCES += \ $$PWD/pieanimation.cpp \ $$PWD/piesliceanimation.cpp \ $$PWD/splineanimation.cpp \ - $$PWD/baranimation.cpp + $$PWD/baranimation.cpp \ + $$PWD/boxplotanimation.cpp \ + animations/boxwhiskersanimation.cpp PRIVATE_HEADERS += \ $$PWD/axisanimation_p.h \ @@ -16,4 +18,6 @@ PRIVATE_HEADERS += \ $$PWD/pieanimation_p.h \ $$PWD/piesliceanimation_p.h \ $$PWD/splineanimation_p.h \ - $$PWD/baranimation_p.h + $$PWD/baranimation_p.h \ + $$PWD/boxplotanimation_p.h \ + $$PWD/boxwhiskersanimation_p.h diff --git a/src/animations/boxplotanimation.cpp b/src/animations/boxplotanimation.cpp new file mode 100644 index 0000000..57add4d --- /dev/null +++ b/src/animations/boxplotanimation.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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$ +** +****************************************************************************/ + +#include "boxplotanimation_p.h" +#include "boxplotchartitem_p.h" +#include "boxwhiskersdata_p.h" +#include "boxwhiskersanimation_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item) + // : ChartAnimation(item), + : m_item(item) +{ +} + +//BoxPlotAnimation::BoxPlotAnimation(BoxWhiskers *box) +// : ChartAnimation(box), +// m_box(box) +//{ +//} + +BoxPlotAnimation::~BoxPlotAnimation() +{ +} + +void BoxPlotAnimation::addBox(BoxWhiskers *box) +{ + BoxWhiskersAnimation *animation = new BoxWhiskersAnimation(box); + m_animations.insert(box, animation); + + BoxWhiskersData start; + start.m_median = box->m_data.m_median; + animation->setup(start, box->m_data); +} + +ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box) +{ + // TODO: Check for missing animation + return m_animations.value(box); +} + + +//#include "moc_boxplotanimation_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/boxplotanimation_p.h b/src/animations/boxplotanimation_p.h new file mode 100644 index 0000000..f4d95e9 --- /dev/null +++ b/src/animations/boxplotanimation_p.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef BOXPLOTANIMATION_P_H +#define BOXPLOTANIMATION_P_H + +#include "chartanimation_p.h" +#include "boxwhiskers_p.h" +#include "boxwhiskersdata_p.h" +#include "boxwhiskersanimation_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class BoxPlotChartItem; + +class BoxPlotAnimation /*: public ChartAnimation*/ +{ + //Q_OBJECT +public: + BoxPlotAnimation(BoxPlotChartItem *item); + ~BoxPlotAnimation(); + + void addBox(BoxWhiskers *box); + ChartAnimation *boxAnimation(BoxWhiskers *box); + +protected: + BoxPlotChartItem *m_item; + QHash m_animations; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // BOXPLOTANIMATION_P_H diff --git a/src/animations/boxwhiskersanimation.cpp b/src/animations/boxwhiskersanimation.cpp new file mode 100644 index 0000000..264f58b --- /dev/null +++ b/src/animations/boxwhiskersanimation.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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$ +** +****************************************************************************/ + +#include "boxwhiskersanimation_p.h" +#include "boxplotanimation_p.h" +#include "boxplotchartitem_p.h" +#include "boxwhiskersdata_p.h" + +Q_DECLARE_METATYPE(QVector) +Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData) +Q_DECLARE_METATYPE(qreal) + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +BoxWhiskersAnimation::BoxWhiskersAnimation(BoxPlotChartItem *item) + : ChartAnimation(item), + m_item(item) +{ + setDuration(ChartAnimationDuration); + setEasingCurve(QEasingCurve::OutQuart); +} + +BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box) + : ChartAnimation(box), + m_box(box) +{ + setDuration(ChartAnimationDuration); + setEasingCurve(QEasingCurve::OutQuart); +} + +BoxWhiskersAnimation::~BoxWhiskersAnimation() +{ +} + +QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const +{ + BoxWhiskersData startData = qvariant_cast(from); + BoxWhiskersData endData = qvariant_cast(to); + BoxWhiskersData result; + + if (endData.m_index == 1) { + //qDebug() << "endData.m_lowerExtreme = " << endData.m_lowerExtreme; + //qDebug() << "endData.m_median = " << endData.m_median; + } + + result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median); + result.m_lowerQuartile = endData.m_median + progress * (endData.m_lowerQuartile - endData.m_median); + result.m_median = endData.m_median; + result.m_upperQuartile = endData.m_median + progress * (endData.m_upperQuartile - endData.m_median); + result.m_upperExtreme = endData.m_median + progress * (endData.m_upperExtreme - endData.m_median); + result.m_index = endData.m_index; + result.m_boxItems = endData.m_boxItems; + +// result.m_lowerExtreme = endData.m_lowerExtreme; +// result.m_lowerQuartile = endData.m_lowerQuartile; +// result.m_median = endData.m_median; +// result.m_upperQuartile = endData.m_upperQuartile; +// result.m_upperExtreme = endData.m_upperExtreme; +// result.m_index = endData.m_index; +// result.m_boxItems = endData.m_boxItems; + + result.m_maxX = endData.m_maxX; + result.m_minX = endData.m_minX; + result.m_maxY = endData.m_maxY; + result.m_minY = endData.m_minY; + //result.m_domainSize = endData.m_domainSize; + + return qVariantFromValue(result); +} + +void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value) +{ + BoxWhiskersData data = qvariant_cast(value); + m_box->setLayout(data); +} + +void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData) +{ + if (endData.m_index == 0) { + qDebug() << "BoxPlotAnimation::setup m_upperExtreme" << endData.m_upperExtreme; + } + setKeyValueAt(0.0, qVariantFromValue(startData)); + setKeyValueAt(1.0, qVariantFromValue(endData)); +} + +#include "moc_boxwhiskersanimation_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE + diff --git a/src/animations/boxwhiskersanimation_p.h b/src/animations/boxwhiskersanimation_p.h new file mode 100644 index 0000000..f2dc6dc --- /dev/null +++ b/src/animations/boxwhiskersanimation_p.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef BOXWHISKERSANIMATION_P_H +#define BOXWHISKERSANIMATION_P_H + +#include "chartanimation_p.h" +#include "boxwhiskers_p.h" +#include "boxwhiskersdata_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class BoxPlotChartItem; + +class BoxWhiskersAnimation : public ChartAnimation +{ + Q_OBJECT + +public: + BoxWhiskersAnimation(BoxPlotChartItem *item); + BoxWhiskersAnimation(BoxWhiskers *box); + ~BoxWhiskersAnimation(); + +public: // from QVariantAnimation + virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; + virtual void updateCurrentValue(const QVariant &value); + + void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData); + +protected: + BoxPlotChartItem *m_item; + BoxWhiskers *m_box; + BoxWhiskersData *m_boxData; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // BOXWHISKERSANIMATION_P_H