From 74962bdcee07ccc1cca7f07aaee141a540270827 2012-11-29 10:37:52 From: Marek Rosa Date: 2012-11-29 10:37:52 Subject: [PATCH] Bar animations refactored --- diff --git a/src/animations/abstractbaranimation.cpp b/src/animations/abstractbaranimation.cpp deleted file mode 100644 index 6635e3d..0000000 --- a/src/animations/abstractbaranimation.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include "abstractbaranimation_p.h" -#include "abstractbarchartitem_p.h" -#include -#include - -Q_DECLARE_METATYPE(QVector) - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -AbstractBarAnimation::AbstractBarAnimation(AbstractBarChartItem *item) - : ChartAnimation(item), - m_item(item) -{ - setDuration(ChartAnimationDuration); - setEasingCurve(QEasingCurve::OutQuart); -} - -AbstractBarAnimation::~AbstractBarAnimation() -{ -} - -QVariant AbstractBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const -{ - Q_UNUSED(from); - Q_UNUSED(to); - Q_UNUSED(progress); - qWarning() << "AbstractBarAnimation::interpolated called"; - return to; -} - -void AbstractBarAnimation::updateCurrentValue(const QVariant &value) -{ - QVector layout = qvariant_cast >(value); - m_item->setLayout(layout); -} - -void AbstractBarAnimation::setup(const QVector &oldLayout, const QVector &newLayout) -{ - QVariantAnimation::KeyValues value; - setKeyValues(value); //workaround for wrong interpolation call - setKeyValueAt(0.0, qVariantFromValue(oldLayout)); - setKeyValueAt(1.0, qVariantFromValue(newLayout)); -} - -#include "moc_abstractbaranimation_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE - diff --git a/src/animations/abstractbaranimation_p.h b/src/animations/abstractbaranimation_p.h deleted file mode 100644 index 3a8bb6b..0000000 --- a/src/animations/abstractbaranimation_p.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -// 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 ABSTRACTBARANIMATION_P_H -#define ABSTRACTBARANIMATION_P_H - -#include "chartanimation_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class AbstractBarChartItem; - -class AbstractBarAnimation : public ChartAnimation -{ - Q_OBJECT - -public: - AbstractBarAnimation(AbstractBarChartItem *item); - ~AbstractBarAnimation(); - -public: // from QVariantAnimation - virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; - virtual void updateCurrentValue(const QVariant &value); - - void setup(const QVector &oldLayout, const QVector &newLayout); - -protected: - AbstractBarChartItem *m_item; -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // ABSTRACTBARANIMATION_P_H diff --git a/src/animations/animations.pri b/src/animations/animations.pri index bb09727..f3f7907 100644 --- a/src/animations/animations.pri +++ b/src/animations/animations.pri @@ -7,13 +7,7 @@ SOURCES += \ $$PWD/pieanimation.cpp \ $$PWD/piesliceanimation.cpp \ $$PWD/splineanimation.cpp \ - $$PWD/baranimation.cpp \ - $$PWD/stackedbaranimation.cpp \ - $$PWD/percentbaranimation.cpp \ - $$PWD/abstractbaranimation.cpp \ - $$PWD/horizontalbaranimation.cpp \ - $$PWD/horizontalstackedbaranimation.cpp \ - $$PWD/horizontalpercentbaranimation.cpp + $$PWD/baranimation.cpp PRIVATE_HEADERS += \ $$PWD/axisanimation_p.h \ @@ -22,10 +16,4 @@ PRIVATE_HEADERS += \ $$PWD/pieanimation_p.h \ $$PWD/piesliceanimation_p.h \ $$PWD/splineanimation_p.h \ - $$PWD/baranimation_p.h \ - $$PWD/stackedbaranimation_p.h \ - $$PWD/percentbaranimation_p.h \ - $$PWD/abstractbaranimation_p.h \ - $$PWD/horizontalbaranimation_p.h \ - $$PWD/horizontalstackedbaranimation_p.h \ - $$PWD/horizontalpercentbaranimation_p.h + $$PWD/baranimation_p.h diff --git a/src/animations/baranimation.cpp b/src/animations/baranimation.cpp index 48b3b06..4c7f643 100644 --- a/src/animations/baranimation.cpp +++ b/src/animations/baranimation.cpp @@ -27,9 +27,11 @@ Q_DECLARE_METATYPE(QVector) QTCOMMERCIALCHART_BEGIN_NAMESPACE BarAnimation::BarAnimation(AbstractBarChartItem *item) - : AbstractBarAnimation(item) + : ChartAnimation(item), + m_item(item) { - + setDuration(ChartAnimationDuration); + setEasingCurve(QEasingCurve::OutQuart); } BarAnimation::~BarAnimation() @@ -47,27 +49,32 @@ QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qr for (int i = 0; i < startVector.count(); i++) { QRectF start = startVector[i].normalized(); QRectF end = endVector[i].normalized(); + qreal x1 = start.left() + progress * (end.left() - start.left()); + qreal x2 = start.right() + progress * (end.right() - start.right()); + qreal y1 = start.top() + progress * (end.top() - start.top()); + qreal y2 = start.bottom() + progress * (end.bottom() - start.bottom()); - qreal x = end.left(); - qreal y; - qreal w = end.width(); - qreal h; - - if (endVector[i].height() < 0) { - // Negative bar - y = end.top(); - h = start.height() + ((end.height() - start.height()) * progress); - } else { - h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); - y = endVector[i].top() + endVector[i].height() - h; - } - - QRectF value(x, y, w, h); + QRectF value(QPointF(x1, y1), QPointF(x2, y2)); result << value.normalized(); } return qVariantFromValue(result); } +void BarAnimation::updateCurrentValue(const QVariant &value) +{ + QVector layout = qvariant_cast >(value); + m_item->setLayout(layout); +} + +void BarAnimation::setup(const QVector &oldLayout, const QVector &newLayout) +{ + QVariantAnimation::KeyValues value; + setKeyValues(value); //workaround for wrong interpolation call + setKeyValueAt(0.0, qVariantFromValue(oldLayout)); + setKeyValueAt(1.0, qVariantFromValue(newLayout)); +} + #include "moc_baranimation_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE + diff --git a/src/animations/baranimation_p.h b/src/animations/baranimation_p.h index 8b6bd6b..7115f05 100644 --- a/src/animations/baranimation_p.h +++ b/src/animations/baranimation_p.h @@ -27,18 +27,16 @@ // // We mean it. -#ifndef BARANIMATION_P_H -#define BARANIMATION_P_H +#ifndef ABSTRACTBARANIMATION_P_H +#define ABSTRACTBARANIMATION_P_H -#include "abstractbaranimation_p.h" #include "chartanimation_p.h" -#include "abstractbarchartitem_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE class AbstractBarChartItem; -class BarAnimation : public AbstractBarAnimation +class BarAnimation : public ChartAnimation { Q_OBJECT @@ -48,8 +46,14 @@ public: public: // from QVariantAnimation virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; + virtual void updateCurrentValue(const QVariant &value); + + void setup(const QVector &oldLayout, const QVector &newLayout); + +protected: + AbstractBarChartItem *m_item; }; QTCOMMERCIALCHART_END_NAMESPACE -#endif +#endif // ABSTRACTBARANIMATION_P_H diff --git a/src/animations/horizontalbaranimation.cpp b/src/animations/horizontalbaranimation.cpp deleted file mode 100644 index 39dd9c3..0000000 --- a/src/animations/horizontalbaranimation.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include "horizontalbaranimation_p.h" -#include "abstractbarchartitem_p.h" -#include - -Q_DECLARE_METATYPE(QVector) - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -HorizontalBarAnimation::HorizontalBarAnimation(AbstractBarChartItem *item) - : AbstractBarAnimation(item) -{ -} - -HorizontalBarAnimation::~HorizontalBarAnimation() -{ - -} - - -QVariant HorizontalBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const -{ - QVector startVector = qvariant_cast >(from); - QVector endVector = qvariant_cast >(to); - QVector result; - - Q_ASSERT(startVector.count() == endVector.count()); - - for (int i = 0; i < startVector.count(); i++) { - QRectF start = startVector[i].normalized(); - QRectF end = endVector[i].normalized(); - - qreal x; - qreal y = end.top(); - qreal w; - qreal h = end.height(); - - if (endVector[i].width() < 0) { - // Negative bar - w = start.width() + ((end.width() - start.width()) * progress); - x = endVector[i].right() - endVector[i].width() - w; - } else { - w = startVector[i].width() + ((endVector[i].width() - startVector[i].width()) * progress); - x = end.left(); - } - - QRectF value(x, y, w, h); - result << value.normalized(); - } - return qVariantFromValue(result); -} - -#include "moc_horizontalbaranimation_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/horizontalbaranimation_p.h b/src/animations/horizontalbaranimation_p.h deleted file mode 100644 index 9c8438b..0000000 --- a/src/animations/horizontalbaranimation_p.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -// 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 HORIZONTALBARANIMATION_P_H -#define HORIZONTALBARANIMATION_P_H - -#include "abstractbaranimation_p.h" -#include "chartanimation_p.h" -#include "abstractbarchartitem_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class HorizontalBarAnimation : public AbstractBarAnimation -{ - Q_OBJECT -public: - explicit HorizontalBarAnimation(AbstractBarChartItem *item); - ~HorizontalBarAnimation(); - - virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; - -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // HORIZONTALBARANIMATION_P_H diff --git a/src/animations/horizontalpercentbaranimation.cpp b/src/animations/horizontalpercentbaranimation.cpp deleted file mode 100644 index 13dfa09..0000000 --- a/src/animations/horizontalpercentbaranimation.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include "horizontalpercentbaranimation_p.h" -#include "abstractbarchartitem_p.h" -#include - -Q_DECLARE_METATYPE(QVector) - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -HorizontalPercentBarAnimation::HorizontalPercentBarAnimation(AbstractBarChartItem *item) : - AbstractBarAnimation(item) -{ -} - -HorizontalPercentBarAnimation::~HorizontalPercentBarAnimation() -{ - -} - - -QVariant HorizontalPercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const -{ - QVector startVector = qvariant_cast >(from); - QVector endVector = qvariant_cast >(to); - QVector result; - - Q_ASSERT(startVector.count() == endVector.count()); - - qreal xAxis = m_item->geometry().x(); - - for (int i = 0; i < startVector.count(); i++) { - qreal h = endVector[i].height(); - qreal w = endVector[i].width() * progress; - qreal x = xAxis + ((endVector[i].left() - xAxis) * progress); - qreal y = endVector[i].top(); - - QRectF value(x, y, w, h); - result << value.normalized(); - } - return qVariantFromValue(result); -} - -#include "moc_horizontalpercentbaranimation_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/horizontalpercentbaranimation_p.h b/src/animations/horizontalpercentbaranimation_p.h deleted file mode 100644 index 82852e6..0000000 --- a/src/animations/horizontalpercentbaranimation_p.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -// 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 HORIZONTALPERCENTBARANIMATION_P_H -#define HORIZONTALPERCENTBARANIMATION_P_H - -#include "abstractbaranimation_p.h" -#include "chartanimation_p.h" -#include "abstractbarchartitem_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class HorizontalPercentBarAnimation : public AbstractBarAnimation -{ - Q_OBJECT -public: - explicit HorizontalPercentBarAnimation(AbstractBarChartItem *item); - ~HorizontalPercentBarAnimation(); - - virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; - -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // HORIZONTALPERCENTBARANIMATION_P_H diff --git a/src/animations/horizontalstackedbaranimation.cpp b/src/animations/horizontalstackedbaranimation.cpp deleted file mode 100644 index 5279c0f..0000000 --- a/src/animations/horizontalstackedbaranimation.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include "horizontalstackedbaranimation_p.h" -#include "abstractbarchartitem_p.h" -#include - -Q_DECLARE_METATYPE(QVector) - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -HorizontalStackedBarAnimation::HorizontalStackedBarAnimation(AbstractBarChartItem *item) : - AbstractBarAnimation(item) -{ -} - -HorizontalStackedBarAnimation::~HorizontalStackedBarAnimation() -{ - -} - - -QVariant HorizontalStackedBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const -{ - QVector startVector = qvariant_cast >(from); - QVector endVector = qvariant_cast >(to); - QVector result; - - Q_ASSERT(startVector.count() == endVector.count()); - - qreal xAxis = m_item->geometry().x(); - - for (int i = 0; i < startVector.count(); i++) { - qreal h = endVector[i].height(); - qreal w = endVector[i].width() * progress; - qreal x = xAxis + ((endVector[i].left() - xAxis) * progress); - qreal y = endVector[i].top(); - - QRectF value(x, y, w, h); - result << value.normalized(); - } - return qVariantFromValue(result); -} - -#include "moc_horizontalstackedbaranimation_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/horizontalstackedbaranimation_p.h b/src/animations/horizontalstackedbaranimation_p.h deleted file mode 100644 index 1520e4d..0000000 --- a/src/animations/horizontalstackedbaranimation_p.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -// 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 HORIZONTALSTACKEDBARANIMATION_P_H -#define HORIZONTALSTACKEDBARANIMATION_P_H - -#include "abstractbaranimation_p.h" -#include "chartanimation_p.h" -#include "abstractbarchartitem_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class HorizontalStackedBarAnimation : public AbstractBarAnimation -{ - Q_OBJECT -public: - explicit HorizontalStackedBarAnimation(AbstractBarChartItem *item); - ~HorizontalStackedBarAnimation(); - - virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; - -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // HORIZONTALSTACKEDBARANIMATION_P_H diff --git a/src/animations/percentbaranimation.cpp b/src/animations/percentbaranimation.cpp deleted file mode 100644 index ea09d90..0000000 --- a/src/animations/percentbaranimation.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include "percentbaranimation_p.h" -#include "percentbarchartitem_p.h" -#include - -Q_DECLARE_METATYPE(QVector) - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -PercentBarAnimation::PercentBarAnimation(PercentBarChartItem *item) - : AbstractBarAnimation(item) -{ - setDuration(ChartAnimationDuration); - setEasingCurve(QEasingCurve::OutQuart); -} - -PercentBarAnimation::~PercentBarAnimation() -{ -} - -QVariant PercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const -{ - QVector startVector = qvariant_cast >(from); - QVector endVector = qvariant_cast >(to); - QVector result; - - Q_ASSERT(startVector.count() == endVector.count()); - - qreal yAxis = m_item->geometry().height() + m_item->geometry().y(); - - for (int i = 0; i < startVector.count(); i++) { - qreal w = endVector[i].width(); - qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); - qreal x = endVector[i].topLeft().x(); - qreal y = yAxis + ((endVector[i].topLeft().y() - yAxis) * progress); - - QRectF value(x, y, w, h); - result << value.normalized(); - } - return qVariantFromValue(result); -} - -#include "moc_percentbaranimation_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/percentbaranimation_p.h b/src/animations/percentbaranimation_p.h deleted file mode 100644 index af40d78..0000000 --- a/src/animations/percentbaranimation_p.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -// 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 PERCENTBARANIMATION_P_H -#define PERCENTBARANIMATION_P_H - -#include "chartanimation_p.h" -#include "abstractbaranimation_p.h" -#include "abstractbarchartitem_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class PercentBarChartItem; -class QBarSet; -class BarSetAnimation; - -class PercentBarAnimation : public AbstractBarAnimation -{ - Q_OBJECT -public: - PercentBarAnimation(PercentBarChartItem *item); - ~PercentBarAnimation(); - - virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // PERCENTBARANIMATION_P_H diff --git a/src/animations/stackedbaranimation.cpp b/src/animations/stackedbaranimation.cpp deleted file mode 100644 index 1d9b9e6..0000000 --- a/src/animations/stackedbaranimation.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include "stackedbaranimation_p.h" -#include "stackedbarchartitem_p.h" -#include - -Q_DECLARE_METATYPE(QVector) - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -StackedBarAnimation::StackedBarAnimation(StackedBarChartItem *item) - : AbstractBarAnimation(item) -{ - setEasingCurve(QEasingCurve::OutQuart); -} - -StackedBarAnimation::~StackedBarAnimation() -{ -} - -QVariant StackedBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const -{ - QVector startVector = qvariant_cast >(from); - QVector endVector = qvariant_cast >(to); - QVector result; - - Q_ASSERT(startVector.count() == endVector.count()); - - qreal yAxis = m_item->geometry().height() + m_item->geometry().y(); - - for (int i = 0; i < startVector.count(); i++) { - qreal w = endVector[i].width(); - qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); - qreal x = endVector[i].topLeft().x(); - qreal y = yAxis + ((endVector[i].topLeft().y() - yAxis) * progress); - - QRectF value(x, y, w, h); - result << value.normalized(); - } - return qVariantFromValue(result); -} - -#include "moc_stackedbaranimation_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/animations/stackedbaranimation_p.h b/src/animations/stackedbaranimation_p.h deleted file mode 100644 index 7661cdd..0000000 --- a/src/animations/stackedbaranimation_p.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -// 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 STACKEDBARANIMATION_P_H -#define STACKEDBARANIMATION_P_H - -#include "chartanimation_p.h" -#include "abstractbarchartitem_p.h" -#include "abstractbaranimation_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class StackedBarChartItem; -class QBarSet; -class BarSetAnimation; - -class StackedBarAnimation : public AbstractBarAnimation -{ - Q_OBJECT -public: - StackedBarAnimation(StackedBarChartItem *item); - ~StackedBarAnimation(); - - virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // STACKEDBARANIMATION_P_H diff --git a/src/barchart/abstractbarchartitem.cpp b/src/barchart/abstractbarchartitem.cpp index 01bbfa9..deb3166 100644 --- a/src/barchart/abstractbarchartitem.cpp +++ b/src/barchart/abstractbarchartitem.cpp @@ -27,7 +27,7 @@ #include "qchart.h" #include "chartpresenter_p.h" #include "charttheme_p.h" -#include "abstractbaranimation_p.h" +#include "baranimation_p.h" #include "chartdataset_p.h" #include @@ -46,7 +46,7 @@ AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphics connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged())); - setZValue(ChartPresenter::BarSeriesZValue); + setZValue(ChartPresenter::BarSeriesZValue); handleDataStructureChanged(); handleVisibleChanged(); handleUpdatedBars(); @@ -70,16 +70,23 @@ QRectF AbstractBarChartItem::boundingRect() const void AbstractBarChartItem::applyLayout(const QVector &layout) { - if (m_animation) { - m_animation->setup(m_layout, layout); - presenter()->startAnimation(m_animation); - } else { - setLayout(layout); - update(); + QSizeF size = geometry().size(); + if (geometry().size().isValid()) { + if (m_animation) { + if (m_layout.count() == 0 || m_oldSize != size) { + initializeLayout(); + m_oldSize = size; + } + m_animation->setup(m_layout, layout); + presenter()->startAnimation(m_animation); + } else { + setLayout(layout); + update(); + } } } -void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation) +void AbstractBarChartItem::setAnimation(BarAnimation *animation) { m_animation = animation; } @@ -154,7 +161,7 @@ void AbstractBarChartItem::handleDataStructureChanged() connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*))); connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int))); connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool))); - m_layout.append(QRectF(0, 0, 0, 0)); + // m_layout.append(QRectF(0, 0, 1, 1)); // Labels m_labels.append(new QGraphicsSimpleTextItem(this)); diff --git a/src/barchart/abstractbarchartitem_p.h b/src/barchart/abstractbarchartitem_p.h index 6ae78d9..d2194c1 100644 --- a/src/barchart/abstractbarchartitem_p.h +++ b/src/barchart/abstractbarchartitem_p.h @@ -41,7 +41,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class Bar; class QAxisCategories; class QChart; -class AbstractBarAnimation; +class BarAnimation; class AbstractBarChartItem : public ChartItem { @@ -55,8 +55,9 @@ public: QRectF boundingRect() const; virtual QVector calculateLayout() = 0; + virtual void initializeLayout() = 0; virtual void applyLayout(const QVector &layout); - virtual void setAnimation(AbstractBarAnimation *animation); + virtual void setAnimation(BarAnimation *animation); void setLayout(const QVector &layout); void updateLayout(const QVector &layout); QRectF geometry() const { return m_rect;} @@ -80,11 +81,12 @@ protected: QRectF m_rect; QVector m_layout; - AbstractBarAnimation *m_animation; + BarAnimation *m_animation; QAbstractBarSeries *m_series; // Not owned. QList m_bars; QList m_labels; + QSizeF m_oldSize; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/horizontal/bar/horizontalbarchartitem.cpp b/src/barchart/horizontal/bar/horizontalbarchartitem.cpp index f51343d..c3633e5 100644 --- a/src/barchart/horizontal/bar/horizontalbarchartitem.cpp +++ b/src/barchart/horizontal/bar/horizontalbarchartitem.cpp @@ -30,6 +30,33 @@ HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, QGrap { } +void HorizontalBarChartItem::initializeLayout() +{ + qreal categoryCount = m_series->d_func()->categoryCount(); + qreal setCount = m_series->count(); + qreal barWidth = m_series->d_func()->barWidth(); + + m_layout.clear(); + for(int category = 0; category < categoryCount; category++) { + for (int set = 0; set < setCount; set++) { + QRectF rect; + QPointF topLeft; + QPointF bottomRight; + if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { + topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth)); + bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2 + (set + 1)/setCount * barWidth)); + } else { + topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth)); + bottomRight = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/setCount * barWidth)); + } + + rect.setTopLeft(topLeft); + rect.setBottomRight(bottomRight); + m_layout.append(rect.normalized()); + } + } +} + QVector HorizontalBarChartItem::calculateLayout() { QVector layout; @@ -39,27 +66,20 @@ QVector HorizontalBarChartItem::calculateLayout() qreal setCount = m_series->count(); qreal barWidth = m_series->d_func()->barWidth(); - int itemIndex(0); for(int category = 0; category < categoryCount; category++) { for (int set = 0; set < setCount; set++) { qreal value = m_series->barSets().at(set)->at(category); QRectF rect; QPointF topLeft; if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) - topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + (set + 1)/(setCount) * barWidth)); + topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth)); else - topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/(setCount) * barWidth)); + topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth)); - QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set)/(setCount) * barWidth)); + QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth)); rect.setTopLeft(topLeft); rect.setBottomRight(bottomRight); - layout.append(rect); - - QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); - label->setPos(rect.center() - label->boundingRect().center()); - label->setZValue(200); - itemIndex++; - label->setBrush(Qt::black); + layout.append(rect.normalized()); } } return layout; diff --git a/src/barchart/horizontal/bar/horizontalbarchartitem_p.h b/src/barchart/horizontal/bar/horizontalbarchartitem_p.h index 4d7aeb9..2e4834f 100644 --- a/src/barchart/horizontal/bar/horizontalbarchartitem_p.h +++ b/src/barchart/horizontal/bar/horizontalbarchartitem_p.h @@ -43,6 +43,7 @@ public: private: virtual QVector calculateLayout(); + void initializeLayout(); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/horizontal/bar/qhorizontalbarseries.cpp b/src/barchart/horizontal/bar/qhorizontalbarseries.cpp index 54a8d74..a234167 100644 --- a/src/barchart/horizontal/bar/qhorizontalbarseries.cpp +++ b/src/barchart/horizontal/bar/qhorizontalbarseries.cpp @@ -21,7 +21,6 @@ #include "qhorizontalbarseries.h" #include "qhorizontalbarseries_p.h" #include "horizontalbarchartitem_p.h" -#include "horizontalbaranimation_p.h" #include "qbarcategoryaxis.h" #include "chartdataset_p.h" @@ -116,18 +115,6 @@ void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) QAbstractSeriesPrivate::initializeGraphics(parent); } -void QHorizontalBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) -{ - HorizontalBarChartItem *bar = static_cast(m_item.data()); - Q_ASSERT(bar); - if (options.testFlag(QChart::SeriesAnimations)) { - bar->setAnimation(new HorizontalBarAnimation(bar)); - }else{ - bar->setAnimation(0); - } - QAbstractSeriesPrivate::initializeAnimations(options); -} - #include "moc_qhorizontalbarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/horizontal/bar/qhorizontalbarseries_p.h b/src/barchart/horizontal/bar/qhorizontalbarseries_p.h index 5fa0fdc..b91a45f 100644 --- a/src/barchart/horizontal/bar/qhorizontalbarseries_p.h +++ b/src/barchart/horizontal/bar/qhorizontalbarseries_p.h @@ -40,7 +40,6 @@ class QHorizontalBarSeriesPrivate: public QAbstractBarSeriesPrivate public: QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q); void initializeGraphics(QGraphicsItem* parent); - void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); void initializeDomain(); private: Q_DECLARE_PUBLIC(QHorizontalBarSeries) diff --git a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp index b36d5d6..af679d0 100644 --- a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp +++ b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp @@ -30,6 +30,33 @@ HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries { } +void HorizontalPercentBarChartItem::initializeLayout() +{ + qreal categoryCount = m_series->d_func()->categoryCount(); + qreal setCount = m_series->count(); + qreal barWidth = m_series->d_func()->barWidth(); + + m_layout.clear(); + for(int category = 0; category < categoryCount; category++) { + for (int set = 0; set < setCount; set++) { + QRectF rect; + QPointF topLeft; + QPointF bottomRight; + if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { + topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2)); + bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2)); + } else { + topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2)); + bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2)); + } + + rect.setTopLeft(topLeft); + rect.setBottomRight(bottomRight); + m_layout.append(rect.normalized()); + } + } +} + QVector HorizontalPercentBarChartItem::calculateLayout() { QVector layout; @@ -47,13 +74,13 @@ QVector HorizontalPercentBarChartItem::calculateLayout() QRectF rect; QPointF topLeft; if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) - topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category + barWidth/2)); + topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category - barWidth/2)); else - topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category + barWidth/2)); - QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category - barWidth/2)); + topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category - barWidth/2)); + QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category + barWidth/2)); rect.setTopLeft(topLeft); rect.setBottomRight(bottomRight); - layout.append(rect); + layout.append(rect.normalized()); sum +=value; } } diff --git a/src/barchart/horizontal/percent/horizontalpercentbarchartitem_p.h b/src/barchart/horizontal/percent/horizontalpercentbarchartitem_p.h index ead2f42..a2471f7 100644 --- a/src/barchart/horizontal/percent/horizontalpercentbarchartitem_p.h +++ b/src/barchart/horizontal/percent/horizontalpercentbarchartitem_p.h @@ -44,6 +44,7 @@ public: private: virtual QVector calculateLayout(); + void initializeLayout(); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp b/src/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp index 2fbf46a..a601180 100644 --- a/src/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp +++ b/src/barchart/horizontal/percent/qhorizontalpercentbarseries.cpp @@ -20,7 +20,6 @@ #include "qhorizontalpercentbarseries.h" #include "qhorizontalpercentbarseries_p.h" #include "horizontalpercentbarchartitem_p.h" -#include "horizontalpercentbaranimation_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" @@ -112,17 +111,6 @@ void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* paren QAbstractSeriesPrivate::initializeGraphics(parent); } -void QHorizontalPercentBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) -{ - HorizontalPercentBarChartItem *bar = static_cast(m_item.data()); - Q_ASSERT(bar); - if (options.testFlag(QChart::SeriesAnimations)) { - bar->setAnimation(new HorizontalPercentBarAnimation(bar)); - }else{ - bar->setAnimation(0); - } - QAbstractSeriesPrivate::initializeAnimations(options); -} #include "moc_qhorizontalpercentbarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/horizontal/percent/qhorizontalpercentbarseries_p.h b/src/barchart/horizontal/percent/qhorizontalpercentbarseries_p.h index a7c33a5..7a51446 100644 --- a/src/barchart/horizontal/percent/qhorizontalpercentbarseries_p.h +++ b/src/barchart/horizontal/percent/qhorizontalpercentbarseries_p.h @@ -40,7 +40,6 @@ class QHorizontalPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate public: QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q); void initializeGraphics(QGraphicsItem* parent); - void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); void initializeDomain(); private: Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries) diff --git a/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp b/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp index eb614f4..e603d04 100644 --- a/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp +++ b/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp @@ -30,6 +30,33 @@ HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries { } +void HorizontalStackedBarChartItem::initializeLayout() +{ + qreal categoryCount = m_series->d_func()->categoryCount(); + qreal setCount = m_series->count(); + qreal barWidth = m_series->d_func()->barWidth(); + + m_layout.clear(); + for(int category = 0; category < categoryCount; category++) { + for (int set = 0; set < setCount; set++) { + QRectF rect; + QPointF topLeft; + QPointF bottomRight; + if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { + topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2)); + bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2)); + } else { + topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2)); + bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2)); + } + + rect.setTopLeft(topLeft); + rect.setBottomRight(bottomRight); + m_layout.append(rect.normalized()); + } + } +} + QVector HorizontalStackedBarChartItem::calculateLayout() { QVector layout; @@ -64,7 +91,7 @@ QVector HorizontalStackedBarChartItem::calculateLayout() } rect.setTopLeft(topLeft); rect.setBottomRight(bottomRight); - layout.append(rect); + layout.append(rect.normalized()); } } return layout; diff --git a/src/barchart/horizontal/stacked/horizontalstackedbarchartitem_p.h b/src/barchart/horizontal/stacked/horizontalstackedbarchartitem_p.h index 25ecab4..e79f155 100644 --- a/src/barchart/horizontal/stacked/horizontalstackedbarchartitem_p.h +++ b/src/barchart/horizontal/stacked/horizontalstackedbarchartitem_p.h @@ -43,6 +43,7 @@ public: private: virtual QVector calculateLayout(); + void initializeLayout(); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/horizontal/stacked/qhorizontalstackedbarseries.cpp b/src/barchart/horizontal/stacked/qhorizontalstackedbarseries.cpp index d478908..1535020 100644 --- a/src/barchart/horizontal/stacked/qhorizontalstackedbarseries.cpp +++ b/src/barchart/horizontal/stacked/qhorizontalstackedbarseries.cpp @@ -20,7 +20,6 @@ #include "qhorizontalstackedbarseries.h" #include "qhorizontalstackedbarseries_p.h" #include "horizontalstackedbarchartitem_p.h" -#include "horizontalstackedbaranimation_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" @@ -111,17 +110,6 @@ void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *paren QAbstractSeriesPrivate::initializeGraphics(parent); } -void QHorizontalStackedBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) -{ - HorizontalStackedBarChartItem *bar = static_cast(m_item.data()); - Q_ASSERT(bar); - if (options.testFlag(QChart::SeriesAnimations)) { - bar->setAnimation(new HorizontalStackedBarAnimation(bar)); - }else{ - bar->setAnimation(0); - } - QAbstractSeriesPrivate::initializeAnimations(options); -} #include "moc_qhorizontalstackedbarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/horizontal/stacked/qhorizontalstackedbarseries_p.h b/src/barchart/horizontal/stacked/qhorizontalstackedbarseries_p.h index b593bc3..261849f 100644 --- a/src/barchart/horizontal/stacked/qhorizontalstackedbarseries_p.h +++ b/src/barchart/horizontal/stacked/qhorizontalstackedbarseries_p.h @@ -40,7 +40,6 @@ class QHorizontalStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate public: QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q); void initializeGraphics(QGraphicsItem* parent); - void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); void initializeDomain(); private: Q_DECLARE_PUBLIC(QHorizontalStackedBarSeries) diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp index 64f98a6..0275a41 100644 --- a/src/barchart/qabstractbarseries.cpp +++ b/src/barchart/qabstractbarseries.cpp @@ -28,6 +28,8 @@ #include "qvalueaxis.h" #include "qbarcategoryaxis.h" #include "qbarlegendmarker.h" +#include "baranimation_p.h" +#include "abstractbarchartitem_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -853,6 +855,18 @@ void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bo } } +void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) +{ + AbstractBarChartItem *bar = static_cast(m_item.data()); + Q_ASSERT(bar); + if (options.testFlag(QChart::SeriesAnimations)) { + bar->setAnimation(new BarAnimation(bar)); + }else{ + bar->setAnimation(0); + } + QAbstractSeriesPrivate::initializeAnimations(options); +} + #include "moc_qabstractbarseries.cpp" #include "moc_qabstractbarseries_p.cpp" diff --git a/src/barchart/qabstractbarseries_p.h b/src/barchart/qabstractbarseries_p.h index 021751a..72d7495 100644 --- a/src/barchart/qabstractbarseries_p.h +++ b/src/barchart/qabstractbarseries_p.h @@ -56,6 +56,7 @@ public: void initializeDomain(); void initializeAxes(); + void initializeAnimations(QChart::AnimationOptions options); void initializeTheme(int index, ChartTheme* theme, bool forced = false); QList createLegendMarkers(QLegend *legend); diff --git a/src/barchart/vertical/bar/barchartitem.cpp b/src/barchart/vertical/bar/barchartitem.cpp index 0df2e79..d58ca35 100644 --- a/src/barchart/vertical/bar/barchartitem.cpp +++ b/src/barchart/vertical/bar/barchartitem.cpp @@ -31,6 +31,34 @@ BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : { } +void BarChartItem::initializeLayout() +{ + qreal categoryCount = m_series->d_func()->categoryCount(); + qreal setCount = m_series->count(); + qreal barWidth = m_series->d_func()->barWidth(); + + m_layout.clear(); + for(int category = 0; category < categoryCount; category++) { + for (int set = 0; set < setCount; set++) { + QRectF rect; + QPointF topLeft; + QPointF bottomRight; + + if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { + topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, domain()->minY())); + bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2 + (set + 1)/setCount * barWidth, domain()->minY())); + } else { + topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0)); + bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0)); + } + + rect.setTopLeft(topLeft); + rect.setBottomRight(bottomRight); + m_layout.append(rect.normalized()); + } + } +} + QVector BarChartItem::calculateLayout() { QVector layout; @@ -52,7 +80,7 @@ QVector BarChartItem::calculateLayout() bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0)); rect.setTopLeft(topLeft); rect.setBottomRight(bottomRight); - layout.append(rect); + layout.append(rect.normalized()); } } return layout; diff --git a/src/barchart/vertical/bar/barchartitem_p.h b/src/barchart/vertical/bar/barchartitem_p.h index 9eb3988..3a3c74a 100644 --- a/src/barchart/vertical/bar/barchartitem_p.h +++ b/src/barchart/vertical/bar/barchartitem_p.h @@ -45,6 +45,7 @@ public: private: virtual QVector calculateLayout(); + void initializeLayout(); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/bar/qbarseries.cpp b/src/barchart/vertical/bar/qbarseries.cpp index 93ad662..819969b 100644 --- a/src/barchart/vertical/bar/qbarseries.cpp +++ b/src/barchart/vertical/bar/qbarseries.cpp @@ -23,7 +23,6 @@ #include "barchartitem_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" -#include "baranimation_p.h" #include "qvalueaxis.h" #include "qbarcategoryaxis.h" @@ -114,18 +113,6 @@ void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) QAbstractSeriesPrivate::initializeGraphics(parent); } -void QBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) -{ - BarChartItem *bar = static_cast(m_item.data()); - Q_ASSERT(bar); - if (options.testFlag(QChart::SeriesAnimations)) { - bar->setAnimation(new BarAnimation(bar)); - }else{ - bar->setAnimation(0); - } - QAbstractSeriesPrivate::initializeAnimations(options); -} - #include "moc_qbarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/bar/qbarseries_p.h b/src/barchart/vertical/bar/qbarseries_p.h index bc30974..3f1fec1 100644 --- a/src/barchart/vertical/bar/qbarseries_p.h +++ b/src/barchart/vertical/bar/qbarseries_p.h @@ -41,7 +41,6 @@ class QBarSeriesPrivate: public QAbstractBarSeriesPrivate public: QBarSeriesPrivate(QBarSeries *q); void initializeGraphics(QGraphicsItem* parent); - void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); void initializeDomain(); private: diff --git a/src/barchart/vertical/percent/percentbarchartitem.cpp b/src/barchart/vertical/percent/percentbarchartitem.cpp index 1c12044..a7e952e 100644 --- a/src/barchart/vertical/percent/percentbarchartitem.cpp +++ b/src/barchart/vertical/percent/percentbarchartitem.cpp @@ -31,6 +31,34 @@ PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsIt { } +void PercentBarChartItem::initializeLayout() +{ + qreal categoryCount = m_series->d_func()->categoryCount(); + qreal setCount = m_series->count(); + qreal barWidth = m_series->d_func()->barWidth(); + + m_layout.clear(); + for(int category = 0; category < categoryCount; category++) { + for (int set = 0; set < setCount; set++) { + QRectF rect; + QPointF topLeft; + QPointF bottomRight; + + if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { + topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY())); + bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY())); + } else { + topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0)); + bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0)); + } + + rect.setTopLeft(topLeft); + rect.setBottomRight(bottomRight); + m_layout.append(rect.normalized()); + } + } +} + QVector PercentBarChartItem::calculateLayout() { QVector layout; @@ -54,7 +82,7 @@ QVector PercentBarChartItem::calculateLayout() bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0)); rect.setTopLeft(topLeft); rect.setBottomRight(bottomRight); - layout.append(rect); + layout.append(rect.normalized()); sum +=value; } } diff --git a/src/barchart/vertical/percent/percentbarchartitem_p.h b/src/barchart/vertical/percent/percentbarchartitem_p.h index d0ceb64..ab729b7 100644 --- a/src/barchart/vertical/percent/percentbarchartitem_p.h +++ b/src/barchart/vertical/percent/percentbarchartitem_p.h @@ -46,7 +46,8 @@ public: void handleUpdatedBars(); private: - virtual QVector calculateLayout(); + virtual QVector calculateLayout(); + void initializeLayout(); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/percent/qpercentbarseries.cpp b/src/barchart/vertical/percent/qpercentbarseries.cpp index 758105e..985edb1 100644 --- a/src/barchart/vertical/percent/qpercentbarseries.cpp +++ b/src/barchart/vertical/percent/qpercentbarseries.cpp @@ -24,7 +24,6 @@ #include "chartdataset_p.h" #include "charttheme_p.h" #include "qvalueaxis.h" -#include "percentbaranimation_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -113,17 +112,6 @@ void QPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) QAbstractSeriesPrivate::initializeGraphics(parent); } -void QPercentBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) -{ - PercentBarChartItem *bar = static_cast(m_item.data()); - Q_ASSERT(bar); - if (options.testFlag(QChart::SeriesAnimations)) { - bar->setAnimation(new PercentBarAnimation(bar)); - }else{ - bar->setAnimation(0); - } - QAbstractSeriesPrivate::initializeAnimations(options); -} #include "moc_qpercentbarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/percent/qpercentbarseries_p.h b/src/barchart/vertical/percent/qpercentbarseries_p.h index d888b73..882eb75 100644 --- a/src/barchart/vertical/percent/qpercentbarseries_p.h +++ b/src/barchart/vertical/percent/qpercentbarseries_p.h @@ -42,7 +42,6 @@ public: QPercentBarSeriesPrivate(QPercentBarSeries *q); void initializeDomain(); void initializeGraphics(QGraphicsItem* parent); - void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); private: Q_DECLARE_PUBLIC(QPercentBarSeries) }; diff --git a/src/barchart/vertical/stacked/qstackedbarseries.cpp b/src/barchart/vertical/stacked/qstackedbarseries.cpp index 8db9612..e9cbc88 100644 --- a/src/barchart/vertical/stacked/qstackedbarseries.cpp +++ b/src/barchart/vertical/stacked/qstackedbarseries.cpp @@ -24,7 +24,6 @@ #include "chartdataset_p.h" #include "charttheme_p.h" #include "qvalueaxis.h" -#include "stackedbaranimation_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -112,17 +111,6 @@ void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) QAbstractSeriesPrivate::initializeGraphics(parent); } -void QStackedBarSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) -{ - StackedBarChartItem *bar = static_cast(m_item.data()); - Q_ASSERT(bar); - if (options.testFlag(QChart::SeriesAnimations)) { - bar->setAnimation(new StackedBarAnimation(bar)); - }else{ - bar->setAnimation(0); - } - QAbstractSeriesPrivate::initializeAnimations(options); -} #include "moc_qstackedbarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/stacked/qstackedbarseries_p.h b/src/barchart/vertical/stacked/qstackedbarseries_p.h index 1a32c40..c51a8b5 100644 --- a/src/barchart/vertical/stacked/qstackedbarseries_p.h +++ b/src/barchart/vertical/stacked/qstackedbarseries_p.h @@ -41,7 +41,6 @@ class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate public: QStackedBarSeriesPrivate(QStackedBarSeries *q); void initializeGraphics(QGraphicsItem* parent); - void initializeAnimations(QtCommercialChart::QChart::AnimationOptions options); void initializeDomain(); private: Q_DECLARE_PUBLIC(QStackedBarSeries) diff --git a/src/barchart/vertical/stacked/stackedbarchartitem.cpp b/src/barchart/vertical/stacked/stackedbarchartitem.cpp index 732c220..377bd5d 100644 --- a/src/barchart/vertical/stacked/stackedbarchartitem.cpp +++ b/src/barchart/vertical/stacked/stackedbarchartitem.cpp @@ -31,6 +31,34 @@ StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsIt { } +void StackedBarChartItem::initializeLayout() +{ + qreal categoryCount = m_series->d_func()->categoryCount(); + qreal setCount = m_series->count(); + qreal barWidth = m_series->d_func()->barWidth(); + + m_layout.clear(); + for(int category = 0; category < categoryCount; category++) { + for (int set = 0; set < setCount; set++) { + QRectF rect; + QPointF topLeft; + QPointF bottomRight; + + if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { + topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY())); + bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY())); + } else { + topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0)); + bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0)); + } + + rect.setTopLeft(topLeft); + rect.setBottomRight(bottomRight); + m_layout.append(rect.normalized()); + } + } +} + QVector StackedBarChartItem::calculateLayout() { QVector layout; @@ -55,16 +83,16 @@ QVector StackedBarChartItem::calculateLayout() topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : 0)); negativeSum += value; } else { - bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum)); + topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum)); if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) - topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY())); + bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY())); else - topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0)); + bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0)); positiveSum += value; } rect.setTopLeft(topLeft); rect.setBottomRight(bottomRight); - layout.append(rect); + layout.append(rect.normalized()); } } return layout; diff --git a/src/barchart/vertical/stacked/stackedbarchartitem_p.h b/src/barchart/vertical/stacked/stackedbarchartitem_p.h index 4a24b9a..9f22987 100644 --- a/src/barchart/vertical/stacked/stackedbarchartitem_p.h +++ b/src/barchart/vertical/stacked/stackedbarchartitem_p.h @@ -45,6 +45,8 @@ public: private: virtual QVector calculateLayout(); + void initializeLayout(); + }; QTCOMMERCIALCHART_END_NAMESPACE