@@ -1,612 +1,612 | |||||
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 "qbarmodelmapper.h" |
|
21 | #include "qbarmodelmapper.h" | |
22 | #include "qbarmodelmapper_p.h" |
|
22 | #include "qbarmodelmapper_p.h" | |
23 | #include "qbarseries.h" |
|
23 | #include "qbarseries.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include <QAbstractItemModel> |
|
26 | #include <QAbstractItemModel> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QBarModelMapper |
|
31 | \class QBarModelMapper | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief Model mapper for bar series | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
35 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
36 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. |
|
36 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. | |
37 | This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
37 | This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
38 | Model mapper maintains equal size of all the BarSets. |
|
38 | Model mapper maintains equal size of all the BarSets. | |
39 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
39 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
40 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
40 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \property QBarModelMapper::series |
|
44 | \property QBarModelMapper::series | |
45 | \brief Defines the QPieSeries object that is used by the mapper. |
|
45 | \brief Defines the QPieSeries object that is used by the mapper. | |
46 | All the data in the series is discarded when it is set to the mapper. |
|
46 | All the data in the series is discarded when it is set to the mapper. | |
47 | When new series is specified the old series is disconnected (it preserves its data) |
|
47 | When new series is specified the old series is disconnected (it preserves its data) | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \property QBarModelMapper::model |
|
51 | \property QBarModelMapper::model | |
52 | \brief Defines the model that is used by the mapper. |
|
52 | \brief Defines the model that is used by the mapper. | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \fn void QBarModelMapper::seriesReplaced() |
|
56 | \fn void QBarModelMapper::seriesReplaced() | |
57 | Emitted when the series to which mapper is connected to has changed. |
|
57 | Emitted when the series to which mapper is connected to has changed. | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \fn void QBarModelMapper::modelReplaced() |
|
61 | \fn void QBarModelMapper::modelReplaced() | |
62 | Emitted when the model to which mapper is connected to has changed. |
|
62 | Emitted when the model to which mapper is connected to has changed. | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | Constructs a mapper object which is a child of \a parent. |
|
66 | Constructs a mapper object which is a child of \a parent. | |
67 | */ |
|
67 | */ | |
68 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
68 | QBarModelMapper::QBarModelMapper(QObject *parent) : | |
69 | QObject(parent), |
|
69 | QObject(parent), | |
70 | d_ptr(new QBarModelMapperPrivate(this)) |
|
70 | d_ptr(new QBarModelMapperPrivate(this)) | |
71 | { |
|
71 | { | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | QAbstractItemModel* QBarModelMapper::model() const |
|
74 | QAbstractItemModel* QBarModelMapper::model() const | |
75 | { |
|
75 | { | |
76 | Q_D(const QBarModelMapper); |
|
76 | Q_D(const QBarModelMapper); | |
77 | return d->m_model; |
|
77 | return d->m_model; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
80 | void QBarModelMapper::setModel(QAbstractItemModel *model) | |
81 | { |
|
81 | { | |
82 | if (model == 0) |
|
82 | if (model == 0) | |
83 | return; |
|
83 | return; | |
84 |
|
84 | |||
85 | Q_D(QBarModelMapper); |
|
85 | Q_D(QBarModelMapper); | |
86 | if (d->m_model) { |
|
86 | if (d->m_model) { | |
87 | disconnect(d->m_model, 0, d, 0); |
|
87 | disconnect(d->m_model, 0, d, 0); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | d->m_model = model; |
|
90 | d->m_model = model; | |
91 | d->initializeBarFromModel(); |
|
91 | d->initializeBarFromModel(); | |
92 | // connect signals from the model |
|
92 | // connect signals from the model | |
93 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
93 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
94 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); |
|
94 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); | |
95 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
95 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
96 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
96 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
97 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
97 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
98 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
98 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
99 |
|
99 | |||
100 | emit modelReplaced(); |
|
100 | emit modelReplaced(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | QBarSeries* QBarModelMapper::series() const |
|
103 | QBarSeries* QBarModelMapper::series() const | |
104 | { |
|
104 | { | |
105 | Q_D(const QBarModelMapper); |
|
105 | Q_D(const QBarModelMapper); | |
106 | return d->m_series; |
|
106 | return d->m_series; | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void QBarModelMapper::setSeries(QBarSeries *series) |
|
109 | void QBarModelMapper::setSeries(QBarSeries *series) | |
110 | { |
|
110 | { | |
111 | Q_D(QBarModelMapper); |
|
111 | Q_D(QBarModelMapper); | |
112 | if (d->m_series) { |
|
112 | if (d->m_series) { | |
113 | disconnect(d->m_series, 0, d, 0); |
|
113 | disconnect(d->m_series, 0, d, 0); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | if (series == 0) |
|
116 | if (series == 0) | |
117 | return; |
|
117 | return; | |
118 |
|
118 | |||
119 | d->m_series = series; |
|
119 | d->m_series = series; | |
120 | d->initializeBarFromModel(); |
|
120 | d->initializeBarFromModel(); | |
121 | // connect the signals from the series |
|
121 | // connect the signals from the series | |
122 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); |
|
122 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); | |
123 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); |
|
123 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); | |
124 |
|
124 | |||
125 | emit seriesReplaced(); |
|
125 | emit seriesReplaced(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Returns which row/column of the model contains the first values of the QBarSets in the series. |
|
129 | Returns which row/column of the model contains the first values of the QBarSets in the series. | |
130 | The default value is 0. |
|
130 | The default value is 0. | |
131 | */ |
|
131 | */ | |
132 | int QBarModelMapper::first() const |
|
132 | int QBarModelMapper::first() const | |
133 | { |
|
133 | { | |
134 | Q_D(const QBarModelMapper); |
|
134 | Q_D(const QBarModelMapper); | |
135 | return d->m_first; |
|
135 | return d->m_first; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Sets which row of the model contains the \a first values of the QBarSets in the series. |
|
139 | Sets which row of the model contains the \a first values of the QBarSets in the series. | |
140 | The default value is 0. |
|
140 | The default value is 0. | |
141 | */ |
|
141 | */ | |
142 | void QBarModelMapper::setFirst(int first) |
|
142 | void QBarModelMapper::setFirst(int first) | |
143 | { |
|
143 | { | |
144 | Q_D(QBarModelMapper); |
|
144 | Q_D(QBarModelMapper); | |
145 | d->m_first = qMax(first, 0); |
|
145 | d->m_first = qMax(first, 0); | |
146 | d->initializeBarFromModel(); |
|
146 | d->initializeBarFromModel(); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Returns the number of rows/columns of the model that are mapped as the data for QBarSeries |
|
150 | Returns the number of rows/columns of the model that are mapped as the data for QBarSeries | |
151 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
151 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
152 | */ |
|
152 | */ | |
153 | int QBarModelMapper::count() const |
|
153 | int QBarModelMapper::count() const | |
154 | { |
|
154 | { | |
155 | Q_D(const QBarModelMapper); |
|
155 | Q_D(const QBarModelMapper); | |
156 | return d->m_count; |
|
156 | return d->m_count; | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Sets the \a count of rows/columns of the model that are mapped as the data for QBarSeries |
|
160 | Sets the \a count of rows/columns of the model that are mapped as the data for QBarSeries | |
161 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
161 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
162 | */ |
|
162 | */ | |
163 | void QBarModelMapper::setCount(int count) |
|
163 | void QBarModelMapper::setCount(int count) | |
164 | { |
|
164 | { | |
165 | Q_D(QBarModelMapper); |
|
165 | Q_D(QBarModelMapper); | |
166 | d->m_count = qMax(count, -1); |
|
166 | d->m_count = qMax(count, -1); | |
167 | d->initializeBarFromModel(); |
|
167 | d->initializeBarFromModel(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
171 | Returns the orientation that is used when QBarModelMapper accesses the model. | |
172 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
172 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) | |
173 | or from columns (Qt::Vertical) |
|
173 | or from columns (Qt::Vertical) | |
174 | */ |
|
174 | */ | |
175 | Qt::Orientation QBarModelMapper::orientation() const |
|
175 | Qt::Orientation QBarModelMapper::orientation() const | |
176 | { |
|
176 | { | |
177 | Q_D(const QBarModelMapper); |
|
177 | Q_D(const QBarModelMapper); | |
178 | return d->m_orientation; |
|
178 | return d->m_orientation; | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
182 | Returns the \a orientation that is used when QBarModelMapper accesses the model. | |
183 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
183 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) | |
184 | or from columns (Qt::Vertical) |
|
184 | or from columns (Qt::Vertical) | |
185 | */ |
|
185 | */ | |
186 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
186 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) | |
187 | { |
|
187 | { | |
188 | Q_D(QBarModelMapper); |
|
188 | Q_D(QBarModelMapper); | |
189 | d->m_orientation = orientation; |
|
189 | d->m_orientation = orientation; | |
190 | d->initializeBarFromModel(); |
|
190 | d->initializeBarFromModel(); | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | Returns which section of the model is used as the data source for the first bar set |
|
194 | Returns which section of the model is used as the data source for the first bar set | |
195 | */ |
|
195 | */ | |
196 | int QBarModelMapper::firstBarSetSection() const |
|
196 | int QBarModelMapper::firstBarSetSection() const | |
197 | { |
|
197 | { | |
198 | Q_D(const QBarModelMapper); |
|
198 | Q_D(const QBarModelMapper); | |
199 | return d->m_firstBarSetSection; |
|
199 | return d->m_firstBarSetSection; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | Sets the model section that is used as the data source for the first bar set |
|
203 | Sets the model section that is used as the data source for the first bar set | |
204 | Parameter \a firstBarSetSection specifies the section of the model. |
|
204 | Parameter \a firstBarSetSection specifies the section of the model. | |
205 | */ |
|
205 | */ | |
206 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
206 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) | |
207 | { |
|
207 | { | |
208 | Q_D(QBarModelMapper); |
|
208 | Q_D(QBarModelMapper); | |
209 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); |
|
209 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); | |
210 | d->initializeBarFromModel(); |
|
210 | d->initializeBarFromModel(); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | /*! |
|
213 | /*! | |
214 | Returns which section of the model is used as the data source for the last bar set |
|
214 | Returns which section of the model is used as the data source for the last bar set | |
215 | */ |
|
215 | */ | |
216 | int QBarModelMapper::lastBarSetSection() const |
|
216 | int QBarModelMapper::lastBarSetSection() const | |
217 | { |
|
217 | { | |
218 | Q_D(const QBarModelMapper); |
|
218 | Q_D(const QBarModelMapper); | |
219 | return d->m_lastBarSetSection; |
|
219 | return d->m_lastBarSetSection; | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Sets the model section that is used as the data source for the last bar set |
|
223 | Sets the model section that is used as the data source for the last bar set | |
224 | Parameter \a lastBarSetSection specifies the section of the model. |
|
224 | Parameter \a lastBarSetSection specifies the section of the model. | |
225 | */ |
|
225 | */ | |
226 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
226 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |
227 | { |
|
227 | { | |
228 | Q_D(QBarModelMapper); |
|
228 | Q_D(QBarModelMapper); | |
229 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); |
|
229 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); | |
230 | d->initializeBarFromModel(); |
|
230 | d->initializeBarFromModel(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | Resets the QBarModelMapper to the default state. |
|
234 | Resets the QBarModelMapper to the default state. | |
235 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 |
|
235 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 | |
236 | */ |
|
236 | */ | |
237 | void QBarModelMapper::reset() |
|
237 | void QBarModelMapper::reset() | |
238 | { |
|
238 | { | |
239 | Q_D(QBarModelMapper); |
|
239 | Q_D(QBarModelMapper); | |
240 | d->m_first = 0; |
|
240 | d->m_first = 0; | |
241 | d->m_count = -1; |
|
241 | d->m_count = -1; | |
242 | d->m_firstBarSetSection = -1; |
|
242 | d->m_firstBarSetSection = -1; | |
243 | d->m_lastBarSetSection = -1; |
|
243 | d->m_lastBarSetSection = -1; | |
244 | d->initializeBarFromModel(); |
|
244 | d->initializeBarFromModel(); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
247 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
248 |
|
248 | |||
249 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
249 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
250 | m_series(0), |
|
250 | m_series(0), | |
251 | m_model(0), |
|
251 | m_model(0), | |
252 | m_first(0), |
|
252 | m_first(0), | |
253 | m_count(-1), |
|
253 | m_count(-1), | |
254 | m_orientation(Qt::Vertical), |
|
254 | m_orientation(Qt::Vertical), | |
255 | m_firstBarSetSection(-1), |
|
255 | m_firstBarSetSection(-1), | |
256 | m_lastBarSetSection(-1), |
|
256 | m_lastBarSetSection(-1), | |
257 | m_seriesSignalsBlock(false), |
|
257 | m_seriesSignalsBlock(false), | |
258 | m_modelSignalsBlock(false), |
|
258 | m_modelSignalsBlock(false), | |
259 | q_ptr(q) |
|
259 | q_ptr(q) | |
260 | { |
|
260 | { | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
263 | void QBarModelMapperPrivate::blockModelSignals(bool block) | |
264 | { |
|
264 | { | |
265 | m_modelSignalsBlock = block; |
|
265 | m_modelSignalsBlock = block; | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
268 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |
269 | { |
|
269 | { | |
270 | m_seriesSignalsBlock = block; |
|
270 | m_seriesSignalsBlock = block; | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
273 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
274 | { |
|
274 | { | |
275 | if (!index.isValid()) |
|
275 | if (!index.isValid()) | |
276 | return 0; |
|
276 | return 0; | |
277 |
|
277 | |||
278 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
278 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { | |
279 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
279 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
280 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
280 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
281 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
281 | return m_series->barSets().at(index.column() - m_firstBarSetSection); | |
282 | // else |
|
282 | // else | |
283 | // return 0; |
|
283 | // return 0; | |
284 | } |
|
284 | } | |
285 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
285 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { | |
286 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
286 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
287 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
287 | return m_series->barSets().at(index.row() - m_firstBarSetSection); | |
288 | } |
|
288 | } | |
289 | return 0; // This part of model has not been mapped to any slice |
|
289 | return 0; // This part of model has not been mapped to any slice | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
292 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) | |
293 | { |
|
293 | { | |
294 | if (m_count != -1 && posInBar >= m_count) |
|
294 | if (m_count != -1 && posInBar >= m_count) | |
295 | return QModelIndex(); // invalid |
|
295 | return QModelIndex(); // invalid | |
296 |
|
296 | |||
297 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
297 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) | |
298 | return QModelIndex(); // invalid |
|
298 | return QModelIndex(); // invalid | |
299 |
|
299 | |||
300 | if (m_orientation == Qt::Vertical) |
|
300 | if (m_orientation == Qt::Vertical) | |
301 | return m_model->index(posInBar + m_first, barSection); |
|
301 | return m_model->index(posInBar + m_first, barSection); | |
302 | else |
|
302 | else | |
303 | return m_model->index(barSection, posInBar + m_first); |
|
303 | return m_model->index(barSection, posInBar + m_first); | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
306 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
307 | { |
|
307 | { | |
308 | Q_UNUSED(topLeft) |
|
308 | Q_UNUSED(topLeft) | |
309 | Q_UNUSED(bottomRight) |
|
309 | Q_UNUSED(bottomRight) | |
310 |
|
310 | |||
311 | if (m_model == 0 || m_series == 0) |
|
311 | if (m_model == 0 || m_series == 0) | |
312 | return; |
|
312 | return; | |
313 |
|
313 | |||
314 | if (m_modelSignalsBlock) |
|
314 | if (m_modelSignalsBlock) | |
315 | return; |
|
315 | return; | |
316 |
|
316 | |||
317 | blockSeriesSignals(); |
|
317 | blockSeriesSignals(); | |
318 | QModelIndex index; |
|
318 | QModelIndex index; | |
319 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
319 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
320 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
320 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
321 | index = topLeft.sibling(row, column); |
|
321 | index = topLeft.sibling(row, column); | |
322 | QBarSet* bar = barSet(index); |
|
322 | QBarSet* bar = barSet(index); | |
323 | if (bar) { |
|
323 | if (bar) { | |
324 | if (m_orientation == Qt::Vertical) |
|
324 | if (m_orientation == Qt::Vertical) | |
325 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
325 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
326 | else |
|
326 | else | |
327 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
327 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 | blockSeriesSignals(false); |
|
331 | blockSeriesSignals(false); | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) |
|
334 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) | |
335 | { |
|
335 | { | |
336 | if (m_model == 0 || m_series == 0) |
|
336 | if (m_model == 0 || m_series == 0) | |
337 | return; |
|
337 | return; | |
338 |
|
338 | |||
339 | if (m_modelSignalsBlock) |
|
339 | if (m_modelSignalsBlock) | |
340 | return; |
|
340 | return; | |
341 |
|
341 | |||
342 | blockSeriesSignals(); |
|
342 | blockSeriesSignals(); | |
343 | if (orientation != m_orientation) { |
|
343 | if (orientation != m_orientation) { | |
344 | for (int section = first; section <= last; section++) { |
|
344 | for (int section = first; section <= last; section++) { | |
345 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { |
|
345 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { | |
346 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); |
|
346 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); | |
347 | if (bar) |
|
347 | if (bar) | |
348 | bar->setLabel(m_model->headerData(section, orientation).toString()); |
|
348 | bar->setLabel(m_model->headerData(section, orientation).toString()); | |
349 | } |
|
349 | } | |
350 | } |
|
350 | } | |
351 | } |
|
351 | } | |
352 | blockSeriesSignals(false); |
|
352 | blockSeriesSignals(false); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
355 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
356 | { |
|
356 | { | |
357 | Q_UNUSED(parent); |
|
357 | Q_UNUSED(parent); | |
358 | Q_UNUSED(end) |
|
358 | Q_UNUSED(end) | |
359 | if (m_modelSignalsBlock) |
|
359 | if (m_modelSignalsBlock) | |
360 | return; |
|
360 | return; | |
361 |
|
361 | |||
362 | blockSeriesSignals(); |
|
362 | blockSeriesSignals(); | |
363 | if (m_orientation == Qt::Vertical) |
|
363 | if (m_orientation == Qt::Vertical) | |
364 | // insertData(start, end); |
|
364 | // insertData(start, end); | |
365 | initializeBarFromModel(); |
|
365 | initializeBarFromModel(); | |
366 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
366 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
367 | initializeBarFromModel(); |
|
367 | initializeBarFromModel(); | |
368 | blockSeriesSignals(false); |
|
368 | blockSeriesSignals(false); | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
371 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
372 | { |
|
372 | { | |
373 | Q_UNUSED(parent); |
|
373 | Q_UNUSED(parent); | |
374 | Q_UNUSED(end) |
|
374 | Q_UNUSED(end) | |
375 | if (m_modelSignalsBlock) |
|
375 | if (m_modelSignalsBlock) | |
376 | return; |
|
376 | return; | |
377 |
|
377 | |||
378 | blockSeriesSignals(); |
|
378 | blockSeriesSignals(); | |
379 | if (m_orientation == Qt::Vertical) |
|
379 | if (m_orientation == Qt::Vertical) | |
380 | // removeData(start, end); |
|
380 | // removeData(start, end); | |
381 | initializeBarFromModel(); |
|
381 | initializeBarFromModel(); | |
382 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
382 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
383 | initializeBarFromModel(); |
|
383 | initializeBarFromModel(); | |
384 | blockSeriesSignals(false); |
|
384 | blockSeriesSignals(false); | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
387 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
388 | { |
|
388 | { | |
389 | Q_UNUSED(parent); |
|
389 | Q_UNUSED(parent); | |
390 | Q_UNUSED(end) |
|
390 | Q_UNUSED(end) | |
391 | if (m_modelSignalsBlock) |
|
391 | if (m_modelSignalsBlock) | |
392 | return; |
|
392 | return; | |
393 |
|
393 | |||
394 | blockSeriesSignals(); |
|
394 | blockSeriesSignals(); | |
395 | if (m_orientation == Qt::Horizontal) |
|
395 | if (m_orientation == Qt::Horizontal) | |
396 | // insertData(start, end); |
|
396 | // insertData(start, end); | |
397 | initializeBarFromModel(); |
|
397 | initializeBarFromModel(); | |
398 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
398 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
399 | initializeBarFromModel(); |
|
399 | initializeBarFromModel(); | |
400 | blockSeriesSignals(false); |
|
400 | blockSeriesSignals(false); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
403 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
404 | { |
|
404 | { | |
405 | Q_UNUSED(parent); |
|
405 | Q_UNUSED(parent); | |
406 | Q_UNUSED(end) |
|
406 | Q_UNUSED(end) | |
407 | if (m_modelSignalsBlock) |
|
407 | if (m_modelSignalsBlock) | |
408 | return; |
|
408 | return; | |
409 |
|
409 | |||
410 | blockSeriesSignals(); |
|
410 | blockSeriesSignals(); | |
411 | if (m_orientation == Qt::Horizontal) |
|
411 | if (m_orientation == Qt::Horizontal) | |
412 | // removeData(start, end); |
|
412 | // removeData(start, end); | |
413 | initializeBarFromModel(); |
|
413 | initializeBarFromModel(); | |
414 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
414 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
415 | initializeBarFromModel(); |
|
415 | initializeBarFromModel(); | |
416 | blockSeriesSignals(false); |
|
416 | blockSeriesSignals(false); | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
419 | void QBarModelMapperPrivate::insertData(int start, int end) | |
420 | { |
|
420 | { | |
421 | Q_UNUSED(end) |
|
421 | Q_UNUSED(end) | |
422 | Q_UNUSED(start) |
|
422 | Q_UNUSED(start) | |
423 | Q_UNUSED(end) |
|
423 | Q_UNUSED(end) | |
424 | // To be implemented |
|
424 | // To be implemented | |
425 | } |
|
425 | } | |
426 |
|
426 | |||
427 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
427 | void QBarModelMapperPrivate::removeData(int start, int end) | |
428 | { |
|
428 | { | |
429 | Q_UNUSED(end) |
|
429 | Q_UNUSED(end) | |
430 | Q_UNUSED(start) |
|
430 | Q_UNUSED(start) | |
431 | Q_UNUSED(end) |
|
431 | Q_UNUSED(end) | |
432 | // To be implemented |
|
432 | // To be implemented | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) |
|
435 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) | |
436 | { |
|
436 | { | |
437 | if (m_seriesSignalsBlock) |
|
437 | if (m_seriesSignalsBlock) | |
438 | return; |
|
438 | return; | |
439 |
|
439 | |||
440 | if (sets.count() == 0) |
|
440 | if (sets.count() == 0) | |
441 | return; |
|
441 | return; | |
442 |
|
442 | |||
443 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); |
|
443 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); | |
444 | if (firstIndex == -1) |
|
444 | if (firstIndex == -1) | |
445 | return; |
|
445 | return; | |
446 |
|
446 | |||
447 | int maxCount = 0; |
|
447 | int maxCount = 0; | |
448 | for(int i = 0; i < sets.count(); i++) |
|
448 | for(int i = 0; i < sets.count(); i++) | |
449 | if (sets.at(i)->count() > m_count) |
|
449 | if (sets.at(i)->count() > m_count) | |
450 | maxCount = sets.at(i)->count(); |
|
450 | maxCount = sets.at(i)->count(); | |
451 |
|
451 | |||
452 | if (m_count != -1 && m_count < maxCount) |
|
452 | if (m_count != -1 && m_count < maxCount) | |
453 | m_count = maxCount; |
|
453 | m_count = maxCount; | |
454 |
|
454 | |||
455 | m_lastBarSetSection += sets.count(); |
|
455 | m_lastBarSetSection += sets.count(); | |
456 |
|
456 | |||
457 | blockModelSignals(); |
|
457 | blockModelSignals(); | |
458 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; |
|
458 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; | |
459 | if (maxCount > modelCapacity) { |
|
459 | if (maxCount > modelCapacity) { | |
460 | if (m_orientation == Qt::Vertical) |
|
460 | if (m_orientation == Qt::Vertical) | |
461 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); |
|
461 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); | |
462 | else |
|
462 | else | |
463 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); |
|
463 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); | |
464 | } |
|
464 | } | |
465 |
|
465 | |||
466 | if (m_orientation == Qt::Vertical) |
|
466 | if (m_orientation == Qt::Vertical) | |
467 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
467 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
468 | else |
|
468 | else | |
469 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
469 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); | |
470 |
|
470 | |||
471 |
|
471 | |||
472 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { |
|
472 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { | |
473 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); |
|
473 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); | |
474 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) |
|
474 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) | |
475 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); |
|
475 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); | |
476 | } |
|
476 | } | |
477 | blockModelSignals(false); |
|
477 | blockModelSignals(false); | |
478 | initializeBarFromModel(); |
|
478 | initializeBarFromModel(); | |
479 | } |
|
479 | } | |
480 |
|
480 | |||
481 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) |
|
481 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) | |
482 | { |
|
482 | { | |
483 | if (m_seriesSignalsBlock) |
|
483 | if (m_seriesSignalsBlock) | |
484 | return; |
|
484 | return; | |
485 |
|
485 | |||
486 | if (sets.count() == 0) |
|
486 | if (sets.count() == 0) | |
487 | return; |
|
487 | return; | |
488 |
|
488 | |||
489 | int firstIndex = m_barSets.indexOf(sets.at(0)); |
|
489 | int firstIndex = m_barSets.indexOf(sets.at(0)); | |
490 | if (firstIndex == -1) |
|
490 | if (firstIndex == -1) | |
491 | return; |
|
491 | return; | |
492 |
|
492 | |||
493 | m_lastBarSetSection -= sets.count(); |
|
493 | m_lastBarSetSection -= sets.count(); | |
494 |
|
494 | |||
495 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) |
|
495 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) | |
496 | m_barSets.removeAt(i); |
|
496 | m_barSets.removeAt(i); | |
497 |
|
497 | |||
498 | blockModelSignals(); |
|
498 | blockModelSignals(); | |
499 | if (m_orientation == Qt::Vertical) |
|
499 | if (m_orientation == Qt::Vertical) | |
500 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
500 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
501 | else |
|
501 | else | |
502 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
502 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); | |
503 | blockModelSignals(false); |
|
503 | blockModelSignals(false); | |
504 | initializeBarFromModel(); |
|
504 | initializeBarFromModel(); | |
505 | } |
|
505 | } | |
506 |
|
506 | |||
507 | void QBarModelMapperPrivate::valuesAdded(int index, int count) |
|
507 | void QBarModelMapperPrivate::valuesAdded(int index, int count) | |
508 | { |
|
508 | { | |
509 | if (m_seriesSignalsBlock) |
|
509 | if (m_seriesSignalsBlock) | |
510 | return; |
|
510 | return; | |
511 |
|
511 | |||
512 | if (m_count != -1) |
|
512 | if (m_count != -1) | |
513 | m_count += count; |
|
513 | m_count += count; | |
514 |
|
514 | |||
515 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
515 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
516 |
|
516 | |||
517 | blockModelSignals(); |
|
517 | blockModelSignals(); | |
518 | if (m_orientation == Qt::Vertical) |
|
518 | if (m_orientation == Qt::Vertical) | |
519 | m_model->insertRows(index + m_first, count); |
|
519 | m_model->insertRows(index + m_first, count); | |
520 | else |
|
520 | else | |
521 | m_model->insertColumns(index + m_first, count); |
|
521 | m_model->insertColumns(index + m_first, count); | |
522 |
|
522 | |||
523 | for (int j = index; j < index + count; j++) |
|
523 | for (int j = index; j < index + count; j++) | |
524 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); |
|
524 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); | |
525 |
|
525 | |||
526 | blockModelSignals(false); |
|
526 | blockModelSignals(false); | |
527 | initializeBarFromModel(); |
|
527 | initializeBarFromModel(); | |
528 | } |
|
528 | } | |
529 |
|
529 | |||
530 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) |
|
530 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) | |
531 | { |
|
531 | { | |
532 | if (m_seriesSignalsBlock) |
|
532 | if (m_seriesSignalsBlock) | |
533 | return; |
|
533 | return; | |
534 |
|
534 | |||
535 | if (m_count != -1) |
|
535 | if (m_count != -1) | |
536 | m_count -= count; |
|
536 | m_count -= count; | |
537 |
|
537 | |||
538 | blockModelSignals(); |
|
538 | blockModelSignals(); | |
539 | if (m_orientation == Qt::Vertical) |
|
539 | if (m_orientation == Qt::Vertical) | |
540 | m_model->removeRows(index + m_first, count); |
|
540 | m_model->removeRows(index + m_first, count); | |
541 | else |
|
541 | else | |
542 | m_model->removeColumns(index + m_first, count); |
|
542 | m_model->removeColumns(index + m_first, count); | |
543 |
|
543 | |||
544 | blockModelSignals(false); |
|
544 | blockModelSignals(false); | |
545 | initializeBarFromModel(); |
|
545 | initializeBarFromModel(); | |
546 | } |
|
546 | } | |
547 |
|
547 | |||
548 | void QBarModelMapperPrivate::barLabelChanged() |
|
548 | void QBarModelMapperPrivate::barLabelChanged() | |
549 | { |
|
549 | { | |
550 | if (m_seriesSignalsBlock) |
|
550 | if (m_seriesSignalsBlock) | |
551 | return; |
|
551 | return; | |
552 |
|
552 | |||
553 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
553 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
554 |
|
554 | |||
555 | blockModelSignals(); |
|
555 | blockModelSignals(); | |
556 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); |
|
556 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); | |
557 | blockModelSignals(false); |
|
557 | blockModelSignals(false); | |
558 | initializeBarFromModel(); |
|
558 | initializeBarFromModel(); | |
559 | } |
|
559 | } | |
560 |
|
560 | |||
561 | void QBarModelMapperPrivate::barValueChanged(int index) |
|
561 | void QBarModelMapperPrivate::barValueChanged(int index) | |
562 | { |
|
562 | { | |
563 | if (m_seriesSignalsBlock) |
|
563 | if (m_seriesSignalsBlock) | |
564 | return; |
|
564 | return; | |
565 |
|
565 | |||
566 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
566 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
567 |
|
567 | |||
568 | blockModelSignals(); |
|
568 | blockModelSignals(); | |
569 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); |
|
569 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); | |
570 | blockModelSignals(false); |
|
570 | blockModelSignals(false); | |
571 | initializeBarFromModel(); |
|
571 | initializeBarFromModel(); | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
574 | void QBarModelMapperPrivate::initializeBarFromModel() | |
575 | { |
|
575 | { | |
576 | if (m_model == 0 || m_series == 0) |
|
576 | if (m_model == 0 || m_series == 0) | |
577 | return; |
|
577 | return; | |
578 |
|
578 | |||
579 | blockSeriesSignals(); |
|
579 | blockSeriesSignals(); | |
580 | // clear current content |
|
580 | // clear current content | |
581 | m_series->clear(); |
|
581 | m_series->clear(); | |
582 | m_barSets.clear(); |
|
582 | m_barSets.clear(); | |
583 |
|
583 | |||
584 | // create the initial bar sets |
|
584 | // create the initial bar sets | |
585 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
585 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { | |
586 | int posInBar = 0; |
|
586 | int posInBar = 0; | |
587 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
587 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
588 | // check if there is such model index |
|
588 | // check if there is such model index | |
589 | if (barIndex.isValid()) { |
|
589 | if (barIndex.isValid()) { | |
590 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); |
|
590 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); | |
591 | while (barIndex.isValid()) { |
|
591 | while (barIndex.isValid()) { | |
592 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
592 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
593 | posInBar++; |
|
593 | posInBar++; | |
594 | barIndex = barModelIndex(i, posInBar); |
|
594 | barIndex = barModelIndex(i, posInBar); | |
595 | } |
|
595 | } | |
596 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); |
|
596 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); | |
597 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); |
|
597 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); | |
598 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); |
|
598 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); | |
599 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); |
|
599 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); | |
600 | m_series->append(barSet); |
|
600 | m_series->append(barSet); | |
601 | m_barSets.append(barSet); |
|
601 | m_barSets.append(barSet); | |
602 | } else { |
|
602 | } else { | |
603 | break; |
|
603 | break; | |
604 | } |
|
604 | } | |
605 | } |
|
605 | } | |
606 | blockSeriesSignals(false); |
|
606 | blockSeriesSignals(false); | |
607 | } |
|
607 | } | |
608 |
|
608 | |||
609 | #include "moc_qbarmodelmapper.cpp" |
|
609 | #include "moc_qbarmodelmapper.cpp" | |
610 | #include "moc_qbarmodelmapper_p.cpp" |
|
610 | #include "moc_qbarmodelmapper_p.cpp" | |
611 |
|
611 | |||
612 | QTCOMMERCIALCHART_END_NAMESPACE |
|
612 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,680 +1,680 | |||||
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 Series for creating a bar chart | |
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 | \qmlclass BarSeries QBarSeries |
|
49 | \qmlclass BarSeries QBarSeries | |
50 |
|
50 | |||
51 | \beginfloatleft |
|
51 | \beginfloatleft | |
52 | \image demos_qmlchart6.png |
|
52 | \image demos_qmlchart6.png | |
53 | \endfloat |
|
53 | \endfloat | |
54 | \clearfloat |
|
54 | \clearfloat | |
55 |
|
55 | |||
56 | The following QML shows how to create a simple bar chart: |
|
56 | The following QML shows how to create a simple bar chart: | |
57 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
57 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QBarSeries::barWidth |
|
61 | \property QBarSeries::barWidth | |
62 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
62 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
63 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
63 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
64 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
64 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
65 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
65 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
66 | \sa QGroupedBarSeries |
|
66 | \sa QGroupedBarSeries | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlproperty real BarSeries::barWidth |
|
69 | \qmlproperty real BarSeries::barWidth | |
70 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
70 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
71 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
71 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
72 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
72 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
73 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
73 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QBarSeries::count |
|
77 | \property QBarSeries::count | |
78 | Holds the number of sets in series. |
|
78 | Holds the number of sets in series. | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty int BarSeries::count |
|
81 | \qmlproperty int BarSeries::count | |
82 | Holds the number of sets in series. |
|
82 | Holds the number of sets in series. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarSeries::labelsVisible |
|
86 | \property QBarSeries::labelsVisible | |
87 | Defines the visibility of the labels in series |
|
87 | Defines the visibility of the labels in series | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty bool BarSeries::labelsVisible |
|
90 | \qmlproperty bool BarSeries::labelsVisible | |
91 | Defines the visibility of the labels in series |
|
91 | Defines the visibility of the labels in series | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \fn void QBarSeries::clicked(QBarSet *barset, int index) |
|
95 | \fn void QBarSeries::clicked(QBarSet *barset, int index) | |
96 |
|
96 | |||
97 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
97 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
98 | Clicked bar inside set is indexed by \a index |
|
98 | Clicked bar inside set is indexed by \a index | |
99 | */ |
|
99 | */ | |
100 | /*! |
|
100 | /*! | |
101 | \qmlsignal BarSeries::onClicked(BarSet barset, int index) |
|
101 | \qmlsignal BarSeries::onClicked(BarSet barset, int index) | |
102 |
|
102 | |||
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
104 | Clicked bar inside set is indexed by \a index |
|
104 | Clicked bar inside set is indexed by \a index | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
108 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
109 |
|
109 | |||
110 | The signal is emitted if mouse is hovered on top of series. |
|
110 | The signal is emitted if mouse is hovered on top of series. | |
111 | Parameter \a barset is the pointer of barset, where hover happened. |
|
111 | Parameter \a barset is the pointer of barset, where hover happened. | |
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlsignal BarSeries::onHovered(BarSet barset, bool status) |
|
115 | \qmlsignal BarSeries::onHovered(BarSet barset, bool status) | |
116 |
|
116 | |||
117 | The signal is emitted if mouse is hovered on top of series. |
|
117 | The signal is emitted if mouse is hovered on top of series. | |
118 | Parameter \a barset is the pointer of barset, where hover happened. |
|
118 | Parameter \a barset is the pointer of barset, where hover happened. | |
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn void QBarSeries::countChanged() |
|
123 | \fn void QBarSeries::countChanged() | |
124 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
124 | This signal is emitted when barset count has been changed, for example by append or remove. | |
125 | */ |
|
125 | */ | |
126 | /*! |
|
126 | /*! | |
127 | \qmlsignal BarSeries::countChanged() |
|
127 | \qmlsignal BarSeries::countChanged() | |
128 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
128 | This signal is emitted when barset count has been changed, for example by append or remove. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \fn void QBarSeries::labelsVisibleChanged() |
|
132 | \fn void QBarSeries::labelsVisibleChanged() | |
133 | This signal is emitted when labels visibility have changed. |
|
133 | This signal is emitted when labels visibility have changed. | |
134 | \sa isLabelsVisible(), setLabelsVisible() |
|
134 | \sa isLabelsVisible(), setLabelsVisible() | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
139 | This signal is emitted when \a sets have been added to the series. |
|
139 | This signal is emitted when \a sets have been added to the series. | |
140 | \sa append(), insert() |
|
140 | \sa append(), insert() | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
144 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
145 | This signal is emitted when \a sets have been removed from the series. |
|
145 | This signal is emitted when \a sets have been removed from the series. | |
146 | \sa remove() |
|
146 | \sa remove() | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Constructs empty QBarSeries. |
|
150 | Constructs empty QBarSeries. | |
151 | QBarSeries is QObject which is a child of a \a parent. |
|
151 | QBarSeries is QObject which is a child of a \a parent. | |
152 | */ |
|
152 | */ | |
153 | QBarSeries::QBarSeries(QObject *parent) : |
|
153 | QBarSeries::QBarSeries(QObject *parent) : | |
154 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
154 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
155 | { |
|
155 | { | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | Destructs barseries and owned barsets. |
|
159 | Destructs barseries and owned barsets. | |
160 | */ |
|
160 | */ | |
161 | QBarSeries::~QBarSeries() |
|
161 | QBarSeries::~QBarSeries() | |
162 | { |
|
162 | { | |
163 | Q_D(QBarSeries); |
|
163 | Q_D(QBarSeries); | |
164 | if(d->m_dataset){ |
|
164 | if(d->m_dataset){ | |
165 | d->m_dataset->removeSeries(this); |
|
165 | d->m_dataset->removeSeries(this); | |
166 | } |
|
166 | } | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | /*! |
|
169 | /*! | |
170 | \internal |
|
170 | \internal | |
171 | */ |
|
171 | */ | |
172 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
172 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
173 | QAbstractSeries(d,parent) |
|
173 | QAbstractSeries(d,parent) | |
174 | { |
|
174 | { | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | Returns the type of series. Derived classes override this. |
|
178 | Returns the type of series. Derived classes override this. | |
179 | */ |
|
179 | */ | |
180 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
180 | QAbstractSeries::SeriesType QBarSeries::type() const | |
181 | { |
|
181 | { | |
182 | return QAbstractSeries::SeriesTypeBar; |
|
182 | return QAbstractSeries::SeriesTypeBar; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
186 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
187 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
187 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
188 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
188 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
189 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
189 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
190 | */ |
|
190 | */ | |
191 | void QBarSeries::setBarWidth(qreal width) |
|
191 | void QBarSeries::setBarWidth(qreal width) | |
192 | { |
|
192 | { | |
193 | Q_D(QBarSeries); |
|
193 | Q_D(QBarSeries); | |
194 | d->setBarWidth(width); |
|
194 | d->setBarWidth(width); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | Returns the width of the bars of the series. |
|
198 | Returns the width of the bars of the series. | |
199 | \sa setBarWidth() |
|
199 | \sa setBarWidth() | |
200 | */ |
|
200 | */ | |
201 | qreal QBarSeries::barWidth() const |
|
201 | qreal QBarSeries::barWidth() const | |
202 | { |
|
202 | { | |
203 | Q_D(const QBarSeries); |
|
203 | Q_D(const QBarSeries); | |
204 | return d->barWidth(); |
|
204 | return d->barWidth(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | 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. |
|
208 | 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. | |
209 | Returns true, if appending succeeded. |
|
209 | Returns true, if appending succeeded. | |
210 | */ |
|
210 | */ | |
211 | bool QBarSeries::append(QBarSet *set) |
|
211 | bool QBarSeries::append(QBarSet *set) | |
212 | { |
|
212 | { | |
213 | Q_D(QBarSeries); |
|
213 | Q_D(QBarSeries); | |
214 | bool success = d->append(set); |
|
214 | bool success = d->append(set); | |
215 | if (success) { |
|
215 | if (success) { | |
216 | QList<QBarSet*> sets; |
|
216 | QList<QBarSet*> sets; | |
217 | sets.append(set); |
|
217 | sets.append(set); | |
218 | emit barsetsAdded(sets); |
|
218 | emit barsetsAdded(sets); | |
219 | emit countChanged(); |
|
219 | emit countChanged(); | |
220 | } |
|
220 | } | |
221 | return success; |
|
221 | return success; | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | /*! |
|
224 | /*! | |
225 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
225 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
226 | Returns true, if set was removed. |
|
226 | Returns true, if set was removed. | |
227 | */ |
|
227 | */ | |
228 | bool QBarSeries::remove(QBarSet *set) |
|
228 | bool QBarSeries::remove(QBarSet *set) | |
229 | { |
|
229 | { | |
230 | Q_D(QBarSeries); |
|
230 | Q_D(QBarSeries); | |
231 | bool success = d->remove(set); |
|
231 | bool success = d->remove(set); | |
232 | if (success) { |
|
232 | if (success) { | |
233 | QList<QBarSet*> sets; |
|
233 | QList<QBarSet*> sets; | |
234 | sets.append(set); |
|
234 | sets.append(set); | |
235 | emit barsetsRemoved(sets); |
|
235 | emit barsetsRemoved(sets); | |
236 | emit countChanged(); |
|
236 | emit countChanged(); | |
237 | } |
|
237 | } | |
238 | return success; |
|
238 | return success; | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
242 | Adds a list of barsets to series. Takes ownership of \a sets. | |
243 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
243 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
244 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
244 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
245 | and function returns false. |
|
245 | and function returns false. | |
246 | */ |
|
246 | */ | |
247 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
247 | bool QBarSeries::append(QList<QBarSet* > sets) | |
248 | { |
|
248 | { | |
249 | Q_D(QBarSeries); |
|
249 | Q_D(QBarSeries); | |
250 | bool success = d->append(sets); |
|
250 | bool success = d->append(sets); | |
251 | if (success) { |
|
251 | if (success) { | |
252 | emit barsetsAdded(sets); |
|
252 | emit barsetsAdded(sets); | |
253 | emit countChanged(); |
|
253 | emit countChanged(); | |
254 | } |
|
254 | } | |
255 | return success; |
|
255 | return success; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
259 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
260 | Returns true, if inserting succeeded. |
|
260 | Returns true, if inserting succeeded. | |
261 |
|
261 | |||
262 | */ |
|
262 | */ | |
263 | bool QBarSeries::insert(int index, QBarSet *set) |
|
263 | bool QBarSeries::insert(int index, QBarSet *set) | |
264 | { |
|
264 | { | |
265 | Q_D(QBarSeries); |
|
265 | Q_D(QBarSeries); | |
266 | bool success = d->insert(index, set); |
|
266 | bool success = d->insert(index, set); | |
267 | if (success) { |
|
267 | if (success) { | |
268 | QList<QBarSet*> sets; |
|
268 | QList<QBarSet*> sets; | |
269 | sets.append(set); |
|
269 | sets.append(set); | |
270 | emit barsetsAdded(sets); |
|
270 | emit barsetsAdded(sets); | |
271 | emit countChanged(); |
|
271 | emit countChanged(); | |
272 | } |
|
272 | } | |
273 | return success; |
|
273 | return success; | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | /*! |
|
276 | /*! | |
277 | Removes all of the bar sets from the series |
|
277 | Removes all of the bar sets from the series | |
278 | */ |
|
278 | */ | |
279 | void QBarSeries::clear() |
|
279 | void QBarSeries::clear() | |
280 | { |
|
280 | { | |
281 | Q_D(QBarSeries); |
|
281 | Q_D(QBarSeries); | |
282 | QList<QBarSet *> sets = barSets(); |
|
282 | QList<QBarSet *> sets = barSets(); | |
283 | bool success = d->remove(sets); |
|
283 | bool success = d->remove(sets); | |
284 | if (success) { |
|
284 | if (success) { | |
285 | emit barsetsRemoved(sets); |
|
285 | emit barsetsRemoved(sets); | |
286 | emit countChanged(); |
|
286 | emit countChanged(); | |
287 | } |
|
287 | } | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | /*! |
|
290 | /*! | |
291 | Returns number of sets in series. |
|
291 | Returns number of sets in series. | |
292 | */ |
|
292 | */ | |
293 | int QBarSeries::count() const |
|
293 | int QBarSeries::count() const | |
294 | { |
|
294 | { | |
295 | Q_D(const QBarSeries); |
|
295 | Q_D(const QBarSeries); | |
296 | return d->m_barSets.count(); |
|
296 | return d->m_barSets.count(); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | Returns a list of sets in series. Keeps ownership of sets. |
|
300 | Returns a list of sets in series. Keeps ownership of sets. | |
301 | */ |
|
301 | */ | |
302 | QList<QBarSet*> QBarSeries::barSets() const |
|
302 | QList<QBarSet*> QBarSeries::barSets() const | |
303 | { |
|
303 | { | |
304 | Q_D(const QBarSeries); |
|
304 | Q_D(const QBarSeries); | |
305 | return d->m_barSets; |
|
305 | return d->m_barSets; | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | /*! |
|
308 | /*! | |
309 | Sets the visibility of labels in series to \a visible |
|
309 | Sets the visibility of labels in series to \a visible | |
310 | */ |
|
310 | */ | |
311 | void QBarSeries::setLabelsVisible(bool visible) |
|
311 | void QBarSeries::setLabelsVisible(bool visible) | |
312 | { |
|
312 | { | |
313 | Q_D(QBarSeries); |
|
313 | Q_D(QBarSeries); | |
314 | if (d->m_labelsVisible != visible) { |
|
314 | if (d->m_labelsVisible != visible) { | |
315 | d->setLabelsVisible(visible); |
|
315 | d->setLabelsVisible(visible); | |
316 | emit labelsVisibleChanged(); |
|
316 | emit labelsVisibleChanged(); | |
317 | } |
|
317 | } | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | /*! |
|
320 | /*! | |
321 | Returns the visibility of labels |
|
321 | Returns the visibility of labels | |
322 | */ |
|
322 | */ | |
323 | bool QBarSeries::isLabelsVisible() const |
|
323 | bool QBarSeries::isLabelsVisible() const | |
324 | { |
|
324 | { | |
325 | Q_D(const QBarSeries); |
|
325 | Q_D(const QBarSeries); | |
326 | return d->m_labelsVisible; |
|
326 | return d->m_labelsVisible; | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
329 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
330 |
|
330 | |||
331 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
331 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
332 | QAbstractSeriesPrivate(q), |
|
332 | QAbstractSeriesPrivate(q), | |
333 | m_barWidth(0.5), // Default value is 50% of category width |
|
333 | m_barWidth(0.5), // Default value is 50% of category width | |
334 | m_labelsVisible(false), |
|
334 | m_labelsVisible(false), | |
335 | m_visible(true) |
|
335 | m_visible(true) | |
336 | { |
|
336 | { | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | int QBarSeriesPrivate::categoryCount() const |
|
339 | int QBarSeriesPrivate::categoryCount() const | |
340 | { |
|
340 | { | |
341 | // No categories defined. return count of longest set. |
|
341 | // No categories defined. return count of longest set. | |
342 | int count = 0; |
|
342 | int count = 0; | |
343 | for (int i=0; i<m_barSets.count(); i++) { |
|
343 | for (int i=0; i<m_barSets.count(); i++) { | |
344 | if (m_barSets.at(i)->count() > count) { |
|
344 | if (m_barSets.at(i)->count() > count) { | |
345 | count = m_barSets.at(i)->count(); |
|
345 | count = m_barSets.at(i)->count(); | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | return count; |
|
349 | return count; | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | void QBarSeriesPrivate::setBarWidth(qreal width) |
|
352 | void QBarSeriesPrivate::setBarWidth(qreal width) | |
353 | { |
|
353 | { | |
354 | if (width < 0.0) { |
|
354 | if (width < 0.0) { | |
355 | width = 0.0; |
|
355 | width = 0.0; | |
356 | } |
|
356 | } | |
357 | m_barWidth = width; |
|
357 | m_barWidth = width; | |
358 | emit updatedBars(); |
|
358 | emit updatedBars(); | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | qreal QBarSeriesPrivate::barWidth() const |
|
361 | qreal QBarSeriesPrivate::barWidth() const | |
362 | { |
|
362 | { | |
363 | return m_barWidth; |
|
363 | return m_barWidth; | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
366 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
367 | { |
|
367 | { | |
368 | return m_barSets.at(index); |
|
368 | return m_barSets.at(index); | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | void QBarSeriesPrivate::setVisible(bool visible) |
|
371 | void QBarSeriesPrivate::setVisible(bool visible) | |
372 | { |
|
372 | { | |
373 | m_visible = visible; |
|
373 | m_visible = visible; | |
374 | emit updatedBars(); |
|
374 | emit updatedBars(); | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | void QBarSeriesPrivate::setLabelsVisible(bool visible) |
|
377 | void QBarSeriesPrivate::setLabelsVisible(bool visible) | |
378 | { |
|
378 | { | |
379 | m_labelsVisible = visible; |
|
379 | m_labelsVisible = visible; | |
380 | emit labelsVisibleChanged(visible); |
|
380 | emit labelsVisibleChanged(visible); | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | qreal QBarSeriesPrivate::min() |
|
383 | qreal QBarSeriesPrivate::min() | |
384 | { |
|
384 | { | |
385 | if (m_barSets.count() <= 0) { |
|
385 | if (m_barSets.count() <= 0) { | |
386 | return 0; |
|
386 | return 0; | |
387 | } |
|
387 | } | |
388 | qreal min = INT_MAX; |
|
388 | qreal min = INT_MAX; | |
389 |
|
389 | |||
390 | for (int i = 0; i < m_barSets.count(); i++) { |
|
390 | for (int i = 0; i < m_barSets.count(); i++) { | |
391 | int categoryCount = m_barSets.at(i)->count(); |
|
391 | int categoryCount = m_barSets.at(i)->count(); | |
392 | for (int j = 0; j < categoryCount; j++) { |
|
392 | for (int j = 0; j < categoryCount; j++) { | |
393 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
393 | qreal temp = m_barSets.at(i)->at(j).y(); | |
394 | if (temp < min) |
|
394 | if (temp < min) | |
395 | min = temp; |
|
395 | min = temp; | |
396 | } |
|
396 | } | |
397 | } |
|
397 | } | |
398 | return min; |
|
398 | return min; | |
399 | } |
|
399 | } | |
400 |
|
400 | |||
401 | qreal QBarSeriesPrivate::max() |
|
401 | qreal QBarSeriesPrivate::max() | |
402 | { |
|
402 | { | |
403 | if (m_barSets.count() <= 0) { |
|
403 | if (m_barSets.count() <= 0) { | |
404 | return 0; |
|
404 | return 0; | |
405 | } |
|
405 | } | |
406 | qreal max = INT_MIN; |
|
406 | qreal max = INT_MIN; | |
407 |
|
407 | |||
408 | for (int i = 0; i < m_barSets.count(); i++) { |
|
408 | for (int i = 0; i < m_barSets.count(); i++) { | |
409 | int categoryCount = m_barSets.at(i)->count(); |
|
409 | int categoryCount = m_barSets.at(i)->count(); | |
410 | for (int j = 0; j < categoryCount; j++) { |
|
410 | for (int j = 0; j < categoryCount; j++) { | |
411 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
411 | qreal temp = m_barSets.at(i)->at(j).y(); | |
412 | if (temp > max) |
|
412 | if (temp > max) | |
413 | max = temp; |
|
413 | max = temp; | |
414 | } |
|
414 | } | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | return max; |
|
417 | return max; | |
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
420 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
421 | { |
|
421 | { | |
422 | if ((set < 0) || (set >= m_barSets.count())) { |
|
422 | if ((set < 0) || (set >= m_barSets.count())) { | |
423 | // No set, no value. |
|
423 | // No set, no value. | |
424 | return 0; |
|
424 | return 0; | |
425 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
425 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
426 | // No category, no value. |
|
426 | // No category, no value. | |
427 | return 0; |
|
427 | return 0; | |
428 | } |
|
428 | } | |
429 |
|
429 | |||
430 | return m_barSets.at(set)->at(category).y(); |
|
430 | return m_barSets.at(set)->at(category).y(); | |
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
433 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
434 | { |
|
434 | { | |
435 | if ((set < 0) || (set >= m_barSets.count())) { |
|
435 | if ((set < 0) || (set >= m_barSets.count())) { | |
436 | // No set, no value. |
|
436 | // No set, no value. | |
437 | return 0; |
|
437 | return 0; | |
438 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
438 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
439 | // No category, no value. |
|
439 | // No category, no value. | |
440 | return 0; |
|
440 | return 0; | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | qreal value = m_barSets.at(set)->at(category).y(); |
|
443 | qreal value = m_barSets.at(set)->at(category).y(); | |
444 | qreal sum = categorySum(category); |
|
444 | qreal sum = categorySum(category); | |
445 | if ( qFuzzyIsNull(sum) ) { |
|
445 | if ( qFuzzyIsNull(sum) ) { | |
446 | return 0; |
|
446 | return 0; | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | return value / sum; |
|
449 | return value / sum; | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | qreal QBarSeriesPrivate::categorySum(int category) |
|
452 | qreal QBarSeriesPrivate::categorySum(int category) | |
453 | { |
|
453 | { | |
454 | qreal sum(0); |
|
454 | qreal sum(0); | |
455 | int count = m_barSets.count(); // Count sets |
|
455 | int count = m_barSets.count(); // Count sets | |
456 | for (int set = 0; set < count; set++) { |
|
456 | for (int set = 0; set < count; set++) { | |
457 | if (category < m_barSets.at(set)->count()) |
|
457 | if (category < m_barSets.at(set)->count()) | |
458 | sum += m_barSets.at(set)->at(category).y(); |
|
458 | sum += m_barSets.at(set)->at(category).y(); | |
459 | } |
|
459 | } | |
460 | return sum; |
|
460 | return sum; | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
463 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
464 | { |
|
464 | { | |
465 | qreal sum(0); |
|
465 | qreal sum(0); | |
466 | int count = m_barSets.count(); // Count sets |
|
466 | int count = m_barSets.count(); // Count sets | |
467 | for (int set = 0; set < count; set++) { |
|
467 | for (int set = 0; set < count; set++) { | |
468 | if (category < m_barSets.at(set)->count()) |
|
468 | if (category < m_barSets.at(set)->count()) | |
469 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
469 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
470 | } |
|
470 | } | |
471 | return sum; |
|
471 | return sum; | |
472 | } |
|
472 | } | |
473 |
|
473 | |||
474 | qreal QBarSeriesPrivate::maxCategorySum() |
|
474 | qreal QBarSeriesPrivate::maxCategorySum() | |
475 | { |
|
475 | { | |
476 | qreal max = INT_MIN; |
|
476 | qreal max = INT_MIN; | |
477 | int count = categoryCount(); |
|
477 | int count = categoryCount(); | |
478 | for (int i = 0; i < count; i++) { |
|
478 | for (int i = 0; i < count; i++) { | |
479 | qreal sum = categorySum(i); |
|
479 | qreal sum = categorySum(i); | |
480 | if (sum > max) |
|
480 | if (sum > max) | |
481 | max = sum; |
|
481 | max = sum; | |
482 | } |
|
482 | } | |
483 | return max; |
|
483 | return max; | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | qreal QBarSeriesPrivate::minX() |
|
486 | qreal QBarSeriesPrivate::minX() | |
487 | { |
|
487 | { | |
488 | if (m_barSets.count() <= 0) { |
|
488 | if (m_barSets.count() <= 0) { | |
489 | return 0; |
|
489 | return 0; | |
490 | } |
|
490 | } | |
491 | qreal min = INT_MAX; |
|
491 | qreal min = INT_MAX; | |
492 |
|
492 | |||
493 | for (int i = 0; i < m_barSets.count(); i++) { |
|
493 | for (int i = 0; i < m_barSets.count(); i++) { | |
494 | int categoryCount = m_barSets.at(i)->count(); |
|
494 | int categoryCount = m_barSets.at(i)->count(); | |
495 | for (int j = 0; j < categoryCount; j++) { |
|
495 | for (int j = 0; j < categoryCount; j++) { | |
496 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
496 | qreal temp = m_barSets.at(i)->at(j).x(); | |
497 | if (temp < min) |
|
497 | if (temp < min) | |
498 | min = temp; |
|
498 | min = temp; | |
499 | } |
|
499 | } | |
500 | } |
|
500 | } | |
501 | return min; |
|
501 | return min; | |
502 | } |
|
502 | } | |
503 |
|
503 | |||
504 | qreal QBarSeriesPrivate::maxX() |
|
504 | qreal QBarSeriesPrivate::maxX() | |
505 | { |
|
505 | { | |
506 | if (m_barSets.count() <= 0) { |
|
506 | if (m_barSets.count() <= 0) { | |
507 | return 0; |
|
507 | return 0; | |
508 | } |
|
508 | } | |
509 | qreal max = INT_MIN; |
|
509 | qreal max = INT_MIN; | |
510 |
|
510 | |||
511 | for (int i = 0; i < m_barSets.count(); i++) { |
|
511 | for (int i = 0; i < m_barSets.count(); i++) { | |
512 | int categoryCount = m_barSets.at(i)->count(); |
|
512 | int categoryCount = m_barSets.at(i)->count(); | |
513 | for (int j = 0; j < categoryCount; j++) { |
|
513 | for (int j = 0; j < categoryCount; j++) { | |
514 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
514 | qreal temp = m_barSets.at(i)->at(j).x(); | |
515 | if (temp > max) |
|
515 | if (temp > max) | |
516 | max = temp; |
|
516 | max = temp; | |
517 | } |
|
517 | } | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | return max; |
|
520 | return max; | |
521 | } |
|
521 | } | |
522 |
|
522 | |||
523 |
|
523 | |||
524 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
524 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
525 | { |
|
525 | { | |
526 | qreal minX(domain.minX()); |
|
526 | qreal minX(domain.minX()); | |
527 | qreal minY(domain.minY()); |
|
527 | qreal minY(domain.minY()); | |
528 | qreal maxX(domain.maxX()); |
|
528 | qreal maxX(domain.maxX()); | |
529 | qreal maxY(domain.maxY()); |
|
529 | qreal maxY(domain.maxY()); | |
530 | int tickXCount(domain.tickXCount()); |
|
530 | int tickXCount(domain.tickXCount()); | |
531 | int tickYCount(domain.tickYCount()); |
|
531 | int tickYCount(domain.tickYCount()); | |
532 |
|
532 | |||
533 | qreal seriesMinX = this->minX(); |
|
533 | qreal seriesMinX = this->minX(); | |
534 | qreal seriesMaxX = this->maxX(); |
|
534 | qreal seriesMaxX = this->maxX(); | |
535 | qreal y = max(); |
|
535 | qreal y = max(); | |
536 | minX = qMin(minX, seriesMinX - 0.5); |
|
536 | minX = qMin(minX, seriesMinX - 0.5); | |
537 | minY = qMin(minY, y); |
|
537 | minY = qMin(minY, y); | |
538 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
538 | maxX = qMax(maxX, seriesMaxX + 0.5); | |
539 | maxY = qMax(maxY, y); |
|
539 | maxY = qMax(maxY, y); | |
540 | tickXCount = categoryCount()+1; |
|
540 | tickXCount = categoryCount()+1; | |
541 |
|
541 | |||
542 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
542 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
543 | } |
|
543 | } | |
544 |
|
544 | |||
545 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
545 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
546 | { |
|
546 | { | |
547 | Q_Q(QBarSeries); |
|
547 | Q_Q(QBarSeries); | |
548 |
|
548 | |||
549 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
549 | BarChartItem* bar = new BarChartItem(q,presenter); | |
550 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
550 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
551 | presenter->animator()->addAnimation(bar); |
|
551 | presenter->animator()->addAnimation(bar); | |
552 | } |
|
552 | } | |
553 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
553 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
554 | return bar; |
|
554 | return bar; | |
555 |
|
555 | |||
556 | } |
|
556 | } | |
557 |
|
557 | |||
558 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
558 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
559 | { |
|
559 | { | |
560 | Q_Q(QBarSeries); |
|
560 | Q_Q(QBarSeries); | |
561 | QList<LegendMarker*> markers; |
|
561 | QList<LegendMarker*> markers; | |
562 | foreach(QBarSet* set, q->barSets()) { |
|
562 | foreach(QBarSet* set, q->barSets()) { | |
563 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
563 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
564 | markers << marker; |
|
564 | markers << marker; | |
565 | } |
|
565 | } | |
566 |
|
566 | |||
567 | return markers; |
|
567 | return markers; | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
570 | bool QBarSeriesPrivate::append(QBarSet *set) | |
571 | { |
|
571 | { | |
572 | Q_Q(QBarSeries); |
|
572 | Q_Q(QBarSeries); | |
573 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
573 | if ((m_barSets.contains(set)) || (set == 0)) { | |
574 | // Fail if set is already in list or set is null. |
|
574 | // Fail if set is already in list or set is null. | |
575 | return false; |
|
575 | return false; | |
576 | } |
|
576 | } | |
577 | m_barSets.append(set); |
|
577 | m_barSets.append(set); | |
578 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
578 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
579 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
579 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
580 | emit restructuredBars(); // this notifies barchartitem |
|
580 | emit restructuredBars(); // this notifies barchartitem | |
581 | if (m_dataset) { |
|
581 | if (m_dataset) { | |
582 | m_dataset->updateSeries(q); // this notifies legend |
|
582 | m_dataset->updateSeries(q); // this notifies legend | |
583 | } |
|
583 | } | |
584 | return true; |
|
584 | return true; | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
587 | bool QBarSeriesPrivate::remove(QBarSet *set) | |
588 | { |
|
588 | { | |
589 | Q_Q(QBarSeries); |
|
589 | Q_Q(QBarSeries); | |
590 | if (!m_barSets.contains(set)) { |
|
590 | if (!m_barSets.contains(set)) { | |
591 | // Fail if set is not in list |
|
591 | // Fail if set is not in list | |
592 | return false; |
|
592 | return false; | |
593 | } |
|
593 | } | |
594 | m_barSets.removeOne(set); |
|
594 | m_barSets.removeOne(set); | |
595 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
595 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
596 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
596 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
597 | emit restructuredBars(); // this notifies barchartitem |
|
597 | emit restructuredBars(); // this notifies barchartitem | |
598 | if (m_dataset) { |
|
598 | if (m_dataset) { | |
599 | m_dataset->updateSeries(q); // this notifies legend |
|
599 | m_dataset->updateSeries(q); // this notifies legend | |
600 | } |
|
600 | } | |
601 | return true; |
|
601 | return true; | |
602 | } |
|
602 | } | |
603 |
|
603 | |||
604 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
604 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) | |
605 | { |
|
605 | { | |
606 | Q_Q(QBarSeries); |
|
606 | Q_Q(QBarSeries); | |
607 | foreach (QBarSet* set, sets) { |
|
607 | foreach (QBarSet* set, sets) { | |
608 | if ((set == 0) || (m_barSets.contains(set))) { |
|
608 | if ((set == 0) || (m_barSets.contains(set))) { | |
609 | // Fail if any of the sets is null or is already appended. |
|
609 | // Fail if any of the sets is null or is already appended. | |
610 | return false; |
|
610 | return false; | |
611 | } |
|
611 | } | |
612 | if (sets.count(set) != 1) { |
|
612 | if (sets.count(set) != 1) { | |
613 | // Also fail if same set is more than once in given list. |
|
613 | // Also fail if same set is more than once in given list. | |
614 | return false; |
|
614 | return false; | |
615 | } |
|
615 | } | |
616 | } |
|
616 | } | |
617 |
|
617 | |||
618 | foreach (QBarSet* set, sets) { |
|
618 | foreach (QBarSet* set, sets) { | |
619 | m_barSets.append(set); |
|
619 | m_barSets.append(set); | |
620 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
620 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
621 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
621 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
622 | } |
|
622 | } | |
623 | emit restructuredBars(); // this notifies barchartitem |
|
623 | emit restructuredBars(); // this notifies barchartitem | |
624 | if (m_dataset) { |
|
624 | if (m_dataset) { | |
625 | m_dataset->updateSeries(q); // this notifies legend |
|
625 | m_dataset->updateSeries(q); // this notifies legend | |
626 | } |
|
626 | } | |
627 | return true; |
|
627 | return true; | |
628 | } |
|
628 | } | |
629 |
|
629 | |||
630 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
630 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
631 | { |
|
631 | { | |
632 | Q_Q(QBarSeries); |
|
632 | Q_Q(QBarSeries); | |
633 | if (sets.count() == 0) { |
|
633 | if (sets.count() == 0) { | |
634 | return false; |
|
634 | return false; | |
635 | } |
|
635 | } | |
636 | foreach (QBarSet* set, sets) { |
|
636 | foreach (QBarSet* set, sets) { | |
637 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
637 | if ((set == 0) || (!m_barSets.contains(set))) { | |
638 | // Fail if any of the sets is null or is not in series |
|
638 | // Fail if any of the sets is null or is not in series | |
639 | return false; |
|
639 | return false; | |
640 | } |
|
640 | } | |
641 | if (sets.count(set) != 1) { |
|
641 | if (sets.count(set) != 1) { | |
642 | // Also fail if same set is more than once in given list. |
|
642 | // Also fail if same set is more than once in given list. | |
643 | return false; |
|
643 | return false; | |
644 | } |
|
644 | } | |
645 | } |
|
645 | } | |
646 |
|
646 | |||
647 | foreach (QBarSet* set, sets) { |
|
647 | foreach (QBarSet* set, sets) { | |
648 | m_barSets.removeOne(set); |
|
648 | m_barSets.removeOne(set); | |
649 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
649 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
650 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
650 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
651 | } |
|
651 | } | |
652 |
|
652 | |||
653 | emit restructuredBars(); // this notifies barchartitem |
|
653 | emit restructuredBars(); // this notifies barchartitem | |
654 | if (m_dataset) { |
|
654 | if (m_dataset) { | |
655 | m_dataset->updateSeries(q); // this notifies legend |
|
655 | m_dataset->updateSeries(q); // this notifies legend | |
656 | } |
|
656 | } | |
657 | return true; |
|
657 | return true; | |
658 | } |
|
658 | } | |
659 |
|
659 | |||
660 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) |
|
660 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) | |
661 | { |
|
661 | { | |
662 | Q_Q(QBarSeries); |
|
662 | Q_Q(QBarSeries); | |
663 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
663 | if ((m_barSets.contains(set)) || (set == 0)) { | |
664 | // Fail if set is already in list or set is null. |
|
664 | // Fail if set is already in list or set is null. | |
665 | return false; |
|
665 | return false; | |
666 | } |
|
666 | } | |
667 | m_barSets.insert(index, set); |
|
667 | m_barSets.insert(index, set); | |
668 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
668 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
669 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
669 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
670 | emit restructuredBars(); // this notifies barchartitem |
|
670 | emit restructuredBars(); // this notifies barchartitem | |
671 | if (m_dataset) { |
|
671 | if (m_dataset) { | |
672 | m_dataset->updateSeries(q); // this notifies legend |
|
672 | m_dataset->updateSeries(q); // this notifies legend | |
673 | } |
|
673 | } | |
674 | return true; |
|
674 | return true; | |
675 | } |
|
675 | } | |
676 |
|
676 | |||
677 | #include "moc_qbarseries.cpp" |
|
677 | #include "moc_qbarseries.cpp" | |
678 | #include "moc_qbarseries_p.cpp" |
|
678 | #include "moc_qbarseries_p.cpp" | |
679 |
|
679 | |||
680 | QTCOMMERCIALCHART_END_NAMESPACE |
|
680 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,639 +1,639 | |||||
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 "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief part of QtCommercial chart API. |
|
28 | \brief Building block for different bar charts | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 | /*! |
|
39 | /*! | |
40 | \qmlclass BarSet QBarSet |
|
40 | \qmlclass BarSet QBarSet | |
41 |
|
41 | |||
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. | |
43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
43 | First value of set is assumed to belong to first category, second to second category and so on. | |
44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
44 | If set has fewer values than there are categories, then the missing values are assumed to be | |
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
46 | \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries |
|
46 | \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QBarSet::label |
|
50 | \property QBarSet::label | |
51 | Defines the label of the barSet. |
|
51 | Defines the label of the barSet. | |
52 | */ |
|
52 | */ | |
53 | /*! |
|
53 | /*! | |
54 | \qmlproperty string BarSet::label |
|
54 | \qmlproperty string BarSet::label | |
55 | Defines the label of the barSet. |
|
55 | Defines the label of the barSet. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QBarSet::pen |
|
59 | \property QBarSet::pen | |
60 | \brief Defines the pen used by the barSet. |
|
60 | \brief Defines the pen used by the barSet. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarSet::brush |
|
64 | \property QBarSet::brush | |
65 | \brief Defines the brush used by the barSet. |
|
65 | \brief Defines the brush used by the barSet. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarSet::labelBrush |
|
69 | \property QBarSet::labelBrush | |
70 | \brief Defines the brush used by the barSet's label. |
|
70 | \brief Defines the brush used by the barSet's label. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \property QBarSet::labelFont |
|
74 | \property QBarSet::labelFont | |
75 | \brief Defines the font used by the barSet's label. |
|
75 | \brief Defines the font used by the barSet's label. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \property QBarSet::color |
|
79 | \property QBarSet::color | |
80 | The fill (brush) color of the bar set. |
|
80 | The fill (brush) color of the bar set. | |
81 | */ |
|
81 | */ | |
82 | /*! |
|
82 | /*! | |
83 | \qmlproperty color BarSet::color |
|
83 | \qmlproperty color BarSet::color | |
84 | The fill (brush) color of the bar set. |
|
84 | The fill (brush) color of the bar set. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QBarSet::borderColor |
|
88 | \property QBarSet::borderColor | |
89 | The line (pen) color of the bar set. |
|
89 | The line (pen) color of the bar set. | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty color BarSet::borderColor |
|
92 | \qmlproperty color BarSet::borderColor | |
93 | The line (pen) color of the bar set. |
|
93 | The line (pen) color of the bar set. | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \property QBarSet::labelColor |
|
97 | \property QBarSet::labelColor | |
98 | The text (label) color of the bar set. |
|
98 | The text (label) color of the bar set. | |
99 | */ |
|
99 | */ | |
100 | /*! |
|
100 | /*! | |
101 | \qmlproperty color BarSet::labelColor |
|
101 | \qmlproperty color BarSet::labelColor | |
102 | The text (label) color of the bar set. |
|
102 | The text (label) color of the bar set. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \fn void QBarSet::clicked(int index) |
|
106 | \fn void QBarSet::clicked(int index) | |
107 |
|
107 | |||
108 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
108 | The signal is emitted if the user clicks with a mouse on top of barset. | |
109 | Clicked bar inside set is indexed by \a index |
|
109 | Clicked bar inside set is indexed by \a index | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QBarSet::hovered(bool status) |
|
113 | \fn void QBarSet::hovered(bool status) | |
114 |
|
114 | |||
115 | The signal is emitted if mouse is hovered on top of barset. |
|
115 | The signal is emitted if mouse is hovered on top of barset. | |
116 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
116 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \fn void QBarSet::labelChanged() |
|
121 | \fn void QBarSet::labelChanged() | |
122 | This signal is emitted when the label of the barSet has changed. |
|
122 | This signal is emitted when the label of the barSet has changed. | |
123 | \sa label |
|
123 | \sa label | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QBarSet::penChanged() |
|
127 | \fn void QBarSet::penChanged() | |
128 | This signal is emitted when the pen of the barSet has changed. |
|
128 | This signal is emitted when the pen of the barSet has changed. | |
129 | \sa pen |
|
129 | \sa pen | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QBarSet::brushChanged() |
|
133 | \fn void QBarSet::brushChanged() | |
134 | This signal is emitted when the brush of the barSet has changed. |
|
134 | This signal is emitted when the brush of the barSet has changed. | |
135 | \sa brush |
|
135 | \sa brush | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QBarSet::labelBrushChanged() |
|
139 | \fn void QBarSet::labelBrushChanged() | |
140 | This signal is emitted when the brush of the barSet's label has changed. |
|
140 | This signal is emitted when the brush of the barSet's label has changed. | |
141 | \sa labelBrush |
|
141 | \sa labelBrush | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QBarSet::labelFontChanged() |
|
145 | \fn void QBarSet::labelFontChanged() | |
146 | This signal is emitted when the font of the barSet's label has changed. |
|
146 | This signal is emitted when the font of the barSet's label has changed. | |
147 | \sa labelBrush |
|
147 | \sa labelBrush | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \fn void QBarSet::colorChanged(QColor) |
|
151 | \fn void QBarSet::colorChanged(QColor) | |
152 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
152 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
153 | */ |
|
153 | */ | |
154 | /*! |
|
154 | /*! | |
155 | \qmlsignal BarSet::onColorChanged(color color) |
|
155 | \qmlsignal BarSet::onColorChanged(color color) | |
156 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
156 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | \fn void QBarSet::borderColorChanged(QColor) |
|
160 | \fn void QBarSet::borderColorChanged(QColor) | |
161 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
161 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
162 | */ |
|
162 | */ | |
163 | /*! |
|
163 | /*! | |
164 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
164 | \qmlsignal BarSet::onBorderColorChanged(color color) | |
165 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
165 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
166 | */ |
|
166 | */ | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | \fn void QBarSet::labelColorChanged(QColor) |
|
169 | \fn void QBarSet::labelColorChanged(QColor) | |
170 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
170 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
171 | */ |
|
171 | */ | |
172 | /*! |
|
172 | /*! | |
173 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
173 | \qmlsignal BarSet::onLabelColorChanged(color color) | |
174 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
174 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
175 | */ |
|
175 | */ | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | \fn void QBarSet::valuesAdded(int index, int count) |
|
178 | \fn void QBarSet::valuesAdded(int index, int count) | |
179 | This signal is emitted when new values have been added to the set. |
|
179 | This signal is emitted when new values have been added to the set. | |
180 | Parameter \a index indicates the position of the first inserted value. |
|
180 | Parameter \a index indicates the position of the first inserted value. | |
181 | Parameter \a count is the number of iserted values. |
|
181 | Parameter \a count is the number of iserted values. | |
182 | \sa append(), insert() |
|
182 | \sa append(), insert() | |
183 | */ |
|
183 | */ | |
184 | /*! |
|
184 | /*! | |
185 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
185 | \qmlsignal BarSet::onValuesAdded(int index, int count) | |
186 | This signal is emitted when new values have been added to the set. |
|
186 | This signal is emitted when new values have been added to the set. | |
187 | Parameter \a index indicates the position of the first inserted value. |
|
187 | Parameter \a index indicates the position of the first inserted value. | |
188 | Parameter \a count is the number of iserted values. |
|
188 | Parameter \a count is the number of iserted values. | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
192 | \fn void QBarSet::valuesRemoved(int index, int count) | |
193 | This signal is emitted values have been removed from the set. |
|
193 | This signal is emitted values have been removed from the set. | |
194 | Parameter \a index indicates the position of the first removed value. |
|
194 | Parameter \a index indicates the position of the first removed value. | |
195 | Parameter \a count is the number of removed values. |
|
195 | Parameter \a count is the number of removed values. | |
196 | \sa remove() |
|
196 | \sa remove() | |
197 | */ |
|
197 | */ | |
198 | /*! |
|
198 | /*! | |
199 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
199 | \qmlsignal BarSet::onValuesRemoved(int index, int count) | |
200 | This signal is emitted values have been removed from the set. |
|
200 | This signal is emitted values have been removed from the set. | |
201 | Parameter \a index indicates the position of the first removed value. |
|
201 | Parameter \a index indicates the position of the first removed value. | |
202 | Parameter \a count is the number of removed values. |
|
202 | Parameter \a count is the number of removed values. | |
203 | */ |
|
203 | */ | |
204 |
|
204 | |||
205 | /*! |
|
205 | /*! | |
206 | \fn void QBarSet::valueChanged(int index) |
|
206 | \fn void QBarSet::valueChanged(int index) | |
207 | This signal is emitted values the value in the set has been modified. |
|
207 | This signal is emitted values the value in the set has been modified. | |
208 | Parameter \a index indicates the position of the modified value. |
|
208 | Parameter \a index indicates the position of the modified value. | |
209 | \sa at() |
|
209 | \sa at() | |
210 | */ |
|
210 | */ | |
211 | /*! |
|
211 | /*! | |
212 | \qmlsignal BarSet::onValueChanged(int index) |
|
212 | \qmlsignal BarSet::onValueChanged(int index) | |
213 | This signal is emitted values the value in the set has been modified. |
|
213 | This signal is emitted values the value in the set has been modified. | |
214 | Parameter \a index indicates the position of the modified value. |
|
214 | Parameter \a index indicates the position of the modified value. | |
215 | */ |
|
215 | */ | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
218 | Constructs QBarSet with a label of \a label and with parent of \a parent | |
219 | */ |
|
219 | */ | |
220 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
220 | QBarSet::QBarSet(const QString label, QObject *parent) | |
221 | : QObject(parent) |
|
221 | : QObject(parent) | |
222 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
222 | ,d_ptr(new QBarSetPrivate(label,this)) | |
223 | { |
|
223 | { | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | /*! |
|
226 | /*! | |
227 | Destroys the barset |
|
227 | Destroys the barset | |
228 | */ |
|
228 | */ | |
229 | QBarSet::~QBarSet() |
|
229 | QBarSet::~QBarSet() | |
230 | { |
|
230 | { | |
231 | // NOTE: d_ptr destroyed by QObject |
|
231 | // NOTE: d_ptr destroyed by QObject | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | Sets new \a label for set. |
|
235 | Sets new \a label for set. | |
236 | */ |
|
236 | */ | |
237 | void QBarSet::setLabel(const QString label) |
|
237 | void QBarSet::setLabel(const QString label) | |
238 | { |
|
238 | { | |
239 | d_ptr->m_label = label; |
|
239 | d_ptr->m_label = label; | |
240 | emit labelChanged(); |
|
240 | emit labelChanged(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Returns label of the set. |
|
244 | Returns label of the set. | |
245 | */ |
|
245 | */ | |
246 | QString QBarSet::label() const |
|
246 | QString QBarSet::label() const | |
247 | { |
|
247 | { | |
248 | return d_ptr->m_label; |
|
248 | return d_ptr->m_label; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | /*! |
|
251 | /*! | |
252 | Appends a point to set. Parameter \a value x coordinate defines the |
|
252 | Appends a point to set. Parameter \a value x coordinate defines the | |
253 | position in x-axis and y coordinate defines the height of bar. |
|
253 | position in x-axis and y coordinate defines the height of bar. | |
254 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) |
|
254 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) | |
255 | the x values are used or ignored. |
|
255 | the x values are used or ignored. | |
256 | */ |
|
256 | */ | |
257 | void QBarSet::append(const QPointF value) |
|
257 | void QBarSet::append(const QPointF value) | |
258 | { |
|
258 | { | |
259 | int index = d_ptr->m_values.count(); |
|
259 | int index = d_ptr->m_values.count(); | |
260 | d_ptr->append(value); |
|
260 | d_ptr->append(value); | |
261 | emit valuesAdded(index, 1); |
|
261 | emit valuesAdded(index, 1); | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | /*! |
|
264 | /*! | |
265 | Appends a list of \a values to set. Works like append with single point. |
|
265 | Appends a list of \a values to set. Works like append with single point. | |
266 | \sa append() |
|
266 | \sa append() | |
267 | */ |
|
267 | */ | |
268 | void QBarSet::append(const QList<QPointF> &values) |
|
268 | void QBarSet::append(const QList<QPointF> &values) | |
269 | { |
|
269 | { | |
270 | int index = d_ptr->m_values.count(); |
|
270 | int index = d_ptr->m_values.count(); | |
271 | d_ptr->append(values); |
|
271 | d_ptr->append(values); | |
272 | emit valuesAdded(index, values.count()); |
|
272 | emit valuesAdded(index, values.count()); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, |
|
276 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, | |
277 | with x coordinate being the index of appended value and y coordinate is the value. |
|
277 | with x coordinate being the index of appended value and y coordinate is the value. | |
278 | */ |
|
278 | */ | |
279 | void QBarSet::append(const qreal value) |
|
279 | void QBarSet::append(const qreal value) | |
280 | { |
|
280 | { | |
281 | // Convert to QPointF and use other append(QPointF) method. |
|
281 | // Convert to QPointF and use other append(QPointF) method. | |
282 | append(QPointF(d_ptr->m_values.count(), value)); |
|
282 | append(QPointF(d_ptr->m_values.count(), value)); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | /*! |
|
285 | /*! | |
286 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
286 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
287 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. |
|
287 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. | |
288 | \sa append() |
|
288 | \sa append() | |
289 | */ |
|
289 | */ | |
290 | void QBarSet::append(const QList<qreal> &values) |
|
290 | void QBarSet::append(const QList<qreal> &values) | |
291 | { |
|
291 | { | |
292 | int index = d_ptr->m_values.count(); |
|
292 | int index = d_ptr->m_values.count(); | |
293 | d_ptr->append(values); |
|
293 | d_ptr->append(values); | |
294 | emit valuesAdded(index, values.count()); |
|
294 | emit valuesAdded(index, values.count()); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | /*! |
|
297 | /*! | |
298 | Convinience operator. Same as append, with real \a value. |
|
298 | Convinience operator. Same as append, with real \a value. | |
299 | \sa append() |
|
299 | \sa append() | |
300 | */ |
|
300 | */ | |
301 | QBarSet& QBarSet::operator << (const qreal &value) |
|
301 | QBarSet& QBarSet::operator << (const qreal &value) | |
302 | { |
|
302 | { | |
303 | append(value); |
|
303 | append(value); | |
304 | return *this; |
|
304 | return *this; | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | /*! |
|
307 | /*! | |
308 | Convinience operator. Same as append, with QPointF \a value. |
|
308 | Convinience operator. Same as append, with QPointF \a value. | |
309 | \sa append() |
|
309 | \sa append() | |
310 | */ |
|
310 | */ | |
311 | QBarSet& QBarSet::operator << (const QPointF &value) |
|
311 | QBarSet& QBarSet::operator << (const QPointF &value) | |
312 | { |
|
312 | { | |
313 | append(value); |
|
313 | append(value); | |
314 | return *this; |
|
314 | return *this; | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | /*! |
|
317 | /*! | |
318 | Inserts new \a value on the \a index position. |
|
318 | Inserts new \a value on the \a index position. | |
319 | The value that is currently at this postion is moved to postion index + 1 |
|
319 | The value that is currently at this postion is moved to postion index + 1 | |
320 | \sa remove() |
|
320 | \sa remove() | |
321 | */ |
|
321 | */ | |
322 | void QBarSet::insert(const int index, const qreal value) |
|
322 | void QBarSet::insert(const int index, const qreal value) | |
323 | { |
|
323 | { | |
324 | d_ptr->insert(index, value); |
|
324 | d_ptr->insert(index, value); | |
325 | emit valuesAdded(index,1); |
|
325 | emit valuesAdded(index,1); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | /*! |
|
328 | /*! | |
329 | Inserts new \a value on the \a index position. |
|
329 | Inserts new \a value on the \a index position. | |
330 | The value that is currently at this postion is moved to postion index + 1 |
|
330 | The value that is currently at this postion is moved to postion index + 1 | |
331 | \sa remove() |
|
331 | \sa remove() | |
332 | */ |
|
332 | */ | |
333 | void QBarSet::insert(const int index, const QPointF value) |
|
333 | void QBarSet::insert(const int index, const QPointF value) | |
334 | { |
|
334 | { | |
335 | d_ptr->insert(index,value); |
|
335 | d_ptr->insert(index,value); | |
336 | emit valuesAdded(index,1); |
|
336 | emit valuesAdded(index,1); | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | /*! |
|
339 | /*! | |
340 | Removes \a count number of values from the set starting at \a index. |
|
340 | Removes \a count number of values from the set starting at \a index. | |
341 | Returns true if remove operation was succesfull. |
|
341 | Returns true if remove operation was succesfull. | |
342 | \sa insert() |
|
342 | \sa insert() | |
343 | */ |
|
343 | */ | |
344 | bool QBarSet::remove(const int index, const int count) |
|
344 | bool QBarSet::remove(const int index, const int count) | |
345 | { |
|
345 | { | |
346 | bool success = d_ptr->remove(index,count); |
|
346 | bool success = d_ptr->remove(index,count); | |
347 | if (success) { |
|
347 | if (success) { | |
348 | emit valuesRemoved(index,count); |
|
348 | emit valuesRemoved(index,count); | |
349 | } |
|
349 | } | |
350 | return success; |
|
350 | return success; | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | /*! |
|
353 | /*! | |
354 | Sets a new value \a value to set, indexed by \a index |
|
354 | Sets a new value \a value to set, indexed by \a index | |
355 | */ |
|
355 | */ | |
356 | void QBarSet::replace(const int index, const qreal value) |
|
356 | void QBarSet::replace(const int index, const qreal value) | |
357 | { |
|
357 | { | |
358 | d_ptr->replace(index,value); |
|
358 | d_ptr->replace(index,value); | |
359 | emit valueChanged(index); |
|
359 | emit valueChanged(index); | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | /*! |
|
362 | /*! | |
363 | Sets a new value \a value to set, indexed by \a index |
|
363 | Sets a new value \a value to set, indexed by \a index | |
364 | */ |
|
364 | */ | |
365 | void QBarSet::replace(const int index, const QPointF value) |
|
365 | void QBarSet::replace(const int index, const QPointF value) | |
366 | { |
|
366 | { | |
367 | d_ptr->replace(index,value); |
|
367 | d_ptr->replace(index,value); | |
368 | emit valueChanged(index); |
|
368 | emit valueChanged(index); | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | /*! |
|
371 | /*! | |
372 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. |
|
372 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. | |
373 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
373 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |
374 | of the QPointF (if appended with QPointF append). |
|
374 | of the QPointF (if appended with QPointF append). | |
375 | If the index is out of bounds QPointF(0, 0.0) is returned. |
|
375 | If the index is out of bounds QPointF(0, 0.0) is returned. | |
376 | */ |
|
376 | */ | |
377 | QPointF QBarSet::at(const int index) const |
|
377 | QPointF QBarSet::at(const int index) const | |
378 | { |
|
378 | { | |
379 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
379 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
380 | return QPointF(index, 0.0); |
|
380 | return QPointF(index, 0.0); | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | return d_ptr->m_values.at(index); |
|
383 | return d_ptr->m_values.at(index); | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | /*! |
|
386 | /*! | |
387 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. |
|
387 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. | |
388 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
388 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |
389 | of the QPointF (if appended with QPointF append). |
|
389 | of the QPointF (if appended with QPointF append). | |
390 | */ |
|
390 | */ | |
391 | QPointF QBarSet::operator [](const int index) const |
|
391 | QPointF QBarSet::operator [](const int index) const | |
392 | { |
|
392 | { | |
393 | return d_ptr->m_values.at(index); |
|
393 | return d_ptr->m_values.at(index); | |
394 | } |
|
394 | } | |
395 |
|
395 | |||
396 | /*! |
|
396 | /*! | |
397 | Returns count of values in set. |
|
397 | Returns count of values in set. | |
398 | */ |
|
398 | */ | |
399 | int QBarSet::count() const |
|
399 | int QBarSet::count() const | |
400 | { |
|
400 | { | |
401 | return d_ptr->m_values.count(); |
|
401 | return d_ptr->m_values.count(); | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | /*! |
|
404 | /*! | |
405 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. |
|
405 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. | |
406 | */ |
|
406 | */ | |
407 | qreal QBarSet::sum() const |
|
407 | qreal QBarSet::sum() const | |
408 | { |
|
408 | { | |
409 | qreal total(0); |
|
409 | qreal total(0); | |
410 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
410 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
411 | //total += d_ptr->m_values.at(i); |
|
411 | //total += d_ptr->m_values.at(i); | |
412 | total += d_ptr->m_values.at(i).y(); |
|
412 | total += d_ptr->m_values.at(i).y(); | |
413 | } |
|
413 | } | |
414 | return total; |
|
414 | return total; | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | /*! |
|
417 | /*! | |
418 | Sets pen for set. Bars of this set are drawn using \a pen |
|
418 | Sets pen for set. Bars of this set are drawn using \a pen | |
419 | */ |
|
419 | */ | |
420 | void QBarSet::setPen(const QPen &pen) |
|
420 | void QBarSet::setPen(const QPen &pen) | |
421 | { |
|
421 | { | |
422 | if(d_ptr->m_pen!=pen){ |
|
422 | if(d_ptr->m_pen!=pen){ | |
423 | d_ptr->m_pen = pen; |
|
423 | d_ptr->m_pen = pen; | |
424 | emit d_ptr->updatedBars(); |
|
424 | emit d_ptr->updatedBars(); | |
425 | emit penChanged(); |
|
425 | emit penChanged(); | |
426 | } |
|
426 | } | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | /*! |
|
429 | /*! | |
430 | Returns pen of the set. |
|
430 | Returns pen of the set. | |
431 | */ |
|
431 | */ | |
432 | QPen QBarSet::pen() const |
|
432 | QPen QBarSet::pen() const | |
433 | { |
|
433 | { | |
434 | return d_ptr->m_pen; |
|
434 | return d_ptr->m_pen; | |
435 | } |
|
435 | } | |
436 |
|
436 | |||
437 | /*! |
|
437 | /*! | |
438 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
438 | Sets brush for the set. Bars of this set are drawn using \a brush | |
439 | */ |
|
439 | */ | |
440 | void QBarSet::setBrush(const QBrush &brush) |
|
440 | void QBarSet::setBrush(const QBrush &brush) | |
441 | { |
|
441 | { | |
442 | if(d_ptr->m_brush!=brush){ |
|
442 | if(d_ptr->m_brush!=brush){ | |
443 | d_ptr->m_brush = brush; |
|
443 | d_ptr->m_brush = brush; | |
444 | emit d_ptr->updatedBars(); |
|
444 | emit d_ptr->updatedBars(); | |
445 | emit brushChanged(); |
|
445 | emit brushChanged(); | |
446 | } |
|
446 | } | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | /*! |
|
449 | /*! | |
450 | Returns brush of the set. |
|
450 | Returns brush of the set. | |
451 | */ |
|
451 | */ | |
452 | QBrush QBarSet::brush() const |
|
452 | QBrush QBarSet::brush() const | |
453 | { |
|
453 | { | |
454 | return d_ptr->m_brush; |
|
454 | return d_ptr->m_brush; | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | /*! |
|
457 | /*! | |
458 | Sets \a brush of the values that are drawn on top of this barset |
|
458 | Sets \a brush of the values that are drawn on top of this barset | |
459 | */ |
|
459 | */ | |
460 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
460 | void QBarSet::setLabelBrush(const QBrush &brush) | |
461 | { |
|
461 | { | |
462 | if(d_ptr->m_labelBrush!=brush){ |
|
462 | if(d_ptr->m_labelBrush!=brush){ | |
463 | d_ptr->m_labelBrush = brush; |
|
463 | d_ptr->m_labelBrush = brush; | |
464 | emit d_ptr->updatedBars(); |
|
464 | emit d_ptr->updatedBars(); | |
465 | emit labelBrushChanged(); |
|
465 | emit labelBrushChanged(); | |
466 | } |
|
466 | } | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | /*! |
|
469 | /*! | |
470 | Returns brush of the values that are drawn on top of this barset |
|
470 | Returns brush of the values that are drawn on top of this barset | |
471 | */ |
|
471 | */ | |
472 | QBrush QBarSet::labelBrush() const |
|
472 | QBrush QBarSet::labelBrush() const | |
473 | { |
|
473 | { | |
474 | return d_ptr->m_labelBrush; |
|
474 | return d_ptr->m_labelBrush; | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | /*! |
|
477 | /*! | |
478 | Sets the \a font for values that are drawn on top of this barset |
|
478 | Sets the \a font for values that are drawn on top of this barset | |
479 | */ |
|
479 | */ | |
480 | void QBarSet::setLabelFont(const QFont &font) |
|
480 | void QBarSet::setLabelFont(const QFont &font) | |
481 | { |
|
481 | { | |
482 | if(d_ptr->m_labelFont!=font) { |
|
482 | if(d_ptr->m_labelFont!=font) { | |
483 | d_ptr->m_labelFont = font; |
|
483 | d_ptr->m_labelFont = font; | |
484 | emit d_ptr->updatedBars(); |
|
484 | emit d_ptr->updatedBars(); | |
485 | emit labelFontChanged(); |
|
485 | emit labelFontChanged(); | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | /*! |
|
490 | /*! | |
491 | Returns the pen for values that are drawn on top of this barset |
|
491 | Returns the pen for values that are drawn on top of this barset | |
492 | */ |
|
492 | */ | |
493 | QFont QBarSet::labelFont() const |
|
493 | QFont QBarSet::labelFont() const | |
494 | { |
|
494 | { | |
495 | return d_ptr->m_labelFont; |
|
495 | return d_ptr->m_labelFont; | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | /*! |
|
498 | /*! | |
499 | Returns the color of the brush of barset. |
|
499 | Returns the color of the brush of barset. | |
500 | */ |
|
500 | */ | |
501 | QColor QBarSet::color() |
|
501 | QColor QBarSet::color() | |
502 | { |
|
502 | { | |
503 | return brush().color(); |
|
503 | return brush().color(); | |
504 | } |
|
504 | } | |
505 |
|
505 | |||
506 | /*! |
|
506 | /*! | |
507 | Sets the \a color of brush for this barset |
|
507 | Sets the \a color of brush for this barset | |
508 | */ |
|
508 | */ | |
509 | void QBarSet::setColor(QColor color) |
|
509 | void QBarSet::setColor(QColor color) | |
510 | { |
|
510 | { | |
511 | QBrush b = brush(); |
|
511 | QBrush b = brush(); | |
512 | if (b.color() != color) { |
|
512 | if (b.color() != color) { | |
513 | b.setColor(color); |
|
513 | b.setColor(color); | |
514 | setBrush(b); |
|
514 | setBrush(b); | |
515 | emit colorChanged(color); |
|
515 | emit colorChanged(color); | |
516 | } |
|
516 | } | |
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | /*! |
|
519 | /*! | |
520 | Returns the color of pen of this barset |
|
520 | Returns the color of pen of this barset | |
521 | */ |
|
521 | */ | |
522 | QColor QBarSet::borderColor() |
|
522 | QColor QBarSet::borderColor() | |
523 | { |
|
523 | { | |
524 | return pen().color(); |
|
524 | return pen().color(); | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | /*! |
|
527 | /*! | |
528 | Sets the color of pen for this barset |
|
528 | Sets the color of pen for this barset | |
529 | */ |
|
529 | */ | |
530 | void QBarSet::setBorderColor(QColor color) |
|
530 | void QBarSet::setBorderColor(QColor color) | |
531 | { |
|
531 | { | |
532 | QPen p = pen(); |
|
532 | QPen p = pen(); | |
533 | if (p.color() != color) { |
|
533 | if (p.color() != color) { | |
534 | p.setColor(color); |
|
534 | p.setColor(color); | |
535 | setPen(p); |
|
535 | setPen(p); | |
536 | emit borderColorChanged(color); |
|
536 | emit borderColorChanged(color); | |
537 | } |
|
537 | } | |
538 | } |
|
538 | } | |
539 |
|
539 | |||
540 | /*! |
|
540 | /*! | |
541 | Returns the color of labels of this barset |
|
541 | Returns the color of labels of this barset | |
542 | */ |
|
542 | */ | |
543 | QColor QBarSet::labelColor() |
|
543 | QColor QBarSet::labelColor() | |
544 | { |
|
544 | { | |
545 | return labelBrush().color(); |
|
545 | return labelBrush().color(); | |
546 | } |
|
546 | } | |
547 |
|
547 | |||
548 | /*! |
|
548 | /*! | |
549 | Sets the color of labels for this barset |
|
549 | Sets the color of labels for this barset | |
550 | */ |
|
550 | */ | |
551 | void QBarSet::setLabelColor(QColor color) |
|
551 | void QBarSet::setLabelColor(QColor color) | |
552 | { |
|
552 | { | |
553 | QBrush b = labelBrush(); |
|
553 | QBrush b = labelBrush(); | |
554 | if (b.color() != color) { |
|
554 | if (b.color() != color) { | |
555 | b.setColor(color); |
|
555 | b.setColor(color); | |
556 | setLabelBrush(b); |
|
556 | setLabelBrush(b); | |
557 | emit labelColorChanged(color); |
|
557 | emit labelColorChanged(color); | |
558 | } |
|
558 | } | |
559 | } |
|
559 | } | |
560 |
|
560 | |||
561 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
561 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
562 |
|
562 | |||
563 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
563 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
564 | q_ptr(parent), |
|
564 | q_ptr(parent), | |
565 | m_label(label) |
|
565 | m_label(label) | |
566 | { |
|
566 | { | |
567 | } |
|
567 | } | |
568 |
|
568 | |||
569 | QBarSetPrivate::~QBarSetPrivate() |
|
569 | QBarSetPrivate::~QBarSetPrivate() | |
570 | { |
|
570 | { | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 | void QBarSetPrivate::append(QPointF value) |
|
573 | void QBarSetPrivate::append(QPointF value) | |
574 | { |
|
574 | { | |
575 | m_values.append(value); |
|
575 | m_values.append(value); | |
576 | emit restructuredBars(); |
|
576 | emit restructuredBars(); | |
577 | } |
|
577 | } | |
578 |
|
578 | |||
579 | void QBarSetPrivate::append(QList<QPointF> values) |
|
579 | void QBarSetPrivate::append(QList<QPointF> values) | |
580 | { |
|
580 | { | |
581 | for (int i=0; i<values.count(); i++) { |
|
581 | for (int i=0; i<values.count(); i++) { | |
582 | m_values.append(values.at(i)); |
|
582 | m_values.append(values.at(i)); | |
583 | } |
|
583 | } | |
584 | emit restructuredBars(); |
|
584 | emit restructuredBars(); | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | void QBarSetPrivate::append(QList<qreal> values) |
|
587 | void QBarSetPrivate::append(QList<qreal> values) | |
588 | { |
|
588 | { | |
589 | int index = m_values.count(); |
|
589 | int index = m_values.count(); | |
590 | for (int i=0; i<values.count(); i++) { |
|
590 | for (int i=0; i<values.count(); i++) { | |
591 | m_values.append(QPointF(index,values.at(i))); |
|
591 | m_values.append(QPointF(index,values.at(i))); | |
592 | index++; |
|
592 | index++; | |
593 | } |
|
593 | } | |
594 | emit restructuredBars(); |
|
594 | emit restructuredBars(); | |
595 | } |
|
595 | } | |
596 |
|
596 | |||
597 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
597 | void QBarSetPrivate::insert(const int index, const qreal value) | |
598 | { |
|
598 | { | |
599 | m_values.insert(index, QPointF(index, value)); |
|
599 | m_values.insert(index, QPointF(index, value)); | |
600 | emit restructuredBars(); |
|
600 | emit restructuredBars(); | |
601 | } |
|
601 | } | |
602 |
|
602 | |||
603 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
603 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
604 | { |
|
604 | { | |
605 | m_values.insert(index, value); |
|
605 | m_values.insert(index, value); | |
606 | emit restructuredBars(); |
|
606 | emit restructuredBars(); | |
607 | } |
|
607 | } | |
608 |
|
608 | |||
609 | bool QBarSetPrivate::remove(const int index, const int count) |
|
609 | bool QBarSetPrivate::remove(const int index, const int count) | |
610 | { |
|
610 | { | |
611 | if ((index + count) > m_values.count()) { |
|
611 | if ((index + count) > m_values.count()) { | |
612 | // cant remove more values than there are |
|
612 | // cant remove more values than there are | |
613 | return false; |
|
613 | return false; | |
614 | } |
|
614 | } | |
615 | int c = count; |
|
615 | int c = count; | |
616 | while (c > 0) { |
|
616 | while (c > 0) { | |
617 | m_values.removeAt(index); |
|
617 | m_values.removeAt(index); | |
618 | c--; |
|
618 | c--; | |
619 | } |
|
619 | } | |
620 | emit restructuredBars(); |
|
620 | emit restructuredBars(); | |
621 | return true; |
|
621 | return true; | |
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
624 | void QBarSetPrivate::replace(const int index, const qreal value) | |
625 | { |
|
625 | { | |
626 | m_values.replace(index,QPointF(index,value)); |
|
626 | m_values.replace(index,QPointF(index,value)); | |
627 | emit updatedBars(); |
|
627 | emit updatedBars(); | |
628 | } |
|
628 | } | |
629 |
|
629 | |||
630 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
630 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
631 | { |
|
631 | { | |
632 | m_values.replace(index,value); |
|
632 | m_values.replace(index,value); | |
633 | emit updatedBars(); |
|
633 | emit updatedBars(); | |
634 | } |
|
634 | } | |
635 |
|
635 | |||
636 | #include "moc_qbarset.cpp" |
|
636 | #include "moc_qbarset.cpp" | |
637 | #include "moc_qbarset_p.cpp" |
|
637 | #include "moc_qbarset_p.cpp" | |
638 |
|
638 | |||
639 | QTCOMMERCIALCHART_END_NAMESPACE |
|
639 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,116 +1,116 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qgroupedbarseries.h" |
|
21 | #include "qgroupedbarseries.h" | |
22 | #include "qgroupedbarseries_p.h" |
|
22 | #include "qgroupedbarseries_p.h" | |
23 | #include "groupedbarchartitem_p.h" |
|
23 | #include "groupedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QGroupedBarSeries |
|
31 | \class QGroupedBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief Series for creating grouped bar chart | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
35 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data |
|
36 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data | |
37 | from sets to categories, which are defined by a QStringList. |
|
37 | from sets to categories, which are defined by a QStringList. | |
38 |
|
38 | |||
39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. | |
40 | \image examples_groupedbarchart.png |
|
40 | \image examples_groupedbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries |
|
42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries | |
43 | */ |
|
43 | */ | |
44 | /*! |
|
44 | /*! | |
45 | \qmlclass GroupedBarSeries QGroupedBarSeries |
|
45 | \qmlclass GroupedBarSeries QGroupedBarSeries | |
46 | \inherits BarSeries |
|
46 | \inherits BarSeries | |
47 |
|
47 | |||
48 | The following QML shows how to create a simple grouped bar chart: |
|
48 | The following QML shows how to create a simple grouped bar chart: | |
49 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
49 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
50 | \beginfloatleft |
|
50 | \beginfloatleft | |
51 | \image demos_qmlchart7.png |
|
51 | \image demos_qmlchart7.png | |
52 | \endfloat |
|
52 | \endfloat | |
53 | \clearfloat |
|
53 | \clearfloat | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | Constructs empty QGroupedBarSeries. |
|
57 | Constructs empty QGroupedBarSeries. | |
58 | QGroupedBarSeries is QObject which is a child of a \a parent. |
|
58 | QGroupedBarSeries is QObject which is a child of a \a parent. | |
59 | */ |
|
59 | */ | |
60 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) |
|
60 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) | |
61 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) |
|
61 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) | |
62 | { |
|
62 | { | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | Returns QChartSeries::SeriesTypeGroupedBar. |
|
66 | Returns QChartSeries::SeriesTypeGroupedBar. | |
67 | */ |
|
67 | */ | |
68 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const |
|
68 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const | |
69 | { |
|
69 | { | |
70 | return QAbstractSeries::SeriesTypeGroupedBar; |
|
70 | return QAbstractSeries::SeriesTypeGroupedBar; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
74 |
|
74 | |||
75 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q) |
|
75 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q) | |
76 | { |
|
76 | { | |
77 |
|
77 | |||
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
80 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) | |
81 | { |
|
81 | { | |
82 | qreal minX(domain.minX()); |
|
82 | qreal minX(domain.minX()); | |
83 | qreal minY(domain.minY()); |
|
83 | qreal minY(domain.minY()); | |
84 | qreal maxX(domain.maxX()); |
|
84 | qreal maxX(domain.maxX()); | |
85 | qreal maxY(domain.maxY()); |
|
85 | qreal maxY(domain.maxY()); | |
86 | int tickXCount(domain.tickXCount()); |
|
86 | int tickXCount(domain.tickXCount()); | |
87 | int tickYCount(domain.tickYCount()); |
|
87 | int tickYCount(domain.tickYCount()); | |
88 |
|
88 | |||
89 | qreal x = categoryCount(); |
|
89 | qreal x = categoryCount(); | |
90 | qreal y = max(); |
|
90 | qreal y = max(); | |
91 | minX = qMin(minX, -0.5); |
|
91 | minX = qMin(minX, -0.5); | |
92 | minY = qMin(minY, y); |
|
92 | minY = qMin(minY, y); | |
93 | maxX = qMax(maxX, x - 0.5); |
|
93 | maxX = qMax(maxX, x - 0.5); | |
94 | maxY = qMax(maxY, y); |
|
94 | maxY = qMax(maxY, y); | |
95 | tickXCount = x+1; |
|
95 | tickXCount = x+1; | |
96 |
|
96 | |||
97 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
97 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 |
|
100 | |||
101 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
101 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
102 | { |
|
102 | { | |
103 | Q_Q(QGroupedBarSeries); |
|
103 | Q_Q(QGroupedBarSeries); | |
104 |
|
104 | |||
105 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
105 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); | |
106 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
106 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
107 | presenter->animator()->addAnimation(bar); |
|
107 | presenter->animator()->addAnimation(bar); | |
108 | } |
|
108 | } | |
109 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
109 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
110 | return bar; |
|
110 | return bar; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | #include "moc_qgroupedbarseries.cpp" |
|
113 | #include "moc_qgroupedbarseries.cpp" | |
114 |
|
114 | |||
115 | QTCOMMERCIALCHART_END_NAMESPACE |
|
115 | QTCOMMERCIALCHART_END_NAMESPACE | |
116 |
|
116 |
@@ -1,199 +1,199 | |||||
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 "qhbarmodelmapper.h" |
|
21 | #include "qhbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHBarModelMapper |
|
26 | \class QHBarModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief Horizontal model mapper for bar series | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
31 | Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass HBarModelMapper QHBarModelMapper |
|
37 | \qmlclass HBarModelMapper QHBarModelMapper | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
40 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source | |
41 | for any bar series. Adding/removing value from the BarSet causes the the same change in the rest of the BarSets |
|
41 | for any bar series. Adding/removing value from the BarSet causes the the same change in the rest of the BarSets | |
42 | added to the same series. The following QML example would create a bar series with three bar sets (assuming the |
|
42 | added to the same series. The following QML example would create a bar series with three bar sets (assuming the | |
43 | model has at least four rows). Each bar set would contain data starting from column 1. The name of a set would be |
|
43 | model has at least four rows). Each bar set would contain data starting from column 1. The name of a set would be | |
44 | defined by the vertical header (of the row). |
|
44 | defined by the vertical header (of the row). | |
45 | \code |
|
45 | \code | |
46 | BarSeries { |
|
46 | BarSeries { | |
47 | HBarModelMapper { |
|
47 | HBarModelMapper { | |
48 | model: myCustomModel // QAbstractItemModel derived implementation |
|
48 | model: myCustomModel // QAbstractItemModel derived implementation | |
49 | firstBarSetRow: 1 |
|
49 | firstBarSetRow: 1 | |
50 | lastBarSetRow: 3 |
|
50 | lastBarSetRow: 3 | |
51 | firstColumn: 1 |
|
51 | firstColumn: 1 | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \qmlproperty BarSeries HBarModelMapper::series |
|
58 | \qmlproperty BarSeries HBarModelMapper::series | |
59 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
59 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
60 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
60 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty Model HBarModelMapper::model |
|
64 | \qmlproperty Model HBarModelMapper::model | |
65 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
65 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
66 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
66 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
67 | and modifying the data of the cells. |
|
67 | and modifying the data of the cells. | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \property QHBarModelMapper::firstBarSetRow |
|
71 | \property QHBarModelMapper::firstBarSetRow | |
72 | \brief Defines which column of the model is used as the data source for the first bar set |
|
72 | \brief Defines which column of the model is used as the data source for the first bar set | |
73 | Default value is: -1 (invalid mapping) |
|
73 | Default value is: -1 (invalid mapping) | |
74 | */ |
|
74 | */ | |
75 | /*! |
|
75 | /*! | |
76 | \qmlproperty int HBarModelMapper::firstBarSetRow |
|
76 | \qmlproperty int HBarModelMapper::firstBarSetRow | |
77 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 |
|
77 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 | |
78 | (invalid mapping). |
|
78 | (invalid mapping). | |
79 | */ |
|
79 | */ | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | \property QHBarModelMapper::lastBarSetRow |
|
82 | \property QHBarModelMapper::lastBarSetRow | |
83 | \brief Defines which column of the model is used as the data source for the last bar set |
|
83 | \brief Defines which column of the model is used as the data source for the last bar set | |
84 | Default value is: -1 (invalid mapping) |
|
84 | Default value is: -1 (invalid mapping) | |
85 | */ |
|
85 | */ | |
86 | /*! |
|
86 | /*! | |
87 | \qmlproperty int HBarModelMapper::lastBarSetRow |
|
87 | \qmlproperty int HBarModelMapper::lastBarSetRow | |
88 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 |
|
88 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 | |
89 | (invalid mapping). |
|
89 | (invalid mapping). | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \property QHBarModelMapper::firstColumn |
|
93 | \property QHBarModelMapper::firstColumn | |
94 | \brief Defines which column of the model contains the first values of the QBarSets in the series. |
|
94 | \brief Defines which column of the model contains the first values of the QBarSets in the series. | |
95 | Minimal and default value is: 0 |
|
95 | Minimal and default value is: 0 | |
96 | */ |
|
96 | */ | |
97 | /*! |
|
97 | /*! | |
98 | \qmlproperty int HBarModelMapper::firstColumn |
|
98 | \qmlproperty int HBarModelMapper::firstColumn | |
99 | Defines which column of the model contains the first values of the QBarSets in the series. |
|
99 | Defines which column of the model contains the first values of the QBarSets in the series. | |
100 | The default value is 0. |
|
100 | The default value is 0. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \property QHBarModelMapper::columnCount |
|
104 | \property QHBarModelMapper::columnCount | |
105 | \brief Defines the number of columns of the model that are mapped as the data for QBarSeries |
|
105 | \brief Defines the number of columns of the model that are mapped as the data for QBarSeries | |
106 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
106 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |
107 | */ |
|
107 | */ | |
108 | /*! |
|
108 | /*! | |
109 | \qmlproperty int HBarModelMapper::columnCount |
|
109 | \qmlproperty int HBarModelMapper::columnCount | |
110 | Defines the number of columns of the model that are mapped as the data for QBarSeries. The default value is |
|
110 | Defines the number of columns of the model that are mapped as the data for QBarSeries. The default value is | |
111 | -1 (count limited by the number of columns in the model) |
|
111 | -1 (count limited by the number of columns in the model) | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
|
115 | \fn void QHBarModelMapper::firstBarSetRowChanged() | |
116 |
|
116 | |||
117 | Emitted when the firstBarSetRow has changed. |
|
117 | Emitted when the firstBarSetRow has changed. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
|
121 | \fn void QHBarModelMapper::lastBarSetRowChanged() | |
122 |
|
122 | |||
123 | Emitted when the lastBarSetRow has changed. |
|
123 | Emitted when the lastBarSetRow has changed. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QHBarModelMapper::firstColumnChanged() |
|
127 | \fn void QHBarModelMapper::firstColumnChanged() | |
128 | Emitted when the firstColumn has changed. |
|
128 | Emitted when the firstColumn has changed. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \fn void QHBarModelMapper::columnCountChanged() |
|
132 | \fn void QHBarModelMapper::columnCountChanged() | |
133 | Emitted when the columnCount has changed. |
|
133 | Emitted when the columnCount has changed. | |
134 | */ |
|
134 | */ | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Constructs a mapper object which is a child of \a parent. |
|
137 | Constructs a mapper object which is a child of \a parent. | |
138 | */ |
|
138 | */ | |
139 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
139 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : | |
140 | QBarModelMapper(parent) |
|
140 | QBarModelMapper(parent) | |
141 | { |
|
141 | { | |
142 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
142 | QBarModelMapper::setOrientation(Qt::Horizontal); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | int QHBarModelMapper::firstBarSetRow() const |
|
145 | int QHBarModelMapper::firstBarSetRow() const | |
146 | { |
|
146 | { | |
147 | return QBarModelMapper::firstBarSetSection(); |
|
147 | return QBarModelMapper::firstBarSetSection(); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
150 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) | |
151 | { |
|
151 | { | |
152 | if (firstBarSetRow != firstBarSetSection()) { |
|
152 | if (firstBarSetRow != firstBarSetSection()) { | |
153 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
153 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); | |
154 | emit firstBarSetRowChanged(); |
|
154 | emit firstBarSetRowChanged(); | |
155 | } |
|
155 | } | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | int QHBarModelMapper::lastBarSetRow() const |
|
158 | int QHBarModelMapper::lastBarSetRow() const | |
159 | { |
|
159 | { | |
160 | return QBarModelMapper::lastBarSetSection(); |
|
160 | return QBarModelMapper::lastBarSetSection(); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
163 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) | |
164 | { |
|
164 | { | |
165 | if (lastBarSetRow != lastBarSetSection()) { |
|
165 | if (lastBarSetRow != lastBarSetSection()) { | |
166 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
166 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); | |
167 | emit lastBarSetRowChanged(); |
|
167 | emit lastBarSetRowChanged(); | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | int QHBarModelMapper::firstColumn() const |
|
171 | int QHBarModelMapper::firstColumn() const | |
172 | { |
|
172 | { | |
173 | return QBarModelMapper::first(); |
|
173 | return QBarModelMapper::first(); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void QHBarModelMapper::setFirstColumn(int firstColumn) |
|
176 | void QHBarModelMapper::setFirstColumn(int firstColumn) | |
177 | { |
|
177 | { | |
178 | if (firstColumn != first()) { |
|
178 | if (firstColumn != first()) { | |
179 | QBarModelMapper::setFirst(firstColumn); |
|
179 | QBarModelMapper::setFirst(firstColumn); | |
180 | emit firstColumnChanged(); |
|
180 | emit firstColumnChanged(); | |
181 | } |
|
181 | } | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | int QHBarModelMapper::columnCount() const |
|
184 | int QHBarModelMapper::columnCount() const | |
185 | { |
|
185 | { | |
186 | return QBarModelMapper::count(); |
|
186 | return QBarModelMapper::count(); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | void QHBarModelMapper::setColumnCount(int columnCount) |
|
189 | void QHBarModelMapper::setColumnCount(int columnCount) | |
190 | { |
|
190 | { | |
191 | if (columnCount != count()) { |
|
191 | if (columnCount != count()) { | |
192 | QBarModelMapper::setCount(columnCount); |
|
192 | QBarModelMapper::setCount(columnCount); | |
193 | emit firstColumnChanged(); |
|
193 | emit firstColumnChanged(); | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | #include "moc_qhbarmodelmapper.cpp" |
|
197 | #include "moc_qhbarmodelmapper.cpp" | |
198 |
|
198 | |||
199 | QTCOMMERCIALCHART_END_NAMESPACE |
|
199 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,115 +1,115 | |||||
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 "qpercentbarseries.h" |
|
21 | #include "qpercentbarseries.h" | |
22 | #include "qpercentbarseries_p.h" |
|
22 | #include "qpercentbarseries_p.h" | |
23 | #include "percentbarchartitem_p.h" |
|
23 | #include "percentbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QPercentBarSeries |
|
31 | \class QPercentBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief Series for creating percent bar chart | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
35 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
36 | as stacks, where each bar is shown as percentage of all bars in that category. | |
37 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
37 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. | |
38 |
|
38 | |||
39 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
39 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. | |
40 | \image examples_percentbarchart.png |
|
40 | \image examples_percentbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QStackedBarSeries, QBarSeries |
|
42 | \sa QBarSet, QStackedBarSeries, QBarSeries | |
43 | */ |
|
43 | */ | |
44 | /*! |
|
44 | /*! | |
45 | \qmlclass PercentBarSeries QPercentBarSeries |
|
45 | \qmlclass PercentBarSeries QPercentBarSeries | |
46 | \inherits BarSeries |
|
46 | \inherits BarSeries | |
47 |
|
47 | |||
48 | The following QML shows how to create a simple percent bar chart: |
|
48 | The following QML shows how to create a simple percent bar chart: | |
49 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 |
|
49 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 | |
50 | \beginfloatleft |
|
50 | \beginfloatleft | |
51 | \image demos_qmlchart9.png |
|
51 | \image demos_qmlchart9.png | |
52 | \endfloat |
|
52 | \endfloat | |
53 | \clearfloat |
|
53 | \clearfloat | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | Constructs empty QPercentBarSeries. |
|
57 | Constructs empty QPercentBarSeries. | |
58 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
58 | QPercentBarSeries is QObject which is a child of a \a parent. | |
59 | */ |
|
59 | */ | |
60 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
60 | QPercentBarSeries::QPercentBarSeries(QObject *parent) | |
61 | : QBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
61 | : QBarSeries(*new QPercentBarSeriesPrivate(this), parent) | |
62 | { |
|
62 | { | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | Returns QChartSeries::SeriesTypePercentBar. |
|
66 | Returns QChartSeries::SeriesTypePercentBar. | |
67 | */ |
|
67 | */ | |
68 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
68 | QAbstractSeries::SeriesType QPercentBarSeries::type() const | |
69 | { |
|
69 | { | |
70 | return QAbstractSeries::SeriesTypePercentBar; |
|
70 | return QAbstractSeries::SeriesTypePercentBar; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
74 |
|
74 | |||
75 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q) |
|
75 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q) | |
76 | { |
|
76 | { | |
77 |
|
77 | |||
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
80 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
81 | { |
|
81 | { | |
82 | qreal minX(domain.minX()); |
|
82 | qreal minX(domain.minX()); | |
83 | qreal minY(domain.minY()); |
|
83 | qreal minY(domain.minY()); | |
84 | qreal maxX(domain.maxX()); |
|
84 | qreal maxX(domain.maxX()); | |
85 | qreal maxY(domain.maxY()); |
|
85 | qreal maxY(domain.maxY()); | |
86 | int tickXCount(domain.tickXCount()); |
|
86 | int tickXCount(domain.tickXCount()); | |
87 | int tickYCount(domain.tickYCount()); |
|
87 | int tickYCount(domain.tickYCount()); | |
88 |
|
88 | |||
89 | qreal x = categoryCount(); |
|
89 | qreal x = categoryCount(); | |
90 | minX = qMin(minX, -0.5); |
|
90 | minX = qMin(minX, -0.5); | |
91 | maxX = qMax(maxX, x - 0.5); |
|
91 | maxX = qMax(maxX, x - 0.5); | |
92 | minY = 0; |
|
92 | minY = 0; | |
93 | maxY = 100; |
|
93 | maxY = 100; | |
94 | tickXCount = x+1; |
|
94 | tickXCount = x+1; | |
95 |
|
95 | |||
96 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
96 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 |
|
99 | |||
100 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
100 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
101 | { |
|
101 | { | |
102 | Q_Q(QPercentBarSeries); |
|
102 | Q_Q(QPercentBarSeries); | |
103 |
|
103 | |||
104 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
104 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); | |
105 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
105 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
106 | presenter->animator()->addAnimation(bar); |
|
106 | presenter->animator()->addAnimation(bar); | |
107 | } |
|
107 | } | |
108 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
108 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
109 | return bar; |
|
109 | return bar; | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | #include "moc_qpercentbarseries.cpp" |
|
112 | #include "moc_qpercentbarseries.cpp" | |
113 |
|
113 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE | |
115 |
|
115 |
@@ -1,117 +1,117 | |||||
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 "qstackedbarseries.h" |
|
21 | #include "qstackedbarseries.h" | |
22 | #include "qstackedbarseries_p.h" |
|
22 | #include "qstackedbarseries_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QStackedBarSeries |
|
31 | \class QStackedBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief Series for creating stacked bar chart | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
35 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as stacks, where bars in same category are stacked on top of each other. |
|
36 | as stacks, where bars in same category are stacked on top of each other. | |
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
38 |
|
38 | |||
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
40 | \image examples_stackedbarchart.png |
|
40 | \image examples_stackedbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries |
|
42 | \sa QBarSet, QPercentBarSeries, QBarSeries | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \qmlclass StackedBarSeries QStackedBarSeries |
|
46 | \qmlclass StackedBarSeries QStackedBarSeries | |
47 | \inherits BarSeries |
|
47 | \inherits BarSeries | |
48 |
|
48 | |||
49 | The following QML shows how to create a simple stacked bar chart: |
|
49 | The following QML shows how to create a simple stacked bar chart: | |
50 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
50 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
51 | \beginfloatleft |
|
51 | \beginfloatleft | |
52 | \image demos_qmlchart8.png |
|
52 | \image demos_qmlchart8.png | |
53 | \endfloat |
|
53 | \endfloat | |
54 | \clearfloat |
|
54 | \clearfloat | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | Constructs empty QStackedBarSeries. |
|
58 | Constructs empty QStackedBarSeries. | |
59 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
59 | QStackedBarSeries is QObject which is a child of a \a parent. | |
60 | */ |
|
60 | */ | |
61 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
61 | QStackedBarSeries::QStackedBarSeries(QObject *parent) | |
62 | : QBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
62 | : QBarSeries(*new QStackedBarSeriesPrivate(this), parent) | |
63 | { |
|
63 | { | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Returns QChartSeries::SeriesTypeStackedBar. |
|
67 | Returns QChartSeries::SeriesTypeStackedBar. | |
68 | */ |
|
68 | */ | |
69 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
69 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
70 | { |
|
70 | { | |
71 | return QAbstractSeries::SeriesTypeStackedBar; |
|
71 | return QAbstractSeries::SeriesTypeStackedBar; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
75 |
|
75 | |||
76 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q) |
|
76 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q) | |
77 | { |
|
77 | { | |
78 |
|
78 | |||
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
81 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
82 | { |
|
82 | { | |
83 | qreal minX(domain.minX()); |
|
83 | qreal minX(domain.minX()); | |
84 | qreal minY(domain.minY()); |
|
84 | qreal minY(domain.minY()); | |
85 | qreal maxX(domain.maxX()); |
|
85 | qreal maxX(domain.maxX()); | |
86 | qreal maxY(domain.maxY()); |
|
86 | qreal maxY(domain.maxY()); | |
87 | int tickXCount(domain.tickXCount()); |
|
87 | int tickXCount(domain.tickXCount()); | |
88 | int tickYCount(domain.tickYCount()); |
|
88 | int tickYCount(domain.tickYCount()); | |
89 |
|
89 | |||
90 | qreal x = categoryCount(); |
|
90 | qreal x = categoryCount(); | |
91 | qreal y = maxCategorySum(); |
|
91 | qreal y = maxCategorySum(); | |
92 | minX = qMin(minX, -0.5); |
|
92 | minX = qMin(minX, -0.5); | |
93 | minY = qMin(minY, y); |
|
93 | minY = qMin(minY, y); | |
94 | maxX = qMax(maxX, x - 0.5); |
|
94 | maxX = qMax(maxX, x - 0.5); | |
95 | maxY = qMax(maxY, y); |
|
95 | maxY = qMax(maxY, y); | |
96 | tickXCount = x+1; |
|
96 | tickXCount = x+1; | |
97 |
|
97 | |||
98 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
98 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
102 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
103 | { |
|
103 | { | |
104 | Q_Q(QStackedBarSeries); |
|
104 | Q_Q(QStackedBarSeries); | |
105 |
|
105 | |||
106 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
106 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
107 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
107 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
108 | presenter->animator()->addAnimation(bar); |
|
108 | presenter->animator()->addAnimation(bar); | |
109 | } |
|
109 | } | |
110 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
110 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
111 | return bar; |
|
111 | return bar; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | #include "moc_qstackedbarseries.cpp" |
|
114 | #include "moc_qstackedbarseries.cpp" | |
115 |
|
115 | |||
116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
116 | QTCOMMERCIALCHART_END_NAMESPACE | |
117 |
|
117 |
@@ -1,197 +1,197 | |||||
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 "qvbarmodelmapper.h" |
|
21 | #include "qvbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVBarModelMapper |
|
26 | \class QVBarModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief Vertical model mapper for bar series | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
31 | Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass VBarModelMapper |
|
37 | \qmlclass VBarModelMapper | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |
41 | for any bar series. Adding/removing value from the BarSet causes the the same change in the rest of the BarSets |
|
41 | for any bar series. Adding/removing value from the BarSet causes the the same change in the rest of the BarSets | |
42 | added to the same series. The following QML example would create a bar series with three bar sets (assuming the |
|
42 | added to the same series. The following QML example would create a bar series with three bar sets (assuming the | |
43 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be |
|
43 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be | |
44 | defined by the horizontal header (of the column). |
|
44 | defined by the horizontal header (of the column). | |
45 | \code |
|
45 | \code | |
46 | GroupedBarSeries { |
|
46 | GroupedBarSeries { | |
47 | VBarModelMapper { |
|
47 | VBarModelMapper { | |
48 | model: myCustomModel // QAbstractItemModel derived implementation |
|
48 | model: myCustomModel // QAbstractItemModel derived implementation | |
49 | firstBarSetColumn: 1 |
|
49 | firstBarSetColumn: 1 | |
50 | lastBarSetColumn: 3 |
|
50 | lastBarSetColumn: 3 | |
51 | firstRow: 1 |
|
51 | firstRow: 1 | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \qmlproperty BarSeries VBarModelMapper::series |
|
58 | \qmlproperty BarSeries VBarModelMapper::series | |
59 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
59 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
60 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
60 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty Model VBarModelMapper::model |
|
64 | \qmlproperty Model VBarModelMapper::model | |
65 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
65 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
66 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
66 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
67 | and modifying the data of the cells. |
|
67 | and modifying the data of the cells. | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \property QVBarModelMapper::firstBarSetColumn |
|
71 | \property QVBarModelMapper::firstBarSetColumn | |
72 | \brief Defines which column of the model is used as the data source for the first bar set |
|
72 | \brief Defines which column of the model is used as the data source for the first bar set | |
73 | Default value is: -1 (invalid mapping) |
|
73 | Default value is: -1 (invalid mapping) | |
74 | */ |
|
74 | */ | |
75 | /*! |
|
75 | /*! | |
76 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
76 | \qmlproperty int VBarModelMapper::firstBarSetColumn | |
77 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
77 | Defines which column of the model is used as the data source for the first bar set. Default value | |
78 | is: -1 (invalid mapping). |
|
78 | is: -1 (invalid mapping). | |
79 | */ |
|
79 | */ | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | \property QVBarModelMapper::lastBarSetColumn |
|
82 | \property QVBarModelMapper::lastBarSetColumn | |
83 | \brief Defines which column of the model is used as the data source for the last bar set |
|
83 | \brief Defines which column of the model is used as the data source for the last bar set | |
84 | Default value is: -1 (invalid mapping) |
|
84 | Default value is: -1 (invalid mapping) | |
85 | */ |
|
85 | */ | |
86 | /*! |
|
86 | /*! | |
87 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
87 | \qmlproperty int VBarModelMapper::lastBarSetColumn | |
88 | Defines which column of the model is used as the data source for the last bar set. Default |
|
88 | Defines which column of the model is used as the data source for the last bar set. Default | |
89 | value is: -1 (invalid mapping). |
|
89 | value is: -1 (invalid mapping). | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \property QVBarModelMapper::firstRow |
|
93 | \property QVBarModelMapper::firstRow | |
94 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
94 | \brief Defines which row of the model contains the first values of the QBarSets in the series. | |
95 | Minimal and default value is: 0 |
|
95 | Minimal and default value is: 0 | |
96 | */ |
|
96 | */ | |
97 | /*! |
|
97 | /*! | |
98 | \qmlproperty int VBarModelMapper::firstRow |
|
98 | \qmlproperty int VBarModelMapper::firstRow | |
99 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
99 | Defines which row of the model contains the first values of the QBarSets in the series. | |
100 | The default value is 0. |
|
100 | The default value is 0. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \property QVBarModelMapper::rowCount |
|
104 | \property QVBarModelMapper::rowCount | |
105 | \brief Defines the number of rows of the model that are mapped as the data for QBarSeries |
|
105 | \brief Defines the number of rows of the model that are mapped as the data for QBarSeries | |
106 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
106 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
107 | */ |
|
107 | */ | |
108 | /*! |
|
108 | /*! | |
109 | \qmlproperty int VBarModelMapper::rowCount |
|
109 | \qmlproperty int VBarModelMapper::rowCount | |
110 | Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is |
|
110 | Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is | |
111 | -1 (count limited by the number of rows in the model) |
|
111 | -1 (count limited by the number of rows in the model) | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
115 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |
116 | Emitted when the firstBarSetColumn has changed. |
|
116 | Emitted when the firstBarSetColumn has changed. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
120 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |
121 | Emitted when the lastBarSetColumn has changed. |
|
121 | Emitted when the lastBarSetColumn has changed. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \fn void QVBarModelMapper::firstRowChanged() |
|
125 | \fn void QVBarModelMapper::firstRowChanged() | |
126 | Emitted when the firstRow has changed. |
|
126 | Emitted when the firstRow has changed. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \fn void QVBarModelMapper::rowCountChanged() |
|
130 | \fn void QVBarModelMapper::rowCountChanged() | |
131 | Emitted when the rowCount has changed. |
|
131 | Emitted when the rowCount has changed. | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | Constructs a mapper object which is a child of \a parent. |
|
135 | Constructs a mapper object which is a child of \a parent. | |
136 | */ |
|
136 | */ | |
137 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
137 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
138 | QBarModelMapper(parent) |
|
138 | QBarModelMapper(parent) | |
139 | { |
|
139 | { | |
140 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
140 | QBarModelMapper::setOrientation(Qt::Vertical); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | int QVBarModelMapper::firstBarSetColumn() const |
|
143 | int QVBarModelMapper::firstBarSetColumn() const | |
144 | { |
|
144 | { | |
145 | return QBarModelMapper::firstBarSetSection(); |
|
145 | return QBarModelMapper::firstBarSetSection(); | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
148 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
149 | { |
|
149 | { | |
150 | if (firstBarSetColumn != firstBarSetSection()) { |
|
150 | if (firstBarSetColumn != firstBarSetSection()) { | |
151 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
151 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |
152 | emit firstBarSetColumnChanged(); |
|
152 | emit firstBarSetColumnChanged(); | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | int QVBarModelMapper::lastBarSetColumn() const |
|
156 | int QVBarModelMapper::lastBarSetColumn() const | |
157 | { |
|
157 | { | |
158 | return QBarModelMapper::lastBarSetSection(); |
|
158 | return QBarModelMapper::lastBarSetSection(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
161 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
162 | { |
|
162 | { | |
163 | if (lastBarSetColumn != lastBarSetSection()) { |
|
163 | if (lastBarSetColumn != lastBarSetSection()) { | |
164 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
164 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |
165 | emit lastBarSetColumnChanged(); |
|
165 | emit lastBarSetColumnChanged(); | |
166 | } |
|
166 | } | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | int QVBarModelMapper::firstRow() const |
|
169 | int QVBarModelMapper::firstRow() const | |
170 | { |
|
170 | { | |
171 | return QBarModelMapper::first(); |
|
171 | return QBarModelMapper::first(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
174 | void QVBarModelMapper::setFirstRow(int firstRow) | |
175 | { |
|
175 | { | |
176 | if (firstRow != first()) { |
|
176 | if (firstRow != first()) { | |
177 | QBarModelMapper::setFirst(firstRow); |
|
177 | QBarModelMapper::setFirst(firstRow); | |
178 | emit firstRowChanged(); |
|
178 | emit firstRowChanged(); | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | int QVBarModelMapper::rowCount() const |
|
182 | int QVBarModelMapper::rowCount() const | |
183 | { |
|
183 | { | |
184 | return QBarModelMapper::count(); |
|
184 | return QBarModelMapper::count(); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void QVBarModelMapper::setRowCount(int rowCount) |
|
187 | void QVBarModelMapper::setRowCount(int rowCount) | |
188 | { |
|
188 | { | |
189 | if (rowCount != count()) { |
|
189 | if (rowCount != count()) { | |
190 | QBarModelMapper::setCount(rowCount); |
|
190 | QBarModelMapper::setCount(rowCount); | |
191 | emit firstRowChanged(); |
|
191 | emit firstRowChanged(); | |
192 | } |
|
192 | } | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | #include "moc_qvbarmodelmapper.cpp" |
|
195 | #include "moc_qvbarmodelmapper.cpp" | |
196 |
|
196 | |||
197 | QTCOMMERCIALCHART_END_NAMESPACE |
|
197 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now