Skip to content

Commit 13039ee

Browse files
author
Davide Faconti
committed
fix issue #318
1 parent 5b01a40 commit 13039ee

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

plotter_gui/mainwindow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ void MainWindow::updateRecentLayoutMenu(QStringList new_filenames)
875875

876876
void MainWindow::deleteAllData()
877877
{
878-
forEachWidget([](PlotWidget* plot) { plot->detachAllCurves(); });
878+
forEachWidget([](PlotWidget* plot) { plot->removeAllCurves(); });
879879

880880
_mapped_plot_data.numeric.clear();
881881
_mapped_plot_data.user_defined.clear();

plotter_gui/plotwidget.cpp

+41-27
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void PlotWidget::buildActions()
226226
connect(_action_removeCurve, &QAction::triggered, this, &PlotWidget::launchRemoveCurveDialog);
227227

228228
_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);
230230
connect(_action_removeAllCurves, &QAction::triggered, this, &PlotWidget::undoableChange);
231231

232232
_action_changeColorsDialog = new QAction("&Change colors", this);
@@ -722,7 +722,7 @@ void PlotWidget::dropEvent(QDropEvent*)
722722
_dragging.curves.clear();
723723
}
724724

725-
void PlotWidget::detachAllCurves()
725+
void PlotWidget::removeAllCurves()
726726
{
727727
for (auto& it : _curve_list)
728728
{
@@ -829,14 +829,20 @@ QDomElement PlotWidget::xmlSaveState(QDomDocument& doc) const
829829

830830
bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
831831
{
832-
std::set<std::string> added_curve_names;
833-
834832
QDomElement transform = plot_widget.firstChildElement("transform");
835833
QString trans_value = transform.attribute("value");
836834

837835
if (trans_value == "XYPlot")
838836
{
839-
convertToXY();
837+
if( !isXYPlot()){
838+
convertToXY();
839+
}
840+
}
841+
else {
842+
if( isXYPlot() ){
843+
removeAllCurves();
844+
_xy_mode = false;
845+
}
840846
}
841847

842848
QDomElement limitY_el = plot_widget.firstChildElement("limitY");
@@ -869,7 +875,34 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
869875

870876
bool curve_added = false;
871877

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();
873906
curve_element = curve_element.nextSiblingElement("curve"))
874907
{
875908
QString curve_name = curve_element.attribute("name");
@@ -891,7 +924,6 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
891924
auto added = addCurve(curve_name_std);
892925
curve_added = curve_added || added;
893926
_curve_list[curve_name_std]->setPen(color, 1.0);
894-
added_curve_names.insert(curve_name_std);
895927
}
896928
}
897929
else
@@ -909,7 +941,6 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
909941
auto added = addCurveXY(curve_x, curve_y, curve_name);
910942
curve_added = curve_added || added;
911943
_curve_list[curve_name_std]->setPen(color, 1.0);
912-
added_curve_names.insert(curve_name_std);
913944
}
914945
}
915946

@@ -922,23 +953,6 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
922953
}
923954
}
924955

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-
942956
if (trans_value.isEmpty() || trans_value == "noTransform")
943957
{
944958
_action_noTransform->trigger();
@@ -971,7 +985,7 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
971985
_action_custom_transform->setChecked(true);
972986
}
973987

974-
if (curve_removed || curve_added)
988+
if (curve_added)
975989
{
976990
_tracker->redraw();
977991
// replot();
@@ -1604,7 +1618,7 @@ void PlotWidget::convertToXY()
16041618

16051619
this->setFooter(text);
16061620

1607-
zoomOut(true);
1621+
zoomOut(false);
16081622
on_changeDateTimeScale(_use_date_time_scale);
16091623
replot();
16101624
}

plotter_gui/plotwidget.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public slots:
102102

103103
void updateCurves();
104104

105-
void detachAllCurves();
105+
void removeAllCurves();
106106

107107
void on_panned(int dx, int dy);
108108

plotter_gui/tabbedplotwidget.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,8 @@ bool TabbedPlotWidget::xmlLoadState(QDomElement& tabbed_area)
152152
this->addTab(NULL);
153153
num_tabs++;
154154
}
155-
PlotMatrix* plot_matrix = static_cast<PlotMatrix*>(tabWidget()->widget(index));
156-
bool success = plot_matrix->xmlLoadState(plotmatrix_el);
157155

156+
PlotMatrix* plot_matrix = static_cast<PlotMatrix*>(tabWidget()->widget(index));
158157
// read tab name
159158
if (plotmatrix_el.hasAttribute("tab_name"))
160159
{
@@ -163,6 +162,8 @@ bool TabbedPlotWidget::xmlLoadState(QDomElement& tabbed_area)
163162
plot_matrix->setName(tab_name);
164163
}
165164

165+
bool success = plot_matrix->xmlLoadState(plotmatrix_el);
166+
166167
if (!success)
167168
{
168169
return false;
@@ -495,7 +496,7 @@ void TabbedPlotWidget::on_tabWidget_tabCloseRequested(int index)
495496
for (unsigned p = 0; p < matrix->plotCount(); p++)
496497
{
497498
PlotWidget* plot = matrix->plotAt(p);
498-
plot->detachAllCurves();
499+
plot->removeAllCurves();
499500
plot->deleteLater();
500501
}
501502
matrix->deleteLater();

0 commit comments

Comments
 (0)