@@ -1,97 +1,97 | |||||
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 "horizontalbarchartitem_p.h" |
|
21 | #include "horizontalbarchartitem_p.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset_p.h" |
|
23 | #include "qbarset_p.h" | |
24 | #include "bar_p.h" |
|
24 | #include "bar_p.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) |
|
28 | HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) | |
29 | : AbstractBarChartItem(series, item) |
|
29 | : AbstractBarChartItem(series, item) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void HorizontalBarChartItem::initializeLayout() |
|
33 | void HorizontalBarChartItem::initializeLayout() | |
34 | { |
|
34 | { | |
35 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
35 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
36 | qreal setCount = m_series->count(); |
|
36 | qreal setCount = m_series->count(); | |
37 | qreal barWidth = m_series->d_func()->barWidth(); |
|
37 | qreal barWidth = m_series->d_func()->barWidth(); | |
38 |
|
38 | |||
39 | m_layout.clear(); |
|
39 | m_layout.clear(); | |
40 | for(int category = 0; category < categoryCount; category++) { |
|
40 | for(int category = 0; category < categoryCount; category++) { | |
41 | for (int set = 0; set < setCount; set++) { |
|
41 | for (int set = 0; set < setCount; set++) { | |
42 | QRectF rect; |
|
42 | QRectF rect; | |
43 | QPointF topLeft; |
|
43 | QPointF topLeft; | |
44 | QPointF bottomRight; |
|
44 | QPointF bottomRight; | |
45 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { |
|
45 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { | |
46 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth), m_validData); |
|
46 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth), m_validData); | |
47 |
bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category |
|
47 | bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData); | |
48 | } else { |
|
48 | } else { | |
49 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth), m_validData); |
|
49 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth), m_validData); | |
50 | bottomRight = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData); |
|
50 | bottomRight = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | if (!m_validData) |
|
53 | if (!m_validData) | |
54 | return; |
|
54 | return; | |
55 |
|
55 | |||
56 | rect.setTopLeft(topLeft); |
|
56 | rect.setTopLeft(topLeft); | |
57 | rect.setBottomRight(bottomRight); |
|
57 | rect.setBottomRight(bottomRight); | |
58 | m_layout.append(rect.normalized()); |
|
58 | m_layout.append(rect.normalized()); | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | QVector<QRectF> HorizontalBarChartItem::calculateLayout() |
|
63 | QVector<QRectF> HorizontalBarChartItem::calculateLayout() | |
64 | { |
|
64 | { | |
65 | QVector<QRectF> layout; |
|
65 | QVector<QRectF> layout; | |
66 |
|
66 | |||
67 | // Use temporary qreals for accuracy |
|
67 | // Use temporary qreals for accuracy | |
68 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
68 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
69 | qreal setCount = m_series->count(); |
|
69 | qreal setCount = m_series->count(); | |
70 | qreal barWidth = m_series->d_func()->barWidth(); |
|
70 | qreal barWidth = m_series->d_func()->barWidth(); | |
71 |
|
71 | |||
72 | for(int category = 0; category < categoryCount; category++) { |
|
72 | for(int category = 0; category < categoryCount; category++) { | |
73 | for (int set = 0; set < setCount; set++) { |
|
73 | for (int set = 0; set < setCount; set++) { | |
74 | qreal value = m_series->barSets().at(set)->at(category); |
|
74 | qreal value = m_series->barSets().at(set)->at(category); | |
75 | QRectF rect; |
|
75 | QRectF rect; | |
76 | QPointF topLeft; |
|
76 | QPointF topLeft; | |
77 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
77 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
78 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth), m_validData); |
|
78 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth), m_validData); | |
79 | else |
|
79 | else | |
80 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth), m_validData); |
|
80 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth), m_validData); | |
81 |
|
81 | |||
82 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData); |
|
82 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData); | |
83 |
|
83 | |||
84 | if (!m_validData) |
|
84 | if (!m_validData) | |
85 | return QVector<QRectF>(); |
|
85 | return QVector<QRectF>(); | |
86 |
|
86 | |||
87 | rect.setTopLeft(topLeft); |
|
87 | rect.setTopLeft(topLeft); | |
88 | rect.setBottomRight(bottomRight); |
|
88 | rect.setBottomRight(bottomRight); | |
89 | layout.append(rect.normalized()); |
|
89 | layout.append(rect.normalized()); | |
90 | } |
|
90 | } | |
91 | } |
|
91 | } | |
92 | return layout; |
|
92 | return layout; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | #include "moc_horizontalbarchartitem_p.cpp" |
|
95 | #include "moc_horizontalbarchartitem_p.cpp" | |
96 |
|
96 | |||
97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,97 +1,97 | |||||
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 "barchartitem_p.h" |
|
21 | #include "barchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qabstractbarseries_p.h" |
|
23 | #include "qabstractbarseries_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qbarset_p.h" |
|
25 | #include "qbarset_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : |
|
29 | BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
30 | AbstractBarChartItem(series, item) |
|
30 | AbstractBarChartItem(series, item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void BarChartItem::initializeLayout() |
|
34 | void BarChartItem::initializeLayout() | |
35 | { |
|
35 | { | |
36 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
36 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
37 | qreal setCount = m_series->count(); |
|
37 | qreal setCount = m_series->count(); | |
38 | qreal barWidth = m_series->d_func()->barWidth(); |
|
38 | qreal barWidth = m_series->d_func()->barWidth(); | |
39 |
|
39 | |||
40 | m_layout.clear(); |
|
40 | m_layout.clear(); | |
41 | for(int category = 0; category < categoryCount; category++) { |
|
41 | for(int category = 0; category < categoryCount; category++) { | |
42 | for (int set = 0; set < setCount; set++) { |
|
42 | for (int set = 0; set < setCount; set++) { | |
43 | QRectF rect; |
|
43 | QRectF rect; | |
44 | QPointF topLeft; |
|
44 | QPointF topLeft; | |
45 | QPointF bottomRight; |
|
45 | QPointF bottomRight; | |
46 |
|
46 | |||
47 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { |
|
47 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { | |
48 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, domain()->minY()), m_validData); |
|
48 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, domain()->minY()), m_validData); | |
49 |
bottomRight = domain()->calculateGeometryPoint(QPointF(category |
|
49 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, domain()->minY()), m_validData); | |
50 | } else { |
|
50 | } else { | |
51 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0), m_validData); |
|
51 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0), m_validData); | |
52 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0), m_validData); |
|
52 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0), m_validData); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | if (!m_validData) |
|
55 | if (!m_validData) | |
56 | return; |
|
56 | return; | |
57 | rect.setTopLeft(topLeft); |
|
57 | rect.setTopLeft(topLeft); | |
58 | rect.setBottomRight(bottomRight); |
|
58 | rect.setBottomRight(bottomRight); | |
59 | m_layout.append(rect.normalized()); |
|
59 | m_layout.append(rect.normalized()); | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | QVector<QRectF> BarChartItem::calculateLayout() |
|
64 | QVector<QRectF> BarChartItem::calculateLayout() | |
65 | { |
|
65 | { | |
66 | QVector<QRectF> layout; |
|
66 | QVector<QRectF> layout; | |
67 |
|
67 | |||
68 | // Use temporary qreals for accuracy |
|
68 | // Use temporary qreals for accuracy | |
69 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
69 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
70 | qreal setCount = m_series->count(); |
|
70 | qreal setCount = m_series->count(); | |
71 | qreal barWidth = m_series->d_func()->barWidth(); |
|
71 | qreal barWidth = m_series->d_func()->barWidth(); | |
72 |
|
72 | |||
73 | for(int category = 0; category < categoryCount; category++) { |
|
73 | for(int category = 0; category < categoryCount; category++) { | |
74 | for (int set = 0; set < setCount; set++) { |
|
74 | for (int set = 0; set < setCount; set++) { | |
75 | qreal value = m_series->barSets().at(set)->at(category); |
|
75 | qreal value = m_series->barSets().at(set)->at(category); | |
76 | QRectF rect; |
|
76 | QRectF rect; | |
77 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value), m_validData); |
|
77 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value), m_validData); | |
78 | QPointF bottomRight; |
|
78 | QPointF bottomRight; | |
79 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
79 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
80 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY()), m_validData); |
|
80 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY()), m_validData); | |
81 | else |
|
81 | else | |
82 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0), m_validData); |
|
82 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0), m_validData); | |
83 |
|
83 | |||
84 | if (!m_validData) |
|
84 | if (!m_validData) | |
85 | return QVector<QRectF>(); |
|
85 | return QVector<QRectF>(); | |
86 |
|
86 | |||
87 | rect.setTopLeft(topLeft); |
|
87 | rect.setTopLeft(topLeft); | |
88 | rect.setBottomRight(bottomRight); |
|
88 | rect.setBottomRight(bottomRight); | |
89 | layout.append(rect.normalized()); |
|
89 | layout.append(rect.normalized()); | |
90 | } |
|
90 | } | |
91 | } |
|
91 | } | |
92 | return layout; |
|
92 | return layout; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | #include "moc_barchartitem_p.cpp" |
|
95 | #include "moc_barchartitem_p.cpp" | |
96 |
|
96 | |||
97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now