BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleCompositionForm.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/SampleDesigner/ParticleCompositionForm.cpp
6 //! @brief Implements class ParticleCompositionForm
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 
18 #include "GUI/Util/ActionFactory.h"
22 
23 #include <QAction>
24 #include <QPushButton>
25 
27  ParticleCompositionItem* compositionItem,
28  SampleEditorController* ec, bool allowRemove)
29  : QGroupBox(parent)
30  , m_compositionItem(compositionItem)
31  , m_ec(ec)
32 {
33  setTitle("Composition of particles");
34 
35  FormLayouter layouter(this, ec);
36  layouter.setContentsMargins(30, 6, 0, 0);
37  layouter.addVector(compositionItem->positionVector(), false);
39  layouter.addValue(compositionItem->abundance());
40 
41  for (auto* particle : compositionItem->particles())
42  layouter.addRow(
43  LayerEditorUtils::createWidgetForItemWithParticles(this, particle, false, ec));
44 
46  this, [=](FormFactorItemCatalog::Type type) { ec->addParticle(compositionItem, type); },
48 
50  layouter.addStructureEditingRow(btn);
51 
52  auto* collapser = GroupBoxCollapser::installIntoGroupBox(this);
53 
54  auto* showInRealSpaceAction = ActionFactory::createShowInRealSpaceAction(
55  this, "particle composition", [=] { ec->requestViewInRealSpace(compositionItem); });
56  collapser->addAction(showInRealSpaceAction);
57 
58  if (allowRemove) {
60  this, "particle composition", [=] { ec->removeParticle(compositionItem); });
61  collapser->addAction(m_removeAction);
62  }
63 
64  m_layout = layouter.layout();
65 }
66 
68 {
69  if (m_removeAction)
70  m_removeAction->setVisible(b);
71  for (auto* w : m_structureEditingWidgets)
72  w->setVisible(b);
73 }
74 
76 {
77  return m_compositionItem;
78 }
79 
81 {
82  int index = m_compositionItem->particles().indexOf(p);
83  const int rowInLayout =
84  m_layout->rowCount() - 1 - (m_compositionItem->particles().size() - 1) + index; // -1: btn
85 
86  m_layout->insertRow(rowInLayout,
88 }
89 
91 {
92  int index = m_compositionItem->particles().indexOf(item);
93  const int rowInLayout =
94  m_layout->rowCount() - m_compositionItem->particles().size() - 1 + index; // -1: btn
95 
96  m_layout->removeRow(rowInLayout);
97 }
Defines class ActionFactory.
Defines classes FormLayouter.
Defines class GroupBoxCollapser.
Defines class LayerEditorUtils.
Defines class ParticleCompositionForm.
Defines class ParticleCompositionItem.
Defines class VectorDescriptor.
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.
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.
int addValue(const DoubleDescriptor &d)
Adds a row with a bold printed label and a DoubleSpinBox.
int addVector(const VectorDescriptor &d, bool vertically=true)
Adds a row with a bold printed label and the 3 values of a 3D vector.
void setContentsMargins(int left, int top, int right, int bottom)
Convenience method to set the contents margins.
int addSelection(const SelectionDescriptor< T > &d)
Add a row with a selection.
Definition: FormLayouter.h:170
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
DoubleDescriptor abundance() const
SelectionDescriptor< RotationItem * > rotation()
Returns selection descriptor for rotation methods.
VectorDescriptor positionVector() const
SampleEditorController * m_ec
void onAboutToRemoveParticle(ItemWithParticles *item)
ParticleCompositionItem * m_compositionItem
ParticleCompositionForm(QWidget *parent, ParticleCompositionItem *compositionItem, SampleEditorController *ec, bool allowRemove=true)
ParticleCompositionItem * compositionItem() const
void onParticleAdded(ItemWithParticles *item)
QList< QWidget * > m_structureEditingWidgets
QVector< ItemWithParticles * > particles() const
Class to modify a sample from the layer oriented sample editor.
void requestViewInRealSpace(SampleItem item)
void addParticle(ParticleLayoutItem *layout, ItemWithParticlesCatalog::Type type)
void removeParticle(ItemWithParticles *item)
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)