@@ -1,482 +1,428 | |||||
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 | 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. |
|
35 | 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 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. |
|
36 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. | |
37 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. |
|
37 | 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 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. |
|
38 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. | |
39 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
39 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \property QBarModelMapper::series |
|
43 | \property QBarModelMapper::series | |
44 | \brief Defines the QPieSeries object that is used by the mapper. |
|
44 | \brief Defines the QPieSeries object that is used by the mapper. | |
45 |
|
45 | |||
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 | \property QBarModelMapper::first |
|
56 | \property QBarModelMapper::first | |
57 | \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. |
|
57 | \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. | |
58 |
|
58 | |||
59 | Minimal and default value is: 0 |
|
59 | Minimal and default value is: 0 | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QBarModelMapper::count |
|
63 | \property QBarModelMapper::count | |
64 | \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries |
|
64 | \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries | |
65 |
|
65 | |||
66 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
66 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | Constructs a mapper object which is a child of \a parent. |
|
70 | Constructs a mapper object which is a child of \a parent. | |
71 | */ |
|
71 | */ | |
72 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
72 | QBarModelMapper::QBarModelMapper(QObject *parent) : | |
73 | QObject(parent), |
|
73 | QObject(parent), | |
74 | d_ptr(new QBarModelMapperPrivate(this)) |
|
74 | d_ptr(new QBarModelMapperPrivate(this)) | |
75 | { |
|
75 | { | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | QAbstractItemModel* QBarModelMapper::model() const |
|
78 | QAbstractItemModel* QBarModelMapper::model() const | |
79 | { |
|
79 | { | |
80 | Q_D(const QBarModelMapper); |
|
80 | Q_D(const QBarModelMapper); | |
81 | return d->m_model; |
|
81 | return d->m_model; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
84 | void QBarModelMapper::setModel(QAbstractItemModel *model) | |
85 | { |
|
85 | { | |
86 | if (model == 0) |
|
86 | if (model == 0) | |
87 | return; |
|
87 | return; | |
88 |
|
88 | |||
89 | Q_D(QBarModelMapper); |
|
89 | Q_D(QBarModelMapper); | |
90 | if (d->m_model) { |
|
90 | if (d->m_model) { | |
91 | disconnect(d->m_model, 0, d, 0); |
|
91 | disconnect(d->m_model, 0, d, 0); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | d->m_model = model; |
|
94 | d->m_model = model; | |
95 | d->initializeBarFromModel(); |
|
95 | d->initializeBarFromModel(); | |
96 | // connect signals from the model |
|
96 | // connect signals from the model | |
97 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
97 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
98 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
98 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
99 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
99 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
100 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
100 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
101 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
101 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | QBarSeries* QBarModelMapper::series() const |
|
104 | QBarSeries* QBarModelMapper::series() const | |
105 | { |
|
105 | { | |
106 | Q_D(const QBarModelMapper); |
|
106 | Q_D(const QBarModelMapper); | |
107 | return d->m_series; |
|
107 | return d->m_series; | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void QBarModelMapper::setSeries(QBarSeries *series) |
|
110 | void QBarModelMapper::setSeries(QBarSeries *series) | |
111 | { |
|
111 | { | |
112 | Q_D(QBarModelMapper); |
|
112 | Q_D(QBarModelMapper); | |
113 | if (d->m_series) { |
|
113 | if (d->m_series) { | |
114 | disconnect(d->m_series, 0, d, 0); |
|
114 | disconnect(d->m_series, 0, d, 0); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | if (series == 0) |
|
117 | if (series == 0) | |
118 | return; |
|
118 | return; | |
119 |
|
119 | |||
120 | d->m_series = series; |
|
120 | d->m_series = series; | |
121 | d->initializeBarFromModel(); |
|
121 | d->initializeBarFromModel(); | |
122 | // connect the signals from the series |
|
122 | // connect the signals from the series | |
123 | // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); |
|
123 | // TODO: TO be implemented | |
124 | // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); |
|
|||
125 | // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); |
|
|||
126 | } |
|
124 | } | |
127 |
|
125 | |||
128 | int QBarModelMapper::first() const |
|
126 | int QBarModelMapper::first() const | |
129 | { |
|
127 | { | |
130 | Q_D(const QBarModelMapper); |
|
128 | Q_D(const QBarModelMapper); | |
131 | return d->m_first; |
|
129 | return d->m_first; | |
132 | } |
|
130 | } | |
133 |
|
131 | |||
134 | void QBarModelMapper::setFirst(int first) |
|
132 | void QBarModelMapper::setFirst(int first) | |
135 | { |
|
133 | { | |
136 | Q_D(QBarModelMapper); |
|
134 | Q_D(QBarModelMapper); | |
137 | d->m_first = qMax(first, 0); |
|
135 | d->m_first = qMax(first, 0); | |
138 | d->initializeBarFromModel(); |
|
136 | d->initializeBarFromModel(); | |
139 | } |
|
137 | } | |
140 |
|
138 | |||
141 | int QBarModelMapper::count() const |
|
139 | int QBarModelMapper::count() const | |
142 | { |
|
140 | { | |
143 | Q_D(const QBarModelMapper); |
|
141 | Q_D(const QBarModelMapper); | |
144 | return d->m_count; |
|
142 | return d->m_count; | |
145 | } |
|
143 | } | |
146 |
|
144 | |||
147 | void QBarModelMapper::setCount(int count) |
|
145 | void QBarModelMapper::setCount(int count) | |
148 | { |
|
146 | { | |
149 | Q_D(QBarModelMapper); |
|
147 | Q_D(QBarModelMapper); | |
150 | d->m_count = qMax(count, -1); |
|
148 | d->m_count = qMax(count, -1); | |
151 | d->initializeBarFromModel(); |
|
149 | d->initializeBarFromModel(); | |
152 | } |
|
150 | } | |
153 |
|
151 | |||
154 | /*! |
|
152 | /*! | |
155 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
153 | Returns the orientation that is used when QBarModelMapper accesses the model. | |
156 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
154 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) | |
157 | or from columns (Qt::Vertical) |
|
155 | or from columns (Qt::Vertical) | |
158 | */ |
|
156 | */ | |
159 | Qt::Orientation QBarModelMapper::orientation() const |
|
157 | Qt::Orientation QBarModelMapper::orientation() const | |
160 | { |
|
158 | { | |
161 | Q_D(const QBarModelMapper); |
|
159 | Q_D(const QBarModelMapper); | |
162 | return d->m_orientation; |
|
160 | return d->m_orientation; | |
163 | } |
|
161 | } | |
164 |
|
162 | |||
165 | /*! |
|
163 | /*! | |
166 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
164 | Returns the \a orientation that is used when QBarModelMapper accesses the model. | |
167 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
165 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) | |
168 | or from columns (Qt::Vertical) |
|
166 | or from columns (Qt::Vertical) | |
169 | */ |
|
167 | */ | |
170 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
168 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) | |
171 | { |
|
169 | { | |
172 | Q_D(QBarModelMapper); |
|
170 | Q_D(QBarModelMapper); | |
173 | d->m_orientation = orientation; |
|
171 | d->m_orientation = orientation; | |
174 | d->initializeBarFromModel(); |
|
172 | d->initializeBarFromModel(); | |
175 | } |
|
173 | } | |
176 |
|
174 | |||
177 | /*! |
|
175 | /*! | |
178 | Returns which section of the model is used as the data source for the first bar set |
|
176 | Returns which section of the model is used as the data source for the first bar set | |
179 | */ |
|
177 | */ | |
180 | int QBarModelMapper::firstBarSetSection() const |
|
178 | int QBarModelMapper::firstBarSetSection() const | |
181 | { |
|
179 | { | |
182 | Q_D(const QBarModelMapper); |
|
180 | Q_D(const QBarModelMapper); | |
183 | return d->m_firstBarSetSection; |
|
181 | return d->m_firstBarSetSection; | |
184 | } |
|
182 | } | |
185 |
|
183 | |||
186 | /*! |
|
184 | /*! | |
187 | Sets the model section that is used as the data source for the first bar set |
|
185 | Sets the model section that is used as the data source for the first bar set | |
188 | Parameter \a firstBarSetSection specifies the section of the model. |
|
186 | Parameter \a firstBarSetSection specifies the section of the model. | |
189 | */ |
|
187 | */ | |
190 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
188 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) | |
191 | { |
|
189 | { | |
192 | Q_D(QBarModelMapper); |
|
190 | Q_D(QBarModelMapper); | |
193 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); |
|
191 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); | |
194 | d->initializeBarFromModel(); |
|
192 | d->initializeBarFromModel(); | |
195 | } |
|
193 | } | |
196 |
|
194 | |||
197 | /*! |
|
195 | /*! | |
198 | Returns which section of the model is used as the data source for the last bar set |
|
196 | Returns which section of the model is used as the data source for the last bar set | |
199 | */ |
|
197 | */ | |
200 | int QBarModelMapper::lastBarSetSection() const |
|
198 | int QBarModelMapper::lastBarSetSection() const | |
201 | { |
|
199 | { | |
202 | Q_D(const QBarModelMapper); |
|
200 | Q_D(const QBarModelMapper); | |
203 | return d->m_lastBarSetSection; |
|
201 | return d->m_lastBarSetSection; | |
204 | } |
|
202 | } | |
205 |
|
203 | |||
206 | /*! |
|
204 | /*! | |
207 | Sets the model section that is used as the data source for the last bar set |
|
205 | Sets the model section that is used as the data source for the last bar set | |
208 | Parameter \a lastBarSetSection specifies the section of the model. |
|
206 | Parameter \a lastBarSetSection specifies the section of the model. | |
209 | */ |
|
207 | */ | |
210 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
208 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |
211 | { |
|
209 | { | |
212 | Q_D(QBarModelMapper); |
|
210 | Q_D(QBarModelMapper); | |
213 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); |
|
211 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); | |
214 | d->initializeBarFromModel(); |
|
212 | d->initializeBarFromModel(); | |
215 | } |
|
213 | } | |
216 |
|
214 | |||
217 | /*! |
|
215 | /*! | |
218 | Resets the QBarModelMapper to the default state. |
|
216 | Resets the QBarModelMapper to the default state. | |
219 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 |
|
217 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 | |
220 | */ |
|
218 | */ | |
221 | void QBarModelMapper::reset() |
|
219 | void QBarModelMapper::reset() | |
222 | { |
|
220 | { | |
223 | Q_D(QBarModelMapper); |
|
221 | Q_D(QBarModelMapper); | |
224 | d->m_first = 0; |
|
222 | d->m_first = 0; | |
225 | d->m_count = -1; |
|
223 | d->m_count = -1; | |
226 | d->m_firstBarSetSection = -1; |
|
224 | d->m_firstBarSetSection = -1; | |
227 | d->m_lastBarSetSection = -1; |
|
225 | d->m_lastBarSetSection = -1; | |
228 | d->initializeBarFromModel(); |
|
226 | d->initializeBarFromModel(); | |
229 | } |
|
227 | } | |
230 |
|
228 | |||
231 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
229 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
232 |
|
230 | |||
233 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
231 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
234 | m_series(0), |
|
232 | m_series(0), | |
235 | m_model(0), |
|
233 | m_model(0), | |
236 | m_first(0), |
|
234 | m_first(0), | |
237 | m_count(-1), |
|
235 | m_count(-1), | |
238 | m_orientation(Qt::Vertical), |
|
236 | m_orientation(Qt::Vertical), | |
239 | m_firstBarSetSection(-1), |
|
237 | m_firstBarSetSection(-1), | |
240 | m_lastBarSetSection(-1), |
|
238 | m_lastBarSetSection(-1), | |
241 | m_seriesSignalsBlock(false), |
|
239 | m_seriesSignalsBlock(false), | |
242 | m_modelSignalsBlock(false), |
|
240 | m_modelSignalsBlock(false), | |
243 | q_ptr(q) |
|
241 | q_ptr(q) | |
244 | { |
|
242 | { | |
245 | } |
|
243 | } | |
246 |
|
244 | |||
247 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
245 | void QBarModelMapperPrivate::blockModelSignals(bool block) | |
248 | { |
|
246 | { | |
249 | m_modelSignalsBlock = block; |
|
247 | m_modelSignalsBlock = block; | |
250 | } |
|
248 | } | |
251 |
|
249 | |||
252 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
250 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |
253 | { |
|
251 | { | |
254 | m_seriesSignalsBlock = block; |
|
252 | m_seriesSignalsBlock = block; | |
255 | } |
|
253 | } | |
256 |
|
254 | |||
257 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
255 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
258 | { |
|
256 | { | |
259 | if (!index.isValid()) |
|
257 | if (!index.isValid()) | |
260 | return 0; |
|
258 | return 0; | |
261 |
|
259 | |||
262 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
260 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { | |
263 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
261 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
264 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
262 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
265 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
263 | return m_series->barSets().at(index.column() - m_firstBarSetSection); | |
266 | // else |
|
264 | // else | |
267 | // return 0; |
|
265 | // return 0; | |
268 | } |
|
266 | } | |
269 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
267 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { | |
270 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
268 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
271 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
269 | return m_series->barSets().at(index.row() - m_firstBarSetSection); | |
272 | } |
|
270 | } | |
273 | return 0; // This part of model has not been mapped to any slice |
|
271 | return 0; // This part of model has not been mapped to any slice | |
274 | } |
|
272 | } | |
275 |
|
273 | |||
276 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
274 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) | |
277 | { |
|
275 | { | |
278 | if (m_count != -1 && posInBar >= m_count) |
|
276 | if (m_count != -1 && posInBar >= m_count) | |
279 | return QModelIndex(); // invalid |
|
277 | return QModelIndex(); // invalid | |
280 |
|
278 | |||
281 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
279 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) | |
282 | return QModelIndex(); // invalid |
|
280 | return QModelIndex(); // invalid | |
283 |
|
281 | |||
284 | if (m_orientation == Qt::Vertical) |
|
282 | if (m_orientation == Qt::Vertical) | |
285 | return m_model->index(posInBar + m_first, barSection); |
|
283 | return m_model->index(posInBar + m_first, barSection); | |
286 | else |
|
284 | else | |
287 | return m_model->index(barSection, posInBar + m_first); |
|
285 | return m_model->index(barSection, posInBar + m_first); | |
288 | } |
|
286 | } | |
289 |
|
287 | |||
290 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
288 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
291 | { |
|
289 | { | |
292 | Q_UNUSED(topLeft) |
|
290 | Q_UNUSED(topLeft) | |
293 | Q_UNUSED(bottomRight) |
|
291 | Q_UNUSED(bottomRight) | |
294 |
|
292 | |||
295 | if (m_model == 0 || m_series == 0) |
|
293 | if (m_model == 0 || m_series == 0) | |
296 | return; |
|
294 | return; | |
297 |
|
295 | |||
298 | if (m_modelSignalsBlock) |
|
296 | if (m_modelSignalsBlock) | |
299 | return; |
|
297 | return; | |
300 |
|
298 | |||
301 | blockSeriesSignals(); |
|
299 | blockSeriesSignals(); | |
302 | QModelIndex index; |
|
300 | QModelIndex index; | |
303 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
301 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
304 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
302 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
305 | index = topLeft.sibling(row, column); |
|
303 | index = topLeft.sibling(row, column); | |
306 | QBarSet* bar = barSet(index); |
|
304 | QBarSet* bar = barSet(index); | |
307 | if (bar) { |
|
305 | if (bar) { | |
308 | if (m_orientation == Qt::Vertical) |
|
306 | if (m_orientation == Qt::Vertical) | |
309 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
307 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
310 | else |
|
308 | else | |
311 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
309 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
312 | } |
|
310 | } | |
313 | } |
|
311 | } | |
314 | } |
|
312 | } | |
315 | blockSeriesSignals(false); |
|
313 | blockSeriesSignals(false); | |
316 | } |
|
314 | } | |
317 |
|
315 | |||
318 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
316 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
319 | { |
|
317 | { | |
320 | Q_UNUSED(parent); |
|
318 | Q_UNUSED(parent); | |
321 | Q_UNUSED(end) |
|
319 | Q_UNUSED(end) | |
322 | if (m_modelSignalsBlock) |
|
320 | if (m_modelSignalsBlock) | |
323 | return; |
|
321 | return; | |
324 |
|
322 | |||
325 | blockSeriesSignals(); |
|
323 | blockSeriesSignals(); | |
326 | if (m_orientation == Qt::Vertical) |
|
324 | if (m_orientation == Qt::Vertical) | |
327 | // insertData(start, end); |
|
325 | // insertData(start, end); | |
328 | initializeBarFromModel(); |
|
326 | initializeBarFromModel(); | |
329 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
327 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
330 | initializeBarFromModel(); |
|
328 | initializeBarFromModel(); | |
331 | blockSeriesSignals(false); |
|
329 | blockSeriesSignals(false); | |
332 | } |
|
330 | } | |
333 |
|
331 | |||
334 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
332 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
335 | { |
|
333 | { | |
336 | Q_UNUSED(parent); |
|
334 | Q_UNUSED(parent); | |
337 | Q_UNUSED(end) |
|
335 | Q_UNUSED(end) | |
338 | if (m_modelSignalsBlock) |
|
336 | if (m_modelSignalsBlock) | |
339 | return; |
|
337 | return; | |
340 |
|
338 | |||
341 | blockSeriesSignals(); |
|
339 | blockSeriesSignals(); | |
342 | if (m_orientation == Qt::Vertical) |
|
340 | if (m_orientation == Qt::Vertical) | |
343 | // removeData(start, end); |
|
341 | // removeData(start, end); | |
344 | initializeBarFromModel(); |
|
342 | initializeBarFromModel(); | |
345 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
343 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
346 | initializeBarFromModel(); |
|
344 | initializeBarFromModel(); | |
347 | blockSeriesSignals(false); |
|
345 | blockSeriesSignals(false); | |
348 | } |
|
346 | } | |
349 |
|
347 | |||
350 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
348 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
351 | { |
|
349 | { | |
352 | Q_UNUSED(parent); |
|
350 | Q_UNUSED(parent); | |
353 | Q_UNUSED(end) |
|
351 | Q_UNUSED(end) | |
354 | if (m_modelSignalsBlock) |
|
352 | if (m_modelSignalsBlock) | |
355 | return; |
|
353 | return; | |
356 |
|
354 | |||
357 | blockSeriesSignals(); |
|
355 | blockSeriesSignals(); | |
358 | if (m_orientation == Qt::Horizontal) |
|
356 | if (m_orientation == Qt::Horizontal) | |
359 | // insertData(start, end); |
|
357 | // insertData(start, end); | |
360 | initializeBarFromModel(); |
|
358 | initializeBarFromModel(); | |
361 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
359 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
362 | initializeBarFromModel(); |
|
360 | initializeBarFromModel(); | |
363 | blockSeriesSignals(false); |
|
361 | blockSeriesSignals(false); | |
364 | } |
|
362 | } | |
365 |
|
363 | |||
366 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
364 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
367 | { |
|
365 | { | |
368 | Q_UNUSED(parent); |
|
366 | Q_UNUSED(parent); | |
369 | Q_UNUSED(end) |
|
367 | Q_UNUSED(end) | |
370 | if (m_modelSignalsBlock) |
|
368 | if (m_modelSignalsBlock) | |
371 | return; |
|
369 | return; | |
372 |
|
370 | |||
373 | blockSeriesSignals(); |
|
371 | blockSeriesSignals(); | |
374 | if (m_orientation == Qt::Horizontal) |
|
372 | if (m_orientation == Qt::Horizontal) | |
375 | // removeData(start, end); |
|
373 | // removeData(start, end); | |
376 | initializeBarFromModel(); |
|
374 | initializeBarFromModel(); | |
377 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
375 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
378 | initializeBarFromModel(); |
|
376 | initializeBarFromModel(); | |
379 | blockSeriesSignals(false); |
|
377 | blockSeriesSignals(false); | |
380 | } |
|
378 | } | |
381 |
|
379 | |||
382 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
380 | void QBarModelMapperPrivate::insertData(int start, int end) | |
383 | { |
|
381 | { | |
384 | Q_UNUSED(end) |
|
382 | Q_UNUSED(end) | |
385 | if (m_model == 0 || m_series == 0) |
|
383 | Q_UNUSED(start) | |
386 | return; |
|
384 | Q_UNUSED(end) | |
387 |
|
385 | // To be implemented | ||
388 | if (m_count != -1 && start >= m_first + m_count) { |
|
|||
389 | return; |
|
|||
390 | } /*else { |
|
|||
391 | int addedCount = end - start + 1; |
|
|||
392 | if (m_count != -1 && addedCount > m_count) |
|
|||
393 | addedCount = m_count; |
|
|||
394 | int first = qMax(start, m_first); |
|
|||
395 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
|||
396 | for (int k = 0; k < m_series->barSets().count(); k++) { |
|
|||
397 | for (int i = first; i <= last; i++) { |
|
|||
398 | QBar point; |
|
|||
399 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
|||
400 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
|||
401 | m_series->insert(i - m_first, point); |
|
|||
402 | } |
|
|||
403 | >>>>>>> Stashed changes |
|
|||
404 | } |
|
|||
405 |
|
||||
406 | // remove excess of slices (abouve m_count) |
|
|||
407 | if (m_count != -1 && m_series->points().size() > m_count) |
|
|||
408 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { |
|
|||
409 | m_series->remove(m_series->points().at(i)); |
|
|||
410 | } |
|
|||
411 | }*/ |
|
|||
412 | } |
|
386 | } | |
413 |
|
387 | |||
414 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
388 | void QBarModelMapperPrivate::removeData(int start, int end) | |
415 | { |
|
389 | { | |
416 | Q_UNUSED(end) |
|
390 | Q_UNUSED(end) | |
417 | if (m_model == 0 || m_series == 0) |
|
391 | Q_UNUSED(start) | |
418 | return; |
|
392 | Q_UNUSED(end) | |
419 |
|
393 | // To be implemented | ||
420 | // int removedCount = end - start + 1; |
|
|||
421 | if (m_count != -1 && start >= m_first + m_count) { |
|
|||
422 | return; |
|
|||
423 | } /*else { |
|
|||
424 | int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed |
|
|||
425 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
|||
426 | int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed. |
|
|||
427 | for (int i = last; i >= first; i--) { |
|
|||
428 | m_series->remove(m_series->points().at(i - m_first)); |
|
|||
429 | } |
|
|||
430 |
|
||||
431 | if (m_count != -1) { |
|
|||
432 | int itemsAvailable; // check how many are available to be added |
|
|||
433 | if (m_orientation == Qt::Vertical) |
|
|||
434 | itemsAvailable = m_model->rowCount() - m_first - m_series->count(); |
|
|||
435 | else |
|
|||
436 | itemsAvailable = m_model->columnCount() - m_first - m_series->count(); |
|
|||
437 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled. |
|
|||
438 | int currentSize = m_series->count(); |
|
|||
439 | if (toBeAdded > 0) |
|
|||
440 | for (int i = m_series->count(); i < currentSize + toBeAdded; i++) { |
|
|||
441 | QPointF point; |
|
|||
442 | point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble()); |
|
|||
443 | point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble()); |
|
|||
444 | m_series->insert(i, point); |
|
|||
445 | } |
|
|||
446 | } |
|
|||
447 | }*/ |
|
|||
448 | } |
|
394 | } | |
449 |
|
395 | |||
450 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
396 | void QBarModelMapperPrivate::initializeBarFromModel() | |
451 | { |
|
397 | { | |
452 | if (m_model == 0 || m_series == 0) |
|
398 | if (m_model == 0 || m_series == 0) | |
453 | return; |
|
399 | return; | |
454 |
|
400 | |||
455 | blockSeriesSignals(); |
|
401 | blockSeriesSignals(); | |
456 | // clear current content |
|
402 | // clear current content | |
457 | m_series->clear(); |
|
403 | m_series->clear(); | |
458 |
|
404 | |||
459 | // create the initial bar sets |
|
405 | // create the initial bar sets | |
460 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
406 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { | |
461 | int posInBar = 0; |
|
407 | int posInBar = 0; | |
462 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
408 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
463 | // check if there is such model index |
|
409 | // check if there is such model index | |
464 | if (barIndex.isValid()) { |
|
410 | if (barIndex.isValid()) { | |
465 | QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); |
|
411 | QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); | |
466 | while (barIndex.isValid()) { |
|
412 | while (barIndex.isValid()) { | |
467 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
413 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
468 | posInBar++; |
|
414 | posInBar++; | |
469 | barIndex = barModelIndex(i, posInBar); |
|
415 | barIndex = barModelIndex(i, posInBar); | |
470 | } |
|
416 | } | |
471 | m_series->append(barSet); |
|
417 | m_series->append(barSet); | |
472 | } else { |
|
418 | } else { | |
473 | break; |
|
419 | break; | |
474 | } |
|
420 | } | |
475 | } |
|
421 | } | |
476 | blockSeriesSignals(false); |
|
422 | blockSeriesSignals(false); | |
477 | } |
|
423 | } | |
478 |
|
424 | |||
479 | #include "moc_qbarmodelmapper.cpp" |
|
425 | #include "moc_qbarmodelmapper.cpp" | |
480 | #include "moc_qbarmodelmapper_p.cpp" |
|
426 | #include "moc_qbarmodelmapper_p.cpp" | |
481 |
|
427 | |||
482 | QTCOMMERCIALCHART_END_NAMESPACE |
|
428 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,90 +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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QBARMODELMAPPER_P_H |
|
30 | #ifndef QBARMODELMAPPER_P_H | |
31 | #define QBARMODELMAPPER_P_H |
|
31 | #define QBARMODELMAPPER_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include <QObject> |
|
34 | #include <QObject> | |
35 | #include "qbarmodelmapper.h" |
|
35 | #include "qbarmodelmapper.h" | |
36 |
|
36 | |||
37 | class QModelIndex; |
|
37 | class QModelIndex; | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class QBarSet; |
|
41 | class QBarSet; | |
42 |
|
42 | |||
43 | class QBarModelMapperPrivate : public QObject |
|
43 | class QBarModelMapperPrivate : public QObject | |
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 | public: |
|
46 | public: | |
47 | explicit QBarModelMapperPrivate(QBarModelMapper *q); |
|
47 | explicit QBarModelMapperPrivate(QBarModelMapper *q); | |
48 |
|
48 | |||
49 | public Q_SLOTS: |
|
49 | public Q_SLOTS: | |
50 | // for the model |
|
50 | // for the model | |
51 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
51 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
52 | void modelRowsAdded(QModelIndex parent, int start, int end); |
|
52 | void modelRowsAdded(QModelIndex parent, int start, int end); | |
53 | void modelRowsRemoved(QModelIndex parent, int start, int end); |
|
53 | void modelRowsRemoved(QModelIndex parent, int start, int end); | |
54 | void modelColumnsAdded(QModelIndex parent, int start, int end); |
|
54 | void modelColumnsAdded(QModelIndex parent, int start, int end); | |
55 | void modelColumnsRemoved(QModelIndex parent, int start, int end); |
|
55 | void modelColumnsRemoved(QModelIndex parent, int start, int end); | |
56 |
|
56 | |||
57 | // // for the series |
|
|||
58 | // void handlePointAdded(int pointPos); |
|
|||
59 | // void handlePointRemoved(int pointPos); |
|
|||
60 | // void handlePointReplaced(int pointPos); |
|
|||
61 |
|
||||
62 | void initializeBarFromModel(); |
|
57 | void initializeBarFromModel(); | |
63 |
|
58 | |||
64 | private: |
|
59 | private: | |
65 | QBarSet* barSet(QModelIndex index); |
|
60 | QBarSet* barSet(QModelIndex index); | |
66 | QModelIndex barModelIndex(int barSection, int posInBar); |
|
61 | QModelIndex barModelIndex(int barSection, int posInBar); | |
67 | void insertData(int start, int end); |
|
62 | void insertData(int start, int end); | |
68 | void removeData(int start, int end); |
|
63 | void removeData(int start, int end); | |
69 | void blockModelSignals(bool block = true); |
|
64 | void blockModelSignals(bool block = true); | |
70 | void blockSeriesSignals(bool block = true); |
|
65 | void blockSeriesSignals(bool block = true); | |
71 |
|
66 | |||
72 | private: |
|
67 | private: | |
73 | QBarSeries *m_series; |
|
68 | QBarSeries *m_series; | |
74 | QAbstractItemModel *m_model; |
|
69 | QAbstractItemModel *m_model; | |
75 | int m_first; |
|
70 | int m_first; | |
76 | int m_count; |
|
71 | int m_count; | |
77 | Qt::Orientation m_orientation; |
|
72 | Qt::Orientation m_orientation; | |
78 | int m_firstBarSetSection; |
|
73 | int m_firstBarSetSection; | |
79 | int m_lastBarSetSection; |
|
74 | int m_lastBarSetSection; | |
80 | bool m_seriesSignalsBlock; |
|
75 | bool m_seriesSignalsBlock; | |
81 | bool m_modelSignalsBlock; |
|
76 | bool m_modelSignalsBlock; | |
82 |
|
77 | |||
83 | private: |
|
78 | private: | |
84 | QBarModelMapper *q_ptr; |
|
79 | QBarModelMapper *q_ptr; | |
85 | Q_DECLARE_PUBLIC(QBarModelMapper) |
|
80 | Q_DECLARE_PUBLIC(QBarModelMapper) | |
86 | }; |
|
81 | }; | |
87 |
|
82 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | QTCOMMERCIALCHART_END_NAMESPACE | |
89 |
|
84 | |||
90 | #endif // QBARMODELMAPPER_P_H |
|
85 | #endif // QBARMODELMAPPER_P_H |
@@ -1,47 +1,46 | |||||
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 QHPIEMODELMAPPER_H |
|
21 | #ifndef QHPIEMODELMAPPER_H | |
22 | #define QHPIEMODELMAPPER_H |
|
22 | #define QHPIEMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include "qpiemodelmapper.h" |
|
24 | #include "qpiemodelmapper.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow) |
|
31 | Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow) | |
32 | Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow) |
|
32 | Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow) | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | explicit QHPieModelMapper(QObject *parent = 0); |
|
35 | explicit QHPieModelMapper(QObject *parent = 0); | |
36 |
|
36 | |||
37 | int valuesRow() const; |
|
37 | int valuesRow() const; | |
38 | void setValuesRow(int valuesRow); |
|
38 | void setValuesRow(int valuesRow); | |
39 |
|
39 | |||
40 | int labelsRow() const; |
|
40 | int labelsRow() const; | |
41 | void setLabelsRow(int labelsRow); |
|
41 | void setLabelsRow(int labelsRow); | |
42 |
|
||||
43 | }; |
|
42 | }; | |
44 |
|
43 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | QTCOMMERCIALCHART_END_NAMESPACE | |
46 |
|
45 | |||
47 | #endif // QHPIEMODELMAPPER_H |
|
46 | #endif // QHPIEMODELMAPPER_H |
@@ -1,596 +1,595 | |||||
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 "qpiemodelmapper_p.h" |
|
21 | #include "qpiemodelmapper_p.h" | |
22 | #include "qpiemodelmapper.h" |
|
22 | #include "qpiemodelmapper.h" | |
23 | #include "qpieseries.h" |
|
23 | #include "qpieseries.h" | |
24 | #include "qpieslice.h" |
|
24 | #include "qpieslice.h" | |
25 | #include <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
|
30 | \class QPieModelMapper | |||
|
31 | \brief part of QtCommercial chart API. | |||
|
32 | \mainclass | |||
|
33 | ||||
|
34 | The instance of this class cannot be created directly. QHPieModelMapper of QVPieModelMapper should be used instead. This class is used to create a connection between QPieSeries and QAbstractItemModel derived model object. | |||
|
35 | It is possible to use both QAbstractItemModel and QPieSeries model API. QPieModelMapper makes sure that Pie and the model are kept in sync. | |||
|
36 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |||
|
37 | */ | |||
|
38 | ||||
|
39 | /*! | |||
30 | \property QPieModelMapper::series |
|
40 | \property QPieModelMapper::series | |
31 | \brief Defines the QPieSeries object that is used by the mapper. |
|
41 | \brief Defines the QPieSeries object that is used by the mapper. | |
32 |
|
42 | |||
33 | All the data in the series is discarded when it is set to the mapper. |
|
43 | All the data in the series is discarded when it is set to the mapper. | |
34 | When new series is specified the old series is disconnected (it preserves its data) |
|
44 | When new series is specified the old series is disconnected (it preserves its data) | |
35 | */ |
|
45 | */ | |
36 |
|
46 | |||
37 | /*! |
|
47 | /*! | |
38 | \property QPieModelMapper::model |
|
48 | \property QPieModelMapper::model | |
39 | \brief Defines the model that is used by the mapper. |
|
49 | \brief Defines the model that is used by the mapper. | |
40 | */ |
|
50 | */ | |
41 |
|
51 | |||
42 | /*! |
|
52 | /*! | |
43 | \property QPieModelMapper::first |
|
53 | \property QPieModelMapper::first | |
44 | \brief Defines which item of the model's row/column should be mapped as the value/label of the first slice of the pie |
|
54 | \brief Defines which item of the model's row/column should be mapped as the value/label of the first slice of the pie | |
45 |
|
55 | |||
46 | Minimal and default value is: 0 |
|
56 | Minimal and default value is: 0 | |
47 | */ |
|
57 | */ | |
48 |
|
58 | |||
49 | /*! |
|
59 | /*! | |
50 | \property QPieModelMapper::count |
|
60 | \property QPieModelMapper::count | |
51 | \brief Defines the number of rows/columns of the model that are mapped as the data for the pie. |
|
61 | \brief Defines the number of rows/columns of the model that are mapped as the data for the pie. | |
52 |
|
62 | |||
53 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
63 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
54 | */ |
|
64 | */ | |
55 |
|
65 | |||
56 | /*! |
|
66 | /*! | |
57 | \class QPieModelMapper |
|
|||
58 | \brief part of QtCommercial chart API. |
|
|||
59 | \mainclass |
|
|||
60 |
|
||||
61 | The instance of this class cannot be created directly. QHPieModelMapper of QVPieModelMapper should be used instead. This class is used to create a connection between QPieSeries and QAbstractItemModel derived model object. |
|
|||
62 | It is possible to use both QAbstractItemModel and QPieSeries model API. QPieModelMapper makes sure that Pie and the model are kept in sync. |
|
|||
63 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
|||
64 | */ |
|
|||
65 |
|
||||
66 | /*! |
|
|||
67 | Constructs a mapper object which is a child of \a parent. |
|
67 | Constructs a mapper object which is a child of \a parent. | |
68 | */ |
|
68 | */ | |
69 | QPieModelMapper::QPieModelMapper(QObject *parent) : |
|
69 | QPieModelMapper::QPieModelMapper(QObject *parent) : | |
70 | QObject(parent), |
|
70 | QObject(parent), | |
71 | d_ptr(new QPieModelMapperPrivate(this)) |
|
71 | d_ptr(new QPieModelMapperPrivate(this)) | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | QAbstractItemModel* QPieModelMapper::model() const |
|
75 | QAbstractItemModel* QPieModelMapper::model() const | |
76 | { |
|
76 | { | |
77 | Q_D(const QPieModelMapper); |
|
77 | Q_D(const QPieModelMapper); | |
78 | return d->m_model; |
|
78 | return d->m_model; | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void QPieModelMapper::setModel(QAbstractItemModel *model) |
|
81 | void QPieModelMapper::setModel(QAbstractItemModel *model) | |
82 | { |
|
82 | { | |
83 | if (model == 0) |
|
83 | if (model == 0) | |
84 | return; |
|
84 | return; | |
85 |
|
85 | |||
86 | Q_D(QPieModelMapper); |
|
86 | Q_D(QPieModelMapper); | |
87 | if (d->m_model) { |
|
87 | if (d->m_model) { | |
88 | disconnect(d->m_model, 0, d, 0); |
|
88 | disconnect(d->m_model, 0, d, 0); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | d->m_model = model; |
|
91 | d->m_model = model; | |
92 | d->initializePieFromModel(); |
|
92 | d->initializePieFromModel(); | |
93 | // connect signals from the model |
|
93 | // connect signals from the model | |
94 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
94 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
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 |
|
100 | |||
101 | QPieSeries* QPieModelMapper::series() const |
|
101 | QPieSeries* QPieModelMapper::series() const | |
102 | { |
|
102 | { | |
103 | Q_D(const QPieModelMapper); |
|
103 | Q_D(const QPieModelMapper); | |
104 | return d->m_series; |
|
104 | return d->m_series; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void QPieModelMapper::setSeries(QPieSeries *series) |
|
107 | void QPieModelMapper::setSeries(QPieSeries *series) | |
108 | { |
|
108 | { | |
109 | Q_D(QPieModelMapper); |
|
109 | Q_D(QPieModelMapper); | |
110 | if (d->m_series) { |
|
110 | if (d->m_series) { | |
111 | disconnect(d->m_series, 0, d, 0); |
|
111 | disconnect(d->m_series, 0, d, 0); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | if (series == 0) |
|
114 | if (series == 0) | |
115 | return; |
|
115 | return; | |
116 |
|
116 | |||
117 | d->m_series = series; |
|
117 | d->m_series = series; | |
118 | d->initializePieFromModel(); |
|
118 | d->initializePieFromModel(); | |
119 | // connect the signals from the series |
|
119 | // connect the signals from the series | |
120 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); |
|
120 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); | |
121 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); |
|
121 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | int QPieModelMapper::first() const |
|
124 | int QPieModelMapper::first() const | |
125 | { |
|
125 | { | |
126 | Q_D(const QPieModelMapper); |
|
126 | Q_D(const QPieModelMapper); | |
127 | return d->m_first; |
|
127 | return d->m_first; | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void QPieModelMapper::setFirst(int first) |
|
130 | void QPieModelMapper::setFirst(int first) | |
131 | { |
|
131 | { | |
132 | Q_D(QPieModelMapper); |
|
132 | Q_D(QPieModelMapper); | |
133 | d->m_first = qMax(first, 0); |
|
133 | d->m_first = qMax(first, 0); | |
134 | d->initializePieFromModel(); |
|
134 | d->initializePieFromModel(); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | int QPieModelMapper::count() const |
|
137 | int QPieModelMapper::count() const | |
138 | { |
|
138 | { | |
139 | Q_D(const QPieModelMapper); |
|
139 | Q_D(const QPieModelMapper); | |
140 | return d->m_count; |
|
140 | return d->m_count; | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void QPieModelMapper::setCount(int count) |
|
143 | void QPieModelMapper::setCount(int count) | |
144 | { |
|
144 | { | |
145 | Q_D(QPieModelMapper); |
|
145 | Q_D(QPieModelMapper); | |
146 | d->m_count = qMax(count, -1); |
|
146 | d->m_count = qMax(count, -1); | |
147 | d->initializePieFromModel(); |
|
147 | d->initializePieFromModel(); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | Returns the orientation that is used when QPieModelMapper accesses the model. |
|
151 | Returns the orientation that is used when QPieModelMapper accesses the model. | |
152 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) |
|
152 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) | |
153 | or from columns (Qt::Vertical) |
|
153 | or from columns (Qt::Vertical) | |
154 | */ |
|
154 | */ | |
155 | Qt::Orientation QPieModelMapper::orientation() const |
|
155 | Qt::Orientation QPieModelMapper::orientation() const | |
156 | { |
|
156 | { | |
157 | Q_D(const QPieModelMapper); |
|
157 | Q_D(const QPieModelMapper); | |
158 | return d->m_orientation; |
|
158 | return d->m_orientation; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Returns the \a orientation that is used when QPieModelMapper accesses the model. |
|
162 | Returns the \a orientation that is used when QPieModelMapper accesses the model. | |
163 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) |
|
163 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) | |
164 | or from columns (Qt::Vertical) |
|
164 | or from columns (Qt::Vertical) | |
165 | */ |
|
165 | */ | |
166 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) |
|
166 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) | |
167 | { |
|
167 | { | |
168 | Q_D(QPieModelMapper); |
|
168 | Q_D(QPieModelMapper); | |
169 | d->m_orientation = orientation; |
|
169 | d->m_orientation = orientation; | |
170 | d->initializePieFromModel(); |
|
170 | d->initializePieFromModel(); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | Returns which section of the model is kept in sync with the values of the pie's slices |
|
174 | Returns which section of the model is kept in sync with the values of the pie's slices | |
175 | */ |
|
175 | */ | |
176 | int QPieModelMapper::valuesSection() const |
|
176 | int QPieModelMapper::valuesSection() const | |
177 | { |
|
177 | { | |
178 | Q_D(const QPieModelMapper); |
|
178 | Q_D(const QPieModelMapper); | |
179 | return d->m_valuesSection; |
|
179 | return d->m_valuesSection; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | Sets the model section that is kept in sync with the pie slices values. |
|
183 | Sets the model section that is kept in sync with the pie slices values. | |
184 | Parameter \a valuesSection specifies the section of the model. |
|
184 | Parameter \a valuesSection specifies the section of the model. | |
185 | */ |
|
185 | */ | |
186 | void QPieModelMapper::setValuesSection(int valuesSection) |
|
186 | void QPieModelMapper::setValuesSection(int valuesSection) | |
187 | { |
|
187 | { | |
188 | Q_D(QPieModelMapper); |
|
188 | Q_D(QPieModelMapper); | |
189 | d->m_valuesSection = qMax(-1, valuesSection); |
|
189 | d->m_valuesSection = qMax(-1, valuesSection); | |
190 | d->initializePieFromModel(); |
|
190 | d->initializePieFromModel(); | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | Returns which section of the model is kept in sync with the labels of the pie's slices |
|
194 | Returns which section of the model is kept in sync with the labels of the pie's slices | |
195 | */ |
|
195 | */ | |
196 | int QPieModelMapper::labelsSection() const |
|
196 | int QPieModelMapper::labelsSection() const | |
197 | { |
|
197 | { | |
198 | Q_D(const QPieModelMapper); |
|
198 | Q_D(const QPieModelMapper); | |
199 | return d->m_labelsSection; |
|
199 | return d->m_labelsSection; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | Sets the model section that is kept in sync with the pie slices labels. |
|
203 | Sets the model section that is kept in sync with the pie slices labels. | |
204 | Parameter \a labelsSection specifies the section of the model. |
|
204 | Parameter \a labelsSection specifies the section of the model. | |
205 | */ |
|
205 | */ | |
206 | void QPieModelMapper::setLabelsSection(int labelsSection) |
|
206 | void QPieModelMapper::setLabelsSection(int labelsSection) | |
207 | { |
|
207 | { | |
208 | Q_D(QPieModelMapper); |
|
208 | Q_D(QPieModelMapper); | |
209 | d->m_labelsSection = qMax(-1, labelsSection); |
|
209 | d->m_labelsSection = qMax(-1, labelsSection); | |
210 | d->initializePieFromModel(); |
|
210 | d->initializePieFromModel(); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | /*! |
|
213 | /*! | |
214 | Resets the QPieModelMapper to the default state. |
|
214 | Resets the QPieModelMapper to the default state. | |
215 | first: 0; count: -1; valuesSection: -1; labelsSection: -1; |
|
215 | first: 0; count: -1; valuesSection: -1; labelsSection: -1; | |
216 | */ |
|
216 | */ | |
217 | void QPieModelMapper::reset() |
|
217 | void QPieModelMapper::reset() | |
218 | { |
|
218 | { | |
219 | Q_D(QPieModelMapper); |
|
219 | Q_D(QPieModelMapper); | |
220 | d->m_first = 0; |
|
220 | d->m_first = 0; | |
221 | d->m_count = -1; |
|
221 | d->m_count = -1; | |
222 | d->m_valuesSection = -1; |
|
222 | d->m_valuesSection = -1; | |
223 | d->m_labelsSection = -1; |
|
223 | d->m_labelsSection = -1; | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
226 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
227 |
|
227 | |||
228 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
228 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : | |
229 | m_series(0), |
|
229 | m_series(0), | |
230 | m_model(0), |
|
230 | m_model(0), | |
231 | m_first(0), |
|
231 | m_first(0), | |
232 | m_count(-1), |
|
232 | m_count(-1), | |
233 | m_orientation(Qt::Vertical), |
|
233 | m_orientation(Qt::Vertical), | |
234 | m_valuesSection(-1), |
|
234 | m_valuesSection(-1), | |
235 | m_labelsSection(-1), |
|
235 | m_labelsSection(-1), | |
236 | m_seriesSignalsBlock(false), |
|
236 | m_seriesSignalsBlock(false), | |
237 | m_modelSignalsBlock(false), |
|
237 | m_modelSignalsBlock(false), | |
238 | q_ptr(q) |
|
238 | q_ptr(q) | |
239 | { |
|
239 | { | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | void QPieModelMapperPrivate::blockModelSignals(bool block) |
|
242 | void QPieModelMapperPrivate::blockModelSignals(bool block) | |
243 | { |
|
243 | { | |
244 | m_modelSignalsBlock = block; |
|
244 | m_modelSignalsBlock = block; | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) |
|
247 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) | |
248 | { |
|
248 | { | |
249 | m_seriesSignalsBlock = block; |
|
249 | m_seriesSignalsBlock = block; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 |
|
252 | |||
253 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const |
|
253 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const | |
254 | { |
|
254 | { | |
255 | if (!index.isValid()) |
|
255 | if (!index.isValid()) | |
256 | return 0; // index is invalid |
|
256 | return 0; // index is invalid | |
257 |
|
257 | |||
258 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) { |
|
258 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) { | |
259 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
259 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
260 | if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
260 | if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
261 | return m_series->slices().at(index.row() - m_first); |
|
261 | return m_series->slices().at(index.row() - m_first); | |
262 | else |
|
262 | else | |
263 | return 0; |
|
263 | return 0; | |
264 | } |
|
264 | } | |
265 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) { |
|
265 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) { | |
266 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { |
|
266 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { | |
267 | if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid()) |
|
267 | if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid()) | |
268 | return m_series->slices().at(index.column() - m_first); |
|
268 | return m_series->slices().at(index.column() - m_first); | |
269 | else |
|
269 | else | |
270 | return 0; |
|
270 | return 0; | |
271 | } |
|
271 | } | |
272 | } |
|
272 | } | |
273 | return 0; // This part of model has not been mapped to any slice |
|
273 | return 0; // This part of model has not been mapped to any slice | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) |
|
276 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) | |
277 | { |
|
277 | { | |
278 | if (m_count != -1 && slicePos >= m_count) |
|
278 | if (m_count != -1 && slicePos >= m_count) | |
279 | return QModelIndex(); // invalid |
|
279 | return QModelIndex(); // invalid | |
280 |
|
280 | |||
281 | if (m_orientation == Qt::Vertical) |
|
281 | if (m_orientation == Qt::Vertical) | |
282 | return m_model->index(slicePos + m_first, m_valuesSection); |
|
282 | return m_model->index(slicePos + m_first, m_valuesSection); | |
283 | else |
|
283 | else | |
284 | return m_model->index(m_valuesSection, slicePos + m_first); |
|
284 | return m_model->index(m_valuesSection, slicePos + m_first); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) |
|
287 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) | |
288 | { |
|
288 | { | |
289 | if (m_count != -1 && slicePos >= m_count) |
|
289 | if (m_count != -1 && slicePos >= m_count) | |
290 | return QModelIndex(); // invalid |
|
290 | return QModelIndex(); // invalid | |
291 |
|
291 | |||
292 | if (m_orientation == Qt::Vertical) |
|
292 | if (m_orientation == Qt::Vertical) | |
293 | return m_model->index(slicePos + m_first, m_labelsSection); |
|
293 | return m_model->index(slicePos + m_first, m_labelsSection); | |
294 | else |
|
294 | else | |
295 | return m_model->index(m_labelsSection, slicePos + m_first); |
|
295 | return m_model->index(m_labelsSection, slicePos + m_first); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const |
|
298 | bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const | |
299 | { |
|
299 | { | |
300 | if (m_orientation == Qt::Vertical && index.column() == m_labelsSection) |
|
300 | if (m_orientation == Qt::Vertical && index.column() == m_labelsSection) | |
301 | return true; |
|
301 | return true; | |
302 | else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection) |
|
302 | else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection) | |
303 | return true; |
|
303 | return true; | |
304 |
|
304 | |||
305 | return false; |
|
305 | return false; | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const |
|
308 | bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const | |
309 | { |
|
309 | { | |
310 | if (m_orientation == Qt::Vertical && index.column() == m_valuesSection) |
|
310 | if (m_orientation == Qt::Vertical && index.column() == m_valuesSection) | |
311 | return true; |
|
311 | return true; | |
312 | else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection) |
|
312 | else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection) | |
313 | return true; |
|
313 | return true; | |
314 |
|
314 | |||
315 | return false; |
|
315 | return false; | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) |
|
318 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) | |
319 | { |
|
319 | { | |
320 | if (m_seriesSignalsBlock) |
|
320 | if (m_seriesSignalsBlock) | |
321 | return; |
|
321 | return; | |
322 |
|
322 | |||
323 | if (slices.count() == 0) |
|
323 | if (slices.count() == 0) | |
324 | return; |
|
324 | return; | |
325 |
|
325 | |||
326 | int firstIndex = m_series->slices().indexOf(slices.at(0)); |
|
326 | int firstIndex = m_series->slices().indexOf(slices.at(0)); | |
327 | if (firstIndex == -1) |
|
327 | if (firstIndex == -1) | |
328 | return; |
|
328 | return; | |
329 |
|
329 | |||
330 | if (m_count != -1) |
|
330 | if (m_count != -1) | |
331 | m_count += slices.count(); |
|
331 | m_count += slices.count(); | |
332 |
|
332 | |||
333 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
333 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
334 | m_slices.insert(i, slices.at(i - firstIndex)); |
|
334 | m_slices.insert(i, slices.at(i - firstIndex)); | |
335 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
335 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
336 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
336 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | blockModelSignals(); |
|
339 | blockModelSignals(); | |
340 | if (m_orientation == Qt::Vertical) |
|
340 | if (m_orientation == Qt::Vertical) | |
341 | m_model->insertRows(firstIndex + m_first, slices.count()); |
|
341 | m_model->insertRows(firstIndex + m_first, slices.count()); | |
342 | else |
|
342 | else | |
343 | m_model->insertColumns(firstIndex + m_first, slices.count()); |
|
343 | m_model->insertColumns(firstIndex + m_first, slices.count()); | |
344 |
|
344 | |||
345 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
345 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
346 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); |
|
346 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); | |
347 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); |
|
347 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); | |
348 | } |
|
348 | } | |
349 | blockModelSignals(false); |
|
349 | blockModelSignals(false); | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) |
|
352 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) | |
353 | { |
|
353 | { | |
354 | if (m_seriesSignalsBlock) |
|
354 | if (m_seriesSignalsBlock) | |
355 | return; |
|
355 | return; | |
356 |
|
356 | |||
357 | if (slices.count() == 0) |
|
357 | if (slices.count() == 0) | |
358 | return; |
|
358 | return; | |
359 |
|
359 | |||
360 | int firstIndex = m_slices.indexOf(slices.at(0)); |
|
360 | int firstIndex = m_slices.indexOf(slices.at(0)); | |
361 | if (firstIndex == -1) |
|
361 | if (firstIndex == -1) | |
362 | return; |
|
362 | return; | |
363 |
|
363 | |||
364 | if (m_count != -1) |
|
364 | if (m_count != -1) | |
365 | m_count -= slices.count(); |
|
365 | m_count -= slices.count(); | |
366 |
|
366 | |||
367 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) |
|
367 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) | |
368 | m_slices.removeAt(i); |
|
368 | m_slices.removeAt(i); | |
369 |
|
369 | |||
370 | blockModelSignals(); |
|
370 | blockModelSignals(); | |
371 | if (m_orientation == Qt::Vertical) |
|
371 | if (m_orientation == Qt::Vertical) | |
372 | m_model->removeRows(firstIndex + m_first, slices.count()); |
|
372 | m_model->removeRows(firstIndex + m_first, slices.count()); | |
373 | else |
|
373 | else | |
374 | m_model->removeColumns(firstIndex + m_first, slices.count()); |
|
374 | m_model->removeColumns(firstIndex + m_first, slices.count()); | |
375 | blockModelSignals(false); |
|
375 | blockModelSignals(false); | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | void QPieModelMapperPrivate::sliceLabelChanged() |
|
378 | void QPieModelMapperPrivate::sliceLabelChanged() | |
379 | { |
|
379 | { | |
380 | if (m_seriesSignalsBlock) |
|
380 | if (m_seriesSignalsBlock) | |
381 | return; |
|
381 | return; | |
382 |
|
382 | |||
383 | blockModelSignals(); |
|
383 | blockModelSignals(); | |
384 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
384 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
385 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); |
|
385 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); | |
386 | blockModelSignals(false); |
|
386 | blockModelSignals(false); | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | void QPieModelMapperPrivate::sliceValueChanged() |
|
389 | void QPieModelMapperPrivate::sliceValueChanged() | |
390 | { |
|
390 | { | |
391 | if (m_seriesSignalsBlock) |
|
391 | if (m_seriesSignalsBlock) | |
392 | return; |
|
392 | return; | |
393 |
|
393 | |||
394 | blockModelSignals(); |
|
394 | blockModelSignals(); | |
395 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
395 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
396 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); |
|
396 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); | |
397 | blockModelSignals(false); |
|
397 | blockModelSignals(false); | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
400 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
401 | { |
|
401 | { | |
402 | if (m_model == 0 || m_series == 0) |
|
402 | if (m_model == 0 || m_series == 0) | |
403 | return; |
|
403 | return; | |
404 |
|
404 | |||
405 | if (m_modelSignalsBlock) |
|
405 | if (m_modelSignalsBlock) | |
406 | return; |
|
406 | return; | |
407 |
|
407 | |||
408 | blockSeriesSignals(); |
|
408 | blockSeriesSignals(); | |
409 | QModelIndex index; |
|
409 | QModelIndex index; | |
410 | QPieSlice *slice; |
|
410 | QPieSlice *slice; | |
411 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
411 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
412 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
412 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
413 | index = topLeft.sibling(row, column); |
|
413 | index = topLeft.sibling(row, column); | |
414 | slice = pieSlice(index); |
|
414 | slice = pieSlice(index); | |
415 | if (slice) { |
|
415 | if (slice) { | |
416 | if (isValueIndex(index)) |
|
416 | if (isValueIndex(index)) | |
417 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); |
|
417 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); | |
418 | if (isLabelIndex(index)) |
|
418 | if (isLabelIndex(index)) | |
419 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); |
|
419 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); | |
420 | } |
|
420 | } | |
421 | } |
|
421 | } | |
422 | } |
|
422 | } | |
423 | blockSeriesSignals(false); |
|
423 | blockSeriesSignals(false); | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 |
|
426 | |||
427 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
427 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
428 | { |
|
428 | { | |
429 | Q_UNUSED(parent); |
|
429 | Q_UNUSED(parent); | |
430 | if (m_modelSignalsBlock) |
|
430 | if (m_modelSignalsBlock) | |
431 | return; |
|
431 | return; | |
432 |
|
432 | |||
433 | blockSeriesSignals(); |
|
433 | blockSeriesSignals(); | |
434 | if (m_orientation == Qt::Vertical) |
|
434 | if (m_orientation == Qt::Vertical) | |
435 | insertData(start, end); |
|
435 | insertData(start, end); | |
436 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
436 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
437 | initializePieFromModel(); |
|
437 | initializePieFromModel(); | |
438 | blockSeriesSignals(false); |
|
438 | blockSeriesSignals(false); | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
441 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
442 | { |
|
442 | { | |
443 | Q_UNUSED(parent); |
|
443 | Q_UNUSED(parent); | |
444 | if (m_modelSignalsBlock) |
|
444 | if (m_modelSignalsBlock) | |
445 | return; |
|
445 | return; | |
446 |
|
446 | |||
447 | blockSeriesSignals(); |
|
447 | blockSeriesSignals(); | |
448 | if (m_orientation == Qt::Vertical) |
|
448 | if (m_orientation == Qt::Vertical) | |
449 | removeData(start, end); |
|
449 | removeData(start, end); | |
450 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
450 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
451 | initializePieFromModel(); |
|
451 | initializePieFromModel(); | |
452 | blockSeriesSignals(false); |
|
452 | blockSeriesSignals(false); | |
453 | } |
|
453 | } | |
454 |
|
454 | |||
455 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
455 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
456 | { |
|
456 | { | |
457 | Q_UNUSED(parent); |
|
457 | Q_UNUSED(parent); | |
458 | if (m_modelSignalsBlock) |
|
458 | if (m_modelSignalsBlock) | |
459 | return; |
|
459 | return; | |
460 |
|
460 | |||
461 | blockSeriesSignals(); |
|
461 | blockSeriesSignals(); | |
462 | if (m_orientation == Qt::Horizontal) |
|
462 | if (m_orientation == Qt::Horizontal) | |
463 | insertData(start, end); |
|
463 | insertData(start, end); | |
464 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
464 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
465 | initializePieFromModel(); |
|
465 | initializePieFromModel(); | |
466 | blockSeriesSignals(false); |
|
466 | blockSeriesSignals(false); | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
469 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
470 | { |
|
470 | { | |
471 | Q_UNUSED(parent); |
|
471 | Q_UNUSED(parent); | |
472 | if (m_modelSignalsBlock) |
|
472 | if (m_modelSignalsBlock) | |
473 | return; |
|
473 | return; | |
474 |
|
474 | |||
475 | blockSeriesSignals(); |
|
475 | blockSeriesSignals(); | |
476 | if (m_orientation == Qt::Horizontal) |
|
476 | if (m_orientation == Qt::Horizontal) | |
477 | removeData(start, end); |
|
477 | removeData(start, end); | |
478 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
478 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
479 | initializePieFromModel(); |
|
479 | initializePieFromModel(); | |
480 | blockSeriesSignals(false); |
|
480 | blockSeriesSignals(false); | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | void QPieModelMapperPrivate::insertData(int start, int end) |
|
483 | void QPieModelMapperPrivate::insertData(int start, int end) | |
484 | { |
|
484 | { | |
485 | if (m_model == 0 || m_series == 0) |
|
485 | if (m_model == 0 || m_series == 0) | |
486 | return; |
|
486 | return; | |
487 |
|
487 | |||
488 | if (m_count != -1 && start >= m_first + m_count) { |
|
488 | if (m_count != -1 && start >= m_first + m_count) { | |
489 | return; |
|
489 | return; | |
490 | } else { |
|
490 | } else { | |
491 | int addedCount = end - start + 1; |
|
491 | int addedCount = end - start + 1; | |
492 | if (m_count != -1 && addedCount > m_count) |
|
492 | if (m_count != -1 && addedCount > m_count) | |
493 | addedCount = m_count; |
|
493 | addedCount = m_count; | |
494 | int first = qMax(start, m_first); |
|
494 | int first = qMax(start, m_first); | |
495 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
495 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
496 | for (int i = first; i <= last; i++) { |
|
496 | for (int i = first; i <= last; i++) { | |
497 | QModelIndex valueIndex = valueModelIndex(i - m_first); |
|
497 | QModelIndex valueIndex = valueModelIndex(i - m_first); | |
498 | QModelIndex labelIndex = labelModelIndex(i - m_first); |
|
498 | QModelIndex labelIndex = labelModelIndex(i - m_first); | |
499 | if (valueIndex.isValid() && labelIndex.isValid()) { |
|
499 | if (valueIndex.isValid() && labelIndex.isValid()) { | |
500 | QPieSlice *slice = new QPieSlice; |
|
500 | QPieSlice *slice = new QPieSlice; | |
501 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
501 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
502 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
502 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
503 | slice->setLabelVisible(); |
|
503 | slice->setLabelVisible(); | |
504 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
504 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
505 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
505 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
506 | m_series->insert(i - m_first, slice); |
|
506 | m_series->insert(i - m_first, slice); | |
507 | m_slices.insert(i - m_first, slice); |
|
507 | m_slices.insert(i - m_first, slice); | |
508 | } |
|
508 | } | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | // remove excess of slices (abouve m_count) |
|
511 | // remove excess of slices (abouve m_count) | |
512 | if (m_count != -1 && m_series->slices().size() > m_count) |
|
512 | if (m_count != -1 && m_series->slices().size() > m_count) | |
513 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { |
|
513 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { | |
514 | m_series->remove(m_series->slices().at(i)); |
|
514 | m_series->remove(m_series->slices().at(i)); | |
515 | m_slices.removeAt(i); |
|
515 | m_slices.removeAt(i); | |
516 | } |
|
516 | } | |
517 | } |
|
517 | } | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | void QPieModelMapperPrivate::removeData(int start, int end) |
|
520 | void QPieModelMapperPrivate::removeData(int start, int end) | |
521 | { |
|
521 | { | |
522 | if (m_model == 0 || m_series == 0) |
|
522 | if (m_model == 0 || m_series == 0) | |
523 | return; |
|
523 | return; | |
524 |
|
524 | |||
525 | int removedCount = end - start + 1; |
|
525 | int removedCount = end - start + 1; | |
526 | if (m_count != -1 && start >= m_first + m_count) { |
|
526 | if (m_count != -1 && start >= m_first + m_count) { | |
527 | return; |
|
527 | return; | |
528 | } else { |
|
528 | } else { | |
529 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed |
|
529 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed | |
530 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
530 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
531 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. |
|
531 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. | |
532 | for (int i = last; i >= first; i--) { |
|
532 | for (int i = last; i >= first; i--) { | |
533 | m_series->remove(m_series->slices().at(i - m_first)); |
|
533 | m_series->remove(m_series->slices().at(i - m_first)); | |
534 | m_slices.removeAt(i - m_first); |
|
534 | m_slices.removeAt(i - m_first); | |
535 | } |
|
535 | } | |
536 |
|
536 | |||
537 | if (m_count != -1) { |
|
537 | if (m_count != -1) { | |
538 | int itemsAvailable; // check how many are available to be added |
|
538 | int itemsAvailable; // check how many are available to be added | |
539 | if (m_orientation == Qt::Vertical) |
|
539 | if (m_orientation == Qt::Vertical) | |
540 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); |
|
540 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); | |
541 | else |
|
541 | else | |
542 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); |
|
542 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); | |
543 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. |
|
543 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. | |
544 | int currentSize = m_series->slices().size(); |
|
544 | int currentSize = m_series->slices().size(); | |
545 | if (toBeAdded > 0) |
|
545 | if (toBeAdded > 0) | |
546 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { |
|
546 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { | |
547 | QModelIndex valueIndex = valueModelIndex(i - m_first); |
|
547 | QModelIndex valueIndex = valueModelIndex(i - m_first); | |
548 | QModelIndex labelIndex = labelModelIndex(i - m_first); |
|
548 | QModelIndex labelIndex = labelModelIndex(i - m_first); | |
549 | if (valueIndex.isValid() && labelIndex.isValid()) { |
|
549 | if (valueIndex.isValid() && labelIndex.isValid()) { | |
550 | QPieSlice *slice = new QPieSlice; |
|
550 | QPieSlice *slice = new QPieSlice; | |
551 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
551 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
552 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
552 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
553 | slice->setLabelVisible(); |
|
553 | slice->setLabelVisible(); | |
554 | m_series->insert(i, slice); |
|
554 | m_series->insert(i, slice); | |
555 | m_slices.insert(i, slice); |
|
555 | m_slices.insert(i, slice); | |
556 | } |
|
556 | } | |
557 | } |
|
557 | } | |
558 | } |
|
558 | } | |
559 | } |
|
559 | } | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | void QPieModelMapperPrivate::initializePieFromModel() |
|
562 | void QPieModelMapperPrivate::initializePieFromModel() | |
563 | { |
|
563 | { | |
564 | if (m_model == 0 || m_series == 0) |
|
564 | if (m_model == 0 || m_series == 0) | |
565 | return; |
|
565 | return; | |
566 |
|
566 | |||
567 | blockSeriesSignals(); |
|
567 | blockSeriesSignals(); | |
568 | // clear current content |
|
568 | // clear current content | |
569 | m_series->clear(); |
|
569 | m_series->clear(); | |
570 | m_slices.clear(); |
|
570 | m_slices.clear(); | |
571 |
|
571 | |||
572 | // create the initial slices set |
|
572 | // create the initial slices set | |
573 | int slicePos = 0; |
|
573 | int slicePos = 0; | |
574 | QModelIndex valueIndex = valueModelIndex(slicePos); |
|
574 | QModelIndex valueIndex = valueModelIndex(slicePos); | |
575 | QModelIndex labelIndex = labelModelIndex(slicePos); |
|
575 | QModelIndex labelIndex = labelModelIndex(slicePos); | |
576 | while (valueIndex.isValid() && labelIndex.isValid()) { |
|
576 | while (valueIndex.isValid() && labelIndex.isValid()) { | |
577 | QPieSlice *slice = new QPieSlice; |
|
577 | QPieSlice *slice = new QPieSlice; | |
578 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
578 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
579 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
579 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
580 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
580 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
581 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
581 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
582 | m_series->append(slice); |
|
582 | m_series->append(slice); | |
583 | m_slices.append(slice); |
|
583 | m_slices.append(slice); | |
584 | // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
|||
585 | slicePos++; |
|
584 | slicePos++; | |
586 | valueIndex = valueModelIndex(slicePos); |
|
585 | valueIndex = valueModelIndex(slicePos); | |
587 | labelIndex = labelModelIndex(slicePos); |
|
586 | labelIndex = labelModelIndex(slicePos); | |
588 | } |
|
587 | } | |
589 | m_series->setLabelsVisible(true); |
|
588 | m_series->setLabelsVisible(true); | |
590 | blockSeriesSignals(false); |
|
589 | blockSeriesSignals(false); | |
591 | } |
|
590 | } | |
592 |
|
591 | |||
593 | #include "moc_qpiemodelmapper_p.cpp" |
|
592 | #include "moc_qpiemodelmapper_p.cpp" | |
594 | #include "moc_qpiemodelmapper.cpp" |
|
593 | #include "moc_qpiemodelmapper.cpp" | |
595 |
|
594 | |||
596 | QTCOMMERCIALCHART_END_NAMESPACE |
|
595 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,47 +1,46 | |||||
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 QHXYMODELMAPPER_H |
|
21 | #ifndef QHXYMODELMAPPER_H | |
22 | #define QHXYMODELMAPPER_H |
|
22 | #define QHXYMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include <QXYModelMapper> |
|
24 | #include <QXYModelMapper> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QHXYModelMapper : public QXYModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QHXYModelMapper : public QXYModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int xRow READ xRow WRITE setXRow) |
|
31 | Q_PROPERTY(int xRow READ xRow WRITE setXRow) | |
32 | Q_PROPERTY(int yRow READ yRow WRITE setYRow) |
|
32 | Q_PROPERTY(int yRow READ yRow WRITE setYRow) | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | explicit QHXYModelMapper(QObject *parent = 0); |
|
35 | explicit QHXYModelMapper(QObject *parent = 0); | |
36 |
|
36 | |||
37 | int xRow() const; |
|
37 | int xRow() const; | |
38 | void setXRow(int xRow); |
|
38 | void setXRow(int xRow); | |
39 |
|
39 | |||
40 | int yRow() const; |
|
40 | int yRow() const; | |
41 | void setYRow(int yRow); |
|
41 | void setYRow(int yRow); | |
42 |
|
||||
43 | }; |
|
42 | }; | |
44 |
|
43 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | QTCOMMERCIALCHART_END_NAMESPACE | |
46 |
|
45 | |||
47 | #endif // QHXYMODELMAPPER_H |
|
46 | #endif // QHXYMODELMAPPER_H |
@@ -1,78 +1,80 | |||||
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 "qvxymodelmapper.h" |
|
21 | #include "qvxymodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVXYModelMapper |
|
26 | \class QVXYModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Nothing here yet |
|
30 | Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. | |
|
31 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. | |||
|
32 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |||
31 | */ |
|
33 | */ | |
32 |
|
34 | |||
33 | /*! |
|
35 | /*! | |
34 | \property QVXYModelMapper::xColumn |
|
36 | \property QVXYModelMapper::xColumn | |
35 | \brief Defines which column of the model is kept in sync with the x values of QXYSeries |
|
37 | \brief Defines which column of the model is kept in sync with the x values of QXYSeries | |
36 |
|
38 | |||
37 | Default value is: -1 (invalid mapping) |
|
39 | Default value is: -1 (invalid mapping) | |
38 | */ |
|
40 | */ | |
39 |
|
41 | |||
40 | /*! |
|
42 | /*! | |
41 | \property QVXYModelMapper::yColumn |
|
43 | \property QVXYModelMapper::yColumn | |
42 | \brief Defines which column of the model is kept in sync with the y values of QXYSeries |
|
44 | \brief Defines which column of the model is kept in sync with the y values of QXYSeries | |
43 |
|
45 | |||
44 | Default value is: -1 (invalid mapping) |
|
46 | Default value is: -1 (invalid mapping) | |
45 | */ |
|
47 | */ | |
46 |
|
48 | |||
47 | /*! |
|
49 | /*! | |
48 | Constructs a mapper object which is a child of \a parent. |
|
50 | Constructs a mapper object which is a child of \a parent. | |
49 | */ |
|
51 | */ | |
50 | QVXYModelMapper::QVXYModelMapper(QObject *parent) : |
|
52 | QVXYModelMapper::QVXYModelMapper(QObject *parent) : | |
51 | QXYModelMapper(parent) |
|
53 | QXYModelMapper(parent) | |
52 | { |
|
54 | { | |
53 | QXYModelMapper::setOrientation(Qt::Vertical); |
|
55 | QXYModelMapper::setOrientation(Qt::Vertical); | |
54 | } |
|
56 | } | |
55 |
|
57 | |||
56 | int QVXYModelMapper::xColumn() const |
|
58 | int QVXYModelMapper::xColumn() const | |
57 | { |
|
59 | { | |
58 | return QXYModelMapper::xSection(); |
|
60 | return QXYModelMapper::xSection(); | |
59 | } |
|
61 | } | |
60 |
|
62 | |||
61 | void QVXYModelMapper::setXColumn(int xColumn) |
|
63 | void QVXYModelMapper::setXColumn(int xColumn) | |
62 | { |
|
64 | { | |
63 | return QXYModelMapper::setXSection(xColumn); |
|
65 | return QXYModelMapper::setXSection(xColumn); | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | int QVXYModelMapper::yColumn() const |
|
68 | int QVXYModelMapper::yColumn() const | |
67 | { |
|
69 | { | |
68 | return QXYModelMapper::ySection(); |
|
70 | return QXYModelMapper::ySection(); | |
69 | } |
|
71 | } | |
70 |
|
72 | |||
71 | void QVXYModelMapper::setYColumn(int yColumn) |
|
73 | void QVXYModelMapper::setYColumn(int yColumn) | |
72 | { |
|
74 | { | |
73 | return QXYModelMapper::setYSection(yColumn); |
|
75 | return QXYModelMapper::setYSection(yColumn); | |
74 | } |
|
76 | } | |
75 |
|
77 | |||
76 | #include "moc_qvxymodelmapper.cpp" |
|
78 | #include "moc_qvxymodelmapper.cpp" | |
77 |
|
79 | |||
78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
80 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,47 +1,46 | |||||
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 QVXYMODELMAPPER_H |
|
21 | #ifndef QVXYMODELMAPPER_H | |
22 | #define QVXYMODELMAPPER_H |
|
22 | #define QVXYMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include <QXYModelMapper> |
|
24 | #include <QXYModelMapper> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QVXYModelMapper : public QXYModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QVXYModelMapper : public QXYModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn) |
|
31 | Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn) | |
32 | Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn) |
|
32 | Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn) | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | explicit QVXYModelMapper(QObject *parent = 0); |
|
35 | explicit QVXYModelMapper(QObject *parent = 0); | |
36 |
|
36 | |||
37 | int xColumn() const; |
|
37 | int xColumn() const; | |
38 | void setXColumn(int xColumn); |
|
38 | void setXColumn(int xColumn); | |
39 |
|
39 | |||
40 | int yColumn() const; |
|
40 | int yColumn() const; | |
41 | void setYColumn(int yColumn); |
|
41 | void setYColumn(int yColumn); | |
42 |
|
||||
43 | }; |
|
42 | }; | |
44 |
|
43 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | QTCOMMERCIALCHART_END_NAMESPACE | |
46 |
|
45 | |||
47 | #endif // QVXYMODELMAPPER_H |
|
46 | #endif // QVXYMODELMAPPER_H |
General Comments 0
You need to be logged in to leave comments.
Login now