@@ -226,7 +226,7 @@ void PlotWidget::buildActions()
226
226
connect (_action_removeCurve, &QAction::triggered, this , &PlotWidget::launchRemoveCurveDialog);
227
227
228
228
_action_removeAllCurves = new QAction (" &Remove ALL curves" , this );
229
- connect (_action_removeAllCurves, &QAction::triggered, this , &PlotWidget::detachAllCurves );
229
+ connect (_action_removeAllCurves, &QAction::triggered, this , &PlotWidget::removeAllCurves );
230
230
connect (_action_removeAllCurves, &QAction::triggered, this , &PlotWidget::undoableChange);
231
231
232
232
_action_changeColorsDialog = new QAction (" &Change colors" , this );
@@ -722,7 +722,7 @@ void PlotWidget::dropEvent(QDropEvent*)
722
722
_dragging.curves .clear ();
723
723
}
724
724
725
- void PlotWidget::detachAllCurves ()
725
+ void PlotWidget::removeAllCurves ()
726
726
{
727
727
for (auto & it : _curve_list)
728
728
{
@@ -829,14 +829,20 @@ QDomElement PlotWidget::xmlSaveState(QDomDocument& doc) const
829
829
830
830
bool PlotWidget::xmlLoadState (QDomElement& plot_widget)
831
831
{
832
- std::set<std::string> added_curve_names;
833
-
834
832
QDomElement transform = plot_widget.firstChildElement (" transform" );
835
833
QString trans_value = transform.attribute (" value" );
836
834
837
835
if (trans_value == " XYPlot" )
838
836
{
839
- convertToXY ();
837
+ if ( !isXYPlot ()){
838
+ convertToXY ();
839
+ }
840
+ }
841
+ else {
842
+ if ( isXYPlot () ){
843
+ removeAllCurves ();
844
+ _xy_mode = false ;
845
+ }
840
846
}
841
847
842
848
QDomElement limitY_el = plot_widget.firstChildElement (" limitY" );
@@ -869,7 +875,34 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
869
875
870
876
bool curve_added = false ;
871
877
872
- for (QDomElement curve_element = plot_widget.firstChildElement (" curve" ); !curve_element.isNull ();
878
+ std::set<std::string> curves_to_add;
879
+ for (QDomElement curve_element = plot_widget.firstChildElement (" curve" );
880
+ !curve_element.isNull ();
881
+ curve_element = curve_element.nextSiblingElement (" curve" ))
882
+ {
883
+ curves_to_add.insert (curve_element.attribute (" name" ).toStdString () );
884
+ }
885
+
886
+ bool curve_removed = true ;
887
+
888
+ while (curve_removed)
889
+ {
890
+ curve_removed = false ;
891
+ for (auto & it : _curve_list)
892
+ {
893
+ auto curve_name = it.first ;
894
+ if (curves_to_add.find (curve_name) == curves_to_add.end ())
895
+ {
896
+ removeCurve (curve_name);
897
+ curve_removed = true ;
898
+ break ;
899
+ }
900
+ }
901
+ }
902
+ // ---------------------------------------
903
+
904
+ for (QDomElement curve_element = plot_widget.firstChildElement (" curve" );
905
+ !curve_element.isNull ();
873
906
curve_element = curve_element.nextSiblingElement (" curve" ))
874
907
{
875
908
QString curve_name = curve_element.attribute (" name" );
@@ -891,7 +924,6 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
891
924
auto added = addCurve (curve_name_std);
892
925
curve_added = curve_added || added;
893
926
_curve_list[curve_name_std]->setPen (color, 1.0 );
894
- added_curve_names.insert (curve_name_std);
895
927
}
896
928
}
897
929
else
@@ -909,7 +941,6 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
909
941
auto added = addCurveXY (curve_x, curve_y, curve_name);
910
942
curve_added = curve_added || added;
911
943
_curve_list[curve_name_std]->setPen (color, 1.0 );
912
- added_curve_names.insert (curve_name_std);
913
944
}
914
945
}
915
946
@@ -922,23 +953,6 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
922
953
}
923
954
}
924
955
925
- bool curve_removed = true ;
926
-
927
- while (curve_removed)
928
- {
929
- curve_removed = false ;
930
- for (auto & it : _curve_list)
931
- {
932
- auto curve_name = it.first ;
933
- if (added_curve_names.find (curve_name) == added_curve_names.end ())
934
- {
935
- removeCurve (curve_name);
936
- curve_removed = true ;
937
- break ;
938
- }
939
- }
940
- }
941
-
942
956
if (trans_value.isEmpty () || trans_value == " noTransform" )
943
957
{
944
958
_action_noTransform->trigger ();
@@ -971,7 +985,7 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
971
985
_action_custom_transform->setChecked (true );
972
986
}
973
987
974
- if (curve_removed || curve_added)
988
+ if (curve_added)
975
989
{
976
990
_tracker->redraw ();
977
991
// replot();
@@ -1604,7 +1618,7 @@ void PlotWidget::convertToXY()
1604
1618
1605
1619
this ->setFooter (text);
1606
1620
1607
- zoomOut (true );
1621
+ zoomOut (false );
1608
1622
on_changeDateTimeScale (_use_date_time_scale);
1609
1623
replot ();
1610
1624
}
0 commit comments