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

Description

Class to modify a sample from the layer oriented sample editor.

Use this class to modify the sample model. It takes care of notifications and creating undo/redo commands. It operates on one MultiLayerItem (which is a sample).

Definition at line 50 of file SampleEditorController.h.

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

Signals

void aboutToRemoveItem (SampleItem item)
 
void modified ()
 
void requestViewInRealSpace (SampleItem item)
 

Public Member Functions

 SampleEditorController (ProjectDocument *document, MultiLayerItem *multi)
 
void addLayer (LayerItem *before)
 
void addLayerFromUndo (int atIndex)
 
void addLayout (LayerForm *layerItem)
 
void addParticle (ParticleCompositionItem *composition, FormFactorItemCatalog::Type type)
 
void addParticle (ParticleCompositionItem *composition, ItemWithParticlesCatalog::Type type)
 
void addParticle (ParticleLayoutItem *layout, FormFactorItemCatalog::Type t)
 
void addParticle (ParticleLayoutItem *layout, ItemWithParticlesCatalog::Type type)
 
MaterialItemsmaterialItems () const
 The materials of the current document. More...
 
void onStartingToMoveLayer ()
 
void onStoppedToMoveLayer (QWidget *widgetToMove, QWidget *moveAboveThisWidget)
 
ProjectDocumentprojectDocument () const
 The current document. More...
 
void removeLayer (LayerItem *layerItem)
 
void removeLayerFromUndo (int atIndex)
 
void removeLayout (LayerForm *layerItem, ParticleLayoutItem *layout)
 
void removeParticle (ItemWithParticles *item)
 
MultiLayerFormsampleForm () const
 The current form. More...
 
MultiLayerItemsampleItem () const
 The item on which this controller operates. More...
 
void selectInterference (InterferenceForm *widget, int newIndex)
 
void selectMaterial (ItemWithMaterial *item, const QString &newMaterialIdentifier)
 
void setCoreFormFactor (ParticleCoreShellForm *widget, FormFactorItemCatalog::Type type)
 
void setCurrentIndex (AbstractSelectionContainerForm *widget, int index, const AbstractSelectionDescriptor &d)
 
void setDensityRelatedValue (InterferenceItem *interferenceItem, double newValue, DoubleDescriptor d)
 Set an interference function's value which affects the total particle density of the containing particle layout. More...
 
void setDouble (double newValue, DoubleDescriptor d)
 
void setDoubleFromUndo (double newValue, const QString &path)
 
void setInt (int newValue, UIntDescriptor d)
 
void setIntegrateOverXi (LatticeTypeSelectionForm *widget, bool newValue)
 
void setMaterialValue (ItemWithMaterial *item, double newValue, DoubleDescriptor d)
 
void setMesoCrystalBasis (MesoCrystalForm *widget, FormFactorItemCatalog::Type type)
 
void setMesoCrystalBasis (MesoCrystalForm *widget, ItemWithParticlesCatalog::Type type)
 
void setMultiLayerForm (MultiLayerForm *view)
 Set the current form. More...
 
void setSampleDescription (const QString &description)
 
void setSampleName (const QString &name)
 
void setShellFormFactor (ParticleCoreShellForm *widget, FormFactorItemCatalog::Type type)
 
QUndoStack * undoStack ()
 The contained undo stack. More...
 

Private Member Functions

ItemWithParticlescreateAndInitParticle (FormFactorItemCatalog::Type formFactorType) const
 
ItemWithParticlescreateAndInitParticle (ItemWithParticlesCatalog::Type itemType) const
 

Private Attributes

ProjectDocumentm_document
 
MultiLayerFormm_sampleForm
 
MultiLayerItemm_sampleItem
 
QUndoStack m_undoStack
 

Constructor & Destructor Documentation

◆ SampleEditorController()

SampleEditorController::SampleEditorController ( ProjectDocument document,
MultiLayerItem multi 
)

Definition at line 41 of file SampleEditorController.cpp.

42  : m_sampleItem(multi)
43  , m_sampleForm(nullptr)
44  , m_document(document)
45 {
46 }

Member Function Documentation

◆ aboutToRemoveItem

void SampleEditorController::aboutToRemoveItem ( SampleItem  item)
signal

◆ addLayer()

void SampleEditorController::addLayer ( LayerItem before)

Definition at line 63 of file SampleEditorController.cpp.

