##// END OF EJS Templates
Small updates to tablemodelchart example
Marek Rosa -
r861:08ca4cc23d24
parent child
Show More
@@ -267,7 +267,7 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & pare
267
267
268 void CustomTableModel::addMapping(QString color, QRect area)
268 void CustomTableModel::addMapping(QString color, QRect area)
269 {
269 {
270 m_mapping.insert(color, area);
270 m_mapping.insertMulti(color, area);
271 }
271 }
272
272
273 void CustomTableModel::addMapping(QString color, int left, int top, int right, int bottom)
273 void CustomTableModel::addMapping(QString color, int left, int top, int right, int bottom)
@@ -46,7 +46,7 TableWidget::TableWidget(QWidget *parent)
46 m_model = new CustomTableModel;
46 m_model = new CustomTableModel;
47 m_tableView = new QTableView;
47 m_tableView = new QTableView;
48 m_tableView->setModel(m_model);
48 m_tableView->setModel(m_model);
49 m_tableView->setMinimumHeight(240);
49 m_tableView->setMinimumHeight(300);
50 // tableView->setMinimumSize(340, 480);
50 // tableView->setMinimumSize(340, 480);
51 // tableView->setItemDelegate(new QStyledItemDelegate);
51 // tableView->setItemDelegate(new QStyledItemDelegate);
52 m_chart = new QChart;
52 m_chart = new QChart;
@@ -140,10 +140,6 void TableWidget::updateChartType()
140
140
141 if (m_lineRadioButton->isChecked())
141 if (m_lineRadioButton->isChecked())
142 {
142 {
143
144 m_chart->axisX()->setRange(0, 500);
145 m_chart->axisY()->setRange(0, 120);
146
147 // series 1
143 // series 1
148 m_series = new QLineSeries;
144 m_series = new QLineSeries;
149 m_series->setModel(m_model);
145 m_series->setModel(m_model);
@@ -276,11 +272,15 void TableWidget::updateChartType()
276 QLineSeries* upperLineSeries = new QLineSeries;
272 QLineSeries* upperLineSeries = new QLineSeries;
277 upperLineSeries->setModel(m_model);
273 upperLineSeries->setModel(m_model);
278 upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
274 upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
275 upperLineSeries->setModelMappingShift(1, 5);
279 QLineSeries* lowerLineSeries = new QLineSeries;
276 QLineSeries* lowerLineSeries = new QLineSeries;
280 lowerLineSeries->setModel(m_model);
277 lowerLineSeries->setModel(m_model);
281 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
278 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
282 QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
279 QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
283 m_chart->addSeries(areaSeries);
280 m_chart->addSeries(areaSeries);
281 seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
282 m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
283 m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
284 }
284 }
285 else if (m_barRadioButton->isChecked())
285 else if (m_barRadioButton->isChecked())
286 {
286 {
@@ -295,6 +295,10 void TableWidget::updateChartType()
295 }
295 }
296 }
296 }
297
297
298
299 m_chart->axisX()->setRange(0, 500);
300 m_chart->axisY()->setRange(0, 120);
301
298 // repaint table view colors
302 // repaint table view colors
299 m_tableView->repaint();
303 m_tableView->repaint();
300 m_tableView->setFocus();
304 m_tableView->setFocus();
@@ -434,9 +434,6 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
434 int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
434 int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
435 int extraItemsAvailable = 0;
435 int extraItemsAvailable = 0;
436 if (m_mapOrientation == Qt::Vertical) {
436 if (m_mapOrientation == Qt::Vertical) {
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);
437 extraItemsAvailable = qMax(m_model->rowCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0);
441 } else {
438 } else {
442 extraItemsAvailable = qMax(m_model->columnCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0);
439 extraItemsAvailable = qMax(m_model->columnCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0);
@@ -484,14 +481,12 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientat
484 m_mapFirst = 0;
481 m_mapFirst = 0;
485 m_mapOrientation = orientation;
482 m_mapOrientation = orientation;
486 if (m_mapOrientation == Qt::Vertical) {
483 if (m_mapOrientation == Qt::Vertical) {
487 // m_mapCount = m_model->rowCount();
488 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
484 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
489 connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
485 connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
490 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
486 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
491 connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
487 connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
492 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
488 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
493 } else {
489 } else {
494 // m_mapCount = m_model->columnCount();
495 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
490 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)));
491 connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
497 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
492 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
General Comments 0
You need to be logged in to leave comments. Login now