##// END OF EJS Templates
Small code comments fixes
Marek Rosa -
r1880:a21a3c098ff7
parent child
Show More
@@ -1,66 +1,65
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 QCATEGORIESAXIS_H
21 #ifndef QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qvalueaxis.h"
25 #include "qvalueaxis.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QCategoryAxisPrivate;
29 class QCategoryAxisPrivate;
30
30
31 class QTCOMMERCIALCHART_EXPORT QCategoryAxis : public QValueAxis
31 class QTCOMMERCIALCHART_EXPORT QCategoryAxis : public QValueAxis
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(qreal startValue READ startValue WRITE setStartValue)
34 Q_PROPERTY(qreal startValue READ startValue WRITE setStartValue)
35
35
36 public:
36 public:
37 explicit QCategoryAxis(QObject *parent = 0);
37 explicit QCategoryAxis(QObject *parent = 0);
38 ~QCategoryAxis();
38 ~QCategoryAxis();
39
39
40 protected:
40 protected:
41 QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent = 0);
41 QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent = 0);
42
42
43 public:
43 public:
44 AxisType type() const;
44 AxisType type() const;
45
45
46 void append(const QString& label, qreal categoryEndValue);
46 void append(const QString& label, qreal categoryEndValue);
47 void remove(const QString& label);
47 void remove(const QString& label);
48 void replaceLabel(const QString& oldLabel, const QString& newLabel);
48 void replaceLabel(const QString& oldLabel, const QString& newLabel);
49
49
50 qreal startValue(const QString& categoryLabel = QString()) const;
50 qreal startValue(const QString& categoryLabel = QString()) const;
51 void setStartValue(qreal min);
51 void setStartValue(qreal min);
52
52
53 // qreal startValue(const QString& categoryLabel) const;
54 qreal endValue(const QString& categoryLabel) const;
53 qreal endValue(const QString& categoryLabel) const;
55
54
56 QStringList categoriesLabels();
55 QStringList categoriesLabels();
57 int count() const;
56 int count() const;
58
57
59 private:
58 private:
60 Q_DECLARE_PRIVATE(QCategoryAxis)
59 Q_DECLARE_PRIVATE(QCategoryAxis)
61 Q_DISABLE_COPY(QCategoryAxis)
60 Q_DISABLE_COPY(QCategoryAxis)
62 };
61 };
63
62
64 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
65
64
66 #endif // QCATEGORIESAXIS_H
65 #endif // QCATEGORIESAXIS_H
@@ -1,506 +1,506
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 "qxymodelmapper.h"
21 #include "qxymodelmapper.h"
22 #include "qxymodelmapper_p.h"
22 #include "qxymodelmapper_p.h"
23 #include "qxyseries.h"
23 #include "qxyseries.h"
24 #include <QAbstractItemModel>
24 #include <QAbstractItemModel>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 Constructs a mapper object which is a child of \a parent.
29 Constructs a mapper object which is a child of \a parent.
30 */
30 */
31 QXYModelMapper::QXYModelMapper(QObject *parent):
31 QXYModelMapper::QXYModelMapper(QObject *parent):
32 QObject(parent),
32 QObject(parent),
33 d_ptr(new QXYModelMapperPrivate(this))
33 d_ptr(new QXYModelMapperPrivate(this))
34 {
34 {
35 }
35 }
36
36
37 /*!
37 /*!
38 \internal
38 \internal
39 */
39 */
40 QAbstractItemModel* QXYModelMapper::model() const
40 QAbstractItemModel* QXYModelMapper::model() const
41 {
41 {
42 Q_D(const QXYModelMapper);
42 Q_D(const QXYModelMapper);
43 return d->m_model;
43 return d->m_model;
44 }
44 }
45
45
46 /*!
46 /*!
47 \internal
47 \internal
48 */
48 */
49 void QXYModelMapper::setModel(QAbstractItemModel *model)
49 void QXYModelMapper::setModel(QAbstractItemModel *model)
50 {
50 {
51 if (model == 0)
51 if (model == 0)
52 return;
52 return;
53
53
54 Q_D(QXYModelMapper);
54 Q_D(QXYModelMapper);
55 if (d->m_model) {
55 if (d->m_model) {
56 disconnect(d->m_model, 0, d, 0);
56 disconnect(d->m_model, 0, d, 0);
57 }
57 }
58
58
59 d->m_model = model;
59 d->m_model = model;
60 d->initializeXYFromModel();
60 d->initializeXYFromModel();
61 // connect signals from the model
61 // connect signals from the model
62 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
62 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
63 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
63 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
64 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
64 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
65 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
65 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
66 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
66 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
67 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
67 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
68 }
68 }
69
69
70 /*!
70 /*!
71 \internal
71 \internal
72 */
72 */
73 QXYSeries* QXYModelMapper::series() const
73 QXYSeries* QXYModelMapper::series() const
74 {
74 {
75 Q_D(const QXYModelMapper);
75 Q_D(const QXYModelMapper);
76 return d->m_series;
76 return d->m_series;
77 }
77 }
78
78
79 /*!
79 /*!
80 \internal
80 \internal
81 */
81 */
82 void QXYModelMapper::setSeries(QXYSeries *series)
82 void QXYModelMapper::setSeries(QXYSeries *series)
83 {
83 {
84 Q_D(QXYModelMapper);
84 Q_D(QXYModelMapper);
85 if (d->m_series) {
85 if (d->m_series) {
86 disconnect(d->m_series, 0, d, 0);
86 disconnect(d->m_series, 0, d, 0);
87 }
87 }
88
88
89 if (series == 0)
89 if (series == 0)
90 return;
90 return;
91
91
92 d->m_series = series;
92 d->m_series = series;
93 d->initializeXYFromModel();
93 d->initializeXYFromModel();
94 // connect the signals from the series
94 // connect the signals from the series
95 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
95 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
96 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
96 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
97 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
97 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
98 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
98 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
99 }
99 }
100
100
101 /*!
101 /*!
102 \internal
102 \internal
103 */
103 */
104 int QXYModelMapper::first() const
104 int QXYModelMapper::first() const
105 {
105 {
106 Q_D(const QXYModelMapper);
106 Q_D(const QXYModelMapper);
107 return d->m_first;
107 return d->m_first;
108 }
108 }
109
109
110 /*!
110 /*!
111 \internal
111 \internal
112 */
112 */
113 void QXYModelMapper::setFirst(int first)
113 void QXYModelMapper::setFirst(int first)
114 {
114 {
115 Q_D(QXYModelMapper);
115 Q_D(QXYModelMapper);
116 d->m_first = qMax(first, 0);
116 d->m_first = qMax(first, 0);
117 d->initializeXYFromModel();
117 d->initializeXYFromModel();
118 }
118 }
119
119
120 /*!
120 /*!
121 \internal
121 \internal
122 */
122 */
123 int QXYModelMapper::count() const
123 int QXYModelMapper::count() const
124 {
124 {
125 Q_D(const QXYModelMapper);
125 Q_D(const QXYModelMapper);
126 return d->m_count;
126 return d->m_count;
127 }
127 }
128
128
129 /*!
129 /*!
130 \internal
130 \internal
131 */
131 */
132 void QXYModelMapper::setCount(int count)
132 void QXYModelMapper::setCount(int count)
133 {
133 {
134 Q_D(QXYModelMapper);
134 Q_D(QXYModelMapper);
135 d->m_count = qMax(count, -1);
135 d->m_count = qMax(count, -1);
136 d->initializeXYFromModel();
136 d->initializeXYFromModel();
137 }
137 }
138
138
139 /*!
139 /*!
140 Returns the orientation that is used when QXYModelMapper accesses the model.
140 Returns the orientation that is used when QXYModelMapper accesses the model.
141 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
141 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
142 or from columns (Qt::Vertical)
142 or from columns (Qt::Vertical)
143 */
143 */
144 Qt::Orientation QXYModelMapper::orientation() const
144 Qt::Orientation QXYModelMapper::orientation() const
145 {
145 {
146 Q_D(const QXYModelMapper);
146 Q_D(const QXYModelMapper);
147 return d->m_orientation;
147 return d->m_orientation;
148 }
148 }
149
149
150 /*!
150 /*!
151 Returns the \a orientation that is used when QXYModelMapper accesses the model.
151 Returns the \a orientation that is used when QXYModelMapper accesses the model.
152 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
152 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
153 or from columns (Qt::Vertical)
153 or from columns (Qt::Vertical)
154 */
154 */
155 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
155 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
156 {
156 {
157 Q_D(QXYModelMapper);
157 Q_D(QXYModelMapper);
158 d->m_orientation = orientation;
158 d->m_orientation = orientation;
159 d->initializeXYFromModel();
159 d->initializeXYFromModel();
160 }
160 }
161
161
162 /*!
162 /*!
163 Returns which section of the model is kept in sync with the x values of the QXYSeries
163 Returns which section of the model is kept in sync with the x values of the QXYSeries
164 */
164 */
165 int QXYModelMapper::xSection() const
165 int QXYModelMapper::xSection() const
166 {
166 {
167 Q_D(const QXYModelMapper);
167 Q_D(const QXYModelMapper);
168 return d->m_xSection;
168 return d->m_xSection;
169 }
169 }
170
170
171 /*!
171 /*!
172 Sets the model section that is kept in sync with the x values of the QXYSeries.
172 Sets the model section that is kept in sync with the x values of the QXYSeries.
173 Parameter \a xSection specifies the section of the model.
173 Parameter \a xSection specifies the section of the model.
174 */
174 */
175 void QXYModelMapper::setXSection(int xSection)
175 void QXYModelMapper::setXSection(int xSection)
176 {
176 {
177 Q_D(QXYModelMapper);
177 Q_D(QXYModelMapper);
178 d->m_xSection = qMax(-1, xSection);
178 d->m_xSection = qMax(-1, xSection);
179 d->initializeXYFromModel();
179 d->initializeXYFromModel();
180 }
180 }
181
181
182 /*!
182 /*!
183 Returns which section of the model is kept in sync with the y values of the QXYSeries
183 Returns which section of the model is kept in sync with the y values of the QXYSeries
184 */
184 */
185 int QXYModelMapper::ySection() const
185 int QXYModelMapper::ySection() const
186 {
186 {
187 Q_D(const QXYModelMapper);
187 Q_D(const QXYModelMapper);
188 return d->m_ySection;
188 return d->m_ySection;
189 }
189 }
190
190
191 /*!
191 /*!
192 Sets the model section that is kept in sync with the y values of the QXYSeries.
192 Sets the model section that is kept in sync with the y values of the QXYSeries.
193 Parameter \a ySection specifies the section of the model.
193 Parameter \a ySection specifies the section of the model.
194 */
194 */
195 void QXYModelMapper::setYSection(int ySection)
195 void QXYModelMapper::setYSection(int ySection)
196 {
196 {
197 Q_D(QXYModelMapper);
197 Q_D(QXYModelMapper);
198 d->m_ySection = qMax(-1, ySection);
198 d->m_ySection = qMax(-1, ySection);
199 d->initializeXYFromModel();
199 d->initializeXYFromModel();
200 }
200 }
201
201
202 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
202 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
203
203
204 QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) :
204 QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) :
205 QObject(q),
205 QObject(q),
206 m_series(0),
206 m_series(0),
207 m_model(0),
207 m_model(0),
208 m_first(0),
208 m_first(0),
209 m_count(-1),
209 m_count(-1),
210 m_orientation(Qt::Vertical),
210 m_orientation(Qt::Vertical),
211 m_xSection(-1),
211 m_xSection(-1),
212 m_ySection(-1),
212 m_ySection(-1),
213 m_seriesSignalsBlock(false),
213 m_seriesSignalsBlock(false),
214 m_modelSignalsBlock(false),
214 m_modelSignalsBlock(false),
215 q_ptr(q)
215 q_ptr(q)
216 {
216 {
217 }
217 }
218
218
219 void QXYModelMapperPrivate::blockModelSignals(bool block)
219 void QXYModelMapperPrivate::blockModelSignals(bool block)
220 {
220 {
221 m_modelSignalsBlock = block;
221 m_modelSignalsBlock = block;
222 }
222 }
223
223
224 void QXYModelMapperPrivate::blockSeriesSignals(bool block)
224 void QXYModelMapperPrivate::blockSeriesSignals(bool block)
225 {
225 {
226 m_seriesSignalsBlock = block;
226 m_seriesSignalsBlock = block;
227 }
227 }
228
228
229 QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos)
229 QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos)
230 {
230 {
231 if (m_count != -1 && xPos >= m_count)
231 if (m_count != -1 && xPos >= m_count)
232 return QModelIndex(); // invalid
232 return QModelIndex(); // invalid
233
233
234 if (m_orientation == Qt::Vertical)
234 if (m_orientation == Qt::Vertical)
235 return m_model->index(xPos + m_first, m_xSection);
235 return m_model->index(xPos + m_first, m_xSection);
236 else
236 else
237 return m_model->index(m_xSection, xPos + m_first);
237 return m_model->index(m_xSection, xPos + m_first);
238 }
238 }
239
239
240 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
240 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
241 {
241 {
242 if (m_count != -1 && yPos >= m_count)
242 if (m_count != -1 && yPos >= m_count)
243 return QModelIndex(); // invalid
243 return QModelIndex(); // invalid
244
244
245 if (m_orientation == Qt::Vertical)
245 if (m_orientation == Qt::Vertical)
246 return m_model->index(yPos + m_first, m_ySection);
246 return m_model->index(yPos + m_first, m_ySection);
247 else
247 else
248 return m_model->index(m_ySection, yPos + m_first);
248 return m_model->index(m_ySection, yPos + m_first);
249 }
249 }
250
250
251 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
251 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
252 {
252 {
253 if (m_seriesSignalsBlock)
253 if (m_seriesSignalsBlock)
254 return;
254 return;
255
255
256 if (m_count != -1)
256 if (m_count != -1)
257 m_count += 1;
257 m_count += 1;
258
258
259 blockModelSignals();
259 blockModelSignals();
260 if (m_orientation == Qt::Vertical)
260 if (m_orientation == Qt::Vertical)
261 m_model->insertRows(pointPos + m_first, 1);
261 m_model->insertRows(pointPos + m_first, 1);
262 else
262 else
263 m_model->insertColumns(pointPos + m_first, 1);
263 m_model->insertColumns(pointPos + m_first, 1);
264
264
265 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
265 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
266 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
266 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
267 blockModelSignals(false);
267 blockModelSignals(false);
268 }
268 }
269
269
270 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
270 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
271 {
271 {
272 if (m_seriesSignalsBlock)
272 if (m_seriesSignalsBlock)
273 return;
273 return;
274
274
275 if (m_count != -1)
275 if (m_count != -1)
276 m_count -= 1;
276 m_count -= 1;
277
277
278 blockModelSignals();
278 blockModelSignals();
279 if (m_orientation == Qt::Vertical)
279 if (m_orientation == Qt::Vertical)
280 m_model->removeRow(pointPos + m_first);
280 m_model->removeRow(pointPos + m_first);
281 else
281 else
282 m_model->removeColumn(pointPos + m_first);
282 m_model->removeColumn(pointPos + m_first);
283 blockModelSignals(false);
283 blockModelSignals(false);
284 }
284 }
285
285
286 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
286 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
287 {
287 {
288 if (m_seriesSignalsBlock)
288 if (m_seriesSignalsBlock)
289 return;
289 return;
290
290
291 blockModelSignals();
291 blockModelSignals();
292 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
292 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
293 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
293 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
294 blockModelSignals(false);
294 blockModelSignals(false);
295 }
295 }
296
296
297 void QXYModelMapperPrivate::handleSeriesDestroyed()
297 void QXYModelMapperPrivate::handleSeriesDestroyed()
298 {
298 {
299 m_series = 0;
299 m_series = 0;
300 }
300 }
301
301
302 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
302 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
303 {
303 {
304 if (m_model == 0 || m_series == 0)
304 if (m_model == 0 || m_series == 0)
305 return;
305 return;
306
306
307 if (m_modelSignalsBlock)
307 if (m_modelSignalsBlock)
308 return;
308 return;
309
309
310 blockSeriesSignals();
310 blockSeriesSignals();
311 QModelIndex index;
311 QModelIndex index;
312 QPointF oldPoint;
312 QPointF oldPoint;
313 QPointF newPoint;
313 QPointF newPoint;
314 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
314 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
315 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
315 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
316 index = topLeft.sibling(row, column);
316 index = topLeft.sibling(row, column);
317 if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) {
317 if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) {
318 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
318 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
319 QModelIndex xIndex = xModelIndex(index.row() - m_first);
319 QModelIndex xIndex = xModelIndex(index.row() - m_first);
320 QModelIndex yIndex = yModelIndex(index.row() - m_first);
320 QModelIndex yIndex = yModelIndex(index.row() - m_first);
321 if (xIndex.isValid() && yIndex.isValid()) {
321 if (xIndex.isValid() && yIndex.isValid()) {
322 oldPoint = m_series->points().at(index.row() - m_first);
322 oldPoint = m_series->points().at(index.row() - m_first);
323 newPoint.setX(m_model->data(xIndex).toReal());
323 newPoint.setX(m_model->data(xIndex).toReal());
324 newPoint.setY(m_model->data(yIndex).toReal());
324 newPoint.setY(m_model->data(yIndex).toReal());
325 }
325 }
326 }
326 }
327 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
327 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
328 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
328 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
329 QModelIndex xIndex = xModelIndex(index.column() - m_first);
329 QModelIndex xIndex = xModelIndex(index.column() - m_first);
330 QModelIndex yIndex = yModelIndex(index.column() - m_first);
330 QModelIndex yIndex = yModelIndex(index.column() - m_first);
331 if (xIndex.isValid() && yIndex.isValid()) {
331 if (xIndex.isValid() && yIndex.isValid()) {
332 oldPoint = m_series->points().at(index.column() - m_first);
332 oldPoint = m_series->points().at(index.column() - m_first);
333 newPoint.setX(m_model->data(xIndex).toReal());
333 newPoint.setX(m_model->data(xIndex).toReal());
334 newPoint.setY(m_model->data(yIndex).toReal());
334 newPoint.setY(m_model->data(yIndex).toReal());
335 }
335 }
336 }
336 }
337 } else {
337 } else {
338 continue;
338 continue;
339 }
339 }
340 m_series->replace(oldPoint, newPoint);
340 m_series->replace(oldPoint, newPoint);
341 }
341 }
342 }
342 }
343 blockSeriesSignals(false);
343 blockSeriesSignals(false);
344 }
344 }
345
345
346 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
346 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
347 {
347 {
348 Q_UNUSED(parent);
348 Q_UNUSED(parent);
349 if (m_modelSignalsBlock)
349 if (m_modelSignalsBlock)
350 return;
350 return;
351
351
352 blockSeriesSignals();
352 blockSeriesSignals();
353 if (m_orientation == Qt::Vertical)
353 if (m_orientation == Qt::Vertical)
354 insertData(start, end);
354 insertData(start, end);
355 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
355 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
356 initializeXYFromModel();
356 initializeXYFromModel();
357 blockSeriesSignals(false);
357 blockSeriesSignals(false);
358 }
358 }
359
359
360 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
360 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
361 {
361 {
362 Q_UNUSED(parent);
362 Q_UNUSED(parent);
363 if (m_modelSignalsBlock)
363 if (m_modelSignalsBlock)
364 return;
364 return;
365
365
366 blockSeriesSignals();
366 blockSeriesSignals();
367 if (m_orientation == Qt::Vertical)
367 if (m_orientation == Qt::Vertical)
368 removeData(start, end);
368 removeData(start, end);
369 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
369 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
370 initializeXYFromModel();
370 initializeXYFromModel();
371 blockSeriesSignals(false);
371 blockSeriesSignals(false);
372 }
372 }
373
373
374 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
374 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
375 {
375 {
376 Q_UNUSED(parent);
376 Q_UNUSED(parent);
377 if (m_modelSignalsBlock)
377 if (m_modelSignalsBlock)
378 return;
378 return;
379
379
380 blockSeriesSignals();
380 blockSeriesSignals();
381 if (m_orientation == Qt::Horizontal)
381 if (m_orientation == Qt::Horizontal)
382 insertData(start, end);
382 insertData(start, end);
383 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
383 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
384 initializeXYFromModel();
384 initializeXYFromModel();
385 blockSeriesSignals(false);
385 blockSeriesSignals(false);
386 }
386 }
387
387
388 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
388 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
389 {
389 {
390 Q_UNUSED(parent);
390 Q_UNUSED(parent);
391 if (m_modelSignalsBlock)
391 if (m_modelSignalsBlock)
392 return;
392 return;
393
393
394 blockSeriesSignals();
394 blockSeriesSignals();
395 if (m_orientation == Qt::Horizontal)
395 if (m_orientation == Qt::Horizontal)
396 removeData(start, end);
396 removeData(start, end);
397 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
397 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
398 initializeXYFromModel();
398 initializeXYFromModel();
399 blockSeriesSignals(false);
399 blockSeriesSignals(false);
400 }
400 }
401
401
402 void QXYModelMapperPrivate::handleModelDestroyed()
402 void QXYModelMapperPrivate::handleModelDestroyed()
403 {
403 {
404 m_model = 0;
404 m_model = 0;
405 }
405 }
406
406
407 void QXYModelMapperPrivate::insertData(int start, int end)
407 void QXYModelMapperPrivate::insertData(int start, int end)
408 {
408 {
409 if (m_model == 0 || m_series == 0)
409 if (m_model == 0 || m_series == 0)
410 return;
410 return;
411
411
412 if (m_count != -1 && start >= m_first + m_count) {
412 if (m_count != -1 && start >= m_first + m_count) {
413 return;
413 return;
414 } else {
414 } else {
415 int addedCount = end - start + 1;
415 int addedCount = end - start + 1;
416 if (m_count != -1 && addedCount > m_count)
416 if (m_count != -1 && addedCount > m_count)
417 addedCount = m_count;
417 addedCount = m_count;
418 int first = qMax(start, m_first);
418 int first = qMax(start, m_first);
419 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
419 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
420 for (int i = first; i <= last; i++) {
420 for (int i = first; i <= last; i++) {
421 QPointF point;
421 QPointF point;
422 QModelIndex xIndex = xModelIndex(i - m_first);
422 QModelIndex xIndex = xModelIndex(i - m_first);
423 QModelIndex yIndex = yModelIndex(i - m_first);
423 QModelIndex yIndex = yModelIndex(i - m_first);
424 if (xIndex.isValid() && yIndex.isValid()) {
424 if (xIndex.isValid() && yIndex.isValid()) {
425 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
425 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
426 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
426 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
427 m_series->insert(i - m_first, point);
427 m_series->insert(i - m_first, point);
428 }
428 }
429 }
429 }
430
430
431 // remove excess of slices (abouve m_count)
431 // remove excess of points (above m_count)
432 if (m_count != -1 && m_series->points().size() > m_count)
432 if (m_count != -1 && m_series->points().size() > m_count)
433 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
433 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
434 m_series->remove(m_series->points().at(i));
434 m_series->remove(m_series->points().at(i));
435 }
435 }
436 }
436 }
437 }
437 }
438
438
439 void QXYModelMapperPrivate::removeData(int start, int end)
439 void QXYModelMapperPrivate::removeData(int start, int end)
440 {
440 {
441 if (m_model == 0 || m_series == 0)
441 if (m_model == 0 || m_series == 0)
442 return;
442 return;
443
443
444 int removedCount = end - start + 1;
444 int removedCount = end - start + 1;
445 if (m_count != -1 && start >= m_first + m_count) {
445 if (m_count != -1 && start >= m_first + m_count) {
446 return;
446 return;
447 } else {
447 } else {
448 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
448 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
449 int first = qMax(start, m_first); // get the index of the first item that will be removed.
449 int first = qMax(start, m_first); // get the index of the first item that will be removed.
450 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
450 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
451 for (int i = last; i >= first; i--) {
451 for (int i = last; i >= first; i--) {
452 m_series->remove(m_series->points().at(i - m_first));
452 m_series->remove(m_series->points().at(i - m_first));
453 }
453 }
454
454
455 if (m_count != -1) {
455 if (m_count != -1) {
456 int itemsAvailable; // check how many are available to be added
456 int itemsAvailable; // check how many are available to be added
457 if (m_orientation == Qt::Vertical)
457 if (m_orientation == Qt::Vertical)
458 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
458 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
459 else
459 else
460 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
460 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
461 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
461 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
462 int currentSize = m_series->count();
462 int currentSize = m_series->count();
463 if (toBeAdded > 0)
463 if (toBeAdded > 0)
464 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
464 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
465 QPointF point;
465 QPointF point;
466 QModelIndex xIndex = xModelIndex(i);
466 QModelIndex xIndex = xModelIndex(i);
467 QModelIndex yIndex = yModelIndex(i);
467 QModelIndex yIndex = yModelIndex(i);
468 if (xIndex.isValid() && yIndex.isValid()) {
468 if (xIndex.isValid() && yIndex.isValid()) {
469 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
469 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
470 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
470 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
471 m_series->insert(i, point);
471 m_series->insert(i, point);
472 }
472 }
473 }
473 }
474 }
474 }
475 }
475 }
476 }
476 }
477
477
478 void QXYModelMapperPrivate::initializeXYFromModel()
478 void QXYModelMapperPrivate::initializeXYFromModel()
479 {
479 {
480 if (m_model == 0 || m_series == 0)
480 if (m_model == 0 || m_series == 0)
481 return;
481 return;
482
482
483 blockSeriesSignals();
483 blockSeriesSignals();
484 // clear current content
484 // clear current content
485 m_series->clear();
485 m_series->clear();
486
486
487 // create the initial slices set
487 // create the initial points set
488 int pointPos = 0;
488 int pointPos = 0;
489 QModelIndex xIndex = xModelIndex(pointPos);
489 QModelIndex xIndex = xModelIndex(pointPos);
490 QModelIndex yIndex = yModelIndex(pointPos);
490 QModelIndex yIndex = yModelIndex(pointPos);
491 while (xIndex.isValid() && yIndex.isValid()) {
491 while (xIndex.isValid() && yIndex.isValid()) {
492 QPointF point;
492 QPointF point;
493 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
493 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
494 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
494 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
495 m_series->append(point);
495 m_series->append(point);
496 pointPos++;
496 pointPos++;
497 xIndex = xModelIndex(pointPos);
497 xIndex = xModelIndex(pointPos);
498 yIndex = yModelIndex(pointPos);
498 yIndex = yModelIndex(pointPos);
499 }
499 }
500 blockSeriesSignals(false);
500 blockSeriesSignals(false);
501 }
501 }
502
502
503 #include "moc_qxymodelmapper.cpp"
503 #include "moc_qxymodelmapper.cpp"
504 #include "moc_qxymodelmapper_p.cpp"
504 #include "moc_qxymodelmapper_p.cpp"
505
505
506 QTCOMMERCIALCHART_END_NAMESPACE
506 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now