64 {
65  const int newIndex = (before != nullptr) ? m_sampleItem->layers().indexOf(before)
66  : m_sampleItem->layers().size();
67  m_undoStack.push(new CommandAddLayer(this, newIndex));
68 }
Command to add a layer to a sample.
QVector< LayerItem * > layers() const

References MultiLayerItem::layers(), m_sampleItem, and m_undoStack.

Here is the call graph for this function:

◆ addLayerFromUndo()

void SampleEditorController::addLayerFromUndo ( int  atIndex)

Definition at line 70 of file SampleEditorController.cpp.

71 {
72 
73  // -- find a color for the new layer
74  QColor color;
75  auto unusedColors = LayerEditorUtils::predefinedLayerColors();
76  for (auto* l : m_sampleItem->layers())
77  unusedColors.removeAll(l->color());
78  if (!unusedColors.isEmpty())
79  color = unusedColors.first();
80  else {
81  // search for a color which has been used the less, and which is not the same as in the
82  // layers above and below
83  QMap<QString, int> usage;
84  for (auto* l : m_sampleItem->layers())
85  usage[l->color().name()] += 1;
86 
87  auto sortedByUsage = LayerEditorUtils::predefinedLayerColors();
88  std::stable_sort(
89  sortedByUsage.begin(), sortedByUsage.end(),
90  [&](const QColor& a, const QColor& b) { return usage[a.name()] < usage[b.name()]; });
91 
92 
93  const QColor above =
94  (atIndex > 0) ? m_sampleItem->layers()[atIndex - 1]->color() : QColor();
95  const QColor below = (atIndex < m_sampleItem->layers().size())
96  ? m_sampleItem->layers()[atIndex]->color()
97  : QColor();
98 
99  for (const auto& col : sortedByUsage)
100  if (col != above && col != below) {
101  color = col;
102  break;
103  }
104  }
105 
106  // - create new layer
107  LayerItem* layer = m_sampleItem->addLayer(atIndex);
108  layer->setMaterial(materialItems()->defaultMaterial());
109  layer->setColor(color);
110 
111  ASSERT(m_sampleForm);
112  m_sampleForm->onLayerAdded(layer);
114 
115  emit modified();
116 
117  // expand the new layer's form for better workflow
118  for (auto* c : m_sampleForm->findChildren<LayerForm*>())
119  if (c->layerItem() == layer)
120  c->expand();
121 }
void setMaterial(const MaterialItem *materialItem)
Set the material this item shall use. Stores the identifier, not the pointer!
Form for editing a layer.
Definition: LayerForm.h:29
void setColor(const QColor &color)
Definition: LayerItem.cpp:158
void onLayerAdded(LayerItem *layerItem)
Create widgets for the new layer.
void updateUnits()
Update the presented units in all contained widgets according to current settings.
LayerItem * addLayer(int index=-1)
Creates and inserts a layer at given index.
MaterialItems * materialItems() const
The materials of the current document.
QList< QColor > predefinedLayerColors()

References MultiLayerItem::addLayer(), MultiLayerItem::layers(), m_sampleForm, m_sampleItem, materialItems(), modified(), MultiLayerForm::onLayerAdded(), LayerEditorUtils::predefinedLayerColors(), LayerItem::setColor(), ItemWithMaterial::setMaterial(), and MultiLayerForm::updateUnits().

Referenced by CommandAddLayer::redo().

Here is the call graph for this function:

◆ addLayout()

void SampleEditorController::addLayout ( LayerForm layerItem)

Definition at line 123 of file SampleEditorController.cpp.

124 {
125  auto* newLayoutItem = layerItemWidget->layerItem()->addLayout();
126  layerItemWidget->onLayoutAdded(newLayoutItem);
128 
129  for (auto* layoutForms : layerItemWidget->findChildren<ParticleLayoutForm*>())
130  layoutForms->updateTitle(layerItemWidget->layerItem());
131 
132  emit modified();
133 }
Form for editing a particle layout.

References LayerItem::addLayout(), LayerForm::layerItem(), m_sampleForm, modified(), LayerForm::onLayoutAdded(), and MultiLayerForm::updateUnits().

Referenced by LayerForm::LayerForm().

Here is the call graph for this function:

◆ addParticle() [1/4]

void SampleEditorController::addParticle ( ParticleCompositionItem composition,
FormFactorItemCatalog::Type  type 
)

