QAbstractTableModel Q
-
void wSpectrum::InitTableWidget() { QList<QPair<QString, QList<qreal>>> lstTemp; QPair<QString, QList<qreal>> pairTemp; pairTemp.first = "WaveLength"; pairTemp.second = m_pSpectrumInfo->GetWaves(); lstTemp.append(pairTemp); QPair<QString, QList<qreal>> pairTemp1; pairTemp1.first = "Data"; pairTemp1.second.append(2.123); pairTemp1.second.append(1.9052); pairTemp1.second.append(2.0935); pairTemp1.second.append(5.29804); pairTemp1.second.append(4.712890); pairTemp1.second.append(3.132087); lstTemp.append(pairTemp1); m_pModel = new usrTableModel(lstTemp); this->ui.tableWidget->setModel(m_pModel); auto xAixs = std::minmax_element(lstTemp[0].second.begin(), lstTemp[0].second.end()); m_pChart->axisX()->setRange(*xAixs.first, *xAixs.second); xAixs = std::minmax_element(lstTemp[1].second.begin(), lstTemp[1].second.end()); m_pChart->axisY()->setRange(*xAixs.first, *xAixs.second); QValueAxis* axisx = qobject_cast<QValueAxis*>(m_pChart->axes(Qt::Horizontal).first()); axisx->setTickCount(m_pSpectrumInfo->GetWaves().count()); QLineSeries* pSeries = new QLineSeries(m_pChart); QVXYModelMapper* mapper = new QVXYModelMapper(this); mapper->setXColumn(0); mapper->setYColumn(1); mapper->setSeries(pSeries); mapper->setModel(m_pModel); m_pChart->addSeries(pSeries); //AddChartSeries(); // [테스트] QPair<QString, QList<qreal>> pairTemp2; pairTemp2.first = "Data"; pairTemp2.second.append(1.123); pairTemp2.second.append(2.2052); pairTemp2.second.append(3.3935); pairTemp2.second.append(4.49804); pairTemp2.second.append(5.512890); pairTemp2.second.append(6.6132087); m_pModel->AppendData(pairTemp2); QLineSeries* pSeries1 = new QLineSeries(m_pChart); QVXYModelMapper* mapper1 = new QVXYModelMapper(this); mapper1->setXColumn(2); mapper1->setYColumn(3); mapper1->setSeries(pSeries1); mapper1->setModel(m_pModel); m_pChart->addSeries(pSeries1); //AddChartSeries(); }
The line series of the first data is drawn normally. The second data line is not drawn.
When the model changes, the chart must also be updated.
I wonder how. -
void wSpectrum::InitTableWidget() { QList<QPair<QString, QList<qreal>>> lstTemp; QPair<QString, QList<qreal>> pairTemp; pairTemp.first = "WaveLength"; pairTemp.second = m_pSpectrumInfo->GetWaves(); lstTemp.append(pairTemp); QPair<QString, QList<qreal>> pairTemp1; pairTemp1.first = "Data"; pairTemp1.second.append(2.123); pairTemp1.second.append(1.9052); pairTemp1.second.append(2.0935); pairTemp1.second.append(5.29804); pairTemp1.second.append(4.712890); pairTemp1.second.append(3.132087); lstTemp.append(pairTemp1); m_pModel = new usrTableModel(lstTemp); this->ui.tableWidget->setModel(m_pModel); auto xAixs = std::minmax_element(lstTemp[0].second.begin(), lstTemp[0].second.end()); m_pChart->axisX()->setRange(*xAixs.first, *xAixs.second); xAixs = std::minmax_element(lstTemp[1].second.begin(), lstTemp[1].second.end()); m_pChart->axisY()->setRange(*xAixs.first, *xAixs.second); QValueAxis* axisx = qobject_cast<QValueAxis*>(m_pChart->axes(Qt::Horizontal).first()); axisx->setTickCount(m_pSpectrumInfo->GetWaves().count()); QLineSeries* pSeries = new QLineSeries(m_pChart); QVXYModelMapper* mapper = new QVXYModelMapper(this); mapper->setXColumn(0); mapper->setYColumn(1); mapper->setSeries(pSeries); mapper->setModel(m_pModel); m_pChart->addSeries(pSeries); //AddChartSeries(); // [테스트] QPair<QString, QList<qreal>> pairTemp2; pairTemp2.first = "Data"; pairTemp2.second.append(1.123); pairTemp2.second.append(2.2052); pairTemp2.second.append(3.3935); pairTemp2.second.append(4.49804); pairTemp2.second.append(5.512890); pairTemp2.second.append(6.6132087); m_pModel->AppendData(pairTemp2); QLineSeries* pSeries1 = new QLineSeries(m_pChart); QVXYModelMapper* mapper1 = new QVXYModelMapper(this); mapper1->setXColumn(2); mapper1->setYColumn(3); mapper1->setSeries(pSeries1); mapper1->setModel(m_pModel); m_pChart->addSeries(pSeries1); //AddChartSeries(); }
The line series of the first data is drawn normally. The second data line is not drawn.
When the model changes, the chart must also be updated.
I wonder how.@IknowQT said in QAbstractTableModel Q:
void wSpectrum::InitTableWidget() { QList<QPair<QString, QList<qreal>>> lstTemp; QPair<QString, QList<qreal>> pairTemp; pairTemp.first = "WaveLength"; pairTemp.second = m_pSpectrumInfo->GetWaves(); lstTemp.append(pairTemp); QPair<QString, QList<qreal>> pairTemp1; pairTemp1.first = "Data"; pairTemp1.second.append(2.123); pairTemp1.second.append(1.9052); pairTemp1.second.append(2.0935); pairTemp1.second.append(5.29804); pairTemp1.second.append(4.712890); pairTemp1.second.append(3.132087); lstTemp.append(pairTemp1); m_pModel = new usrTableModel(lstTemp); this->ui.tableWidget->setModel(m_pModel); auto xAixs = std::minmax_element(lstTemp[0].second.begin(), lstTemp[0].second.end()); m_pChart->axisX()->setRange(*xAixs.first, *xAixs.second); xAixs = std::minmax_element(lstTemp[1].second.begin(), lstTemp[1].second.end()); m_pChart->axisY()->setRange(*xAixs.first, *xAixs.second); QValueAxis* axisx = qobject_cast<QValueAxis*>(m_pChart->axes(Qt::Horizontal).first()); axisx->setTickCount(m_pSpectrumInfo->GetWaves().count()); QLineSeries* pSeries = new QLineSeries(m_pChart); QVXYModelMapper* mapper = new QVXYModelMapper(this); mapper->setXColumn(0); mapper->setYColumn(1); mapper->setSeries(pSeries); mapper->setModel(m_pModel); m_pChart->addSeries(pSeries); //AddChartSeries(); // [테스트] QPair<QString, QList<qreal>> pairTemp2; pairTemp2.first = "Data"; pairTemp2.second.append(1.123); pairTemp2.second.append(2.2052); pairTemp2.second.append(3.3935); pairTemp2.second.append(4.49804); pairTemp2.second.append(5.512890); pairTemp2.second.append(6.6132087); m_pModel->AppendData(pairTemp2); QLineSeries* pSeries1 = new QLineSeries(m_pChart); QVXYModelMapper* mapper1 = new QVXYModelMapper(this); mapper1->setXColumn(2); mapper1->setYColumn(3); mapper1->setSeries(pSeries1); mapper1->setModel(m_pModel); m_pChart->addSeries(pSeries1); //AddChartSeries(); }
The line series of the first data is drawn normally. The second data line is not drawn.
When the model changes, the chart must also be updated.
I wonder how.===================================================================
QLineSeries* pSeries = new QLineSeries(m_pChart); QVXYModelMapper* mapper = new QVXYModelMapper(this); mapper->setXColumn(0); mapper->setYColumn(1); mapper->setSeries(pSeries); mapper->setModel(m_pModel); m_pChart->addSeries(pSeries); //AddChartSeries(); // [테스트] QPair<QString, QList<qreal>> pairTemp2; pairTemp2.first = "Data"; pairTemp2.second.append(1.123); pairTemp2.second.append(7.2052); pairTemp2.second.append(4.3935); pairTemp2.second.append(3.49804); pairTemp2.second.append(1.512890); pairTemp2.second.append(2.6132087); m_pModel->AppendData(pairTemp2); QLineSeries* pSeries1 = new QLineSeries(m_pChart); QVXYModelMapper* mapper1 = new QVXYModelMapper(this); mapper1->setXColumn(0); mapper1->setYColumn(2); mapper1->setSeries(pSeries1); mapper1->setModel(m_pModel); m_pChart->addSeries(pSeries1);I set the Column of the first series mapper to 0, 1.
I set the Column of the second series mapper to 0, 2.
Then it prints normally.
I didn't fully understand the function of setXColumn. What function does it specifically do? I've looked at the documentation, but I don't understand.