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

Description

Form to present/edit a MultiLayer (sample)

Definition at line 28 of file MultiLayerForm.h.

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

Public Member Functions

 MultiLayerForm (QWidget *parent, MultiLayerItem *sampleItem, SampleEditorController *ec)
 
void ensureVisible (QWidget *w)
 
LayerFormfindNextLayerForm (QWidget *w)
 Search for the next LayerForm, starting from the given widget. More...
 
void onAboutToRemoveLayer (LayerItem *layerItem)
 Call this before removing (deleting) a LayerItem. More...
 
void onLayerAdded (LayerItem *layerItem)
 Create widgets for the new layer. More...
 
void onLayerMoved (LayerItem *layerItem)
 Call this when a layerItem has been moved to a different position. More...
 
void setUseAngstrom (bool angstrom)
 Show values in Angstrom or nanometers. More...
 
void setUseRadiant (bool radiant)
 Show values in radiants or degrees. More...
 
void showAddLayerButtons (bool show)
 Shows or hides the "Add Layer" buttons. More...
 
void showInlineEditButtons (bool b)
 Show or hide all buttons related to structure editing (like "add layer", "remove particle") More...
 
void updateRowVisibilities ()
 
void updateUnits ()
 Update the presented units in all contained widgets according to current settings. More...
 
bool useAngstrom () const
 
bool useRadiant () const
 

Private Attributes

QList< QPushButton * > m_addLayerButtons
 
SampleEditorControllerm_ec
 Ptr is borrowed, don't delete. More...
 
QVBoxLayout * m_layout
 
MultiLayerItemm_sampleItem
 Ptr is borrowed, don't delete. More...
 
bool m_showInlineEditButtons = false
 
bool m_useAngstrom
 
bool m_useRadiant
 

Constructor & Destructor Documentation

◆ MultiLayerForm()

MultiLayerForm::MultiLayerForm ( QWidget *  parent,
MultiLayerItem sampleItem,
SampleEditorController ec 
)

Definition at line 55 of file MultiLayerForm.cpp.

57  : QWidget(parent)
58  , m_sampleItem(sampleItem)
59  , m_ec(ec)
60  , m_useAngstrom(false)
61  , m_useRadiant(false)
62 {
63  setObjectName("MultiLayerForm"); // important for style sheet addressing
64  setAttribute(Qt::WA_StyledBackground, true);
65 
66  m_layout = new QVBoxLayout(this);
67 
68  auto* props = new QGroupBox(this);
69  props->setTitle("Sample");
70  FormLayouter layouter(props, ec);
71  layouter.setContentsMargins(6, 6, 0, 6);
72 
73  auto* nameEdit = new QLineEdit(props);
74  layouter.addRow("Name:", nameEdit);
75  nameEdit->setText(sampleItem->sampleName());
76  connect(nameEdit, &QLineEdit::textEdited, ec, &SampleEditorController::setSampleName);
77 
78  auto* descriptionEdit = new QTextEdit(props);
79  descriptionEdit->setMinimumWidth(300);
80  descriptionEdit->setMaximumHeight(100);
81  descriptionEdit->setAcceptRichText(false);
82  descriptionEdit->setTabChangesFocus(true);
83  descriptionEdit->setPlainText(sampleItem->description());
84  layouter.addRow("Description:", descriptionEdit);
85  connect(descriptionEdit, &QTextEdit::textChanged,
86  [=]() { m_ec->setSampleDescription(descriptionEdit->toPlainText()); });
87 
88  layouter.addValue(sampleItem->crossCorrLength());
89  layouter.addVector(sampleItem->externalFieldVector(), false);
90  auto* collapser = GroupBoxCollapser::installIntoGroupBox(props, false);
91 
92  auto* showInRealSpaceAction = ActionFactory::createShowInRealSpaceAction(
93  this, "sample", [=] { m_ec->requestViewInRealSpace(m_sampleItem); });
94 
95  collapser->addAction(showInRealSpaceAction);
96 
97  m_layout->addWidget(props);
98 
99  for (auto* layer : sampleItem->layers()) {
100  m_layout->addWidget(new AddLayerWidget(this, layer, m_ec));
101  m_layout->addWidget(new LayerForm(this, layer, m_ec));
102  }
103  m_layout->addWidget(new AddLayerWidget(this, nullptr, m_ec));
104  m_layout->setSizeConstraint(QLayout::SetMinimumSize);
105  m_layout->addStretch(1);
106 }
static QAction * createShowInRealSpaceAction(QObject *parent, const QString &what, std::function< void()> slot=nullptr)
Create "show in RealSpace" action.
Utility class to populate a QFormLayout.
Definition: FormLayouter.h:36
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
Form for editing a layer.
Definition: LayerForm.h:29
SampleEditorController * m_ec
Ptr is borrowed, don't delete.
QVBoxLayout * m_layout
MultiLayerItem * m_sampleItem
Ptr is borrowed, don't delete.
QString sampleName() const
QVector< LayerItem * > layers() const
QString description() const
DoubleDescriptor crossCorrLength() const
VectorDescriptor externalFieldVector() const
void setSampleDescription(const QString &description)
void requestViewInRealSpace(SampleItem item)
void setSampleName(const QString &name)