Definition at line 210 of file SampleEditorController.cpp.

212 {
213  auto* newParticle = createAndInitParticle(formFactorType);
214  compositionItem->addParticle(newParticle);
215 
216  emit modified();
217 
218  // search for composition widget for notification
219  ASSERT(m_sampleForm);
220  for (auto* c : m_sampleForm->findChildren<ParticleCompositionForm*>())
221  if (c->compositionItem() == compositionItem)
222  c->onParticleAdded(newParticle);
224 }
Form for editing a particle composition.
ItemWithParticles * createAndInitParticle(FormFactorItemCatalog::Type formFactorType) const

References ParticleCompositionItem::addParticle(), createAndInitParticle(), m_sampleForm, modified(), and MultiLayerForm::updateUnits().

Here is the call graph for this function:

◆ addParticle() [2/4]

void SampleEditorController::addParticle ( ParticleCompositionItem composition,
ItemWithParticlesCatalog::Type  type 
)

Definition at line 194 of file SampleEditorController.cpp.

196 {
197  auto* newItem = createAndInitParticle(type);
198  compositionItem->addParticle(newItem);
199 
200  emit modified();
201 
202  // search for composition widget for notification
203  ASSERT(m_sampleForm);
204  for (auto* c : m_sampleForm->findChildren<ParticleCompositionForm*>())
205  if (c->compositionItem() == compositionItem)
206  c->onParticleAdded(newItem);
208 }

References ParticleCompositionItem::addParticle(), createAndInitParticle(), m_sampleForm, modified(), and MultiLayerForm::updateUnits().

Here is the call graph for this function:

◆ addParticle() [3/4]

void SampleEditorController::addParticle ( ParticleLayoutItem layout,
FormFactorItemCatalog::Type  t 
)

Definition at line 162 of file SampleEditorController.cpp.

164 {
165  auto* newParticle = createAndInitParticle(formFactorType);
166  layoutItem->addParticle(newParticle);
167 
168  emit modified();
169 
170  // search for particle layout widget for notification
171  ASSERT(m_sampleForm);
172  for (auto* w : m_sampleForm->findChildren<ParticleLayoutForm*>())
173  if (w->layoutItem() == layoutItem)
174  w->onParticleAdded(newParticle);
176 }

References ParticleLayoutItem::addParticle(), createAndInitParticle(), m_sampleForm, modified(), and MultiLayerForm::updateUnits().

Here is the call graph for this function:

◆ addParticle() [4/4]

void SampleEditorController::addParticle ( ParticleLayoutItem layout,
ItemWithParticlesCatalog::Type  type 
)

Definition at line 178 of file SampleEditorController.cpp.

180 {
181  auto* newItem = createAndInitParticle(type);
182  layoutItem->addParticle(newItem);
183 
184  emit modified();
185 
186  // search for particle layout widget for notification
187  ASSERT(m_sampleForm);
188  for (auto* w : m_sampleForm->findChildren<ParticleLayoutForm*>())
189  if (w->layoutItem() == layoutItem)
190  w->onParticleAdded(newItem);
192 }

References ParticleLayoutItem::addParticle(), createAndInitParticle(), m_sampleForm, modified(), and MultiLayerForm::updateUnits().

Referenced by ParticleCompositionForm::ParticleCompositionForm(), and ParticleLayoutForm::ParticleLayoutForm().

Here is the call graph for this function:

◆ createAndInitParticle() [1/2]

ItemWithParticles * SampleEditorController::createAndInitParticle ( FormFactorItemCatalog::Type  formFactorType) const
private

Definition at line 227 of file SampleEditorController.cpp.

228 {
229  auto* newParticle = new ParticleItem(materialItems());
230  newParticle->setFormFactor(FormFactorItemCatalog::create(formFactorType));
231  newParticle->setMaterial(materialItems()->defaultMaterial());
232  return newParticle;
233 }
static FormFactorItem * create(Type type)
Creates the item of the given type.

References FormFactorItemCatalog::create(), and materialItems().

Referenced by addParticle(), and setMesoCrystalBasis().

Here is the call graph for this function:

◆ createAndInitParticle() [2/2]

ItemWithParticles * SampleEditorController::createAndInitParticle ( ItemWithParticlesCatalog::Type  itemType) const
private

Definition at line 236 of file SampleEditorController.cpp.

