@@ -1,222 +1,234 | |||||
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 "barlabel_p.h" |
|
23 | #include "barlabel_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> |
|
|||
33 | #include <QToolTip> |
|
32 | #include <QToolTip> | |
|
33 | #include <QPainter> | |||
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 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
44 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |
45 | setZValue(ChartPresenter::BarSeriesZValue); |
|
45 | setZValue(ChartPresenter::BarSeriesZValue); | |
46 | dataChanged(); |
|
46 | dataChanged(); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | BarChartItem::~BarChartItem() |
|
49 | BarChartItem::~BarChartItem() | |
50 | { |
|
50 | { | |
51 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
51 | disconnect(this,SLOT(showToolTip(QPoint,QString))); | |
|
52 | deleteItems(); | |||
52 | } |
|
53 | } | |
53 |
|
54 | |||
54 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
55 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
55 | { |
|
56 | { | |
56 | if (!m_layoutSet) { |
|
57 | if (!m_layoutSet) { | |
57 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; |
|
58 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; | |
58 | return; |
|
59 | return; | |
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | foreach(QGraphicsItem* i, childItems()) |
|
62 | painter->save(); | |
62 | i->paint(painter,option,widget); |
|
63 | painter->setClipRect(m_clipRect); | |
|
64 | foreach (Bar *bar, m_bars) | |||
|
65 | bar->paint(painter,option,widget); | |||
|
66 | foreach (BarLabel* label, m_labels) | |||
|
67 | label->paint(painter,option,widget); | |||
|
68 | painter->restore(); | |||
63 | } |
|
69 | } | |
64 |
|
70 | |||
65 | QRectF BarChartItem::boundingRect() const |
|
71 | QRectF BarChartItem::boundingRect() const | |
66 | { |
|
72 | { | |
67 | return m_rect; |
|
73 | return m_rect.translated(-m_rect.topLeft()); | |
|
74 | // return m_rect; | |||
68 | } |
|
75 | } | |
69 |
|
76 | |||
70 | void BarChartItem::dataChanged() |
|
77 | void BarChartItem::dataChanged() | |
71 | { |
|
78 | { | |
72 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
79 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
73 | // Delete old bars |
|
80 | deleteItems(); | |
74 | foreach (QGraphicsItem *item, childItems()) |
|
|||
75 | delete item; |
|
|||
76 |
|
81 | |||
77 | m_bars.clear(); |
|
82 | m_bars.clear(); | |
78 | m_labels.clear(); |
|
83 | m_labels.clear(); | |
79 | m_layout.clear(); |
|
84 | m_layout.clear(); | |
80 |
|
85 | |||
81 | // Create new graphic items for bars |
|
86 | // Create new graphic items for bars | |
82 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
87 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
83 | QString category = m_series->categoryName(c); |
|
88 | QString category = m_series->categoryName(c); | |
84 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
89 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
85 | QBarSet *set = m_series->barsetAt(s); |
|
90 | QBarSet *set = m_series->barsetAt(s); | |
86 |
Bar *bar = new Bar(category, |
|
91 | Bar *bar = new Bar(category,0); // Null parent is best :) | |
87 | childItems().append(bar); |
|
|||
88 | m_bars.append(bar); |
|
92 | m_bars.append(bar); | |
89 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); |
|
93 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); | |
90 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); |
|
94 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); | |
91 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); |
|
95 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); | |
92 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
96 | m_layout.append(QRectF(0, 0, 0, 0)); | |
93 | } |
|
97 | } | |
94 | } |
|
98 | } | |
95 |
|
99 | |||
96 | // Create labels |
|
100 | // Create labels | |
97 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
101 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
98 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
102 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
99 | QBarSet *set = m_series->barsetAt(s); |
|
103 | QBarSet *set = m_series->barsetAt(s); | |
100 |
BarLabel *value = new BarLabel(*set, |
|
104 | BarLabel *value = new BarLabel(*set, 0); | |
101 | childItems().append(value); |
|
|||
102 | m_labels.append(value); |
|
105 | m_labels.append(value); | |
103 | connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); |
|
106 | connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); | |
104 | } |
|
107 | } | |
105 | } |
|
108 | } | |
106 | } |
|
109 | } | |
107 |
|
110 | |||
108 | QVector<QRectF> BarChartItem::calculateLayout() |
|
111 | QVector<QRectF> BarChartItem::calculateLayout() | |
109 | { |
|
112 | { | |
110 | QVector<QRectF> layout; |
|
113 | QVector<QRectF> layout; | |
111 |
|
114 | |||
112 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
115 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
113 | qreal categoryCount = m_series->categoryCount(); |
|
116 | qreal categoryCount = m_series->categoryCount(); | |
114 | qreal setCount = m_series->barsetCount(); |
|
117 | qreal setCount = m_series->barsetCount(); | |
115 |
|
118 | |||
116 | qreal width = geometry().width(); |
|
119 | qreal width = geometry().width(); | |
117 | qreal height = geometry().height(); |
|
120 | qreal height = geometry().height(); | |
118 |
|
121 | |||
119 | qreal max = m_series->max(); |
|
122 | qreal max = m_series->max(); | |
120 |
|
123 | |||
121 | // Domain: |
|
124 | // Domain: | |
122 | if (m_domainMaxY > max) { |
|
125 | if (m_domainMaxY > max) { | |
123 | max = m_domainMaxY; |
|
126 | max = m_domainMaxY; | |
124 | } |
|
127 | } | |
125 |
|
128 | |||
126 | qreal scale = (height / max); |
|
129 | qreal scale = (height / max); | |
127 | qreal categoryWidth = width / categoryCount; |
|
130 | qreal categoryWidth = width / categoryCount; | |
128 | qreal barWidth = categoryWidth / (setCount+1); |
|
131 | qreal barWidth = categoryWidth / (setCount+1); | |
129 |
|
132 | |||
130 | int itemIndex(0); |
|
133 | int itemIndex(0); | |
131 | for (int category = 0; category < categoryCount; category++) { |
|
134 | for (int category = 0; category < categoryCount; category++) { | |
132 | qreal xPos = categoryWidth * category + barWidth / 2; |
|
135 | qreal xPos = categoryWidth * category + barWidth / 2; | |
133 | qreal yPos = height; |
|
136 | qreal yPos = height; | |
134 | for (int set = 0; set < setCount; set++) { |
|
137 | for (int set = 0; set < setCount; set++) { | |
135 | QBarSet* barSet = m_series->barsetAt(set); |
|
138 | QBarSet* barSet = m_series->barsetAt(set); | |
136 |
|
139 | |||
137 | qreal barHeight = barSet->valueAt(category) * scale; |
|
140 | qreal barHeight = barSet->valueAt(category) * scale; | |
138 | Bar* bar = m_bars.at(itemIndex); |
|
141 | Bar* bar = m_bars.at(itemIndex); | |
139 |
|
142 | |||
140 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
143 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
141 | layout.append(rect); |
|
144 | layout.append(rect); | |
142 | bar->setPen(barSet->pen()); |
|
145 | bar->setPen(barSet->pen()); | |
143 | bar->setBrush(barSet->brush()); |
|
146 | bar->setBrush(barSet->brush()); | |
144 |
|
147 | |||
145 | BarLabel* label = m_labels.at(itemIndex); |
|
148 | BarLabel* label = m_labels.at(itemIndex); | |
146 |
|
149 | |||
147 | if (!qFuzzyIsNull(barSet->valueAt(category))) { |
|
150 | if (!qFuzzyIsNull(barSet->valueAt(category))) { | |
148 | label->setText(QString::number(barSet->valueAt(category))); |
|
151 | label->setText(QString::number(barSet->valueAt(category))); | |
149 | } else { |
|
152 | } else { | |
150 | label->setText(QString("")); |
|
153 | label->setText(QString("")); | |
151 | } |
|
154 | } | |
152 |
|
155 | |||
153 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
156 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
154 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
157 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
155 |
|
|
158 | label->setFont(barSet->labelFont()); | |
156 |
|
159 | |||
157 | itemIndex++; |
|
160 | itemIndex++; | |
158 | xPos += barWidth; |
|
161 | xPos += barWidth; | |
159 | } |
|
162 | } | |
160 | } |
|
163 | } | |
161 | return layout; |
|
164 | return layout; | |
162 | } |
|
165 | } | |
163 |
|
166 | |||
164 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
167 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
165 | { |
|
168 | { | |
166 | if (animator()) |
|
169 | if (animator()) | |
167 | animator()->updateLayout(this, m_layout, layout); |
|
170 | animator()->updateLayout(this, m_layout, layout); | |
168 | else |
|
171 | else | |
169 | setLayout(layout); |
|
172 | setLayout(layout); | |
170 | } |
|
173 | } | |
171 |
|
174 | |||
172 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
175 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
173 | { |
|
176 | { | |
174 | m_layout = layout; |
|
177 | m_layout = layout; | |
175 |
|
178 | |||
176 | for (int i=0; i < m_bars.count(); i++) |
|
179 | for (int i=0; i < m_bars.count(); i++) | |
177 | m_bars.at(i)->setRect(layout.at(i)); |
|
180 | m_bars.at(i)->setRect(layout.at(i)); | |
178 |
|
181 | |||
179 | update(); |
|
182 | update(); | |
180 | } |
|
183 | } | |
181 |
|
184 | |||
|
185 | void BarChartItem::deleteItems() | |||
|
186 | { | |||
|
187 | foreach (Bar *bar, m_bars) | |||
|
188 | delete bar; | |||
|
189 | foreach (BarLabel* label, m_labels) | |||
|
190 | delete label; | |||
|
191 | } | |||
|
192 | ||||
182 | //handlers |
|
193 | //handlers | |
183 |
|
194 | |||
184 | void BarChartItem::handleModelChanged(int index) |
|
195 | void BarChartItem::handleModelChanged(int index) | |
185 | { |
|
196 | { | |
186 | Q_UNUSED(index) |
|
197 | Q_UNUSED(index) | |
187 | dataChanged(); |
|
198 | dataChanged(); | |
188 | } |
|
199 | } | |
189 |
|
200 | |||
190 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
201 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
191 | { |
|
202 | { | |
192 | m_domainMinX = minX; |
|
203 | m_domainMinX = minX; | |
193 | m_domainMaxX = maxX; |
|
204 | m_domainMaxX = maxX; | |
194 | m_domainMinY = minY; |
|
205 | m_domainMinY = minY; | |
195 | m_domainMaxY = maxY; |
|
206 | m_domainMaxY = maxY; | |
196 | handleLayoutChanged(); |
|
207 | handleLayoutChanged(); | |
197 | } |
|
208 | } | |
198 |
|
209 | |||
199 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
210 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
200 | { |
|
211 | { | |
|
212 | m_clipRect = rect.translated(-rect.topLeft()); | |||
201 | m_rect = rect; |
|
213 | m_rect = rect; | |
202 | handleLayoutChanged(); |
|
214 | handleLayoutChanged(); | |
203 | m_layoutSet = true; |
|
215 | m_layoutSet = true; | |
204 | setPos(rect.topLeft()); |
|
216 | setPos(rect.topLeft()); | |
205 | } |
|
217 | } | |
206 |
|
218 | |||
207 | void BarChartItem::handleLayoutChanged() |
|
219 | void BarChartItem::handleLayoutChanged() | |
208 | { |
|
220 | { | |
209 | QVector<QRectF> layout = calculateLayout(); |
|
221 | QVector<QRectF> layout = calculateLayout(); | |
210 | applyLayout(layout); |
|
222 | applyLayout(layout); | |
211 | update(); |
|
223 | update(); | |
212 | } |
|
224 | } | |
213 |
|
225 | |||
214 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
226 | void BarChartItem::showToolTip(QPoint pos, QString tip) | |
215 | { |
|
227 | { | |
216 | // TODO: cool tooltip instead of default |
|
228 | // TODO: cool tooltip instead of default | |
217 | QToolTip::showText(pos, tip); |
|
229 | QToolTip::showText(pos, tip); | |
218 | } |
|
230 | } | |
219 |
|
231 | |||
220 | #include "moc_barchartitem_p.cpp" |
|
232 | #include "moc_barchartitem_p.cpp" | |
221 |
|
233 | |||
222 | QTCOMMERCIALCHART_END_NAMESPACE |
|
234 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,89 +1,93 | |||||
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 BarLabel; |
|
32 | class BarLabel; | |
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 | public: |
|
45 | public: | |
46 | // From QGraphicsItem |
|
46 | // From QGraphicsItem | |
47 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
47 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
48 | QRectF boundingRect() const; |
|
48 | QRectF boundingRect() const; | |
49 |
|
49 | |||
50 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
50 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it | |
51 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
51 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
52 |
|
52 | |||
53 | virtual QVector<QRectF> calculateLayout(); |
|
53 | virtual QVector<QRectF> calculateLayout(); | |
54 | void applyLayout(const QVector<QRectF> &layout); |
|
54 | void applyLayout(const QVector<QRectF> &layout); | |
55 | void setLayout(const QVector<QRectF> &layout); |
|
55 | void setLayout(const QVector<QRectF> &layout); | |
56 | void updateLayout(const QVector<QRectF> &layout); |
|
56 | void updateLayout(const QVector<QRectF> &layout); | |
57 |
|
57 | |||
58 | QRectF geometry() const { return m_rect;} |
|
58 | QRectF geometry() const { return m_rect;} | |
59 |
|
59 | |||
|
60 | private: | |||
|
61 | void deleteItems(); | |||
|
62 | ||||
60 | public Q_SLOTS: |
|
63 | public Q_SLOTS: | |
61 | void handleModelChanged(int index); |
|
64 | void handleModelChanged(int index); | |
62 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
65 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
63 | void handleGeometryChanged(const QRectF &size); |
|
66 | void handleGeometryChanged(const QRectF &size); | |
64 | void handleLayoutChanged(); |
|
67 | void handleLayoutChanged(); | |
65 |
|
68 | |||
66 | // Internal slots |
|
69 | // Internal slots | |
67 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) |
|
70 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) | |
68 |
|
71 | |||
69 | protected: |
|
72 | protected: | |
70 |
|
73 | |||
71 | // TODO: consider these. |
|
74 | // TODO: consider these. | |
72 | qreal m_domainMinX; |
|
75 | qreal m_domainMinX; | |
73 | qreal m_domainMaxX; |
|
76 | qreal m_domainMaxX; | |
74 | qreal m_domainMinY; |
|
77 | qreal m_domainMinY; | |
75 | qreal m_domainMaxY; |
|
78 | qreal m_domainMaxY; | |
76 |
|
79 | |||
77 | QRectF m_rect; |
|
80 | QRectF m_rect; | |
|
81 | QRectF m_clipRect; | |||
78 | bool m_layoutSet; // True, if component has been laid out. |
|
82 | bool m_layoutSet; // True, if component has been laid out. | |
79 | QVector<QRectF> m_layout; |
|
83 | QVector<QRectF> m_layout; | |
80 |
|
84 | |||
81 | // Not owned. |
|
85 | // Not owned. | |
82 | QBarSeries *m_series; |
|
86 | QBarSeries *m_series; | |
83 | QList<Bar *> m_bars; |
|
87 | QList<Bar *> m_bars; | |
84 | QList<BarLabel *> m_labels; |
|
88 | QList<BarLabel *> m_labels; | |
85 | }; |
|
89 | }; | |
86 |
|
90 | |||
87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
88 |
|
92 | |||
89 | #endif // BARCHARTITEM_H |
|
93 | #endif // BARCHARTITEM_H |
@@ -1,86 +1,85 | |||||
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 "barlabel_p.h" |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include <QDebug> |
|
|||
26 |
|
25 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
27 | |||
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
28 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
29 | BarChartItem(series, presenter) | |
31 | { |
|
30 | { | |
32 | } |
|
31 | } | |
33 |
|
32 | |||
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
33 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
35 | { |
|
34 | { | |
36 | QVector<QRectF> layout; |
|
35 | QVector<QRectF> layout; | |
37 |
|
36 | |||
38 |
// Use temporary qreals for accurancy |
|
37 | // Use temporary qreals for accurancy | |
39 | qreal width = geometry().width(); |
|
38 | qreal width = geometry().width(); | |
40 | qreal height = geometry().height(); |
|
39 | qreal height = geometry().height(); | |
41 |
|
40 | |||
42 | qreal categoryCount = m_series->categoryCount(); |
|
41 | qreal categoryCount = m_series->categoryCount(); | |
43 | qreal barWidth = width / (m_series->categoryCount() * 2); |
|
42 | qreal barWidth = width / (m_series->categoryCount() * 2); | |
44 | qreal xStep = width / categoryCount; |
|
43 | qreal xStep = width / categoryCount; | |
45 | qreal xPos = xStep / 2 - barWidth / 2; |
|
44 | qreal xPos = xStep / 2 - barWidth / 2; | |
46 |
|
45 | |||
47 | int itemIndex(0); |
|
46 | int itemIndex(0); | |
48 | for (int category = 0; category < categoryCount; category++) { |
|
47 | for (int category = 0; category < categoryCount; category++) { | |
49 | qreal colSum = m_series->categorySum(category); |
|
48 | qreal colSum = m_series->categorySum(category); | |
50 | qreal scale = (height / colSum); |
|
49 | qreal scale = (height / colSum); | |
51 | qreal yPos = height; |
|
50 | qreal yPos = height; | |
52 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
51 | for (int set=0; set < m_series->barsetCount(); set++) { | |
53 | QBarSet* barSet = m_series->barsetAt(set); |
|
52 | QBarSet* barSet = m_series->barsetAt(set); | |
54 | qreal barHeight = barSet->valueAt(category) * scale; |
|
53 | qreal barHeight = barSet->valueAt(category) * scale; | |
55 | Bar* bar = m_bars.at(itemIndex); |
|
54 | Bar* bar = m_bars.at(itemIndex); | |
56 | bar->setPen(barSet->pen()); |
|
55 | bar->setPen(barSet->pen()); | |
57 | bar->setBrush(barSet->brush()); |
|
56 | bar->setBrush(barSet->brush()); | |
58 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
57 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
59 | layout.append(rect); |
|
58 | layout.append(rect); | |
60 |
|
59 | |||
61 | BarLabel* label = m_labels.at(itemIndex); |
|
60 | BarLabel* label = m_labels.at(itemIndex); | |
62 |
|
61 | |||
63 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
62 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
64 | int p = m_series->percentageAt(set,category) * 100; |
|
63 | int p = m_series->percentageAt(set,category) * 100; | |
65 | QString vString(QString::number(p)); |
|
64 | QString vString(QString::number(p)); | |
66 | vString.truncate(3); |
|
65 | vString.truncate(3); | |
67 | vString.append("%"); |
|
66 | vString.append("%"); | |
68 | label->setText(vString); |
|
67 | label->setText(vString); | |
69 | } else { |
|
68 | } else { | |
70 | label->setText(QString("")); |
|
69 | label->setText(QString("")); | |
71 | } |
|
70 | } | |
72 |
|
71 | |||
73 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
72 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
74 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
73 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
75 |
|
|
74 | label->setFont(barSet->labelFont()); | |
76 | itemIndex++; |
|
75 | itemIndex++; | |
77 | yPos -= barHeight; |
|
76 | yPos -= barHeight; | |
78 | } |
|
77 | } | |
79 | xPos += xStep; |
|
78 | xPos += xStep; | |
80 | } |
|
79 | } | |
81 | return layout; |
|
80 | return layout; | |
82 | } |
|
81 | } | |
83 |
|
82 | |||
84 | #include "moc_percentbarchartitem_p.cpp" |
|
83 | #include "moc_percentbarchartitem_p.cpp" | |
85 |
|
84 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,404 +1,407 | |||||
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 | /*! | |||
|
395 | Sets the visibility of labels in series to \a visible | |||
|
396 | */ | |||
394 | void QBarSeries::setLabelsVisible(bool visible) |
|
397 | void QBarSeries::setLabelsVisible(bool visible) | |
395 | { |
|
398 | { | |
396 | foreach (QBarSet* s, barSets()) { |
|
399 | foreach (QBarSet* s, barSets()) { | |
397 | s->setLabelsVisible(visible); |
|
400 | s->setLabelsVisible(visible); | |
398 | } |
|
401 | } | |
399 | } |
|
402 | } | |
400 |
|
403 | |||
401 |
|
404 | |||
402 | #include "moc_qbarseries.cpp" |
|
405 | #include "moc_qbarseries.cpp" | |
403 |
|
406 | |||
404 | QTCOMMERCIALCHART_END_NAMESPACE |
|
407 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,274 +1,274 | |||||
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::setLabelssVisible(bool visible = true) |
|
59 | \fn void QBarSet::setLabelssVisible(bool visible = true) | |
60 | \brief Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. |
|
60 | \brief Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | |
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 | ,m_labelsVisible(false) |
|
75 | ,m_labelsVisible(false) | |
76 | { |
|
76 | { | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | Sets new \a name for set. |
|
80 | Sets new \a name for set. | |
81 | */ |
|
81 | */ | |
82 | void QBarSet::setName(QString name) |
|
82 | void QBarSet::setName(QString name) | |
83 | { |
|
83 | { | |
84 | m_name = name; |
|
84 | m_name = name; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | Returns name of the set. |
|
88 | Returns name of the set. | |
89 | */ |
|
89 | */ | |
90 | QString QBarSet::name() const |
|
90 | QString QBarSet::name() const | |
91 | { |
|
91 | { | |
92 | return m_name; |
|
92 | return m_name; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | Appends new value \a value to the end of set. |
|
96 | Appends new value \a value to the end of set. | |
97 | */ |
|
97 | */ | |
98 | QBarSet& QBarSet::operator << (const qreal &value) |
|
98 | QBarSet& QBarSet::operator << (const qreal &value) | |
99 | { |
|
99 | { | |
100 | m_values.append(value); |
|
100 | m_values.append(value); | |
101 | emit structureChanged(); |
|
101 | emit structureChanged(); | |
102 | return *this; |
|
102 | return *this; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void QBarSet::insertValue(int i, qreal value) |
|
105 | void QBarSet::insertValue(int i, qreal value) | |
106 | { |
|
106 | { | |
107 | m_values.insert(i, value); |
|
107 | m_values.insert(i, value); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void QBarSet::removeValue(int i) |
|
110 | void QBarSet::removeValue(int i) | |
111 | { |
|
111 | { | |
112 | m_values.removeAt(i); |
|
112 | m_values.removeAt(i); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | Returns count of values in set. |
|
116 | Returns count of values in set. | |
117 | */ |
|
117 | */ | |
118 | int QBarSet::count() const |
|
118 | int QBarSet::count() const | |
119 | { |
|
119 | { | |
120 | return m_values.count(); |
|
120 | return m_values.count(); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Returns value of set indexed by \a index |
|
124 | Returns value of set indexed by \a index | |
125 | */ |
|
125 | */ | |
126 | qreal QBarSet::valueAt(int index) const |
|
126 | qreal QBarSet::valueAt(int index) const | |
127 | { |
|
127 | { | |
128 | return m_values.at(index); |
|
128 | return m_values.at(index); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | Sets a new value \a value to set, indexed by \a index |
|
132 | Sets a new value \a value to set, indexed by \a index | |
133 | */ |
|
133 | */ | |
134 | void QBarSet::setValue(int index, qreal value) |
|
134 | void QBarSet::setValue(int index, qreal value) | |
135 | { |
|
135 | { | |
136 | m_values.replace(index,value); |
|
136 | m_values.replace(index,value); | |
137 | emit valueChanged(); |
|
137 | emit valueChanged(); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | Returns total sum of all values in barset. |
|
141 | Returns total sum of all values in barset. | |
142 | */ |
|
142 | */ | |
143 | qreal QBarSet::total() const |
|
143 | qreal QBarSet::total() const | |
144 | { |
|
144 | { | |
145 | qreal total(0); |
|
145 | qreal total(0); | |
146 | for (int i=0; i < m_values.count(); i++) { |
|
146 | for (int i=0; i < m_values.count(); i++) { | |
147 | total += m_values.at(i); |
|
147 | total += m_values.at(i); | |
148 | } |
|
148 | } | |
149 | return total; |
|
149 | return total; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Sets pen for set. Bars of this set are drawn using \a pen |
|
153 | Sets pen for set. Bars of this set are drawn using \a pen | |
154 | */ |
|
154 | */ | |
155 | void QBarSet::setPen(const QPen &pen) |
|
155 | void QBarSet::setPen(const QPen &pen) | |
156 | { |
|
156 | { | |
157 | m_pen = pen; |
|
157 | m_pen = pen; | |
158 | emit valueChanged(); |
|
158 | emit valueChanged(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Returns pen of the set. |
|
162 | Returns pen of the set. | |
163 | */ |
|
163 | */ | |
164 | QPen QBarSet::pen() const |
|
164 | QPen QBarSet::pen() const | |
165 | { |
|
165 | { | |
166 | return m_pen; |
|
166 | return m_pen; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | /*! |
|
169 | /*! | |
170 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
170 | Sets brush for the set. Bars of this set are drawn using \a brush | |
171 | */ |
|
171 | */ | |
172 | void QBarSet::setBrush(const QBrush &brush) |
|
172 | void QBarSet::setBrush(const QBrush &brush) | |
173 | { |
|
173 | { | |
174 | m_brush = brush; |
|
174 | m_brush = brush; | |
175 | emit valueChanged(); |
|
175 | emit valueChanged(); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | /*! |
|
178 | /*! | |
179 | Returns brush of the set. |
|
179 | Returns brush of the set. | |
180 | */ |
|
180 | */ | |
181 | QBrush QBarSet::brush() const |
|
181 | QBrush QBarSet::brush() const | |
182 | { |
|
182 | { | |
183 | return m_brush; |
|
183 | return m_brush; | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | Sets pen of the values that are drawn on top of this barset |
|
187 | Sets \a pen of the values that are drawn on top of this barset | |
188 | */ |
|
188 | */ | |
189 | void QBarSet::setLabelPen(const QPen &pen) |
|
189 | void QBarSet::setLabelPen(const QPen &pen) | |
190 | { |
|
190 | { | |
191 | m_labelPen = pen; |
|
191 | m_labelPen = pen; | |
192 | emit valueChanged(); |
|
192 | emit valueChanged(); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | Returns pen of the values that are drawn on top of this barset |
|
196 | Returns pen of the values that are drawn on top of this barset | |
197 | */ |
|
197 | */ | |
198 | QPen QBarSet::labelPen() const |
|
198 | QPen QBarSet::labelPen() const | |
199 | { |
|
199 | { | |
200 | return m_labelPen; |
|
200 | return m_labelPen; | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Sets brush of the values that are drawn on top of this barset |
|
204 | Sets \a brush of the values that are drawn on top of this barset | |
205 | */ |
|
205 | */ | |
206 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
206 | void QBarSet::setLabelBrush(const QBrush &brush) | |
207 | { |
|
207 | { | |
208 | m_labelBrush = brush; |
|
208 | m_labelBrush = brush; | |
209 | emit valueChanged(); |
|
209 | emit valueChanged(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Returns brush of the values that are drawn on top of this barset |
|
213 | Returns brush of the values that are drawn on top of this barset | |
214 | */ |
|
214 | */ | |
215 | QBrush QBarSet::labelBrush() const |
|
215 | QBrush QBarSet::labelBrush() const | |
216 | { |
|
216 | { | |
217 | return m_labelBrush; |
|
217 | return m_labelBrush; | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 |
Sets the |
|
221 | Sets the \a font for values that are drawn on top of this barset | |
222 | */ |
|
222 | */ | |
223 | void QBarSet::setLabelFont(const QFont &font) |
|
223 | void QBarSet::setLabelFont(const QFont &font) | |
224 | { |
|
224 | { | |
225 | m_labelFont = font; |
|
225 | m_labelFont = font; | |
226 | emit valueChanged(); |
|
226 | emit valueChanged(); | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | Returns the pen for values that are drawn on top of this set |
|
230 | Returns the pen for values that are drawn on top of this set | |
231 | */ |
|
231 | */ | |
232 | QFont QBarSet::labelFont() const |
|
232 | QFont QBarSet::labelFont() const | |
233 | { |
|
233 | { | |
234 | return m_labelFont; |
|
234 | return m_labelFont; | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | Sets the visibility of barset values to \a visible |
|
238 | Sets the visibility of barset values to \a visible | |
239 | */ |
|
239 | */ | |
240 | void QBarSet::setLabelsVisible(bool visible) |
|
240 | void QBarSet::setLabelsVisible(bool visible) | |
241 | { |
|
241 | { | |
242 | m_labelsVisible = visible; |
|
242 | m_labelsVisible = visible; | |
243 | emit labelsVisibleChanged(visible); |
|
243 | emit labelsVisibleChanged(visible); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | Returns the visibility of values |
|
247 | Returns the visibility of values | |
248 | */ |
|
248 | */ | |
249 | bool QBarSet::labelsVisible() const |
|
249 | bool QBarSet::labelsVisible() const | |
250 | { |
|
250 | { | |
251 | return m_labelsVisible; |
|
251 | return m_labelsVisible; | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 | \internal \a pos |
|
255 | \internal \a pos | |
256 | */ |
|
256 | */ | |
257 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
257 | void QBarSet::barHoverEnterEvent(QPoint pos) | |
258 | { |
|
258 | { | |
259 | emit showToolTip(pos, m_name); |
|
259 | emit showToolTip(pos, m_name); | |
260 | emit hoverEnter(pos); |
|
260 | emit hoverEnter(pos); | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | /*! |
|
263 | /*! | |
264 | \internal |
|
264 | \internal | |
265 | */ |
|
265 | */ | |
266 | void QBarSet::barHoverLeaveEvent() |
|
266 | void QBarSet::barHoverLeaveEvent() | |
267 | { |
|
267 | { | |
268 | // Emit signal to user of charts |
|
268 | // Emit signal to user of charts | |
269 | emit hoverLeave(); |
|
269 | emit hoverLeave(); | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | #include "moc_qbarset.cpp" |
|
272 | #include "moc_qbarset.cpp" | |
273 |
|
273 | |||
274 | QTCOMMERCIALCHART_END_NAMESPACE |
|
274 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,92 +1,83 | |||||
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 "barlabel_p.h" |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include <QDebug> |
|
|||
26 |
|
25 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
27 | |||
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
28 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
29 | BarChartItem(series, presenter) | |
31 | { |
|
30 | { | |
32 | } |
|
31 | } | |
33 |
|
32 | |||
34 | StackedBarChartItem::~StackedBarChartItem() |
|
|||
35 | { |
|
|||
36 | } |
|
|||
37 |
|
||||
38 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
33 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
39 | { |
|
34 | { | |
40 | QVector<QRectF> layout; |
|
35 | QVector<QRectF> layout; | |
41 |
// Use temporary qreals for accurancy |
|
36 | // Use temporary qreals for accurancy | |
42 |
|
37 | |||
43 | qreal maxSum = m_series->maxCategorySum(); |
|
|||
44 | // Domain: |
|
38 | // Domain: | |
45 | if (m_domainMaxY > maxSum) { |
|
39 | qreal range = m_domainMaxY - m_domainMinY; | |
46 | maxSum = m_domainMaxY; |
|
|||
47 | } |
|
|||
48 |
|
||||
49 | qreal height = geometry().height(); |
|
40 | qreal height = geometry().height(); | |
50 | qreal width = geometry().width(); |
|
41 | qreal width = geometry().width(); | |
51 |
qreal scale = (height / |
|
42 | qreal scale = (height / range); | |
52 | qreal categotyCount = m_series->categoryCount(); |
|
43 | qreal categotyCount = m_series->categoryCount(); | |
53 | qreal barWidth = width / (categotyCount * 2); |
|
44 | qreal barWidth = width / (categotyCount * 2); | |
54 | qreal xStep = width / categotyCount; |
|
45 | qreal xStep = width / categotyCount; | |
55 | qreal xPos = xStep / 2 - barWidth / 2; |
|
46 | qreal xPos = xStep / 2 - barWidth / 2; | |
56 |
|
47 | |||
57 | int itemIndex(0); |
|
48 | int itemIndex(0); | |
58 | for (int category = 0; category < categotyCount; category++) { |
|
49 | for (int category = 0; category < categotyCount; category++) { | |
59 | qreal yPos = height; |
|
50 | qreal yPos = height + scale * m_domainMinY; | |
60 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
51 | for (int set=0; set < m_series->barsetCount(); set++) { | |
61 | QBarSet* barSet = m_series->barsetAt(set); |
|
52 | QBarSet* barSet = m_series->barsetAt(set); | |
62 |
|
53 | |||
63 | qreal barHeight = barSet->valueAt(category) * scale; |
|
54 | qreal barHeight = barSet->valueAt(category) * scale; | |
64 | Bar* bar = m_bars.at(itemIndex); |
|
55 | Bar* bar = m_bars.at(itemIndex); | |
65 | bar->setPen(barSet->pen()); |
|
56 | bar->setPen(barSet->pen()); | |
66 | bar->setBrush(barSet->brush()); |
|
57 | bar->setBrush(barSet->brush()); | |
67 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
58 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
68 | layout.append(rect); |
|
59 | layout.append(rect); | |
69 |
|
60 | |||
70 | BarLabel* label = m_labels.at(itemIndex); |
|
61 | BarLabel* label = m_labels.at(itemIndex); | |
71 |
|
62 | |||
72 | if (!qFuzzyIsNull(barSet->valueAt(category))) { |
|
63 | if (!qFuzzyIsNull(barSet->valueAt(category))) { | |
73 | label->setText(QString::number(barSet->valueAt(category))); |
|
64 | label->setText(QString::number(barSet->valueAt(category))); | |
74 | } else { |
|
65 | } else { | |
75 | label->setText(QString("")); |
|
66 | label->setText(QString("")); | |
76 | } |
|
67 | } | |
77 |
|
68 | |||
78 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
69 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
79 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
70 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
80 |
|
|
71 | label->setFont(barSet->labelFont()); | |
81 | itemIndex++; |
|
72 | itemIndex++; | |
82 | yPos -= barHeight; |
|
73 | yPos -= barHeight; | |
83 | } |
|
74 | } | |
84 | xPos += xStep; |
|
75 | xPos += xStep; | |
85 | } |
|
76 | } | |
86 |
|
77 | |||
87 | return layout; |
|
78 | return layout; | |
88 | } |
|
79 | } | |
89 |
|
80 | |||
90 | #include "moc_stackedbarchartitem_p.cpp" |
|
81 | #include "moc_stackedbarchartitem_p.cpp" | |
91 |
|
82 | |||
92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,48 +1,47 | |||||
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 STACKEDBARCHARTITEM_H |
|
21 | #ifndef STACKEDBARCHARTITEM_H | |
22 | #define STACKEDBARCHARTITEM_H |
|
22 | #define STACKEDBARCHARTITEM_H | |
23 |
|
23 | |||
24 | #include "barchartitem_p.h" |
|
24 | #include "barchartitem_p.h" | |
25 | #include "qstackedbarseries.h" |
|
25 | #include "qstackedbarseries.h" | |
26 | #include <QGraphicsItem> |
|
26 | #include <QGraphicsItem> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class StackedBarChartItem : public BarChartItem |
|
30 | class StackedBarChartItem : public BarChartItem | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
34 | StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
35 | ~StackedBarChartItem(); |
|
|||
36 |
|
35 | |||
37 | private: |
|
36 | private: | |
38 | // From BarChartItem |
|
37 | // From BarChartItem | |
39 | virtual QVector<QRectF> calculateLayout(); |
|
38 | virtual QVector<QRectF> calculateLayout(); | |
40 |
|
39 | |||
41 | private: |
|
40 | private: | |
42 |
|
41 | |||
43 | // Data |
|
42 | // Data | |
44 | }; |
|
43 | }; | |
45 |
|
44 | |||
46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | QTCOMMERCIALCHART_END_NAMESPACE | |
47 |
|
46 | |||
48 | #endif // STACKEDBARCHARTITEM_H |
|
47 | #endif // STACKEDBARCHARTITEM_H |
General Comments 0
You need to be logged in to leave comments.
Login now