BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleLayoutForm.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/SampleDesigner/ParticleLayoutForm.cpp
6 //! @brief Implements class ParticleLayoutForm
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include "GUI/Util/ActionFactory.h"
27 
28 #include <QAction>
29 #include <QPushButton>
30 
33  : QGroupBox(parent)
34  , m_layoutItem(layoutItem)
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 }
70 
72 {
73  m_removeAction->setVisible(b);
74  for (auto* w : m_structureEditingWidgets)
75  w->setVisible(b);
76 }
77 
79 {
80  return m_layoutItem;
81 }
82 
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 }
92 
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 }
101 
103 {
105 }
106 
108 {
110 }
111 
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 }
Defines class ActionFactory.
Defines class DoubleSpinBox.
Defines class GroupBoxCollapser.
Defines class InterferenceForm.
Defines InterferenceItems's classes.
Defines abstract item with a material property.
Defines class LayerEditorUtils.
Defines class LayerForm.
Defines class LayerItem.
Defines class ParticleLayoutForm.
Defines class ParticleLayoutItem.
Defines class SampleEditorController.
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
void updateValue()
Update the shown value to the one contained in the value descriptor.
Utility class to populate a QFormLayout.
Definition: FormLayouter.h:36
void addStructureEditingRow(QPushButton *button)
Adds a button for structure editing.
QFormLayout * layout()
The layout where this layouter is operating on.
int addRow(QWidget *w)
Convenience method to add a widget.
T widgetAt(int row, QFormLayout::ItemRole role)
Find a widget in the given position.
Definition: FormLayouter.h:177
int addValue(const DoubleDescriptor &d)
Adds a row with a bold printed label and a DoubleSpinBox.
void setContentsMargins(int left, int top, int right, int bottom)
Convenience method to set the contents margins.
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)
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...
Form for editing interference functions.
Form for editing a layer.
Definition: LayerForm.h:29
LayerItem * layerItem() const
Definition: LayerForm.cpp:188
QVector< ParticleLayoutItem * > layouts() const
Definition: LayerItem.cpp:136
void enableStructureEditing(bool b)
void updateDensityEnabling()
Disable/enable total density property depending on type of interference function.
QFormLayout * m_layout
void onParticleAdded(ItemWithParticles *item)
SampleEditorController * m_ec
void onAboutToRemoveParticle(ItemWithParticles *item)
void updateTitle(const LayerItem *layerItem)
ParticleLayoutForm(LayerForm *parent, ParticleLayoutItem *layoutItem, SampleEditorController *ec)
GroupBoxCollapser * m_collapser
void updateDensityValue()
Update the shown density value.
ParticleLayoutItem * m_layoutItem
ParticleLayoutItem * layoutItem() const
DoubleSpinBox * m_totalDensitySpinBox
QList< QWidget * > m_structureEditingWidgets
bool totalDensityIsDefinedByInterference() const
Returns whether total density is defined by the currently selected interference.
DoubleDescriptor weight() const
DoubleDescriptor totalDensity() const
The real density.
QVector< ItemWithParticles * > particles() const
The particles this layout contains.
Class to modify a sample from the layer oriented sample editor.
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)