@@ -1,97 +1,97 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "horizontalbarchartitem_p.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset_p.h" |
|
24 | 24 | #include "bar_p.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) |
|
29 | 29 | : AbstractBarChartItem(series, item) |
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | void HorizontalBarChartItem::initializeLayout() |
|
34 | 34 | { |
|
35 | 35 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
36 | 36 | qreal setCount = m_series->count(); |
|
37 | 37 | qreal barWidth = m_series->d_func()->barWidth(); |
|
38 | 38 | |
|
39 | 39 | m_layout.clear(); |
|
40 | 40 | for(int category = 0; category < categoryCount; category++) { |
|
41 | 41 | for (int set = 0; set < setCount; set++) { |
|
42 | 42 | QRectF rect; |
|
43 | 43 | QPointF topLeft; |
|
44 | 44 | QPointF bottomRight; |
|
45 | 45 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { |
|
46 | 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 | 48 | } else { |
|
49 | 49 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth), m_validData); |
|
50 | 50 | bottomRight = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData); |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | if (!m_validData) |
|
54 | 54 | return; |
|
55 | 55 | |
|
56 | 56 | rect.setTopLeft(topLeft); |
|
57 | 57 | rect.setBottomRight(bottomRight); |
|
58 | 58 | m_layout.append(rect.normalized()); |
|
59 | 59 | } |
|
60 | 60 | } |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | QVector<QRectF> HorizontalBarChartItem::calculateLayout() |
|
64 | 64 | { |
|
65 | 65 | QVector<QRectF> layout; |
|
66 | 66 | |
|
67 | 67 | // Use temporary qreals for accuracy |
|
68 | 68 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
69 | 69 | qreal setCount = m_series->count(); |
|
70 | 70 | qreal barWidth = m_series->d_func()->barWidth(); |
|
71 | 71 | |
|
72 | 72 | for(int category = 0; category < categoryCount; category++) { |
|
73 | 73 | for (int set = 0; set < setCount; set++) { |
|
74 | 74 | qreal value = m_series->barSets().at(set)->at(category); |
|
75 | 75 | QRectF rect; |
|
76 | 76 | QPointF topLeft; |
|
77 | 77 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
78 | 78 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth), m_validData); |
|
79 | 79 | else |
|
80 | 80 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth), m_validData); |
|
81 | 81 | |
|
82 | 82 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData); |
|
83 | 83 | |
|
84 | 84 | if (!m_validData) |
|
85 | 85 | return QVector<QRectF>(); |
|
86 | 86 | |
|
87 | 87 | rect.setTopLeft(topLeft); |
|
88 | 88 | rect.setBottomRight(bottomRight); |
|
89 | 89 | layout.append(rect.normalized()); |
|
90 | 90 | } |
|
91 | 91 | } |
|
92 | 92 | return layout; |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | #include "moc_horizontalbarchartitem_p.cpp" |
|
96 | 96 | |
|
97 | 97 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,97 +1,97 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "barchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 | 23 | #include "qabstractbarseries_p.h" |
|
24 | 24 | #include "qbarset.h" |
|
25 | 25 | #include "qbarset_p.h" |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : |
|
30 | 30 | AbstractBarChartItem(series, item) |
|
31 | 31 | { |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | void BarChartItem::initializeLayout() |
|
35 | 35 | { |
|
36 | 36 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
37 | 37 | qreal setCount = m_series->count(); |
|
38 | 38 | qreal barWidth = m_series->d_func()->barWidth(); |
|
39 | 39 | |
|
40 | 40 | m_layout.clear(); |
|
41 | 41 | for(int category = 0; category < categoryCount; category++) { |
|
42 | 42 | for (int set = 0; set < setCount; set++) { |
|
43 | 43 | QRectF rect; |
|
44 | 44 | QPointF topLeft; |
|
45 | 45 | QPointF bottomRight; |
|
46 | 46 | |
|
47 | 47 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { |
|
48 | 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 | 50 | } else { |
|
51 | 51 | topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0), m_validData); |
|
52 | 52 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0), m_validData); |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | if (!m_validData) |
|
56 | 56 | return; |
|
57 | 57 | rect.setTopLeft(topLeft); |
|
58 | 58 | rect.setBottomRight(bottomRight); |
|
59 | 59 | m_layout.append(rect.normalized()); |
|
60 | 60 | } |
|
61 | 61 | } |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | QVector<QRectF> BarChartItem::calculateLayout() |
|
65 | 65 | { |
|
66 | 66 | QVector<QRectF> layout; |
|
67 | 67 | |
|
68 | 68 | // Use temporary qreals for accuracy |
|
69 | 69 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
70 | 70 | qreal setCount = m_series->count(); |
|
71 | 71 | qreal barWidth = m_series->d_func()->barWidth(); |
|
72 | 72 | |
|
73 | 73 | for(int category = 0; category < categoryCount; category++) { |
|
74 | 74 | for (int set = 0; set < setCount; set++) { |
|
75 | 75 | qreal value = m_series->barSets().at(set)->at(category); |
|
76 | 76 | QRectF rect; |
|
77 | 77 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value), m_validData); |
|
78 | 78 | QPointF bottomRight; |
|
79 | 79 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
80 | 80 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY()), m_validData); |
|
81 | 81 | else |
|
82 | 82 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0), m_validData); |
|
83 | 83 | |
|
84 | 84 | if (!m_validData) |
|
85 | 85 | return QVector<QRectF>(); |
|
86 | 86 | |
|
87 | 87 | rect.setTopLeft(topLeft); |
|
88 | 88 | rect.setBottomRight(bottomRight); |
|
89 | 89 | layout.append(rect.normalized()); |
|
90 | 90 | } |
|
91 | 91 | } |
|
92 | 92 | return layout; |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | #include "moc_barchartitem_p.cpp" |
|
96 | 96 | |
|
97 | 97 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now