diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ed61fb9..e42f963 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -270,6 +270,22 @@ void MainWindow::setupMenus() plotToolBar->addAction(act); connect(act,&QAction::triggered,this,&MainWindow::deleteVar); + m_plotTypeMenu=new QMenu(tr("plot type")); + m_plotTypeActionGroup=new QActionGroup(this); + m_plotTypeActionGroup->setExclusive(true); + act=new QAction(tr("line series"),this); + act->setCheckable(true); + act->setChecked(true); + connect(act,&QAction::triggered,this,&MainWindow::plotStyleChanged); + m_plotTypeMenu->addAction(act); + m_plotTypeActionGroup->addAction(act); + m_lineSeriesAveragedAct=new QAction(tr("line series averaged"),this); + m_lineSeriesAveragedAct->setCheckable(true); + connect(m_lineSeriesAveragedAct,&QAction::triggered,this,&MainWindow::plotStyleChanged); + m_plotTypeActionGroup->addAction(m_lineSeriesAveragedAct); + m_plotTypeMenu->addAction(m_lineSeriesAveragedAct); + m_plotMenu->addMenu(m_plotTypeMenu); + QAction *testAction=new QAction("test",this); connect(testAction, &QAction::triggered, this, &MainWindow::test); m_plotMenu->addAction(testAction); @@ -806,10 +822,35 @@ void MainWindow::plotSelected() } chartView->updateMarker(); } - +/*! + * \brief plot series + * if x values contain strings, use a bar instead of a line chart + * \param index_x + * \param vars + * \param yn + * \param multiPlot + */ void MainWindow::addSeriesToChart(const int index_x,const QStringList &vars,const QString &yn,bool multiPlot){ + bool discretePoints=false; //(m_columnType[index_x]!=COL_INT) && (m_columnType[index_x]!=COL_FLOAT); for now, detection not done generally + if(discretePoints){ + addBarSeriesToChart(index_x,vars,yn,multiPlot); + }else{ + addLineSeriesToChart(index_x,vars,yn,multiPlot); + } +} +/*! + * \brief add LineSeries To Chart + * Assume x is number + * \param index_x column of x (sweep) value + * \param vars group vars + * \param yn plot value + * \param multiPlot if multiple values will be plotted + */ +void MainWindow::addLineSeriesToChart(const int index_x, const QStringList &vars, const QString &yn, bool multiPlot) +{ int index_y=getIndex(yn); if(index_y<0) return; + bool averaging=m_lineSeriesAveragedAct->isChecked(); QList lits=groupBy(vars,m_visibleRows); foreach(LoopIteration lit,lits){ QLineSeries *series = new QLineSeries(); @@ -821,20 +862,64 @@ void MainWindow::addSeriesToChart(const int index_x,const QStringList &vars,cons }else{ series->setName(yn); } - for(std::size_t i=0;iappend(pt); - } - } + QList points=getPoints(index_x,index_y,lit); + if(averaging){ + points=averagePointSeries(points); } + series->append(points); chartView->addSeries(series); } } + +QList MainWindow::getPoints(const int index_x,const int index_y,const LoopIteration &lit) +{ + QList series; + for(std::size_t i=0;i MainWindow::averagePointSeries(const QList &points) +{ + QList avg; + int n=0; + QPointF resultingPoint; + for(const auto &pt:points){ + if(n==0){ + resultingPoint=pt; + ++n; + }else{ + if(pt.x()==resultingPoint.x()){ + resultingPoint.setY(resultingPoint.y()+pt.y()); + ++n; + }else{ + resultingPoint.setY(resultingPoint.y()/n); + avg<currentIndex()==1){ + plotSelected(); + } +} /*! * \brief operator << for debug QList * \param d @@ -2083,6 +2178,8 @@ QList MainWindow::groupBy(QStringList sweepVar,std::vector return result; } + + /* TODO avg plot histogram diff --git a/src/mainwindow.h b/src/mainwindow.h index e02cb0a..9a17088 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -52,6 +52,8 @@ class MainWindow : public QMainWindow void updateSweeps(bool filterChecked=true); void plotSelected(); void addSeriesToChart(const int index_x, const QStringList &vars, const QString &yn, bool multiPlot); + void addLineSeriesToChart(const int index_x, const QStringList &vars, const QString &yn, bool multiPlot); + void addBarSeriesToChart(const int index_x, const QStringList &vars, const QString &yn, bool multiPlot); void tabChanged(int index); void headerMenuRequested(QPoint pt); void addSweepVar(); @@ -92,6 +94,7 @@ class MainWindow : public QMainWindow void filterElementChanged(bool checked); bool parseQuery(const QString &text,const QString &data,const ColumnType col_type=COL_STRING); int determineOperator(const QString &text,QString &reference); + void plotStyleChanged(); void test(); void copyCell(); void copyHeader(); @@ -119,18 +122,24 @@ class MainWindow : public QMainWindow QString unquote(const QString &text) const; QList groupBy(QStringList sweepVar,std::vector providedIndices=std::vector() ); + QList getPoints(const int index_x,const int index_y,const LoopIteration &lit); + QList averagePointSeries(const QList &points); private: QMenu *m_fileMenu; QMenu *m_plotMenu; QMenu *m_editMenu; QMenu *m_recentFilesMenu,*m_recentTemplatesMenu; + QMenu *m_plotTypeMenu; QAction *m_openAct; QAction *m_reloadAct; QAction *m_exitAct; QAction *m_plotAct; QAction *m_logxAct,*m_logyAct; + QAction *m_lineSeriesAveragedAct; + + QActionGroup *m_plotTypeActionGroup; QTabWidget *tabWidget; QTableWidget *tableWidget;