BornAgain
1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
|
Utility class to populate a QFormLayout.
Helps to add edit controls which operate on descriptors (DoubleDescriptor, UIntDescriptor and so on). Also takes care of bold printed labels, the connection of labels and edit controls (buddies), which is necessary to realize the "label shows unit of value" feature. Connections to a given SampleEditorController are established as well.
Definition at line 36 of file FormLayouter.h.
Public Member Functions | |
FormLayouter (QWidget *parent, SampleEditorController *ec) | |
Create a layouter which operates on the given parent widget. More... | |
int | addGroupOfValues (const QString &labelText, const DoubleDescriptors &values) |
Adds a row with a bold printed label and a set of DoubleDescriptors. More... | |
int | addRow (const QString &label, QWidget *w) |
Add a row with a bold printed label. More... | |
int | addRow (QWidget *w) |
Convenience method to add a widget. More... | |
template<typename T > | |
int | addSelection (const SelectionDescriptor< T > &d) |
Add a row with a selection. More... | |
void | addStructureEditingRow (QPushButton *button) |
Adds a button for structure editing. More... | |
int | addValue (const DoubleDescriptor &d) |
Adds a row with a bold printed label and a DoubleSpinBox. More... | |
int | addValue (const DoubleDescriptor &d, function< void(double)> onValueChange) |
Adds a row with a bold printed label and a DoubleSpinBox. More... | |
int | addValue (const UIntDescriptor &d) |
Adds a row with a bold printed label and a QSpinBox. More... | |
int | addVector (const VectorDescriptor &d, bool vertically=true) |
Adds a row with a bold printed label and the 3 values of a 3D vector. More... | |
void | insertRow (int row, QString label, QWidget *w) |
Insert a row with a bold printed label. More... | |
void | insertRow (int row, QWidget *w) |
Convenience method to insert a widget. More... | |
void | insertValue (int row, const DoubleDescriptor &d) |
Inserts a row with a bold printed label and a DoubleSpinBox. More... | |
void | insertValue (int row, const DoubleDescriptor &d, function< void(double)> onValueChange) |
Inserts a row with a bold printed label and a DoubleSpinBox. More... | |
QFormLayout * | layout () |
The layout where this layouter is operating on. More... | |
void | removeRow (int row) |
Convenience method to remove a row. More... | |
void | setContentsMargins (int left, int top, int right, int bottom) |
Convenience method to set the contents margins. More... | |
void | setRowVisible (int row, bool visible) |
Shows or hides the widgets in a row. More... | |
template<typename T > | |
T | widgetAt (int row, QFormLayout::ItemRole role) |
Find a widget in the given position. More... | |
Private Attributes | |
SampleEditorController * | m_ec |
QFormLayout * | m_formLayout |
FormLayouter::FormLayouter | ( | QWidget * | parent, |
SampleEditorController * | ec | ||
) |
Create a layouter which operates on the given parent widget.
If the parent has no layout yet, a QFormLayout is installed. If the parentWidget already has a QFormLayout, this will be used for the calls later on. The given SampleEditorController is used to create connections e.g. when a DoubleSpinBox value has been changed.
Definition at line 54 of file FormLayouter.cpp.
References GroupBoxCollapser::findInstalledCollapser(), and m_formLayout.
int FormLayouter::addGroupOfValues | ( | const QString & | labelText, |
const DoubleDescriptors & | values | ||
) |
Adds a row with a bold printed label and a set of DoubleDescriptors.
The label describes the set of the Descriptors and is located in the first column of the layout. The DoubleSpinBoxes for each DoubleDescriptor are created as children of a newly created widget, which is positioned in the second column of the layout. If the number of values is greater than 1, the related labels are shown above them, to limit the necessary space to the right. For the creation, signaling, unit handling etc. of one DoubleDescriptor the same applies as when adding a single DoubleDesciptor with the method addValue(), therefore please read there for more details. Returns the newly added row.
Definition at line 96 of file FormLayouter.cpp.
References LayerEditorUtils::addMultiPropertyToGrid(), addRow(), m_ec, and m_formLayout.
Referenced by ParticleForm::ParticleForm().
int FormLayouter::addRow | ( | const QString & | label, |
QWidget * | w | ||
) |
Add a row with a bold printed label.
If necessary, a colon (':') is added to the label. Returns the newly added row.
Definition at line 83 of file FormLayouter.cpp.
References insertRow(), and m_formLayout.
int FormLayouter::addRow | ( | QWidget * | w | ) |
Convenience method to add a widget.
Calls QFormLayout::addRow() and returns the row of the newly added widget.
Definition at line 195 of file FormLayouter.cpp.
References m_formLayout.
Referenced by InterferenceForm::InterferenceForm(), MesoCrystalForm::MesoCrystalForm(), MultiLayerForm::MultiLayerForm(), ParticleCompositionForm::ParticleCompositionForm(), ParticleCoreShellForm::ParticleCoreShellForm(), ParticleForm::ParticleForm(), ParticleLayoutForm::ParticleLayoutForm(), addGroupOfValues(), addSelection(), addStructureEditingRow(), addValue(), addVector(), and InterferenceForm::createInterferenceWidgets().
int FormLayouter::addSelection | ( | const SelectionDescriptor< T > & | d | ) |
Add a row with a selection.
The whole selection is realized by adding a SelectionContainerForm. This SelectionContainerForm is limited to contain the selection combo box and a list of double values represented by DoubleDescriptors. To add more complex selections (e.g. with sub-selections or different value types), this method and the SelectionContainerForm is not sufficient. It has to be done "manually". For more details, see SelectionContainerForm. Returns the newly added row.
Definition at line 170 of file FormLayouter.h.
References addRow(), SelectionDescriptor< T >::label, m_ec, and m_formLayout.
Referenced by MesoCrystalForm::MesoCrystalForm(), ParticleCompositionForm::ParticleCompositionForm(), ParticleCoreShellForm::ParticleCoreShellForm(), ParticleForm::ParticleForm(), and InterferenceForm::createInterferenceWidgets().
void FormLayouter::addStructureEditingRow | ( | QPushButton * | button | ) |
Adds a button for structure editing.
Creates a widget, places the given button as a child left-aligned into this widget and adds the newly created widget as a row in the layout.
Definition at line 140 of file FormLayouter.cpp.
References addRow(), and m_formLayout.
Referenced by ParticleCompositionForm::ParticleCompositionForm(), and ParticleLayoutForm::ParticleLayoutForm().
int FormLayouter::addValue | ( | const DoubleDescriptor & | d | ) |
Adds a row with a bold printed label and a DoubleSpinBox.
The DoubleSpinBox is initialized with the contents found in the descriptor (e.g. limits, decimals, unit). The DoubleSpinBox is set as the "buddy" of the label. This is necessary to realize the "label shows unit of value" feature. Changes of the DoubleSpinBox are signaled to the SampleEditorController which has been overhanded in the constructor of this FormLayouter. It is connected to SampleEditorController::setDouble(). If a different method should be called (e.g. for a special undo functionality), this method is not sufficient. It would have to be done "manually" or with the overload which takes a slot (see below). Returns the newly added row.
Definition at line 157 of file FormLayouter.cpp.
References insertValue(), and m_formLayout.
Referenced by MesoCrystalForm::MesoCrystalForm(), MultiLayerForm::MultiLayerForm(), ParticleCompositionForm::ParticleCompositionForm(), ParticleCoreShellForm::ParticleCoreShellForm(), ParticleForm::ParticleForm(), ParticleLayoutForm::ParticleLayoutForm(), and InterferenceForm::createInterferenceWidgets().
int FormLayouter::addValue | ( | const DoubleDescriptor & | d, |
function< void(double)> | onValueChange | ||
) |
Adds a row with a bold printed label and a DoubleSpinBox.
Same as above, but the called slot in case of a value change has to be overhanded. Use this only if the standard (calling SampleEditorController::setDouble()) is not sufficient.
Definition at line 163 of file FormLayouter.cpp.
References insertValue(), and m_formLayout.
int FormLayouter::addValue | ( | const UIntDescriptor & | d | ) |
Adds a row with a bold printed label and a QSpinBox.
Right now in the sample model there is no uint value which has a unit, therefore no unit displaying is implemented. Beside this, the same as for addValue(DoubleDescriptor) applies. Returns the newly added row.
Definition at line 151 of file FormLayouter.cpp.
References addRow(), GUI::Util::createSpinBox(), UIntDescriptor::label, m_ec, and m_formLayout.
int FormLayouter::addVector | ( | const VectorDescriptor & | d, |
bool | vertically = true |
||
) |
Adds a row with a bold printed label and the 3 values of a 3D vector.
Works the same as addGroupOfValues. The label is taken from the VectorDescriptor. In addition, the caller can define whether the labels are above the values (vertically=true), or whether labels and values are all placed in one row (vertically=false).
Definition at line 112 of file FormLayouter.cpp.
References LayerEditorUtils::addMultiPropertyToGrid(), addRow(), VectorDescriptor::label, m_ec, m_formLayout, VectorDescriptor::x, VectorDescriptor::y, and VectorDescriptor::z.
Referenced by MesoCrystalForm::MesoCrystalForm(), MultiLayerForm::MultiLayerForm(), ParticleCompositionForm::ParticleCompositionForm(), ParticleCoreShellForm::ParticleCoreShellForm(), and ParticleForm::ParticleForm().
void FormLayouter::insertRow | ( | int | row, |
QString | label, | ||
QWidget * | w | ||
) |
Insert a row with a bold printed label.
If necessary, a colon (':') is added to the label.
Definition at line 89 of file FormLayouter.cpp.
References LayerEditorUtils::createBoldLabel(), and m_formLayout.
void FormLayouter::insertRow | ( | int | row, |
QWidget * | w | ||
) |
Convenience method to insert a widget.
Calls QFormLayout::insertRow().
Definition at line 201 of file FormLayouter.cpp.
References m_formLayout.
Referenced by addRow().
void FormLayouter::insertValue | ( | int | row, |
const DoubleDescriptor & | d | ||
) |
Inserts a row with a bold printed label and a DoubleSpinBox.
Same functionality as addValue(), please read there.
Definition at line 169 of file FormLayouter.cpp.
References m_ec, and SampleEditorController::setDouble().
Referenced by addValue().
void FormLayouter::insertValue | ( | int | row, |
const DoubleDescriptor & | d, | ||
function< void(double)> | onValueChange | ||
) |
Inserts a row with a bold printed label and a DoubleSpinBox.
Same functionality as addValue(), please read there.
Definition at line 175 of file FormLayouter.cpp.
References DoubleSpinBox::baseValueChanged(), LayerEditorUtils::createBoldLabel(), DoubleDescriptor::label, m_formLayout, and LayerEditorUtils::updateLabelUnit().
QFormLayout * FormLayouter::layout | ( | ) |
The layout where this layouter is operating on.
Use this, if you want to modify the layout with means not given in here.
Definition at line 73 of file FormLayouter.cpp.
References m_formLayout.
Referenced by MesoCrystalForm::MesoCrystalForm(), ParticleCompositionForm::ParticleCompositionForm(), ParticleLayoutForm::ParticleLayoutForm(), and InterferenceForm::onInterferenceTypeChanged().
void FormLayouter::removeRow | ( | int | row | ) |
Convenience method to remove a row.
Calls QFormLayout::removeRow().
Definition at line 135 of file FormLayouter.cpp.
References m_formLayout.
void FormLayouter::setContentsMargins | ( | int | left, |
int | top, | ||
int | right, | ||
int | bottom | ||
) |
Convenience method to set the contents margins.
Directly calls QFormLayout::setContentsMargins()
Definition at line 78 of file FormLayouter.cpp.
References m_formLayout.
Referenced by InterferenceForm::InterferenceForm(), MesoCrystalForm::MesoCrystalForm(), MultiLayerForm::MultiLayerForm(), ParticleCompositionForm::ParticleCompositionForm(), ParticleCoreShellForm::ParticleCoreShellForm(), and ParticleLayoutForm::ParticleLayoutForm().
void FormLayouter::setRowVisible | ( | int | row, |
bool | visible | ||
) |
Shows or hides the widgets in a row.
Definition at line 129 of file FormLayouter.cpp.
References m_formLayout.
T FormLayouter::widgetAt | ( | int | row, |
QFormLayout::ItemRole | role | ||
) |
Find a widget in the given position.
The widget will be qobject_cast'ed to the template parameter
Definition at line 177 of file FormLayouter.h.
References m_formLayout.
Referenced by ParticleLayoutForm::ParticleLayoutForm().
|
private |
Definition at line 165 of file FormLayouter.h.
Referenced by addGroupOfValues(), addSelection(), addValue(), addVector(), and insertValue().
|
private |
Definition at line 166 of file FormLayouter.h.
Referenced by FormLayouter(), addGroupOfValues(), addRow(), addSelection(), addStructureEditingRow(), addValue(), addVector(), insertRow(), insertValue(), layout(), removeRow(), setContentsMargins(), setRowVisible(), and widgetAt().