##// END OF EJS Templates
XYSeries model with limits working.
Marek Rosa -
r833:16b8c9450c47
parent child
Show More
@@ -17,7 +17,7 SUBDIRS += \
17 splinechart \
17 splinechart \
18 stackedbarchart \
18 stackedbarchart \
19 stackedbarchartdrilldown \
19 stackedbarchartdrilldown \
20 #tablemodelchart \
20 tablemodelchart \
21 zoomlinechart
21 zoomlinechart
22
22
23
23
@@ -98,7 +98,7 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation,
98 }
98 }
99 }
99 }
100 else
100 else
101 return QString("%1").arg(section + 1);
101 return QString("%1").arg(section /*+ 1*/);
102 }
102 }
103
103
104 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
104 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
@@ -203,7 +203,10 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & pare
203 {
203 {
204 if (i - 1 >= 0)
204 if (i - 1 >= 0)
205 {
205 {
206 if (row > 0)
206 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
207 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
208 else
209 difference = (int)((qAbs(m_data[i]->at(k)/count)));
207 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
210 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
208 }
211 }
209 else
212 else
@@ -42,14 +42,15 TableWidget::TableWidget(QWidget *parent)
42 // create simple model for storing data
42 // create simple model for storing data
43 // user's table data model
43 // user's table data model
44 m_model = new CustomTableModel;
44 m_model = new CustomTableModel;
45 tableView = new QTableView;
45 m_tableView = new QTableView;
46 tableView->setModel(m_model);
46 m_tableView->setModel(m_model);
47 tableView->setMinimumHeight(240);
47 m_tableView->setMinimumHeight(240);
48 // tableView->setMinimumSize(340, 480);
48 // tableView->setMinimumSize(340, 480);
49 // tableView->setItemDelegate(new QStyledItemDelegate);
49 // tableView->setItemDelegate(new QStyledItemDelegate);
50 chartView = new QChartView(this);
50 m_chart = new QChart;
51 chartView->setRenderHint(QPainter::Antialiasing);
51 m_chartView = new QChartView(m_chart);
52 chartView->setMinimumSize(640, 480);
52 m_chartView->setRenderHint(QPainter::Antialiasing);
53 m_chartView->setMinimumSize(640, 480);
53
54
54 // create
55 // create
55 // QLineSeries* series = new QLineSeries;
56 // QLineSeries* series = new QLineSeries;
@@ -74,59 +75,59 TableWidget::TableWidget(QWidget *parent)
74 QPushButton* removeRowButton = new QPushButton("Remove row");
75 QPushButton* removeRowButton = new QPushButton("Remove row");
75 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
76 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
76
77
77 linesCountSpinBox = new QSpinBox;
78 m_linesCountSpinBox = new QSpinBox;
78 linesCountSpinBox->setRange(1, 10);
79 m_linesCountSpinBox->setRange(1, 10);
79 linesCountSpinBox->setValue(1);
80 m_linesCountSpinBox->setValue(1);
80
81
81 // buttons layout
82 // buttons layout
82 QVBoxLayout* buttonsLayout = new QVBoxLayout;
83 QVBoxLayout* buttonsLayout = new QVBoxLayout;
83 buttonsLayout->addWidget(linesCountSpinBox);
84 buttonsLayout->addWidget(m_linesCountSpinBox);
84 buttonsLayout->addWidget(addRowAboveButton);
85 buttonsLayout->addWidget(addRowAboveButton);
85 buttonsLayout->addWidget(addRowBelowButton);
86 buttonsLayout->addWidget(addRowBelowButton);
86 buttonsLayout->addWidget(removeRowButton);
87 buttonsLayout->addWidget(removeRowButton);
87 buttonsLayout->addStretch();
88 buttonsLayout->addStretch();
88
89
89 // chart type radio buttons
90 // chart type radio buttons
90 lineRadioButton = new QRadioButton("Line");
91 m_lineRadioButton = new QRadioButton("Line");
91 splineRadioButton = new QRadioButton("Spline");
92 m_splineRadioButton = new QRadioButton("Spline");
92 scatterRadioButton = new QRadioButton("Scatter");
93 m_scatterRadioButton = new QRadioButton("Scatter");
93 pieRadioButton = new QRadioButton("Pie");
94 m_pieRadioButton = new QRadioButton("Pie");
94 areaRadioButton = new QRadioButton("Area");
95 m_areaRadioButton = new QRadioButton("Area");
95 barRadioButton = new QRadioButton("Bar");
96 m_barRadioButton = new QRadioButton("Bar");
96
97
97 connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
98 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
98 connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
99 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
99 connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
100 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
100 connect(pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
101 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
101 connect(areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
102 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
102 connect(barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
103 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
103 lineRadioButton->setChecked(true);
104 m_lineRadioButton->setChecked(true);
104
105
105 // radio buttons layout
106 // radio buttons layout
106 QVBoxLayout* radioLayout = new QVBoxLayout;
107 QVBoxLayout* radioLayout = new QVBoxLayout;
107 radioLayout->addWidget(lineRadioButton);
108 radioLayout->addWidget(m_lineRadioButton);
108 radioLayout->addWidget(splineRadioButton);
109 radioLayout->addWidget(m_splineRadioButton);
109 radioLayout->addWidget(scatterRadioButton);
110 radioLayout->addWidget(m_scatterRadioButton);
110 radioLayout->addWidget(pieRadioButton);
111 radioLayout->addWidget(m_pieRadioButton);
111 radioLayout->addWidget(areaRadioButton);
112 radioLayout->addWidget(m_areaRadioButton);
112 radioLayout->addWidget(barRadioButton);
113 radioLayout->addWidget(m_barRadioButton);
113 radioLayout->addStretch();
114 radioLayout->addStretch();
114
115
115 // create main layout
116 // create main layout
116 QGridLayout* mainLayout = new QGridLayout;
117 QGridLayout* mainLayout = new QGridLayout;
117 mainLayout->addLayout(buttonsLayout, 1, 0);
118 mainLayout->addLayout(buttonsLayout, 1, 1);
118 mainLayout->addLayout(radioLayout, 2, 0);
119 mainLayout->addLayout(radioLayout, 2, 1);
119 mainLayout->addWidget(tableView, 1, 1);
120 mainLayout->addWidget(m_tableView, 1, 0);
120 mainLayout->addWidget(chartView, 2, 1);
121 mainLayout->addWidget(m_chartView, 2, 0);
121 setLayout(mainLayout);
122 setLayout(mainLayout);
122 lineRadioButton->setFocus();
123 m_lineRadioButton->setFocus();
123 }
124 }
124
125
125 void TableWidget::addRowAbove()
126 void TableWidget::addRowAbove()
126 {
127 {
127 // m_model->insertRow(m_model->rowCount());
128 // m_model->insertRow(m_model->rowCount());
128 // m_model->insertRow(tableView->currentIndex().row());
129 // m_model->insertRow(tableView->currentIndex().row());
129 m_model->insertRows(tableView->currentIndex().row(), linesCountSpinBox->value());
130 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
130
131
131 }
132 }
132
133
@@ -134,7 +135,7 void TableWidget::addRowBelow()
134 {
135 {
135 // m_model->insertRow(m_model->rowCount());
136 // m_model->insertRow(m_model->rowCount());
136 // m_model->insertRow(tableView->currentIndex().row() + 1);
137 // m_model->insertRow(tableView->currentIndex().row() + 1);
137 m_model->insertRows(tableView->currentIndex().row() + 1, linesCountSpinBox->value());
138 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
138
139
139 }
140 }
140
141
@@ -142,14 +143,14 void TableWidget::removeRow()
142 {
143 {
143 // m_model->removeRow(m_model->rowCount() - 1);
144 // m_model->removeRow(m_model->rowCount() - 1);
144 // m_model->removeRow(tableView->currentIndex().row());
145 // m_model->removeRow(tableView->currentIndex().row());
145 m_model->removeRows(tableView->currentIndex().row(), qMin(m_model->rowCount() - tableView->currentIndex().row(), linesCountSpinBox->value()));
146 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
146 }
147 }
147
148
148 void TableWidget::updateChartType()
149 void TableWidget::updateChartType()
149 {
150 {
150 chartView->removeAllSeries();
151 m_chart->removeAllSeries();
151
152
152 if (lineRadioButton->isChecked())
153 if (m_lineRadioButton->isChecked())
153 {
154 {
154 QPen pen;
155 QPen pen;
155 pen.setWidth(2);
156 pen.setWidth(2);
@@ -157,15 +158,15 void TableWidget::updateChartType()
157 QColor seriesColor("#8FBC8F");
158 QColor seriesColor("#8FBC8F");
158
159
159 // series 1
160 // series 1
160 series = new QLineSeries;
161 m_series = new QLineSeries;
161 series->setModel(m_model);
162 m_series->setModel(m_model);
162 series->setModelMapping(0,1, Qt::Vertical);
163 m_series->setModelMapping(0,1, Qt::Vertical);
163 series->setModelMappingShift(1, 4);
164 m_series->setModelMappingShift(3, 3);
164 // series->setModelMapping(0,1, Qt::Horizontal);
165 // series->setModelMapping(0,1, Qt::Horizontal);
165
166
166 pen.setColor(seriesColor);
167 pen.setColor(seriesColor);
167 series->setPen(pen);
168 m_series->setPen(pen);
168 chartView->addSeries(series);
169 m_chart->addSeries(m_series);
169 for (int i = 1; i <=4; i++)
170 for (int i = 1; i <=4; i++)
170 {
171 {
171 m_model->setData(m_model->index(i, 0), seriesColor , Qt::BackgroundRole);
172 m_model->setData(m_model->index(i, 0), seriesColor , Qt::BackgroundRole);
@@ -176,15 +177,16 void TableWidget::updateChartType()
176 seriesColor = QColor("#1E90FF");
177 seriesColor = QColor("#1E90FF");
177
178
178 // series 2
179 // series 2
179 series = new QLineSeries;
180 m_series = new QLineSeries;
180 series->setModel(m_model);
181 m_series->setModel(m_model);
181 series->setModelMapping(2,3, Qt::Vertical);
182 m_series->setModelMapping(2,3, Qt::Vertical);
182 // series->setModelMapping(2,3, Qt::Horizontal);
183 // series->setModelMapping(2,3, Qt::Horizontal);
183 pen.setColor(seriesColor);
184 pen.setColor(seriesColor);
184 series->setPen(pen);
185 m_series->setPen(pen);
185 chartView->addSeries(series);
186 // m_chart->addSeries(m_series);
186
187
187 chartView->axisX()->setRange(0, 500);
188 m_chart->axisX()->setRange(0, 500);
189 m_chart->axisY()->setRange(0, 120);
188
190
189 for (int i = 0; i < m_model->rowCount(); i++)
191 for (int i = 0; i < m_model->rowCount(); i++)
190 {
192 {
@@ -198,56 +200,56 void TableWidget::updateChartType()
198 //// series->setModelMapping(4,5, Qt::Horizontal);
200 //// series->setModelMapping(4,5, Qt::Horizontal);
199 // chartView->addSeries(series);
201 // chartView->addSeries(series);
200 }
202 }
201 else if (splineRadioButton->isChecked())
203 else if (m_splineRadioButton->isChecked())
202 {
204 {
203 // series 1
205 // series 1
204 series = new QSplineSeries;
206 m_series = new QSplineSeries;
205 series->setModel(m_model);
207 m_series->setModel(m_model);
206 series->setModelMapping(0,1, Qt::Vertical);
208 m_series->setModelMapping(0,1, Qt::Vertical);
207 series->setModelMappingShift(1, 4);
209 m_series->setModelMappingShift(1, 4);
208 // series->setModelMapping(0,1, Qt::Horizontal);
210 // series->setModelMapping(0,1, Qt::Horizontal);
209 chartView->addSeries(series);
211 m_chart->addSeries(m_series);
210
212
211 // series 2
213 // series 2
212 series = new QSplineSeries;
214 m_series = new QSplineSeries;
213 series->setModel(m_model);
215 m_series->setModel(m_model);
214 series->setModelMapping(2,3, Qt::Vertical);
216 m_series->setModelMapping(2,3, Qt::Vertical);
215 series->setModelMappingShift(0, 0);
217 m_series->setModelMappingShift(0, 0);
216 // series->setModelMapping(2,3, Qt::Horizontal);
218 // series->setModelMapping(2,3, Qt::Horizontal);
217 chartView->addSeries(series);
219 m_chart->addSeries(m_series);
218
220
219 // series 3
221 // series 3
220 series = new QSplineSeries;
222 m_series = new QSplineSeries;
221 series->setModel(m_model);
223 m_series->setModel(m_model);
222 series->setModelMapping(4,5, Qt::Vertical);
224 m_series->setModelMapping(4,5, Qt::Vertical);
223 series->setModelMappingShift(0, 0);
225 m_series->setModelMappingShift(0, 0);
224 // series->setModelMapping(4,5, Qt::Horizontal);
226 // series->setModelMapping(4,5, Qt::Horizontal);
225 chartView->addSeries(series);
227 m_chart->addSeries(m_series);
226 }
228 }
227 else if (scatterRadioButton->isChecked())
229 else if (m_scatterRadioButton->isChecked())
228 {
230 {
229 // series 1
231 // series 1
230 series = new QScatterSeries;
232 m_series = new QScatterSeries;
231 series->setModel(m_model);
233 m_series->setModel(m_model);
232 series->setModelMapping(0,1, Qt::Vertical);
234 m_series->setModelMapping(0,1, Qt::Vertical);
233 // series->setModelMapping(0,1, Qt::Horizontal);
235 // series->setModelMapping(0,1, Qt::Horizontal);
234 chartView->addSeries(series);
236 m_chart->addSeries(m_series);
235
237
236 // series 2
238 // series 2
237 series = new QScatterSeries;
239 m_series = new QScatterSeries;
238 series->setModel(m_model);
240 m_series->setModel(m_model);
239 series->setModelMapping(2,3, Qt::Vertical);
241 m_series->setModelMapping(2,3, Qt::Vertical);
240 // series->setModelMapping(2,3, Qt::Horizontal);
242 // series->setModelMapping(2,3, Qt::Horizontal);
241 chartView->addSeries(series);
243 m_chart->addSeries(m_series);
242
244
243 // series 3
245 // series 3
244 series = new QScatterSeries;
246 m_series = new QScatterSeries;
245 series->setModel(m_model);
247 m_series->setModel(m_model);
246 series->setModelMapping(4,5, Qt::Vertical);
248 m_series->setModelMapping(4,5, Qt::Vertical);
247 // series->setModelMapping(4,5, Qt::Horizontal);
249 // series->setModelMapping(4,5, Qt::Horizontal);
248 chartView->addSeries(series);
250 m_chart->addSeries(m_series);
249 }
251 }
250 else if (pieRadioButton->isChecked())
252 else if (m_pieRadioButton->isChecked())
251 {
253 {
252 // pie 1
254 // pie 1
253 QPieSeries* pieSeries = new QPieSeries;
255 QPieSeries* pieSeries = new QPieSeries;
@@ -256,7 +258,7 void TableWidget::updateChartType()
256 pieSeries->setLabelsVisible(true);
258 pieSeries->setLabelsVisible(true);
257 pieSeries->setPieSize(0.4);
259 pieSeries->setPieSize(0.4);
258 pieSeries->setPiePosition(0.2, 0.35);
260 pieSeries->setPiePosition(0.2, 0.35);
259 chartView->addSeries(pieSeries);
261 m_chart->addSeries(pieSeries);
260
262
261 // pie 2
263 // pie 2
262 pieSeries = new QPieSeries;
264 pieSeries = new QPieSeries;
@@ -265,7 +267,7 void TableWidget::updateChartType()
265 pieSeries->setLabelsVisible(true);
267 pieSeries->setLabelsVisible(true);
266 pieSeries->setPieSize(0.4);
268 pieSeries->setPieSize(0.4);
267 pieSeries->setPiePosition(0.8, 0.35);
269 pieSeries->setPiePosition(0.8, 0.35);
268 chartView->addSeries(pieSeries);
270 m_chart->addSeries(pieSeries);
269
271
270 // pie 3
272 // pie 3
271 pieSeries = new QPieSeries;
273 pieSeries = new QPieSeries;
@@ -274,9 +276,9 void TableWidget::updateChartType()
274 pieSeries->setLabelsVisible(true);
276 pieSeries->setLabelsVisible(true);
275 pieSeries->setPieSize(0.4);
277 pieSeries->setPieSize(0.4);
276 pieSeries->setPiePosition(0.5, 0.65);
278 pieSeries->setPiePosition(0.5, 0.65);
277 chartView->addSeries(pieSeries);
279 m_chart->addSeries(pieSeries);
278 }
280 }
279 else if (areaRadioButton->isChecked())
281 else if (m_areaRadioButton->isChecked())
280 {
282 {
281 QLineSeries* upperLineSeries = new QLineSeries;
283 QLineSeries* upperLineSeries = new QLineSeries;
282 upperLineSeries->setModel(m_model);
284 upperLineSeries->setModel(m_model);
@@ -285,15 +287,15 void TableWidget::updateChartType()
285 lowerLineSeries->setModel(m_model);
287 lowerLineSeries->setModel(m_model);
286 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
288 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
287 QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
289 QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
288 chartView->addSeries(areaSeries);
290 m_chart->addSeries(areaSeries);
289 }
291 }
290 else if (barRadioButton->isChecked())
292 else if (m_barRadioButton->isChecked())
291 {
293 {
292 QBarSeries* barSeries = new QBarSeries(QStringList());
294 QBarSeries* barSeries = new QBarSeries(QStringList());
293 barSeries->setModel(m_model);
295 barSeries->setModel(m_model);
294 barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
296 barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
295 barSeries->setToolTipEnabled(true);
297 barSeries->setToolTipEnabled(true);
296 chartView->addSeries(barSeries);
298 m_chart->addSeries(barSeries);
297 }
299 }
298
300
299 // series->setModel(m_model);
301 // series->setModel(m_model);
@@ -49,17 +49,18 public:
49 void updateChartType();
49 void updateChartType();
50
50
51 private:
51 private:
52 QChartView* chartView;
52 QChartView* m_chartView;
53 QXYSeries* series;
53 QChart* m_chart;
54 QXYSeries* m_series;
54 CustomTableModel* m_model;
55 CustomTableModel* m_model;
55 QTableView* tableView;
56 QTableView* m_tableView;
56 QRadioButton* lineRadioButton;
57 QRadioButton* m_lineRadioButton;
57 QRadioButton* splineRadioButton;
58 QRadioButton* m_splineRadioButton;
58 QRadioButton* scatterRadioButton;
59 QRadioButton* m_scatterRadioButton;
59 QRadioButton* pieRadioButton;
60 QRadioButton* m_pieRadioButton;
60 QRadioButton* areaRadioButton;
61 QRadioButton* m_areaRadioButton;
61 QRadioButton* barRadioButton;
62 QRadioButton* m_barRadioButton;
62 QSpinBox* linesCountSpinBox;
63 QSpinBox* m_linesCountSpinBox;
63 };
64 };
64
65
65 #endif // TABLEWIDGET_H
66 #endif // TABLEWIDGET_H
@@ -345,10 +345,10 void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end)
345 // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem
345 // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem
346 // internal storage before new ones can be added
346 // internal storage before new ones can be added
347
347
348 int itemsToRemove = qMin(count() - (start - m_mapFirst), end - start + 1);
348 int itemsToRemove = qMin(count() - qMax(start - m_mapFirst, 0), end - start + 1);
349 if (m_mapCount == count()) {
349 if (m_mapCount == count()) {
350 for (int i = 0; i < itemsToRemove; i++)
350 for (int i = 0; i < itemsToRemove; i++)
351 emit pointRemoved(count() - 1 - i);
351 emit pointRemoved(qMin(end, count()) - i);
352 }
352 }
353 }
353 }
354 } else {
354 } else {
@@ -372,14 +372,16 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
372 // the added data is in the mapped area or before it
372 // the added data is in the mapped area or before it
373 // update needed
373 // update needed
374 if (count() > 0) {
374 if (count() > 0) {
375 for (int i = 0; i < qMin(m_mapCount - (start - m_mapFirst), end - start + 1); i++)
375 int toBeAdded = qMin(m_mapCount - (start - m_mapFirst), end - start + 1);
376 emit pointAdded(qMax(start + i - m_mapFirst, 0));
376 for (int i = 0; i < toBeAdded; i++)
377 if (start + i >= m_mapFirst)
378 emit pointAdded(start + i);
377 }
379 }
378 }
380 }
379 } else {
381 } else {
380 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
382 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
381 for (int i = 0; i < end - start + 1; i++)
383 for (int i = 0; i < end - start + 1; i++)
382 emit pointAdded(qMax(start + i - m_mapFirst, 0));
384 emit pointAdded(start + i);
383 }
385 }
384 }
386 }
385
387
@@ -403,12 +405,12 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end
403 // the max is the current number of items in storage (count())
405 // the max is the current number of items in storage (count())
404 int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
406 int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
405 for (int i = 0; i < itemsToRemove; i++)
407 for (int i = 0; i < itemsToRemove; i++)
406 emit pointRemoved(qMax(start - m_mapFirst, 0));
408 emit pointRemoved(start);
407 }
409 }
408 } else {
410 } else {
409 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
411 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
410 for (int i = 0; i < end - start + 1; i++)
412 for (int i = 0; i < end - start + 1; i++)
411 emit pointRemoved(qMax(start - m_mapFirst, 0));
413 emit pointRemoved(start);
412 }
414 }
413 }
415 }
414
416
@@ -428,18 +430,22 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
428 } else {
430 } else {
429 // if the current items count in the whole model is bigger than the index of the last item
431 // if the current items count in the whole model is bigger than the index of the last item
430 // that was removed than it means there are some extra items available
432 // that was removed than it means there are some extra items available
433
434 int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
431 int extraItemsAvailable = 0;
435 int extraItemsAvailable = 0;
432 if (m_mapOrientation == Qt::Vertical) {
436 if (m_mapOrientation == Qt::Vertical) {
433 extraItemsAvailable = qMax(m_model->rowCount() - end, 0);
437 // int temp1 = m_model->rowCount();
438 // int temp2 = (end - start + 1);
439 // int temp3 = qMax(end + 1, m_mapFirst + m_mapCount);
440 extraItemsAvailable = qMax(m_model->rowCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0);
434 } else {
441 } else {
435 extraItemsAvailable = qMax(m_model->columnCount() - end, 0);
442 extraItemsAvailable = qMax(m_model->columnCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0);
436 }
443 }
437
444
438 // if there are excess items available (below the mapped area) use them to repopulate mapped area
445 // if there are excess items available (below the mapped area) use them to repopulate mapped area
439 int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - qMax(start, m_mapFirst) + 1);
440 int toBeAdded = qMin(extraItemsAvailable, removedItemsCount);
446 int toBeAdded = qMin(extraItemsAvailable, removedItemsCount);
441 for (int k = 0; k < toBeAdded; k++)
447 for (int k = 0; k < toBeAdded; k++)
442 emit pointAdded(qMax(start - m_mapFirst, m_mapFirst) + k);
448 emit pointAdded(m_mapFirst + m_mapCount - removedItemsCount + k);
443 }
449 }
444 } else {
450 } else {
445 // data was removed from XYSeries interal storage. Nothing more to do
451 // data was removed from XYSeries interal storage. Nothing more to do
@@ -64,6 +64,7 public:
64
64
65 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
65 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
66 virtual void setModelMappingShift(int first, int count = 0);
66 virtual void setModelMappingShift(int first, int count = 0);
67 int mapFirst() const { return m_mapFirst; }
67
68
68 private Q_SLOTS:
69 private Q_SLOTS:
69 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
70 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
@@ -105,21 +105,40 void XYChartItem::setLayout(QVector<QPointF> &points)
105
105
106 void XYChartItem::handlePointAdded(int index)
106 void XYChartItem::handlePointAdded(int index)
107 {
107 {
108 QVector<QPointF> points = m_points;
109 QPointF point;
110 if (m_series->model()) {
111 point = calculateGeometryPoint(index - m_series->mapFirst());
112 points.insert(index - m_series->mapFirst(), point);
113 updateLayout(m_points, points, index - m_series->mapFirst());
114 }
115 else {
116 // this checks do not work correctly if model is set
108 Q_ASSERT(index<m_series->count());
117 Q_ASSERT(index<m_series->count());
109 Q_ASSERT(index>=0);
118 Q_ASSERT(index>=0);
110 QPointF point = calculateGeometryPoint(index);
119 point = calculateGeometryPoint(index);
111 QVector<QPointF> points = m_points;
112 points.insert(index,point);
120 points.insert(index, point);
113 updateLayout(m_points,points,index);
121 updateLayout(m_points, points, index);
122 }
114 update();
123 update();
115 }
124 }
116 void XYChartItem::handlePointRemoved(int index)
125 void XYChartItem::handlePointRemoved(int index)
117 {
126 {
127 QVector<QPointF> points = m_points;
128 if (m_series->model()) {
129 if (index < m_series->mapFirst())
130 points.remove(0);
131 else
132 points.remove(index - m_series->mapFirst());
133 updateLayout(m_points, points, index - m_series->mapFirst());
134 }
135 else {
136 // this checks do not work correctly if model is set
118 Q_ASSERT(index<m_series->count() + 1);
137 Q_ASSERT(index<m_series->count() + 1);
119 Q_ASSERT(index>=0);
138 Q_ASSERT(index>=0);
120 QVector<QPointF> points = m_points;
121 points.remove(index);
139 points.remove(index);
122 updateLayout(m_points,points,index);
140 updateLayout(m_points, points, index);
141 }
123 update();
142 update();
124 }
143 }
125
144
General Comments 0
You need to be logged in to leave comments. Login now