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

Description

A widget to contain a selection, defined by a SelectionDescriptor.

This SelectionContainerForm is limited to contain the selection combo box and a list of double values represented by DoubleDescriptors. The list of DoubleDescriptors is queried by calling LayerEditorUtils::doubleDescriptorsOfItem(). To have the correct DoubleDescriptors on this form, you may have to overload this method according to your class and your needs. The overload will expect the template type you defined for SelectionDescriptor.

Example: SelectionDescriptor<RotationItem*> => LayerEditorUtils::doubleDescriptorsOfItem(RotationItem*)

The connection from selection combo -> SelectionDescriptor is made via SampleEditorController::setCurrentIndex(), where a command can be used for undo purposes.

For each DoubleDescriptor, a unit-aware DoubleSpinBox is created. The connection from each spinbox to the DoubleDescriptor is made via SampleEditorController::setDouble(), where a command can be used for undo purposes.

If a more complex selection shall be realized (e.g. with sub-selections or different value types), this class is not sufficient.

Definition at line 100 of file SelectionContainerForm.h.

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

Public Member Functions

template<typename T >
 SelectionContainerForm (QWidget *parent, const SelectionDescriptor< T > &d, SampleEditorController *ec)
 
virtual void createContent ()
 

Protected Member Functions

template<typename T >
void initUI (const SelectionDescriptor< T > &d)
 

Protected Attributes

QComboBox * m_combo
 
SampleEditorControllerm_ec
 
QGridLayout * m_gridLayout
 

Private Member Functions

void clear ()
 Remove all descriptors from the layout. More...
 

Private Attributes

function< DoubleDescriptors()> currentValues = nullptr
 

Constructor & Destructor Documentation

◆ SelectionContainerForm()

template<typename T >
SelectionContainerForm::SelectionContainerForm ( QWidget *  parent,
const SelectionDescriptor< T > &  d,
SampleEditorController ec 
)
inline

Definition at line 103 of file SelectionContainerForm.h.

105  : AbstractSelectionContainerForm(parent, ec)
106  {
107  if (d.currentItem != nullptr)
108  currentValues = [=] {
110  };
111  else
112  currentValues = [] { return DoubleDescriptors(); };
113 
114  initUI(d);
115  }
QList< DoubleDescriptor > DoubleDescriptors
AbstractSelectionContainerForm(QWidget *parent, SampleEditorController *ec)
void initUI(const SelectionDescriptor< T > &d)
function< DoubleDescriptors()> currentValues
function< T()> currentItem
Function to get currently selected item.
DoubleDescriptors doubleDescriptorsOfItem(LayerBasicRoughnessItem *item)

References SelectionDescriptor< T >::currentItem, currentValues, LayerEditorUtils::doubleDescriptorsOfItem(), and AbstractSelectionContainerForm::initUI().

Here is the call graph for this function:

Member Function Documentation

◆ clear()

void AbstractSelectionContainerForm::clear ( )
inlineprivateinherited

Remove all descriptors from the layout.

Definition at line 66 of file SelectionContainerForm.h.

67  {
68  auto* layoutItemOfComboBox = m_gridLayout->itemAtPosition(1, 0);
69  m_gridLayout->takeAt(m_gridLayout->indexOf(layoutItemOfComboBox));
71  m_gridLayout->addWidget(layoutItemOfComboBox->widget(), 1, 0);
72  }
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:68

References GUI::Util::Layout::clearLayout(), and AbstractSelectionContainerForm::m_gridLayout.

Referenced by AbstractSelectionContainerForm::initUI().

Here is the call graph for this function:

◆ createContent()

virtual void SelectionContainerForm::createContent ( )
inlinevirtual

Implements AbstractSelectionContainerForm.

Definition at line 117 of file SelectionContainerForm.h.

118  {
119  if (currentValues != nullptr)
121  }
void addMultiPropertyToGrid(QGridLayout *m_gridLayout, int firstCol, const DoubleDescriptors &valueDescriptors, SampleEditorController *ec, bool vertically, bool addSpacer)
Create DoubleSpinBoxes for the DoubeDescriptors and connect them to SampleEditorController::setDouble...

References LayerEditorUtils::addMultiPropertyToGrid(), currentValues, AbstractSelectionContainerForm::m_ec, and AbstractSelectionContainerForm::m_gridLayout.

Here is the call graph for this function:

◆ initUI()

template<typename T >
void AbstractSelectionContainerForm::initUI ( const SelectionDescriptor< T > &  d)
inlineprotectedinherited

Definition at line 42 of file SelectionContainerForm.h.

43  {
44  m_gridLayout = new QGridLayout(this);
45  m_gridLayout->setContentsMargins(0, 0, 0, 0);
46  m_gridLayout->setSpacing(6);
47 
48  m_combo = new QComboBox;
50  m_combo->addItems(d.options);
51  m_combo->setCurrentIndex(d.currentIndex());
52  m_combo->setMaxVisibleItems(m_combo->count());
53 
54  QObject::connect(m_combo, QOverload<int>::of(&QComboBox::currentIndexChanged),
55  [=](int current) {
56  clear();
57  m_ec->setCurrentIndex(this, current, d);
58  });
59 
60  m_gridLayout->addWidget(m_combo, 1, 0);
61  createContent();
62  }
void clear()
Remove all descriptors from the layout.
virtual void createContent()=0
void setCurrentIndex(AbstractSelectionContainerForm *widget, int index, const AbstractSelectionDescriptor &d)
int currentIndex() const override
Get currently selected option.
QStringList options
List of options, usually presented as combo entries.
static void install(QObject *obj)

References AbstractSelectionContainerForm::clear(), AbstractSelectionContainerForm::createContent(), SelectionDescriptor< T >::currentIndex(), WheelEventEater::install(), AbstractSelectionContainerForm::m_combo, AbstractSelectionContainerForm::m_ec, AbstractSelectionContainerForm::m_gridLayout, SelectionDescriptor< T >::options, and SampleEditorController::setCurrentIndex().

Referenced by LatticeTypeSelectionForm::LatticeTypeSelectionForm(), and SelectionContainerForm().

Here is the call graph for this function:

Member Data Documentation

◆ currentValues

function<DoubleDescriptors()> SelectionContainerForm::currentValues = nullptr
private

Definition at line 124 of file SelectionContainerForm.h.

Referenced by SelectionContainerForm(), and createContent().

◆ m_combo

QComboBox* AbstractSelectionContainerForm::m_combo
protectedinherited

Definition at line 76 of file SelectionContainerForm.h.

Referenced by AbstractSelectionContainerForm::initUI().

◆ m_ec

SampleEditorController* AbstractSelectionContainerForm::m_ec
protectedinherited

◆ m_gridLayout

QGridLayout* AbstractSelectionContainerForm::m_gridLayout
protectedinherited

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