Skip to content

Commit

Permalink
split function
Browse files Browse the repository at this point in the history
  • Loading branch information
sunderme committed Jul 22, 2023
1 parent 668bb75 commit 9434f09
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
58 changes: 30 additions & 28 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,36 +790,9 @@ void MainWindow::plotSelected()
bool multiPlot=m_plotValues.size()>1;
chartView->clear();
for(const QString &yn:m_plotValues){
int index_y=getIndex(yn);
if(index_y<0) continue;

QList<LoopIteration> lits=groupBy(vars,m_visibleRows);
foreach(LoopIteration lit,lits){
QLineSeries *series = new QLineSeries();
if(!lit.value.isEmpty()){
QString name=lit.value.left(lit.value.size()-1);
if(multiPlot)
name=yn+":"+name;
series->setName(name);
}else{
series->setName(yn);
}
for(std::size_t i=0;i<lit.indices.size();++i){
if(lit.indices[i]){
bool ok_x,ok_y;
qreal x=m_csv[index_x].value(i).toDouble(&ok_x);
qreal y=m_csv[index_y].value(i).toDouble(&ok_y);
if(ok_x && ok_y){
QPointF pt(x,y);
series->append(pt);
}
}
}
chartView->addSeries(series);
}
addSeriesToChart(index_x,vars,yn,multiPlot);
}


chartView->setTitle("Line chart");
if(tabWidget->currentIndex()!=1){
tabWidget->setCurrentIndex(1); // plot tab
Expand All @@ -833,6 +806,35 @@ void MainWindow::plotSelected()
}
chartView->updateMarker();
}

void MainWindow::addSeriesToChart(const int index_x,const QStringList &vars,const QString &yn,bool multiPlot){
int index_y=getIndex(yn);
if(index_y<0) return;
QList<LoopIteration> lits=groupBy(vars,m_visibleRows);
foreach(LoopIteration lit,lits){
QLineSeries *series = new QLineSeries();
if(!lit.value.isEmpty()){
QString name=lit.value.left(lit.value.size()-1);
if(multiPlot)
name=yn+":"+name;
series->setName(name);
}else{
series->setName(yn);
}
for(std::size_t i=0;i<lit.indices.size();++i){
if(lit.indices[i]){
bool ok_x,ok_y;
qreal x=m_csv[index_x].value(i).toDouble(&ok_x);
qreal y=m_csv[index_y].value(i).toDouble(&ok_y);
if(ok_x && ok_y){
QPointF pt(x,y);
series->append(pt);
}
}
}
chartView->addSeries(series);
}
}
/*!
* \brief plot if changed to plot tab
* \param index
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MainWindow : public QMainWindow
void updateSweepGUI();
void updateSweeps(bool filterChecked=true);
void plotSelected();
void addSeriesToChart(const int index_x, const QStringList &vars, const QString &yn, bool multiPlot);
void tabChanged(int index);
void headerMenuRequested(QPoint pt);
void addSweepVar();
Expand Down

0 comments on commit 9434f09

Please sign in to comment.