References FormLayouter::addRow(), FormLayouter::addValue(), FormLayouter::addVector(), ActionFactory::createShowInRealSpaceAction(), MultiLayerItem::crossCorrLength(), MultiLayerItem::description(), MultiLayerItem::externalFieldVector(), GroupBoxCollapser::installIntoGroupBox(), MultiLayerItem::layers(), m_ec, m_layout, m_sampleItem, SampleEditorController::requestViewInRealSpace(), MultiLayerItem::sampleName(), FormLayouter::setContentsMargins(), SampleEditorController::setSampleDescription(), and SampleEditorController::setSampleName().

Here is the call graph for this function:

Member Function Documentation

◆ ensureVisible()

void MultiLayerForm::ensureVisible ( QWidget *  w)

Definition at line 248 of file MultiLayerForm.cpp.

249 {
250  // #baLayerEditor implement ensureVisible
251 }

Referenced by SampleEditorController::setDoubleFromUndo().

◆ findNextLayerForm()

LayerForm * MultiLayerForm::findNextLayerForm ( QWidget *  w)

Search for the next LayerForm, starting from the given widget.

The search starts with the given widget itself If it is a LayerForm, it is returned. If no following LayerForm is found, nullptr is returned.

Definition at line 282 of file MultiLayerForm.cpp.

283 {
284  while (w != nullptr && dynamic_cast<LayerForm*>(w) == nullptr) {
285  const auto index = m_layout->indexOf(w);
286  if (index + 1 < m_layout->count())
287  w = m_layout->itemAt(index + 1)->widget();
288  else
289  return nullptr;
290  }
291 
292  return dynamic_cast<LayerForm*>(w);
293 }

References m_layout.

Referenced by SampleEditorController::onStoppedToMoveLayer().

◆ onAboutToRemoveLayer()

void MultiLayerForm::onAboutToRemoveLayer ( LayerItem layerItem)

Call this before removing (deleting) a LayerItem.

Any widgets related to the item will be deleted or scheduled for later deletion.

Definition at line 161 of file MultiLayerForm.cpp.

162 {
163  LayerForm* layerForm = nullptr;
164  AddLayerWidget* addLayerWidget = nullptr;
165  for (auto* c : findChildren<QWidget*>()) {
166  if (auto* w = dynamic_cast<AddLayerWidget*>(c))
167  if (w->m_layer == layerItem)
168  addLayerWidget = w;
169 
170  if (auto* w = dynamic_cast<LayerForm*>(c)) {
171  if (w->layerItem() == layerItem)
172  layerForm = w;
173  }
174  }
175 
176  if (layerForm) {
177  // delete editors which are subscribed to SessionItems
178  GUI::Util::Layout::clearLayout(layerForm->layout());
179  layerForm->hide();
180  layerForm->setParent(nullptr); // so it is not findable in update routines
181  layerForm->deleteLater(); // delete later (this is the sender)
182  }
183 
184 
185  delete addLayerWidget;
186 }
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:68

References GUI::Util::Layout::clearLayout().

Referenced by SampleEditorController::removeLayerFromUndo().

Here is the call graph for this function:

◆ onLayerAdded()

void MultiLayerForm::onLayerAdded ( LayerItem layerItem)

Create widgets for the new layer.

Definition at line 114 of file MultiLayerForm.cpp.

115 {
116  const int rowInMultiLayer = m_sampleItem->layers().indexOf(layerItem);
117 
118  const int rowInLayout = rowInMultiLayer * 2 + 1;
119 
120  m_layout->insertWidget(rowInLayout, new LayerForm(this, layerItem, m_ec));
121 
122  // same row => button is above!
123  m_layout->insertWidget(rowInLayout, new AddLayerWidget(this, layerItem, m_ec));
124 
126 }
void updateRowVisibilities()

References MultiLayerItem::layers(), m_ec, m_layout, m_sampleItem, and updateRowVisibilities().

Referenced by SampleEditorController::addLayerFromUndo(), and CommandRemoveLayer::undo().

Here is the call graph for this function:

◆ onLayerMoved()

void MultiLayerForm::onLayerMoved ( LayerItem layerItem)

Call this when a layerItem has been moved to a different position.

This updates the item's position in the layout.

Definition at line 128 of file MultiLayerForm.cpp.

