@@ -1,234 +1,233 | |||||
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 "barvalue_p.h" |
|
23 | #include "barvalue_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qchart.h" |
|
26 | #include "qchart.h" | |
27 | #include "qchartaxis.h" |
|
27 | #include "qchartaxis.h" | |
28 | #include "qchartaxiscategories.h" |
|
28 | #include "qchartaxiscategories.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartanimator_p.h" |
|
30 | #include "chartanimator_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QDebug> |
|
32 | #include <QDebug> | |
33 | #include <QToolTip> |
|
33 | #include <QToolTip> | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
37 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
38 | ChartItem(presenter), |
|
38 | ChartItem(presenter), | |
39 | m_layoutSet(false), |
|
39 | m_layoutSet(false), | |
40 | m_series(series) |
|
40 | m_series(series) | |
41 | { |
|
41 | { | |
42 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); |
|
42 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); | |
43 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
43 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
44 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); |
|
|||
45 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
44 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |
46 | setZValue(ChartPresenter::BarSeriesZValue); |
|
45 | setZValue(ChartPresenter::BarSeriesZValue); | |
47 | dataChanged(); |
|
46 | dataChanged(); | |
48 | } |
|
47 | } | |
49 |
|
48 | |||
50 | BarChartItem::~BarChartItem() |
|
49 | BarChartItem::~BarChartItem() | |
51 | { |
|
50 | { | |
52 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
51 | disconnect(this,SLOT(showToolTip(QPoint,QString))); | |
53 | } |
|
52 | } | |
54 |
|
53 | |||
55 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
54 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
56 | { |
|
55 | { | |
57 | if (!m_layoutSet) { |
|
56 | if (!m_layoutSet) { | |
58 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; |
|
57 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; | |
59 | return; |
|
58 | return; | |
60 | } |
|
59 | } | |
61 |
|
60 | |||
62 | foreach(QGraphicsItem* i, childItems()) |
|
61 | foreach(QGraphicsItem* i, childItems()) | |
63 | i->paint(painter,option,widget); |
|
62 | i->paint(painter,option,widget); | |
64 | } |
|
63 | } | |
65 |
|
64 | |||
66 | QRectF BarChartItem::boundingRect() const |
|
65 | QRectF BarChartItem::boundingRect() const | |
67 | { |
|
66 | { | |
68 | return m_rect; |
|
67 | return m_rect; | |
69 | } |
|
68 | } | |
70 |
|
69 | |||
71 | void BarChartItem::dataChanged() |
|
70 | void BarChartItem::dataChanged() | |
72 | { |
|
71 | { | |
73 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
72 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
74 | // Delete old bars |
|
73 | // Delete old bars | |
75 | foreach (QGraphicsItem *item, childItems()) |
|
74 | foreach (QGraphicsItem *item, childItems()) | |
76 | delete item; |
|
75 | delete item; | |
77 |
|
76 | |||
78 | m_bars.clear(); |
|
77 | m_bars.clear(); | |
79 |
m_ |
|
78 | m_values.clear(); | |
80 | m_layout.clear(); |
|
79 | m_layout.clear(); | |
81 |
|
80 | |||
82 | // Create new graphic items for bars |
|
81 | // Create new graphic items for bars | |
83 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
82 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
84 | QString category = m_series->categoryName(c); |
|
83 | QString category = m_series->categoryName(c); | |
85 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
84 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
86 | QBarSet *set = m_series->barsetAt(s); |
|
85 | QBarSet *set = m_series->barsetAt(s); | |
87 | Bar *bar = new Bar(category,this); |
|
86 | Bar *bar = new Bar(category,this); | |
88 | childItems().append(bar); |
|
87 | childItems().append(bar); | |
89 | m_bars.append(bar); |
|
88 | m_bars.append(bar); | |
90 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); |
|
89 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); | |
91 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); |
|
90 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); | |
92 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); |
|
91 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); | |
93 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
92 | m_layout.append(QRectF(0, 0, 0, 0)); | |
94 | } |
|
93 | } | |
95 | } |
|
94 | } | |
96 |
|
95 | |||
97 | // Create floating values |
|
96 | // Create floating values | |
98 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
97 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
99 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
98 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
100 | QBarSet *set = m_series->barsetAt(s); |
|
99 | QBarSet *set = m_series->barsetAt(s); | |
101 | BarValue *value = new BarValue(*set, this); |
|
100 | BarValue *value = new BarValue(*set, this); | |
102 | childItems().append(value); |
|
101 | childItems().append(value); | |
103 |
m_ |
|
102 | m_values.append(value); | |
104 | connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible())); |
|
103 | connect(set,SIGNAL(valuesVisibleChanged(bool)),value,SLOT(valuesVisibleChanged(bool))); | |
105 | } |
|
104 | } | |
106 | } |
|
105 | } | |
107 | } |
|
106 | } | |
108 |
|
107 | |||
109 | QVector<QRectF> BarChartItem::calculateLayout() |
|
108 | QVector<QRectF> BarChartItem::calculateLayout() | |
110 | { |
|
109 | { | |
111 | QVector<QRectF> layout; |
|
110 | QVector<QRectF> layout; | |
112 |
|
111 | |||
113 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
112 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
114 | qreal categoryCount = m_series->categoryCount(); |
|
113 | qreal categoryCount = m_series->categoryCount(); | |
115 | qreal setCount = m_series->barsetCount(); |
|
114 | qreal setCount = m_series->barsetCount(); | |
116 |
|
115 | |||
117 | qreal width = geometry().width(); |
|
116 | qreal width = geometry().width(); | |
118 | qreal height = geometry().height(); |
|
117 | qreal height = geometry().height(); | |
119 |
|
118 | |||
120 | qreal max = m_series->max(); |
|
119 | qreal max = m_series->max(); | |
121 |
|
120 | |||
122 | // Domain: |
|
121 | // Domain: | |
123 | if (m_domainMaxY > max) { |
|
122 | if (m_domainMaxY > max) { | |
124 | max = m_domainMaxY; |
|
123 | max = m_domainMaxY; | |
125 | } |
|
124 | } | |
126 |
|
125 | |||
127 | qreal scale = (height / max); |
|
126 | qreal scale = (height / max); | |
128 | qreal categoryWidth = width / categoryCount; |
|
127 | qreal categoryWidth = width / categoryCount; | |
129 | qreal barWidth = categoryWidth / (setCount+1); |
|
128 | qreal barWidth = categoryWidth / (setCount+1); | |
130 |
|
129 | |||
131 | int itemIndex(0); |
|
130 | int itemIndex(0); | |
132 | for (int category = 0; category < categoryCount; category++) { |
|
131 | for (int category = 0; category < categoryCount; category++) { | |
133 | qreal xPos = categoryWidth * category + barWidth / 2; |
|
132 | qreal xPos = categoryWidth * category + barWidth / 2; | |
134 | qreal yPos = height; |
|
133 | qreal yPos = height; | |
135 | for (int set = 0; set < setCount; set++) { |
|
134 | for (int set = 0; set < setCount; set++) { | |
136 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
135 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
137 | Bar* bar = m_bars.at(itemIndex); |
|
136 | Bar* bar = m_bars.at(itemIndex); | |
138 |
|
137 | |||
139 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
138 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
140 | layout.append(rect); |
|
139 | layout.append(rect); | |
141 | bar->setPen(m_series->barsetAt(set)->pen()); |
|
140 | bar->setPen(m_series->barsetAt(set)->pen()); | |
142 | bar->setBrush(m_series->barsetAt(set)->brush()); |
|
141 | bar->setBrush(m_series->barsetAt(set)->brush()); | |
143 | itemIndex++; |
|
142 | itemIndex++; | |
144 | xPos += barWidth; |
|
143 | xPos += barWidth; | |
145 | } |
|
144 | } | |
146 | } |
|
145 | } | |
147 |
|
146 | |||
148 | // Position floating values |
|
147 | // Position floating values | |
149 | itemIndex = 0; |
|
148 | itemIndex = 0; | |
150 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
149 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
151 | qreal xPos = categoryWidth * category + barWidth; |
|
150 | qreal xPos = categoryWidth * category + barWidth; | |
152 | qreal yPos = height; |
|
151 | qreal yPos = height; | |
153 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
152 | for (int set=0; set < m_series->barsetCount(); set++) { | |
154 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
153 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
155 |
BarValue* value = m_ |
|
154 | BarValue* value = m_values.at(itemIndex); | |
156 |
|
155 | |||
157 | QBarSet* barSet = m_series->barsetAt(set); |
|
156 | QBarSet* barSet = m_series->barsetAt(set); | |
158 |
|
157 | |||
159 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
158 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
160 | value->setText(QString::number(m_series->valueAt(set, category))); |
|
159 | value->setText(QString::number(m_series->valueAt(set, category))); | |
161 | } else { |
|
160 | } else { | |
162 | value->setText(QString("")); |
|
161 | value->setText(QString("")); | |
163 | } |
|
162 | } | |
164 |
|
163 | |||
165 | value->setPos(xPos, yPos-barHeight / 2); |
|
164 | value->setPos(xPos, yPos-barHeight / 2); | |
166 | value->setPen(barSet->floatingValuePen()); |
|
165 | value->setPen(barSet->floatingValuePen()); | |
167 |
|
166 | |||
168 | itemIndex++; |
|
167 | itemIndex++; | |
169 | xPos += barWidth; |
|
168 | xPos += barWidth; | |
170 | } |
|
169 | } | |
171 | } |
|
170 | } | |
172 |
|
171 | |||
173 | return layout; |
|
172 | return layout; | |
174 | } |
|
173 | } | |
175 |
|
174 | |||
176 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
175 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
177 | { |
|
176 | { | |
178 | if (animator()) |
|
177 | if (animator()) | |
179 | animator()->updateLayout(this, m_layout, layout); |
|
178 | animator()->updateLayout(this, m_layout, layout); | |
180 | else |
|
179 | else | |
181 | setLayout(layout); |
|
180 | setLayout(layout); | |
182 | } |
|
181 | } | |
183 |
|
182 | |||
184 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
183 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
185 | { |
|
184 | { | |
186 | m_layout = layout; |
|
185 | m_layout = layout; | |
187 |
|
186 | |||
188 | for (int i=0; i < m_bars.count(); i++) |
|
187 | for (int i=0; i < m_bars.count(); i++) | |
189 | m_bars.at(i)->setRect(layout.at(i)); |
|
188 | m_bars.at(i)->setRect(layout.at(i)); | |
190 |
|
189 | |||
191 | update(); |
|
190 | update(); | |
192 | } |
|
191 | } | |
193 |
|
192 | |||
194 | //handlers |
|
193 | //handlers | |
195 |
|
194 | |||
196 | void BarChartItem::handleModelChanged(int index) |
|
195 | void BarChartItem::handleModelChanged(int index) | |
197 | { |
|
196 | { | |
198 | Q_UNUSED(index) |
|
197 | Q_UNUSED(index) | |
199 | dataChanged(); |
|
198 | dataChanged(); | |
200 | } |
|
199 | } | |
201 |
|
200 | |||
202 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
201 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
203 | { |
|
202 | { | |
204 | m_domainMinX = minX; |
|
203 | m_domainMinX = minX; | |
205 | m_domainMaxX = maxX; |
|
204 | m_domainMaxX = maxX; | |
206 | m_domainMinY = minY; |
|
205 | m_domainMinY = minY; | |
207 | m_domainMaxY = maxY; |
|
206 | m_domainMaxY = maxY; | |
208 | handleLayoutChanged(); |
|
207 | handleLayoutChanged(); | |
209 | } |
|
208 | } | |
210 |
|
209 | |||
211 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
210 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
212 | { |
|
211 | { | |
213 | m_rect = rect; |
|
212 | m_rect = rect; | |
214 | handleLayoutChanged(); |
|
213 | handleLayoutChanged(); | |
215 | m_layoutSet = true; |
|
214 | m_layoutSet = true; | |
216 | setPos(rect.topLeft()); |
|
215 | setPos(rect.topLeft()); | |
217 | } |
|
216 | } | |
218 |
|
217 | |||
219 | void BarChartItem::handleLayoutChanged() |
|
218 | void BarChartItem::handleLayoutChanged() | |
220 | { |
|
219 | { | |
221 | QVector<QRectF> layout = calculateLayout(); |
|
220 | QVector<QRectF> layout = calculateLayout(); | |
222 | applyLayout(layout); |
|
221 | applyLayout(layout); | |
223 | update(); |
|
222 | update(); | |
224 | } |
|
223 | } | |
225 |
|
224 | |||
226 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
225 | void BarChartItem::showToolTip(QPoint pos, QString tip) | |
227 | { |
|
226 | { | |
228 | // TODO: cool tooltip instead of default |
|
227 | // TODO: cool tooltip instead of default | |
229 | QToolTip::showText(pos, tip); |
|
228 | QToolTip::showText(pos, tip); | |
230 | } |
|
229 | } | |
231 |
|
230 | |||
232 | #include "moc_barchartitem_p.cpp" |
|
231 | #include "moc_barchartitem_p.cpp" | |
233 |
|
232 | |||
234 | QTCOMMERCIALCHART_END_NAMESPACE |
|
233 | 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 | #ifndef BARCHARTITEM_H |
|
21 | #ifndef BARCHARTITEM_H | |
22 | #define BARCHARTITEM_H |
|
22 | #define BARCHARTITEM_H | |
23 |
|
23 | |||
24 | #include "chartitem_p.h" |
|
24 | #include "chartitem_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class Bar; |
|
31 | class Bar; | |
32 | class BarValue; |
|
32 | class BarValue; | |
33 | class QChartAxisCategories; |
|
33 | class QChartAxisCategories; | |
34 | class QChart; |
|
34 | class QChart; | |
35 |
|
35 | |||
36 | //typedef QVector<QRectF> BarLayout; |
|
36 | //typedef QVector<QRectF> BarLayout; | |
37 |
|
37 | |||
38 | class BarChartItem : public ChartItem |
|
38 | class BarChartItem : public ChartItem | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
42 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
43 | virtual ~BarChartItem(); |
|
43 | virtual ~BarChartItem(); | |
44 |
|
44 | |||
45 | // Common implemantation of different presenters. Not to be instantiated. |
|
45 | // Common implemantation of different presenters. Not to be instantiated. | |
46 | // TODO: combine this with BarPresenter and derive other presenters from it? |
|
46 | // TODO: combine this with BarPresenter and derive other presenters from it? | |
47 |
|
47 | |||
48 | public: |
|
48 | public: | |
49 | // From QGraphicsItem |
|
49 | // From QGraphicsItem | |
50 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
50 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
51 | QRectF boundingRect() const; |
|
51 | QRectF boundingRect() const; | |
52 |
|
52 | |||
53 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
53 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it | |
54 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
54 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
55 |
|
55 | |||
56 | virtual QVector<QRectF> calculateLayout(); |
|
56 | virtual QVector<QRectF> calculateLayout(); | |
57 | void applyLayout(const QVector<QRectF> &layout); |
|
57 | void applyLayout(const QVector<QRectF> &layout); | |
58 | void setLayout(const QVector<QRectF> &layout); |
|
58 | void setLayout(const QVector<QRectF> &layout); | |
59 | void updateLayout(const QVector<QRectF> &layout); |
|
59 | void updateLayout(const QVector<QRectF> &layout); | |
60 |
|
60 | |||
61 | QRectF geometry() const { return m_rect;} |
|
61 | QRectF geometry() const { return m_rect;} | |
62 |
|
62 | |||
63 | public Q_SLOTS: |
|
63 | public Q_SLOTS: | |
64 | void handleModelChanged(int index); |
|
64 | void handleModelChanged(int index); | |
65 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
65 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
66 | void handleGeometryChanged(const QRectF &size); |
|
66 | void handleGeometryChanged(const QRectF &size); | |
67 | void handleLayoutChanged(); |
|
67 | void handleLayoutChanged(); | |
68 |
|
68 | |||
69 | // Internal slots |
|
69 | // Internal slots | |
70 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) |
|
70 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) | |
71 |
|
71 | |||
72 | protected: |
|
72 | protected: | |
73 |
|
73 | |||
74 | // TODO: consider these. |
|
74 | // TODO: consider these. | |
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 | bool m_layoutSet; // True, if component has been laid out. |
|
81 | bool m_layoutSet; // True, if component has been laid out. | |
82 | QVector<QRectF> m_layout; |
|
82 | QVector<QRectF> m_layout; | |
83 |
|
83 | |||
84 | // Not owned. |
|
84 | // Not owned. | |
85 | QBarSeries *m_series; |
|
85 | QBarSeries *m_series; | |
86 | QList<Bar *> m_bars; |
|
86 | QList<Bar *> m_bars; | |
87 |
QList<BarValue *> m_ |
|
87 | QList<BarValue *> m_values; | |
88 | }; |
|
88 | }; | |
89 |
|
89 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE | |
91 |
|
91 | |||
92 | #endif // BARCHARTITEM_H |
|
92 | #endif // BARCHARTITEM_H |
@@ -1,88 +1,88 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "barvalue_p.h" |
|
21 | #include "barvalue_p.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include <QPen> |
|
23 | #include <QPen> | |
24 | #include <QGraphicsSimpleTextItem> |
|
24 | #include <QGraphicsSimpleTextItem> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) : QGraphicsObject(parent), |
|
28 | BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) : QGraphicsObject(parent), | |
29 | m_barSet(set), |
|
29 | m_barSet(set), | |
30 | m_textItem(new QGraphicsSimpleTextItem(this)) |
|
30 | m_textItem(new QGraphicsSimpleTextItem(this)) | |
31 | { |
|
31 | { | |
|
32 | // connect(&set,SIGNAL(valuesVisibleChanged(bool)),value,SLOT(valuesVisibleChanged(bool))); | |||
32 | setVisible(false); |
|
33 | setVisible(false); | |
33 | } |
|
34 | } | |
34 |
|
35 | |||
35 | void BarValue::setText(QString str) |
|
36 | void BarValue::setText(QString str) | |
36 | { |
|
37 | { | |
37 | m_textItem->setText(str); |
|
38 | m_textItem->setText(str); | |
38 | } |
|
39 | } | |
39 |
|
40 | |||
40 | QString BarValue::text() const |
|
41 | QString BarValue::text() const | |
41 | { |
|
42 | { | |
42 | return m_textItem->text(); |
|
43 | return m_textItem->text(); | |
43 | } |
|
44 | } | |
44 |
|
45 | |||
45 | void BarValue::setPen(const QPen &pen) |
|
46 | void BarValue::setPen(const QPen &pen) | |
46 | { |
|
47 | { | |
47 | m_textItem->setPen(pen); |
|
48 | m_textItem->setPen(pen); | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 | QPen BarValue::pen() const |
|
51 | QPen BarValue::pen() const | |
51 | { |
|
52 | { | |
52 | return m_textItem->pen(); |
|
53 | return m_textItem->pen(); | |
53 | } |
|
54 | } | |
54 |
|
55 | |||
55 | void BarValue::setFont(const QFont &font) |
|
56 | void BarValue::setFont(const QFont &font) | |
56 | { |
|
57 | { | |
57 | m_textItem->setFont(font); |
|
58 | m_textItem->setFont(font); | |
58 | } |
|
59 | } | |
59 |
|
60 | |||
60 | QFont BarValue::font() const |
|
61 | QFont BarValue::font() const | |
61 | { |
|
62 | { | |
62 | return m_textItem->font(); |
|
63 | return m_textItem->font(); | |
63 | } |
|
64 | } | |
64 |
|
65 | |||
65 | void BarValue::setPos(qreal x, qreal y) |
|
66 | void BarValue::setPos(qreal x, qreal y) | |
66 | { |
|
67 | { | |
67 | m_textItem->setPos(x,y); |
|
68 | m_textItem->setPos(x,y); | |
68 | } |
|
69 | } | |
69 |
|
70 | |||
70 | void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
71 | void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
71 | { |
|
72 | { | |
72 | Q_UNUSED(option) |
|
73 | Q_UNUSED(option) | |
73 | Q_UNUSED(widget) |
|
74 | Q_UNUSED(widget) | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | QRectF BarValue::boundingRect() const |
|
77 | QRectF BarValue::boundingRect() const | |
77 | { |
|
78 | { | |
78 | return m_textItem->boundingRect(); |
|
79 | return m_textItem->boundingRect(); | |
79 | } |
|
80 | } | |
80 |
|
81 | |||
81 |
void BarValue:: |
|
82 | void BarValue::valuesVisibleChanged(bool visible) | |
82 | { |
|
83 | { | |
83 | qDebug() << "toggle visible"; |
|
84 | setVisible(visible); | |
84 | setVisible(!isVisible()); |
|
|||
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | #include "moc_barvalue_p.cpp" |
|
87 | #include "moc_barvalue_p.cpp" | |
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,67 +1,67 | |||||
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 | #ifndef BARVALUE_P_H |
|
21 | #ifndef BARVALUE_P_H | |
22 | #define BARVALUE_P_H |
|
22 | #define BARVALUE_P_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include <QGraphicsObject> |
|
25 | #include <QGraphicsObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | class QGraphicsSimpleTextItem; |
|
27 | class QGraphicsSimpleTextItem; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QBarSet; |
|
31 | class QBarSet; | |
32 |
|
32 | |||
33 | // Visual class for floating bar values |
|
33 | // Visual class for floating bar values | |
34 | // By default these are not visible. |
|
34 | // By default these are not visible. | |
35 | class BarValue : public QGraphicsObject |
|
35 | class BarValue : public QGraphicsObject | |
36 | { |
|
36 | { | |
37 | Q_OBJECT |
|
37 | Q_OBJECT | |
38 | public: |
|
38 | public: | |
39 | BarValue(QBarSet &set, QGraphicsItem *parent = 0); |
|
39 | BarValue(QBarSet &set, QGraphicsItem *parent = 0); | |
40 |
|
40 | |||
41 | void setText(QString str); |
|
41 | void setText(QString str); | |
42 | QString text() const; |
|
42 | QString text() const; | |
43 |
|
43 | |||
44 | void setPen(const QPen &pen); |
|
44 | void setPen(const QPen &pen); | |
45 | QPen pen() const; |
|
45 | QPen pen() const; | |
46 |
|
46 | |||
47 | void setFont(const QFont &font); |
|
47 | void setFont(const QFont &font); | |
48 | QFont font() const; |
|
48 | QFont font() const; | |
49 |
|
49 | |||
50 | void setPos(qreal x, qreal y); |
|
50 | void setPos(qreal x, qreal y); | |
51 |
|
51 | |||
52 | // From QGraphicsItem |
|
52 | // From QGraphicsItem | |
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
54 | QRectF boundingRect() const; |
|
54 | QRectF boundingRect() const; | |
55 |
|
55 | |||
56 | public Q_SLOTS: |
|
56 | public Q_SLOTS: | |
57 |
void |
|
57 | void valuesVisibleChanged(bool visible); | |
58 |
|
58 | |||
59 | private: |
|
59 | private: | |
60 |
|
60 | |||
61 | QBarSet &m_barSet; |
|
61 | QBarSet &m_barSet; | |
62 | QGraphicsSimpleTextItem *m_textItem; |
|
62 | QGraphicsSimpleTextItem *m_textItem; | |
63 | }; |
|
63 | }; | |
64 |
|
64 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
66 | |||
67 | #endif // BARVALUE_P_H |
|
67 | #endif // BARVALUE_P_H |
@@ -1,101 +1,101 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "percentbarchartitem_p.h" |
|
21 | #include "percentbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barvalue_p.h" |
|
23 | #include "barvalue_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
35 | { |
|
35 | { | |
36 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
37 |
|
37 | |||
38 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
38 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
39 | qreal width = geometry().width(); |
|
39 | qreal width = geometry().width(); | |
40 | qreal height = geometry().height(); |
|
40 | qreal height = geometry().height(); | |
41 |
|
41 | |||
42 | qreal categoryCount = m_series->categoryCount(); |
|
42 | qreal categoryCount = m_series->categoryCount(); | |
43 | qreal barWidth = width / (m_series->categoryCount() * 2); |
|
43 | qreal barWidth = width / (m_series->categoryCount() * 2); | |
44 | qreal xStep = width / categoryCount; |
|
44 | qreal xStep = width / categoryCount; | |
45 | qreal xPos = xStep / 2 - barWidth / 2; |
|
45 | qreal xPos = xStep / 2 - barWidth / 2; | |
46 |
|
46 | |||
47 | int itemIndex(0); |
|
47 | int itemIndex(0); | |
48 | for (int category = 0; category < categoryCount; category++) { |
|
48 | for (int category = 0; category < categoryCount; category++) { | |
49 | qreal colSum = m_series->categorySum(category); |
|
49 | qreal colSum = m_series->categorySum(category); | |
50 | qreal scale = (height / colSum); |
|
50 | qreal scale = (height / colSum); | |
51 | qreal yPos = height; |
|
51 | qreal yPos = height; | |
52 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
52 | for (int set=0; set < m_series->barsetCount(); set++) { | |
53 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
53 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
54 | Bar* bar = m_bars.at(itemIndex); |
|
54 | Bar* bar = m_bars.at(itemIndex); | |
55 | bar->setPen(m_series->barsetAt(set)->pen()); |
|
55 | bar->setPen(m_series->barsetAt(set)->pen()); | |
56 | bar->setBrush(m_series->barsetAt(set)->brush()); |
|
56 | bar->setBrush(m_series->barsetAt(set)->brush()); | |
57 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
57 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
58 | layout.append(rect); |
|
58 | layout.append(rect); | |
59 | itemIndex++; |
|
59 | itemIndex++; | |
60 | yPos -= barHeight; |
|
60 | yPos -= barHeight; | |
61 | } |
|
61 | } | |
62 | xPos += xStep; |
|
62 | xPos += xStep; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | // Position floating values |
|
65 | // Position floating values | |
66 | itemIndex = 0; |
|
66 | itemIndex = 0; | |
67 | xPos = (width/categoryCount); |
|
67 | xPos = (width/categoryCount); | |
68 | for (int category=0; category < m_series->categoryCount(); category++) { |
|
68 | for (int category=0; category < m_series->categoryCount(); category++) { | |
69 | qreal yPos = height; |
|
69 | qreal yPos = height; | |
70 | qreal colSum = m_series->categorySum(category); |
|
70 | qreal colSum = m_series->categorySum(category); | |
71 | qreal scale = (height / colSum); |
|
71 | qreal scale = (height / colSum); | |
72 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
72 | for (int set=0; set < m_series->barsetCount(); set++) { | |
73 | qreal barHeight = m_series->valueAt(set,category) * scale; |
|
73 | qreal barHeight = m_series->valueAt(set,category) * scale; | |
74 |
BarValue* value = m_ |
|
74 | BarValue* value = m_values.at(itemIndex); | |
75 |
|
75 | |||
76 | QBarSet* barSet = m_series->barsetAt(set); |
|
76 | QBarSet* barSet = m_series->barsetAt(set); | |
77 |
|
77 | |||
78 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
78 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
79 | int p = m_series->percentageAt(set,category) * 100; |
|
79 | int p = m_series->percentageAt(set,category) * 100; | |
80 | QString vString(QString::number(p)); |
|
80 | QString vString(QString::number(p)); | |
81 | vString.truncate(3); |
|
81 | vString.truncate(3); | |
82 | vString.append("%"); |
|
82 | vString.append("%"); | |
83 | value->setText(vString); |
|
83 | value->setText(vString); | |
84 | } else { |
|
84 | } else { | |
85 | value->setText(QString("")); |
|
85 | value->setText(QString("")); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | value->setPos(xPos, yPos-barHeight / 2); |
|
88 | value->setPos(xPos, yPos-barHeight / 2); | |
89 | value->setPen(barSet->floatingValuePen()); |
|
89 | value->setPen(barSet->floatingValuePen()); | |
90 |
|
90 | |||
91 | itemIndex++; |
|
91 | itemIndex++; | |
92 | yPos -= barHeight; |
|
92 | yPos -= barHeight; | |
93 | } |
|
93 | } | |
94 | xPos += xStep; |
|
94 | xPos += xStep; | |
95 | } |
|
95 | } | |
96 | return layout; |
|
96 | return layout; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | #include "moc_percentbarchartitem_p.cpp" |
|
99 | #include "moc_percentbarchartitem_p.cpp" | |
100 |
|
100 | |||
101 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,396 +1,404 | |||||
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 <QDebug> |
|
21 | #include <QDebug> | |
22 | #include "qbarseries.h" |
|
22 | #include "qbarseries.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "barchartmodel_p.h" |
|
24 | #include "barchartmodel_p.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QBarSeries |
|
29 | \class QBarSeries | |
30 | \brief part of QtCommercial chart API. |
|
30 | \brief part of QtCommercial chart API. | |
31 |
|
31 | |||
32 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
32 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
33 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
33 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
34 | by QStringList. |
|
34 | by QStringList. | |
35 |
|
35 | |||
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
38 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \fn virtual QSeriesType QBarSeries::type() const |
|
42 | \fn virtual QSeriesType QBarSeries::type() const | |
43 | \brief Returns type of series. |
|
43 | \brief Returns type of series. | |
44 | \sa QSeries, QSeriesType |
|
44 | \sa QSeries, QSeriesType | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
48 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
49 | \brief \internal \a pos \a tip |
|
49 | \brief \internal \a pos \a tip | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
53 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
54 | QBarSeries is QObject which is a child of a \a parent. |
|
54 | QBarSeries is QObject which is a child of a \a parent. | |
55 | */ |
|
55 | */ | |
56 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), |
|
56 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), | |
57 | m_internalModel(new BarChartModel(categories, this)) |
|
57 | m_internalModel(new BarChartModel(categories, this)) | |
58 | { |
|
58 | { | |
59 | m_model = 0; |
|
59 | m_model = 0; | |
60 | m_mapCategories = -1; |
|
60 | m_mapCategories = -1; | |
61 | m_mapBarBottom = -1; |
|
61 | m_mapBarBottom = -1; | |
62 | m_mapBarTop = -1; |
|
62 | m_mapBarTop = -1; | |
63 | m_mapFirst = 0; |
|
63 | m_mapFirst = 0; | |
64 | m_mapCount = 0; |
|
64 | m_mapCount = 0; | |
65 | m_mapOrientation = Qt::Vertical; |
|
65 | m_mapOrientation = Qt::Vertical; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | Adds a set of bars to series. Takes ownership of \a set. |
|
69 | Adds a set of bars to series. Takes ownership of \a set. | |
70 | Connects the clicked(QString, Qt::MouseButtons) signal |
|
70 | Connects the clicked(QString, Qt::MouseButtons) signal | |
71 | of \a set to this series |
|
71 | of \a set to this series | |
72 | */ |
|
72 | */ | |
73 | void QBarSeries::appendBarSet(QBarSet *set) |
|
73 | void QBarSeries::appendBarSet(QBarSet *set) | |
74 | { |
|
74 | { | |
75 | m_internalModel->appendBarSet(set); |
|
75 | m_internalModel->appendBarSet(set); | |
76 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
76 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
77 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
77 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
78 | emit updatedBars(); |
|
78 | emit updatedBars(); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
82 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
83 | Disconnects the clicked(QString, Qt::MouseButtons) signal |
|
83 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
84 | of \a set from this series |
|
84 | of \a set from this series | |
85 | */ |
|
85 | */ | |
86 | void QBarSeries::removeBarSet(QBarSet *set) |
|
86 | void QBarSeries::removeBarSet(QBarSet *set) | |
87 | { |
|
87 | { | |
88 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
88 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
89 | m_internalModel->removeBarSet(set); |
|
89 | m_internalModel->removeBarSet(set); | |
90 | emit updatedBars(); |
|
90 | emit updatedBars(); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
93 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
94 | { |
|
94 | { | |
95 | m_internalModel->insertBarSet(i, set); |
|
95 | m_internalModel->insertBarSet(i, set); | |
96 | // emit barsetChanged(); |
|
96 | // emit barsetChanged(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void QBarSeries::insertCategory(int i, QString category) |
|
99 | void QBarSeries::insertCategory(int i, QString category) | |
100 | { |
|
100 | { | |
101 | m_internalModel->insertCategory(i, category); |
|
101 | m_internalModel->insertCategory(i, category); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void QBarSeries::removeCategory(int i) |
|
104 | void QBarSeries::removeCategory(int i) | |
105 | { |
|
105 | { | |
106 | m_internalModel->removeCategory(i); |
|
106 | m_internalModel->removeCategory(i); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | Returns number of sets in series. |
|
110 | Returns number of sets in series. | |
111 | */ |
|
111 | */ | |
112 | int QBarSeries::barsetCount() const |
|
112 | int QBarSeries::barsetCount() const | |
113 | { |
|
113 | { | |
114 | // if(m_model) |
|
114 | // if(m_model) | |
115 | // return m_mapBarTop - m_mapBarBottom; |
|
115 | // return m_mapBarTop - m_mapBarBottom; | |
116 | // else |
|
116 | // else | |
117 | return m_internalModel->barsetCount(); |
|
117 | return m_internalModel->barsetCount(); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Returns number of categories in series |
|
121 | Returns number of categories in series | |
122 | */ |
|
122 | */ | |
123 | int QBarSeries::categoryCount() const |
|
123 | int QBarSeries::categoryCount() const | |
124 | { |
|
124 | { | |
125 | return m_internalModel->categoryCount(); |
|
125 | return m_internalModel->categoryCount(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Returns a list of sets in series. Keeps ownership of sets. |
|
129 | Returns a list of sets in series. Keeps ownership of sets. | |
130 | */ |
|
130 | */ | |
131 | QList<QBarSet*> QBarSeries::barSets() const |
|
131 | QList<QBarSet*> QBarSeries::barSets() const | |
132 | { |
|
132 | { | |
133 | return m_internalModel->barSets(); |
|
133 | return m_internalModel->barSets(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | \internal \a index |
|
137 | \internal \a index | |
138 | */ |
|
138 | */ | |
139 | QBarSet* QBarSeries::barsetAt(int index) |
|
139 | QBarSet* QBarSeries::barsetAt(int index) | |
140 | { |
|
140 | { | |
141 | return m_internalModel->barsetAt(index); |
|
141 | return m_internalModel->barsetAt(index); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \internal \a category |
|
145 | \internal \a category | |
146 | */ |
|
146 | */ | |
147 | QString QBarSeries::categoryName(int category) |
|
147 | QString QBarSeries::categoryName(int category) | |
148 | { |
|
148 | { | |
149 | return m_internalModel->categoryName(category); |
|
149 | return m_internalModel->categoryName(category); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Enables or disables tooltip depending on parameter \a enabled. |
|
153 | Enables or disables tooltip depending on parameter \a enabled. | |
154 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
154 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
155 | Calling without parameter \a enabled, enables the tooltip |
|
155 | Calling without parameter \a enabled, enables the tooltip | |
156 | */ |
|
156 | */ | |
157 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
157 | void QBarSeries::setToolTipEnabled(bool enabled) | |
158 | { |
|
158 | { | |
159 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
159 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
160 | if (enabled) { |
|
160 | if (enabled) { | |
161 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
161 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
162 | QBarSet *set = m_internalModel->barsetAt(i); |
|
162 | QBarSet *set = m_internalModel->barsetAt(i); | |
163 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
163 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
164 | } |
|
164 | } | |
165 | } else { |
|
165 | } else { | |
166 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
166 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
167 | QBarSet *set = m_internalModel->barsetAt(i); |
|
167 | QBarSet *set = m_internalModel->barsetAt(i); | |
168 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
168 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
169 | } |
|
169 | } | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | \internal \a category |
|
175 | \internal \a category | |
176 | */ |
|
176 | */ | |
177 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) |
|
177 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) | |
178 | { |
|
178 | { | |
179 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); |
|
179 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | \internal |
|
183 | \internal | |
184 | */ |
|
184 | */ | |
185 | qreal QBarSeries::min() |
|
185 | qreal QBarSeries::min() | |
186 | { |
|
186 | { | |
187 | return m_internalModel->min(); |
|
187 | return m_internalModel->min(); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | \internal |
|
191 | \internal | |
192 | */ |
|
192 | */ | |
193 | qreal QBarSeries::max() |
|
193 | qreal QBarSeries::max() | |
194 | { |
|
194 | { | |
195 | return m_internalModel->max(); |
|
195 | return m_internalModel->max(); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \internal \a set \a category |
|
199 | \internal \a set \a category | |
200 | */ |
|
200 | */ | |
201 | qreal QBarSeries::valueAt(int set, int category) |
|
201 | qreal QBarSeries::valueAt(int set, int category) | |
202 | { |
|
202 | { | |
203 | return m_internalModel->valueAt(set, category); |
|
203 | return m_internalModel->valueAt(set, category); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | \internal \a set \a category |
|
207 | \internal \a set \a category | |
208 | */ |
|
208 | */ | |
209 | qreal QBarSeries::percentageAt(int set, int category) |
|
209 | qreal QBarSeries::percentageAt(int set, int category) | |
210 | { |
|
210 | { | |
211 | return m_internalModel->percentageAt(set, category); |
|
211 | return m_internalModel->percentageAt(set, category); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | \internal \a category |
|
215 | \internal \a category | |
216 | */ |
|
216 | */ | |
217 | qreal QBarSeries::categorySum(int category) |
|
217 | qreal QBarSeries::categorySum(int category) | |
218 | { |
|
218 | { | |
219 | return m_internalModel->categorySum(category); |
|
219 | return m_internalModel->categorySum(category); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | \internal |
|
223 | \internal | |
224 | */ |
|
224 | */ | |
225 | qreal QBarSeries::maxCategorySum() |
|
225 | qreal QBarSeries::maxCategorySum() | |
226 | { |
|
226 | { | |
227 | return m_internalModel->maxCategorySum(); |
|
227 | return m_internalModel->maxCategorySum(); | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | \internal |
|
231 | \internal | |
232 | */ |
|
232 | */ | |
233 | BarChartModel& QBarSeries::model() |
|
233 | BarChartModel& QBarSeries::model() | |
234 | { |
|
234 | { | |
235 | return *m_internalModel; |
|
235 | return *m_internalModel; | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
238 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
239 | { |
|
239 | { | |
240 | // disconnect signals from old model |
|
240 | // disconnect signals from old model | |
241 | if(m_model) |
|
241 | if(m_model) | |
242 | { |
|
242 | { | |
243 | disconnect(m_model, 0, this, 0); |
|
243 | disconnect(m_model, 0, this, 0); | |
244 | m_mapCategories = -1; |
|
244 | m_mapCategories = -1; | |
245 | m_mapBarBottom = -1; |
|
245 | m_mapBarBottom = -1; | |
246 | m_mapBarTop = -1; |
|
246 | m_mapBarTop = -1; | |
247 | m_mapFirst = 0; |
|
247 | m_mapFirst = 0; | |
248 | m_mapCount = 0; |
|
248 | m_mapCount = 0; | |
249 | m_mapOrientation = Qt::Vertical; |
|
249 | m_mapOrientation = Qt::Vertical; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | // set new model |
|
252 | // set new model | |
253 | if(model) |
|
253 | if(model) | |
254 | { |
|
254 | { | |
255 | m_model = model; |
|
255 | m_model = model; | |
256 | return true; |
|
256 | return true; | |
257 | } |
|
257 | } | |
258 | else |
|
258 | else | |
259 | { |
|
259 | { | |
260 | m_model = 0; |
|
260 | m_model = 0; | |
261 | return false; |
|
261 | return false; | |
262 | } |
|
262 | } | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | // TODO |
|
265 | // TODO | |
266 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
266 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
267 | { |
|
267 | { | |
268 | if (!m_model) |
|
268 | if (!m_model) | |
269 | return; |
|
269 | return; | |
270 |
|
270 | |||
271 | m_mapCategories = categories; |
|
271 | m_mapCategories = categories; | |
272 | m_mapBarBottom = bottomBoundry; |
|
272 | m_mapBarBottom = bottomBoundry; | |
273 | m_mapBarTop = topBoundry; |
|
273 | m_mapBarTop = topBoundry; | |
274 | // m_mapFirst = 1; |
|
274 | // m_mapFirst = 1; | |
275 | m_mapOrientation = orientation; |
|
275 | m_mapOrientation = orientation; | |
276 |
|
276 | |||
277 | // connect the signals |
|
277 | // connect the signals | |
278 | if (m_mapOrientation == Qt::Vertical) { |
|
278 | if (m_mapOrientation == Qt::Vertical) { | |
279 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
279 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
280 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
280 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
281 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
281 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
282 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), |
|
282 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
283 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
283 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
284 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), |
|
284 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
285 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
285 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
286 | } else { |
|
286 | } else { | |
287 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
287 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
288 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
288 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
289 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
289 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
290 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), |
|
290 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
291 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
291 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
292 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), |
|
292 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
293 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
293 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 |
|
296 | |||
297 | // create the initial bars |
|
297 | // create the initial bars | |
298 | delete m_internalModel; |
|
298 | delete m_internalModel; | |
299 | if (m_mapOrientation == Qt::Vertical) { |
|
299 | if (m_mapOrientation == Qt::Vertical) { | |
300 | QStringList categories; |
|
300 | QStringList categories; | |
301 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
301 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
302 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
302 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
303 | m_internalModel = new BarChartModel(categories, this); |
|
303 | m_internalModel = new BarChartModel(categories, this); | |
304 |
|
304 | |||
305 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
305 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
306 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
306 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
307 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
307 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
308 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
308 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
309 | appendBarSet(barSet); |
|
309 | appendBarSet(barSet); | |
310 | } |
|
310 | } | |
311 | } else { |
|
311 | } else { | |
312 | QStringList categories; |
|
312 | QStringList categories; | |
313 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
313 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
314 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
314 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
315 | m_internalModel = new BarChartModel(categories, this); |
|
315 | m_internalModel = new BarChartModel(categories, this); | |
316 |
|
316 | |||
317 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
317 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
318 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
318 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
319 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
319 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
320 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
320 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
321 | appendBarSet(barSet); |
|
321 | appendBarSet(barSet); | |
322 | } |
|
322 | } | |
323 | } |
|
323 | } | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | void QBarSeries::setModelMappingShift(int first, int count) |
|
326 | void QBarSeries::setModelMappingShift(int first, int count) | |
327 | { |
|
327 | { | |
328 | m_mapFirst = first; |
|
328 | m_mapFirst = first; | |
329 | m_mapCount = count; |
|
329 | m_mapCount = count; | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
332 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
333 | { |
|
333 | { | |
334 | Q_UNUSED(bottomRight) |
|
334 | Q_UNUSED(bottomRight) | |
335 |
|
335 | |||
336 | if (m_mapOrientation == Qt::Vertical) |
|
336 | if (m_mapOrientation == Qt::Vertical) | |
337 | { |
|
337 | { | |
338 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
338 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
339 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) |
|
339 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
340 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
340 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
341 | } |
|
341 | } | |
342 | else |
|
342 | else | |
343 | { |
|
343 | { | |
344 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
344 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
345 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
345 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
346 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
346 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
347 | } |
|
347 | } | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
350 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
351 | { |
|
351 | { | |
352 | if (m_mapOrientation == Qt::Vertical) { |
|
352 | if (m_mapOrientation == Qt::Vertical) { | |
353 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
353 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
354 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
354 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
355 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
355 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
356 | } |
|
356 | } | |
357 | } else { |
|
357 | } else { | |
358 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
358 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
359 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
359 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
360 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
360 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
361 | } |
|
361 | } | |
362 | } |
|
362 | } | |
363 | emit restructuredBar(1); |
|
363 | emit restructuredBar(1); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
366 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
367 | { |
|
367 | { | |
368 | Q_UNUSED(parent) |
|
368 | Q_UNUSED(parent) | |
369 | Q_UNUSED(end) |
|
369 | Q_UNUSED(end) | |
370 |
|
370 | |||
371 | removeCategory(start - m_mapFirst); |
|
371 | removeCategory(start - m_mapFirst); | |
372 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
372 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
373 | { |
|
373 | { | |
374 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
374 | barsetAt(i)->removeValue(start - m_mapFirst); | |
375 | } |
|
375 | } | |
376 | emit restructuredBar(1); |
|
376 | emit restructuredBar(1); | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | void QBarSeries::barsetChanged() |
|
379 | void QBarSeries::barsetChanged() | |
380 | { |
|
380 | { | |
381 | emit updatedBars(); |
|
381 | emit updatedBars(); | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | QBarCategories QBarSeries::categories() const |
|
384 | QBarCategories QBarSeries::categories() const | |
385 | { |
|
385 | { | |
386 | QBarCategories categories; |
|
386 | QBarCategories categories; | |
387 | int count = m_internalModel->categoryCount(); |
|
387 | int count = m_internalModel->categoryCount(); | |
388 | for (int i=1; i <= count; i++) { |
|
388 | for (int i=1; i <= count; i++) { | |
389 | categories.insert(i, m_internalModel->categoryName(i - 1)); |
|
389 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
390 | } |
|
390 | } | |
391 | return categories; |
|
391 | return categories; | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
|
394 | void QBarSeries::setValuesVisible(bool visible) | |||
|
395 | { | |||
|
396 | foreach (QBarSet* s, barSets()) { | |||
|
397 | s->setValuesVisible(visible); | |||
|
398 | } | |||
|
399 | } | |||
|
400 | ||||
|
401 | ||||
394 | #include "moc_qbarseries.cpp" |
|
402 | #include "moc_qbarseries.cpp" | |
395 |
|
403 | |||
396 | QTCOMMERCIALCHART_END_NAMESPACE |
|
404 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,114 +1,116 | |||||
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 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qseries.h> |
|
24 | #include <qseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | typedef QStringList QBarCategories; |
|
29 | typedef QStringList QBarCategories; | |
30 |
|
30 | |||
31 | class QBarSet; |
|
31 | class QBarSet; | |
32 | class BarChartModel; |
|
32 | class BarChartModel; | |
33 | class BarCategory; |
|
33 | class BarCategory; | |
34 |
|
34 | |||
35 | // Container for series |
|
35 | // Container for series | |
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | public: |
|
39 | public: | |
40 | QBarSeries(QStringList categories, QObject *parent = 0); |
|
40 | QBarSeries(QStringList categories, QObject *parent = 0); | |
41 |
|
41 | |||
42 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
42 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
43 |
|
43 | |||
44 | void appendBarSet(QBarSet *set); // Takes ownership of set |
|
44 | void appendBarSet(QBarSet *set); // Takes ownership of set | |
45 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
45 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
46 | void insertBarSet(int i, QBarSet *set); |
|
46 | void insertBarSet(int i, QBarSet *set); | |
47 | void insertCategory(int i, QString category); |
|
47 | void insertCategory(int i, QString category); | |
48 | void removeCategory(int i); |
|
48 | void removeCategory(int i); | |
49 | int barsetCount() const; |
|
49 | int barsetCount() const; | |
50 | int categoryCount() const; |
|
50 | int categoryCount() const; | |
51 | QList<QBarSet*> barSets() const; |
|
51 | QList<QBarSet*> barSets() const; | |
52 | QBarCategories categories() const; |
|
52 | QBarCategories categories() const; | |
53 |
|
53 | |||
|
54 | void setValuesVisible(bool visible = true); | |||
|
55 | ||||
54 | bool setModel(QAbstractItemModel *model); |
|
56 | bool setModel(QAbstractItemModel *model); | |
55 | QAbstractItemModel *modelExt() { return m_model; } |
|
57 | QAbstractItemModel *modelExt() { return m_model; } | |
56 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
58 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
57 | void setModelMappingShift(int first, int count); |
|
59 | void setModelMappingShift(int first, int count); | |
58 |
|
60 | |||
59 | public: |
|
61 | public: | |
60 | // TODO: Functions below this are not part of api and will be moved |
|
62 | // TODO: Functions below this are not part of api and will be moved | |
61 | // to private implementation, when we start using it |
|
63 | // to private implementation, when we start using it | |
62 | // TODO: TO PIMPL ---> |
|
64 | // TODO: TO PIMPL ---> | |
63 | QBarSet* barsetAt(int index); |
|
65 | QBarSet* barsetAt(int index); | |
64 | QString categoryName(int category); |
|
66 | QString categoryName(int category); | |
65 | qreal min(); |
|
67 | qreal min(); | |
66 | qreal max(); |
|
68 | qreal max(); | |
67 | qreal valueAt(int set, int category); |
|
69 | qreal valueAt(int set, int category); | |
68 | qreal percentageAt(int set, int category); |
|
70 | qreal percentageAt(int set, int category); | |
69 | qreal categorySum(int category); |
|
71 | qreal categorySum(int category); | |
70 | qreal maxCategorySum(); |
|
72 | qreal maxCategorySum(); | |
71 | BarChartModel& model(); |
|
73 | BarChartModel& model(); | |
72 | // <--- TO PIMPL |
|
74 | // <--- TO PIMPL | |
73 |
|
75 | |||
74 | Q_SIGNALS: |
|
76 | Q_SIGNALS: | |
75 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals |
|
77 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals | |
76 |
|
78 | |||
77 | // |
|
79 | // | |
78 | void updatedBars(); |
|
80 | void updatedBars(); | |
79 | void restructuredBar(int); |
|
81 | void restructuredBar(int); | |
80 |
|
82 | |||
81 | // TODO: internal signals, these to private implementation. |
|
83 | // TODO: internal signals, these to private implementation. | |
82 | // TODO: TO PIMPL ---> |
|
84 | // TODO: TO PIMPL ---> | |
83 | void showToolTip(QPoint pos, QString tip); |
|
85 | void showToolTip(QPoint pos, QString tip); | |
84 | // <--- TO PIMPL |
|
86 | // <--- TO PIMPL | |
85 |
|
87 | |||
86 | public Q_SLOTS: |
|
88 | public Q_SLOTS: | |
87 | void setToolTipEnabled(bool enabled = true); // enables tooltips |
|
89 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
88 |
|
90 | |||
89 | // TODO: TO PIMPL ---> |
|
91 | // TODO: TO PIMPL ---> | |
90 | void barsetClicked(QString category, Qt::MouseButtons button); |
|
92 | void barsetClicked(QString category, Qt::MouseButtons button); | |
91 | // <--- TO PIMPL |
|
93 | // <--- TO PIMPL | |
92 |
|
94 | |||
93 | private Q_SLOTS: |
|
95 | private Q_SLOTS: | |
94 | // slots for updating bars when data in model changes |
|
96 | // slots for updating bars when data in model changes | |
95 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
97 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
96 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
98 | void modelDataAdded(QModelIndex parent, int start, int end); | |
97 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
99 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
98 | void barsetChanged(); |
|
100 | void barsetChanged(); | |
99 |
|
101 | |||
100 | protected: |
|
102 | protected: | |
101 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
103 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
102 |
|
104 | |||
103 | QAbstractItemModel* m_model; |
|
105 | QAbstractItemModel* m_model; | |
104 | int m_mapCategories; |
|
106 | int m_mapCategories; | |
105 | int m_mapBarBottom; |
|
107 | int m_mapBarBottom; | |
106 | int m_mapBarTop; |
|
108 | int m_mapBarTop; | |
107 | int m_mapFirst; |
|
109 | int m_mapFirst; | |
108 | int m_mapCount; |
|
110 | int m_mapCount; | |
109 | Qt::Orientation m_mapOrientation; |
|
111 | Qt::Orientation m_mapOrientation; | |
110 | }; |
|
112 | }; | |
111 |
|
113 | |||
112 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE | |
113 |
|
115 | |||
114 | #endif // BARSERIES_H |
|
116 | #endif // BARSERIES_H |
@@ -1,221 +1,229 | |||||
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 "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QToolTip> |
|
23 | #include <QToolTip> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QBarSet |
|
28 | \class QBarSet | |
29 | \brief part of QtCommercial chart API. |
|
29 | \brief part of QtCommercial chart API. | |
30 |
|
30 | |||
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
32 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | First value of set is assumed to belong to first category, second to second category and so on. | |
33 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | If set has fewer values than there are categories, then the missing values are assumed to be | |
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
35 |
|
35 | |||
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) |
|
42 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) | |
43 | \brief signals that set has been clicked |
|
43 | \brief signals that set has been clicked | |
44 | Parameter \a category describes on which category was clicked |
|
44 | Parameter \a category describes on which category was clicked | |
45 | Parameter \a button mouse button |
|
45 | Parameter \a button mouse button | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
49 | \fn void QBarSet::hoverEnter(QPoint pos) | |
50 | \brief signals that mouse has entered over the set at position \a pos. |
|
50 | \brief signals that mouse has entered over the set at position \a pos. | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \fn void QBarSet::hoverLeave() |
|
54 | \fn void QBarSet::hoverLeave() | |
55 | \brief signals that mouse has left from the set. |
|
55 | \brief signals that mouse has left from the set. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \fn void QBarSet::toggleFloatingValues() |
|
59 | \fn void QBarSet::toggleFloatingValues() | |
60 | \brief \internal |
|
60 | \brief \internal | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
64 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) | |
65 | \brief \internal \a pos \a tip |
|
65 | \brief \internal \a pos \a tip | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
70 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
71 | */ |
|
71 | */ | |
72 | QBarSet::QBarSet(QString name, QObject *parent) |
|
72 | QBarSet::QBarSet(QString name, QObject *parent) | |
73 | : QObject(parent) |
|
73 | : QObject(parent) | |
74 | ,m_name(name) |
|
74 | ,m_name(name) | |
75 | { |
|
75 | { | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | Sets new \a name for set. |
|
79 | Sets new \a name for set. | |
80 | */ |
|
80 | */ | |
81 | void QBarSet::setName(QString name) |
|
81 | void QBarSet::setName(QString name) | |
82 | { |
|
82 | { | |
83 | m_name = name; |
|
83 | m_name = name; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | Returns name of the set. |
|
87 | Returns name of the set. | |
88 | */ |
|
88 | */ | |
89 | QString QBarSet::name() const |
|
89 | QString QBarSet::name() const | |
90 | { |
|
90 | { | |
91 | return m_name; |
|
91 | return m_name; | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | Appends new value \a value to the end of set. |
|
95 | Appends new value \a value to the end of set. | |
96 | */ |
|
96 | */ | |
97 | QBarSet& QBarSet::operator << (const qreal &value) |
|
97 | QBarSet& QBarSet::operator << (const qreal &value) | |
98 | { |
|
98 | { | |
99 | m_values.append(value); |
|
99 | m_values.append(value); | |
100 | emit structureChanged(); |
|
100 | emit structureChanged(); | |
101 | return *this; |
|
101 | return *this; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void QBarSet::insertValue(int i, qreal value) |
|
104 | void QBarSet::insertValue(int i, qreal value) | |
105 | { |
|
105 | { | |
106 | m_values.insert(i, value); |
|
106 | m_values.insert(i, value); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void QBarSet::removeValue(int i) |
|
109 | void QBarSet::removeValue(int i) | |
110 | { |
|
110 | { | |
111 | m_values.removeAt(i); |
|
111 | m_values.removeAt(i); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | Returns count of values in set. |
|
115 | Returns count of values in set. | |
116 | */ |
|
116 | */ | |
117 | int QBarSet::count() const |
|
117 | int QBarSet::count() const | |
118 | { |
|
118 | { | |
119 | return m_values.count(); |
|
119 | return m_values.count(); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Returns value of set indexed by \a index |
|
123 | Returns value of set indexed by \a index | |
124 | */ |
|
124 | */ | |
125 | qreal QBarSet::valueAt(int index) const |
|
125 | qreal QBarSet::valueAt(int index) const | |
126 | { |
|
126 | { | |
127 | return m_values.at(index); |
|
127 | return m_values.at(index); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | Sets a new value \a value to set, indexed by \a index |
|
131 | Sets a new value \a value to set, indexed by \a index | |
132 | */ |
|
132 | */ | |
133 | void QBarSet::setValue(int index, qreal value) |
|
133 | void QBarSet::setValue(int index, qreal value) | |
134 | { |
|
134 | { | |
135 | m_values.replace(index,value); |
|
135 | m_values.replace(index,value); | |
136 | emit valueChanged(); |
|
136 | emit valueChanged(); | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | Returns total sum of all values in barset. |
|
140 | Returns total sum of all values in barset. | |
141 | */ |
|
141 | */ | |
142 | qreal QBarSet::total() const |
|
142 | qreal QBarSet::total() const | |
143 | { |
|
143 | { | |
144 | qreal total(0); |
|
144 | qreal total(0); | |
145 | for (int i=0; i < m_values.count(); i++) { |
|
145 | for (int i=0; i < m_values.count(); i++) { | |
146 | total += m_values.at(i); |
|
146 | total += m_values.at(i); | |
147 | } |
|
147 | } | |
148 | return total; |
|
148 | return total; | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | Sets pen for set. Bars of this set are drawn using \a pen |
|
152 | Sets pen for set. Bars of this set are drawn using \a pen | |
153 | */ |
|
153 | */ | |
154 | void QBarSet::setPen(const QPen &pen) |
|
154 | void QBarSet::setPen(const QPen &pen) | |
155 | { |
|
155 | { | |
156 | m_pen = pen; |
|
156 | m_pen = pen; | |
157 | emit valueChanged(); |
|
157 | emit valueChanged(); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | Returns pen of the set. |
|
161 | Returns pen of the set. | |
162 | */ |
|
162 | */ | |
163 | QPen QBarSet::pen() const |
|
163 | QPen QBarSet::pen() const | |
164 | { |
|
164 | { | |
165 | return m_pen; |
|
165 | return m_pen; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
169 | Sets brush for the set. Bars of this set are drawn using \a brush | |
170 | */ |
|
170 | */ | |
171 | void QBarSet::setBrush(const QBrush &brush) |
|
171 | void QBarSet::setBrush(const QBrush &brush) | |
172 | { |
|
172 | { | |
173 | m_brush = brush; |
|
173 | m_brush = brush; | |
174 | emit valueChanged(); |
|
174 | emit valueChanged(); | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | Returns brush of the set. |
|
178 | Returns brush of the set. | |
179 | */ |
|
179 | */ | |
180 | QBrush QBarSet::brush() const |
|
180 | QBrush QBarSet::brush() const | |
181 | { |
|
181 | { | |
182 | return m_brush; |
|
182 | return m_brush; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Sets the pen for floating values that are drawn on top of this set |
|
186 | Sets the pen for floating values that are drawn on top of this set | |
187 | */ |
|
187 | */ | |
188 | void QBarSet::setFloatingValuePen(const QPen &pen) |
|
188 | void QBarSet::setFloatingValuePen(const QPen &pen) | |
189 | { |
|
189 | { | |
190 | m_floatingValuePen = pen; |
|
190 | m_floatingValuePen = pen; | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | Returns the pen for floating values that are drawn on top of this set |
|
194 | Returns the pen for floating values that are drawn on top of this set | |
195 | */ |
|
195 | */ | |
196 | QPen QBarSet::floatingValuePen() const |
|
196 | QPen QBarSet::floatingValuePen() const | |
197 | { |
|
197 | { | |
198 | return m_floatingValuePen; |
|
198 | return m_floatingValuePen; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
|
202 | Sets the visibility of barset values to \a visible | |||
|
203 | */ | |||
|
204 | void QBarSet::setValuesVisible(bool visible) | |||
|
205 | { | |||
|
206 | emit valuesVisibleChanged(visible); | |||
|
207 | } | |||
|
208 | ||||
|
209 | /*! | |||
202 | \internal \a pos |
|
210 | \internal \a pos | |
203 | */ |
|
211 | */ | |
204 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
212 | void QBarSet::barHoverEnterEvent(QPoint pos) | |
205 | { |
|
213 | { | |
206 | emit showToolTip(pos, m_name); |
|
214 | emit showToolTip(pos, m_name); | |
207 | emit hoverEnter(pos); |
|
215 | emit hoverEnter(pos); | |
208 | } |
|
216 | } | |
209 |
|
217 | |||
210 | /*! |
|
218 | /*! | |
211 | \internal |
|
219 | \internal | |
212 | */ |
|
220 | */ | |
213 | void QBarSet::barHoverLeaveEvent() |
|
221 | void QBarSet::barHoverLeaveEvent() | |
214 | { |
|
222 | { | |
215 | // Emit signal to user of charts |
|
223 | // Emit signal to user of charts | |
216 | emit hoverLeave(); |
|
224 | emit hoverLeave(); | |
217 | } |
|
225 | } | |
218 |
|
226 | |||
219 | #include "moc_qbarset.cpp" |
|
227 | #include "moc_qbarset.cpp" | |
220 |
|
228 | |||
221 | QTCOMMERCIALCHART_END_NAMESPACE |
|
229 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,93 +1,94 | |||||
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 | #ifndef QBARSET_H |
|
21 | #ifndef QBARSET_H | |
22 | #define QBARSET_H |
|
22 | #define QBARSET_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QBrush> |
|
26 | #include <QBrush> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
30 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | QBarSet(QString name, QObject *parent = 0); |
|
34 | QBarSet(QString name, QObject *parent = 0); | |
35 |
|
35 | |||
36 | void setName(QString name); |
|
36 | void setName(QString name); | |
37 | QString name() const; |
|
37 | QString name() const; | |
38 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
38 | QBarSet& operator << (const qreal &value); // appends new value to set | |
39 | void insertValue(int i, qreal value); |
|
39 | void insertValue(int i, qreal value); | |
40 | void removeValue(int i); |
|
40 | void removeValue(int i); | |
41 |
|
41 | |||
42 | // TODO: remove indices eventually. Use as internal? |
|
42 | // TODO: remove indices eventually. Use as internal? | |
43 | int count() const; // count of values in set |
|
43 | int count() const; // count of values in set | |
44 | qreal valueAt(int index) const; // for modifying individual values |
|
44 | qreal valueAt(int index) const; // for modifying individual values | |
45 | void setValue(int index, qreal value); // setter for individual value |
|
45 | void setValue(int index, qreal value); // setter for individual value | |
46 | qreal total() const; // total values in the set |
|
46 | qreal total() const; // total values in the set | |
47 |
|
47 | |||
48 | // TODO: |
|
48 | // TODO: | |
49 | //qreal value(QString category); |
|
49 | //qreal value(QString category); | |
50 | //void setValue(QString category, qreal value); |
|
50 | //void setValue(QString category, qreal value); | |
51 |
|
51 | |||
52 | void setPen(const QPen &pen); |
|
52 | void setPen(const QPen &pen); | |
53 | QPen pen() const; |
|
53 | QPen pen() const; | |
54 |
|
54 | |||
55 | void setBrush(const QBrush &brush); |
|
55 | void setBrush(const QBrush &brush); | |
56 | QBrush brush() const; |
|
56 | QBrush brush() const; | |
57 |
|
57 | |||
58 | void setFloatingValuePen(const QPen &pen); |
|
58 | void setFloatingValuePen(const QPen &pen); | |
59 | QPen floatingValuePen() const; |
|
59 | QPen floatingValuePen() const; | |
60 |
|
60 | |||
|
61 | void setValuesVisible(bool visible = true); | |||
|
62 | ||||
61 | Q_SIGNALS: |
|
63 | Q_SIGNALS: | |
62 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user |
|
64 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user | |
63 | void toggleFloatingValues(); |
|
|||
64 |
|
65 | |||
65 | // TODO: Expose this to user or not? |
|
|||
66 | // TODO: TO PIMPL ---> |
|
66 | // TODO: TO PIMPL ---> | |
67 | void structureChanged(); |
|
67 | void structureChanged(); | |
68 | void valueChanged(); |
|
68 | void valueChanged(); | |
69 | void hoverEnter(QPoint pos); |
|
69 | void hoverEnter(QPoint pos); | |
70 | void hoverLeave(); |
|
70 | void hoverLeave(); | |
71 | void showToolTip(QPoint pos, QString tip); // Private signal |
|
71 | void showToolTip(QPoint pos, QString tip); // Private signal | |
|
72 | void valuesVisibleChanged(bool visible); | |||
72 | // <--- TO PIMPL |
|
73 | // <--- TO PIMPL | |
73 |
|
74 | |||
74 | public Q_SLOTS: |
|
75 | public Q_SLOTS: | |
75 | // These are for internal communication |
|
76 | // These are for internal communication | |
76 | // TODO: TO PIMPL ---> |
|
77 | // TODO: TO PIMPL ---> | |
77 | void barHoverEnterEvent(QPoint pos); |
|
78 | void barHoverEnterEvent(QPoint pos); | |
78 | void barHoverLeaveEvent(); |
|
79 | void barHoverLeaveEvent(); | |
79 | // <--- TO PIMPL |
|
80 | // <--- TO PIMPL | |
80 |
|
81 | |||
81 | private: |
|
82 | private: | |
82 |
|
83 | |||
83 | QString m_name; |
|
84 | QString m_name; | |
84 | QList<qreal> m_values; // TODO: replace with map (category, value) |
|
85 | QList<qreal> m_values; // TODO: replace with map (category, value) | |
85 | QMap<QString, qreal> m_mappedValues; |
|
86 | QMap<QString, qreal> m_mappedValues; | |
86 | QPen m_pen; |
|
87 | QPen m_pen; | |
87 | QBrush m_brush; |
|
88 | QBrush m_brush; | |
88 | QPen m_floatingValuePen; |
|
89 | QPen m_floatingValuePen; | |
89 | }; |
|
90 | }; | |
90 |
|
91 | |||
91 | QTCOMMERCIALCHART_END_NAMESPACE |
|
92 | QTCOMMERCIALCHART_END_NAMESPACE | |
92 |
|
93 | |||
93 | #endif // QBARSET_H |
|
94 | #endif // QBARSET_H |
@@ -1,103 +1,103 | |||||
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 "barvalue_p.h" |
|
23 | #include "barvalue_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | StackedBarChartItem::~StackedBarChartItem() |
|
34 | StackedBarChartItem::~StackedBarChartItem() | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
38 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
39 | { |
|
39 | { | |
40 | QVector<QRectF> layout; |
|
40 | QVector<QRectF> layout; | |
41 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
41 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
42 |
|
42 | |||
43 | qreal maxSum = m_series->maxCategorySum(); |
|
43 | qreal maxSum = m_series->maxCategorySum(); | |
44 | // Domain: |
|
44 | // Domain: | |
45 | if (m_domainMaxY > maxSum) { |
|
45 | if (m_domainMaxY > maxSum) { | |
46 | maxSum = m_domainMaxY; |
|
46 | maxSum = m_domainMaxY; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | qreal height = geometry().height(); |
|
49 | qreal height = geometry().height(); | |
50 | qreal width = geometry().width(); |
|
50 | qreal width = geometry().width(); | |
51 | qreal scale = (height / m_series->maxCategorySum()); |
|
51 | qreal scale = (height / m_series->maxCategorySum()); | |
52 | qreal categotyCount = m_series->categoryCount(); |
|
52 | qreal categotyCount = m_series->categoryCount(); | |
53 | qreal barWidth = width / (categotyCount * 2); |
|
53 | qreal barWidth = width / (categotyCount * 2); | |
54 | qreal xStep = width / categotyCount; |
|
54 | qreal xStep = width / categotyCount; | |
55 | qreal xPos = xStep / 2 - barWidth / 2; |
|
55 | qreal xPos = xStep / 2 - barWidth / 2; | |
56 |
|
56 | |||
57 | int itemIndex(0); |
|
57 | int itemIndex(0); | |
58 | for (int category = 0; category < categotyCount; category++) { |
|
58 | for (int category = 0; category < categotyCount; category++) { | |
59 | qreal yPos = height; |
|
59 | qreal yPos = height; | |
60 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
60 | for (int set=0; set < m_series->barsetCount(); set++) { | |
61 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
61 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
62 | Bar* bar = m_bars.at(itemIndex); |
|
62 | Bar* bar = m_bars.at(itemIndex); | |
63 | bar->setPen(m_series->barsetAt(set)->pen()); |
|
63 | bar->setPen(m_series->barsetAt(set)->pen()); | |
64 | bar->setBrush(m_series->barsetAt(set)->brush()); |
|
64 | bar->setBrush(m_series->barsetAt(set)->brush()); | |
65 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
65 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
66 | layout.append(rect); |
|
66 | layout.append(rect); | |
67 | itemIndex++; |
|
67 | itemIndex++; | |
68 | yPos -= barHeight; |
|
68 | yPos -= barHeight; | |
69 | } |
|
69 | } | |
70 | xPos += xStep; |
|
70 | xPos += xStep; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | // Position floating values |
|
73 | // Position floating values | |
74 | itemIndex = 0; |
|
74 | itemIndex = 0; | |
75 | xPos = (width/categotyCount); |
|
75 | xPos = (width/categotyCount); | |
76 | for (int category=0; category < m_series->categoryCount(); category++) { |
|
76 | for (int category=0; category < m_series->categoryCount(); category++) { | |
77 | qreal yPos = height; |
|
77 | qreal yPos = height; | |
78 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
78 | for (int set=0; set < m_series->barsetCount(); set++) { | |
79 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
79 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
80 |
BarValue* value = m_ |
|
80 | BarValue* value = m_values.at(itemIndex); | |
81 |
|
81 | |||
82 | QBarSet* barSet = m_series->barsetAt(set); |
|
82 | QBarSet* barSet = m_series->barsetAt(set); | |
83 |
|
83 | |||
84 | if (!qFuzzyIsNull(m_series->valueAt(set, category))) { |
|
84 | if (!qFuzzyIsNull(m_series->valueAt(set, category))) { | |
85 | value->setText(QString::number(m_series->valueAt(set,category))); |
|
85 | value->setText(QString::number(m_series->valueAt(set,category))); | |
86 | } else { |
|
86 | } else { | |
87 | value->setText(QString("")); |
|
87 | value->setText(QString("")); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | value->setPos(xPos, yPos-barHeight / 2); |
|
90 | value->setPos(xPos, yPos-barHeight / 2); | |
91 | value->setPen(barSet->floatingValuePen()); |
|
91 | value->setPen(barSet->floatingValuePen()); | |
92 |
|
92 | |||
93 | itemIndex++; |
|
93 | itemIndex++; | |
94 | yPos -= barHeight; |
|
94 | yPos -= barHeight; | |
95 | } |
|
95 | } | |
96 | xPos += xStep; |
|
96 | xPos += xStep; | |
97 | } |
|
97 | } | |
98 | return layout; |
|
98 | return layout; | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | #include "moc_stackedbarchartitem_p.cpp" |
|
101 | #include "moc_stackedbarchartitem_p.cpp" | |
102 |
|
102 | |||
103 | QTCOMMERCIALCHART_END_NAMESPACE |
|
103 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now