##// END OF EJS Templates
Fixed problem with qhxymodelmapper
Marek Rosa -
r1317:1951d151d7af
parent child
Show More
@@ -255,15 +255,23 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottom
255 255 index = topLeft.sibling(row, column);
256 256 if (m_orientation == Qt::Vertical && (index.column() == m_xSection|| index.column() == m_ySection)) {
257 257 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
258 QModelIndex xIndex = xModelIndex(index.row() - m_first);
259 QModelIndex yIndex = yModelIndex(index.row() - m_first);
260 if (xIndex.isValid() && yIndex.isValid()) {
258 261 oldPoint = m_series->points().at(index.row() - m_first);
259 newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal());
260 newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal());
262 newPoint.setX(m_model->data(xIndex).toReal());
263 newPoint.setY(m_model->data(yIndex).toReal());
264 }
261 265 }
262 266 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
263 267 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
268 QModelIndex xIndex = xModelIndex(index.column() - m_first);
269 QModelIndex yIndex = yModelIndex(index.column() - m_first);
270 if (xIndex.isValid() && yIndex.isValid()) {
264 271 oldPoint = m_series->points().at(index.column() - m_first);
265 newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal());
266 newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal());
272 newPoint.setX(m_model->data(xIndex).toReal());
273 newPoint.setY(m_model->data(yIndex).toReal());
274 }
267 275 }
268 276 } else {
269 277 continue;
@@ -345,10 +353,14 void QXYModelMapperPrivate::insertData(int start, int end)
345 353 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
346 354 for (int i = first; i <= last; i++) {
347 355 QPointF point;
348 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
349 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
356 QModelIndex xIndex = xModelIndex(i - m_first);
357 QModelIndex yIndex = yModelIndex(i - m_first);
358 if (xIndex.isValid() && yIndex.isValid()) {
359 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
360 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
350 361 m_series->insert(i - m_first, point);
351 362 }
363 }
352 364
353 365 // remove excess of slices (abouve m_count)
354 366 if (m_count != -1 && m_series->points().size() > m_count)
@@ -385,13 +397,17 void QXYModelMapperPrivate::removeData(int start, int end)
385 397 if (toBeAdded > 0)
386 398 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
387 399 QPointF point;
388 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
389 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
400 QModelIndex xIndex = xModelIndex(i);
401 QModelIndex yIndex = yModelIndex(i);
402 if (xIndex.isValid() && yIndex.isValid()) {
403 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
404 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
390 405 m_series->insert(i, point);
391 406 }
392 407 }
393 408 }
394 409 }
410 }
395 411
396 412 void QXYModelMapperPrivate::initializeXYFromModel()
397 413 {
@@ -30,7 +30,7 CustomTableModel::CustomTableModel(QObject *parent) :
30 30 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
31 31
32 32 m_columnCount = 7;
33 m_rowCount = 9;
33 m_rowCount = 1029;
34 34
35 35 m_labels.append("Apples");
36 36 m_labels.append("Oranges");
@@ -67,7 +67,7 int CustomTableModel::rowCount(const QModelIndex & parent) const
67 67 int CustomTableModel::columnCount(const QModelIndex & parent) const
68 68 {
69 69 Q_UNUSED(parent)
70 return m_columnCount + 1;
70 return m_columnCount;// + 1;
71 71 }
72 72
73 73 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
@@ -102,8 +102,8 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
102 102 {
103 103 switch(index.column())
104 104 {
105 case 7:
106 return m_labels[index.row()];
105 // case 7:
106 // return m_labels[index.row()];
107 107 default:
108 108 return m_data[index.row()]->at(index.column());
109 109 break;
@@ -113,8 +113,8 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
113 113 {
114 114 switch(index.column())
115 115 {
116 case 7:
117 return m_labels[index.row()];
116 // case 7:
117 // return m_labels[index.row()];
118 118 default:
119 119 return m_data[index.row()]->at(index.column());
120 120 break;
@@ -236,27 +236,27 void TableWidget::updateChartType(bool toggle)
236 236
237 237 if (m_lineRadioButton->isChecked())
238 238 {
239 m_chart->setAnimationOptions(QChart::NoAnimation);
239 // m_chart->setAnimationOptions(QChart::NoAnimation);
240 240
241 241 // series 1
242 242 m_series = new QLineSeries;
243 243
244 m_mapper = new QHXYModelMapper;
245 m_mapper->setModel(m_model);
246 m_mapper->setSeries(m_series);
247 m_mapper->setXRow(0);
248 m_mapper->setYRow(1);
249 m_mapper->setFirst(3);
250 m_mapper->setCount(4);
251
252 // m_mapper = new QVXYModelMapper;
244 // m_mapper = new QHXYModelMapper;
253 245 // m_mapper->setModel(m_model);
254 246 // m_mapper->setSeries(m_series);
255 // m_mapper->setXColumn(0);
256 // m_mapper->setYColumn(1);
247 // m_mapper->setXRow(0);
248 // m_mapper->setYRow(1);
257 249 // m_mapper->setFirst(3);
258 250 // m_mapper->setCount(4);
259 251
252 m_mapper = new QVXYModelMapper;
253 m_mapper->setModel(m_model);
254 m_mapper->setSeries(m_series);
255 m_mapper->setXColumn(0);
256 m_mapper->setYColumn(1);
257 m_mapper->setFirst(3);
258 // m_mapper->setCount(4);
259
260 260 // m_series->setModelMapping(0,1, Qt::Vertical);
261 261 // m_series->setModelMappingRange(3, 4);
262 262 m_chart->addSeries(m_series);
@@ -505,8 +505,8 void TableWidget::updateChartType(bool toggle)
505 505
506 506
507 507 if (!m_barRadioButton->isChecked()) {
508 m_chart->axisX()->setRange(0, 500);
509 m_chart->axisY()->setRange(0, 220);
508 // m_chart->axisX()->setRange(0, 500);
509 // m_chart->axisY()->setRange(0, 220);
510 510 }
511 511 m_chart->legend()->setVisible(true);
512 512
@@ -63,7 +63,7 public:
63 63 QChartView* m_chartView;
64 64 QChart* m_chart;
65 65 QXYSeries* m_series;
66 QHXYModelMapper *m_mapper;
66 QVXYModelMapper *m_mapper;
67 67 CustomTableModel* m_model;
68 68 QTableView* m_tableView;
69 69 QRadioButton* m_lineRadioButton;
General Comments 0
You need to be logged in to leave comments. Login now