129 {
130  LayerForm* wl = nullptr;
131  AddLayerWidget* al = nullptr;
132  for (int index = 0; index < m_layout->count(); index++) {
133  if (auto* w = dynamic_cast<AddLayerWidget*>(m_layout->itemAt(index)->widget()))
134  if (w->m_layer == layerItem) {
135  al = w;
136  m_layout->takeAt(index);
137  break;
138  }
139  }
140 
141  for (int index = 0; index < m_layout->count(); index++) {
142  if (auto* w = dynamic_cast<LayerForm*>(m_layout->itemAt(index)->widget()))
143  if (w->layerItem() == layerItem) {
144  wl = w;
145  m_layout->takeAt(index);
146  break;
147  }
148  }
149 
150  const int rowInMultiLayer = m_sampleItem->layers().indexOf(layerItem);
151  const int rowInLayout = rowInMultiLayer * 2 + 1;
152 
153  m_layout->insertWidget(rowInLayout, wl);
154 
155  // same row => button is above!
156  m_layout->insertWidget(rowInLayout, al);
157 
159 }

References MultiLayerItem::layers(), m_layout, m_sampleItem, and updateRowVisibilities().

Referenced by SampleEditorController::onStoppedToMoveLayer().

Here is the call graph for this function:

◆ setUseAngstrom()

void MultiLayerForm::setUseAngstrom ( bool  angstrom)

Show values in Angstrom or nanometers.

Definition at line 253 of file MultiLayerForm.cpp.

254 {
256  updateUnits();
257 }
@ angstrom
void updateUnits()
Update the presented units in all contained widgets according to current settings.

References angstrom, m_useAngstrom, and updateUnits().

Referenced by LayerOrientedSampleEditor::onUnitActionToggled(), and LayerOrientedSampleEditor::setCurrentSample().

Here is the call graph for this function:

◆ setUseRadiant()

void MultiLayerForm::setUseRadiant ( bool  radiant)

Show values in radiants or degrees.

Definition at line 264 of file MultiLayerForm.cpp.

265 {
267  updateUnits();
268 }
@ radiant

References m_useRadiant, radiant, and updateUnits().

Here is the call graph for this function:

◆ showAddLayerButtons()

void MultiLayerForm::showAddLayerButtons ( bool  show)

Shows or hides the "Add Layer" buttons.

Definition at line 275 of file MultiLayerForm.cpp.

276 {
277  for (auto* c : findChildren<QWidget*>())
278  if (dynamic_cast<AddLayerWidget*>(c))
279  c->setVisible(show);
280 }

Referenced by SampleEditorController::onStartingToMoveLayer(), SampleEditorController::onStoppedToMoveLayer(), and updateRowVisibilities().

◆ showInlineEditButtons()

void MultiLayerForm::showInlineEditButtons ( bool  b)

Show or hide all buttons related to structure editing (like "add layer", "remove particle")

Definition at line 108 of file MultiLayerForm.cpp.

109 {
112 }
bool m_showInlineEditButtons

References m_showInlineEditButtons, and updateRowVisibilities().

Referenced by LayerOrientedSampleEditor::onShowInlineEditButtonsToggled(), and LayerOrientedSampleEditor::setCurrentSample().

Here is the call graph for this function:

◆ updateRowVisibilities()

void MultiLayerForm::updateRowVisibilities ( )

Definition at line 188 of file MultiLayerForm.cpp.

189 {
190  for (auto* c : findChildren<QWidget*>()) {
191  if (auto* w = dynamic_cast<LayerForm*>(c))
192  w->enableStructureEditing(m_showInlineEditButtons);
193  if (auto* w = dynamic_cast<ParticleLayoutForm*>(c))
194  w->enableStructureEditing(m_showInlineEditButtons);
195  if (auto* w = dynamic_cast<ParticleForm*>(c))
196  w->enableStructureEditing(m_showInlineEditButtons);
197  if (auto* w = dynamic_cast<ParticleCompositionForm*>(c))
198  w->enableStructureEditing(m_showInlineEditButtons);
199  if (auto* w = dynamic_cast<ParticleCoreShellForm*>(c))
200  w->enableStructureEditing(m_showInlineEditButtons);
201  if (auto* w = dynamic_cast<MesoCrystalForm*>(c))
202  w->enableStructureEditing(m_showInlineEditButtons);
203  }
204 
206 
207  for (auto* c : findChildren<LayerForm*>())
208  c->updateLayerPositionDependentElements();
209 }
Form for editing a mesocrystal.
void showAddLayerButtons(bool show)
Shows or hides the "Add Layer" buttons.
Form for editing a particle composition.
Form for editing a core/shell particle.
Form for editing a particle.
Definition: ParticleForm.h:25
Form for editing a particle layout.

References m_showInlineEditButtons, and showAddLayerButtons().

Referenced by onLayerAdded(), onLayerMoved(), SampleEditorController::removeLayerFromUndo(), and showInlineEditButtons().

