@@ -1,597 +1,633 | |||||
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 part of QtCommercial chart API. | |
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. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
36 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
37 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. |
|
37 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. | |
38 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. |
|
38 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. | |
39 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. |
|
39 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. | |
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 |
|
46 | |||
47 | All the data in the series is discarded when it is set to the mapper. |
|
47 | All the data in the series is discarded when it is set to the mapper. | |
48 | When new series is specified the old series is disconnected (it preserves its data) |
|
48 | When new series is specified the old series is disconnected (it preserves its data) | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \property QBarModelMapper::model |
|
52 | \property QBarModelMapper::model | |
53 | \brief Defines the model that is used by the mapper. |
|
53 | \brief Defines the model that is used by the mapper. | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \property QBarModelMapper::first |
|
57 | \property QBarModelMapper::first | |
58 | \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. |
|
58 | \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. | |
59 |
|
59 | |||
60 | Minimal and default value is: 0 |
|
60 | Minimal and default value is: 0 | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarModelMapper::count |
|
64 | \property QBarModelMapper::count | |
65 | \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries |
|
65 | \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries | |
66 |
|
66 | |||
67 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
67 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
|
71 | \fn void QBarModelMapper::seriesReplaced() | |||
|
72 | ||||
|
73 | Emitted when the series to which mapper is connected to has changed. | |||
|
74 | */ | |||
|
75 | ||||
|
76 | /*! | |||
|
77 | \fn void QBarModelMapper::modelReplaced() | |||
|
78 | ||||
|
79 | Emitted when the model to which mapper is connected to has changed. | |||
|
80 | */ | |||
|
81 | ||||
|
82 | /*! | |||
|
83 | \fn void QBarModelMapper::firstChanged() | |||
|
84 | ||||
|
85 | Emitted when the value for the first has changed. | |||
|
86 | */ | |||
|
87 | ||||
|
88 | /*! | |||
|
89 | \fn void QBarModelMapper::countChanged() | |||
|
90 | ||||
|
91 | Emitted when the value for the count has changed. | |||
|
92 | */ | |||
|
93 | ||||
|
94 | /*! | |||
71 | Constructs a mapper object which is a child of \a parent. |
|
95 | Constructs a mapper object which is a child of \a parent. | |
72 | */ |
|
96 | */ | |
73 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
97 | QBarModelMapper::QBarModelMapper(QObject *parent) : | |
74 | QObject(parent), |
|
98 | QObject(parent), | |
75 | d_ptr(new QBarModelMapperPrivate(this)) |
|
99 | d_ptr(new QBarModelMapperPrivate(this)) | |
76 | { |
|
100 | { | |
77 | } |
|
101 | } | |
78 |
|
102 | |||
79 | QAbstractItemModel* QBarModelMapper::model() const |
|
103 | QAbstractItemModel* QBarModelMapper::model() const | |
80 | { |
|
104 | { | |
81 | Q_D(const QBarModelMapper); |
|
105 | Q_D(const QBarModelMapper); | |
82 | return d->m_model; |
|
106 | return d->m_model; | |
83 | } |
|
107 | } | |
84 |
|
108 | |||
85 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
109 | void QBarModelMapper::setModel(QAbstractItemModel *model) | |
86 | { |
|
110 | { | |
87 | if (model == 0) |
|
111 | if (model == 0) | |
88 | return; |
|
112 | return; | |
89 |
|
113 | |||
90 | Q_D(QBarModelMapper); |
|
114 | Q_D(QBarModelMapper); | |
91 | if (d->m_model) { |
|
115 | if (d->m_model) { | |
92 | disconnect(d->m_model, 0, d, 0); |
|
116 | disconnect(d->m_model, 0, d, 0); | |
93 | } |
|
117 | } | |
94 |
|
118 | |||
95 | d->m_model = model; |
|
119 | d->m_model = model; | |
96 | d->initializeBarFromModel(); |
|
120 | d->initializeBarFromModel(); | |
97 | // connect signals from the model |
|
121 | // connect signals from the model | |
98 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
122 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
99 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); |
|
123 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); | |
100 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
124 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
101 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
125 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
102 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
126 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
103 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
127 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
|
128 | ||||
|
129 | emit modelReplaced(); | |||
104 | } |
|
130 | } | |
105 |
|
131 | |||
106 | QBarSeries* QBarModelMapper::series() const |
|
132 | QBarSeries* QBarModelMapper::series() const | |
107 | { |
|
133 | { | |
108 | Q_D(const QBarModelMapper); |
|
134 | Q_D(const QBarModelMapper); | |
109 | return d->m_series; |
|
135 | return d->m_series; | |
110 | } |
|
136 | } | |
111 |
|
137 | |||
112 | void QBarModelMapper::setSeries(QBarSeries *series) |
|
138 | void QBarModelMapper::setSeries(QBarSeries *series) | |
113 | { |
|
139 | { | |
114 | Q_D(QBarModelMapper); |
|
140 | Q_D(QBarModelMapper); | |
115 | if (d->m_series) { |
|
141 | if (d->m_series) { | |
116 | disconnect(d->m_series, 0, d, 0); |
|
142 | disconnect(d->m_series, 0, d, 0); | |
117 | } |
|
143 | } | |
118 |
|
144 | |||
119 | if (series == 0) |
|
145 | if (series == 0) | |
120 | return; |
|
146 | return; | |
121 |
|
147 | |||
122 | d->m_series = series; |
|
148 | d->m_series = series; | |
123 | d->initializeBarFromModel(); |
|
149 | d->initializeBarFromModel(); | |
124 | // connect the signals from the series |
|
150 | // connect the signals from the series | |
125 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); |
|
151 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); | |
126 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); |
|
152 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); | |
|
153 | ||||
|
154 | emit seriesReplaced(); | |||
127 | } |
|
155 | } | |
128 |
|
156 | |||
129 | int QBarModelMapper::first() const |
|
157 | int QBarModelMapper::first() const | |
130 | { |
|
158 | { | |
131 | Q_D(const QBarModelMapper); |
|
159 | Q_D(const QBarModelMapper); | |
132 | return d->m_first; |
|
160 | return d->m_first; | |
133 | } |
|
161 | } | |
134 |
|
162 | |||
135 | void QBarModelMapper::setFirst(int first) |
|
163 | void QBarModelMapper::setFirst(int first) | |
136 | { |
|
164 | { | |
137 | Q_D(QBarModelMapper); |
|
165 | Q_D(QBarModelMapper); | |
138 | d->m_first = qMax(first, 0); |
|
166 | if (first != d->m_first) { | |
139 | d->initializeBarFromModel(); |
|
167 | d->m_first = qMax(first, 0); | |
|
168 | d->initializeBarFromModel(); | |||
|
169 | ||||
|
170 | emit firstChanged(); | |||
|
171 | } | |||
140 | } |
|
172 | } | |
141 |
|
173 | |||
142 | int QBarModelMapper::count() const |
|
174 | int QBarModelMapper::count() const | |
143 | { |
|
175 | { | |
144 | Q_D(const QBarModelMapper); |
|
176 | Q_D(const QBarModelMapper); | |
145 | return d->m_count; |
|
177 | return d->m_count; | |
146 | } |
|
178 | } | |
147 |
|
179 | |||
148 | void QBarModelMapper::setCount(int count) |
|
180 | void QBarModelMapper::setCount(int count) | |
149 | { |
|
181 | { | |
150 | Q_D(QBarModelMapper); |
|
182 | Q_D(QBarModelMapper); | |
151 | d->m_count = qMax(count, -1); |
|
183 | if (count != d->m_count) { | |
152 | d->initializeBarFromModel(); |
|
184 | d->m_count = qMax(count, -1); | |
|
185 | d->initializeBarFromModel(); | |||
|
186 | ||||
|
187 | emit countChanged(); | |||
|
188 | } | |||
153 | } |
|
189 | } | |
154 |
|
190 | |||
155 | /*! |
|
191 | /*! | |
156 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
192 | Returns the orientation that is used when QBarModelMapper accesses the model. | |
157 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
193 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) | |
158 | or from columns (Qt::Vertical) |
|
194 | or from columns (Qt::Vertical) | |
159 | */ |
|
195 | */ | |
160 | Qt::Orientation QBarModelMapper::orientation() const |
|
196 | Qt::Orientation QBarModelMapper::orientation() const | |
161 | { |
|
197 | { | |
162 | Q_D(const QBarModelMapper); |
|
198 | Q_D(const QBarModelMapper); | |
163 | return d->m_orientation; |
|
199 | return d->m_orientation; | |
164 | } |
|
200 | } | |
165 |
|
201 | |||
166 | /*! |
|
202 | /*! | |
167 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
203 | Returns the \a orientation that is used when QBarModelMapper accesses the model. | |
168 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
204 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) | |
169 | or from columns (Qt::Vertical) |
|
205 | or from columns (Qt::Vertical) | |
170 | */ |
|
206 | */ | |
171 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
207 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) | |
172 | { |
|
208 | { | |
173 | Q_D(QBarModelMapper); |
|
209 | Q_D(QBarModelMapper); | |
174 | d->m_orientation = orientation; |
|
210 | d->m_orientation = orientation; | |
175 | d->initializeBarFromModel(); |
|
211 | d->initializeBarFromModel(); | |
176 | } |
|
212 | } | |
177 |
|
213 | |||
178 | /*! |
|
214 | /*! | |
179 | Returns which section of the model is used as the data source for the first bar set |
|
215 | Returns which section of the model is used as the data source for the first bar set | |
180 | */ |
|
216 | */ | |
181 | int QBarModelMapper::firstBarSetSection() const |
|
217 | int QBarModelMapper::firstBarSetSection() const | |
182 | { |
|
218 | { | |
183 | Q_D(const QBarModelMapper); |
|
219 | Q_D(const QBarModelMapper); | |
184 | return d->m_firstBarSetSection; |
|
220 | return d->m_firstBarSetSection; | |
185 | } |
|
221 | } | |
186 |
|
222 | |||
187 | /*! |
|
223 | /*! | |
188 | Sets the model section that is used as the data source for the first bar set |
|
224 | Sets the model section that is used as the data source for the first bar set | |
189 | Parameter \a firstBarSetSection specifies the section of the model. |
|
225 | Parameter \a firstBarSetSection specifies the section of the model. | |
190 | */ |
|
226 | */ | |
191 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
227 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) | |
192 | { |
|
228 | { | |
193 | Q_D(QBarModelMapper); |
|
229 | Q_D(QBarModelMapper); | |
194 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); |
|
230 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); | |
195 | d->initializeBarFromModel(); |
|
231 | d->initializeBarFromModel(); | |
196 | } |
|
232 | } | |
197 |
|
233 | |||
198 | /*! |
|
234 | /*! | |
199 | Returns which section of the model is used as the data source for the last bar set |
|
235 | Returns which section of the model is used as the data source for the last bar set | |
200 | */ |
|
236 | */ | |
201 | int QBarModelMapper::lastBarSetSection() const |
|
237 | int QBarModelMapper::lastBarSetSection() const | |
202 | { |
|
238 | { | |
203 | Q_D(const QBarModelMapper); |
|
239 | Q_D(const QBarModelMapper); | |
204 | return d->m_lastBarSetSection; |
|
240 | return d->m_lastBarSetSection; | |
205 | } |
|
241 | } | |
206 |
|
242 | |||
207 | /*! |
|
243 | /*! | |
208 | Sets the model section that is used as the data source for the last bar set |
|
244 | Sets the model section that is used as the data source for the last bar set | |
209 | Parameter \a lastBarSetSection specifies the section of the model. |
|
245 | Parameter \a lastBarSetSection specifies the section of the model. | |
210 | */ |
|
246 | */ | |
211 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
247 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |
212 | { |
|
248 | { | |
213 | Q_D(QBarModelMapper); |
|
249 | Q_D(QBarModelMapper); | |
214 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); |
|
250 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); | |
215 | d->initializeBarFromModel(); |
|
251 | d->initializeBarFromModel(); | |
216 | } |
|
252 | } | |
217 |
|
253 | |||
218 | /*! |
|
254 | /*! | |
219 | Resets the QBarModelMapper to the default state. |
|
255 | Resets the QBarModelMapper to the default state. | |
220 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 |
|
256 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 | |
221 | */ |
|
257 | */ | |
222 | void QBarModelMapper::reset() |
|
258 | void QBarModelMapper::reset() | |
223 | { |
|
259 | { | |
224 | Q_D(QBarModelMapper); |
|
260 | Q_D(QBarModelMapper); | |
225 | d->m_first = 0; |
|
261 | d->m_first = 0; | |
226 | d->m_count = -1; |
|
262 | d->m_count = -1; | |
227 | d->m_firstBarSetSection = -1; |
|
263 | d->m_firstBarSetSection = -1; | |
228 | d->m_lastBarSetSection = -1; |
|
264 | d->m_lastBarSetSection = -1; | |
229 | d->initializeBarFromModel(); |
|
265 | d->initializeBarFromModel(); | |
230 | } |
|
266 | } | |
231 |
|
267 | |||
232 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
268 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
233 |
|
269 | |||
234 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
270 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
235 | m_series(0), |
|
271 | m_series(0), | |
236 | m_model(0), |
|
272 | m_model(0), | |
237 | m_first(0), |
|
273 | m_first(0), | |
238 | m_count(-1), |
|
274 | m_count(-1), | |
239 | m_orientation(Qt::Vertical), |
|
275 | m_orientation(Qt::Vertical), | |
240 | m_firstBarSetSection(-1), |
|
276 | m_firstBarSetSection(-1), | |
241 | m_lastBarSetSection(-1), |
|
277 | m_lastBarSetSection(-1), | |
242 | m_seriesSignalsBlock(false), |
|
278 | m_seriesSignalsBlock(false), | |
243 | m_modelSignalsBlock(false), |
|
279 | m_modelSignalsBlock(false), | |
244 | q_ptr(q) |
|
280 | q_ptr(q) | |
245 | { |
|
281 | { | |
246 | } |
|
282 | } | |
247 |
|
283 | |||
248 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
284 | void QBarModelMapperPrivate::blockModelSignals(bool block) | |
249 | { |
|
285 | { | |
250 | m_modelSignalsBlock = block; |
|
286 | m_modelSignalsBlock = block; | |
251 | } |
|
287 | } | |
252 |
|
288 | |||
253 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
289 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |
254 | { |
|
290 | { | |
255 | m_seriesSignalsBlock = block; |
|
291 | m_seriesSignalsBlock = block; | |
256 | } |
|
292 | } | |
257 |
|
293 | |||
258 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
294 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
259 | { |
|
295 | { | |
260 | if (!index.isValid()) |
|
296 | if (!index.isValid()) | |
261 | return 0; |
|
297 | return 0; | |
262 |
|
298 | |||
263 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
299 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { | |
264 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
300 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
265 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
301 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
266 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
302 | return m_series->barSets().at(index.column() - m_firstBarSetSection); | |
267 | // else |
|
303 | // else | |
268 | // return 0; |
|
304 | // return 0; | |
269 | } |
|
305 | } | |
270 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
306 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { | |
271 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
307 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
272 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
308 | return m_series->barSets().at(index.row() - m_firstBarSetSection); | |
273 | } |
|
309 | } | |
274 | return 0; // This part of model has not been mapped to any slice |
|
310 | return 0; // This part of model has not been mapped to any slice | |
275 | } |
|
311 | } | |
276 |
|
312 | |||
277 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
313 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) | |
278 | { |
|
314 | { | |
279 | if (m_count != -1 && posInBar >= m_count) |
|
315 | if (m_count != -1 && posInBar >= m_count) | |
280 | return QModelIndex(); // invalid |
|
316 | return QModelIndex(); // invalid | |
281 |
|
317 | |||
282 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
318 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) | |
283 | return QModelIndex(); // invalid |
|
319 | return QModelIndex(); // invalid | |
284 |
|
320 | |||
285 | if (m_orientation == Qt::Vertical) |
|
321 | if (m_orientation == Qt::Vertical) | |
286 | return m_model->index(posInBar + m_first, barSection); |
|
322 | return m_model->index(posInBar + m_first, barSection); | |
287 | else |
|
323 | else | |
288 | return m_model->index(barSection, posInBar + m_first); |
|
324 | return m_model->index(barSection, posInBar + m_first); | |
289 | } |
|
325 | } | |
290 |
|
326 | |||
291 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
327 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
292 | { |
|
328 | { | |
293 | Q_UNUSED(topLeft) |
|
329 | Q_UNUSED(topLeft) | |
294 | Q_UNUSED(bottomRight) |
|
330 | Q_UNUSED(bottomRight) | |
295 |
|
331 | |||
296 | if (m_model == 0 || m_series == 0) |
|
332 | if (m_model == 0 || m_series == 0) | |
297 | return; |
|
333 | return; | |
298 |
|
334 | |||
299 | if (m_modelSignalsBlock) |
|
335 | if (m_modelSignalsBlock) | |
300 | return; |
|
336 | return; | |
301 |
|
337 | |||
302 | blockSeriesSignals(); |
|
338 | blockSeriesSignals(); | |
303 | QModelIndex index; |
|
339 | QModelIndex index; | |
304 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
340 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
305 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
341 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
306 | index = topLeft.sibling(row, column); |
|
342 | index = topLeft.sibling(row, column); | |
307 | QBarSet* bar = barSet(index); |
|
343 | QBarSet* bar = barSet(index); | |
308 | if (bar) { |
|
344 | if (bar) { | |
309 | if (m_orientation == Qt::Vertical) |
|
345 | if (m_orientation == Qt::Vertical) | |
310 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
346 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
311 | else |
|
347 | else | |
312 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
348 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
313 | } |
|
349 | } | |
314 | } |
|
350 | } | |
315 | } |
|
351 | } | |
316 | blockSeriesSignals(false); |
|
352 | blockSeriesSignals(false); | |
317 | } |
|
353 | } | |
318 |
|
354 | |||
319 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) |
|
355 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) | |
320 | { |
|
356 | { | |
321 | if (m_model == 0 || m_series == 0) |
|
357 | if (m_model == 0 || m_series == 0) | |
322 | return; |
|
358 | return; | |
323 |
|
359 | |||
324 | if (m_modelSignalsBlock) |
|
360 | if (m_modelSignalsBlock) | |
325 | return; |
|
361 | return; | |
326 |
|
362 | |||
327 | blockSeriesSignals(); |
|
363 | blockSeriesSignals(); | |
328 | if (orientation != m_orientation) { |
|
364 | if (orientation != m_orientation) { | |
329 | for (int section = first; section <= last; section++) { |
|
365 | for (int section = first; section <= last; section++) { | |
330 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { |
|
366 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { | |
331 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); |
|
367 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); | |
332 | if (bar) |
|
368 | if (bar) | |
333 | bar->setLabel(m_model->headerData(section, orientation).toString()); |
|
369 | bar->setLabel(m_model->headerData(section, orientation).toString()); | |
334 | } |
|
370 | } | |
335 | } |
|
371 | } | |
336 | } |
|
372 | } | |
337 | blockSeriesSignals(false); |
|
373 | blockSeriesSignals(false); | |
338 | } |
|
374 | } | |
339 |
|
375 | |||
340 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
376 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
341 | { |
|
377 | { | |
342 | Q_UNUSED(parent); |
|
378 | Q_UNUSED(parent); | |
343 | Q_UNUSED(end) |
|
379 | Q_UNUSED(end) | |
344 | if (m_modelSignalsBlock) |
|
380 | if (m_modelSignalsBlock) | |
345 | return; |
|
381 | return; | |
346 |
|
382 | |||
347 | blockSeriesSignals(); |
|
383 | blockSeriesSignals(); | |
348 | if (m_orientation == Qt::Vertical) |
|
384 | if (m_orientation == Qt::Vertical) | |
349 | // insertData(start, end); |
|
385 | // insertData(start, end); | |
350 | initializeBarFromModel(); |
|
386 | initializeBarFromModel(); | |
351 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
387 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
352 | initializeBarFromModel(); |
|
388 | initializeBarFromModel(); | |
353 | blockSeriesSignals(false); |
|
389 | blockSeriesSignals(false); | |
354 | } |
|
390 | } | |
355 |
|
391 | |||
356 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
392 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
357 | { |
|
393 | { | |
358 | Q_UNUSED(parent); |
|
394 | Q_UNUSED(parent); | |
359 | Q_UNUSED(end) |
|
395 | Q_UNUSED(end) | |
360 | if (m_modelSignalsBlock) |
|
396 | if (m_modelSignalsBlock) | |
361 | return; |
|
397 | return; | |
362 |
|
398 | |||
363 | blockSeriesSignals(); |
|
399 | blockSeriesSignals(); | |
364 | if (m_orientation == Qt::Vertical) |
|
400 | if (m_orientation == Qt::Vertical) | |
365 | // removeData(start, end); |
|
401 | // removeData(start, end); | |
366 | initializeBarFromModel(); |
|
402 | initializeBarFromModel(); | |
367 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
403 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
368 | initializeBarFromModel(); |
|
404 | initializeBarFromModel(); | |
369 | blockSeriesSignals(false); |
|
405 | blockSeriesSignals(false); | |
370 | } |
|
406 | } | |
371 |
|
407 | |||
372 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
408 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
373 | { |
|
409 | { | |
374 | Q_UNUSED(parent); |
|
410 | Q_UNUSED(parent); | |
375 | Q_UNUSED(end) |
|
411 | Q_UNUSED(end) | |
376 | if (m_modelSignalsBlock) |
|
412 | if (m_modelSignalsBlock) | |
377 | return; |
|
413 | return; | |
378 |
|
414 | |||
379 | blockSeriesSignals(); |
|
415 | blockSeriesSignals(); | |
380 | if (m_orientation == Qt::Horizontal) |
|
416 | if (m_orientation == Qt::Horizontal) | |
381 | // insertData(start, end); |
|
417 | // insertData(start, end); | |
382 | initializeBarFromModel(); |
|
418 | initializeBarFromModel(); | |
383 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
419 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
384 | initializeBarFromModel(); |
|
420 | initializeBarFromModel(); | |
385 | blockSeriesSignals(false); |
|
421 | blockSeriesSignals(false); | |
386 | } |
|
422 | } | |
387 |
|
423 | |||
388 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
424 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
389 | { |
|
425 | { | |
390 | Q_UNUSED(parent); |
|
426 | Q_UNUSED(parent); | |
391 | Q_UNUSED(end) |
|
427 | Q_UNUSED(end) | |
392 | if (m_modelSignalsBlock) |
|
428 | if (m_modelSignalsBlock) | |
393 | return; |
|
429 | return; | |
394 |
|
430 | |||
395 | blockSeriesSignals(); |
|
431 | blockSeriesSignals(); | |
396 | if (m_orientation == Qt::Horizontal) |
|
432 | if (m_orientation == Qt::Horizontal) | |
397 | // removeData(start, end); |
|
433 | // removeData(start, end); | |
398 | initializeBarFromModel(); |
|
434 | initializeBarFromModel(); | |
399 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
435 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
400 | initializeBarFromModel(); |
|
436 | initializeBarFromModel(); | |
401 | blockSeriesSignals(false); |
|
437 | blockSeriesSignals(false); | |
402 | } |
|
438 | } | |
403 |
|
439 | |||
404 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
440 | void QBarModelMapperPrivate::insertData(int start, int end) | |
405 | { |
|
441 | { | |
406 | Q_UNUSED(end) |
|
442 | Q_UNUSED(end) | |
407 | Q_UNUSED(start) |
|
443 | Q_UNUSED(start) | |
408 | Q_UNUSED(end) |
|
444 | Q_UNUSED(end) | |
409 | // To be implemented |
|
445 | // To be implemented | |
410 | } |
|
446 | } | |
411 |
|
447 | |||
412 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
448 | void QBarModelMapperPrivate::removeData(int start, int end) | |
413 | { |
|
449 | { | |
414 | Q_UNUSED(end) |
|
450 | Q_UNUSED(end) | |
415 | Q_UNUSED(start) |
|
451 | Q_UNUSED(start) | |
416 | Q_UNUSED(end) |
|
452 | Q_UNUSED(end) | |
417 | // To be implemented |
|
453 | // To be implemented | |
418 | } |
|
454 | } | |
419 |
|
455 | |||
420 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) |
|
456 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) | |
421 | { |
|
457 | { | |
422 | if (m_seriesSignalsBlock) |
|
458 | if (m_seriesSignalsBlock) | |
423 | return; |
|
459 | return; | |
424 |
|
460 | |||
425 | if (sets.count() == 0) |
|
461 | if (sets.count() == 0) | |
426 | return; |
|
462 | return; | |
427 |
|
463 | |||
428 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); |
|
464 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); | |
429 | if (firstIndex == -1) |
|
465 | if (firstIndex == -1) | |
430 | return; |
|
466 | return; | |
431 |
|
467 | |||
432 | int maxCount = 0; |
|
468 | int maxCount = 0; | |
433 | for(int i = 0; i < sets.count(); i++) |
|
469 | for(int i = 0; i < sets.count(); i++) | |
434 | if (sets.at(i)->count() > m_count) |
|
470 | if (sets.at(i)->count() > m_count) | |
435 | maxCount = sets.at(i)->count(); |
|
471 | maxCount = sets.at(i)->count(); | |
436 |
|
472 | |||
437 | if (m_count != -1 && m_count < maxCount) |
|
473 | if (m_count != -1 && m_count < maxCount) | |
438 | m_count = maxCount; |
|
474 | m_count = maxCount; | |
439 |
|
475 | |||
440 | m_lastBarSetSection += sets.count(); |
|
476 | m_lastBarSetSection += sets.count(); | |
441 |
|
477 | |||
442 | blockModelSignals(); |
|
478 | blockModelSignals(); | |
443 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; |
|
479 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; | |
444 | if (maxCount > modelCapacity) { |
|
480 | if (maxCount > modelCapacity) { | |
445 | if (m_orientation == Qt::Vertical) |
|
481 | if (m_orientation == Qt::Vertical) | |
446 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); |
|
482 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); | |
447 | else |
|
483 | else | |
448 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); |
|
484 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); | |
449 | } |
|
485 | } | |
450 |
|
486 | |||
451 | if (m_orientation == Qt::Vertical) |
|
487 | if (m_orientation == Qt::Vertical) | |
452 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
488 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
453 | else |
|
489 | else | |
454 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
490 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); | |
455 |
|
491 | |||
456 |
|
492 | |||
457 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { |
|
493 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { | |
458 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); |
|
494 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); | |
459 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) |
|
495 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) | |
460 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); |
|
496 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); | |
461 | } |
|
497 | } | |
462 | blockModelSignals(false); |
|
498 | blockModelSignals(false); | |
463 | initializeBarFromModel(); |
|
499 | initializeBarFromModel(); | |
464 | } |
|
500 | } | |
465 |
|
501 | |||
466 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) |
|
502 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) | |
467 | { |
|
503 | { | |
468 | if (m_seriesSignalsBlock) |
|
504 | if (m_seriesSignalsBlock) | |
469 | return; |
|
505 | return; | |
470 |
|
506 | |||
471 | if (sets.count() == 0) |
|
507 | if (sets.count() == 0) | |
472 | return; |
|
508 | return; | |
473 |
|
509 | |||
474 | int firstIndex = m_barSets.indexOf(sets.at(0)); |
|
510 | int firstIndex = m_barSets.indexOf(sets.at(0)); | |
475 | if (firstIndex == -1) |
|
511 | if (firstIndex == -1) | |
476 | return; |
|
512 | return; | |
477 |
|
513 | |||
478 | m_lastBarSetSection -= sets.count(); |
|
514 | m_lastBarSetSection -= sets.count(); | |
479 |
|
515 | |||
480 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) |
|
516 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) | |
481 | m_barSets.removeAt(i); |
|
517 | m_barSets.removeAt(i); | |
482 |
|
518 | |||
483 | blockModelSignals(); |
|
519 | blockModelSignals(); | |
484 | if (m_orientation == Qt::Vertical) |
|
520 | if (m_orientation == Qt::Vertical) | |
485 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
521 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
486 | else |
|
522 | else | |
487 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
523 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); | |
488 | blockModelSignals(false); |
|
524 | blockModelSignals(false); | |
489 | initializeBarFromModel(); |
|
525 | initializeBarFromModel(); | |
490 | } |
|
526 | } | |
491 |
|
527 | |||
492 | void QBarModelMapperPrivate::valuesAdded(int index, int count) |
|
528 | void QBarModelMapperPrivate::valuesAdded(int index, int count) | |
493 | { |
|
529 | { | |
494 | if (m_seriesSignalsBlock) |
|
530 | if (m_seriesSignalsBlock) | |
495 | return; |
|
531 | return; | |
496 |
|
532 | |||
497 | if (m_count != -1) |
|
533 | if (m_count != -1) | |
498 | m_count += count; |
|
534 | m_count += count; | |
499 |
|
535 | |||
500 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
536 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
501 |
|
537 | |||
502 | blockModelSignals(); |
|
538 | blockModelSignals(); | |
503 | if (m_orientation == Qt::Vertical) |
|
539 | if (m_orientation == Qt::Vertical) | |
504 | m_model->insertRows(index + m_first, count); |
|
540 | m_model->insertRows(index + m_first, count); | |
505 | else |
|
541 | else | |
506 | m_model->insertColumns(index + m_first, count); |
|
542 | m_model->insertColumns(index + m_first, count); | |
507 |
|
543 | |||
508 | for (int j = index; j < index + count; j++) |
|
544 | for (int j = index; j < index + count; j++) | |
509 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); |
|
545 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); | |
510 |
|
546 | |||
511 | blockModelSignals(false); |
|
547 | blockModelSignals(false); | |
512 | initializeBarFromModel(); |
|
548 | initializeBarFromModel(); | |
513 | } |
|
549 | } | |
514 |
|
550 | |||
515 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) |
|
551 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) | |
516 | { |
|
552 | { | |
517 | if (m_seriesSignalsBlock) |
|
553 | if (m_seriesSignalsBlock) | |
518 | return; |
|
554 | return; | |
519 |
|
555 | |||
520 | if (m_count != -1) |
|
556 | if (m_count != -1) | |
521 | m_count -= count; |
|
557 | m_count -= count; | |
522 |
|
558 | |||
523 | blockModelSignals(); |
|
559 | blockModelSignals(); | |
524 | if (m_orientation == Qt::Vertical) |
|
560 | if (m_orientation == Qt::Vertical) | |
525 | m_model->removeRows(index + m_first, count); |
|
561 | m_model->removeRows(index + m_first, count); | |
526 | else |
|
562 | else | |
527 | m_model->removeColumns(index + m_first, count); |
|
563 | m_model->removeColumns(index + m_first, count); | |
528 |
|
564 | |||
529 | blockModelSignals(false); |
|
565 | blockModelSignals(false); | |
530 | initializeBarFromModel(); |
|
566 | initializeBarFromModel(); | |
531 | } |
|
567 | } | |
532 |
|
568 | |||
533 | void QBarModelMapperPrivate::barLabelChanged() |
|
569 | void QBarModelMapperPrivate::barLabelChanged() | |
534 | { |
|
570 | { | |
535 | if (m_seriesSignalsBlock) |
|
571 | if (m_seriesSignalsBlock) | |
536 | return; |
|
572 | return; | |
537 |
|
573 | |||
538 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
574 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
539 |
|
575 | |||
540 | blockModelSignals(); |
|
576 | blockModelSignals(); | |
541 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); |
|
577 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); | |
542 | blockModelSignals(false); |
|
578 | blockModelSignals(false); | |
543 | initializeBarFromModel(); |
|
579 | initializeBarFromModel(); | |
544 | } |
|
580 | } | |
545 |
|
581 | |||
546 | void QBarModelMapperPrivate::barValueChanged(int index) |
|
582 | void QBarModelMapperPrivate::barValueChanged(int index) | |
547 | { |
|
583 | { | |
548 | if (m_seriesSignalsBlock) |
|
584 | if (m_seriesSignalsBlock) | |
549 | return; |
|
585 | return; | |
550 |
|
586 | |||
551 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
587 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
552 |
|
588 | |||
553 | blockModelSignals(); |
|
589 | blockModelSignals(); | |
554 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); |
|
590 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); | |
555 | blockModelSignals(false); |
|
591 | blockModelSignals(false); | |
556 | initializeBarFromModel(); |
|
592 | initializeBarFromModel(); | |
557 | } |
|
593 | } | |
558 |
|
594 | |||
559 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
595 | void QBarModelMapperPrivate::initializeBarFromModel() | |
560 | { |
|
596 | { | |
561 | if (m_model == 0 || m_series == 0) |
|
597 | if (m_model == 0 || m_series == 0) | |
562 | return; |
|
598 | return; | |
563 |
|
599 | |||
564 | blockSeriesSignals(); |
|
600 | blockSeriesSignals(); | |
565 | // clear current content |
|
601 | // clear current content | |
566 | m_series->clear(); |
|
602 | m_series->clear(); | |
567 | m_barSets.clear(); |
|
603 | m_barSets.clear(); | |
568 |
|
604 | |||
569 | // create the initial bar sets |
|
605 | // create the initial bar sets | |
570 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
606 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { | |
571 | int posInBar = 0; |
|
607 | int posInBar = 0; | |
572 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
608 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
573 | // check if there is such model index |
|
609 | // check if there is such model index | |
574 | if (barIndex.isValid()) { |
|
610 | if (barIndex.isValid()) { | |
575 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); |
|
611 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); | |
576 | while (barIndex.isValid()) { |
|
612 | while (barIndex.isValid()) { | |
577 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
613 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
578 | posInBar++; |
|
614 | posInBar++; | |
579 | barIndex = barModelIndex(i, posInBar); |
|
615 | barIndex = barModelIndex(i, posInBar); | |
580 | } |
|
616 | } | |
581 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); |
|
617 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); | |
582 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); |
|
618 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); | |
583 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); |
|
619 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); | |
584 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); |
|
620 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); | |
585 | m_series->append(barSet); |
|
621 | m_series->append(barSet); | |
586 | m_barSets.append(barSet); |
|
622 | m_barSets.append(barSet); | |
587 | } else { |
|
623 | } else { | |
588 | break; |
|
624 | break; | |
589 | } |
|
625 | } | |
590 | } |
|
626 | } | |
591 | blockSeriesSignals(false); |
|
627 | blockSeriesSignals(false); | |
592 | } |
|
628 | } | |
593 |
|
629 | |||
594 | #include "moc_qbarmodelmapper.cpp" |
|
630 | #include "moc_qbarmodelmapper.cpp" | |
595 | #include "moc_qbarmodelmapper_p.cpp" |
|
631 | #include "moc_qbarmodelmapper_p.cpp" | |
596 |
|
632 | |||
597 | QTCOMMERCIALCHART_END_NAMESPACE |
|
633 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,79 +1,85 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QBARMODELMAPPER_H |
|
21 | #ifndef QBARMODELMAPPER_H | |
22 | #define QBARMODELMAPPER_H |
|
22 | #define QBARMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 |
|
26 | |||
27 | class QAbstractItemModel; |
|
27 | class QAbstractItemModel; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QBarModelMapperPrivate; |
|
31 | class QBarModelMapperPrivate; | |
32 | class QBarSeries; |
|
32 | class QBarSeries; | |
33 | class QChart; |
|
33 | class QChart; | |
34 |
|
34 | |||
35 | class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject |
|
35 | class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject | |
36 | { |
|
36 | { | |
37 | Q_OBJECT |
|
37 | Q_OBJECT | |
38 | Q_PROPERTY(QBarSeries *series READ series WRITE setSeries) |
|
38 | Q_PROPERTY(QBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |
39 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel) |
|
39 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) | |
40 | Q_PROPERTY(int first READ first WRITE setFirst) |
|
40 | Q_PROPERTY(int first READ first WRITE setFirst NOTIFY firstChanged) | |
41 | Q_PROPERTY(int count READ count WRITE setCount) |
|
41 | Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) | |
42 | Q_ENUMS(Qt::Orientation) |
|
42 | Q_ENUMS(Qt::Orientation) | |
43 |
|
43 | |||
44 | protected: |
|
44 | protected: | |
45 | explicit QBarModelMapper(QObject *parent = 0); |
|
45 | explicit QBarModelMapper(QObject *parent = 0); | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 | QAbstractItemModel* model() const; |
|
48 | QAbstractItemModel* model() const; | |
49 | void setModel(QAbstractItemModel *model); |
|
49 | void setModel(QAbstractItemModel *model); | |
50 |
|
50 | |||
51 | QBarSeries* series() const; |
|
51 | QBarSeries* series() const; | |
52 | void setSeries(QBarSeries *series); |
|
52 | void setSeries(QBarSeries *series); | |
53 |
|
53 | |||
54 | int first() const; |
|
54 | int first() const; | |
55 | void setFirst(int first); |
|
55 | void setFirst(int first); | |
56 |
|
56 | |||
57 | int count() const; |
|
57 | int count() const; | |
58 | void setCount(int count); |
|
58 | void setCount(int count); | |
59 |
|
59 | |||
60 | void reset(); |
|
60 | void reset(); | |
61 |
|
61 | |||
62 | protected: |
|
62 | protected: | |
63 | int firstBarSetSection() const; |
|
63 | int firstBarSetSection() const; | |
64 | void setFirstBarSetSection(int firstBarSetSection); |
|
64 | void setFirstBarSetSection(int firstBarSetSection); | |
65 |
|
65 | |||
66 | int lastBarSetSection() const; |
|
66 | int lastBarSetSection() const; | |
67 | void setLastBarSetSection(int lastBarSetSection); |
|
67 | void setLastBarSetSection(int lastBarSetSection); | |
68 |
|
68 | |||
69 | Qt::Orientation orientation() const; |
|
69 | Qt::Orientation orientation() const; | |
70 | void setOrientation(Qt::Orientation orientation); |
|
70 | void setOrientation(Qt::Orientation orientation); | |
71 |
|
71 | |||
|
72 | Q_SIGNALS: | |||
|
73 | void seriesReplaced(); | |||
|
74 | void modelReplaced(); | |||
|
75 | void firstChanged(); | |||
|
76 | void countChanged(); | |||
|
77 | ||||
72 | protected: |
|
78 | protected: | |
73 | QBarModelMapperPrivate * const d_ptr; |
|
79 | QBarModelMapperPrivate * const d_ptr; | |
74 | Q_DECLARE_PRIVATE(QBarModelMapper) |
|
80 | Q_DECLARE_PRIVATE(QBarModelMapper) | |
75 | }; |
|
81 | }; | |
76 |
|
82 | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | QTCOMMERCIALCHART_END_NAMESPACE | |
78 |
|
84 | |||
79 | #endif // QBARMODELMAPPER_H |
|
85 | #endif // QBARMODELMAPPER_H |
@@ -1,83 +1,101 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "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 part of QtCommercial chart API. | |
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 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. |
|
32 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. | |
33 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. |
|
33 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. | |
34 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. |
|
34 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. | |
35 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
35 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \property QHBarModelMapper::firstBarSetRow |
|
39 | \property QHBarModelMapper::firstBarSetRow | |
40 | \brief Defines which column of the model is used as the data source for the first bar set |
|
40 | \brief Defines which column of the model is used as the data source for the first bar set | |
41 |
|
41 | |||
42 | Default value is: -1 (invalid mapping) |
|
42 | Default value is: -1 (invalid mapping) | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \property QHBarModelMapper::lastBarSetRow |
|
46 | \property QHBarModelMapper::lastBarSetRow | |
47 | \brief Defines which column of the model is used as the data source for the last bar set |
|
47 | \brief Defines which column of the model is used as the data source for the last bar set | |
48 |
|
48 | |||
49 | Default value is: -1 (invalid mapping) |
|
49 | Default value is: -1 (invalid mapping) | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
|
53 | \fn void QHBarModelMapper::firstBarSetRowChanged() | |||
|
54 | ||||
|
55 | Emitted when the firstBarSetRow has changed. | |||
|
56 | */ | |||
|
57 | ||||
|
58 | /*! | |||
|
59 | \fn void QHBarModelMapper::lastBarSetRowChanged() | |||
|
60 | ||||
|
61 | Emitted when the lastBarSetRow has changed. | |||
|
62 | */ | |||
|
63 | ||||
|
64 | /*! | |||
53 | Constructs a mapper object which is a child of \a parent. |
|
65 | Constructs a mapper object which is a child of \a parent. | |
54 | */ |
|
66 | */ | |
55 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
67 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : | |
56 | QBarModelMapper(parent) |
|
68 | QBarModelMapper(parent) | |
57 | { |
|
69 | { | |
58 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
70 | QBarModelMapper::setOrientation(Qt::Horizontal); | |
59 | } |
|
71 | } | |
60 |
|
72 | |||
61 | int QHBarModelMapper::firstBarSetRow() const |
|
73 | int QHBarModelMapper::firstBarSetRow() const | |
62 | { |
|
74 | { | |
63 | return QBarModelMapper::firstBarSetSection(); |
|
75 | return QBarModelMapper::firstBarSetSection(); | |
64 | } |
|
76 | } | |
65 |
|
77 | |||
66 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
78 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) | |
67 | { |
|
79 | { | |
68 | return QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
80 | if (firstBarSetRow != firstBarSetSection()) { | |
|
81 | return QBarModelMapper::setFirstBarSetSection(firstBarSetRow); | |||
|
82 | emit firstBarSetRowChanged(); | |||
|
83 | } | |||
69 | } |
|
84 | } | |
70 |
|
85 | |||
71 | int QHBarModelMapper::lastBarSetRow() const |
|
86 | int QHBarModelMapper::lastBarSetRow() const | |
72 | { |
|
87 | { | |
73 | return QBarModelMapper::lastBarSetSection(); |
|
88 | return QBarModelMapper::lastBarSetSection(); | |
74 | } |
|
89 | } | |
75 |
|
90 | |||
76 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
91 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) | |
77 | { |
|
92 | { | |
78 | return QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
93 | if (lastBarSetRow != lastBarSetSection()) { | |
|
94 | return QBarModelMapper::setLastBarSetSection(lastBarSetRow); | |||
|
95 | emit lastBarSetRowChanged(); | |||
|
96 | } | |||
79 | } |
|
97 | } | |
80 |
|
98 | |||
81 | #include "moc_qhbarmodelmapper.cpp" |
|
99 | #include "moc_qhbarmodelmapper.cpp" | |
82 |
|
100 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,50 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QHBARMODELMAPPER_H |
|
21 | #ifndef QHBARMODELMAPPER_H | |
22 | #define QHBARMODELMAPPER_H |
|
22 | #define QHBARMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include <QBarModelMapper> |
|
24 | #include <QBarModelMapper> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow) |
|
31 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow NOTIFY firstBarSetRowChanged) | |
32 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow) |
|
32 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow NOTIFY lastBarSetRowChanged) | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | explicit QHBarModelMapper(QObject *parent = 0); |
|
35 | explicit QHBarModelMapper(QObject *parent = 0); | |
36 |
|
36 | |||
37 | int firstBarSetRow() const; |
|
37 | int firstBarSetRow() const; | |
38 | void setFirstBarSetRow(int firstBarSetRow); |
|
38 | void setFirstBarSetRow(int firstBarSetRow); | |
39 |
|
39 | |||
40 | int lastBarSetRow() const; |
|
40 | int lastBarSetRow() const; | |
41 | void setLastBarSetRow(int lastBarSetRow); |
|
41 | void setLastBarSetRow(int lastBarSetRow); | |
|
42 | ||||
|
43 | Q_SIGNALS: | |||
|
44 | void firstBarSetRowChanged(); | |||
|
45 | void lastBarSetRowChanged(); | |||
42 | }; |
|
46 | }; | |
43 |
|
47 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
49 | |||
46 | #endif // QHBARMODELMAPPER_H |
|
50 | #endif // QHBARMODELMAPPER_H |
@@ -1,83 +1,101 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "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 part of QtCommercial chart API. | |
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 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. |
|
32 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. | |
33 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. |
|
33 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. | |
34 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. |
|
34 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. | |
35 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
35 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \property QVBarModelMapper::firstBarSetColumn |
|
39 | \property QVBarModelMapper::firstBarSetColumn | |
40 | \brief Defines which column of the model is used as the data source for the first bar set |
|
40 | \brief Defines which column of the model is used as the data source for the first bar set | |
41 |
|
41 | |||
42 | Default value is: -1 (invalid mapping) |
|
42 | Default value is: -1 (invalid mapping) | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \property QVBarModelMapper::lastBarSetColumn |
|
46 | \property QVBarModelMapper::lastBarSetColumn | |
47 | \brief Defines which column of the model is used as the data source for the last bar set |
|
47 | \brief Defines which column of the model is used as the data source for the last bar set | |
48 |
|
48 | |||
49 | Default value is: -1 (invalid mapping) |
|
49 | Default value is: -1 (invalid mapping) | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
|
53 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |||
|
54 | ||||
|
55 | Emitted when the firstBarSetColumn has changed. | |||
|
56 | */ | |||
|
57 | ||||
|
58 | /*! | |||
|
59 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |||
|
60 | ||||
|
61 | Emitted when the lastBarSetColumn has changed. | |||
|
62 | */ | |||
|
63 | ||||
|
64 | /*! | |||
53 | Constructs a mapper object which is a child of \a parent. |
|
65 | Constructs a mapper object which is a child of \a parent. | |
54 | */ |
|
66 | */ | |
55 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
67 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
56 | QBarModelMapper(parent) |
|
68 | QBarModelMapper(parent) | |
57 | { |
|
69 | { | |
58 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
70 | QBarModelMapper::setOrientation(Qt::Vertical); | |
59 | } |
|
71 | } | |
60 |
|
72 | |||
61 | int QVBarModelMapper::firstBarSetColumn() const |
|
73 | int QVBarModelMapper::firstBarSetColumn() const | |
62 | { |
|
74 | { | |
63 | return QBarModelMapper::firstBarSetSection(); |
|
75 | return QBarModelMapper::firstBarSetSection(); | |
64 | } |
|
76 | } | |
65 |
|
77 | |||
66 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
78 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
67 | { |
|
79 | { | |
68 | return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
80 | if (firstBarSetColumn != firstBarSetSection()) { | |
|
81 | return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |||
|
82 | emit firstBarSetColumnChanged(); | |||
|
83 | } | |||
69 | } |
|
84 | } | |
70 |
|
85 | |||
71 | int QVBarModelMapper::lastBarSetColumn() const |
|
86 | int QVBarModelMapper::lastBarSetColumn() const | |
72 | { |
|
87 | { | |
73 | return QBarModelMapper::lastBarSetSection(); |
|
88 | return QBarModelMapper::lastBarSetSection(); | |
74 | } |
|
89 | } | |
75 |
|
90 | |||
76 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
91 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
77 | { |
|
92 | { | |
78 | return QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
93 | if (lastBarSetColumn != lastBarSetSection()) { | |
|
94 | return QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |||
|
95 | emit lastBarSetColumnChanged(); | |||
|
96 | } | |||
79 | } |
|
97 | } | |
80 |
|
98 | |||
81 | #include "moc_qvbarmodelmapper.cpp" |
|
99 | #include "moc_qvbarmodelmapper.cpp" | |
82 |
|
100 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,50 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QVBARMODELMAPPER_H |
|
21 | #ifndef QVBARMODELMAPPER_H | |
22 | #define QVBARMODELMAPPER_H |
|
22 | #define QVBARMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include <QBarModelMapper> |
|
24 | #include <QBarModelMapper> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn) |
|
31 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn NOTIFY firstBarSetColumnChanged) | |
32 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn) |
|
32 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn NOTIFY lastBarSetColumnChanged) | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | explicit QVBarModelMapper(QObject *parent = 0); |
|
35 | explicit QVBarModelMapper(QObject *parent = 0); | |
36 |
|
36 | |||
37 | int firstBarSetColumn() const; |
|
37 | int firstBarSetColumn() const; | |
38 | void setFirstBarSetColumn(int firstBarSetColumn); |
|
38 | void setFirstBarSetColumn(int firstBarSetColumn); | |
39 |
|
39 | |||
40 | int lastBarSetColumn() const; |
|
40 | int lastBarSetColumn() const; | |
41 | void setLastBarSetColumn(int lastBarSetColumn); |
|
41 | void setLastBarSetColumn(int lastBarSetColumn); | |
|
42 | ||||
|
43 | Q_SIGNALS: | |||
|
44 | void firstBarSetColumnChanged(); | |||
|
45 | void lastBarSetColumnChanged(); | |||
42 | }; |
|
46 | }; | |
43 |
|
47 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
49 | |||
46 | #endif // QVBARMODELMAPPER_H |
|
50 | #endif // QVBARMODELMAPPER_H |
General Comments 0
You need to be logged in to leave comments.
Login now