@@ -1,205 +1,212 | |||||
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 "abstractbarchartitem_p.h" |
|
21 | #include "abstractbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qabstractbarseries.h" |
|
25 | #include "qabstractbarseries.h" | |
26 | #include "qabstractbarseries_p.h" |
|
26 | #include "qabstractbarseries_p.h" | |
27 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
28 | #include "chartpresenter_p.h" |
|
28 | #include "chartpresenter_p.h" | |
29 | #include "charttheme_p.h" |
|
29 | #include "charttheme_p.h" | |
30 | #include "abstractbaranimation_p.h" |
|
30 | #include "abstractbaranimation_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : |
|
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
37 | ChartItem(series->d_func(),item), |
|
37 | ChartItem(series->d_func(),item), | |
38 | m_animation(0), |
|
38 | m_animation(0), | |
39 | m_series(series) |
|
39 | m_series(series) | |
40 | { |
|
40 | { | |
41 |
|
41 | |||
42 | setFlag(ItemClipsChildrenToShape); |
|
42 | setFlag(ItemClipsChildrenToShape); | |
43 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); |
|
43 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); | |
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); |
|
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); | |
45 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
45 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
46 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); |
|
46 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
47 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); |
|
47 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); | |
48 | connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged())); |
|
48 | connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged())); | |
49 | setZValue(ChartPresenter::BarSeriesZValue); |
|
49 | setZValue(ChartPresenter::BarSeriesZValue); | |
50 |
|
|
50 | handleDataStructureChanged(); | |
|
51 | handleVisibleChanged(); | |||
|
52 | handleUpdatedBars(); | |||
51 | } |
|
53 | } | |
52 |
|
54 | |||
53 | AbstractBarChartItem::~AbstractBarChartItem() |
|
55 | AbstractBarChartItem::~AbstractBarChartItem() | |
54 | { |
|
56 | { | |
55 | } |
|
57 | } | |
56 |
|
58 | |||
57 | void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
59 | void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
58 | { |
|
60 | { | |
59 | Q_UNUSED(painter); |
|
61 | Q_UNUSED(painter); | |
60 | Q_UNUSED(option); |
|
62 | Q_UNUSED(option); | |
61 | Q_UNUSED(widget); |
|
63 | Q_UNUSED(widget); | |
62 | } |
|
64 | } | |
63 |
|
65 | |||
64 | QRectF AbstractBarChartItem::boundingRect() const |
|
66 | QRectF AbstractBarChartItem::boundingRect() const | |
65 | { |
|
67 | { | |
66 | return m_rect; |
|
68 | return m_rect; | |
67 | } |
|
69 | } | |
68 |
|
70 | |||
69 | void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
71 | void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout) | |
70 | { |
|
72 | { | |
71 | if (m_animation) { |
|
73 | if (m_animation) { | |
72 | m_animation->setup(m_layout, layout); |
|
74 | m_animation->setup(m_layout, layout); | |
73 | presenter()->startAnimation(m_animation); |
|
75 | presenter()->startAnimation(m_animation); | |
74 | } else { |
|
76 | } else { | |
75 | setLayout(layout); |
|
77 | setLayout(layout); | |
76 | update(); |
|
78 | update(); | |
77 | } |
|
79 | } | |
78 | } |
|
80 | } | |
79 |
|
81 | |||
80 | void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation) |
|
82 | void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation) | |
81 | { |
|
83 | { | |
82 | m_animation = animation; |
|
84 | m_animation = animation; | |
83 | } |
|
85 | } | |
84 |
|
86 | |||
85 | void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout) |
|
87 | void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout) | |
86 | { |
|
88 | { | |
87 | if (layout.count() != m_bars.count()) |
|
89 | if (layout.count() != m_bars.count()) | |
88 | return; |
|
90 | return; | |
89 |
|
91 | |||
90 | m_layout = layout; |
|
92 | m_layout = layout; | |
91 |
|
93 | |||
92 | for (int i = 0; i < m_bars.count(); i++) |
|
94 | for (int i = 0; i < m_bars.count(); i++) { | |
93 | m_bars.at(i)->setRect(layout.at(i)); |
|
95 | m_bars.at(i)->setRect(layout.at(i)); | |
|
96 | QGraphicsSimpleTextItem *label = m_labels.at(i); | |||
|
97 | label->setPos(layout.at(i).center() - label->boundingRect().center()); | |||
|
98 | ||||
|
99 | } | |||
94 | } |
|
100 | } | |
95 | //handlers |
|
101 | //handlers | |
96 |
|
102 | |||
97 | void AbstractBarChartItem::handleDomainUpdated() |
|
103 | void AbstractBarChartItem::handleDomainUpdated() | |
98 | { |
|
104 | { | |
99 | m_domainMinX = domain()->minX(); |
|
105 | m_domainMinX = domain()->minX(); | |
100 | m_domainMaxX = domain()->maxX(); |
|
106 | m_domainMaxX = domain()->maxX(); | |
101 | m_domainMinY = domain()->minY(); |
|
107 | m_domainMinY = domain()->minY(); | |
102 | m_domainMaxY = domain()->maxY(); |
|
108 | m_domainMaxY = domain()->maxY(); | |
103 |
|
109 | |||
104 | QRectF rect(QPointF(0,0),domain()->size()); |
|
110 | QRectF rect(QPointF(0,0),domain()->size()); | |
105 |
|
111 | |||
106 | if(m_rect != rect){ |
|
112 | if(m_rect != rect){ | |
107 | prepareGeometryChange(); |
|
113 | prepareGeometryChange(); | |
108 | m_rect = rect; |
|
114 | m_rect = rect; | |
109 | } |
|
115 | } | |
110 |
|
116 | |||
111 | handleLayoutChanged(); |
|
117 | handleLayoutChanged(); | |
112 | } |
|
118 | } | |
113 |
|
119 | |||
114 | void AbstractBarChartItem::handleLayoutChanged() |
|
120 | void AbstractBarChartItem::handleLayoutChanged() | |
115 | { |
|
121 | { | |
116 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) |
|
122 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) | |
117 | return; // rect size zero. |
|
123 | return; // rect size zero. | |
118 | QVector<QRectF> layout = calculateLayout(); |
|
124 | QVector<QRectF> layout = calculateLayout(); | |
119 | applyLayout(layout); |
|
125 | applyLayout(layout); | |
120 | } |
|
126 | } | |
121 |
|
127 | |||
122 | void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible) |
|
128 | void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible) | |
123 | { |
|
129 | { | |
124 | foreach (QGraphicsSimpleTextItem *label, m_labels) |
|
130 | foreach (QGraphicsSimpleTextItem *label, m_labels) | |
125 | label->setVisible(visible); |
|
131 | label->setVisible(visible); | |
126 | update(); |
|
132 | update(); | |
127 | } |
|
133 | } | |
128 |
|
134 | |||
129 | void AbstractBarChartItem::handleDataStructureChanged() |
|
135 | void AbstractBarChartItem::handleDataStructureChanged() | |
130 | { |
|
136 | { | |
131 | foreach (QGraphicsItem *item, childItems()) |
|
137 | foreach (QGraphicsItem *item, childItems()) | |
132 | delete item; |
|
138 | delete item; | |
133 |
|
139 | |||
134 | m_bars.clear(); |
|
140 | m_bars.clear(); | |
135 | m_labels.clear(); |
|
141 | m_labels.clear(); | |
136 | m_layout.clear(); |
|
142 | m_layout.clear(); | |
137 |
|
143 | |||
138 | bool labelsVisible = m_series->isLabelsVisible(); |
|
144 | bool labelsVisible = m_series->isLabelsVisible(); | |
139 |
|
145 | |||
140 | // Create new graphic items for bars |
|
146 | // Create new graphic items for bars | |
141 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { |
|
147 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { | |
142 | for (int s = 0; s < m_series->count(); s++) { |
|
148 | for (int s = 0; s < m_series->count(); s++) { | |
143 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
149 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
144 |
|
150 | |||
145 | // Bars |
|
151 | // Bars | |
146 | Bar *bar = new Bar(set, c, this); |
|
152 | Bar *bar = new Bar(set, c, this); | |
147 | m_bars.append(bar); |
|
153 | m_bars.append(bar); | |
148 | connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*))); |
|
154 | connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*))); | |
149 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*))); |
|
155 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*))); | |
150 | connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int))); |
|
156 | connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int))); | |
151 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool))); |
|
157 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool))); | |
152 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
158 | m_layout.append(QRectF(0, 0, 0, 0)); | |
153 |
|
159 | |||
154 | // Labels |
|
160 | // Labels | |
155 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); |
|
161 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); | |
156 | label->setVisible(labelsVisible); |
|
162 | label->setVisible(labelsVisible); | |
157 | m_labels.append(label); |
|
163 | m_labels.append(label); | |
158 | } |
|
164 | } | |
159 | } |
|
165 | } | |
160 |
|
166 | |||
161 | if(themeManager()) themeManager()->updateSeries(m_series); |
|
167 | if(themeManager()) themeManager()->updateSeries(m_series); | |
162 | handleLayoutChanged(); |
|
168 | handleLayoutChanged(); | |
163 | } |
|
169 | } | |
164 |
|
170 | |||
165 | void AbstractBarChartItem::handleVisibleChanged() |
|
171 | void AbstractBarChartItem::handleVisibleChanged() | |
166 | { |
|
172 | { | |
167 | bool visible = m_series->isVisible(); |
|
173 | bool visible = m_series->isVisible(); | |
168 | handleLabelsVisibleChanged(visible); |
|
174 | handleLabelsVisibleChanged(visible); | |
169 | foreach (QGraphicsItem *item, childItems()) |
|
175 | foreach (QGraphicsItem *item, childItems()) | |
170 | item->setVisible(visible); |
|
176 | item->setVisible(visible); | |
171 | } |
|
177 | } | |
172 |
|
178 | |||
173 | void AbstractBarChartItem::handleOpacityChanged() |
|
179 | void AbstractBarChartItem::handleOpacityChanged() | |
174 | { |
|
180 | { | |
175 | foreach (QGraphicsItem *item, childItems()) |
|
181 | foreach (QGraphicsItem *item, childItems()) | |
176 | item->setOpacity(m_series->opacity()); |
|
182 | item->setOpacity(m_series->opacity()); | |
177 | } |
|
183 | } | |
178 |
|
184 | |||
179 | void AbstractBarChartItem::handleUpdatedBars() |
|
185 | void AbstractBarChartItem::handleUpdatedBars() | |
180 | { |
|
186 | { | |
181 | // Handle changes in pen, brush, labels etc. |
|
187 | // Handle changes in pen, brush, labels etc. | |
182 | int categoryCount = m_series->d_func()->categoryCount(); |
|
188 | int categoryCount = m_series->d_func()->categoryCount(); | |
183 | int setCount = m_series->count(); |
|
189 | int setCount = m_series->count(); | |
184 | int itemIndex(0); |
|
190 | int itemIndex(0); | |
185 |
|
191 | |||
186 | for (int category = 0; category < categoryCount; category++) { |
|
192 | for (int category = 0; category < categoryCount; category++) { | |
187 | for (int set = 0; set < setCount; set++) { |
|
193 | for (int set = 0; set < setCount; set++) { | |
188 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
194 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
189 | Bar *bar = m_bars.at(itemIndex); |
|
195 | Bar *bar = m_bars.at(itemIndex); | |
190 | bar->setPen(barSet->m_pen); |
|
196 | bar->setPen(barSet->m_pen); | |
191 | bar->setBrush(barSet->m_brush); |
|
197 | bar->setBrush(barSet->m_brush); | |
192 | bar->update(); |
|
198 | bar->update(); | |
193 |
|
199 | |||
194 | QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
200 | QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); | |
|
201 | label->setText(QString("%1").arg(barSet->value(category))); | |||
195 | label->setFont(barSet->m_labelFont); |
|
202 | label->setFont(barSet->m_labelFont); | |
196 | label->setBrush(barSet->m_labelBrush); |
|
203 | label->setBrush(barSet->m_labelBrush); | |
197 | label->update(); |
|
204 | label->update(); | |
198 | itemIndex++; |
|
205 | itemIndex++; | |
199 | } |
|
206 | } | |
200 | } |
|
207 | } | |
201 | } |
|
208 | } | |
202 |
|
209 | |||
203 | #include "moc_abstractbarchartitem_p.cpp" |
|
210 | #include "moc_abstractbarchartitem_p.cpp" | |
204 |
|
211 | |||
205 | QTCOMMERCIALCHART_END_NAMESPACE |
|
212 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,92 +1,92 | |||||
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 ABSTRACTBARCHARTITEM_H |
|
31 | #ifndef ABSTRACTBARCHARTITEM_H | |
32 | #define ABSTRACTBARCHARTITEM_H |
|
32 | #define ABSTRACTBARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "qabstractbarseries.h" |
|
35 | #include "qabstractbarseries.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 | class AbstractBarAnimation; |
|
44 | class AbstractBarAnimation; | |
45 |
|
45 | |||
46 | class AbstractBarChartItem : public ChartItem |
|
46 | class AbstractBarChartItem : public ChartItem | |
47 | { |
|
47 | { | |
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 | public: |
|
49 | public: | |
50 | AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); |
|
50 | AbstractBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
51 | virtual ~AbstractBarChartItem(); |
|
51 | virtual ~AbstractBarChartItem(); | |
52 |
|
52 | |||
53 | public: |
|
53 | public: | |
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
55 | QRectF boundingRect() const; |
|
55 | QRectF boundingRect() const; | |
56 |
|
56 | |||
57 | virtual QVector<QRectF> calculateLayout() = 0; |
|
57 | virtual QVector<QRectF> calculateLayout() = 0; | |
58 | virtual void applyLayout(const QVector<QRectF> &layout); |
|
58 | virtual void applyLayout(const QVector<QRectF> &layout); | |
59 | virtual void setAnimation(AbstractBarAnimation *animation); |
|
59 | virtual void setAnimation(AbstractBarAnimation *animation); | |
60 | void setLayout(const QVector<QRectF> &layout); |
|
60 | void setLayout(const QVector<QRectF> &layout); | |
61 | void updateLayout(const QVector<QRectF> &layout); |
|
61 | void updateLayout(const QVector<QRectF> &layout); | |
62 | QRectF geometry() const { return m_rect;} |
|
62 | QRectF geometry() const { return m_rect;} | |
63 |
|
63 | |||
64 | public Q_SLOTS: |
|
64 | public Q_SLOTS: | |
65 | void handleDomainUpdated(); |
|
65 | void handleDomainUpdated(); | |
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 | void handleVisibleChanged(); |
|
69 | void handleVisibleChanged(); | |
70 | void handleOpacityChanged(); |
|
70 | void handleOpacityChanged(); | |
71 | void handleUpdatedBars(); |
|
71 | virtual void handleUpdatedBars(); | |
72 |
|
72 | |||
73 | protected: |
|
73 | protected: | |
74 |
|
74 | |||
75 | qreal m_domainMinX; |
|
75 | qreal m_domainMinX; | |
76 | qreal m_domainMaxX; |
|
76 | qreal m_domainMaxX; | |
77 | qreal m_domainMinY; |
|
77 | qreal m_domainMinY; | |
78 | qreal m_domainMaxY; |
|
78 | qreal m_domainMaxY; | |
79 |
|
79 | |||
80 | QRectF m_rect; |
|
80 | QRectF m_rect; | |
81 | QVector<QRectF> m_layout; |
|
81 | QVector<QRectF> m_layout; | |
82 |
|
82 | |||
83 | AbstractBarAnimation *m_animation; |
|
83 | AbstractBarAnimation *m_animation; | |
84 |
|
84 | |||
85 | QAbstractBarSeries *m_series; // Not owned. |
|
85 | QAbstractBarSeries *m_series; // Not owned. | |
86 | QList<Bar *> m_bars; |
|
86 | QList<Bar *> m_bars; | |
87 | QList<QGraphicsSimpleTextItem *> m_labels; |
|
87 | QList<QGraphicsSimpleTextItem *> m_labels; | |
88 | }; |
|
88 | }; | |
89 |
|
89 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE | |
91 |
|
91 | |||
92 | #endif // ABSTRACTBARCHARTITEM_H |
|
92 | #endif // ABSTRACTBARCHARTITEM_H |
@@ -1,131 +1,70 | |||||
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 | QVector<QRectF> HorizontalBarChartItem::calculateLayout() |
|
33 | QVector<QRectF> HorizontalBarChartItem::calculateLayout() | |
34 | { |
|
34 | { | |
35 | QVector<QRectF> layout; |
|
35 | QVector<QRectF> layout; | |
36 |
|
36 | |||
37 | // Use temporary qreals for accuracy |
|
37 | // Use temporary qreals for accuracy | |
38 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
38 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
39 | qreal setCount = m_series->count(); |
|
39 | qreal setCount = m_series->count(); | |
40 | // bool barsVisible = m_series->isVisible(); |
|
|||
41 | qreal barWidth = m_series->d_func()->barWidth(); |
|
40 | qreal barWidth = m_series->d_func()->barWidth(); | |
42 |
|
41 | |||
43 | int itemIndex(0); |
|
42 | int itemIndex(0); | |
44 | for(int category = 0; category < categoryCount; category++) { |
|
43 | for(int category = 0; category < categoryCount; category++) { | |
45 | for (int set = 0; set < setCount; set++) { |
|
44 | for (int set = 0; set < setCount; set++) { | |
46 | qreal value = m_series->barSets().at(set)->at(category); |
|
45 | qreal value = m_series->barSets().at(set)->at(category); | |
47 | QRectF rect; |
|
46 | QRectF rect; | |
48 | QPointF topLeft; |
|
47 | QPointF topLeft; | |
49 | if (domain()->type() == AbstractDomain::LogXYDomain |
|
48 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
50 | || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
|||
51 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + (set + 1)/(setCount) * barWidth)); |
|
49 | topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + (set + 1)/(setCount) * barWidth)); | |
52 | else |
|
50 | else | |
53 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/(setCount) * barWidth)); |
|
51 | topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/(setCount) * barWidth)); | |
54 |
|
52 | |||
55 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set)/(setCount) * barWidth)); |
|
53 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set)/(setCount) * barWidth)); | |
56 | rect.setTopLeft(topLeft); |
|
54 | rect.setTopLeft(topLeft); | |
57 | rect.setBottomRight(bottomRight); |
|
55 | rect.setBottomRight(bottomRight); | |
58 | layout.append(rect); |
|
56 | layout.append(rect); | |
59 |
|
57 | |||
60 | QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
58 | QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); | |
|
59 | label->setPos(rect.center() - label->boundingRect().center()); | |||
61 | label->setZValue(200); |
|
60 | label->setZValue(200); | |
62 | itemIndex++; |
|
61 | itemIndex++; | |
63 | if (!qFuzzyCompare(value, 0)) |
|
|||
64 | label->setText(QString::number(value)); |
|
|||
65 | else |
|
|||
66 | label->setText(QString("")); |
|
|||
67 |
|
||||
68 | // label->setFont(m_series->barSets().at(set)->labelFont()); |
|
|||
69 | // label->setBrush(m_series->barSets().at(set)->labelBrush()); |
|
|||
70 | label->setBrush(Qt::black); |
|
62 | label->setBrush(Qt::black); | |
71 |
|
||||
72 | label->setPos(rect.center() - label->boundingRect().center()); |
|
|||
73 |
|
||||
74 | } |
|
63 | } | |
75 | } |
|
64 | } | |
76 |
|
||||
77 |
|
||||
78 | // // AbstractDomain: |
|
|||
79 | // qreal width = geometry().width(); |
|
|||
80 | // qreal height = geometry().height(); |
|
|||
81 | // qreal rangeY = m_domainMaxY - m_domainMinY; |
|
|||
82 | // qreal rangeX = m_domainMaxX - m_domainMinX; |
|
|||
83 | // qreal scaleY = (height / rangeY); |
|
|||
84 | // qreal scaleX = (width / rangeX); |
|
|||
85 |
|
||||
86 | // // On horizontal chart barWidth of the barseries means height of the rect. |
|
|||
87 | // qreal rectHeight = (scaleY / setCount) * m_series->d_func()->barWidth(); |
|
|||
88 |
|
||||
89 | // int itemIndex(0); |
|
|||
90 | // for (int category = 0; category < categoryCount; category++) { |
|
|||
91 | // qreal xPos = -scaleX * m_domainMinX + geometry().left(); |
|
|||
92 | // for (int set = 0; set < setCount; set++) { |
|
|||
93 | // QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
|||
94 |
|
||||
95 | // qreal yPos = geometry().bottom() + (m_domainMinY - barSet->pos(category)) * scaleY; |
|
|||
96 | // yPos += setCount * rectHeight / 2; |
|
|||
97 | // yPos -= set * rectHeight; |
|
|||
98 |
|
||||
99 | // qreal rectWidth = barSet->value(category) * scaleX; |
|
|||
100 | // Bar *bar = m_bars.at(itemIndex); |
|
|||
101 |
|
||||
102 | // QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight); |
|
|||
103 | // layout.append(rect); |
|
|||
104 | // bar->setPen(barSet->m_pen); |
|
|||
105 | // bar->setBrush(barSet->m_brush); |
|
|||
106 | // if (qFuzzyCompare(rectHeight, 0)) |
|
|||
107 | // bar->setVisible(false); |
|
|||
108 | // else |
|
|||
109 | // bar->setVisible(barsVisible); |
|
|||
110 |
|
||||
111 | // QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
|||
112 |
|
||||
113 | // if (!qFuzzyCompare(barSet->value(category), 0)) |
|
|||
114 | // label->setText(QString::number(barSet->value(category))); |
|
|||
115 | // else |
|
|||
116 | // label->setText(QString("")); |
|
|||
117 |
|
||||
118 | // label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2), |
|
|||
119 | // yPos - rectHeight / 2 - label->boundingRect().height() / 2); |
|
|||
120 | // label->setFont(barSet->m_labelFont); |
|
|||
121 | // label->setBrush(barSet->m_labelBrush); |
|
|||
122 |
|
||||
123 | // itemIndex++; |
|
|||
124 | // } |
|
|||
125 | // } |
|
|||
126 | return layout; |
|
65 | return layout; | |
127 | } |
|
66 | } | |
128 |
|
67 | |||
129 | #include "moc_horizontalbarchartitem_p.cpp" |
|
68 | #include "moc_horizontalbarchartitem_p.cpp" | |
130 |
|
69 | |||
131 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,122 +1,95 | |||||
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 "horizontalpercentbarchartitem_p.h" |
|
21 | #include "horizontalpercentbarchartitem_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 | HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) |
|
28 | HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) | |
29 | : AbstractBarChartItem(series, item) |
|
29 | : AbstractBarChartItem(series, item) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout() |
|
33 | QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout() | |
34 | { |
|
34 | { | |
35 | QVector<QRectF> layout; |
|
35 | QVector<QRectF> layout; | |
36 |
|
36 | |||
37 | // Use temporary qreals for accuracy |
|
37 | // Use temporary qreals for accuracy | |
38 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
38 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
39 | qreal setCount = m_series->count(); |
|
39 | qreal setCount = m_series->count(); | |
40 | // bool barsVisible = m_series->isVisible(); |
|
|||
41 |
|
||||
42 | qreal barWidth = m_series->d_func()->barWidth(); |
|
40 | qreal barWidth = m_series->d_func()->barWidth(); | |
43 |
|
41 | |||
44 | for(int category = 0; category < categoryCount; category++) { |
|
42 | for(int category = 0; category < categoryCount; category++) { | |
45 | qreal sum = 0; |
|
43 | qreal sum = 0; | |
46 | qreal categorySum = m_series->d_func()->categorySum(category); |
|
44 | qreal categorySum = m_series->d_func()->categorySum(category); | |
47 | for (int set = 0; set < setCount; set++) { |
|
45 | for (int set = 0; set < setCount; set++) { | |
48 | qreal value = m_series->barSets().at(set)->at(category); |
|
46 | qreal value = m_series->barSets().at(set)->at(category); | |
49 | QRectF rect; |
|
47 | QRectF rect; | |
50 | QPointF topLeft; |
|
48 | QPointF topLeft; | |
51 | if (domain()->type() == AbstractDomain::LogXYDomain |
|
49 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
52 | || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
|||
53 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category + barWidth/2)); |
|
50 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category + barWidth/2)); | |
54 | else |
|
51 | else | |
55 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category + barWidth/2)); |
|
52 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category + barWidth/2)); | |
56 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category - barWidth/2)); |
|
53 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category - barWidth/2)); | |
57 | rect.setTopLeft(topLeft); |
|
54 | rect.setTopLeft(topLeft); | |
58 | rect.setBottomRight(bottomRight); |
|
55 | rect.setBottomRight(bottomRight); | |
59 | layout.append(rect); |
|
56 | layout.append(rect); | |
60 | sum +=value; |
|
57 | sum +=value; | |
61 | } |
|
58 | } | |
62 | } |
|
59 | } | |
|
60 | return layout; | |||
|
61 | } | |||
63 |
|
62 | |||
64 | // // AbstractDomain: |
|
63 | void HorizontalPercentBarChartItem::handleUpdatedBars() | |
65 | // qreal width = geometry().width(); |
|
64 | { | |
66 | // qreal height = geometry().height(); |
|
65 | // Handle changes in pen, brush, labels etc. | |
67 | // qreal rangeY = m_domainMaxY - m_domainMinY; |
|
66 | int categoryCount = m_series->d_func()->categoryCount(); | |
68 | // qreal rangeX = m_domainMaxX - m_domainMinX; |
|
67 | int setCount = m_series->count(); | |
69 | // qreal scaleY = (height / rangeY); |
|
68 | int itemIndex(0); | |
70 | // qreal scaleX = (width / rangeX); |
|
|||
71 | // qreal rectHeight = scaleY * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect. |
|
|||
72 |
|
||||
73 | // int itemIndex(0); |
|
|||
74 | // for (int category = 0; category < categoryCount; category++) { |
|
|||
75 | // qreal colSum = m_series->d_func()->categorySum(category); |
|
|||
76 | // qreal percentage = (100 / colSum); |
|
|||
77 | // qreal xPos = -scaleX * m_domainMinX + geometry().left(); |
|
|||
78 | // for (int set = 0; set < setCount; set++) { |
|
|||
79 | // QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
|||
80 |
|
||||
81 | // qreal yPos = (m_domainMinY + 0.5 - barSet->pos(category)) * scaleY + geometry().bottom() - rectHeight / 2; |
|
|||
82 |
|
||||
83 | // qreal rectWidth = barSet->value(category) * percentage * scaleX; |
|
|||
84 | // Bar *bar = m_bars.at(itemIndex); |
|
|||
85 |
|
||||
86 | // QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight); |
|
|||
87 | // layout.append(rect); |
|
|||
88 | // bar->setPen(barSet->m_pen); |
|
|||
89 | // bar->setBrush(barSet->m_brush); |
|
|||
90 | // if (qFuzzyCompare(rectHeight, 0)) |
|
|||
91 | // bar->setVisible(false); |
|
|||
92 | // else |
|
|||
93 | // bar->setVisible(barsVisible); |
|
|||
94 |
|
||||
95 | // QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
|||
96 |
|
||||
97 | // if (!qFuzzyCompare(m_series->d_func()->valueAt(set, category), 0)) { |
|
|||
98 | // int p = m_series->d_func()->percentageAt(set, category) * 100; |
|
|||
99 | // QString vString(QString::number(p)); |
|
|||
100 | // vString.truncate(3); |
|
|||
101 | // vString.append("%"); |
|
|||
102 | // label->setText(vString); |
|
|||
103 | // } else { |
|
|||
104 | // label->setText(QString("")); |
|
|||
105 | // } |
|
|||
106 |
|
||||
107 | // label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2), |
|
|||
108 | // yPos - rectHeight / 2 - label->boundingRect().height() / 2); |
|
|||
109 | // label->setFont(barSet->m_labelFont); |
|
|||
110 | // label->setBrush(barSet->m_labelBrush); |
|
|||
111 |
|
69 | |||
112 | // itemIndex++; |
|
70 | for (int category = 0; category < categoryCount; category++) { | |
113 | // xPos += rectWidth; |
|
71 | for (int set = 0; set < setCount; set++) { | |
114 | // } |
|
72 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
115 | // } |
|
73 | Bar *bar = m_bars.at(itemIndex); | |
116 | return layout; |
|
74 | bar->setPen(barSet->m_pen); | |
|
75 | bar->setBrush(barSet->m_brush); | |||
|
76 | bar->update(); | |||
|
77 | ||||
|
78 | QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); | |||
|
79 | int p = m_series->d_func()->percentageAt(set, category) * 100; | |||
|
80 | QString vString(QString::number(p)); | |||
|
81 | vString.truncate(3); | |||
|
82 | vString.append("%"); | |||
|
83 | label->setText(vString); | |||
|
84 | label->setFont(barSet->m_labelFont); | |||
|
85 | label->setBrush(barSet->m_labelBrush); | |||
|
86 | label->update(); | |||
|
87 | itemIndex++; | |||
|
88 | } | |||
|
89 | } | |||
117 | } |
|
90 | } | |
118 |
|
91 | |||
119 | #include "moc_horizontalpercentbarchartitem_p.cpp" |
|
92 | #include "moc_horizontalpercentbarchartitem_p.cpp" | |
120 |
|
93 | |||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
94 | QTCOMMERCIALCHART_END_NAMESPACE | |
122 |
|
95 |
@@ -1,50 +1,51 | |||||
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 HORIZONTALPERCENTBARCHARTITEM_P_H |
|
30 | #ifndef HORIZONTALPERCENTBARCHARTITEM_P_H | |
31 | #define HORIZONTALPERCENTBARCHARTITEM_P_H |
|
31 | #define HORIZONTALPERCENTBARCHARTITEM_P_H | |
32 |
|
32 | |||
33 | #include "abstractbarchartitem_p.h" |
|
33 | #include "abstractbarchartitem_p.h" | |
34 | #include <QGraphicsItem> |
|
34 | #include <QGraphicsItem> | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class HorizontalPercentBarChartItem : public AbstractBarChartItem |
|
38 | class HorizontalPercentBarChartItem : public AbstractBarChartItem | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); |
|
42 | HorizontalPercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
|
43 | void handleUpdatedBars(); | |||
43 |
|
44 | |||
44 | private: |
|
45 | private: | |
45 | virtual QVector<QRectF> calculateLayout(); |
|
46 | virtual QVector<QRectF> calculateLayout(); | |
46 | }; |
|
47 | }; | |
47 |
|
48 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
49 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
50 | |||
50 | #endif // HORIZONTALPERCENTBARCHARTITEM_P_H |
|
51 | #endif // HORIZONTALPERCENTBARCHARTITEM_P_H |
@@ -1,134 +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 "horizontalstackedbarchartitem_p.h" |
|
21 | #include "horizontalstackedbarchartitem_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 | HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) |
|
28 | HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) | |
29 | : AbstractBarChartItem(series, item) |
|
29 | : AbstractBarChartItem(series, item) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout() |
|
33 | QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout() | |
34 | { |
|
34 | { | |
35 | QVector<QRectF> layout; |
|
35 | QVector<QRectF> layout; | |
36 |
|
36 | |||
37 | // Use temporary qreals for accuracy |
|
37 | // Use temporary qreals for accuracy | |
38 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
38 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
39 | qreal setCount = m_series->count(); |
|
39 | qreal setCount = m_series->count(); | |
40 | // bool barsVisible = m_series->isVisible(); |
|
|||
41 |
|
||||
42 | qreal barWidth = m_series->d_func()->barWidth(); |
|
40 | qreal barWidth = m_series->d_func()->barWidth(); | |
43 |
|
41 | |||
44 | for(int category = 0; category < categoryCount; category++) { |
|
42 | for(int category = 0; category < categoryCount; category++) { | |
45 | qreal positiveSum = 0; |
|
43 | qreal positiveSum = 0; | |
46 | qreal negativeSum = 0; |
|
44 | qreal negativeSum = 0; | |
47 | for (int set = 0; set < setCount; set++) { |
|
45 | for (int set = 0; set < setCount; set++) { | |
48 | qreal value = m_series->barSets().at(set)->at(category); |
|
46 | qreal value = m_series->barSets().at(set)->at(category); | |
49 | QRectF rect; |
|
47 | QRectF rect; | |
50 | QPointF topLeft; |
|
48 | QPointF topLeft; | |
51 | QPointF bottomRight; |
|
49 | QPointF bottomRight; | |
52 | if (value < 0) { |
|
50 | if (value < 0) { | |
53 | bottomRight = domain()->calculateGeometryPoint(QPointF(value + negativeSum, category - barWidth / 2)); |
|
51 | bottomRight = domain()->calculateGeometryPoint(QPointF(value + negativeSum, category - barWidth / 2)); | |
54 | if (domain()->type() == AbstractDomain::LogXYDomain |
|
52 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
55 | || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
|||
56 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : domain()->minX(), category + barWidth / 2)); |
|
53 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : domain()->minX(), category + barWidth / 2)); | |
57 | else |
|
54 | else | |
58 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : 0, category + barWidth / 2)); |
|
55 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : 0, category + barWidth / 2)); | |
59 | negativeSum += value; |
|
56 | negativeSum += value; | |
60 | } else { |
|
57 | } else { | |
61 | bottomRight = domain()->calculateGeometryPoint(QPointF(value + positiveSum, category - barWidth / 2)); |
|
58 | bottomRight = domain()->calculateGeometryPoint(QPointF(value + positiveSum, category - barWidth / 2)); | |
62 | if (domain()->type() == AbstractDomain::LogXYDomain |
|
59 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
63 | || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
|||
64 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : domain()->minX(), category + barWidth / 2)); |
|
60 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : domain()->minX(), category + barWidth / 2)); | |
65 | else |
|
61 | else | |
66 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : 0, category + barWidth / 2)); |
|
62 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : 0, category + barWidth / 2)); | |
67 | positiveSum += value; |
|
63 | positiveSum += value; | |
68 | } |
|
64 | } | |
69 | rect.setTopLeft(topLeft); |
|
65 | rect.setTopLeft(topLeft); | |
70 | rect.setBottomRight(bottomRight); |
|
66 | rect.setBottomRight(bottomRight); | |
71 | layout.append(rect); |
|
67 | layout.append(rect); | |
72 | } |
|
68 | } | |
73 | } |
|
69 | } | |
74 |
|
||||
75 | // // AbstractDomain: |
|
|||
76 | // qreal width = geometry().width(); |
|
|||
77 | // qreal height = geometry().height(); |
|
|||
78 | // qreal rangeY = m_domainMaxY - m_domainMinY; |
|
|||
79 | // qreal rangeX = m_domainMaxX - m_domainMinX; |
|
|||
80 | // qreal scaleY = (height / rangeY); |
|
|||
81 | // qreal scaleX = (width / rangeX); |
|
|||
82 | // qreal rectHeight = scaleY * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect. |
|
|||
83 |
|
||||
84 | // int itemIndex(0); |
|
|||
85 | // for (int category = 0; category < categoryCount; category++) { |
|
|||
86 | // qreal xMax = -scaleX * m_domainMinX + geometry().left(); |
|
|||
87 | // qreal xMin = -scaleX * m_domainMinX + geometry().left(); |
|
|||
88 | // for (int set = 0; set < setCount; set++) { |
|
|||
89 | // QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
|||
90 |
|
||||
91 | // qreal yPos = (m_domainMinY + 0.5 - barSet->pos(category)) * scaleY + geometry().bottom() - rectHeight / 2; |
|
|||
92 |
|
||||
93 | // qreal rectWidth = barSet->value(category) * scaleX; |
|
|||
94 | // Bar *bar = m_bars.at(itemIndex); |
|
|||
95 |
|
||||
96 | // bar->setPen(barSet->m_pen); |
|
|||
97 | // bar->setBrush(barSet->m_brush); |
|
|||
98 | // if (qFuzzyCompare(rectHeight, 0)) |
|
|||
99 | // bar->setVisible(false); |
|
|||
100 | // else |
|
|||
101 | // bar->setVisible(barsVisible); |
|
|||
102 |
|
||||
103 | // QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
|||
104 |
|
||||
105 | // if (!qFuzzyCompare(barSet->value(category), 0)) |
|
|||
106 | // label->setText(QString::number(barSet->value(category))); |
|
|||
107 | // else |
|
|||
108 | // label->setText(QString("")); |
|
|||
109 | // label->setFont(barSet->m_labelFont); |
|
|||
110 | // label->setBrush(barSet->m_labelBrush); |
|
|||
111 |
|
||||
112 | // if (rectWidth > 0) { |
|
|||
113 | // QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight); |
|
|||
114 | // layout.append(rect); |
|
|||
115 | // label->setPos(xMax + (rect.width() / 2 - label->boundingRect().width() / 2), |
|
|||
116 | // yPos - rectHeight / 2 - label->boundingRect().height() / 2); |
|
|||
117 | // xMax += rectWidth; |
|
|||
118 | // } else { |
|
|||
119 | // QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight); |
|
|||
120 | // layout.append(rect); |
|
|||
121 | // label->setPos(xMin + (rect.width() / 2 - label->boundingRect().width() / 2), |
|
|||
122 | // yPos - rectHeight / 2 - label->boundingRect().height() / 2); |
|
|||
123 | // xMin += rectWidth; |
|
|||
124 | // } |
|
|||
125 | // itemIndex++; |
|
|||
126 | // } |
|
|||
127 | // } |
|
|||
128 | return layout; |
|
70 | return layout; | |
129 | } |
|
71 | } | |
130 |
|
72 | |||
131 | #include "moc_horizontalstackedbarchartitem_p.cpp" |
|
73 | #include "moc_horizontalstackedbarchartitem_p.cpp" | |
132 |
|
74 | |||
133 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE | |
134 |
|
76 |
@@ -1,129 +1,63 | |||||
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 | QVector<QRectF> BarChartItem::calculateLayout() |
|
34 | QVector<QRectF> BarChartItem::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->count(); |
|
40 | qreal setCount = m_series->count(); | |
41 | // bool barsVisible = m_series->isVisible(); |
|
|||
42 | qreal barWidth = m_series->d_func()->barWidth(); |
|
41 | qreal barWidth = m_series->d_func()->barWidth(); | |
43 | // barWidth = 1.8; |
|
|||
44 |
|
42 | |||
45 | int itemIndex(0); |
|
|||
46 | for(int category = 0; category < categoryCount; category++) { |
|
43 | for(int category = 0; category < categoryCount; category++) { | |
47 | for (int set = 0; set < setCount; set++) { |
|
44 | for (int set = 0; set < setCount; set++) { | |
48 | qreal value = m_series->barSets().at(set)->at(category); |
|
45 | qreal value = m_series->barSets().at(set)->at(category); | |
49 | QRectF rect; |
|
46 | QRectF rect; | |
50 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value)); |
|
47 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value)); | |
51 | QPointF bottomRight; |
|
48 | QPointF bottomRight; | |
52 | if (domain()->type() == AbstractDomain::XLogYDomain |
|
49 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
53 | || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
|||
54 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY())); |
|
50 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY())); | |
55 | else |
|
51 | else | |
56 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0)); |
|
52 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0)); | |
57 | rect.setTopLeft(topLeft); |
|
53 | rect.setTopLeft(topLeft); | |
58 | rect.setBottomRight(bottomRight); |
|
54 | rect.setBottomRight(bottomRight); | |
59 | layout.append(rect); |
|
55 | layout.append(rect); | |
60 |
|
||||
61 | QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
|||
62 | label->setZValue(200); |
|
|||
63 | itemIndex++; |
|
|||
64 | if (!qFuzzyCompare(value, 0)) |
|
|||
65 | label->setText(QString::number(value)); |
|
|||
66 | else |
|
|||
67 | label->setText(QString("")); |
|
|||
68 |
|
||||
69 | // label->setFont(m_series->barSets().at(set)->labelFont()); |
|
|||
70 | // label->setBrush(m_series->barSets().at(set)->labelBrush()); |
|
|||
71 | label->setBrush(Qt::black); |
|
|||
72 |
|
||||
73 | label->setPos(rect.center() - label->boundingRect().center()); |
|
|||
74 |
|
||||
75 | } |
|
56 | } | |
76 | } |
|
57 | } | |
77 |
|
||||
78 | // AbstractDomain: |
|
|||
79 | // qreal width = geometry().width(); |
|
|||
80 | // qreal height = geometry().height(); |
|
|||
81 | // qreal rangeY = m_domainMaxY - m_domainMinY; |
|
|||
82 | // qreal rangeX = m_domainMaxX - m_domainMinX; |
|
|||
83 | // qreal scaleY = (height / rangeY); |
|
|||
84 | // qreal scaleX = (width / rangeX); |
|
|||
85 | // qreal rectWidth = (scaleX / setCount) * m_series->d_func()->barWidth(); |
|
|||
86 |
|
||||
87 | // int itemIndex(0); |
|
|||
88 | // for (int category = 0; category < categoryCount; category++) { |
|
|||
89 | // qreal yPos = height + scaleY * m_domainMinY + geometry().top(); |
|
|||
90 | // for (int set = 0; set < setCount; set++) { |
|
|||
91 | // QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
|||
92 |
|
||||
93 | // qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left(); |
|
|||
94 | // xPos -= setCount * rectWidth / 2; |
|
|||
95 | // xPos += set * rectWidth;barWidth / 2 |
|
|||
96 |
|
||||
97 | // qreal rectHeight = barSet->value(category) * scaleY; |
|
|||
98 | // Bar *bar = m_bars.at(itemIndex); |
|
|||
99 |
|
||||
100 | // QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight); |
|
|||
101 | // layout.append(rect); |
|
|||
102 | // bar->setPen(barSet->m_pen); |
|
|||
103 | // bar->setBrush(barSet->m_brush); |
|
|||
104 | // if (qFuzzyIsNull(rectHeight)) |
|
|||
105 | // bar->setVisible(false); |
|
|||
106 | // else |
|
|||
107 | // bar->setVisible(barsVisible); |
|
|||
108 |
|
||||
109 | // QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
|||
110 |
|
||||
111 | // if (!qFuzzyIsNull(barSet->value(category))) |
|
|||
112 | // label->setText(QString::number(barSet->value(category))); |
|
|||
113 | // else |
|
|||
114 | // label->setText(QString("")); |
|
|||
115 |
|
||||
116 | // label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2), |
|
|||
117 | // yPos - rectHeight / 2 - label->boundingRect().height() / 2); |
|
|||
118 | // label->setFont(barSet->m_labelFont); |
|
|||
119 | // label->setBrush(barSet->m_labelBrush); |
|
|||
120 |
|
||||
121 | // itemIndex++; |
|
|||
122 | // } |
|
|||
123 | // } |
|
|||
124 | return layout; |
|
58 | return layout; | |
125 | } |
|
59 | } | |
126 |
|
60 | |||
127 | #include "moc_barchartitem_p.cpp" |
|
61 | #include "moc_barchartitem_p.cpp" | |
128 |
|
62 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,122 +1,95 | |||||
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 "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 | PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : |
|
29 | PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
30 | AbstractBarChartItem(series, item) |
|
30 | AbstractBarChartItem(series, item) | |
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->count(); |
|
40 | qreal setCount = m_series->count(); | |
41 | // bool barsVisible = m_series->isVisible(); |
|
|||
42 |
|
||||
43 | qreal barWidth = m_series->d_func()->barWidth(); |
|
41 | qreal barWidth = m_series->d_func()->barWidth(); | |
44 |
|
42 | |||
45 | for(int category = 0; category < categoryCount; category++) { |
|
43 | for(int category = 0; category < categoryCount; category++) { | |
46 | qreal sum = 0; |
|
44 | qreal sum = 0; | |
47 | qreal categorySum = m_series->d_func()->categorySum(category); |
|
45 | qreal categorySum = m_series->d_func()->categorySum(category); | |
48 | for (int set = 0; set < setCount; set++) { |
|
46 | for (int set = 0; set < setCount; set++) { | |
49 | qreal value = m_series->barSets().at(set)->at(category); |
|
47 | qreal value = m_series->barSets().at(set)->at(category); | |
50 |
QRectF rect; |
|
48 | QRectF rect; | |
51 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, 100 * (value + sum)/categorySum)); |
|
49 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, 100 * (value + sum)/categorySum)); | |
52 | QPointF bottomRight; |
|
50 | QPointF bottomRight; | |
53 | if (domain()->type() == AbstractDomain::XLogYDomain |
|
51 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
54 | || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
|||
55 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : domain()->minY())); |
|
52 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : domain()->minY())); | |
56 | else |
|
53 | else | |
57 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0)); |
|
54 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0)); | |
58 | rect.setTopLeft(topLeft); |
|
55 | rect.setTopLeft(topLeft); | |
59 | rect.setBottomRight(bottomRight); |
|
56 | rect.setBottomRight(bottomRight); | |
60 | layout.append(rect); |
|
57 | layout.append(rect); | |
61 | sum +=value; |
|
58 | sum +=value; | |
62 | } |
|
59 | } | |
63 | } |
|
60 | } | |
|
61 | return layout; | |||
|
62 | } | |||
64 |
|
63 | |||
65 | // AbstractDomain: |
|
64 | void PercentBarChartItem::handleUpdatedBars() | |
66 | // qreal width = geometry().width(); |
|
65 | { | |
67 | // qreal height = geometry().height(); |
|
66 | // Handle changes in pen, brush, labels etc. | |
68 | // qreal rangeY = m_domainMaxY - m_domainMinY; |
|
67 | int categoryCount = m_series->d_func()->categoryCount(); | |
69 | // qreal rangeX = m_domainMaxX - m_domainMinX; |
|
68 | int setCount = m_series->count(); | |
70 | // qreal scaleY = (height / rangeY); |
|
69 | int itemIndex(0); | |
71 | // qreal scaleX = (width / rangeX); |
|
|||
72 | // qreal rectWidth = scaleX * m_series->d_func()->barWidth(); |
|
|||
73 |
|
||||
74 | // int itemIndex(0); |
|
|||
75 | // for (int category = 0; category < categoryCount; category++) { |
|
|||
76 | // qreal colSum = m_series->d_func()->categorySum(category); |
|
|||
77 | // qreal percentage = (100 / colSum); |
|
|||
78 | // qreal yPos = height + scaleY * m_domainMinY + geometry().top(); |
|
|||
79 | // for (int set = 0; set < setCount; set++) { |
|
|||
80 | // QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
|||
81 |
|
||||
82 | // qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left() - rectWidth / 2; |
|
|||
83 |
|
||||
84 | // qreal rectHeight = barSet->value(category) * percentage * scaleY; |
|
|||
85 | // Bar *bar = m_bars.at(itemIndex); |
|
|||
86 | // bar->setPen(barSet->m_pen); |
|
|||
87 | // bar->setBrush(barSet->m_brush); |
|
|||
88 | // if (qFuzzyIsNull(rectHeight)) |
|
|||
89 | // bar->setVisible(false); |
|
|||
90 | // else |
|
|||
91 | // bar->setVisible(barsVisible); |
|
|||
92 |
|
||||
93 | // QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight); |
|
|||
94 | // layout.append(rect); |
|
|||
95 |
|
||||
96 | // QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
|||
97 |
|
||||
98 | // if (!qFuzzyIsNull(m_series->d_func()->valueAt(set, category))) { |
|
|||
99 | // int p = m_series->d_func()->percentageAt(set, category) * 100; |
|
|||
100 | // QString vString(QString::number(p)); |
|
|||
101 | // vString.truncate(3); |
|
|||
102 | // vString.append("%"); |
|
|||
103 | // label->setText(vString); |
|
|||
104 | // } else { |
|
|||
105 | // label->setText(QString("")); |
|
|||
106 | // } |
|
|||
107 |
|
||||
108 | // label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2), |
|
|||
109 | // yPos - rectHeight / 2 - label->boundingRect().height() / 2); |
|
|||
110 | // label->setFont(barSet->m_labelFont); |
|
|||
111 | // label->setBrush(barSet->m_labelBrush); |
|
|||
112 |
|
70 | |||
113 | // itemIndex++; |
|
71 | for (int category = 0; category < categoryCount; category++) { | |
114 | // yPos -= rectHeight; |
|
72 | for (int set = 0; set < setCount; set++) { | |
115 | // } |
|
73 | QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
116 | // } |
|
74 | Bar *bar = m_bars.at(itemIndex); | |
117 | return layout; |
|
75 | bar->setPen(barSet->m_pen); | |
|
76 | bar->setBrush(barSet->m_brush); | |||
|
77 | bar->update(); | |||
|
78 | ||||
|
79 | QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); | |||
|
80 | int p = m_series->d_func()->percentageAt(set, category) * 100; | |||
|
81 | QString vString(QString::number(p)); | |||
|
82 | vString.truncate(3); | |||
|
83 | vString.append("%"); | |||
|
84 | label->setText(vString); | |||
|
85 | label->setFont(barSet->m_labelFont); | |||
|
86 | label->setBrush(barSet->m_labelBrush); | |||
|
87 | label->update(); | |||
|
88 | itemIndex++; | |||
|
89 | } | |||
|
90 | } | |||
118 | } |
|
91 | } | |
119 |
|
92 | |||
120 | #include "moc_percentbarchartitem_p.cpp" |
|
93 | #include "moc_percentbarchartitem_p.cpp" | |
121 |
|
94 | |||
122 | QTCOMMERCIALCHART_END_NAMESPACE |
|
95 | 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 "abstractbarchartitem_p.h" |
|
34 | #include "abstractbarchartitem_p.h" | |
35 | #include <QGraphicsItem> |
|
35 | #include <QGraphicsItem> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class QAbstractBarSeries; |
|
39 | class QAbstractBarSeries; | |
40 |
|
40 | |||
41 | class PercentBarChartItem : public AbstractBarChartItem |
|
41 | class PercentBarChartItem : public AbstractBarChartItem | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 | public: |
|
44 | public: | |
45 | PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); |
|
45 | PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); | |
|
46 | void handleUpdatedBars(); | |||
46 |
|
47 | |||
47 | private: |
|
48 | private: | |
48 | virtual QVector<QRectF> calculateLayout(); |
|
49 | virtual QVector<QRectF> calculateLayout(); | |
49 | }; |
|
50 | }; | |
50 |
|
51 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE | |
52 |
|
53 | |||
53 | #endif // PERCENTBARCHARTITEM_H |
|
54 | #endif // PERCENTBARCHARTITEM_H |
@@ -1,135 +1,75 | |||||
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 "qabstractbarseries_p.h" |
|
24 | #include "qabstractbarseries_p.h" | |
25 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : |
|
29 | StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : | |
30 | AbstractBarChartItem(series, item) |
|
30 | AbstractBarChartItem(series, item) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
35 | { |
|
35 | { | |
36 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
37 | // Use temporary qreals for accuracy |
|
37 | // Use temporary qreals for accuracy | |
38 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
38 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
39 | qreal setCount = m_series->count(); |
|
39 | qreal setCount = m_series->count(); | |
40 | // bool barsVisible = m_series->isVisible(); |
|
|||
41 | qreal barWidth = m_series->d_func()->barWidth(); |
|
40 | qreal barWidth = m_series->d_func()->barWidth(); | |
42 |
|
41 | |||
43 | for(int category = 0; category < categoryCount; category++) { |
|
42 | for(int category = 0; category < categoryCount; category++) { | |
44 | qreal positiveSum = 0; |
|
43 | qreal positiveSum = 0; | |
45 | qreal negativeSum = 0; |
|
44 | qreal negativeSum = 0; | |
46 | for (int set = 0; set < setCount; set++) { |
|
45 | for (int set = 0; set < setCount; set++) { | |
47 | qreal value = m_series->barSets().at(set)->at(category); |
|
46 | qreal value = m_series->barSets().at(set)->at(category); | |
48 | QRectF rect; |
|
47 | QRectF rect; | |
49 | QPointF topLeft; |
|
48 | QPointF topLeft; | |
50 | QPointF bottomRight; |
|
49 | QPointF bottomRight; | |
51 | if (value < 0) { |
|
50 | if (value < 0) { | |
52 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + negativeSum)); |
|
51 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + negativeSum)); | |
53 | if (domain()->type() == AbstractDomain::XLogYDomain |
|
52 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
54 | || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
|||
55 | topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : domain()->minY())); |
|
53 | topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : domain()->minY())); | |
56 | else |
|
54 | else | |
57 | topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : 0)); |
|
55 | topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : 0)); | |
58 | negativeSum += value; |
|
56 | negativeSum += value; | |
59 | } else { |
|
57 | } else { | |
60 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum)); |
|
58 | bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum)); | |
61 | if (domain()->type() == AbstractDomain::XLogYDomain |
|
59 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
62 | || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
|||
63 | topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY())); |
|
60 | topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY())); | |
64 | else |
|
61 | else | |
65 | topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0)); |
|
62 | topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0)); | |
66 | positiveSum += value; |
|
63 | positiveSum += value; | |
67 | } |
|
64 | } | |
68 | rect.setTopLeft(topLeft); |
|
65 | rect.setTopLeft(topLeft); | |
69 | rect.setBottomRight(bottomRight); |
|
66 | rect.setBottomRight(bottomRight); | |
70 | layout.append(rect); |
|
67 | layout.append(rect); | |
71 | } |
|
68 | } | |
72 | } |
|
69 | } | |
73 |
|
70 | return layout; | ||
74 |
|
||||
75 | // AbstractDomain: |
|
|||
76 | // qreal width = geometry().width(); |
|
|||
77 | // qreal height = geometry().height(); |
|
|||
78 | // qreal rangeY = m_domainMaxY - m_domainMinY; |
|
|||
79 | // qreal rangeX = m_domainMaxX - m_domainMinX; |
|
|||
80 | // qreal scaleY = (height / rangeY); |
|
|||
81 | // qreal scaleX = (width / rangeX); |
|
|||
82 | // qreal rectWidth = scaleX * m_series->d_func()->barWidth(); |
|
|||
83 |
|
||||
84 | // int itemIndex(0); |
|
|||
85 | // for (int category = 0; category < categoryCount; category++) { |
|
|||
86 | // qreal yMax = height + scaleY * m_domainMinY + geometry().top(); |
|
|||
87 | // qreal yMin = height + scaleY * m_domainMinY + geometry().top(); |
|
|||
88 | // for (int set = 0; set < setCount; set++) { |
|
|||
89 | // QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
|||
90 |
|
||||
91 | // qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left() - rectWidth / 2; |
|
|||
92 |
|
||||
93 | // qreal rectHeight = barSet->value(category) * scaleY; |
|
|||
94 | // Bar *bar = m_bars.at(itemIndex); |
|
|||
95 | // bar->setPen(barSet->m_pen); |
|
|||
96 | // bar->setBrush(barSet->m_brush); |
|
|||
97 | // if (qFuzzyIsNull(rectHeight)) |
|
|||
98 | // bar->setVisible(false); |
|
|||
99 | // else |
|
|||
100 | // bar->setVisible(barsVisible); |
|
|||
101 |
|
||||
102 | // QGraphicsSimpleTextItem *label = m_labels.at(itemIndex); |
|
|||
103 |
|
||||
104 | // if (!qFuzzyIsNull(barSet->value(category))) |
|
|||
105 | // label->setText(QString::number(barSet->value(category))); |
|
|||
106 | // else |
|
|||
107 | // label->setText(QString("")); |
|
|||
108 |
|
||||
109 | // label->setFont(barSet->m_labelFont); |
|
|||
110 | // label->setBrush(barSet->m_labelBrush); |
|
|||
111 |
|
||||
112 | // if (rectHeight < 0) { |
|
|||
113 | // QRectF rect(xPos, yMax - rectHeight, rectWidth, rectHeight); |
|
|||
114 | // layout.append(rect); |
|
|||
115 | // label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2), |
|
|||
116 | // yMax - rectHeight / 2 - label->boundingRect().height() / 2); |
|
|||
117 | // yMax -= rectHeight; |
|
|||
118 | // } else { |
|
|||
119 | // QRectF rect(xPos, yMin - rectHeight, rectWidth, rectHeight); |
|
|||
120 | // layout.append(rect); |
|
|||
121 | // label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2), |
|
|||
122 | // yMin - rectHeight / 2 - label->boundingRect().height() / 2); |
|
|||
123 | // yMin -= rectHeight; |
|
|||
124 | // } |
|
|||
125 |
|
||||
126 | // itemIndex++; |
|
|||
127 | // } |
|
|||
128 | // } |
|
|||
129 |
|
||||
130 | return layout; |
|
|||
131 | } |
|
71 | } | |
132 |
|
72 | |||
133 | #include "moc_stackedbarchartitem_p.cpp" |
|
73 | #include "moc_stackedbarchartitem_p.cpp" | |
134 |
|
74 | |||
135 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now