@@ -1,22 +1,25 | |||||
1 | #include "customtablemodel.h" |
|
1 | #include "customtablemodel.h" | |
2 | #include <QVector> |
|
2 | #include <QVector> | |
|
3 | #include <QTime> | |||
3 |
|
4 | |||
4 | CustomTableModel::CustomTableModel(QObject *parent) : |
|
5 | CustomTableModel::CustomTableModel(QObject *parent) : | |
5 | QAbstractTableModel(parent) |
|
6 | QAbstractTableModel(parent) | |
6 | { |
|
7 | { | |
7 | // m_points.append(QPointF(10, 50)); |
|
8 | // m_points.append(QPointF(10, 50)); | |
8 | // m_labels.append("Apples"); |
|
9 | // m_labels.append("Apples"); | |
9 | // m_points.append(QPointF(60, 70)); |
|
10 | // m_points.append(QPointF(60, 70)); | |
10 | // m_labels.append("Oranges"); |
|
11 | // m_labels.append("Oranges"); | |
11 | // m_points.append(QPointF(110, 50)); |
|
12 | // m_points.append(QPointF(110, 50)); | |
12 | // m_labels.append("Bananas"); |
|
13 | // m_labels.append("Bananas"); | |
13 | // m_points.append(QPointF(140, 40)); |
|
14 | // m_points.append(QPointF(140, 40)); | |
14 | // m_labels.append("Lemons"); |
|
15 | // m_labels.append("Lemons"); | |
15 | // m_points.append(QPointF(200, 150)); |
|
16 | // m_points.append(QPointF(200, 150)); | |
16 | // m_labels.append("Plums"); |
|
17 | // m_labels.append("Plums"); | |
17 | // m_points.append(QPointF(225, 75)); |
|
18 | // m_points.append(QPointF(225, 75)); | |
18 | // m_labels.append("Pearls"); |
|
19 | // m_labels.append("Pearls"); | |
19 |
|
20 | |||
|
21 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |||
|
22 | ||||
20 | // m_data |
|
23 | // m_data | |
21 | for (int i = 0; i < 6; i++) |
|
24 | for (int i = 0; i < 6; i++) | |
22 | { |
|
25 | { | |
@@ -168,10 +171,17 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & pare | |||||
168 | dataVec->replace(k, m_data[row - 1]->at(k) + qrand()%qMax(1, difference)); |
|
171 | dataVec->replace(k, m_data[row - 1]->at(k) + qrand()%qMax(1, difference)); | |
169 | } |
|
172 | } | |
170 | else |
|
173 | else | |
171 |
dataVec->replace(k, qrand()% |
|
174 | dataVec->replace(k, qrand()%40 + 10); | |
172 | } |
|
175 | } | |
173 | else |
|
176 | else | |
174 | dataVec->replace(k, m_data[row - 1]->at(k) + qrand()%20); |
|
177 | if (row - 1 >= 0) | |
|
178 | { | |||
|
179 | dataVec->replace(k, m_data[row - 1]->at(k) + qrand()%40 + 10); | |||
|
180 | } | |||
|
181 | else | |||
|
182 | { | |||
|
183 | dataVec->replace(k, qrand()%40 + 10); | |||
|
184 | } | |||
175 | } |
|
185 | } | |
176 | else |
|
186 | else | |
177 | dataVec->replace(k, qrand()%100); |
|
187 | dataVec->replace(k, qrand()%100); | |
@@ -193,7 +203,7 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & pare | |||||
193 | beginRemoveRows(parent, row, row + count - 1); |
|
203 | beginRemoveRows(parent, row, row + count - 1); | |
194 | for (int i = row; i < row + count; i++) |
|
204 | for (int i = row; i < row + count; i++) | |
195 | { |
|
205 | { | |
196 | // m_points.removeAt(row); |
|
206 | // m_points.removeAt(row); | |
197 | QVector<qreal>* item = m_data.at(row); |
|
207 | QVector<qreal>* item = m_data.at(row); | |
198 | m_data.removeAt(row); |
|
208 | m_data.removeAt(row); | |
199 | delete item; |
|
209 | delete item; |
@@ -126,6 +126,7 void TableWidget::updateChartType() | |||||
126 | series = new QLineSeries; |
|
126 | series = new QLineSeries; | |
127 | series->setModel(m_model); |
|
127 | series->setModel(m_model); | |
128 | series->setModelMapping(0,1, Qt::Vertical); |
|
128 | series->setModelMapping(0,1, Qt::Vertical); | |
|
129 | series->setModelMappingShift(1, 4); | |||
129 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
130 | // series->setModelMapping(0,1, Qt::Horizontal); | |
130 | chartView->addSeries(series); |
|
131 | chartView->addSeries(series); | |
131 |
|
132 | |||
@@ -136,19 +137,20 void TableWidget::updateChartType() | |||||
136 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
137 | // series->setModelMapping(2,3, Qt::Horizontal); | |
137 | chartView->addSeries(series); |
|
138 | chartView->addSeries(series); | |
138 |
|
139 | |||
139 | // series 3 |
|
140 | // // series 3 | |
140 | series = new QLineSeries; |
|
141 | // series = new QLineSeries; | |
141 | series->setModel(m_model); |
|
142 | // series->setModel(m_model); | |
142 | series->setModelMapping(4,5, Qt::Vertical); |
|
143 | // series->setModelMapping(4,5, Qt::Vertical); | |
143 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
144 | //// series->setModelMapping(4,5, Qt::Horizontal); | |
144 | chartView->addSeries(series); |
|
145 | // chartView->addSeries(series); | |
145 | } |
|
146 | } | |
146 | else if (splineRadioButton->isChecked()) |
|
147 | else if (splineRadioButton->isChecked()) | |
147 | { |
|
148 | { | |
148 | // series 1 |
|
149 | // series 1 | |
149 | series = new QSplineSeries; |
|
150 | series = new QSplineSeries; | |
150 | series->setModel(m_model); |
|
151 | series->setModel(m_model); | |
151 |
|
|
152 | series->setModelMapping(0,1, Qt::Vertical); | |
|
153 | series->setModelMappingShift(1, 4); | |||
152 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
154 | // series->setModelMapping(0,1, Qt::Horizontal); | |
153 | chartView->addSeries(series); |
|
155 | chartView->addSeries(series); | |
154 |
|
156 |
@@ -41,6 +41,8 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) | |||||
41 | m_mapCategories = -1; |
|
41 | m_mapCategories = -1; | |
42 | m_mapBarBottom = -1; |
|
42 | m_mapBarBottom = -1; | |
43 | m_mapBarTop = -1; |
|
43 | m_mapBarTop = -1; | |
|
44 | m_mapFirst = 0; | |||
|
45 | m_mapCount = 0; | |||
44 | m_mapOrientation = Qt::Vertical; |
|
46 | m_mapOrientation = Qt::Vertical; | |
45 | } |
|
47 | } | |
46 |
|
48 | |||
@@ -234,6 +236,8 bool QBarSeries::setModel(QAbstractItemModel* model) | |||||
234 | m_mapCategories = -1; |
|
236 | m_mapCategories = -1; | |
235 | m_mapBarBottom = -1; |
|
237 | m_mapBarBottom = -1; | |
236 | m_mapBarTop = -1; |
|
238 | m_mapBarTop = -1; | |
|
239 | m_mapFirst = 0; | |||
|
240 | m_mapCount = 0; | |||
237 | m_mapOrientation = Qt::Vertical; |
|
241 | m_mapOrientation = Qt::Vertical; | |
238 | } |
|
242 | } | |
239 |
|
243 | |||
@@ -258,17 +262,20 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||||
258 | m_mapCategories = categories; |
|
262 | m_mapCategories = categories; | |
259 | m_mapBarBottom = bottomBoundry; |
|
263 | m_mapBarBottom = bottomBoundry; | |
260 | m_mapBarTop = topBoundry; |
|
264 | m_mapBarTop = topBoundry; | |
|
265 | m_mapFirst = 1; | |||
261 | m_mapOrientation = orientation; |
|
266 | m_mapOrientation = orientation; | |
262 |
|
267 | |||
263 | // connect the signals |
|
268 | // connect the signals | |
264 | if (m_mapOrientation == Qt::Vertical) |
|
269 | if (m_mapOrientation == Qt::Vertical) | |
265 | { |
|
270 | { | |
|
271 | m_mapCount = m_model->rowCount(); | |||
266 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
272 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
267 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
273 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
268 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
274 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
269 | } |
|
275 | } | |
270 | else |
|
276 | else | |
271 | { |
|
277 | { | |
|
278 | m_mapCount = m_model->columnCount(); | |||
272 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
279 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
273 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
280 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
274 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
281 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
@@ -280,14 +287,14 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||||
280 | if (m_mapOrientation == Qt::Vertical) |
|
287 | if (m_mapOrientation == Qt::Vertical) | |
281 | { |
|
288 | { | |
282 | QStringList categories; |
|
289 | QStringList categories; | |
283 |
for (int k = |
|
290 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
284 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
291 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
285 | mModel = new BarChartModel(categories, this); |
|
292 | mModel = new BarChartModel(categories, this); | |
286 |
|
293 | |||
287 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
294 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
288 | { |
|
295 | { | |
289 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
296 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
290 |
for(int m = |
|
297 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
291 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
298 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
292 | addBarSet(barSet); |
|
299 | addBarSet(barSet); | |
293 | } |
|
300 | } | |
@@ -295,37 +302,41 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||||
295 | else |
|
302 | else | |
296 | { |
|
303 | { | |
297 | QStringList categories; |
|
304 | QStringList categories; | |
298 |
for (int k = |
|
305 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
299 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
306 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
300 | mModel = new BarChartModel(categories, this); |
|
307 | mModel = new BarChartModel(categories, this); | |
301 |
|
308 | |||
302 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
309 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
303 | { |
|
310 | { | |
304 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
311 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
305 |
for(int m = |
|
312 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
306 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
313 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
307 | addBarSet(barSet); |
|
314 | addBarSet(barSet); | |
308 | } |
|
315 | } | |
309 | } |
|
316 | } | |
310 | } |
|
317 | } | |
311 |
|
318 | |||
|
319 | void QBarSeries::setModelMappingShift(int first, int count) | |||
|
320 | { | |||
|
321 | m_mapFirst = first; | |||
|
322 | m_mapCount = count; | |||
|
323 | } | |||
|
324 | ||||
312 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
325 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
313 | { |
|
326 | { | |
314 | Q_UNUSED(bottomRight) |
|
327 | Q_UNUSED(bottomRight) | |
315 |
|
328 | |||
316 | if (m_mapOrientation == Qt::Vertical) |
|
329 | if (m_mapOrientation == Qt::Vertical) | |
317 | { |
|
330 | { | |
318 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) |
|
331 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
319 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
332 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
320 | // else if (topLeft.column() == m_mapCategories) |
|
333 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
321 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
|||
322 | } |
|
334 | } | |
323 | else |
|
335 | else | |
324 | { |
|
336 | { | |
325 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) |
|
337 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
326 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
338 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
327 | // else if (topLeft.row() == m_mapCategories) |
|
339 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
328 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
|||
329 | } |
|
340 | } | |
330 | } |
|
341 | } | |
331 |
|
342 | |||
@@ -333,18 +344,18 void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |||||
333 | { |
|
344 | { | |
334 | if (m_mapOrientation == Qt::Vertical) |
|
345 | if (m_mapOrientation == Qt::Vertical) | |
335 | { |
|
346 | { | |
336 | insertCategory(start, QString("Row: %1").arg(start + 1)); |
|
347 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
337 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
348 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
338 | { |
|
349 | { | |
339 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
350 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
340 | } |
|
351 | } | |
341 | } |
|
352 | } | |
342 | else |
|
353 | else | |
343 | { |
|
354 | { | |
344 | insertCategory(start, QString("Column: %1").arg(start + 1)); |
|
355 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
345 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
356 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
346 | { |
|
357 | { | |
347 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
358 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
348 | } |
|
359 | } | |
349 | } |
|
360 | } | |
350 | emit restructuredBar(1); |
|
361 | emit restructuredBar(1); | |
@@ -352,10 +363,10 void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |||||
352 |
|
363 | |||
353 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int start, int /*end*/) |
|
364 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int start, int /*end*/) | |
354 | { |
|
365 | { | |
355 | removeCategory(start); |
|
366 | removeCategory(start - m_mapFirst); | |
356 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
367 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
357 | { |
|
368 | { | |
358 | barsetAt(i)->removeValue(start); |
|
369 | barsetAt(i)->removeValue(start - m_mapFirst); | |
359 | } |
|
370 | } | |
360 | emit restructuredBar(1); |
|
371 | emit restructuredBar(1); | |
361 | } |
|
372 | } |
@@ -35,6 +35,7 public: | |||||
35 | bool setModel(QAbstractItemModel* model); |
|
35 | bool setModel(QAbstractItemModel* model); | |
36 | QAbstractItemModel* modelExt() {return m_model;} |
|
36 | QAbstractItemModel* modelExt() {return m_model;} | |
37 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
37 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
|
38 | void setModelMappingShift(int first, int count); | |||
38 |
|
39 | |||
39 | public: |
|
40 | public: | |
40 | // TODO: Functions below this are not part of api and will be moved |
|
41 | // TODO: Functions below this are not part of api and will be moved | |
@@ -87,6 +88,8 protected: | |||||
87 | int m_mapCategories; |
|
88 | int m_mapCategories; | |
88 | int m_mapBarBottom; |
|
89 | int m_mapBarBottom; | |
89 | int m_mapBarTop; |
|
90 | int m_mapBarTop; | |
|
91 | int m_mapFirst; | |||
|
92 | int m_mapCount; | |||
90 | Qt::Orientation m_mapOrientation; |
|
93 | Qt::Orientation m_mapOrientation; | |
91 | }; |
|
94 | }; | |
92 |
|
95 |
@@ -147,6 +147,12 bool QSplineSeries::setModel(QAbstractItemModel* model) | |||||
147 | void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
147 | void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
148 | { |
|
148 | { | |
149 | QLineSeries::setModelMapping(modelX, modelY, orientation); |
|
149 | QLineSeries::setModelMapping(modelX, modelY, orientation); | |
|
150 | // calculateControlPoints(); | |||
|
151 | } | |||
|
152 | ||||
|
153 | void QSplineSeries::setModelMappingShift(int first, int count) | |||
|
154 | { | |||
|
155 | QLineSeries::setModelMappingShift(first, count); | |||
150 | calculateControlPoints(); |
|
156 | calculateControlPoints(); | |
151 | } |
|
157 | } | |
152 |
|
158 |
@@ -22,6 +22,7 public: | |||||
22 | bool setModel(QAbstractItemModel* model); |
|
22 | bool setModel(QAbstractItemModel* model); | |
23 |
|
23 | |||
24 | void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); |
|
24 | void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); | |
|
25 | void setModelMappingShift(int first, int count); | |||
25 |
|
26 | |||
26 | // TODO: allow the user to set custom control points |
|
27 | // TODO: allow the user to set custom control points | |
27 | // void setCustomControlPoints(QList<QPointsF> controlPoints); |
|
28 | // void setCustomControlPoints(QList<QPointsF> controlPoints); |
@@ -52,6 +52,9 QXYSeries::QXYSeries(QObject* parent):QSeries(parent) | |||||
52 | { |
|
52 | { | |
53 | m_mapX = -1; |
|
53 | m_mapX = -1; | |
54 | m_mapY = -1; |
|
54 | m_mapY = -1; | |
|
55 | m_mapFirst = 0; | |||
|
56 | m_mapCount = 0; | |||
|
57 | m_mapLimited = false; | |||
55 | m_mapOrientation = Qt::Vertical; |
|
58 | m_mapOrientation = Qt::Vertical; | |
56 | // m_mapYOrientation = Qt::Vertical; |
|
59 | // m_mapYOrientation = Qt::Vertical; | |
57 | } |
|
60 | } | |
@@ -171,10 +174,10 qreal QXYSeries::x(int pos) const | |||||
171 | if (m_model) |
|
174 | if (m_model) | |
172 | if (m_mapOrientation == Qt::Vertical) |
|
175 | if (m_mapOrientation == Qt::Vertical) | |
173 | // consecutive data is read from model's column |
|
176 | // consecutive data is read from model's column | |
174 | return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble(); |
|
177 | return m_model->data(m_model->index(pos + m_mapFirst, m_mapX), Qt::DisplayRole).toDouble(); | |
175 | else |
|
178 | else | |
176 | // consecutive data is read from model's row |
|
179 | // consecutive data is read from model's row | |
177 | return m_model->data(m_model->index(m_mapX, pos), Qt::DisplayRole).toDouble(); |
|
180 | return m_model->data(m_model->index(m_mapX, pos + m_mapFirst), Qt::DisplayRole).toDouble(); | |
178 | else |
|
181 | else | |
179 | // model is not specified, return the data from series' internal data store |
|
182 | // model is not specified, return the data from series' internal data store | |
180 | return m_x.at(pos); |
|
183 | return m_x.at(pos); | |
@@ -188,10 +191,10 qreal QXYSeries::y(int pos) const | |||||
188 | if (m_model) |
|
191 | if (m_model) | |
189 | if (m_mapOrientation == Qt::Vertical) |
|
192 | if (m_mapOrientation == Qt::Vertical) | |
190 | // consecutive data is read from model's column |
|
193 | // consecutive data is read from model's column | |
191 | return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble(); |
|
194 | return m_model->data(m_model->index(pos + m_mapFirst, m_mapY), Qt::DisplayRole).toDouble(); | |
192 | else |
|
195 | else | |
193 | // consecutive data is read from model's row |
|
196 | // consecutive data is read from model's row | |
194 | return m_model->data(m_model->index(m_mapY, pos), Qt::DisplayRole).toDouble(); |
|
197 | return m_model->data(m_model->index(m_mapY, pos + m_mapFirst), Qt::DisplayRole).toDouble(); | |
195 | else |
|
198 | else | |
196 | // model is not specified, return the data from series' internal data store |
|
199 | // model is not specified, return the data from series' internal data store | |
197 | return m_y.at(pos); |
|
200 | return m_y.at(pos); | |
@@ -206,11 +209,23 int QXYSeries::count() const | |||||
206 |
|
209 | |||
207 | if (m_model) { |
|
210 | if (m_model) { | |
208 | if (m_mapOrientation == Qt::Vertical) |
|
211 | if (m_mapOrientation == Qt::Vertical) | |
209 | // data is in a column, so return the number of items in single column |
|
212 | { | |
210 | return m_model->rowCount(); |
|
213 | // data is in a column. Return the number of mapped items if the model's column have enough items | |
|
214 | // or the number of items that can be mapped | |||
|
215 | if (m_mapLimited) | |||
|
216 | return qMin(m_mapCount, qMax(m_model->rowCount() - m_mapFirst, 0)); | |||
|
217 | else | |||
|
218 | return qMax(m_model->rowCount() - m_mapFirst, 0); | |||
|
219 | } | |||
211 | else |
|
220 | else | |
212 | // data is in a row, so return the number of items in single row |
|
221 | { | |
213 | return m_model->columnCount(); |
|
222 | // data is in a row. Return the number of mapped items if the model's row have enough items | |
|
223 | // or the number of items that can be mapped | |||
|
224 | if (m_mapLimited) | |||
|
225 | return qMin(m_mapCount, qMax(m_model->columnCount() - m_mapFirst, 0)); | |||
|
226 | else | |||
|
227 | return qMax(m_model->columnCount() - m_mapFirst, 0); | |||
|
228 | } | |||
214 | } |
|
229 | } | |
215 |
|
230 | |||
216 | // model is not specified, return the number of points in the series internal data store |
|
231 | // model is not specified, return the number of points in the series internal data store | |
@@ -286,23 +301,148 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||||
286 | Q_UNUSED(bottomRight) |
|
301 | Q_UNUSED(bottomRight) | |
287 |
|
302 | |||
288 | if (m_mapOrientation == Qt::Vertical) |
|
303 | if (m_mapOrientation == Qt::Vertical) | |
289 | emit pointReplaced(topLeft.row()); |
|
304 | { | |
|
305 | if (topLeft.row() >= m_mapFirst && (!m_mapLimited || topLeft.row() < m_mapFirst + m_mapCount)) | |||
|
306 | emit pointReplaced(topLeft.row() - m_mapFirst); | |||
|
307 | } | |||
|
308 | else | |||
|
309 | { | |||
|
310 | if (topLeft.column() >= m_mapFirst && (!m_mapLimited || topLeft.column() < m_mapFirst + m_mapCount)) | |||
|
311 | emit pointReplaced(topLeft.column() - m_mapFirst); | |||
|
312 | } | |||
|
313 | } | |||
|
314 | ||||
|
315 | void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) | |||
|
316 | { | |||
|
317 | Q_UNUSED(parent) | |||
|
318 | // Q_UNUSED(end) | |||
|
319 | ||||
|
320 | if (m_mapLimited) | |||
|
321 | { | |||
|
322 | if (start >= m_mapFirst + m_mapCount) | |||
|
323 | // the added data is below mapped area | |||
|
324 | // therefore it has no relevance | |||
|
325 | return; | |||
|
326 | else | |||
|
327 | { | |||
|
328 | // the added data is in the mapped area or before it and update is needed | |||
|
329 | ||||
|
330 | // check how many mapped items there is currently (before new items are added) | |||
|
331 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem | |||
|
332 | // internal storage before new ones can be added | |||
|
333 | if (m_mapCount == count()) | |||
|
334 | for (int i = 0; i < qMin(count(), end - start + 1); i++) | |||
|
335 | emit pointRemoved(count() - 1 - i); | |||
|
336 | } | |||
|
337 | } | |||
290 | else |
|
338 | else | |
291 | emit pointReplaced(topLeft.column()); |
|
339 | { | |
|
340 | // map is not limited (it includes all the items starting from m_mapFirst till the end of model) | |||
|
341 | // nothing to do | |||
|
342 | // emit pointAdded(qMax(start - m_mapFirst, 0)); | |||
|
343 | } | |||
292 | } |
|
344 | } | |
293 |
|
345 | |||
294 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) |
|
346 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
295 | { |
|
347 | { | |
296 | Q_UNUSED(parent) |
|
348 | Q_UNUSED(parent) | |
297 | Q_UNUSED(end) |
|
349 | // Q_UNUSED(end) | |
298 | emit pointAdded(start); |
|
350 | ||
|
351 | if (m_mapLimited) | |||
|
352 | { | |||
|
353 | if (start >= m_mapFirst + m_mapCount) | |||
|
354 | // the added data is below mapped area | |||
|
355 | // therefore it has no relevance | |||
|
356 | return; | |||
|
357 | else | |||
|
358 | { | |||
|
359 | // the added data is in the mapped area or before it | |||
|
360 | // update needed | |||
|
361 | if (count() > 0) | |||
|
362 | for (int i = 0; i < qMin(m_mapCount, end - start + 1); i++) | |||
|
363 | emit pointAdded(qMax(start + i - m_mapFirst, 0)); | |||
|
364 | } | |||
|
365 | } | |||
|
366 | else | |||
|
367 | { | |||
|
368 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |||
|
369 | for (int i = 0; i < end - start + 1; i++) | |||
|
370 | emit pointAdded(qMax(start + i - m_mapFirst, 0)); | |||
|
371 | } | |||
|
372 | } | |||
|
373 | ||||
|
374 | void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) | |||
|
375 | { | |||
|
376 | Q_UNUSED(parent) | |||
|
377 | // Q_UNUSED(end) | |||
|
378 | ||||
|
379 | if (m_mapLimited) | |||
|
380 | { | |||
|
381 | if (start >= m_mapFirst + m_mapCount) | |||
|
382 | // the removed data is below mapped area | |||
|
383 | // therefore it has no relevance | |||
|
384 | return; | |||
|
385 | else | |||
|
386 | { | |||
|
387 | // the removed data is in the mapped area or before it | |||
|
388 | // update needed | |||
|
389 | int itemsToRemove = qMin(count(), end - start + 1); | |||
|
390 | tempItemsRemoved = itemsToRemove; | |||
|
391 | int z = count(); | |||
|
392 | z = z; | |||
|
393 | // if (itemsToRemove > 0) | |||
|
394 | // { | |||
|
395 | for (int i = 0; i < itemsToRemove; i++) | |||
|
396 | emit pointRemoved(qMax(start - m_mapFirst, 0)); | |||
|
397 | } | |||
|
398 | } | |||
|
399 | else | |||
|
400 | { | |||
|
401 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |||
|
402 | for (int i = 0; i < end - start + 1; i++) | |||
|
403 | emit pointRemoved(qMax(start - m_mapFirst, 0)); | |||
|
404 | } | |||
299 | } |
|
405 | } | |
300 |
|
406 | |||
301 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
407 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
302 | { |
|
408 | { | |
303 | Q_UNUSED(parent) |
|
409 | Q_UNUSED(parent) | |
304 | Q_UNUSED(end) |
|
410 | Q_UNUSED(end) | |
305 | emit pointRemoved(start); |
|
411 | ||
|
412 | // how many items there were before data was removed | |||
|
413 | // int oldCount = count() - 1; | |||
|
414 | ||||
|
415 | if (m_mapLimited) | |||
|
416 | { | |||
|
417 | if (start >= m_mapFirst + m_mapCount) | |||
|
418 | // the removed data is below mapped area | |||
|
419 | // therefore it has no relevance | |||
|
420 | return; | |||
|
421 | else | |||
|
422 | { | |||
|
423 | // if there are excess items available (below the map) use them to repopulate mapped area | |||
|
424 | int extraItemsAvailable = 0; | |||
|
425 | if (m_mapOrientation == Qt::Vertical) | |||
|
426 | { | |||
|
427 | extraItemsAvailable = qMax(m_model->rowCount() - m_mapFirst, 0); | |||
|
428 | } | |||
|
429 | else | |||
|
430 | { | |||
|
431 | extraItemsAvailable = qMax(m_model->columnCount() - m_mapFirst, 0); | |||
|
432 | } | |||
|
433 | ||||
|
434 | // int extraItemsNeeded = qMin(extraItemsAvailable, tempItemsRemoved); | |||
|
435 | for (int k = 0; k < tempItemsRemoved; k++) | |||
|
436 | if (start - m_mapFirst + k < extraItemsAvailable) | |||
|
437 | { | |||
|
438 | emit pointAdded(count() - m_mapFirst + k); | |||
|
439 | } | |||
|
440 | } | |||
|
441 | } | |||
|
442 | else | |||
|
443 | { | |||
|
444 | // emit pointRemoved(qMax(start - m_mapFirst, 0)); | |||
|
445 | } | |||
306 | } |
|
446 | } | |
307 |
|
447 | |||
308 | bool QXYSeries::setModel(QAbstractItemModel* model) { |
|
448 | bool QXYSeries::setModel(QAbstractItemModel* model) { | |
@@ -313,6 +453,9 bool QXYSeries::setModel(QAbstractItemModel* model) { | |||||
313 | disconnect(m_model, 0, this, 0); |
|
453 | disconnect(m_model, 0, this, 0); | |
314 | m_mapX = -1; |
|
454 | m_mapX = -1; | |
315 | m_mapY = -1; |
|
455 | m_mapY = -1; | |
|
456 | m_mapFirst = 0; | |||
|
457 | m_mapCount = 0; | |||
|
458 | m_mapLimited = false; | |||
316 | m_mapOrientation = Qt::Vertical; |
|
459 | m_mapOrientation = Qt::Vertical; | |
317 | } |
|
460 | } | |
318 |
|
461 | |||
@@ -335,26 +478,39 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientat | |||||
335 | return; |
|
478 | return; | |
336 | m_mapX = modelX; |
|
479 | m_mapX = modelX; | |
337 | m_mapY = modelY; |
|
480 | m_mapY = modelY; | |
|
481 | m_mapFirst = 0; | |||
338 | m_mapOrientation = orientation; |
|
482 | m_mapOrientation = orientation; | |
339 | if (m_mapOrientation == Qt::Vertical) |
|
483 | if (m_mapOrientation == Qt::Vertical) | |
340 | { |
|
484 | { | |
|
485 | // m_mapCount = m_model->rowCount(); | |||
341 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
486 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
487 | connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |||
342 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
488 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
489 | connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |||
343 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
490 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
344 | } |
|
491 | } | |
345 | else |
|
492 | else | |
346 | { |
|
493 | { | |
|
494 | // m_mapCount = m_model->columnCount(); | |||
347 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
495 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
496 | connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |||
348 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
497 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
498 | connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |||
349 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
499 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
350 | } |
|
500 | } | |
351 | } |
|
501 | } | |
352 |
|
502 | |||
353 | //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation) |
|
503 | void QXYSeries::setModelMappingShift(int first, int count) | |
354 | //{ |
|
504 | { | |
355 | // m_mapY = modelLineIndex; |
|
505 | m_mapFirst = first; | |
356 | // m_mapYOrientation = orientation; |
|
506 | if (count == 0) | |
357 | //} |
|
507 | m_mapLimited = false; | |
|
508 | else | |||
|
509 | { | |||
|
510 | m_mapCount = count; | |||
|
511 | m_mapLimited = true; | |||
|
512 | } | |||
|
513 | } | |||
358 |
|
514 | |||
359 | #include "moc_qxyseries.cpp" |
|
515 | #include "moc_qxyseries.cpp" | |
360 |
|
516 |
@@ -44,11 +44,13 public: | |||||
44 | QAbstractItemModel* model() {return m_model;} |
|
44 | QAbstractItemModel* model() {return m_model;} | |
45 |
|
45 | |||
46 | virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); |
|
46 | virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); | |
47 | // void setModelMappingY(int modelLineIndex, Qt::Orientation orientation = Qt::Vertical); |
|
47 | virtual void setModelMappingShift(int first, int count = 0); | |
48 |
|
48 | |||
49 | private slots: |
|
49 | private slots: | |
50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
51 | void modelDataAboutToBeAdded(QModelIndex parent, int start, int end); | |||
51 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
52 | void modelDataAdded(QModelIndex parent, int start, int end); | |
|
53 | void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end); | |||
52 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
54 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
53 |
|
55 | |||
54 | signals: |
|
56 | signals: | |
@@ -65,11 +67,13 protected: | |||||
65 | QPen m_pen; |
|
67 | QPen m_pen; | |
66 | QBrush m_brush; |
|
68 | QBrush m_brush; | |
67 |
|
69 | |||
68 | // QAbstractItemModel* m_model; |
|
70 | int m_mapX; | |
69 | int m_mapX; |
|
|||
70 | Qt::Orientation m_mapOrientation; |
|
|||
71 |
|
|
71 | int m_mapY; | |
72 | // Qt::Orientation m_mapYOrientation; |
|
72 | int m_mapFirst; | |
|
73 | int m_mapCount; | |||
|
74 | bool m_mapLimited; | |||
|
75 | Qt::Orientation m_mapOrientation; | |||
|
76 | int tempItemsRemoved; | |||
73 | }; |
|
77 | }; | |
74 |
|
78 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now