237 {
238  auto* newItem = ItemWithParticlesCatalog::create(itemType, materialItems());
239 
240  if (auto* p = dynamic_cast<ItemWithMaterial*>(newItem))
241  p->setMaterial(materialItems()->defaultMaterial());
242 
243  if (auto* cs = dynamic_cast<ParticleCoreShellItem*>(newItem)) {
244  cs->createCore(materialItems());
245  cs->createShell(materialItems());
246  cs->core()->setFormFactor(new CylinderItem());
247  cs->shell()->setFormFactor(new CylinderItem());
248  }
249 
250  if (auto* meso = dynamic_cast<MesoCrystalItem*>(newItem); meso && meso->basisParticle())
251  if (auto* p = dynamic_cast<ItemWithMaterial*>(meso->basisParticle()))
252  p->setMaterial(materialItems()->defaultMaterial());
253 
254  return newItem;
255 }
static ItemWithParticles * create(Type type, const MaterialItems *materials)
Creates the item of the given type.
ItemWithParticles * basisParticle() const

References MesoCrystalItem::basisParticle(), ItemWithParticlesCatalog::create(), and materialItems().

Here is the call graph for this function:

◆ materialItems()

MaterialItems * SampleEditorController::materialItems ( ) const

The materials of the current document.

Definition at line 363 of file SampleEditorController.cpp.

364 {
365  return &m_sampleItem->materialItems();
366 }
MaterialItems & materialItems()

References m_sampleItem, and MultiLayerItem::materialItems().

Referenced by LayerForm::LayerForm(), addLayerFromUndo(), createAndInitParticle(), setCoreFormFactor(), and setShellFormFactor().

Here is the call graph for this function:

◆ modified

◆ onStartingToMoveLayer()

void SampleEditorController::onStartingToMoveLayer ( )

Definition at line 416 of file SampleEditorController.cpp.

417 {
418  ASSERT(m_sampleForm);
420 }
void showAddLayerButtons(bool show)
Shows or hides the "Add Layer" buttons.

References m_sampleForm, and MultiLayerForm::showAddLayerButtons().

Referenced by LayerForm::LayerForm().

Here is the call graph for this function:

◆ onStoppedToMoveLayer()

void SampleEditorController::onStoppedToMoveLayer ( QWidget *  widgetToMove,
QWidget *  moveAboveThisWidget 
)

Definition at line 422 of file SampleEditorController.cpp.

424 {
425  ASSERT(m_sampleForm);
427  const auto* moveAboveThisLayerForm = m_sampleForm->findNextLayerForm(moveAboveThisWidget);
428  auto* itemToMove = dynamic_cast<LayerForm*>(widgetToMove)->layerItem();
429  auto* moveBeforeThisItem =
430  moveAboveThisLayerForm != nullptr ? moveAboveThisLayerForm->layerItem() : nullptr;
431 
432  m_sampleItem->moveLayer(itemToMove, moveBeforeThisItem);
433  m_sampleForm->onLayerMoved(itemToMove);
434 
435  // #baLayerEditor: tab order!
436 
437  emit modified();
438 }
LayerItem * layerItem() const
Definition: LayerForm.cpp:188
LayerForm * findNextLayerForm(QWidget *w)
Search for the next LayerForm, starting from the given widget.
void onLayerMoved(LayerItem *layerItem)
Call this when a layerItem has been moved to a different position.
void moveLayer(LayerItem *item, LayerItem *beforeThisLayer)

References MultiLayerForm::findNextLayerForm(), LayerForm::layerItem(), m_sampleForm, m_sampleItem, modified(), MultiLayerItem::moveLayer(), MultiLayerForm::onLayerMoved(), and MultiLayerForm::showAddLayerButtons().

Referenced by LayerForm::LayerForm().

Here is the call graph for this function:

◆ projectDocument()

ProjectDocument * SampleEditorController::projectDocument ( ) const

The current document.

Definition at line 368 of file SampleEditorController.cpp.

369 {
370  return m_document;
371 }

References m_document.

◆ removeLayer()

void SampleEditorController::removeLayer ( LayerItem layerItem)

Definition at line 135 of file SampleEditorController.cpp.

136 {
137  m_undoStack.push(new CommandRemoveLayer(this, layerItem));
138 }
Command to remove a layer from a sample.

References m_undoStack.

Referenced by LayerForm::LayerForm().

◆ removeLayerFromUndo()

