Skip to content
Snippets Groups Projects
Commit 930591d0 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

update all linked material editors if a value changes in one in-place material editor

parent baee9795
No related branches found
No related tags found
1 merge request!420Layer editor improvements3
......@@ -18,6 +18,7 @@
#include "GUI/Models/MaterialItemUtils.h"
#include "GUI/Models/VectorDescriptor.h"
#include "GUI/Views/CommonWidgets/DoubleLineEdit.h"
#include "GUI/Views/CommonWidgets/DoubleSpinBox.h"
#include "GUI/Views/MaterialEditor/MaterialEditorDialog.h"
#include "GUI/Views/SampleDesigner/LayerEditorUtils.h"
#include "GUI/Views/SampleDesigner/SampleEditorController.h"
......@@ -37,6 +38,23 @@ MaterialInplaceForm::MaterialInplaceForm(QWidget* parent, ItemWithMaterial* item
createWidgets();
}
ItemWithMaterial* MaterialInplaceForm::itemWithMaterial() const
{
return m_item;
}
void MaterialInplaceForm::updateValues()
{
for (auto* editor : findChildren<DoubleSpinBox*>()) {
QSignalBlocker b(editor);
editor->setBaseValue(editor->valueDescriptor());
}
for (auto* editor : findChildren<DoubleLineEdit*>()) {
QSignalBlocker b(editor);
editor->setBaseValue(editor->valueDescriptor());
}
}
void MaterialInplaceForm::selectMaterial()
{
const QString newMaterialIdentifier = MaterialEditorDialog::chooseMaterial(
......@@ -72,8 +90,12 @@ void MaterialInplaceForm::createWidgets()
m_layout->addWidget(editor, 1, col++);
}
LayerEditorUtils::addVectorToGrid(m_layout, col, materialItem->magnetizationVector(), m_ec,
true, false);
const auto setNewValue = [=](double value, DoubleDescriptor d) {
m_ec->setMaterialValue(m_item, value, d);
};
LayerEditorUtils::addVectorToGrid(m_layout, col, materialItem->magnetizationVector(),
setNewValue, true, false);
QPushButton* btn = new QPushButton("...", this);
btn->setToolTip("Select material");
......
......@@ -27,6 +27,9 @@ class MaterialInplaceForm : public QWidget {
public:
MaterialInplaceForm(QWidget* parent, ItemWithMaterial* item, SampleEditorController* ec);
ItemWithMaterial* itemWithMaterial() const;
void updateValues();
private:
void selectMaterial();
void createWidgets();
......
......@@ -24,6 +24,7 @@
#include "GUI/Views/CommonWidgets/DoubleSpinBox.h"
#include "GUI/Views/SampleDesigner/InterferenceForm.h"
#include "GUI/Views/SampleDesigner/LayerForm.h"
#include "GUI/Views/SampleDesigner/MaterialInplaceForm.h"
#include "GUI/Views/SampleDesigner/MesoCrystalForm.h"
#include "GUI/Views/SampleDesigner/MultiLayerForm.h"
#include "GUI/Views/SampleDesigner/ParticleCompositionForm.h"
......@@ -297,11 +298,17 @@ void SampleEditorController::selectMaterial(ItemWithMaterial* item,
// #baLayerEditor notify all material users (update link info)
}
void SampleEditorController::setMaterialValue(ItemWithMaterial* /*item*/, double newValue,
void SampleEditorController::setMaterialValue(ItemWithMaterial* item, double newValue,
DoubleDescriptor d)
{
setDouble(newValue, d);
// #baLayerEditor notify all other users of this material (update values)
// -- notify all other users of this material (update values in the UI)
ASSERT(m_multiLayerForm);
for (auto c : m_multiLayerForm->findChildren<MaterialInplaceForm*>())
if (c->itemWithMaterial() != item
&& c->itemWithMaterial()->materialIdentifier() == item->materialIdentifier())
c->updateValues();
}
void SampleEditorController::onStartingToMoveLayer()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment