diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -331,10 +331,9 @@ void MainWindow::onChannelNameChanged(un // This slot is triggered also when a new channel is added, in // this case curve list doesn't contain said channel. No worries, // since `onNumOfChannelsChanged` slot will update curve list. - if ((int) channel < curves.size()) // check if channel exists in curve list + if (channel < plotMan->numOfCurves()) // check if channel exists in curve list { - curves[channel]->setTitle(name); - ui->plot->replot(); + plotMan->setTitle(channel, name); } } diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -185,3 +185,22 @@ unsigned PlotManager::numOfCurves() { return curves.size(); } + +void PlotManager::setTitle(unsigned index, QString title) +{ + curves[index]->setTitle(title); + + plotWidget(index)->replot(); +} + +Plot* PlotManager::plotWidget(unsigned curveIndex) +{ + if (isMulti) + { + return plotWidgets[curveIndex]; + } + else + { + return plotWidgets[0]; + } +} diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -67,6 +67,8 @@ private: void setupLayout(bool multiPlot); Plot* addPlotWidget(); ///< inserts a new plot widget to the current layout + /// Returns the plot widget that given curve is attached to + Plot* plotWidget(unsigned curveIndex); }; #endif // PLOTMANAGER_H