Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAbstractTableModel Q

QAbstractTableModel Q

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 188 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
    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();	
    }
    

    d96cd23e-dca2-4b56-850b-4d1b1254ff22-image.png

    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.

    I 1 Reply Last reply
    0
    • I IknowQT
      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();	
      }
      

      d96cd23e-dca2-4b56-850b-4d1b1254ff22-image.png

      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.

      I Offline
      I Offline
      IknowQT
      wrote on last edited by
      #2

      @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();	
      }
      

      d96cd23e-dca2-4b56-850b-4d1b1254ff22-image.png

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved