@@ -1,214 +1,207 | |||||
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 "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qbarseries_p.h" |
|
26 | #include "qbarseries_p.h" | |
27 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
28 | #include "chartpresenter_p.h" |
|
28 | #include "chartpresenter_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QPainter> |
|
31 | #include <QPainter> | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
35 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
36 | ChartItem(presenter), |
|
36 | ChartItem(presenter), | |
37 | m_series(series) |
|
37 | m_series(series) | |
38 | { |
|
38 | { | |
39 | setFlag(ItemClipsChildrenToShape); |
|
39 | setFlag(ItemClipsChildrenToShape); | |
40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
41 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); |
|
|||
42 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(labelsVisibleChanged(bool))); |
|
41 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(labelsVisibleChanged(bool))); | |
43 | setZValue(ChartPresenter::BarSeriesZValue); |
|
42 | setZValue(ChartPresenter::BarSeriesZValue); | |
44 | dataChanged(); |
|
43 | dataChanged(); | |
45 | } |
|
44 | } | |
46 |
|
45 | |||
47 | BarChartItem::~BarChartItem() |
|
46 | BarChartItem::~BarChartItem() | |
48 | { |
|
47 | { | |
49 | } |
|
48 | } | |
50 |
|
49 | |||
51 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
50 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
52 | { |
|
51 | { | |
53 | Q_UNUSED(painter); |
|
52 | Q_UNUSED(painter); | |
54 | Q_UNUSED(option); |
|
53 | Q_UNUSED(option); | |
55 | Q_UNUSED(widget); |
|
54 | Q_UNUSED(widget); | |
56 | } |
|
55 | } | |
57 |
|
56 | |||
58 | QRectF BarChartItem::boundingRect() const |
|
57 | QRectF BarChartItem::boundingRect() const | |
59 | { |
|
58 | { | |
60 | return m_rect; |
|
59 | return m_rect; | |
61 | } |
|
60 | } | |
62 |
|
61 | |||
63 | void BarChartItem::dataChanged() |
|
62 | void BarChartItem::dataChanged() | |
64 | { |
|
63 | { | |
65 | foreach(QGraphicsItem *item, childItems()) { |
|
64 | foreach(QGraphicsItem *item, childItems()) { | |
66 | delete item; |
|
65 | delete item; | |
67 | } |
|
66 | } | |
68 |
|
67 | |||
69 | m_bars.clear(); |
|
68 | m_bars.clear(); | |
70 | m_labels.clear(); |
|
69 | m_labels.clear(); | |
71 | m_layout.clear(); |
|
70 | m_layout.clear(); | |
72 |
|
71 | |||
73 | bool labelsVisible = m_series->isLabelsVisible(); |
|
72 | bool labelsVisible = m_series->isLabelsVisible(); | |
74 |
|
73 | |||
75 | // Create new graphic items for bars |
|
74 | // Create new graphic items for bars | |
76 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { |
|
75 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { | |
77 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
76 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
78 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
77 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
79 |
|
78 | |||
80 | // Bars |
|
79 | // Bars | |
81 | Bar *bar = new Bar(set,c,this); |
|
80 | Bar *bar = new Bar(set,c,this); | |
82 | m_bars.append(bar); |
|
81 | m_bars.append(bar); | |
83 | connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int))); |
|
82 | connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int))); | |
84 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); |
|
83 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); | |
85 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
84 | m_layout.append(QRectF(0, 0, 0, 0)); | |
86 |
|
85 | |||
87 | // Labels |
|
86 | // Labels | |
88 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); |
|
87 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); | |
89 | label->setVisible(labelsVisible); |
|
88 | label->setVisible(labelsVisible); | |
90 | m_labels.append(label); |
|
89 | m_labels.append(label); | |
91 | } |
|
90 | } | |
92 | } |
|
91 | } | |
93 |
|
92 | |||
94 | // TODO: Is this the right place to call it? |
|
93 | // TODO: Is this the right place to call it? | |
95 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
94 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
96 | } |
|
95 | } | |
97 |
|
96 | |||
98 | QVector<QRectF> BarChartItem::calculateLayout() |
|
97 | QVector<QRectF> BarChartItem::calculateLayout() | |
99 | { |
|
98 | { | |
100 | QVector<QRectF> layout; |
|
99 | QVector<QRectF> layout; | |
101 |
|
100 | |||
102 | // Use temporary qreals for accuracy |
|
101 | // Use temporary qreals for accuracy | |
103 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
102 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
104 | qreal setCount = m_series->barsetCount(); |
|
103 | qreal setCount = m_series->barsetCount(); | |
105 | bool barsVisible = m_series->isVisible(); |
|
104 | bool barsVisible = m_series->isVisible(); | |
106 |
|
105 | |||
107 | // Domain: |
|
106 | // Domain: | |
108 | qreal width = geometry().width(); |
|
107 | qreal width = geometry().width(); | |
109 | qreal height = geometry().height(); |
|
108 | qreal height = geometry().height(); | |
110 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
109 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
111 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
110 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
112 | qreal scaleY = (height / rangeY); |
|
111 | qreal scaleY = (height / rangeY); | |
113 | qreal scaleX = (width / rangeX); |
|
112 | qreal scaleX = (width / rangeX); | |
114 | qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin(); |
|
113 | qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin(); | |
115 |
|
114 | |||
116 | int itemIndex(0); |
|
115 | int itemIndex(0); | |
117 | for (int category = 0; category < categoryCount; category++) { |
|
116 | for (int category = 0; category < categoryCount; category++) { | |
118 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
117 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
119 | for (int set = 0; set < setCount; set++) { |
|
118 | for (int set = 0; set < setCount; set++) { | |
120 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
119 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
121 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
120 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
122 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
121 | qreal barHeight = barSet->at(category).y() * scaleY; | |
123 |
|
122 | |||
124 | Bar* bar = m_bars.at(itemIndex); |
|
123 | Bar* bar = m_bars.at(itemIndex); | |
125 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
124 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
126 |
|
125 | |||
127 | layout.append(rect); |
|
126 | layout.append(rect); | |
128 | bar->setPen(barSet->pen()); |
|
127 | bar->setPen(barSet->pen()); | |
129 | bar->setBrush(barSet->brush()); |
|
128 | bar->setBrush(barSet->brush()); | |
130 | bar->setVisible(barsVisible); |
|
129 | bar->setVisible(barsVisible); | |
131 |
|
130 | |||
132 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
131 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
133 |
|
132 | |||
134 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
133 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
135 | label->setText(QString::number(barSet->at(category).y())); |
|
134 | label->setText(QString::number(barSet->at(category).y())); | |
136 | } else { |
|
135 | } else { | |
137 | label->setText(QString("")); |
|
136 | label->setText(QString("")); | |
138 | } |
|
137 | } | |
139 |
|
138 | |||
140 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
139 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
141 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
140 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
142 | label->setFont(barSet->labelFont()); |
|
141 | label->setFont(barSet->labelFont()); | |
143 | label->setBrush(barSet->labelBrush()); |
|
142 | label->setBrush(barSet->labelBrush()); | |
144 |
|
143 | |||
145 | itemIndex++; |
|
144 | itemIndex++; | |
146 | } |
|
145 | } | |
147 | } |
|
146 | } | |
148 |
|
147 | |||
149 | return layout; |
|
148 | return layout; | |
150 | } |
|
149 | } | |
151 |
|
150 | |||
152 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
151 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
153 | { |
|
152 | { | |
154 | if (animator()) |
|
153 | if (animator()) | |
155 | animator()->updateLayout(this, m_layout, layout); |
|
154 | animator()->updateLayout(this, m_layout, layout); | |
156 | else |
|
155 | else | |
157 | setLayout(layout); |
|
156 | setLayout(layout); | |
158 | } |
|
157 | } | |
159 |
|
158 | |||
160 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
159 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
161 | { |
|
160 | { | |
162 | m_layout = layout; |
|
161 | m_layout = layout; | |
163 |
|
162 | |||
164 | for (int i=0; i < m_bars.count(); i++) |
|
163 | for (int i=0; i < m_bars.count(); i++) | |
165 | m_bars.at(i)->setRect(layout.at(i)); |
|
164 | m_bars.at(i)->setRect(layout.at(i)); | |
166 |
|
165 | |||
167 | update(); |
|
166 | update(); | |
168 | } |
|
167 | } | |
169 | //handlers |
|
168 | //handlers | |
170 |
|
169 | |||
171 | void BarChartItem::handleModelChanged() |
|
|||
172 | { |
|
|||
173 | // dataChanged(); |
|
|||
174 | presenter()->resetAllElements(); |
|
|||
175 | } |
|
|||
176 |
|
||||
177 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
170 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
178 | { |
|
171 | { | |
179 | m_domainMinX = minX; |
|
172 | m_domainMinX = minX; | |
180 | m_domainMaxX = maxX; |
|
173 | m_domainMaxX = maxX; | |
181 | m_domainMinY = minY; |
|
174 | m_domainMinY = minY; | |
182 | m_domainMaxY = maxY; |
|
175 | m_domainMaxY = maxY; | |
183 | handleLayoutChanged(); |
|
176 | handleLayoutChanged(); | |
184 | } |
|
177 | } | |
185 |
|
178 | |||
186 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
179 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
187 | { |
|
180 | { | |
188 | prepareGeometryChange(); |
|
181 | prepareGeometryChange(); | |
189 | m_rect = rect; |
|
182 | m_rect = rect; | |
190 | handleLayoutChanged(); |
|
183 | handleLayoutChanged(); | |
191 | } |
|
184 | } | |
192 |
|
185 | |||
193 | void BarChartItem::handleLayoutChanged() |
|
186 | void BarChartItem::handleLayoutChanged() | |
194 | { |
|
187 | { | |
195 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
188 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
196 | // rect size zero. |
|
189 | // rect size zero. | |
197 | return; |
|
190 | return; | |
198 | } |
|
191 | } | |
199 | QVector<QRectF> layout = calculateLayout(); |
|
192 | QVector<QRectF> layout = calculateLayout(); | |
200 | applyLayout(layout); |
|
193 | applyLayout(layout); | |
201 | update(); |
|
194 | update(); | |
202 | } |
|
195 | } | |
203 |
|
196 | |||
204 | void BarChartItem::labelsVisibleChanged(bool visible) |
|
197 | void BarChartItem::labelsVisibleChanged(bool visible) | |
205 | { |
|
198 | { | |
206 | foreach (QGraphicsSimpleTextItem* label, m_labels) { |
|
199 | foreach (QGraphicsSimpleTextItem* label, m_labels) { | |
207 | label->setVisible(visible); |
|
200 | label->setVisible(visible); | |
208 | } |
|
201 | } | |
209 | update(); |
|
202 | update(); | |
210 | } |
|
203 | } | |
211 |
|
204 | |||
212 | #include "moc_barchartitem_p.cpp" |
|
205 | #include "moc_barchartitem_p.cpp" | |
213 |
|
206 | |||
214 | QTCOMMERCIALCHART_END_NAMESPACE |
|
207 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,90 +1,89 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | #ifndef BARCHARTITEM_H |
|
31 | #ifndef BARCHARTITEM_H | |
32 | #define BARCHARTITEM_H |
|
32 | #define BARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "qbarseries.h" |
|
35 | #include "qbarseries.h" | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QBrush> |
|
37 | #include <QBrush> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class Bar; |
|
41 | class Bar; | |
42 | class QAxisCategories; |
|
42 | class QAxisCategories; | |
43 | class QChart; |
|
43 | class QChart; | |
44 |
|
44 | |||
45 | class BarChartItem : public ChartItem |
|
45 | class BarChartItem : public ChartItem | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
49 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
50 | virtual ~BarChartItem(); |
|
50 | virtual ~BarChartItem(); | |
51 |
|
51 | |||
52 | public: |
|
52 | public: | |
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 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
56 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
57 |
|
57 | |||
58 | virtual QVector<QRectF> calculateLayout(); |
|
58 | virtual QVector<QRectF> calculateLayout(); | |
59 | void applyLayout(const QVector<QRectF> &layout); |
|
59 | void applyLayout(const QVector<QRectF> &layout); | |
60 | void setLayout(const QVector<QRectF> &layout); |
|
60 | void setLayout(const QVector<QRectF> &layout); | |
61 | void updateLayout(const QVector<QRectF> &layout); |
|
61 | void updateLayout(const QVector<QRectF> &layout); | |
62 |
|
62 | |||
63 | QRectF geometry() const { return m_rect;} |
|
63 | QRectF geometry() const { return m_rect;} | |
64 |
|
64 | |||
65 | public Q_SLOTS: |
|
65 | public Q_SLOTS: | |
66 | void handleModelChanged(); |
|
|||
67 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
66 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
68 | void handleGeometryChanged(const QRectF &size); |
|
67 | void handleGeometryChanged(const QRectF &size); | |
69 | void handleLayoutChanged(); |
|
68 | void handleLayoutChanged(); | |
70 | void labelsVisibleChanged(bool visible); |
|
69 | void labelsVisibleChanged(bool visible); | |
71 |
|
70 | |||
72 | protected: |
|
71 | protected: | |
73 |
|
72 | |||
74 | qreal m_domainMinX; |
|
73 | qreal m_domainMinX; | |
75 | qreal m_domainMaxX; |
|
74 | qreal m_domainMaxX; | |
76 | qreal m_domainMinY; |
|
75 | qreal m_domainMinY; | |
77 | qreal m_domainMaxY; |
|
76 | qreal m_domainMaxY; | |
78 |
|
77 | |||
79 | QRectF m_rect; |
|
78 | QRectF m_rect; | |
80 | QVector<QRectF> m_layout; |
|
79 | QVector<QRectF> m_layout; | |
81 |
|
80 | |||
82 | // Not owned. |
|
81 | // Not owned. | |
83 | QBarSeries *m_series; |
|
82 | QBarSeries *m_series; | |
84 | QList<Bar *> m_bars; |
|
83 | QList<Bar *> m_bars; | |
85 | QList<QGraphicsSimpleTextItem *> m_labels; |
|
84 | QList<QGraphicsSimpleTextItem *> m_labels; | |
86 | }; |
|
85 | }; | |
87 |
|
86 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
89 |
|
88 | |||
90 | #endif // BARCHARTITEM_H |
|
89 | #endif // BARCHARTITEM_H |
@@ -1,562 +1,545 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QBarSeries |
|
34 | \class QBarSeries | |
35 | \brief part of QtCommercial chart API. |
|
35 | \brief part of QtCommercial chart API. | |
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
41 | shows the x-values. |
|
41 | shows the x-values. | |
42 |
|
42 | |||
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
44 | \image examples_barchart.png |
|
44 | \image examples_barchart.png | |
45 |
|
45 | |||
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \fn void QBarSeries::clicked(QBarSet *barset, int index) |
|
50 | \fn void QBarSeries::clicked(QBarSet *barset, int index) | |
51 |
|
51 | |||
52 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
52 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
53 | Clicked bar inside set is indexed by \a index |
|
53 | Clicked bar inside set is indexed by \a index | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
57 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
58 |
|
58 | |||
59 | The signal is emitted if mouse is hovered on top of series. |
|
59 | The signal is emitted if mouse is hovered on top of series. | |
60 | Parameter \a barset is the pointer of barset, where hover happened. |
|
60 | Parameter \a barset is the pointer of barset, where hover happened. | |
61 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
61 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | Constructs empty QBarSeries. |
|
65 | Constructs empty QBarSeries. | |
66 | QBarSeries is QObject which is a child of a \a parent. |
|
66 | QBarSeries is QObject which is a child of a \a parent. | |
67 | */ |
|
67 | */ | |
68 | QBarSeries::QBarSeries(QObject *parent) : |
|
68 | QBarSeries::QBarSeries(QObject *parent) : | |
69 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
69 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
70 | { |
|
70 | { | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | Destructs barseries and owned barsets. |
|
74 | Destructs barseries and owned barsets. | |
75 | */ |
|
75 | */ | |
76 | QBarSeries::~QBarSeries() |
|
76 | QBarSeries::~QBarSeries() | |
77 | { |
|
77 | { | |
78 | Q_D(QBarSeries); |
|
78 | Q_D(QBarSeries); | |
79 | if(d->m_dataset){ |
|
79 | if(d->m_dataset){ | |
80 | d->m_dataset->removeSeries(this); |
|
80 | d->m_dataset->removeSeries(this); | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \internal |
|
85 | \internal | |
86 | */ |
|
86 | */ | |
87 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
87 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
88 | QAbstractSeries(d,parent) |
|
88 | QAbstractSeries(d,parent) | |
89 | { |
|
89 | { | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | Returns the type of series. Derived classes override this. |
|
93 | Returns the type of series. Derived classes override this. | |
94 | */ |
|
94 | */ | |
95 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
95 | QAbstractSeries::SeriesType QBarSeries::type() const | |
96 | { |
|
96 | { | |
97 | return QAbstractSeries::SeriesTypeBar; |
|
97 | return QAbstractSeries::SeriesTypeBar; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents |
|
101 | Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents | |
102 | percentage of margin compared to bars |
|
102 | percentage of margin compared to bars | |
103 | */ |
|
103 | */ | |
104 | void QBarSeries::setBarMargin(qreal margin) |
|
104 | void QBarSeries::setBarMargin(qreal margin) | |
105 | { |
|
105 | { | |
106 | Q_D(QBarSeries); |
|
106 | Q_D(QBarSeries); | |
107 | d->setBarMargin(margin); |
|
107 | d->setBarMargin(margin); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | Returns the margin around bars |
|
111 | Returns the margin around bars | |
112 | */ |
|
112 | */ | |
113 | qreal QBarSeries::barMargin() const |
|
113 | qreal QBarSeries::barMargin() const | |
114 | { |
|
114 | { | |
115 | Q_D(const QBarSeries); |
|
115 | Q_D(const QBarSeries); | |
116 | return d->barMargin(); |
|
116 | return d->barMargin(); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
120 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
121 | Returns true, if appending succeeded. |
|
121 | Returns true, if appending succeeded. | |
122 |
|
122 | |||
123 | */ |
|
123 | */ | |
124 | bool QBarSeries::append(QBarSet *set) |
|
124 | bool QBarSeries::append(QBarSet *set) | |
125 | { |
|
125 | { | |
126 | Q_D(QBarSeries); |
|
126 | Q_D(QBarSeries); | |
127 | return d->append(set); |
|
127 | return d->append(set); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
131 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
132 | Returns true, if set was removed. |
|
132 | Returns true, if set was removed. | |
133 | */ |
|
133 | */ | |
134 | bool QBarSeries::remove(QBarSet *set) |
|
134 | bool QBarSeries::remove(QBarSet *set) | |
135 | { |
|
135 | { | |
136 | Q_D(QBarSeries); |
|
136 | Q_D(QBarSeries); | |
137 | return d->remove(set); |
|
137 | return d->remove(set); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
141 | Adds a list of barsets to series. Takes ownership of \a sets. | |
142 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
142 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
143 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
143 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
144 | and function returns false. |
|
144 | and function returns false. | |
145 | */ |
|
145 | */ | |
146 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
146 | bool QBarSeries::append(QList<QBarSet* > sets) | |
147 | { |
|
147 | { | |
148 | Q_D(QBarSeries); |
|
148 | Q_D(QBarSeries); | |
149 | return d->append(sets); |
|
149 | return d->append(sets); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
153 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
154 | */ |
|
154 | */ | |
155 | bool QBarSeries::remove(QList<QBarSet* > sets) |
|
155 | bool QBarSeries::remove(QList<QBarSet* > sets) | |
156 | { |
|
156 | { | |
157 | Q_D(QBarSeries); |
|
157 | Q_D(QBarSeries); | |
158 | return d->remove(sets); |
|
158 | return d->remove(sets); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void QBarSeries::clear() |
|
161 | void QBarSeries::clear() | |
162 | { |
|
162 | { | |
163 | Q_D(QBarSeries); |
|
163 | Q_D(QBarSeries); | |
164 | d->m_barSets.clear(); |
|
164 | d->m_barSets.clear(); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | Returns number of sets in series. |
|
168 | Returns number of sets in series. | |
169 | */ |
|
169 | */ | |
170 | int QBarSeries::barsetCount() const |
|
170 | int QBarSeries::barsetCount() const | |
171 | { |
|
171 | { | |
172 | Q_D(const QBarSeries); |
|
172 | Q_D(const QBarSeries); | |
173 | return d->m_barSets.count(); |
|
173 | return d->m_barSets.count(); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Returns a list of sets in series. Keeps ownership of sets. |
|
177 | Returns a list of sets in series. Keeps ownership of sets. | |
178 | */ |
|
178 | */ | |
179 | QList<QBarSet*> QBarSeries::barSets() const |
|
179 | QList<QBarSet*> QBarSeries::barSets() const | |
180 | { |
|
180 | { | |
181 | Q_D(const QBarSeries); |
|
181 | Q_D(const QBarSeries); | |
182 | return d->m_barSets; |
|
182 | return d->m_barSets; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Sets the visibility of series to \a visible |
|
186 | Sets the visibility of series to \a visible | |
187 | */ |
|
187 | */ | |
188 | void QBarSeries::setVisible(bool visible) |
|
188 | void QBarSeries::setVisible(bool visible) | |
189 | { |
|
189 | { | |
190 | Q_D(QBarSeries); |
|
190 | Q_D(QBarSeries); | |
191 | d->setVisible(visible); |
|
191 | d->setVisible(visible); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | Returns the visibility of series |
|
195 | Returns the visibility of series | |
196 | */ |
|
196 | */ | |
197 | bool QBarSeries::isVisible() const |
|
197 | bool QBarSeries::isVisible() const | |
198 | { |
|
198 | { | |
199 | Q_D(const QBarSeries); |
|
199 | Q_D(const QBarSeries); | |
200 | return d->isVisible(); |
|
200 | return d->isVisible(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Sets the visibility of labels in series to \a visible |
|
204 | Sets the visibility of labels in series to \a visible | |
205 | */ |
|
205 | */ | |
206 | void QBarSeries::setLabelsVisible(bool visible) |
|
206 | void QBarSeries::setLabelsVisible(bool visible) | |
207 | { |
|
207 | { | |
208 | Q_D(QBarSeries); |
|
208 | Q_D(QBarSeries); | |
209 | if (d->m_labelsVisible != visible) { |
|
209 | if (d->m_labelsVisible != visible) { | |
210 | d->m_labelsVisible = visible; |
|
210 | d->m_labelsVisible = visible; | |
211 | emit d->labelsVisibleChanged(visible); |
|
211 | emit d->labelsVisibleChanged(visible); | |
212 | } |
|
212 | } | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | Returns the visibility of labels |
|
216 | Returns the visibility of labels | |
217 | */ |
|
217 | */ | |
218 | bool QBarSeries::isLabelsVisible() const |
|
218 | bool QBarSeries::isLabelsVisible() const | |
219 | { |
|
219 | { | |
220 | Q_D(const QBarSeries); |
|
220 | Q_D(const QBarSeries); | |
221 | return d->m_labelsVisible; |
|
221 | return d->m_labelsVisible; | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
224 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
225 |
|
225 | |||
226 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
226 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
227 | QAbstractSeriesPrivate(q), |
|
227 | QAbstractSeriesPrivate(q), | |
228 | m_barMargin(0.5), // Default value is 50% of category width |
|
228 | m_barMargin(0.5), // Default value is 50% of category width | |
229 | m_labelsVisible(false), |
|
229 | m_labelsVisible(false), | |
230 | m_visible(true) |
|
230 | m_visible(true) | |
231 | { |
|
231 | { | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | void QBarSeriesPrivate::setCategories(QStringList categories) |
|
|||
235 | { |
|
|||
236 | m_categories = categories; |
|
|||
237 | } |
|
|||
238 |
|
||||
239 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
|||
240 | { |
|
|||
241 | m_categories.insert(index, category); |
|
|||
242 | emit categoriesUpdated(); |
|
|||
243 | } |
|
|||
244 |
|
||||
245 | void QBarSeriesPrivate::removeCategory(int index) |
|
|||
246 | { |
|
|||
247 | m_categories.removeAt(index); |
|
|||
248 | emit categoriesUpdated(); |
|
|||
249 | } |
|
|||
250 |
|
||||
251 | int QBarSeriesPrivate::categoryCount() const |
|
234 | int QBarSeriesPrivate::categoryCount() const | |
252 | { |
|
235 | { | |
253 | if (m_categories.count() > 0) { |
|
236 | if (m_categories.count() > 0) { | |
254 | return m_categories.count(); |
|
237 | return m_categories.count(); | |
255 | } |
|
238 | } | |
256 |
|
239 | |||
257 | // No categories defined. return count of longest set. |
|
240 | // No categories defined. return count of longest set. | |
258 | int count = 0; |
|
241 | int count = 0; | |
259 | for (int i=0; i<m_barSets.count(); i++) { |
|
242 | for (int i=0; i<m_barSets.count(); i++) { | |
260 | if (m_barSets.at(i)->count() > count) { |
|
243 | if (m_barSets.at(i)->count() > count) { | |
261 | count = m_barSets.at(i)->count(); |
|
244 | count = m_barSets.at(i)->count(); | |
262 | } |
|
245 | } | |
263 | } |
|
246 | } | |
264 |
|
247 | |||
265 | return count; |
|
248 | return count; | |
266 | } |
|
249 | } | |
267 |
|
250 | |||
268 | QStringList QBarSeriesPrivate::categories() const |
|
251 | QStringList QBarSeriesPrivate::categories() const | |
269 | { |
|
252 | { | |
270 | if (m_categories.count() > 0) { |
|
253 | if (m_categories.count() > 0) { | |
271 | return m_categories; |
|
254 | return m_categories; | |
272 | } |
|
255 | } | |
273 |
|
256 | |||
274 | // No categories defined. retun list of indices. |
|
257 | // No categories defined. retun list of indices. | |
275 | QStringList categories; |
|
258 | QStringList categories; | |
276 |
|
259 | |||
277 | int count = categoryCount(); |
|
260 | int count = categoryCount(); | |
278 | for (int i = 0; i < count; i++) { |
|
261 | for (int i = 0; i < count; i++) { | |
279 | categories.append(QString::number(i)); |
|
262 | categories.append(QString::number(i)); | |
280 | } |
|
263 | } | |
281 | return categories; |
|
264 | return categories; | |
282 | } |
|
265 | } | |
283 |
|
266 | |||
284 | void QBarSeriesPrivate::setBarMargin(qreal margin) |
|
267 | void QBarSeriesPrivate::setBarMargin(qreal margin) | |
285 | { |
|
268 | { | |
286 | if (margin > 1.0) { |
|
269 | if (margin > 1.0) { | |
287 | margin = 1.0; |
|
270 | margin = 1.0; | |
288 | } else if (margin < 0.0) { |
|
271 | } else if (margin < 0.0) { | |
289 | margin = 0.0; |
|
272 | margin = 0.0; | |
290 | } |
|
273 | } | |
291 |
|
274 | |||
292 | m_barMargin = margin; |
|
275 | m_barMargin = margin; | |
293 | emit updatedBars(); |
|
276 | emit updatedBars(); | |
294 | } |
|
277 | } | |
295 |
|
278 | |||
296 | qreal QBarSeriesPrivate::barMargin() const |
|
279 | qreal QBarSeriesPrivate::barMargin() const | |
297 | { |
|
280 | { | |
298 | return m_barMargin; |
|
281 | return m_barMargin; | |
299 | } |
|
282 | } | |
300 |
|
283 | |||
301 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
284 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
302 | { |
|
285 | { | |
303 | return m_barSets.at(index); |
|
286 | return m_barSets.at(index); | |
304 | } |
|
287 | } | |
305 |
|
288 | |||
306 | void QBarSeriesPrivate::setVisible(bool visible) |
|
289 | void QBarSeriesPrivate::setVisible(bool visible) | |
307 | { |
|
290 | { | |
308 | if (m_visible != visible) { |
|
291 | if (m_visible != visible) { | |
309 | m_visible = visible; |
|
292 | m_visible = visible; | |
310 | emit updatedBars(); |
|
293 | emit updatedBars(); | |
311 | } |
|
294 | } | |
312 | } |
|
295 | } | |
313 |
|
296 | |||
314 | bool QBarSeriesPrivate::isVisible() const |
|
297 | bool QBarSeriesPrivate::isVisible() const | |
315 | { |
|
298 | { | |
316 | return m_visible; |
|
299 | return m_visible; | |
317 | } |
|
300 | } | |
318 |
|
301 | |||
319 | QString QBarSeriesPrivate::categoryName(int category) |
|
302 | QString QBarSeriesPrivate::categoryName(int category) | |
320 | { |
|
303 | { | |
321 | if ((category >= 0) && (category < m_categories.count())) { |
|
304 | if ((category >= 0) && (category < m_categories.count())) { | |
322 | return m_categories.at(category); |
|
305 | return m_categories.at(category); | |
323 | } |
|
306 | } | |
324 |
|
307 | |||
325 | return QString::number(category); |
|
308 | return QString::number(category); | |
326 | } |
|
309 | } | |
327 |
|
310 | |||
328 | qreal QBarSeriesPrivate::min() |
|
311 | qreal QBarSeriesPrivate::min() | |
329 | { |
|
312 | { | |
330 | if (m_barSets.count() <= 0) { |
|
313 | if (m_barSets.count() <= 0) { | |
331 | return 0; |
|
314 | return 0; | |
332 | } |
|
315 | } | |
333 | qreal min = INT_MAX; |
|
316 | qreal min = INT_MAX; | |
334 |
|
317 | |||
335 | for (int i = 0; i < m_barSets.count(); i++) { |
|
318 | for (int i = 0; i < m_barSets.count(); i++) { | |
336 | int categoryCount = m_barSets.at(i)->count(); |
|
319 | int categoryCount = m_barSets.at(i)->count(); | |
337 | for (int j = 0; j < categoryCount; j++) { |
|
320 | for (int j = 0; j < categoryCount; j++) { | |
338 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
321 | qreal temp = m_barSets.at(i)->at(j).y(); | |
339 | if (temp < min) |
|
322 | if (temp < min) | |
340 | min = temp; |
|
323 | min = temp; | |
341 | } |
|
324 | } | |
342 | } |
|
325 | } | |
343 | return min; |
|
326 | return min; | |
344 | } |
|
327 | } | |
345 |
|
328 | |||
346 | qreal QBarSeriesPrivate::max() |
|
329 | qreal QBarSeriesPrivate::max() | |
347 | { |
|
330 | { | |
348 | if (m_barSets.count() <= 0) { |
|
331 | if (m_barSets.count() <= 0) { | |
349 | return 0; |
|
332 | return 0; | |
350 | } |
|
333 | } | |
351 | qreal max = INT_MIN; |
|
334 | qreal max = INT_MIN; | |
352 |
|
335 | |||
353 | for (int i = 0; i < m_barSets.count(); i++) { |
|
336 | for (int i = 0; i < m_barSets.count(); i++) { | |
354 | int categoryCount = m_barSets.at(i)->count(); |
|
337 | int categoryCount = m_barSets.at(i)->count(); | |
355 | for (int j = 0; j < categoryCount; j++) { |
|
338 | for (int j = 0; j < categoryCount; j++) { | |
356 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
339 | qreal temp = m_barSets.at(i)->at(j).y(); | |
357 | if (temp > max) |
|
340 | if (temp > max) | |
358 | max = temp; |
|
341 | max = temp; | |
359 | } |
|
342 | } | |
360 | } |
|
343 | } | |
361 |
|
344 | |||
362 | return max; |
|
345 | return max; | |
363 | } |
|
346 | } | |
364 |
|
347 | |||
365 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
348 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
366 | { |
|
349 | { | |
367 | if ((set < 0) || (set >= m_barSets.count())) { |
|
350 | if ((set < 0) || (set >= m_barSets.count())) { | |
368 | // No set, no value. |
|
351 | // No set, no value. | |
369 | return 0; |
|
352 | return 0; | |
370 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
353 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
371 | // No category, no value. |
|
354 | // No category, no value. | |
372 | return 0; |
|
355 | return 0; | |
373 | } |
|
356 | } | |
374 |
|
357 | |||
375 | return m_barSets.at(set)->at(category).y(); |
|
358 | return m_barSets.at(set)->at(category).y(); | |
376 | } |
|
359 | } | |
377 |
|
360 | |||
378 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
361 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
379 | { |
|
362 | { | |
380 | if ((set < 0) || (set >= m_barSets.count())) { |
|
363 | if ((set < 0) || (set >= m_barSets.count())) { | |
381 | // No set, no value. |
|
364 | // No set, no value. | |
382 | return 0; |
|
365 | return 0; | |
383 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
366 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
384 | // No category, no value. |
|
367 | // No category, no value. | |
385 | return 0; |
|
368 | return 0; | |
386 | } |
|
369 | } | |
387 |
|
370 | |||
388 | qreal value = m_barSets.at(set)->at(category).y(); |
|
371 | qreal value = m_barSets.at(set)->at(category).y(); | |
389 | qreal sum = categorySum(category); |
|
372 | qreal sum = categorySum(category); | |
390 | if ( qFuzzyIsNull(sum) ) { |
|
373 | if ( qFuzzyIsNull(sum) ) { | |
391 | return 0; |
|
374 | return 0; | |
392 | } |
|
375 | } | |
393 |
|
376 | |||
394 | return value / sum; |
|
377 | return value / sum; | |
395 | } |
|
378 | } | |
396 |
|
379 | |||
397 | qreal QBarSeriesPrivate::categorySum(int category) |
|
380 | qreal QBarSeriesPrivate::categorySum(int category) | |
398 | { |
|
381 | { | |
399 | qreal sum(0); |
|
382 | qreal sum(0); | |
400 | int count = m_barSets.count(); // Count sets |
|
383 | int count = m_barSets.count(); // Count sets | |
401 | for (int set = 0; set < count; set++) { |
|
384 | for (int set = 0; set < count; set++) { | |
402 | if (category < m_barSets.at(set)->count()) |
|
385 | if (category < m_barSets.at(set)->count()) | |
403 | sum += m_barSets.at(set)->at(category).y(); |
|
386 | sum += m_barSets.at(set)->at(category).y(); | |
404 | } |
|
387 | } | |
405 | return sum; |
|
388 | return sum; | |
406 | } |
|
389 | } | |
407 |
|
390 | |||
408 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
391 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
409 | { |
|
392 | { | |
410 | qreal sum(0); |
|
393 | qreal sum(0); | |
411 | int count = m_barSets.count(); // Count sets |
|
394 | int count = m_barSets.count(); // Count sets | |
412 | for (int set = 0; set < count; set++) { |
|
395 | for (int set = 0; set < count; set++) { | |
413 | if (category < m_barSets.at(set)->count()) |
|
396 | if (category < m_barSets.at(set)->count()) | |
414 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
397 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
415 | } |
|
398 | } | |
416 | return sum; |
|
399 | return sum; | |
417 | } |
|
400 | } | |
418 |
|
401 | |||
419 | qreal QBarSeriesPrivate::maxCategorySum() |
|
402 | qreal QBarSeriesPrivate::maxCategorySum() | |
420 | { |
|
403 | { | |
421 | qreal max = INT_MIN; |
|
404 | qreal max = INT_MIN; | |
422 | int count = categoryCount(); |
|
405 | int count = categoryCount(); | |
423 | for (int i = 0; i < count; i++) { |
|
406 | for (int i = 0; i < count; i++) { | |
424 | qreal sum = categorySum(i); |
|
407 | qreal sum = categorySum(i); | |
425 | if (sum > max) |
|
408 | if (sum > max) | |
426 | max = sum; |
|
409 | max = sum; | |
427 | } |
|
410 | } | |
428 | return max; |
|
411 | return max; | |
429 | } |
|
412 | } | |
430 |
|
413 | |||
431 | void QBarSeriesPrivate::barsetChanged() |
|
414 | void QBarSeriesPrivate::barsetChanged() | |
432 | { |
|
415 | { | |
433 | emit updatedBars(); |
|
416 | emit updatedBars(); | |
434 | } |
|
417 | } | |
435 |
|
418 | |||
436 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
419 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
437 | { |
|
420 | { | |
438 | qreal minX(domain.minX()); |
|
421 | qreal minX(domain.minX()); | |
439 | qreal minY(domain.minY()); |
|
422 | qreal minY(domain.minY()); | |
440 | qreal maxX(domain.maxX()); |
|
423 | qreal maxX(domain.maxX()); | |
441 | qreal maxY(domain.maxY()); |
|
424 | qreal maxY(domain.maxY()); | |
442 | int tickXCount(domain.tickXCount()); |
|
425 | int tickXCount(domain.tickXCount()); | |
443 | int tickYCount(domain.tickYCount()); |
|
426 | int tickYCount(domain.tickYCount()); | |
444 |
|
427 | |||
445 | qreal x = categoryCount(); |
|
428 | qreal x = categoryCount(); | |
446 | qreal y = max(); |
|
429 | qreal y = max(); | |
447 | minX = qMin(minX, x) - 0.5; |
|
430 | minX = qMin(minX, x) - 0.5; | |
448 | minY = qMin(minY, y); |
|
431 | minY = qMin(minY, y); | |
449 | maxX = qMax(maxX, x) - 0.5; |
|
432 | maxX = qMax(maxX, x) - 0.5; | |
450 | maxY = qMax(maxY, y); |
|
433 | maxY = qMax(maxY, y); | |
451 | tickXCount = x+1; |
|
434 | tickXCount = x+1; | |
452 |
|
435 | |||
453 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
436 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
454 | } |
|
437 | } | |
455 |
|
438 | |||
456 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
439 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
457 | { |
|
440 | { | |
458 | Q_Q(QBarSeries); |
|
441 | Q_Q(QBarSeries); | |
459 |
|
442 | |||
460 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
443 | BarChartItem* bar = new BarChartItem(q,presenter); | |
461 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
444 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
462 | presenter->animator()->addAnimation(bar); |
|
445 | presenter->animator()->addAnimation(bar); | |
463 | } |
|
446 | } | |
464 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
447 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
465 | return bar; |
|
448 | return bar; | |
466 |
|
449 | |||
467 | } |
|
450 | } | |
468 |
|
451 | |||
469 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
452 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
470 | { |
|
453 | { | |
471 | Q_Q(QBarSeries); |
|
454 | Q_Q(QBarSeries); | |
472 | QList<LegendMarker*> markers; |
|
455 | QList<LegendMarker*> markers; | |
473 | foreach(QBarSet* set, q->barSets()) { |
|
456 | foreach(QBarSet* set, q->barSets()) { | |
474 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
457 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
475 | markers << marker; |
|
458 | markers << marker; | |
476 | } |
|
459 | } | |
477 |
|
460 | |||
478 | return markers; |
|
461 | return markers; | |
479 | } |
|
462 | } | |
480 |
|
463 | |||
481 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
464 | bool QBarSeriesPrivate::append(QBarSet *set) | |
482 | { |
|
465 | { | |
483 | Q_Q(QBarSeries); |
|
466 | Q_Q(QBarSeries); | |
484 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
467 | if ((m_barSets.contains(set)) || (set == 0)) { | |
485 | // Fail if set is already in list or set is null. |
|
468 | // Fail if set is already in list or set is null. | |
486 | return false; |
|
469 | return false; | |
487 | } |
|
470 | } | |
488 | m_barSets.append(set); |
|
471 | m_barSets.append(set); | |
489 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
472 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
490 | if (m_dataset) { |
|
473 | if (m_dataset) { | |
491 | m_dataset->updateSeries(q); // this notifies legend |
|
474 | m_dataset->updateSeries(q); // this notifies legend | |
492 | } |
|
475 | } | |
493 | emit restructuredBars(); // this notifies barchartitem |
|
476 | // emit restructuredBars(); // this notifies barchartitem | |
494 | return true; |
|
477 | return true; | |
495 | } |
|
478 | } | |
496 |
|
479 | |||
497 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
480 | bool QBarSeriesPrivate::remove(QBarSet *set) | |
498 | { |
|
481 | { | |
499 | Q_Q(QBarSeries); |
|
482 | Q_Q(QBarSeries); | |
500 | if (!m_barSets.contains(set)) { |
|
483 | if (!m_barSets.contains(set)) { | |
501 | // Fail if set is not in list |
|
484 | // Fail if set is not in list | |
502 | return false; |
|
485 | return false; | |
503 | } |
|
486 | } | |
504 | m_barSets.removeOne(set); |
|
487 | m_barSets.removeOne(set); | |
505 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
488 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
506 | if (m_dataset) { |
|
489 | if (m_dataset) { | |
507 | m_dataset->updateSeries(q); // this notifies legend |
|
490 | m_dataset->updateSeries(q); // this notifies legend | |
508 | } |
|
491 | } | |
509 | emit restructuredBars(); // this notifies barchartitem |
|
492 | // emit restructuredBars(); // this notifies barchartitem | |
510 | return true; |
|
493 | return true; | |
511 | } |
|
494 | } | |
512 |
|
495 | |||
513 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
496 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) | |
514 | { |
|
497 | { | |
515 | Q_Q(QBarSeries); |
|
498 | Q_Q(QBarSeries); | |
516 | foreach (QBarSet* set, sets) { |
|
499 | foreach (QBarSet* set, sets) { | |
517 | if ((set == 0) || (m_barSets.contains(set))) { |
|
500 | if ((set == 0) || (m_barSets.contains(set))) { | |
518 | // Fail if any of the sets is null or is already appended. |
|
501 | // Fail if any of the sets is null or is already appended. | |
519 | return false; |
|
502 | return false; | |
520 | } |
|
503 | } | |
521 | if (sets.count(set) != 1) { |
|
504 | if (sets.count(set) != 1) { | |
522 | // Also fail if same set is more than once in given list. |
|
505 | // Also fail if same set is more than once in given list. | |
523 | return false; |
|
506 | return false; | |
524 | } |
|
507 | } | |
525 | } |
|
508 | } | |
526 |
|
509 | |||
527 | foreach (QBarSet* set, sets) { |
|
510 | foreach (QBarSet* set, sets) { | |
528 | m_barSets.append(set); |
|
511 | m_barSets.append(set); | |
529 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
512 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
530 | } |
|
513 | } | |
531 | if (m_dataset) { |
|
514 | if (m_dataset) { | |
532 | m_dataset->updateSeries(q); // this notifies legend |
|
515 | m_dataset->updateSeries(q); // this notifies legend | |
533 | } |
|
516 | } | |
534 | emit restructuredBars(); // this notifies barchartitem |
|
517 | // emit restructuredBars(); // this notifies barchartitem | |
535 | return true; |
|
518 | return true; | |
536 | } |
|
519 | } | |
537 |
|
520 | |||
538 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
521 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
539 | { |
|
522 | { | |
540 | Q_Q(QBarSeries); |
|
523 | Q_Q(QBarSeries); | |
541 | bool setsRemoved = false; |
|
524 | bool setsRemoved = false; | |
542 | foreach (QBarSet* set, sets) { |
|
525 | foreach (QBarSet* set, sets) { | |
543 | if (m_barSets.contains(set)) { |
|
526 | if (m_barSets.contains(set)) { | |
544 | m_barSets.removeOne(set); |
|
527 | m_barSets.removeOne(set); | |
545 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
528 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
546 | setsRemoved = true; |
|
529 | setsRemoved = true; | |
547 | } |
|
530 | } | |
548 | } |
|
531 | } | |
549 |
|
532 | |||
550 | if (setsRemoved) { |
|
533 | if (setsRemoved) { | |
551 | if (m_dataset) { |
|
534 | if (m_dataset) { | |
552 | m_dataset->updateSeries(q); // this notifies legend |
|
535 | m_dataset->updateSeries(q); // this notifies legend | |
553 | } |
|
536 | } | |
554 | emit restructuredBars(); // this notifies barchartitem |
|
537 | // emit restructuredBars(); // this notifies barchartitem | |
555 | } |
|
538 | } | |
556 | return setsRemoved; |
|
539 | return setsRemoved; | |
557 | } |
|
540 | } | |
558 |
|
541 | |||
559 | #include "moc_qbarseries.cpp" |
|
542 | #include "moc_qbarseries.cpp" | |
560 | #include "moc_qbarseries_p.cpp" |
|
543 | #include "moc_qbarseries_p.cpp" | |
561 |
|
544 | |||
562 | QTCOMMERCIALCHART_END_NAMESPACE |
|
545 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,102 +1,99 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QBARSERIES_P_H |
|
30 | #ifndef QBARSERIES_P_H | |
31 | #define QBARSERIES_P_H |
|
31 | #define QBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries.h" |
|
33 | #include "qbarseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 | #include <QStringList> |
|
35 | #include <QStringList> | |
36 | #include <QAbstractSeries> |
|
36 | #include <QAbstractSeries> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class QBarModelMapper; |
|
40 | class QBarModelMapper; | |
41 |
|
41 | |||
42 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
42 | class QBarSeriesPrivate : public QAbstractSeriesPrivate | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | QBarSeriesPrivate(QBarSeries *parent); |
|
46 | QBarSeriesPrivate(QBarSeries *parent); | |
47 | // TODO: refactor/remove private category stuff |
|
47 | // TODO: refactor/remove private category stuff | |
48 | void setCategories(QStringList categories); |
|
|||
49 | void insertCategory(int index, const QString category); |
|
|||
50 | void removeCategory(int index); |
|
|||
51 | int categoryCount() const; |
|
48 | int categoryCount() const; | |
52 | QStringList categories() const; |
|
49 | QStringList categories() const; | |
53 |
|
50 | |||
54 | void setBarMargin(qreal margin); |
|
51 | void setBarMargin(qreal margin); | |
55 | qreal barMargin() const; |
|
52 | qreal barMargin() const; | |
56 |
|
53 | |||
57 | void setVisible(bool visible); |
|
54 | void setVisible(bool visible); | |
58 | bool isVisible() const; |
|
55 | bool isVisible() const; | |
59 |
|
56 | |||
60 | void scaleDomain(Domain& domain); |
|
57 | void scaleDomain(Domain& domain); | |
61 | Chart* createGraphics(ChartPresenter* presenter); |
|
58 | Chart* createGraphics(ChartPresenter* presenter); | |
62 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
59 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
63 |
|
60 | |||
64 | bool append(QBarSet *set); |
|
61 | bool append(QBarSet *set); | |
65 | bool remove(QBarSet *set); |
|
62 | bool remove(QBarSet *set); | |
66 | bool append(QList<QBarSet* > sets); |
|
63 | bool append(QList<QBarSet* > sets); | |
67 | bool remove(QList<QBarSet* > sets); |
|
64 | bool remove(QList<QBarSet* > sets); | |
68 |
|
65 | |||
69 | QBarSet* barsetAt(int index); |
|
66 | QBarSet* barsetAt(int index); | |
70 | QString categoryName(int category); |
|
67 | QString categoryName(int category); | |
71 | qreal min(); |
|
68 | qreal min(); | |
72 | qreal max(); |
|
69 | qreal max(); | |
73 | qreal valueAt(int set, int category); |
|
70 | qreal valueAt(int set, int category); | |
74 | qreal percentageAt(int set, int category); |
|
71 | qreal percentageAt(int set, int category); | |
75 | qreal categorySum(int category); |
|
72 | qreal categorySum(int category); | |
76 | qreal absoluteCategorySum(int category); |
|
73 | qreal absoluteCategorySum(int category); | |
77 | qreal maxCategorySum(); |
|
74 | qreal maxCategorySum(); | |
78 |
|
75 | |||
79 | Q_SIGNALS: |
|
76 | Q_SIGNALS: | |
80 | void clicked(QBarSet *barset, int index); |
|
77 | void clicked(QBarSet *barset, int index); | |
81 | void updatedBars(); |
|
78 | void updatedBars(); | |
82 | void restructuredBars(); |
|
79 | // void restructuredBars(); | |
83 | void categoriesUpdated(); |
|
80 | // void categoriesUpdated(); | |
84 | void labelsVisibleChanged(bool visible); |
|
81 | void labelsVisibleChanged(bool visible); | |
85 |
|
82 | |||
86 | private Q_SLOTS: |
|
83 | private Q_SLOTS: | |
87 | void barsetChanged(); |
|
84 | void barsetChanged(); | |
88 |
|
85 | |||
89 | protected: |
|
86 | protected: | |
90 | QList<QBarSet *> m_barSets; |
|
87 | QList<QBarSet *> m_barSets; | |
91 | QStringList m_categories; |
|
88 | QStringList m_categories; | |
92 | qreal m_barMargin; |
|
89 | qreal m_barMargin; | |
93 | bool m_labelsVisible; |
|
90 | bool m_labelsVisible; | |
94 | bool m_visible; |
|
91 | bool m_visible; | |
95 |
|
92 | |||
96 | private: |
|
93 | private: | |
97 | Q_DECLARE_PUBLIC(QBarSeries) |
|
94 | Q_DECLARE_PUBLIC(QBarSeries) | |
98 | }; |
|
95 | }; | |
99 |
|
96 | |||
100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
101 |
|
98 | |||
102 | #endif // QBARSERIESPRIVATE_P_H |
|
99 | #endif // QBARSERIESPRIVATE_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now