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

Description

Form for editing a particle composition.

Definition at line 28 of file ParticleCompositionForm.h.

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

Public Member Functions

 ParticleCompositionForm (QWidget *parent, ParticleCompositionItem *compositionItem, SampleEditorController *ec, bool allowRemove=true)
 
ParticleCompositionItemcompositionItem () const
 
void enableStructureEditing (bool b)
 
void onAboutToRemoveParticle (ItemWithParticles *item)
 
void onParticleAdded (ItemWithParticles *item)
 

Private Attributes

ParticleCompositionItemm_compositionItem
 
SampleEditorControllerm_ec
 
QFormLayout * m_layout
 
QAction * m_removeAction = nullptr
 
QList< QWidget * > m_structureEditingWidgets
 

Constructor & Destructor Documentation

◆ ParticleCompositionForm()

ParticleCompositionForm::ParticleCompositionForm ( QWidget *  parent,
ParticleCompositionItem compositionItem,
SampleEditorController ec,
bool  allowRemove = true 
)

Definition at line 26 of file ParticleCompositionForm.cpp.

29  : QGroupBox(parent)
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);
38  layouter.addSelection(compositionItem->rotation());
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 }
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
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
ParticleCompositionItem * m_compositionItem
ParticleCompositionItem * compositionItem() const
QList< QWidget * > m_structureEditingWidgets
QVector< ItemWithParticles * > particles() const
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)

References ItemWithParticles::abundance(), SampleEditorController::addParticle(), FormLayouter::addRow(), FormLayouter::addSelection(), FormLayouter::addStructureEditingRow(), FormLayouter::addValue(), FormLayouter::addVector(), compositionItem(), LayerEditorUtils::createAddParticleButton(), ActionFactory::createRemoveAction(), ActionFactory::createShowInRealSpaceAction(), LayerEditorUtils::createWidgetForItemWithParticles(), GroupBoxCollapser::installIntoGroupBox(), FormLayouter::layout(), m_layout, m_removeAction, m_structureEditingWidgets, ParticleCompositionItem::particles(), ItemWithParticles::positionVector(), SampleEditorController::removeParticle(), SampleEditorController::requestViewInRealSpace(), ItemWithParticles::rotation(), and FormLayouter::setContentsMargins().

Here is the call graph for this function:

Member Function Documentation

◆ compositionItem()

ParticleCompositionItem * ParticleCompositionForm::compositionItem ( ) const

Definition at line 75 of file ParticleCompositionForm.cpp.

76 {
77  return m_compositionItem;
78 }

References m_compositionItem.

Referenced by ParticleCompositionForm().

◆ enableStructureEditing()

void ParticleCompositionForm::enableStructureEditing ( bool  b)

Definition at line 67 of file ParticleCompositionForm.cpp.

68 {
69  if (m_removeAction)
70  m_removeAction->setVisible(b);
71  for (auto* w : m_structureEditingWidgets)
72  w->setVisible(b);
73 }

References m_removeAction, and m_structureEditingWidgets.

◆ onAboutToRemoveParticle()

void ParticleCompositionForm::onAboutToRemoveParticle ( ItemWithParticles item)

Definition at line 90 of file ParticleCompositionForm.cpp.

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 }

References m_compositionItem, m_layout, and ParticleCompositionItem::particles().

Here is the call graph for this function:

◆ onParticleAdded()

void ParticleCompositionForm::onParticleAdded ( ItemWithParticles item)

Definition at line 80 of file ParticleCompositionForm.cpp.

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 }

References LayerEditorUtils::createWidgetForItemWithParticles(), m_compositionItem, m_ec, m_layout, and ParticleCompositionItem::particles().

Here is the call graph for this function:

Member Data Documentation

◆ m_compositionItem

ParticleCompositionItem* ParticleCompositionForm::m_compositionItem
private

◆ m_ec

SampleEditorController* ParticleCompositionForm::m_ec
private

Definition at line 43 of file ParticleCompositionForm.h.

Referenced by onParticleAdded().

◆ m_layout

QFormLayout* ParticleCompositionForm::m_layout
private

◆ m_removeAction

QAction* ParticleCompositionForm::m_removeAction = nullptr
private

Definition at line 42 of file ParticleCompositionForm.h.

Referenced by ParticleCompositionForm(), and enableStructureEditing().

◆ m_structureEditingWidgets

QList<QWidget*> ParticleCompositionForm::m_structureEditingWidgets
private

Definition at line 44 of file ParticleCompositionForm.h.

Referenced by ParticleCompositionForm(), and enableStructureEditing().


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