Here is the call graph for this function:

◆ updateUnits()

void MultiLayerForm::updateUnits ( )

Update the presented units in all contained widgets according to current settings.

Definition at line 212 of file MultiLayerForm.cpp.

213 {
214  const auto set = [](DoubleSpinBox* spinbox, Unit valueUnit, Unit displayUnit) {
215  if (spinbox->baseUnit() == valueUnit)
216  spinbox->setDisplayUnit(displayUnit);
217  };
218 
219  for (auto* editor : findChildren<DoubleSpinBox*>()) {
220  if (m_useAngstrom) {
221  set(editor, Unit::nanometer, Unit::angstrom);
222  set(editor, Unit::angstrom, Unit::angstrom);
223  set(editor, Unit::nanometer2, Unit::angstrom2);
224  set(editor, Unit::angstrom2, Unit::angstrom2);
227  } else {
228  set(editor, Unit::nanometer, Unit::nanometer);
229  set(editor, Unit::angstrom, Unit::nanometer);
230  set(editor, Unit::nanometer2, Unit::nanometer2);
231  set(editor, Unit::angstrom2, Unit::nanometer2);
234  }
235 
236  if (m_useRadiant) {
237  set(editor, Unit::degree, Unit::radiant);
238  set(editor, Unit::radiant, Unit::radiant);
239  } else {
240  set(editor, Unit::degree, Unit::degree);
241  set(editor, Unit::radiant, Unit::degree);
242  }
243  }
244  for (auto* label : findChildren<QLabel*>())
246 }
Unit
Defines units, mainly to be able to convert between units.
Definition: Unit.h:26
@ nanometerMinus2
@ nanometer2
@ angstrom2
@ angstromMinus2
@ nanometer
@ degree
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
Unit baseUnit() const
Returns the unit of the contained DoubleDescriptor.
void setDisplayUnit(Unit displayUnit)
Set a display unit.
void updateLabelUnit(QLabel *label)

References angstrom, angstrom2, angstromMinus2, DoubleSpinBox::baseUnit(), degree, m_useAngstrom, m_useRadiant, nanometer, nanometer2, nanometerMinus2, radiant, DoubleSpinBox::setDisplayUnit(), and LayerEditorUtils::updateLabelUnit().

Referenced by SampleEditorController::addLayerFromUndo(), SampleEditorController::addLayout(), SampleEditorController::addParticle(), SampleEditorController::selectInterference(), SampleEditorController::setCoreFormFactor(), SampleEditorController::setCurrentIndex(), SampleEditorController::setMesoCrystalBasis(), SampleEditorController::setShellFormFactor(), setUseAngstrom(), and setUseRadiant().

Here is the call graph for this function:

◆ useAngstrom()

bool MultiLayerForm::useAngstrom ( ) const

Definition at line 259 of file MultiLayerForm.cpp.

260 {
261  return m_useAngstrom;
262 }

References m_useAngstrom.

◆ useRadiant()

bool MultiLayerForm::useRadiant ( ) const

Definition at line 270 of file MultiLayerForm.cpp.

271 {
272  return m_useRadiant;
273 }

References m_useRadiant.

Member Data Documentation

◆ m_addLayerButtons

QList<QPushButton*> MultiLayerForm::m_addLayerButtons
private

Definition at line 80 of file MultiLayerForm.h.

◆ m_ec

SampleEditorController* MultiLayerForm::m_ec
private

Ptr is borrowed, don't delete.

Definition at line 76 of file MultiLayerForm.h.

Referenced by MultiLayerForm(), and onLayerAdded().

◆ m_layout

QVBoxLayout* MultiLayerForm::m_layout
private

Definition at line 74 of file MultiLayerForm.h.

Referenced by MultiLayerForm(), findNextLayerForm(), onLayerAdded(), and onLayerMoved().

◆ m_sampleItem

MultiLayerItem* MultiLayerForm::m_sampleItem
private

Ptr is borrowed, don't delete.

Definition at line 75 of file MultiLayerForm.h.

Referenced by MultiLayerForm(), onLayerAdded(), and onLayerMoved().

◆ m_showInlineEditButtons

bool MultiLayerForm::m_showInlineEditButtons = false
private

Definition at line 77 of file MultiLayerForm.h.

Referenced by showInlineEditButtons(), and updateRowVisibilities().

◆ m_useAngstrom

bool MultiLayerForm::m_useAngstrom
private

Definition at line 78 of file MultiLayerForm.h.

Referenced by setUseAngstrom(), updateUnits(), and useAngstrom().

◆ m_useRadiant

bool MultiLayerForm::m_useRadiant
private

Definition at line 79 of file MultiLayerForm.h.

Referenced by setUseRadiant(), updateUnits(), and useRadiant().


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