void SampleEditorController::removeLayerFromUndo ( int  atIndex)

Definition at line 140 of file SampleEditorController.cpp.

141 {
142  auto* layer = m_sampleItem->layers()[atIndex];
143  emit aboutToRemoveItem(layer);
145  m_sampleItem->removeLayer(layer);
147  emit modified();
148 }
void updateRowVisibilities()
void onAboutToRemoveLayer(LayerItem *layerItem)
Call this before removing (deleting) a LayerItem.
void removeLayer(LayerItem *item)
void aboutToRemoveItem(SampleItem item)

References aboutToRemoveItem(), MultiLayerItem::layers(), m_sampleForm, m_sampleItem, modified(), MultiLayerForm::onAboutToRemoveLayer(), MultiLayerItem::removeLayer(), and MultiLayerForm::updateRowVisibilities().

Referenced by CommandRemoveLayer::redo(), and CommandAddLayer::undo().

Here is the call graph for this function:

◆ removeLayout()

void SampleEditorController::removeLayout ( LayerForm layerItem,
ParticleLayoutItem layout 
)

Definition at line 150 of file SampleEditorController.cpp.

151 {
152  emit aboutToRemoveItem(layout);
153  layerItemWidget->onAboutToRemoveLayout(layout);
154  layerItemWidget->layerItem()->removeLayout(layout);
155 
156  for (auto* layoutForms : layerItemWidget->findChildren<ParticleLayoutForm*>())
157  layoutForms->updateTitle(layerItemWidget->layerItem());
158 
159  emit modified();
160 }

References aboutToRemoveItem(), LayerForm::layerItem(), modified(), LayerForm::onAboutToRemoveLayout(), and LayerItem::removeLayout().

Referenced by ParticleLayoutForm::ParticleLayoutForm().

Here is the call graph for this function:

◆ removeParticle()

void SampleEditorController::removeParticle ( ItemWithParticles item)

Definition at line 285 of file SampleEditorController.cpp.

286 {
287  ASSERT(m_sampleForm);
288 
289  for (auto* layoutForm : m_sampleForm->findChildren<ParticleLayoutForm*>())
290  if (layoutForm->layoutItem()->particles().contains(itemToRemove)) {
291  layoutForm->onAboutToRemoveParticle(itemToRemove);
292 
293  emit aboutToRemoveItem(itemToRemove);
294  layoutForm->layoutItem()->removeParticle(itemToRemove);
295  emit modified();
296  return;
297  }
298 
299  for (auto* c : m_sampleForm->findChildren<ParticleCompositionForm*>())
300  if (c->compositionItem()->particles().contains(itemToRemove)) {
301  c->onAboutToRemoveParticle(itemToRemove);
302 
303  emit aboutToRemoveItem(itemToRemove);
304  c->compositionItem()->removeParticle(itemToRemove);
305  emit modified();
306  return;
307  }
308 }

References aboutToRemoveItem(), m_sampleForm, and modified().

Referenced by MesoCrystalForm::MesoCrystalForm(), ParticleCompositionForm::ParticleCompositionForm(), ParticleCoreShellForm::ParticleCoreShellForm(), and ParticleForm::ParticleForm().

◆ requestViewInRealSpace

◆ sampleForm()

MultiLayerForm * SampleEditorController::sampleForm ( ) const

The current form.

Definition at line 53 of file SampleEditorController.cpp.

54 {
55  return m_sampleForm;
56 }

References m_sampleForm.

Referenced by CommandRemoveLayer::undo().

◆ sampleItem()

MultiLayerItem * SampleEditorController::sampleItem ( ) const

◆ selectInterference()

void SampleEditorController::selectInterference ( InterferenceForm widget,
int  newIndex 
)

Definition at line 472 of file SampleEditorController.cpp.

473 {
474  widget->layoutItem()->interference().setCurrentIndex(newIndex);
475  widget->onInterferenceTypeChanged();
477 
478  // Disable/enable total density property in the particle layout, depending on type of
479  // interference function.
480  QWidget* parent = widget->parentWidget();
481  while (parent != nullptr && dynamic_cast<ParticleLayoutForm*>(parent) == nullptr)
482  parent = parent->parentWidget();
483 
484  if (auto* particleLayoutForm = dynamic_cast<ParticleLayoutForm*>(parent)) {
485  particleLayoutForm->updateDensityEnabling();
486  particleLayoutForm->updateDensityValue();
487  }
488 
489  emit modified();
490 }
void onInterferenceTypeChanged()
ParticleLayoutItem * layoutItem() const
SelectionDescriptor< InterferenceItem * > interference() const

