BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialInplaceForm Class Reference

Description

Form to select a material and to edit it in-place.

Definition at line 26 of file MaterialInplaceForm.h.

Inheritance diagram for MaterialInplaceForm:
[legend]
Collaboration diagram for MaterialInplaceForm:
[legend]

Public Member Functions

 MaterialInplaceForm (QWidget *parent, ItemWithMaterial *item, SampleEditorController *ec)
 
ItemWithMaterialitemWithMaterial () const
 
void updateValues ()
 

Private Member Functions

void createWidgets ()
 
void onMaterialChanged ()
 
void selectMaterial ()
 

Private Attributes

SampleEditorControllerm_ec
 
ItemWithMaterialm_item
 
QGridLayout * m_layout
 

Constructor & Destructor Documentation

◆ MaterialInplaceForm()

MaterialInplaceForm::MaterialInplaceForm ( QWidget *  parent,
ItemWithMaterial item,
SampleEditorController ec 
)

Definition at line 35 of file MaterialInplaceForm.cpp.

37  : QWidget(parent)
38  , m_item(item)
39  , m_ec(ec)
40 {
41  m_layout = new QGridLayout(this);
42  m_layout->setContentsMargins(0, 0, 0, 0);
43  createWidgets();
44 
45  connect(itemWithMaterial()->materialItem(), &MaterialItem::dataChanged, this,
47 }
ItemWithMaterial * m_item
SampleEditorController * m_ec
ItemWithMaterial * itemWithMaterial() const
void dataChanged() const

References createWidgets(), MaterialItem::dataChanged(), itemWithMaterial(), m_layout, and onMaterialChanged().

Here is the call graph for this function:

Member Function Documentation

◆ createWidgets()

void MaterialInplaceForm::createWidgets ( )
private

Definition at line 90 of file MaterialInplaceForm.cpp.

91 {
92  auto* material = m_item->materialItem();
93  ASSERT(material);
94 
95  // -- Create UI for delta/beta resp. sldRe/sldIm
96  DoubleDescriptors values;
97  if (material->hasRefractiveIndex())
98  values << material->delta() << material->beta();
99  else
100  values << material->sldRe() << material->sldIm();
101 
102  int col = 0;
103  for (const auto& d : values) {
104  auto* editor = new DoubleLineEdit(this, d);
105  auto* label = new QLabel(d.label, this);
106  label->setBuddy(editor);
107 
108  QObject::connect(editor, &DoubleLineEdit::baseValueChanged,
109  [=](double newValue) { m_ec->setMaterialValue(m_item, newValue, d); });
110 
111  m_layout->addWidget(label, 0, col);
112  m_layout->addWidget(editor, 1, col++);
113  }
114 
115  // -- Create UI for magnetization vector
116  VectorDescriptor mag = material->magnetizationVector();
117  const auto setNewValue = [=](double value, DoubleDescriptor d) {
118  m_ec->setMaterialValue(m_item, value, d);
119  };
120  LayerEditorUtils::addVectorToGrid(m_layout, col, mag, setNewValue, true, false);
121 
122  // -- Create UI for material selection button
123  auto* btn = new QPushButton("...", this);
124  btn->setToolTip("Select material");
125  m_layout->addWidget(btn, 1, m_layout->columnCount());
126  connect(btn, &QPushButton::clicked, this, &MaterialInplaceForm::selectMaterial);
127 
128  m_layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding), 0, m_layout->columnCount());
129 }
QList< DoubleDescriptor > DoubleDescriptors
Describes properties of a double value which are necessary to allow GUI representation,...
LineEdit to edit values in a scientific notation, operating on a DoubleDescriptor.
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
MaterialItem * materialItem() const
Returns the material item this item links to.
void setMaterialValue(ItemWithMaterial *item, double newValue, DoubleDescriptor d)
Describes properties of a 3D vector, consisting of three double values.
void addVectorToGrid(QGridLayout *m_gridLayout, int firstCol, const VectorDescriptor &v, SampleEditorController *ec, bool vertically, bool addSpacer)
Create DoubleSpinBoxes for the DoubeDescriptors and connect them to SampleEditorController::setDouble...

References LayerEditorUtils::addVectorToGrid(), DoubleLineEdit::baseValueChanged(), m_ec, m_item, m_layout, ItemWithMaterial::materialItem(), selectMaterial(), and SampleEditorController::setMaterialValue().

