diff --git a/examples/tablemodelchart/customtablemodel.cpp b/examples/tablemodelchart/customtablemodel.cpp index 91548f1..0b4077b 100644 --- a/examples/tablemodelchart/customtablemodel.cpp +++ b/examples/tablemodelchart/customtablemodel.cpp @@ -267,7 +267,7 @@ bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & pare void CustomTableModel::addMapping(QString color, QRect area) { - m_mapping.insert(color, area); + m_mapping.insertMulti(color, area); } void CustomTableModel::addMapping(QString color, int left, int top, int right, int bottom) diff --git a/examples/tablemodelchart/tablewidget.cpp b/examples/tablemodelchart/tablewidget.cpp index 13cee84..0e653b5 100644 --- a/examples/tablemodelchart/tablewidget.cpp +++ b/examples/tablemodelchart/tablewidget.cpp @@ -46,7 +46,7 @@ TableWidget::TableWidget(QWidget *parent) m_model = new CustomTableModel; m_tableView = new QTableView; m_tableView->setModel(m_model); - m_tableView->setMinimumHeight(240); + m_tableView->setMinimumHeight(300); // tableView->setMinimumSize(340, 480); // tableView->setItemDelegate(new QStyledItemDelegate); m_chart = new QChart; @@ -140,10 +140,6 @@ void TableWidget::updateChartType() if (m_lineRadioButton->isChecked()) { - - m_chart->axisX()->setRange(0, 500); - m_chart->axisY()->setRange(0, 120); - // series 1 m_series = new QLineSeries; m_series->setModel(m_model); @@ -276,11 +272,15 @@ void TableWidget::updateChartType() QLineSeries* upperLineSeries = new QLineSeries; upperLineSeries->setModel(m_model); upperLineSeries->setModelMapping(0, 1, Qt::Vertical); + upperLineSeries->setModelMappingShift(1, 5); QLineSeries* lowerLineSeries = new QLineSeries; lowerLineSeries->setModel(m_model); lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); m_chart->addSeries(areaSeries); + seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); + m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); + m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); } else if (m_barRadioButton->isChecked()) { @@ -295,6 +295,10 @@ void TableWidget::updateChartType() } } + + m_chart->axisX()->setRange(0, 500); + m_chart->axisY()->setRange(0, 120); + // repaint table view colors m_tableView->repaint(); m_tableView->setFocus(); diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index 548484b..19580bd 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -434,9 +434,6 @@ void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1); int extraItemsAvailable = 0; if (m_mapOrientation == Qt::Vertical) { -// int temp1 = m_model->rowCount(); -// int temp2 = (end - start + 1); -// int temp3 = qMax(end + 1, m_mapFirst + m_mapCount); extraItemsAvailable = qMax(m_model->rowCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0); } else { 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 m_mapFirst = 0; m_mapOrientation = orientation; if (m_mapOrientation == Qt::Vertical) { - // m_mapCount = m_model->rowCount(); connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); } else { - // m_mapCount = m_model->columnCount(); connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));