@@ -182,6 +182,13 @@ void NeTrainSim::setupGenerals(){
182182 this ->replotHistoryLinks ();
183183 });
184184
185+ // Replot when switching tabs so that plots on previously hidden
186+ // tabs receive their data once visible and laid out.
187+ connect (ui->tabWidget_project , &QTabWidget::currentChanged, [this ]() {
188+ this ->replotHistoryNodes ();
189+ this ->replotHistoryLinks ();
190+ });
191+
185192 // show error if tables has only 1 row
186193 connect (ui->table_newNodes , &CustomTableWidget::cannotDeleteRow,
187194 [this ]() {
@@ -287,9 +294,12 @@ void NeTrainSim::setupPage1(){
287294 // add graphs to the plot
288295 ui->plot_createNetwork ->addGraph ();
289296 ui->plot_createNetwork ->addGraph ();
290- // disable viewing the axies
297+ // disable viewing the axes and remove auto margins so the axis rect
298+ // always has positive inner dimensions (even on hidden tabs)
291299 ui->plot_createNetwork ->xAxis ->setVisible (false );
292300 ui->plot_createNetwork ->yAxis ->setVisible (false );
301+ ui->plot_createNetwork ->axisRect ()->setAutoMargins (QCP ::msNone);
302+ ui->plot_createNetwork ->axisRect ()->setMargins (QMargins (5 , 5 , 5 , 5 ));
293303
294304
295305 // get the nodes file
@@ -545,9 +555,12 @@ void NeTrainSim::forceReplotLinks() {
545555
546556
547557void NeTrainSim::setupPage2 (){
548- // disable viewing the axies
558+ // disable viewing the axes and remove auto margins so the axis rect
559+ // always has positive inner dimensions (even on hidden tabs)
549560 ui->plot_trains ->xAxis ->setVisible (false );
550561 ui->plot_trains ->yAxis ->setVisible (false );
562+ ui->plot_trains ->axisRect ()->setAutoMargins (QCP ::msNone);
563+ ui->plot_trains ->axisRect ()->setMargins (QMargins (5 , 5 , 5 , 5 ));
551564
552565 // show the layout as a default
553566 ui->widget_oldTrainOD ->show ();
@@ -759,9 +772,12 @@ void NeTrainSim::setupPage3(){
759772 simulatorWidgetSizes << 229 << 700 ;
760773 ui->splitter_simulator ->setSizes (simulatorWidgetSizes);
761774
762- // disable viewing the axies
775+ // disable viewing the axes and remove auto margins so the axis rect
776+ // always has positive inner dimensions (even on hidden tabs)
763777 ui->plot_simulation ->xAxis ->setVisible (false );
764778 ui->plot_simulation ->yAxis ->setVisible (false );
779+ ui->plot_simulation ->axisRect ()->setAutoMargins (QCP ::msNone);
780+ ui->plot_simulation ->axisRect ()->setMargins (QMargins (5 , 5 , 5 , 5 ));
765781
766782 // add graphs to the plot
767783 auto nodegraph = ui->plot_simulation ->addGraph ();
@@ -1514,7 +1530,6 @@ void NeTrainSim::updateNodesPlot(CustomPlot &plot, QVector<double>xData,
15141530
15151531 // clear the graph data
15161532 graph->data ()->clear ();
1517- plot.replot ();
15181533
15191534 if (xData.size () < 1 ) { return ; }
15201535 if (xData.size () != yData.size ()) {
@@ -1576,7 +1591,6 @@ void NeTrainSim::updateNodesPlot(CustomPlot &plot, QVector<double>xData,
15761591 }
15771592
15781593 plot.resetZoom ();
1579- // plot.replot();
15801594};
15811595
15821596/* *
@@ -1764,11 +1778,11 @@ void NeTrainSim::updateLinksPlot(CustomPlot &plot,
17641778 QVector<QString> endNodeIDs) {
17651779 // check if the plot has at least 2 graphs
17661780 if (plot.graphCount () < 2 ) { return ; }
1781+
17671782 // get the QCPGraph object for the graph in the QCustomPlot
17681783 QCPGraph *graph = plot.graph (1 );
17691784
17701785 graph->data ()->clear ();
1771- plot.replot ();
17721786
17731787 if (startNodeIDs.size () != endNodeIDs.size () ||
17741788 startNodeIDs.size () < 1 || this ->networkNodes .size () < 1 ) {
@@ -1798,8 +1812,8 @@ void NeTrainSim::updateLinksPlot(CustomPlot &plot,
17981812 }
17991813 // set the pen style for the lines
18001814 graph->setPen (QPen (Qt::blue, 2 ));
1815+
18011816 plot.resetZoom ();
1802- // plot.replot();
18031817};
18041818
18051819/* *
0 commit comments