summaryrefslogtreecommitdiffstats
path: root/src/animations
diff options
context:
space:
mode:
authorMika Salmela <mika.salmela@digia.com>2013-06-03 15:01:25 +0300
committerMika Salmela <mika.salmela@digia.com>2013-06-03 15:08:00 +0300
commitb76baa838f46089ff6d50a2f003b7903594fd443 (patch)
tree8a4c55272934f9d0b741806bfa3ce829081dd1b8 /src/animations
parent1ed4427c0b81a534f6318c037115164138073706 (diff)
A new box-and-whiskers series type added to charts.
Change-Id: Iab7a05c44026db9925fa0d68afd2b533b3ea2f91 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/animations')
-rw-r--r--src/animations/animations.pri8
-rw-r--r--src/animations/boxplotanimation.cpp78
-rw-r--r--src/animations/boxplotanimation_p.h61
-rw-r--r--src/animations/boxwhiskersanimation.cpp107
-rw-r--r--src/animations/boxwhiskersanimation_p.h69
5 files changed, 321 insertions, 2 deletions
diff --git a/src/animations/animations.pri b/src/animations/animations.pri
index 93239425..1a0870fa 100644
--- a/src/animations/animations.pri
+++ b/src/animations/animations.pri
@@ -8,7 +8,9 @@ SOURCES += \
$$PWD/piesliceanimation.cpp \
$$PWD/splineanimation.cpp \
$$PWD/baranimation.cpp \
- $$PWD/scatteranimation.cpp
+ $$PWD/scatteranimation.cpp \
+ $$PWD/boxplotanimation.cpp \
+ $$PWD/boxwhiskersanimation.cpp
PRIVATE_HEADERS += \
$$PWD/axisanimation_p.h \
@@ -18,4 +20,6 @@ PRIVATE_HEADERS += \
$$PWD/piesliceanimation_p.h \
$$PWD/splineanimation_p.h \
$$PWD/baranimation_p.h \
- $$PWD/scatteranimation_p.h
+ $$PWD/scatteranimation_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 00000000..1bd88d21
--- /dev/null
+++ b/src/animations/boxplotanimation.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** 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)
+ : m_item(item)
+{
+}
+
+BoxPlotAnimation::~BoxPlotAnimation()
+{
+}
+
+void BoxPlotAnimation::addBox(BoxWhiskers *box)
+{
+ BoxWhiskersAnimation *animation = m_animations.value(box);
+ if (!animation) {
+ 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);
+ } else {
+ animation->stop();
+ animation->setEndData(box->m_data);
+ }
+}
+
+ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box)
+{
+ BoxWhiskersAnimation *animation = m_animations.value(box);
+ if (animation)
+ animation->m_moveMedianLine = false;
+
+ return animation;
+}
+
+ChartAnimation *BoxPlotAnimation::boxChangeAnimation(BoxWhiskers *box)
+{
+ BoxWhiskersAnimation *animation = m_animations.value(box);
+ animation->m_moveMedianLine = true;
+ animation->setEndData(box->m_data);
+
+ return animation;
+}
+
+void BoxPlotAnimation::setAnimationStart(BoxWhiskers *box)
+{
+ BoxWhiskersAnimation *animation = m_animations.value(box);
+ animation->setStartData(box->m_data);
+}
+
+//#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 00000000..52a38f20
--- /dev/null
+++ b/src/animations/boxplotanimation_p.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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:
+ BoxPlotAnimation(BoxPlotChartItem *item);
+ ~BoxPlotAnimation();
+
+ void addBox(BoxWhiskers *box);
+ ChartAnimation *boxAnimation(BoxWhiskers *box);
+ ChartAnimation *boxChangeAnimation(BoxWhiskers *box);
+
+ void setAnimationStart(BoxWhiskers *box);
+
+protected:
+ BoxPlotChartItem *m_item;
+ QHash<BoxWhiskers *, BoxWhiskersAnimation *> 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 00000000..a46aa76a
--- /dev/null
+++ b/src/animations/boxwhiskersanimation.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** 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<QRectF>)
+Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData)
+Q_DECLARE_METATYPE(qreal)
+
+QTCOMMERCIALCHART_BEGIN_NAMESPACE
+
+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<BoxWhiskersData>(from);
+ BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(to);
+ BoxWhiskersData result;
+
+ if (m_moveMedianLine) {
+ result.m_lowerExtreme = startData.m_lowerExtreme + progress * (endData.m_lowerExtreme - startData.m_lowerExtreme);
+ result.m_lowerQuartile = startData.m_lowerQuartile + progress * (endData.m_lowerQuartile - startData.m_lowerQuartile);
+ result.m_median = startData.m_median + progress * (endData.m_median - startData.m_median);
+ result.m_upperQuartile = startData.m_upperQuartile + progress * (endData.m_upperQuartile - startData.m_upperQuartile);
+ result.m_upperExtreme = startData.m_upperExtreme + progress * (endData.m_upperExtreme - startData.m_upperExtreme);
+ } else {
+ 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_maxX = endData.m_maxX;
+ result.m_minX = endData.m_minX;
+ result.m_maxY = endData.m_maxY;
+ result.m_minY = endData.m_minY;
+ result.m_seriesIndex = endData.m_seriesIndex;
+ result.m_seriesCount = endData.m_seriesCount;
+
+ return qVariantFromValue(result);
+}
+
+void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value)
+{
+ BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(value);
+ m_box->setLayout(data);
+}
+
+void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData)
+{
+ setKeyValueAt(0.0, qVariantFromValue(startData));
+ setKeyValueAt(1.0, qVariantFromValue(endData));
+}
+
+void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData)
+{
+ if (state() != QAbstractAnimation::Stopped)
+ stop();
+
+ setEndValue(qVariantFromValue(endData));
+}
+
+void BoxWhiskersAnimation::setStartData(const BoxWhiskersData &endData)
+{
+ if (state() != QAbstractAnimation::Stopped)
+ stop();
+
+ setStartValue(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 00000000..5e3bd905
--- /dev/null
+++ b/src/animations/boxwhiskersanimation_p.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** 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(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);
+ void setEndData(const BoxWhiskersData &endData);
+ void setStartData(const BoxWhiskersData &endData);
+
+ void moveMedianLine(bool move);
+
+protected:
+ friend class BoxPlotAnimation;
+ BoxPlotChartItem *m_item;
+ BoxWhiskers *m_box;
+ BoxWhiskersData *m_boxData;
+ bool m_moveMedianLine;
+};
+
+QTCOMMERCIALCHART_END_NAMESPACE
+
+#endif // BOXWHISKERSANIMATION_P_H