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