@@ -0,0 +1,79 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "percentbaranimation_p.h" | |||
|
22 | #include "percentbarchartitem_p.h" | |||
|
23 | #include <QTimer> | |||
|
24 | ||||
|
25 | Q_DECLARE_METATYPE(QVector<QRectF>) | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
28 | ||||
|
29 | PercentBarAnimation::PercentBarAnimation(BarChartItem *item) | |||
|
30 | :ChartAnimation(item), | |||
|
31 | m_item(item) | |||
|
32 | { | |||
|
33 | setEasingCurve(QEasingCurve::OutQuart); | |||
|
34 | } | |||
|
35 | ||||
|
36 | PercentBarAnimation::~PercentBarAnimation() | |||
|
37 | { | |||
|
38 | } | |||
|
39 | ||||
|
40 | QVariant PercentBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |||
|
41 | { | |||
|
42 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); | |||
|
43 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); | |||
|
44 | QVector<QRectF> result; | |||
|
45 | ||||
|
46 | Q_ASSERT(startVector.count() == endVector.count()); | |||
|
47 | ||||
|
48 | qreal zeroPos = ((m_item->geometry().height() + m_item->geometry().y()) * (1 - progress)); | |||
|
49 | ||||
|
50 | for(int i = 0; i < startVector.count(); i++) { | |||
|
51 | qreal w = endVector[i].width(); | |||
|
52 | qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); | |||
|
53 | qreal x = endVector[i].topLeft().x(); | |||
|
54 | qreal y = startVector[i].topLeft().y() + ((endVector[i].topLeft().y() - startVector[i].topLeft().y()) * progress) | |||
|
55 | + zeroPos; | |||
|
56 | ||||
|
57 | QRectF value(x,y,w,h); | |||
|
58 | result << value; | |||
|
59 | } | |||
|
60 | return qVariantFromValue(result); | |||
|
61 | } | |||
|
62 | ||||
|
63 | void PercentBarAnimation::updateCurrentValue(const QVariant &value) | |||
|
64 | { | |||
|
65 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); | |||
|
66 | m_item->setLayout(layout); | |||
|
67 | } | |||
|
68 | ||||
|
69 | void PercentBarAnimation::updateLayout(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |||
|
70 | { | |||
|
71 | setDuration(ChartAnimationDuration); | |||
|
72 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |||
|
73 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |||
|
74 | QTimer::singleShot(0, this, SLOT(start())); | |||
|
75 | } | |||
|
76 | ||||
|
77 | #include "moc_percentbaranimation_p.cpp" | |||
|
78 | ||||
|
79 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,43 | |||||
|
1 | // W A R N I N G | |||
|
2 | // ------------- | |||
|
3 | // | |||
|
4 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
5 | // implementation detail. This header file may change from version to | |||
|
6 | // version without notice, or even be removed. | |||
|
7 | // | |||
|
8 | // We mean it. | |||
|
9 | ||||
|
10 | #ifndef PERCENTBARANIMATION_P_H | |||
|
11 | #define PERCENTBARANIMATION_P_H | |||
|
12 | ||||
|
13 | #include "chartanimation_p.h" | |||
|
14 | #include "barchartitem_p.h" | |||
|
15 | ||||
|
16 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
17 | ||||
|
18 | class PercentBarChartItem; | |||
|
19 | class QBarSet; | |||
|
20 | class BarSetAnimation; | |||
|
21 | ||||
|
22 | class PercentBarAnimation : public ChartAnimation | |||
|
23 | { | |||
|
24 | Q_OBJECT | |||
|
25 | public: | |||
|
26 | PercentBarAnimation(BarChartItem *item); | |||
|
27 | ~PercentBarAnimation(); | |||
|
28 | ||||
|
29 | public: | |||
|
30 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; | |||
|
31 | virtual void updateCurrentValue(const QVariant &value); | |||
|
32 | ||||
|
33 | void updateLayout(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |||
|
34 | ||||
|
35 | private: | |||
|
36 | BarChartItem *m_item; | |||
|
37 | QHash<QBarSet *, BarSetAnimation *> m_animations; | |||
|
38 | ||||
|
39 | }; | |||
|
40 | ||||
|
41 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
42 | ||||
|
43 | #endif // PERCENTBARANIMATION_P_H |
@@ -0,0 +1,79 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "stackedbaranimation_p.h" | |||
|
22 | #include "stackedbarchartitem_p.h" | |||
|
23 | #include <QTimer> | |||
|
24 | ||||
|
25 | Q_DECLARE_METATYPE(QVector<QRectF>) | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
28 | ||||
|
29 | StackedBarAnimation::StackedBarAnimation(BarChartItem *item) | |||
|
30 | :ChartAnimation(item), | |||
|
31 | m_item(item) | |||
|
32 | { | |||
|
33 | setEasingCurve(QEasingCurve::OutQuart); | |||
|
34 | } | |||
|
35 | ||||
|
36 | StackedBarAnimation::~StackedBarAnimation() | |||
|
37 | { | |||
|
38 | } | |||
|
39 | ||||
|
40 | QVariant StackedBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |||
|
41 | { | |||
|
42 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); | |||
|
43 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); | |||
|
44 | QVector<QRectF> result; | |||
|
45 | ||||
|
46 | Q_ASSERT(startVector.count() == endVector.count()); | |||
|
47 | ||||
|
48 | qreal zeroPos = ((m_item->geometry().height() + m_item->geometry().y()) * (1 - progress)); | |||
|
49 | ||||
|
50 | for(int i = 0; i < startVector.count(); i++) { | |||
|
51 | qreal w = endVector[i].width(); | |||
|
52 | qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); | |||
|
53 | qreal x = endVector[i].topLeft().x(); | |||
|
54 | qreal y = startVector[i].topLeft().y() + ((endVector[i].topLeft().y() - startVector[i].topLeft().y()) * progress) | |||
|
55 | + zeroPos; | |||
|
56 | ||||
|
57 | QRectF value(x,y,w,h); | |||
|
58 | result << value; | |||
|
59 | } | |||
|
60 | return qVariantFromValue(result); | |||
|
61 | } | |||
|
62 | ||||
|
63 | void StackedBarAnimation::updateCurrentValue(const QVariant &value) | |||
|
64 | { | |||
|
65 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); | |||
|
66 | m_item->setLayout(layout); | |||
|
67 | } | |||
|
68 | ||||
|
69 | ||||
|
70 | void StackedBarAnimation::updateLayout(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |||
|
71 | { | |||
|
72 | setDuration(ChartAnimationDuration); | |||
|
73 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |||
|
74 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |||
|
75 | QTimer::singleShot(0, this, SLOT(start())); | |||
|
76 | } | |||
|
77 | #include "moc_stackedbaranimation_p.cpp" | |||
|
78 | ||||
|
79 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,43 | |||||
|
1 | // W A R N I N G | |||
|
2 | // ------------- | |||
|
3 | // | |||
|
4 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
5 | // implementation detail. This header file may change from version to | |||
|
6 | // version without notice, or even be removed. | |||
|
7 | // | |||
|
8 | // We mean it. | |||
|
9 | ||||
|
10 | #ifndef STACKEDBARANIMATION_P_H | |||
|
11 | #define STACKEDBARANIMATION_P_H | |||
|
12 | ||||
|
13 | #include "chartanimation_p.h" | |||
|
14 | #include "barchartitem_p.h" | |||
|
15 | ||||
|
16 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
17 | ||||
|
18 | class StackedBarChartItem; | |||
|
19 | class QBarSet; | |||
|
20 | class BarSetAnimation; | |||
|
21 | ||||
|
22 | class StackedBarAnimation : public ChartAnimation | |||
|
23 | { | |||
|
24 | Q_OBJECT | |||
|
25 | public: | |||
|
26 | StackedBarAnimation(BarChartItem *item); | |||
|
27 | ~StackedBarAnimation(); | |||
|
28 | ||||
|
29 | public: | |||
|
30 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; | |||
|
31 | virtual void updateCurrentValue(const QVariant &value); | |||
|
32 | ||||
|
33 | void updateLayout(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |||
|
34 | ||||
|
35 | private: | |||
|
36 | BarChartItem *m_item; | |||
|
37 | QHash<QBarSet *, BarSetAnimation *> m_animations; | |||
|
38 | ||||
|
39 | }; | |||
|
40 | ||||
|
41 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
42 | ||||
|
43 | #endif // STACKEDBARANIMATION_P_H |
@@ -1,24 +1,27 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/axisanimation.cpp \ |
|
5 | $$PWD/axisanimation.cpp \ | |
6 | $$PWD/chartanimator.cpp \ |
|
6 | $$PWD/chartanimator.cpp \ | |
7 | $$PWD/xyanimation.cpp \ |
|
7 | $$PWD/xyanimation.cpp \ | |
8 | $$PWD/pieanimation.cpp \ |
|
8 | $$PWD/pieanimation.cpp \ | |
9 | $$PWD/piesliceanimation.cpp \ |
|
9 | $$PWD/piesliceanimation.cpp \ | |
10 | $$PWD/splineanimation.cpp \ |
|
10 | $$PWD/splineanimation.cpp \ | |
11 | $$PWD/baranimation.cpp |
|
11 | $$PWD/baranimation.cpp \ | |
|
12 | $$PWD/stackedbaranimation.cpp \ | |||
|
13 | $$PWD/percentbaranimation.cpp | |||
12 |
|
14 | |||
13 |
|
15 | |||
14 |
|
16 | |||
15 | PRIVATE_HEADERS += \ |
|
17 | PRIVATE_HEADERS += \ | |
16 | $$PWD/axisanimation_p.h \ |
|
18 | $$PWD/axisanimation_p.h \ | |
17 | $$PWD/chartanimator_p.h \ |
|
19 | $$PWD/chartanimator_p.h \ | |
18 | $$PWD/chartanimation_p.h \ |
|
20 | $$PWD/chartanimation_p.h \ | |
19 | $$PWD/xyanimation_p.h \ |
|
21 | $$PWD/xyanimation_p.h \ | |
20 | $$PWD/pieanimation_p.h \ |
|
22 | $$PWD/pieanimation_p.h \ | |
21 | $$PWD/piesliceanimation_p.h \ |
|
23 | $$PWD/piesliceanimation_p.h \ | |
22 | $$PWD/splineanimation_p.h \ |
|
24 | $$PWD/splineanimation_p.h \ | |
23 | $$PWD/baranimation_p.h |
|
25 | $$PWD/baranimation_p.h \ | |
24 |
|
26 | $$PWD/stackedbaranimation_p.h \ | ||
|
27 | $$PWD/percentbaranimation_p.h |
@@ -1,72 +1,76 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "baranimation_p.h" |
|
21 | #include "baranimation_p.h" | |
22 | #include "barchartitem_p.h" |
|
22 | #include "barchartitem_p.h" | |
23 | #include <QParallelAnimationGroup> |
|
|||
24 | #include <QTimer> |
|
23 | #include <QTimer> | |
25 |
|
24 | |||
26 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
25 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
27 | //Q_DECLARE_METATYPE(BarLayout) // TODO? |
|
|||
28 |
|
||||
29 |
|
26 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
28 | |||
32 | BarAnimation::BarAnimation(BarChartItem *item) |
|
29 | BarAnimation::BarAnimation(BarChartItem *item) | |
33 | :ChartAnimation(item), |
|
30 | :ChartAnimation(item), | |
34 | m_item(item) |
|
31 | m_item(item) | |
35 | { |
|
32 | { | |
|
33 | setEasingCurve(QEasingCurve::OutQuart); | |||
36 | } |
|
34 | } | |
37 |
|
35 | |||
38 | BarAnimation::~BarAnimation() |
|
36 | BarAnimation::~BarAnimation() | |
39 | { |
|
37 | { | |
40 | } |
|
38 | } | |
41 |
|
39 | |||
42 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
40 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |
43 | { |
|
41 | { | |
44 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); |
|
42 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from); | |
45 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); |
|
43 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to); | |
46 | QVector<QRectF> result; |
|
44 | QVector<QRectF> result; | |
47 |
|
45 | |||
48 | Q_ASSERT(startVector.count() == endVector.count()); |
|
46 | Q_ASSERT(startVector.count() == endVector.count()); | |
49 |
|
47 | |||
50 | for(int i = 0; i < startVector.count(); i++) { |
|
48 | for(int i = 0; i < startVector.count(); i++) { | |
51 | qreal w = endVector[i].width(); |
|
49 | qreal w = endVector[i].width(); | |
52 | qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); |
|
50 | qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress); | |
53 | qreal x = endVector[i].topLeft().x(); |
|
51 | qreal x = endVector[i].topLeft().x(); | |
54 | qreal y = endVector[i].topLeft().y() + endVector[i].height() - h; |
|
52 | qreal y = endVector[i].topLeft().y() + endVector[i].height() - h; | |
55 |
|
53 | |||
56 |
Q |
|
54 | QRectF value(x,y,w,h); | |
57 | QSizeF size(w,h); |
|
|||
58 | QRectF value(topLeft,size); |
|
|||
59 | result << value; |
|
55 | result << value; | |
60 | } |
|
56 | } | |
61 | return qVariantFromValue(result); |
|
57 | return qVariantFromValue(result); | |
62 | } |
|
58 | } | |
63 |
|
59 | |||
64 | void BarAnimation::updateCurrentValue(const QVariant &value) |
|
60 | void BarAnimation::updateCurrentValue(const QVariant &value) | |
65 | { |
|
61 | { | |
66 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); |
|
62 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); | |
67 | m_item->setLayout(layout); |
|
63 | m_item->setLayout(layout); | |
68 | } |
|
64 | } | |
69 |
|
65 | |||
|
66 | void BarAnimation::updateLayout(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |||
|
67 | { | |||
|
68 | setDuration(ChartAnimationDuration); | |||
|
69 | setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |||
|
70 | setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |||
|
71 | QTimer::singleShot(0, this, SLOT(start())); | |||
|
72 | } | |||
|
73 | ||||
70 | #include "moc_baranimation_p.cpp" |
|
74 | #include "moc_baranimation_p.cpp" | |
71 |
|
75 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,63 +1,62 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef BARANIMATION_P_H |
|
30 | #ifndef BARANIMATION_P_H | |
31 | #define BARANIMATION_P_H |
|
31 | #define BARANIMATION_P_H | |
32 |
|
32 | |||
33 | #include "chartanimation_p.h" |
|
33 | #include "chartanimation_p.h" | |
34 | #include "barchartitem_p.h" |
|
34 | #include "barchartitem_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class BarChartItem; |
|
38 | class BarChartItem; | |
39 | class QBarSet; |
|
39 | class QBarSet; | |
40 | class BarSetAnimation; |
|
40 | class BarSetAnimation; | |
41 |
|
41 | |||
42 | class BarAnimation : public ChartAnimation |
|
42 | class BarAnimation : public ChartAnimation | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | BarAnimation(BarChartItem *item); |
|
47 | BarAnimation(BarChartItem *item); | |
48 | ~BarAnimation(); |
|
48 | ~BarAnimation(); | |
49 |
|
49 | |||
50 | public: // from QVariantAnimation |
|
50 | public: // from QVariantAnimation | |
51 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; |
|
51 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; | |
52 | virtual void updateCurrentValue(const QVariant &value); |
|
52 | virtual void updateCurrentValue(const QVariant &value); | |
53 |
|
53 | |||
54 | public Q_SLOTS: |
|
54 | void updateLayout(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
55 |
|
55 | |||
56 | private: |
|
56 | private: | |
57 | BarChartItem *m_item; |
|
57 | BarChartItem *m_item; | |
58 | QHash<QBarSet *, BarSetAnimation *> m_animations; |
|
|||
59 | }; |
|
58 | }; | |
60 |
|
59 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
60 | QTCOMMERCIALCHART_END_NAMESPACE | |
62 |
|
61 | |||
63 | #endif |
|
62 | #endif |
@@ -1,118 +1,168 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartanimator_p.h" |
|
21 | #include "chartanimator_p.h" | |
22 | #include "axisanimation_p.h" |
|
22 | #include "axisanimation_p.h" | |
23 | #include "xyanimation_p.h" |
|
23 | #include "xyanimation_p.h" | |
24 | #include "splineanimation_p.h" |
|
24 | #include "splineanimation_p.h" | |
25 | #include "xychart_p.h" |
|
25 | #include "xychart_p.h" | |
26 | #include "pieanimation_p.h" |
|
26 | #include "pieanimation_p.h" | |
27 | #include "baranimation_p.h" |
|
27 | #include "baranimation_p.h" | |
28 | #include "barchartitem_p.h" |
|
28 | #include "barchartitem_p.h" | |
|
29 | #include "stackedbaranimation_p.h" | |||
|
30 | #include "stackedbarchartitem_p.h" | |||
|
31 | #include "percentbaranimation_p.h" | |||
|
32 | #include "percentbarchartitem_p.h" | |||
29 | #include "areachartitem_p.h" |
|
33 | #include "areachartitem_p.h" | |
30 | #include "splinechartitem_p.h" |
|
34 | #include "splinechartitem_p.h" | |
31 | #include "scatterchartitem_p.h" |
|
35 | #include "scatterchartitem_p.h" | |
32 | #include "chartaxis_p.h" |
|
36 | #include "chartaxis_p.h" | |
33 | #include <QTimer> |
|
37 | #include <QTimer> | |
34 |
|
38 | |||
35 | Q_DECLARE_METATYPE(QVector<QPointF>) |
|
39 | Q_DECLARE_METATYPE(QVector<QPointF>) | |
36 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
40 | Q_DECLARE_METATYPE(QVector<qreal>) | |
37 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
41 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
38 |
|
42 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
44 | |||
41 | ChartAnimator::ChartAnimator(QObject *parent):QObject(parent) |
|
45 | ChartAnimator::ChartAnimator(QObject *parent):QObject(parent) | |
42 | { |
|
46 | { | |
43 | } |
|
47 | } | |
44 |
|
48 | |||
45 | ChartAnimator::~ChartAnimator() |
|
49 | ChartAnimator::~ChartAnimator() | |
46 | { |
|
50 | { | |
47 | } |
|
51 | } | |
48 | void ChartAnimator::addAnimation(PieChartItem *item) |
|
52 | void ChartAnimator::addAnimation(PieChartItem *item) | |
49 | { |
|
53 | { | |
50 | ChartAnimation *animation = m_animations.value(item); |
|
54 | ChartAnimation *animation = m_animations.value(item); | |
51 |
|
55 | |||
52 | if (!animation) { |
|
56 | if (!animation) { | |
53 | animation = new PieAnimation(item); |
|
57 | animation = new PieAnimation(item); | |
54 | m_animations.insert(item, animation); |
|
58 | m_animations.insert(item, animation); | |
55 | } |
|
59 | } | |
56 |
|
60 | |||
57 | item->setAnimator(this); |
|
61 | item->setAnimator(this); | |
58 | } |
|
62 | } | |
59 |
|
63 | |||
60 | void ChartAnimator::addAnimation(BarChartItem *item) |
|
64 | void ChartAnimator::addAnimation(BarChartItem *item) | |
61 | { |
|
65 | { | |
|
66 | // This can handle also GroupedBarChartItem because bars are side by side | |||
62 | ChartAnimation *animation = m_animations.value(item); |
|
67 | ChartAnimation *animation = m_animations.value(item); | |
63 |
|
68 | |||
64 | if (!animation) { |
|
69 | if (!animation) { | |
65 | animation = new BarAnimation(item); |
|
70 | animation = new BarAnimation(item); | |
66 | m_animations.insert(item, animation); |
|
71 | m_animations.insert(item, animation); | |
67 | } |
|
72 | } | |
68 |
|
73 | |||
69 | item->setAnimator(this); |
|
74 | item->setAnimator(this); | |
70 | } |
|
75 | } | |
71 |
|
76 | |||
|
77 | void ChartAnimator::addAnimation(StackedBarChartItem *item) | |||
|
78 | { | |||
|
79 | ChartAnimation *animation = m_animations.value(item); | |||
|
80 | ||||
|
81 | if (!animation) { | |||
|
82 | animation = new StackedBarAnimation(item); | |||
|
83 | m_animations.insert(item, animation); | |||
|
84 | } | |||
|
85 | ||||
|
86 | item->setAnimator(this); | |||
|
87 | } | |||
|
88 | ||||
|
89 | void ChartAnimator::addAnimation(PercentBarChartItem *item) | |||
|
90 | { | |||
|
91 | ChartAnimation *animation = m_animations.value(item); | |||
|
92 | ||||
|
93 | if (!animation) { | |||
|
94 | animation = new PercentBarAnimation(item); | |||
|
95 | m_animations.insert(item, animation); | |||
|
96 | } | |||
|
97 | ||||
|
98 | item->setAnimator(this); | |||
|
99 | } | |||
72 |
|
100 | |||
73 | void ChartAnimator::removeAnimation(Chart *item) |
|
101 | void ChartAnimator::removeAnimation(Chart *item) | |
74 | { |
|
102 | { | |
75 | item->setAnimator(0); |
|
103 | item->setAnimator(0); | |
76 | m_animations.remove(item); |
|
104 | m_animations.remove(item); | |
77 | } |
|
105 | } | |
78 |
|
106 | |||
79 | void ChartAnimator::addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) |
|
107 | void ChartAnimator::addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool startupAnimation) | |
80 | { |
|
108 | { | |
81 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); |
|
109 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
82 | Q_ASSERT(animation); |
|
110 | Q_ASSERT(animation); | |
83 | animation->addSlice(sliceItem, sliceData, startupAnimation); |
|
111 | animation->addSlice(sliceItem, sliceData, startupAnimation); | |
84 | } |
|
112 | } | |
85 |
|
113 | |||
86 | void ChartAnimator::removeAnimation(PieChartItem *item, PieSliceItem *sliceItem) |
|
114 | void ChartAnimator::removeAnimation(PieChartItem *item, PieSliceItem *sliceItem) | |
87 | { |
|
115 | { | |
88 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); |
|
116 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
89 | Q_ASSERT(animation); |
|
117 | Q_ASSERT(animation); | |
90 | animation->removeSlice(sliceItem); |
|
118 | animation->removeSlice(sliceItem); | |
91 | } |
|
119 | } | |
92 |
|
120 | |||
93 | void ChartAnimator::updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData) |
|
121 | void ChartAnimator::updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData) | |
94 | { |
|
122 | { | |
95 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); |
|
123 | PieAnimation *animation = static_cast<PieAnimation *>(m_animations.value(item)); | |
96 | Q_ASSERT(animation); |
|
124 | Q_ASSERT(animation); | |
97 | animation->updateValue(sliceItem, sliceData); |
|
125 | animation->updateValue(sliceItem, sliceData); | |
98 | } |
|
126 | } | |
99 |
|
127 | |||
100 | void ChartAnimator::updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) |
|
128 | void ChartAnimator::updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |
101 | { |
|
129 | { | |
102 | BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item)); |
|
130 | BarAnimation *animation = static_cast<BarAnimation *>(m_animations.value(item)); | |
103 | m_animations.remove(item); |
|
|||
104 | if (animation) { |
|
131 | if (animation) { | |
|
132 | m_animations.remove(item); | |||
105 | animation->deleteLater(); |
|
133 | animation->deleteLater(); | |
106 | animation = 0; |
|
134 | animation = 0; | |
|
135 | addAnimation(item); | |||
107 | } |
|
136 | } | |
108 | addAnimation(item); |
|
|||
109 | animation = static_cast<BarAnimation *>(m_animations.value(item)); |
|
137 | animation = static_cast<BarAnimation *>(m_animations.value(item)); | |
110 | animation->setDuration(ChartAnimationDuration); |
|
138 | animation->updateLayout(oldLayout,newLayout); | |
111 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
139 | } | |
112 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
140 | ||
113 | QTimer::singleShot(0, animation, SLOT(start())); |
|
141 | void ChartAnimator::updateLayout(StackedBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |
|
142 | { | |||
|
143 | StackedBarAnimation *animation = static_cast<StackedBarAnimation *>(m_animations.value(item)); | |||
|
144 | if (animation) { | |||
|
145 | m_animations.remove(item); | |||
|
146 | animation->deleteLater(); | |||
|
147 | animation = 0; | |||
|
148 | addAnimation(item); | |||
|
149 | } | |||
|
150 | animation = static_cast<StackedBarAnimation *>(m_animations.value(item)); | |||
|
151 | animation->updateLayout(oldLayout,newLayout); | |||
114 | } |
|
152 | } | |
115 |
|
153 | |||
|
154 | void ChartAnimator::updateLayout(PercentBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |||
|
155 | { | |||
|
156 | PercentBarAnimation *animation = static_cast<PercentBarAnimation *>(m_animations.value(item)); | |||
|
157 | if (animation) { | |||
|
158 | m_animations.remove(item); | |||
|
159 | animation->deleteLater(); | |||
|
160 | animation = 0; | |||
|
161 | addAnimation(item); | |||
|
162 | } | |||
|
163 | animation = static_cast<PercentBarAnimation *>(m_animations.value(item)); | |||
|
164 | animation->updateLayout(oldLayout,newLayout); | |||
|
165 | } | |||
116 | #include "moc_chartanimator_p.cpp" |
|
166 | #include "moc_chartanimator_p.cpp" | |
117 |
|
167 | |||
118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
168 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,73 +1,77 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTANIMATOR_P_H |
|
30 | #ifndef CHARTANIMATOR_P_H | |
31 | #define CHARTANIMATOR_P_H |
|
31 | #define CHARTANIMATOR_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartanimation_p.h" |
|
34 | #include "chartanimation_p.h" | |
35 | #include "piechartitem_p.h" |
|
35 | #include "piechartitem_p.h" | |
36 | #include "barchartitem_p.h" |
|
36 | #include "barchartitem_p.h" | |
37 | #include <QPointF> |
|
37 | #include <QPointF> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class ChartItem; |
|
41 | class ChartItem; | |
42 | class ChartAxis; |
|
42 | class ChartAxis; | |
43 | class AreaChartItem; |
|
43 | class AreaChartItem; | |
44 | class SplineChartItem; |
|
44 | class SplineChartItem; | |
45 | class ScatterChartItem; |
|
45 | class ScatterChartItem; | |
46 | class LineChartItem; |
|
46 | class LineChartItem; | |
47 | class XYChartItem; |
|
47 | class XYChartItem; | |
48 | class XYAnimation; |
|
48 | class XYAnimation; | |
49 |
|
49 | |||
50 | class ChartAnimator : public QObject |
|
50 | class ChartAnimator : public QObject | |
51 | { |
|
51 | { | |
52 | Q_OBJECT |
|
52 | Q_OBJECT | |
53 | public: |
|
53 | public: | |
54 | ChartAnimator(QObject *parent = 0); |
|
54 | ChartAnimator(QObject *parent = 0); | |
55 | virtual ~ChartAnimator(); |
|
55 | virtual ~ChartAnimator(); | |
56 |
|
56 | |||
57 | void addAnimation(PieChartItem *item); |
|
57 | void addAnimation(PieChartItem *item); | |
58 | void addAnimation(BarChartItem *item); |
|
58 | void addAnimation(BarChartItem *item); // This can handle also grouped bar chart. | |
|
59 | void addAnimation(StackedBarChartItem *item); | |||
|
60 | void addAnimation(PercentBarChartItem *item); | |||
59 | void removeAnimation(Chart *item); |
|
61 | void removeAnimation(Chart *item); | |
60 |
|
62 | |||
61 | void addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool isEmpty); |
|
63 | void addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool isEmpty); | |
62 | void removeAnimation(PieChartItem *item, PieSliceItem *sliceItem); |
|
64 | void removeAnimation(PieChartItem *item, PieSliceItem *sliceItem); | |
63 | void updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData); |
|
65 | void updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData); | |
64 |
|
66 | |||
65 | void updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
67 | void updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
|
68 | void updateLayout(StackedBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |||
|
69 | void updateLayout(PercentBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |||
66 |
|
70 | |||
67 | private: |
|
71 | private: | |
68 | QMap<Chart *, ChartAnimation *> m_animations; |
|
72 | QMap<Chart *, ChartAnimation *> m_animations; | |
69 | }; |
|
73 | }; | |
70 |
|
74 | |||
71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE | |
72 |
|
76 | |||
73 | #endif |
|
77 | #endif |
@@ -1,56 +1,55 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "bar_p.h" |
|
21 | #include "bar_p.h" | |
22 | #include <QDebug> |
|
|||
23 | #include <QPainter> |
|
22 | #include <QPainter> | |
24 | #include <QGraphicsSceneEvent> |
|
23 | #include <QGraphicsSceneEvent> | |
25 |
|
24 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
26 | |||
28 | Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent), |
|
27 | Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent), | |
29 | m_index(index), |
|
28 | m_index(index), | |
30 | m_barset(barset) |
|
29 | m_barset(barset) | |
31 | { |
|
30 | { | |
32 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); |
|
31 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); | |
33 | setAcceptHoverEvents(true); |
|
32 | setAcceptHoverEvents(true); | |
34 | } |
|
33 | } | |
35 |
|
34 | |||
36 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
35 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
37 | { |
|
36 | { | |
38 | Q_UNUSED(event) |
|
37 | Q_UNUSED(event) | |
39 | emit clicked(m_barset, m_index); |
|
38 | emit clicked(m_barset, m_index); | |
40 | } |
|
39 | } | |
41 |
|
40 | |||
42 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
41 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
43 | { |
|
42 | { | |
44 | Q_UNUSED(event) |
|
43 | Q_UNUSED(event) | |
45 | emit hovered(m_barset, true); |
|
44 | emit hovered(m_barset, true); | |
46 | } |
|
45 | } | |
47 |
|
46 | |||
48 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
47 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
49 | { |
|
48 | { | |
50 | Q_UNUSED(event) |
|
49 | Q_UNUSED(event) | |
51 | emit hovered(m_barset, false); |
|
50 | emit hovered(m_barset, false); | |
52 | } |
|
51 | } | |
53 |
|
52 | |||
54 | #include "moc_bar_p.cpp" |
|
53 | #include "moc_bar_p.cpp" | |
55 |
|
54 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,88 +1,88 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | #ifndef BARCHARTITEM_H |
|
31 | #ifndef BARCHARTITEM_H | |
32 | #define BARCHARTITEM_H |
|
32 | #define BARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "qbarseries.h" |
|
35 | #include "qbarseries.h" | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QBrush> |
|
37 | #include <QBrush> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class Bar; |
|
41 | class Bar; | |
42 | class QAxisCategories; |
|
42 | class QAxisCategories; | |
43 | class QChart; |
|
43 | class QChart; | |
44 |
|
44 | |||
45 | class BarChartItem : public ChartItem |
|
45 | class BarChartItem : public ChartItem | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
49 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
50 | virtual ~BarChartItem(); |
|
50 | virtual ~BarChartItem(); | |
51 |
|
51 | |||
52 | public: |
|
52 | public: | |
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
54 | QRectF boundingRect() const; |
|
54 | QRectF boundingRect() const; | |
55 |
|
55 | |||
56 | virtual QVector<QRectF> calculateLayout(); |
|
56 | virtual QVector<QRectF> calculateLayout(); | |
57 | void applyLayout(const QVector<QRectF> &layout); |
|
57 | virtual void applyLayout(const QVector<QRectF> &layout); | |
58 | void setLayout(const QVector<QRectF> &layout); |
|
58 | void setLayout(const QVector<QRectF> &layout); | |
59 | void updateLayout(const QVector<QRectF> &layout); |
|
59 | void updateLayout(const QVector<QRectF> &layout); | |
60 |
|
60 | |||
61 | QRectF geometry() const { return m_rect;} |
|
61 | QRectF geometry() const { return m_rect;} | |
62 |
|
62 | |||
63 | public Q_SLOTS: |
|
63 | public Q_SLOTS: | |
64 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
64 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
65 | void handleGeometryChanged(const QRectF &size); |
|
65 | void handleGeometryChanged(const QRectF &size); | |
66 | void handleLayoutChanged(); |
|
66 | void handleLayoutChanged(); | |
67 | void handleLabelsVisibleChanged(bool visible); |
|
67 | void handleLabelsVisibleChanged(bool visible); | |
68 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items |
|
68 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items | |
69 |
|
69 | |||
70 | protected: |
|
70 | protected: | |
71 |
|
71 | |||
72 | qreal m_domainMinX; |
|
72 | qreal m_domainMinX; | |
73 | qreal m_domainMaxX; |
|
73 | qreal m_domainMaxX; | |
74 | qreal m_domainMinY; |
|
74 | qreal m_domainMinY; | |
75 | qreal m_domainMaxY; |
|
75 | qreal m_domainMaxY; | |
76 |
|
76 | |||
77 | QRectF m_rect; |
|
77 | QRectF m_rect; | |
78 | QVector<QRectF> m_layout; |
|
78 | QVector<QRectF> m_layout; | |
79 |
|
79 | |||
80 | // Not owned. |
|
80 | // Not owned. | |
81 | QBarSeries *m_series; |
|
81 | QBarSeries *m_series; | |
82 | QList<Bar *> m_bars; |
|
82 | QList<Bar *> m_bars; | |
83 | QList<QGraphicsSimpleTextItem *> m_labels; |
|
83 | QList<QGraphicsSimpleTextItem *> m_labels; | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE | |
87 |
|
87 | |||
88 | #endif // BARCHARTITEM_H |
|
88 | #endif // BARCHARTITEM_H |
@@ -1,97 +1,106 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "percentbarchartitem_p.h" |
|
21 | #include "percentbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarseries_p.h" |
|
23 | #include "qbarseries_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include <QDebug> |
|
25 | #include "chartanimator_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
35 | { |
|
35 | { | |
36 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
37 |
|
37 | |||
38 | // Use temporary qreals for accuracy |
|
38 | // Use temporary qreals for accuracy | |
39 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
39 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
40 | qreal setCount = m_series->barsetCount(); |
|
40 | qreal setCount = m_series->barsetCount(); | |
41 | bool barsVisible = m_series->isVisible(); |
|
41 | bool barsVisible = m_series->isVisible(); | |
42 |
|
42 | |||
43 | // Domain: |
|
43 | // Domain: | |
44 | qreal width = geometry().width(); |
|
44 | qreal width = geometry().width(); | |
45 | qreal height = geometry().height(); |
|
45 | qreal height = geometry().height(); | |
46 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
46 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
47 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
47 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
48 | qreal scaleY = (height / rangeY); |
|
48 | qreal scaleY = (height / rangeY); | |
49 | qreal scaleX = (width / rangeX); |
|
49 | qreal scaleX = (width / rangeX); | |
50 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); |
|
50 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); | |
51 |
|
51 | |||
52 | int itemIndex(0); |
|
52 | int itemIndex(0); | |
53 | for (int category = 0; category < categoryCount; category++) { |
|
53 | for (int category = 0; category < categoryCount; category++) { | |
54 | qreal colSum = m_series->d_func()->categorySum(category); |
|
54 | qreal colSum = m_series->d_func()->categorySum(category); | |
55 | qreal percentage = (100 / colSum); |
|
55 | qreal percentage = (100 / colSum); | |
56 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
56 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
57 | for (int set=0; set < setCount; set++) { |
|
57 | for (int set=0; set < setCount; set++) { | |
58 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
58 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
59 |
|
59 | |||
60 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
60 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
61 |
|
61 | |||
62 | qreal barHeight = barSet->at(category).y() * percentage * scaleY; |
|
62 | qreal barHeight = barSet->at(category).y() * percentage * scaleY; | |
63 | Bar* bar = m_bars.at(itemIndex); |
|
63 | Bar* bar = m_bars.at(itemIndex); | |
64 | bar->setPen(barSet->pen()); |
|
64 | bar->setPen(barSet->pen()); | |
65 | bar->setBrush(barSet->brush()); |
|
65 | bar->setBrush(barSet->brush()); | |
66 | bar->setVisible(barsVisible); |
|
66 | bar->setVisible(barsVisible); | |
67 |
|
67 | |||
68 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
68 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
69 | layout.append(rect); |
|
69 | layout.append(rect); | |
70 |
|
70 | |||
71 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
71 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
72 |
|
72 | |||
73 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { |
|
73 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { | |
74 | int p = m_series->d_func()->percentageAt(set,category) * 100; |
|
74 | int p = m_series->d_func()->percentageAt(set,category) * 100; | |
75 | QString vString(QString::number(p)); |
|
75 | QString vString(QString::number(p)); | |
76 | vString.truncate(3); |
|
76 | vString.truncate(3); | |
77 | vString.append("%"); |
|
77 | vString.append("%"); | |
78 | label->setText(vString); |
|
78 | label->setText(vString); | |
79 | } else { |
|
79 | } else { | |
80 | label->setText(QString("")); |
|
80 | label->setText(QString("")); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
83 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
84 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
84 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
85 | label->setFont(barSet->labelFont()); |
|
85 | label->setFont(barSet->labelFont()); | |
86 | label->setBrush(barSet->labelBrush()); |
|
86 | label->setBrush(barSet->labelBrush()); | |
87 |
|
87 | |||
88 | itemIndex++; |
|
88 | itemIndex++; | |
89 | yPos -= barHeight; |
|
89 | yPos -= barHeight; | |
90 | } |
|
90 | } | |
91 | } |
|
91 | } | |
92 | return layout; |
|
92 | return layout; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
|
95 | void PercentBarChartItem::applyLayout(const QVector<QRectF> &layout) | |||
|
96 | { | |||
|
97 | if (animator()) { | |||
|
98 | animator()->updateLayout(this, m_layout, layout); | |||
|
99 | } else { | |||
|
100 | setLayout(layout); | |||
|
101 | update(); | |||
|
102 | } | |||
|
103 | } | |||
95 | #include "moc_percentbarchartitem_p.cpp" |
|
104 | #include "moc_percentbarchartitem_p.cpp" | |
96 |
|
105 | |||
97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
106 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,54 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | #ifndef PERCENTBARCHARTITEM_H |
|
31 | #ifndef PERCENTBARCHARTITEM_H | |
32 | #define PERCENTBARCHARTITEM_H |
|
32 | #define PERCENTBARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "barchartitem_p.h" |
|
34 | #include "barchartitem_p.h" | |
35 | #include <QGraphicsItem> |
|
35 | #include <QGraphicsItem> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class QBarSeries; |
|
39 | class QBarSeries; | |
40 |
|
40 | |||
41 | class PercentBarChartItem : public BarChartItem |
|
41 | class PercentBarChartItem : public BarChartItem | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 | public: |
|
44 | public: | |
45 | PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
45 | PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | virtual QVector<QRectF> calculateLayout(); |
|
48 | virtual QVector<QRectF> calculateLayout(); | |
|
49 | virtual void applyLayout(const QVector<QRectF> &layout); | |||
49 | }; |
|
50 | }; | |
50 |
|
51 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE | |
52 |
|
53 | |||
53 | #endif // PERCENTBARCHARTITEM_H |
|
54 | #endif // PERCENTBARCHARTITEM_H |
@@ -1,90 +1,101 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "stackedbarchartitem_p.h" |
|
21 | #include "stackedbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset_p.h" |
|
23 | #include "qbarset_p.h" | |
24 | #include "qbarseries_p.h" |
|
24 | #include "qbarseries_p.h" | |
25 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
|
26 | #include "chartanimator_p.h" | |||
26 |
|
27 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
29 | |||
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
30 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
31 | BarChartItem(series, presenter) | |
31 | { |
|
32 | { | |
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
35 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
35 | { |
|
36 | { | |
36 | QVector<QRectF> layout; |
|
37 | QVector<QRectF> layout; | |
37 | // Use temporary qreals for accuracy |
|
38 | // Use temporary qreals for accuracy | |
38 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
39 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
39 | qreal setCount = m_series->barsetCount(); |
|
40 | qreal setCount = m_series->barsetCount(); | |
40 | bool barsVisible = m_series->isVisible(); |
|
41 | bool barsVisible = m_series->isVisible(); | |
41 |
|
42 | |||
42 | // Domain: |
|
43 | // Domain: | |
43 | qreal width = geometry().width(); |
|
44 | qreal width = geometry().width(); | |
44 | qreal height = geometry().height(); |
|
45 | qreal height = geometry().height(); | |
45 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
46 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
46 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
47 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
47 | qreal scaleY = (height / rangeY); |
|
48 | qreal scaleY = (height / rangeY); | |
48 | qreal scaleX = (width / rangeX); |
|
49 | qreal scaleX = (width / rangeX); | |
49 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); |
|
50 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); | |
50 |
|
51 | |||
51 | int itemIndex(0); |
|
52 | int itemIndex(0); | |
52 | for (int category = 0; category < categoryCount; category++) { |
|
53 | for (int category = 0; category < categoryCount; category++) { | |
53 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); |
|
54 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); | |
54 | for (int set=0; set < setCount; set++) { |
|
55 | for (int set=0; set < setCount; set++) { | |
55 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
56 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
56 |
|
57 | |||
57 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
58 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
58 |
|
59 | |||
59 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
60 | qreal barHeight = barSet->at(category).y() * scaleY; | |
60 | Bar* bar = m_bars.at(itemIndex); |
|
61 | Bar* bar = m_bars.at(itemIndex); | |
61 | bar->setPen(barSet->pen()); |
|
62 | bar->setPen(barSet->pen()); | |
62 | bar->setBrush(barSet->brush()); |
|
63 | bar->setBrush(barSet->brush()); | |
63 | bar->setVisible(barsVisible); |
|
64 | bar->setVisible(barsVisible); | |
64 |
|
65 | |||
65 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
66 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
66 | layout.append(rect); |
|
67 | layout.append(rect); | |
67 |
|
68 | |||
68 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
69 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
69 |
|
70 | |||
70 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
71 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
71 | label->setText(QString::number(barSet->at(category).y())); |
|
72 | label->setText(QString::number(barSet->at(category).y())); | |
72 | } else { |
|
73 | } else { | |
73 | label->setText(QString("")); |
|
74 | label->setText(QString("")); | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
77 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
77 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
78 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
78 | label->setFont(barSet->labelFont()); |
|
79 | label->setFont(barSet->labelFont()); | |
79 | label->setBrush(barSet->labelBrush()); |
|
80 | label->setBrush(barSet->labelBrush()); | |
80 | itemIndex++; |
|
81 | itemIndex++; | |
81 | yPos -= barHeight; |
|
82 | yPos -= barHeight; | |
82 | } |
|
83 | } | |
83 | } |
|
84 | } | |
84 |
|
85 | |||
85 | return layout; |
|
86 | return layout; | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
|
89 | void StackedBarChartItem::applyLayout(const QVector<QRectF> &layout) | |||
|
90 | { | |||
|
91 | if (animator()) { | |||
|
92 | animator()->updateLayout(this, m_layout, layout); | |||
|
93 | } else { | |||
|
94 | setLayout(layout); | |||
|
95 | update(); | |||
|
96 | } | |||
|
97 | } | |||
|
98 | ||||
88 | #include "moc_stackedbarchartitem_p.cpp" |
|
99 | #include "moc_stackedbarchartitem_p.cpp" | |
89 |
|
100 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,52 +1,53 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | #ifndef STACKEDBARCHARTITEM_H |
|
31 | #ifndef STACKEDBARCHARTITEM_H | |
32 | #define STACKEDBARCHARTITEM_H |
|
32 | #define STACKEDBARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "barchartitem_p.h" |
|
34 | #include "barchartitem_p.h" | |
35 | #include "qstackedbarseries.h" |
|
35 | #include "qstackedbarseries.h" | |
36 | #include <QGraphicsItem> |
|
36 | #include <QGraphicsItem> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class StackedBarChartItem : public BarChartItem |
|
40 | class StackedBarChartItem : public BarChartItem | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | public: |
|
43 | public: | |
44 | StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
44 | StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | virtual QVector<QRectF> calculateLayout(); |
|
47 | virtual QVector<QRectF> calculateLayout(); | |
|
48 | virtual void applyLayout(const QVector<QRectF> &layout); | |||
48 | }; |
|
49 | }; | |
49 |
|
50 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
52 | |||
52 | #endif // STACKEDBARCHARTITEM_H |
|
53 | #endif // STACKEDBARCHARTITEM_H |
General Comments 0
You need to be logged in to leave comments.
Login now