@@ -1,63 +1,61 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "boxplotanimation_p.h" |
|
21 | #include "boxplotanimation_p.h" | |
22 | #include "boxplotchartitem_p.h" |
|
22 | #include "boxplotchartitem_p.h" | |
23 | #include "boxwhiskersdata_p.h" |
|
23 | #include "boxwhiskersdata_p.h" | |
24 | #include "boxwhiskersanimation_p.h" |
|
24 | #include "boxwhiskersanimation_p.h" | |
|
25 | #include <QDebug> | |||
25 |
|
26 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
28 | |||
28 | BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item) |
|
29 | BoxPlotAnimation::BoxPlotAnimation(BoxPlotChartItem *item) | |
29 | // : ChartAnimation(item), |
|
|||
30 | : m_item(item) |
|
30 | : m_item(item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | //BoxPlotAnimation::BoxPlotAnimation(BoxWhiskers *box) |
|
|||
35 | // : ChartAnimation(box), |
|
|||
36 | // m_box(box) |
|
|||
37 | //{ |
|
|||
38 | //} |
|
|||
39 |
|
||||
40 | BoxPlotAnimation::~BoxPlotAnimation() |
|
34 | BoxPlotAnimation::~BoxPlotAnimation() | |
41 | { |
|
35 | { | |
42 | } |
|
36 | } | |
43 |
|
37 | |||
44 | void BoxPlotAnimation::addBox(BoxWhiskers *box) |
|
38 | void BoxPlotAnimation::addBox(BoxWhiskers *box) | |
45 | { |
|
39 | { | |
46 |
BoxWhiskersAnimation *animation = |
|
40 | BoxWhiskersAnimation *animation = m_animations.value(box); | |
|
41 | if (!animation) { | |||
|
42 | animation = new BoxWhiskersAnimation(box); | |||
47 | m_animations.insert(box, animation); |
|
43 | m_animations.insert(box, animation); | |
48 |
|
||||
49 | BoxWhiskersData start; |
|
44 | BoxWhiskersData start; | |
50 | start.m_median = box->m_data.m_median; |
|
45 | start.m_median = box->m_data.m_median; | |
51 | animation->setup(start, box->m_data); |
|
46 | animation->setup(start, box->m_data); | |
|
47 | } else { | |||
|
48 | animation->stop(); | |||
|
49 | animation->setEndData(box->m_data); | |||
|
50 | } | |||
52 | } |
|
51 | } | |
53 |
|
52 | |||
54 | ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box) |
|
53 | ChartAnimation *BoxPlotAnimation::boxAnimation(BoxWhiskers *box) | |
55 | { |
|
54 | { | |
56 | // TODO: Check for missing animation |
|
55 | // TODO: Check for missing animation | |
57 | return m_animations.value(box); |
|
56 | return m_animations.value(box); | |
58 | } |
|
57 | } | |
59 |
|
58 | |||
60 |
|
||||
61 | //#include "moc_boxplotanimation_p.cpp" |
|
59 | //#include "moc_boxplotanimation_p.cpp" | |
62 |
|
60 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,106 +1,113 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "boxwhiskersanimation_p.h" |
|
21 | #include "boxwhiskersanimation_p.h" | |
22 | #include "boxplotanimation_p.h" |
|
22 | #include "boxplotanimation_p.h" | |
23 | #include "boxplotchartitem_p.h" |
|
23 | #include "boxplotchartitem_p.h" | |
24 | #include "boxwhiskersdata_p.h" |
|
24 | #include "boxwhiskersdata_p.h" | |
|
25 | #include <QDebug> | |||
25 |
|
26 | |||
26 | Q_DECLARE_METATYPE(QVector<QRectF>) |
|
27 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
27 | Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData) |
|
28 | Q_DECLARE_METATYPE(QTCOMMERCIALCHART_NAMESPACE::BoxWhiskersData) | |
28 | Q_DECLARE_METATYPE(qreal) |
|
29 | Q_DECLARE_METATYPE(qreal) | |
29 |
|
30 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
32 | |||
32 | BoxWhiskersAnimation::BoxWhiskersAnimation(BoxPlotChartItem *item) |
|
33 | BoxWhiskersAnimation::BoxWhiskersAnimation(BoxPlotChartItem *item) | |
33 | : ChartAnimation(item), |
|
34 | : ChartAnimation(item), | |
34 | m_item(item) |
|
35 | m_item(item) | |
35 | { |
|
36 | { | |
36 | setDuration(ChartAnimationDuration); |
|
37 | setDuration(ChartAnimationDuration); | |
37 | setEasingCurve(QEasingCurve::OutQuart); |
|
38 | setEasingCurve(QEasingCurve::OutQuart); | |
38 | } |
|
39 | } | |
39 |
|
40 | |||
40 | BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box) |
|
41 | BoxWhiskersAnimation::BoxWhiskersAnimation(BoxWhiskers *box) | |
41 | : ChartAnimation(box), |
|
42 | : ChartAnimation(box), | |
42 | m_box(box) |
|
43 | m_box(box) | |
43 | { |
|
44 | { | |
44 | setDuration(ChartAnimationDuration); |
|
45 | setDuration(ChartAnimationDuration); | |
45 | setEasingCurve(QEasingCurve::OutQuart); |
|
46 | setEasingCurve(QEasingCurve::OutQuart); | |
46 | } |
|
47 | } | |
47 |
|
48 | |||
48 | BoxWhiskersAnimation::~BoxWhiskersAnimation() |
|
49 | BoxWhiskersAnimation::~BoxWhiskersAnimation() | |
49 | { |
|
50 | { | |
50 | } |
|
51 | } | |
51 |
|
52 | |||
52 | QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
53 | QVariant BoxWhiskersAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |
53 | { |
|
54 | { | |
54 | BoxWhiskersData startData = qvariant_cast<BoxWhiskersData>(from); |
|
55 | BoxWhiskersData startData = qvariant_cast<BoxWhiskersData>(from); | |
55 | BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(to); |
|
56 | BoxWhiskersData endData = qvariant_cast<BoxWhiskersData>(to); | |
56 | BoxWhiskersData result; |
|
57 | BoxWhiskersData result; | |
57 |
|
58 | |||
58 | if (endData.m_index == 1) { |
|
59 | if (endData.m_index == 1) { | |
59 | //qDebug() << "endData.m_lowerExtreme = " << endData.m_lowerExtreme; |
|
60 | //qDebug() << "endData.m_lowerExtreme = " << endData.m_lowerExtreme; | |
60 | //qDebug() << "endData.m_median = " << endData.m_median; |
|
61 | //qDebug() << "endData.m_median = " << endData.m_median; | |
61 | } |
|
62 | } | |
62 |
|
63 | |||
63 | result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median); |
|
64 | result.m_lowerExtreme = endData.m_median + progress * (endData.m_lowerExtreme - endData.m_median); | |
64 | result.m_lowerQuartile = endData.m_median + progress * (endData.m_lowerQuartile - endData.m_median); |
|
65 | result.m_lowerQuartile = endData.m_median + progress * (endData.m_lowerQuartile - endData.m_median); | |
65 | result.m_median = endData.m_median; |
|
66 | result.m_median = endData.m_median; | |
66 | result.m_upperQuartile = endData.m_median + progress * (endData.m_upperQuartile - endData.m_median); |
|
67 | result.m_upperQuartile = endData.m_median + progress * (endData.m_upperQuartile - endData.m_median); | |
67 | result.m_upperExtreme = endData.m_median + progress * (endData.m_upperExtreme - endData.m_median); |
|
68 | result.m_upperExtreme = endData.m_median + progress * (endData.m_upperExtreme - endData.m_median); | |
68 | result.m_index = endData.m_index; |
|
69 | result.m_index = endData.m_index; | |
69 | result.m_boxItems = endData.m_boxItems; |
|
70 | result.m_boxItems = endData.m_boxItems; | |
70 |
|
71 | |||
71 | // result.m_lowerExtreme = endData.m_lowerExtreme; |
|
72 | // result.m_lowerExtreme = endData.m_lowerExtreme; | |
72 | // result.m_lowerQuartile = endData.m_lowerQuartile; |
|
73 | // result.m_lowerQuartile = endData.m_lowerQuartile; | |
73 | // result.m_median = endData.m_median; |
|
74 | // result.m_median = endData.m_median; | |
74 | // result.m_upperQuartile = endData.m_upperQuartile; |
|
75 | // result.m_upperQuartile = endData.m_upperQuartile; | |
75 | // result.m_upperExtreme = endData.m_upperExtreme; |
|
76 | // result.m_upperExtreme = endData.m_upperExtreme; | |
76 | // result.m_index = endData.m_index; |
|
77 | // result.m_index = endData.m_index; | |
77 | // result.m_boxItems = endData.m_boxItems; |
|
78 | // result.m_boxItems = endData.m_boxItems; | |
78 |
|
79 | |||
79 | result.m_maxX = endData.m_maxX; |
|
80 | result.m_maxX = endData.m_maxX; | |
80 | result.m_minX = endData.m_minX; |
|
81 | result.m_minX = endData.m_minX; | |
81 | result.m_maxY = endData.m_maxY; |
|
82 | result.m_maxY = endData.m_maxY; | |
82 | result.m_minY = endData.m_minY; |
|
83 | result.m_minY = endData.m_minY; | |
83 |
|
|
84 | result.m_seriesIndex = endData.m_seriesIndex; | |
|
85 | result.m_seriesCount = endData.m_seriesCount; | |||
84 |
|
86 | |||
85 | return qVariantFromValue(result); |
|
87 | return qVariantFromValue(result); | |
86 | } |
|
88 | } | |
87 |
|
89 | |||
88 | void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value) |
|
90 | void BoxWhiskersAnimation::updateCurrentValue(const QVariant &value) | |
89 | { |
|
91 | { | |
90 | BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(value); |
|
92 | BoxWhiskersData data = qvariant_cast<BoxWhiskersData>(value); | |
91 | m_box->setLayout(data); |
|
93 | m_box->setLayout(data); | |
92 | } |
|
94 | } | |
93 |
|
95 | |||
94 | void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData) |
|
96 | void BoxWhiskersAnimation::setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData) | |
95 | { |
|
97 | { | |
96 | if (endData.m_index == 0) { |
|
|||
97 | qDebug() << "BoxPlotAnimation::setup m_upperExtreme" << endData.m_upperExtreme; |
|
|||
98 | } |
|
|||
99 | setKeyValueAt(0.0, qVariantFromValue(startData)); |
|
98 | setKeyValueAt(0.0, qVariantFromValue(startData)); | |
100 | setKeyValueAt(1.0, qVariantFromValue(endData)); |
|
99 | setKeyValueAt(1.0, qVariantFromValue(endData)); | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
|
102 | void BoxWhiskersAnimation::setEndData(const BoxWhiskersData &endData) | |||
|
103 | { | |||
|
104 | if (state() != QAbstractAnimation::Stopped) | |||
|
105 | stop(); | |||
|
106 | ||||
|
107 | setEndValue(qVariantFromValue(endData)); | |||
|
108 | } | |||
|
109 | ||||
103 | #include "moc_boxwhiskersanimation_p.cpp" |
|
110 | #include "moc_boxwhiskersanimation_p.cpp" | |
104 |
|
111 | |||
105 | QTCOMMERCIALCHART_END_NAMESPACE |
|
112 | QTCOMMERCIALCHART_END_NAMESPACE | |
106 |
|
113 |
@@ -1,64 +1,65 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 BOXWHISKERSANIMATION_P_H |
|
30 | #ifndef BOXWHISKERSANIMATION_P_H | |
31 | #define BOXWHISKERSANIMATION_P_H |
|
31 | #define BOXWHISKERSANIMATION_P_H | |
32 |
|
32 | |||
33 | #include "chartanimation_p.h" |
|
33 | #include "chartanimation_p.h" | |
34 | #include "boxwhiskers_p.h" |
|
34 | #include "boxwhiskers_p.h" | |
35 | #include "boxwhiskersdata_p.h" |
|
35 | #include "boxwhiskersdata_p.h" | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class BoxPlotChartItem; |
|
39 | class BoxPlotChartItem; | |
40 |
|
40 | |||
41 | class BoxWhiskersAnimation : public ChartAnimation |
|
41 | class BoxWhiskersAnimation : public ChartAnimation | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | BoxWhiskersAnimation(BoxPlotChartItem *item); |
|
46 | BoxWhiskersAnimation(BoxPlotChartItem *item); | |
47 | BoxWhiskersAnimation(BoxWhiskers *box); |
|
47 | BoxWhiskersAnimation(BoxWhiskers *box); | |
48 | ~BoxWhiskersAnimation(); |
|
48 | ~BoxWhiskersAnimation(); | |
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 | void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData); |
|
54 | void setup(const BoxWhiskersData &startData, const BoxWhiskersData &endData); | |
|
55 | void setEndData(const BoxWhiskersData &endData); | |||
55 |
|
56 | |||
56 | protected: |
|
57 | protected: | |
57 | BoxPlotChartItem *m_item; |
|
58 | BoxPlotChartItem *m_item; | |
58 | BoxWhiskers *m_box; |
|
59 | BoxWhiskers *m_box; | |
59 | BoxWhiskersData *m_boxData; |
|
60 | BoxWhiskersData *m_boxData; | |
60 | }; |
|
61 | }; | |
61 |
|
62 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE | |
63 |
|
64 | |||
64 | #endif // BOXWHISKERSANIMATION_P_H |
|
65 | #endif // BOXWHISKERSANIMATION_P_H |
@@ -1,193 +1,189 | |||||
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 "boxwhiskers_p.h" |
|
21 | #include "boxwhiskers_p.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
24 | #include <QWidget> |
|
24 | #include <QWidget> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) : |
|
28 | BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) : | |
29 | QGraphicsObject(parent), |
|
29 | QGraphicsObject(parent), | |
30 | m_domain(domain) |
|
30 | m_domain(domain) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | BoxWhiskers::~BoxWhiskers() |
|
34 | BoxWhiskers::~BoxWhiskers() | |
35 | { |
|
35 | { | |
36 | //qDebug() << "BoxWhiskers::~BoxWhiskers()"; |
|
36 | //qDebug() << "BoxWhiskers::~BoxWhiskers()"; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
39 | void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
40 | { |
|
40 | { | |
41 | Q_UNUSED(event) |
|
41 | Q_UNUSED(event) | |
42 |
|
42 | |||
43 | qDebug() << "BoxWhiskers::mousePressEvent"; |
|
43 | qDebug() << "BoxWhiskers::mousePressEvent"; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
46 | void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
47 | { |
|
47 | { | |
48 | Q_UNUSED(event) |
|
48 | Q_UNUSED(event) | |
49 |
|
49 | |||
50 | qDebug() << "BoxWhiskers::hoverEnterEvent"; |
|
50 | qDebug() << "BoxWhiskers::hoverEnterEvent"; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
53 | void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
54 | { |
|
54 | { | |
55 | Q_UNUSED(event) |
|
55 | Q_UNUSED(event) | |
56 |
|
56 | |||
57 | qDebug() << "BoxWhiskers::hoverLeaveEvent"; |
|
57 | qDebug() << "BoxWhiskers::hoverLeaveEvent"; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void BoxWhiskers::setBrush(const QBrush &brush) |
|
60 | void BoxWhiskers::setBrush(const QBrush &brush) | |
61 | { |
|
61 | { | |
62 | m_brush = brush; |
|
62 | m_brush = brush; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void BoxWhiskers::setPen(const QPen &pen) |
|
65 | void BoxWhiskers::setPen(const QPen &pen) | |
66 | { |
|
66 | { | |
67 | m_pen = pen; |
|
67 | m_pen = pen; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) |
|
70 | void BoxWhiskers::setLayout(const BoxWhiskersData &data) | |
71 | { |
|
71 | { | |
72 | m_data = data; |
|
72 | m_data = data; | |
73 | // if (m_data.m_index == 1) |
|
73 | // if (m_data.m_index == 1) | |
74 | // qDebug() << "BoxWhiskers::setLayout"; |
|
74 | // qDebug() << "BoxWhiskers::setLayout"; | |
75 | updateGeometry(); |
|
75 | updateGeometry(); | |
76 | //update(0.0, 0.0, m_data.m_domainSize.width(), m_data.m_domainSize.height()); |
|
|||
77 | update(); |
|
76 | update(); | |
78 | } |
|
77 | } | |
79 |
|
78 | |||
80 |
|
79 | |||
81 | QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
80 | QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
82 | { |
|
81 | { | |
83 | //Q_UNUSED(which) |
|
82 | //Q_UNUSED(which) | |
84 | Q_UNUSED(constraint) |
|
83 | Q_UNUSED(constraint) | |
85 |
|
84 | |||
86 | qDebug() << "BoxWhiskers::sizeHint, which = " << which; |
|
85 | qDebug() << "BoxWhiskers::sizeHint, which = " << which; | |
87 |
|
86 | |||
88 | return QSizeF(); |
|
87 | return QSizeF(); | |
89 | } |
|
88 | } | |
90 |
|
89 | |||
91 | void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused? |
|
90 | void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused? | |
92 | { |
|
91 | { | |
93 | Q_UNUSED(rect) |
|
92 | Q_UNUSED(rect) | |
94 |
|
93 | |||
95 | qDebug() << "BoxWhiskers::setGeometry"; |
|
94 | qDebug() << "BoxWhiskers::setGeometry"; | |
96 | } |
|
95 | } | |
97 |
|
96 | |||
98 | void BoxWhiskers::setDomainSize(const QSizeF &size) |
|
97 | void BoxWhiskers::setDomainSize(const QSizeF &size) | |
99 | { |
|
98 | { | |
100 | m_domainSize = size; |
|
99 | m_domainSize = size; | |
101 |
|
100 | |||
102 | updateBoundingRect(); |
|
101 | updateBoundingRect(); | |
103 | } |
|
102 | } | |
104 |
|
103 | |||
105 | QRectF BoxWhiskers::boundingRect() const |
|
104 | QRectF BoxWhiskers::boundingRect() const | |
106 | { |
|
105 | { | |
107 | return m_boundingRect; |
|
106 | return m_boundingRect; | |
108 | } |
|
107 | } | |
109 |
|
108 | |||
110 | void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
109 | void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
111 | { |
|
110 | { | |
112 | Q_UNUSED(option) |
|
111 | Q_UNUSED(option) | |
113 | Q_UNUSED(widget) |
|
112 | Q_UNUSED(widget) | |
114 | //Q_UNUSED(painter) |
|
113 | //Q_UNUSED(painter) | |
115 |
|
114 | |||
116 | //painter->save(); |
|
115 | //painter->save(); | |
117 | //painter->setClipRect(parentItem()->boundingRect()); |
|
116 | //painter->setClipRect(parentItem()->boundingRect()); | |
118 | painter->setPen(m_pen); |
|
117 | painter->setPen(m_pen); | |
119 | painter->setBrush(m_brush); |
|
118 | painter->setBrush(m_brush); | |
120 | qreal spanY = m_data.m_maxY - m_data.m_minY; |
|
119 | qreal spanY = m_data.m_maxY - m_data.m_minY; | |
121 | //painter->setClipRect(parentItem()->boundingRect()); |
|
120 | //painter->setClipRect(parentItem()->boundingRect()); | |
122 | painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY); |
|
121 | painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY); | |
123 | painter->drawPath(m_boxPath); |
|
122 | painter->drawPath(m_boxPath); | |
124 | //painter->restore(); |
|
123 | //painter->restore(); | |
125 | } |
|
124 | } | |
126 |
|
125 | |||
127 | void BoxWhiskers::updateGeometry() |
|
126 | void BoxWhiskers::updateGeometry() | |
128 | { |
|
127 | { | |
129 | prepareGeometryChange(); |
|
128 | prepareGeometryChange(); | |
130 |
|
129 | |||
131 | QPainterPath path; |
|
130 | QPainterPath path; | |
132 |
|
131 | |||
133 | // TODO: Dirty hack |
|
|||
134 | if (m_data.m_seriesCount == 0) m_data.m_seriesCount = 1; |
|
|||
135 |
|
||||
136 | qreal columnWidth = 1.0 / m_data.m_seriesCount; |
|
132 | qreal columnWidth = 1.0 / m_data.m_seriesCount; | |
137 | qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
133 | qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
138 | qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
134 | qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
139 | qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex; |
|
135 | qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex; | |
140 |
|
136 | |||
141 | //whisker = 0.35 0.75 |
|
137 | //whisker = 0.35 0.75 | |
142 |
|
138 | |||
143 | // Upper whisker |
|
139 | // Upper whisker | |
144 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); |
|
140 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); | |
145 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); |
|
141 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); | |
146 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); |
|
142 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme); | |
147 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile); |
|
143 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile); | |
148 | path.closeSubpath(); |
|
144 | path.closeSubpath(); | |
149 |
|
145 | |||
150 | // Middle Box |
|
146 | // Middle Box | |
151 | path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile, |
|
147 | path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile, | |
152 | 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile); |
|
148 | 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile); | |
153 |
|
149 | |||
154 | // Median/mean line |
|
150 | // Median/mean line | |
155 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median); |
|
151 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median); | |
156 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median); |
|
152 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median); | |
157 |
|
153 | |||
158 | // Lower whisker |
|
154 | // Lower whisker | |
159 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); |
|
155 | path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); | |
160 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); |
|
156 | path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); | |
161 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); |
|
157 | path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme); | |
162 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile); |
|
158 | path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile); | |
163 | path.closeSubpath(); |
|
159 | path.closeSubpath(); | |
164 |
|
160 | |||
165 | m_boxPath = path; |
|
161 | m_boxPath = path; | |
166 |
|
162 | |||
167 | updateBoundingRect(); |
|
163 | updateBoundingRect(); | |
168 |
|
164 | |||
169 | // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); |
|
165 | // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); | |
170 | // qreal scaleX = m_domainSize.width() / m_data.m_boxItems; |
|
166 | // qreal scaleX = m_domainSize.width() / m_data.m_boxItems; | |
171 | // QRectF br = path.boundingRect(); |
|
167 | // QRectF br = path.boundingRect(); | |
172 | // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); |
|
168 | // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); | |
173 |
|
169 | |||
174 | if (m_data.m_index == 5) { |
|
170 | if (m_data.m_index == 5) { | |
175 | //qDebug() << "myValue = " << myValue; |
|
171 | //qDebug() << "myValue = " << myValue; | |
176 | //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme; |
|
172 | //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme; | |
177 | //qDebug() << "m_boundingRect = " << m_boundingRect; |
|
173 | //qDebug() << "m_boundingRect = " << m_boundingRect; | |
178 | // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = " |
|
174 | // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = " | |
179 | // << m_boundingRect.width() << ", height = " << m_boundingRect.height(); |
|
175 | // << m_boundingRect.width() << ", height = " << m_boundingRect.height(); | |
180 | } |
|
176 | } | |
181 | } |
|
177 | } | |
182 |
|
178 | |||
183 | void BoxWhiskers::updateBoundingRect() |
|
179 | void BoxWhiskers::updateBoundingRect() | |
184 | { |
|
180 | { | |
185 | qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); |
|
181 | qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY); | |
186 | qreal scaleX = m_domainSize.width() / m_data.m_boxItems; |
|
182 | qreal scaleX = m_domainSize.width() / m_data.m_boxItems; | |
187 | QRectF br = m_boxPath.boundingRect(); |
|
183 | QRectF br = m_boxPath.boundingRect(); | |
188 | m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); |
|
184 | m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY); | |
189 | } |
|
185 | } | |
190 |
|
186 | |||
191 | #include "moc_boxwhiskers_p.cpp" |
|
187 | #include "moc_boxwhiskers_p.cpp" | |
192 |
|
188 | |||
193 | QTCOMMERCIALCHART_END_NAMESPACE |
|
189 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now