References ParticleLayoutItem::interference(), InterferenceForm::layoutItem(), m_sampleForm, modified(), InterferenceForm::onInterferenceTypeChanged(), and MultiLayerForm::updateUnits().

Referenced by InterferenceForm::InterferenceForm().

Here is the call graph for this function:

◆ selectMaterial()

void SampleEditorController::selectMaterial ( ItemWithMaterial item,
const QString &  newMaterialIdentifier 
)

Definition at line 373 of file SampleEditorController.cpp.

375 {
376  item->setMaterial(newMaterialIdentifier);
377 
378  // update Layer title
379  ASSERT(m_sampleForm);
380  for (auto* c : m_sampleForm->findChildren<LayerForm*>())
381  if (c->layerItem() == item)
382  c->updateTitle();
383 
384  // #baLayerEditor notify all material users (update link info)
385  emit modified();
386 }

References m_sampleForm, modified(), and ItemWithMaterial::setMaterial().

Referenced by MaterialInplaceForm::selectMaterial().

Here is the call graph for this function:

◆ setCoreFormFactor()

void SampleEditorController::setCoreFormFactor ( ParticleCoreShellForm widget,
FormFactorItemCatalog::Type  type 
)

Definition at line 257 of file SampleEditorController.cpp.

259 {
260  auto* particleCoreShell = widget->coreShellItem();
261 
262  if (particleCoreShell->core() == nullptr)
263  particleCoreShell->createCore(materialItems());
264 
265  particleCoreShell->core()->setFormFactor(FormFactorItemCatalog::create(type));
266  widget->createCoreWidgets();
268  emit modified();
269 }
ParticleCoreShellItem * coreShellItem() const
ParticleItem * createCore(const MaterialItems *materials)
void setFormFactor(FormFactorItem *p)

References ParticleCoreShellForm::coreShellItem(), FormFactorItemCatalog::create(), ParticleCoreShellItem::createCore(), ParticleCoreShellForm::createCoreWidgets(), m_sampleForm, materialItems(), modified(), ParticleItem::setFormFactor(), and MultiLayerForm::updateUnits().

Referenced by ParticleCoreShellForm::onCoreComboChanged().

Here is the call graph for this function:

◆ setCurrentIndex()

void SampleEditorController::setCurrentIndex ( AbstractSelectionContainerForm widget,
int  index,
const AbstractSelectionDescriptor d 
)

Definition at line 349 of file SampleEditorController.cpp.

351 {
352  d.setCurrentIndex(index);
353  widget->createContent();
355  emit modified();
356 }
virtual void createContent()=0
virtual void setCurrentIndex(int newIndex) const =0
Set currently selected option.

References AbstractSelectionContainerForm::createContent(), m_sampleForm, modified(), AbstractSelectionDescriptor::setCurrentIndex(), and MultiLayerForm::updateUnits().

Referenced by AbstractSelectionContainerForm::initUI().

Here is the call graph for this function:

◆ setDensityRelatedValue()

void SampleEditorController::setDensityRelatedValue ( InterferenceItem interferenceItem,
double  newValue,
DoubleDescriptor  d 
)

Set an interference function's value which affects the total particle density of the containing particle layout.

Some values in interference settings affect the total density in the particle layout which contains this interference function. Call this method to provide all the related updating (data & UI).

Definition at line 402 of file SampleEditorController.cpp.

404 {
405  setDouble(newValue, d);
406 
407  // -- notify the containing particle layout UI about changed value
408  ASSERT(m_sampleForm);
409  for (auto* c : m_sampleForm->findChildren<ParticleLayoutForm*>())
410  if (c->layoutItem()->interference() == interferenceItem) {
411  c->updateDensityValue();
412  break;
413  }
414 }
void setDouble(double newValue, DoubleDescriptor d)

References m_sampleForm, and setDouble().

Referenced by LatticeTypeSelectionForm::createContent(), and InterferenceForm::createInterferenceWidgets().

Here is the call graph for this function:

◆ setDouble()

void SampleEditorController::setDouble ( double  newValue,
DoubleDescriptor  d 
)

Definition at line 310 of file SampleEditorController.cpp.

311 {
312  m_undoStack.push(new CommandChangeValue(d.label, this, d.get(), newValue, d.path()));
313  d.set(newValue);
314  emit modified();
315 }
Command to change a double value.
QString label
A label text (short, no trailing colon)
function< void(double)> set
function to set the value
function< double()> get
function to get the current value
function< QString()> path
Path describing this value. Used e.g. for undo/redo.

References DoubleDescriptor::get, DoubleDescriptor::label, m_undoStack, modified(), DoubleDescriptor::path, and DoubleDescriptor::set.

Referenced by LayerEditorUtils::addMultiPropertyToGrid(), FormLayouter::insertValue(), setDensityRelatedValue(), and setMaterialValue().

◆ setDoubleFromUndo()

void SampleEditorController::setDoubleFromUndo ( double  newValue,
const QString &  path 
)

Definition at line 317 of file SampleEditorController.cpp.

318 {
319  ASSERT(m_sampleForm);
320 
321  DoubleSpinBox* spinBox = nullptr;
322  for (auto* s : m_sampleForm->findChildren<DoubleSpinBox*>()) {
323  if (s->valueDescriptor().path() == path) {
324  spinBox = s;
325  break;
326  }
327  }
328 
329  if (!spinBox)
330  return;
331 
332  spinBox->valueDescriptor().set(newValue);
333 
334  m_sampleForm->ensureVisible(spinBox);
335  QSignalBlocker b(spinBox);
336  spinBox->setBaseValue(newValue);
337  spinBox->setFocus();
338  spinBox->selectAll();
339 
340  emit modified();
341 }
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
const DoubleDescriptor & valueDescriptor() const
The descriptor on which this spinbox operates.
void setBaseValue(double baseValue)
Set the base value (unit is the one of the contained descriptor).
void ensureVisible(QWidget *w)

References MultiLayerForm::ensureVisible(), m_sampleForm, modified(), DoubleDescriptor::set, DoubleSpinBox::setBaseValue(), and DoubleSpinBox::valueDescriptor().

Referenced by CommandChangeValue::redo(), and CommandChangeValue::undo().

Here is the call graph for this function:

◆ setInt()

void SampleEditorController::setInt ( int  newValue,
UIntDescriptor  d 
)

Definition at line 343 of file SampleEditorController.cpp.

344 {
345  d.set(newValue);
346  emit modified();
347 }
function< void(uint)> set
function to set the value

References modified(), and UIntDescriptor::set.

◆ setIntegrateOverXi()

void SampleEditorController::setIntegrateOverXi ( LatticeTypeSelectionForm widget,
bool  newValue 
)

Definition at line 492 of file SampleEditorController.cpp.

493 {
494  widget->interferenceItem()->setXiIntegration(newValue);
495  widget->onIntegrateOverXiChanged();
496  emit modified();
497 }
void setXiIntegration(bool xiIntegration)
Interference2DAbstractLatticeItem * interferenceItem() const

References LatticeTypeSelectionForm::interferenceItem(), modified(), LatticeTypeSelectionForm::onIntegrateOverXiChanged(), and Interference2DAbstractLatticeItem::setXiIntegration().

Referenced by LatticeTypeSelectionForm::createContent().

Here is the call graph for this function:

◆ setMaterialValue()

void SampleEditorController::setMaterialValue ( ItemWithMaterial item,
double  newValue,
DoubleDescriptor  d 
)

Definition at line 388 of file SampleEditorController.cpp.

390 {
391  setDouble(newValue, d);
392 
393  // -- notify all other users of this material (update values in the UI)
394  ASSERT(m_sampleForm);
395  for (auto* c : m_sampleForm->findChildren<MaterialInplaceForm*>())
396  if (c->itemWithMaterial() != item
397  && c->itemWithMaterial()->materialIdentifier() == item->materialIdentifier())
398  c->updateValues();
399  emit modified();
400 }
QString materialIdentifier() const
Form to select a material and to edit it in-place.

References m_sampleForm, ItemWithMaterial::materialIdentifier(), modified(), and setDouble().

Referenced by MaterialInplaceForm::createWidgets().

Here is the call graph for this function:

◆ setMesoCrystalBasis() [1/2]

void SampleEditorController::setMesoCrystalBasis ( MesoCrystalForm widget,
FormFactorItemCatalog::Type  type 
)

Definition at line 462 of file SampleEditorController.cpp.

464 {
465  auto* meso = widget->mesoCrystalItem();
466  meso->setBasis(createAndInitParticle(type));
467  widget->createBasisWidgets();
469  emit modified();
470 }
MesoCrystalItem * mesoCrystalItem() const
void setBasis(ItemWithParticles *basis)

References createAndInitParticle(), MesoCrystalForm::createBasisWidgets(), m_sampleForm, MesoCrystalForm::mesoCrystalItem(), modified(), MesoCrystalItem::setBasis(), and MultiLayerForm::updateUnits().

Here is the call graph for this function:

◆ setMesoCrystalBasis() [2/2]

void SampleEditorController::setMesoCrystalBasis ( MesoCrystalForm widget,
ItemWithParticlesCatalog::Type  type 
)

Definition at line 452 of file SampleEditorController.cpp.

454 {
455  auto* meso = widget->mesoCrystalItem();
456  meso->setBasis(createAndInitParticle(type));
457  widget->createBasisWidgets();
459  emit modified();
460 }

References createAndInitParticle(), MesoCrystalForm::createBasisWidgets(), m_sampleForm, MesoCrystalForm::mesoCrystalItem(), modified(), MesoCrystalItem::setBasis(), and MultiLayerForm::updateUnits().

Referenced by MesoCrystalForm::onBasisComboChanged().

Here is the call graph for this function:

◆ setMultiLayerForm()

void SampleEditorController::setMultiLayerForm ( MultiLayerForm view)

Set the current form.

The form can change e.g. when a different sample gets the current one in the layer editor. Also nullptr is allowed.

Definition at line 48 of file SampleEditorController.cpp.

49 {
50  m_sampleForm = view;
51 }

References m_sampleForm.

◆ setSampleDescription()

void SampleEditorController::setSampleDescription ( const QString &  description)

Definition at line 446 of file SampleEditorController.cpp.

447 {
448  m_sampleItem->setDescription(description);
449  emit modified();
450 }
void setDescription(const QString &description)

References m_sampleItem, modified(), and MultiLayerItem::setDescription().

Referenced by MultiLayerForm::MultiLayerForm().

Here is the call graph for this function:

◆ setSampleName()

void SampleEditorController::setSampleName ( const QString &  name)

Definition at line 440 of file SampleEditorController.cpp.

441 {
443  emit modified();
444 }
void setSampleName(const QString &name)
QString const & name(EShape k)
Definition: particles.cpp:20

References m_sampleItem, modified(), GUI::RealSpace::Particles::name(), and MultiLayerItem::setSampleName().

Referenced by MultiLayerForm::MultiLayerForm().

Here is the call graph for this function:

◆ setShellFormFactor()

void SampleEditorController::setShellFormFactor ( ParticleCoreShellForm widget,
FormFactorItemCatalog::Type  type 
)

Definition at line 271 of file SampleEditorController.cpp.

273 {
274  auto* particleCoreShell = widget->coreShellItem();
275 
276  if (particleCoreShell->shell() == nullptr)
277  particleCoreShell->createShell(materialItems());
278 
279  particleCoreShell->shell()->setFormFactor(FormFactorItemCatalog::create(type));
280  widget->createShellWidgets();
282  emit modified();
283 }
ParticleItem * createShell(const MaterialItems *materials)

References ParticleCoreShellForm::coreShellItem(), FormFactorItemCatalog::create(), ParticleCoreShellItem::createShell(), ParticleCoreShellForm::createShellWidgets(), m_sampleForm, materialItems(), modified(), ParticleItem::setFormFactor(), and MultiLayerForm::updateUnits().

Referenced by ParticleCoreShellForm::onShellComboChanged().

Here is the call graph for this function:

◆ undoStack()

QUndoStack * SampleEditorController::undoStack ( )

The contained undo stack.

Definition at line 358 of file SampleEditorController.cpp.

359 {
360  return &m_undoStack;
361 }

References m_undoStack.

Member Data Documentation

◆ m_document

ProjectDocument* SampleEditorController::m_document
private

Definition at line 133 of file SampleEditorController.h.

Referenced by projectDocument().

◆ m_sampleForm

◆ m_sampleItem

◆ m_undoStack

QUndoStack SampleEditorController::m_undoStack
private

Definition at line 130 of file SampleEditorController.h.

Referenced by addLayer(), removeLayer(), setDouble(), and undoStack().


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