Referenced by MaterialInplaceForm(), and selectMaterial().

Here is the call graph for this function:

◆ itemWithMaterial()

ItemWithMaterial * MaterialInplaceForm::itemWithMaterial ( ) const

Definition at line 49 of file MaterialInplaceForm.cpp.

50 {
51  return m_item;
52 }

References m_item.

Referenced by MaterialInplaceForm(), and selectMaterial().

◆ onMaterialChanged()

void MaterialInplaceForm::onMaterialChanged ( )
private

Definition at line 131 of file MaterialInplaceForm.cpp.

132 {
133  updateValues();
134 }

References updateValues().

Referenced by MaterialInplaceForm(), and selectMaterial().

Here is the call graph for this function:

◆ selectMaterial()

void MaterialInplaceForm::selectMaterial ( )
private

Definition at line 66 of file MaterialInplaceForm.cpp.

67 {
68  const auto materialsBackup = GUI::Util::createBackup(&m_ec->sampleItem()->materialItems());
69  const QString newMaterialIdentifier = MaterialEditorDialog::chooseMaterial(
71 
72  if (!newMaterialIdentifier.isEmpty() && newMaterialIdentifier != m_item->materialIdentifier()) {
73  itemWithMaterial()->materialItem()->disconnect(this);
75  m_ec->selectMaterial(m_item, newMaterialIdentifier);
76  createWidgets();
77  connect(itemWithMaterial()->materialItem(), &MaterialItem::dataChanged, this,
79  } else {
80  updateValues(); // necessary, since in the material editor the values could have been
81  // changed without selecting a different material
82 
83  // If the list of materials was edited (e.g. a material added), but the current was not
84  // changed, no modified signal would be sent. Check now for changes and emit if necessary.
85  if (GUI::Util::createBackup(&m_ec->sampleItem()->materialItems()) != materialsBackup)
86  m_ec->modified();
87  }
88 }
QString materialIdentifier() const
static QString chooseMaterial(QWidget *parent, MultiLayerItem *sample, const QString &identifierOfPreviousMaterial)
Use this to choose a material. identifierOfPreviousMaterial is the material which should be selected ...
MaterialItems & materialItems()
MultiLayerItem * sampleItem() const
The item on which this controller operates.
void selectMaterial(ItemWithMaterial *item, const QString &newMaterialIdentifier)
static QMainWindow * mainWindow
Definition: Globals.h:22
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:68
QByteArray createBackup(const T *t)
Definition: Backup.h:24

References MaterialEditorDialog::chooseMaterial(), GUI::Util::Layout::clearLayout(), GUI::Util::createBackup(), createWidgets(), MaterialItem::dataChanged(), itemWithMaterial(), m_ec, m_item, m_layout, GUI::Global::mainWindow, ItemWithMaterial::materialIdentifier(), ItemWithMaterial::materialItem(), MultiLayerItem::materialItems(), SampleEditorController::modified(), onMaterialChanged(), SampleEditorController::sampleItem(), SampleEditorController::selectMaterial(), and updateValues().

Referenced by createWidgets().

Here is the call graph for this function:

◆ updateValues()

void MaterialInplaceForm::updateValues ( )

Definition at line 54 of file MaterialInplaceForm.cpp.

55 {
56  for (auto* editor : findChildren<DoubleSpinBox*>()) {
57  QSignalBlocker b(editor);
58  editor->setBaseValue(editor->valueDescriptor());
59  }
60  for (auto* editor : findChildren<DoubleLineEdit*>()) {
61  QSignalBlocker b(editor);
62  editor->setBaseValue(editor->valueDescriptor());
63  }
64 }

Referenced by onMaterialChanged(), and selectMaterial().

Member Data Documentation

◆ m_ec

SampleEditorController* MaterialInplaceForm::m_ec
private

Definition at line 40 of file MaterialInplaceForm.h.

Referenced by createWidgets(), and selectMaterial().

◆ m_item

ItemWithMaterial* MaterialInplaceForm::m_item
private

Definition at line 39 of file MaterialInplaceForm.h.

Referenced by createWidgets(), itemWithMaterial(), and selectMaterial().

◆ m_layout

QGridLayout* MaterialInplaceForm::m_layout
private

Definition at line 41 of file MaterialInplaceForm.h.

Referenced by MaterialInplaceForm(), createWidgets(), and selectMaterial().


The documentation for this class was generated from the following files: