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

Description

Form for editing a particle layout.

Definition at line 32 of file ParticleLayoutForm.h.

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

Public Member Functions

 ParticleLayoutForm (LayerForm *parent, ParticleLayoutItem *layoutItem, SampleEditorController *ec)
 
void enableStructureEditing (bool b)
 
ParticleLayoutItemlayoutItem () const
 
void onAboutToRemoveParticle (ItemWithParticles *item)
 
void onParticleAdded (ItemWithParticles *item)
 
void updateDensityEnabling ()
 Disable/enable total density property depending on type of interference function. More...
 
void updateDensityValue ()
 Update the shown density value. More...
 
void updateTitle (const LayerItem *layerItem)
 

Private Attributes

GroupBoxCollapserm_collapser
 
SampleEditorControllerm_ec
 
QFormLayout * m_layout
 
ParticleLayoutItemm_layoutItem
 
QAction * m_removeAction
 
QList< QWidget * > m_structureEditingWidgets
 
DoubleSpinBoxm_totalDensitySpinBox
 

Constructor & Destructor Documentation

◆ ParticleLayoutForm()

ParticleLayoutForm::ParticleLayoutForm ( LayerForm parent,
ParticleLayoutItem layoutItem,
SampleEditorController ec 
)

Definition at line 31 of file ParticleLayoutForm.cpp.

33  : QGroupBox(parent)
35  , m_ec(ec)
36 {
37  FormLayouter layouter(this, ec);
38  layouter.setContentsMargins(30, 6, 0, 0);
39  int rowOfTotalDensity = layouter.addValue(m_layoutItem->totalDensity());
41  layouter.widgetAt<DoubleSpinBox*>(rowOfTotalDensity, QFormLayout::FieldRole);
42  ASSERT(m_totalDensitySpinBox);
43  layouter.addValue(m_layoutItem->weight());
44  layouter.addRow(new InterferenceForm(this, layoutItem, ec));
45 
46  for (auto* particle : m_layoutItem->particles())
47  layouter.addRow(
48  LayerEditorUtils::createWidgetForItemWithParticles(this, particle, true, ec));
49 
51  this, [=](FormFactorItemCatalog::Type type) { ec->addParticle(layoutItem, type); },
52  [=](ItemWithParticlesCatalog::Type type) { ec->addParticle(layoutItem, type); });
54  layouter.addStructureEditingRow(btn);
55 
57  this, "particle layout", [=] { ec->removeLayout(parent, layoutItem); });
58 
59  auto* showInRealSpaceAction = ActionFactory::createShowInRealSpaceAction(
60  this, "particle layout", [=] { ec->requestViewInRealSpace(layoutItem); });
61 
63  m_collapser->addAction(showInRealSpaceAction);
65  m_layout = layouter.layout();
66 
68  updateTitle(parent->layerItem());
69 }
static QAction * createShowInRealSpaceAction(QObject *parent, const QString &what, std::function< void()> slot=nullptr)
Create "show in RealSpace" action.
static QAction * createRemoveAction(QObject *parent, const QString &what, std::function< void()> slot=nullptr)
Create "remove" action.
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
Utility class to populate a QFormLayout.
Definition: FormLayouter.h:36
void addAction(QAction *action)
Add a tool button to the title bar, connected to the given action.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
Form for editing interference functions.
LayerItem * layerItem() const
Definition: LayerForm.cpp:188
void updateDensityEnabling()
Disable/enable total density property depending on type of interference function.
QFormLayout * m_layout
SampleEditorController * m_ec
void updateTitle(const LayerItem *layerItem)
GroupBoxCollapser * m_collapser
ParticleLayoutItem * m_layoutItem
ParticleLayoutItem * layoutItem() const
DoubleSpinBox * m_totalDensitySpinBox
QList< QWidget * > m_structureEditingWidgets
DoubleDescriptor weight() const
DoubleDescriptor totalDensity() const
The real density.
QVector< ItemWithParticles * > particles() const
The particles this layout contains.
void removeLayout(LayerForm *layerItem, ParticleLayoutItem *layout)
void requestViewInRealSpace(SampleItem item)
void addParticle(ParticleLayoutItem *layout, ItemWithParticlesCatalog::Type type)
QWidget * createWidgetForItemWithParticles(QWidget *parentWidget, ItemWithParticles *itemWithParticles, bool allowAbundance, SampleEditorController *ec, bool allowRemove=true)
QPushButton * createAddParticleButton(QWidget *parentWidget, std::function< void(FormFactorItemCatalog::Type t)> slotAddFormFactor, std::function< void(ItemWithParticlesCatalog::Type t)> slotAddParticle)

References GroupBoxCollapser::addAction(), SampleEditorController::addParticle(), FormLayouter::addRow(), FormLayouter::addStructureEditingRow(), FormLayouter::addValue(), LayerEditorUtils::createAddParticleButton(), ActionFactory::createRemoveAction(), ActionFactory::createShowInRealSpaceAction(), LayerEditorUtils::createWidgetForItemWithParticles(), GroupBoxCollapser::installIntoGroupBox(), LayerForm::layerItem(), FormLayouter::layout(), layoutItem(), m_collapser, m_layout, m_layoutItem, m_removeAction, m_structureEditingWidgets, m_totalDensitySpinBox, ParticleLayoutItem::particles(), SampleEditorController::removeLayout(), SampleEditorController::requestViewInRealSpace(), FormLayouter::setContentsMargins(), ParticleLayoutItem::totalDensity(), updateDensityEnabling(), updateTitle(), ParticleLayoutItem::weight(), and FormLayouter::widgetAt().

Here is the call graph for this function:

Member Function Documentation

◆ enableStructureEditing()

void ParticleLayoutForm::enableStructureEditing ( bool  b)

Definition at line 71 of file ParticleLayoutForm.cpp.

72 {
73  m_removeAction->setVisible(b);
74  for (auto* w : m_structureEditingWidgets)
75  w->setVisible(b);
76 }

References m_removeAction, and m_structureEditingWidgets.

◆ layoutItem()

ParticleLayoutItem * ParticleLayoutForm::layoutItem ( ) const

Definition at line 78 of file ParticleLayoutForm.cpp.

79 {
80  return m_layoutItem;
81 }

References m_layoutItem.

Referenced by ParticleLayoutForm().

◆ onAboutToRemoveParticle()

void ParticleLayoutForm::onAboutToRemoveParticle ( ItemWithParticles item)

Definition at line 93 of file ParticleLayoutForm.cpp.

94 {
95  int index = m_layoutItem->particles().indexOf(item);
96  const int rowInLayout =
97  m_layout->rowCount() - m_layoutItem->particles().size() - 1 + index; // -1: btn
98 
99  m_layout->removeRow(rowInLayout);
100 }

References m_layout, m_layoutItem, and ParticleLayoutItem::particles().

Here is the call graph for this function:

◆ onParticleAdded()

void ParticleLayoutForm::onParticleAdded ( ItemWithParticles item)

Definition at line 83 of file ParticleLayoutForm.cpp.

84 {
85  int index = m_layoutItem->particles().indexOf(p);
86  const int rowInLayout =
87  m_layout->rowCount() - 1 - (m_layoutItem->particles().size() - 1) + index; // -1: btn
88 
89  m_layout->insertRow(rowInLayout,
91 }

References LayerEditorUtils::createWidgetForItemWithParticles(), m_ec, m_layout, m_layoutItem, and ParticleLayoutItem::particles().

Here is the call graph for this function:

◆ updateDensityEnabling()

void ParticleLayoutForm::updateDensityEnabling ( )

Disable/enable total density property depending on type of interference function.

E.g. 2-dimensional interference calculates density automatically, so the property shown in the particle layout shall be disabled.

Definition at line 102 of file ParticleLayoutForm.cpp.

103 {
105 }
bool totalDensityIsDefinedByInterference() const
Returns whether total density is defined by the currently selected interference.

References m_layoutItem, m_totalDensitySpinBox, and ParticleLayoutItem::totalDensityIsDefinedByInterference().

Referenced by ParticleLayoutForm().

Here is the call graph for this function:

◆ updateDensityValue()

void ParticleLayoutForm::updateDensityValue ( )

Update the shown density value.

This does not update any internal values, it only refreshes the shown value.

Definition at line 107 of file ParticleLayoutForm.cpp.

108 {
110 }
void updateValue()
Update the shown value to the one contained in the value descriptor.

References m_totalDensitySpinBox, and DoubleSpinBox::updateValue().

Here is the call graph for this function:

◆ updateTitle()

void ParticleLayoutForm::updateTitle ( const LayerItem layerItem)

Definition at line 112 of file ParticleLayoutForm.cpp.

113 {
114  const auto layouts = layerItem->layouts();
115  if (layouts.size() > 1)
116  m_collapser->setTitle("Particle layout "
117  + QString::number(layouts.indexOf(m_layoutItem) + 1));
118  else
119  m_collapser->setTitle("Particle layout");
120 }
void setTitle(const QString &title)
Set the title of the group box. Do not use the method groupBox->setTitle() any more once the add-on i...
QVector< ParticleLayoutItem * > layouts() const
Definition: LayerItem.cpp:136

References LayerItem::layouts(), m_collapser, m_layoutItem, and GroupBoxCollapser::setTitle().

Referenced by ParticleLayoutForm().

Here is the call graph for this function:

Member Data Documentation

◆ m_collapser

GroupBoxCollapser* ParticleLayoutForm::m_collapser
private

Definition at line 63 of file ParticleLayoutForm.h.

Referenced by ParticleLayoutForm(), and updateTitle().

◆ m_ec

SampleEditorController* ParticleLayoutForm::m_ec
private

Definition at line 60 of file ParticleLayoutForm.h.

Referenced by onParticleAdded().

◆ m_layout

QFormLayout* ParticleLayoutForm::m_layout
private

◆ m_layoutItem

ParticleLayoutItem* ParticleLayoutForm::m_layoutItem
private

◆ m_removeAction

QAction* ParticleLayoutForm::m_removeAction
private

Definition at line 59 of file ParticleLayoutForm.h.

Referenced by ParticleLayoutForm(), and enableStructureEditing().

◆ m_structureEditingWidgets

QList<QWidget*> ParticleLayoutForm::m_structureEditingWidgets
private

Definition at line 61 of file ParticleLayoutForm.h.

Referenced by ParticleLayoutForm(), and enableStructureEditing().

◆ m_totalDensitySpinBox

DoubleSpinBox* ParticleLayoutForm::m_totalDensitySpinBox
private

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