Commit 0deac9e0 authored by CABEL Tristan's avatar CABEL Tristan

plot2d bugfix dont delete old_fields on field_x->clear()

parent 6d6e7cb9
......@@ -92,6 +92,7 @@ public:
vtkSmartPointer<vtkChartXY> chart = nullptr;
vtkSmartPointer<vtkFieldData> old_fields = nullptr;
QMap< QString, FieldParameters> old_fields_param;
QString old_field_x = "";
QString add_plot_suffix = "";
public:
......@@ -254,12 +255,16 @@ dtkVisualizationPlot2D::dtkVisualizationPlot2D(QWidget *parent) : dtkVisualizati
connect(d->field_x, &QComboBox::currentTextChanged, [=] ()
{
for(vtkIdType i=0; i < d->old_fields->GetNumberOfArrays() ; ++i) {
d->fields_table->RemoveColumnByName(d->old_fields->GetArray(i)->GetName());
d->old_fields->RemoveArray(i);
}
d->old_fields_param.clear();
if(d->field_x->currentText().isEmpty())
return;
if(d->old_field_x != d->field_x->currentText()) {
for(vtkIdType i=0; i < d->old_fields->GetNumberOfArrays() ; ++i) {
d->fields_table->RemoveColumnByName(d->old_fields->GetArray(i)->GetName());
d->old_fields->RemoveArray(i);
}
d->old_fields_param.clear();
}
this->render();
});
connect(d->field_y, &QListWidget::itemChanged, [=] ()
......@@ -290,11 +295,14 @@ dtkVisualizationPlot2D::dtkVisualizationPlot2D(QWidget *parent) : dtkVisualizati
}
if(!d->old_fields->HasArray(new_name.toStdString().c_str())) {
d->old_fields_param.insert(new_name, d->fields_parameters[row_text]);
d->old_field_x = d->field_x->currentText();
dtkVisualizationPlot2DPrivate::FieldParameters new_param = d->fields_parameters[row_text];
d->old_fields_param.insert(new_name, new_param);
vtkSmartPointer<vtkDoubleArray> new_field = vtkSmartPointer<vtkDoubleArray>::New();
new_field->DeepCopy(arr);
new_field->SetName(new_name.toStdString().c_str()) ;
d->old_fields->AddArray(new_field); // todo also save properties
d->old_fields->AddArray(new_field);
this->addFieldY(new_field,
false,
d->fields_parameters[row_text].chart_type,
......@@ -586,7 +594,6 @@ void dtkVisualizationPlot2D::clearFields(void)
d->field_y->blockSignals(false);
d->fields_parameters.clear();
for(vtkIdType i=0; i < d->fields_table->GetNumberOfColumns(); ++i) {
d->fields_table->RemoveColumn(i);
}
......@@ -614,17 +621,6 @@ void dtkVisualizationPlot2D::removeField(const QString& field)
d->field_x->removeItem(idx);
}
// QList<int> rows_to_delete;
// for(int i=0; i < d->field_y->count(); ++i) {
// if(d->field_y->item(i)->text() == field)
// rows_to_delete << i;
// }
// for(int row : rows_to_delete) {
// auto *item = d->field_y->takeItem(row);
// delete item;
// }
qDeleteAll(d->field_y->findItems(field, Qt::MatchFixedString));
d->fields_parameters.remove(field);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment