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

Description

Form for editing a layer.

Definition at line 29 of file LayerForm.h.

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

Public Member Functions

 LayerForm (QWidget *parent, LayerItem *layer, SampleEditorController *ec)
 
void enableStructureEditing (bool b)
 
void expand ()
 
LayerItemlayerItem () const
 
void onAboutToRemoveLayout (ParticleLayoutItem *layoutItem)
 
void onLayoutAdded (ParticleLayoutItem *layoutItem)
 
void updateLayerPositionDependentElements ()
 
void updateTitle ()
 

Private Member Functions

void updateColor ()
 

Private Attributes

GroupBoxCollapserm_collapser
 
SampleEditorControllerm_ec
 
LayerItemm_layer
 
std::unique_ptr< FormLayouterm_layouter
 
WidgetMoverButtonm_moveButton
 
QAction * m_removeAction
 
int m_roughnessRow = -1
 
QList< QWidget * > m_structureEditingWidgets
 
int m_thicknessRow = -1
 

Constructor & Destructor Documentation

◆ LayerForm()

LayerForm::LayerForm ( QWidget *  parent,
LayerItem layer,
SampleEditorController ec 
)

Definition at line 31 of file LayerForm.cpp.

32  : QGroupBox(parent)
33  , m_layer(layer)
34  , m_ec(ec)
35 {
36  setTitle(m_layer->layerName());
37  m_layouter = std::make_unique<FormLayouter>(this, ec);
38  m_layouter->setContentsMargins(6, 6, 0, 6);
40 
42  ActionFactory::createRemoveAction(this, "layer", [=] { ec->removeLayer(layer); });
43 
44  auto* chooseColorAction = new QAction(this);
45  chooseColorAction->setText("Choose color");
46  chooseColorAction->setIcon(QIcon(":/images/palette.svg"));
47  chooseColorAction->setIconText("Choose color");
48  chooseColorAction->setToolTip("Choose a color for this layer");
49  auto* menu = new QMenu(this);
50  chooseColorAction->setMenu(menu);
51 
52  for (const auto& col : LayerEditorUtils::predefinedLayerColors()) {
53  QPixmap p(64, 64);
54  p.fill(col);
55  auto* ca = menu->addAction(QIcon(p), "");
56  connect(ca, &QAction::triggered, [=]() {
57  layer->setColor(col);
58  updateColor();
59  });
60  }
61 
62  m_moveButton = new WidgetMoverButton(this, this, 1);
63  m_moveButton->setToolTip("Move layer up/down");
68 
69  auto* showInRealSpaceAction = ActionFactory::createShowInRealSpaceAction(
70  this, "layer", [=] { m_ec->requestViewInRealSpace(layer); });
71 
72  m_collapser->addAction(showInRealSpaceAction);
73  m_collapser->addAction(chooseColorAction);
77 
78  QColor bckgroundCol = m_layer->color();
79  setStyleSheet("QGroupBox {background-color: " + bckgroundCol.name(QColor::HexRgb) + "}");
80 
81  m_layouter->addRow("Material:", new MaterialInplaceForm(this, layer, ec));
83  m_layouter->addValue(m_layer->numSlices());
84  m_roughnessRow = m_layouter->addSelection(m_layer->roughness());
85 
86  // -- layouts
87  for (auto* layout : layer->layouts())
88  m_layouter->addRow(new ParticleLayoutForm(this, layout, ec));
89 
90  // -- Button for adding a new layout
91  auto* btn = new QPushButton("Add particle layout", this);
92  connect(btn, &QPushButton::clicked, [=] { ec->addLayout(this); });
94  m_layouter->addStructureEditingRow(btn);
95 
96  // listen to changes in materials to update the title (contains the material name). Necessary
97  // to reflect e.g. a name change done in the material editor.
99 
101 }
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.
void addAction(QAction *action)
Add a tool button to the title bar, connected to the given action.
void addWidget(QWidget *widget)
Add a widget to the title bar.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
GroupBoxCollapser * m_collapser
Definition: LayerForm.h:46
int m_thicknessRow
Definition: LayerForm.h:51
void updateColor()
Definition: LayerForm.cpp:114
QAction * m_removeAction
Definition: LayerForm.h:49
LayerItem * m_layer
Definition: LayerForm.h:48
void updateLayerPositionDependentElements()
Definition: LayerForm.cpp:132
void updateTitle()
Definition: LayerForm.cpp:120
WidgetMoverButton * m_moveButton
Definition: LayerForm.h:54
std::unique_ptr< FormLayouter > m_layouter
Definition: LayerForm.h:47
SampleEditorController * m_ec
Definition: LayerForm.h:52
QList< QWidget * > m_structureEditingWidgets
Definition: LayerForm.h:53
int m_roughnessRow
Definition: LayerForm.h:50
QColor color() const
Definition: LayerItem.cpp:153
UIntDescriptor numSlices() const
Definition: LayerItem.cpp:131
void setColor(const QColor &color)
Definition: LayerItem.cpp:158
QVector< ParticleLayoutItem * > layouts() const
Definition: LayerItem.cpp:136
DoubleDescriptor thickness() const
Definition: LayerItem.cpp:97
QString layerName() const
Definition: LayerItem.cpp:75
SelectionDescriptor< LayerBasicRoughnessItem * > roughness()
Definition: LayerItem.cpp:102
Form to select a material and to edit it in-place.
void materialChanged(MaterialItem *materialItem)
Form for editing a particle layout.
void requestViewInRealSpace(SampleItem item)
MaterialItems * materialItems() const
The materials of the current document.
void onStoppedToMoveLayer(QWidget *widgetToMove, QWidget *moveAboveThisWidget)
void addLayout(LayerForm *layerItem)
void removeLayer(LayerItem *layerItem)
Button to move a widget vertically in a layout.
void finishedMoving(QWidget *widgetToMove, QWidget *moveAboveThisWidget)
QList< QColor > predefinedLayerColors()

References GroupBoxCollapser::addAction(), SampleEditorController::addLayout(), GroupBoxCollapser::addWidget(), LayerItem::color(), ActionFactory::createRemoveAction(), ActionFactory::createShowInRealSpaceAction(), WidgetMoverButton::finishedMoving(), GroupBoxCollapser::installIntoGroupBox(), LayerItem::layerName(), LayerItem::layouts(), m_collapser, m_ec, m_layer, m_layouter, m_moveButton, m_removeAction, m_roughnessRow, m_structureEditingWidgets, m_thicknessRow, MaterialItems::materialChanged(), SampleEditorController::materialItems(), LayerItem::numSlices(), SampleEditorController::onStartingToMoveLayer(), SampleEditorController::onStoppedToMoveLayer(), LayerEditorUtils::predefinedLayerColors(), SampleEditorController::removeLayer(), SampleEditorController::requestViewInRealSpace(), LayerItem::roughness(), LayerItem::setColor(), WidgetMoverButton::startingToMove(), LayerItem::thickness(), updateColor(), updateLayerPositionDependentElements(), and updateTitle().

Here is the call graph for this function:

Member Function Documentation

◆ enableStructureEditing()

void LayerForm::enableStructureEditing ( bool  b)

Definition at line 103 of file LayerForm.cpp.

104 {
105  m_removeAction->setVisible(b);
106 
107  for (auto* w : m_structureEditingWidgets)
108  w->setVisible(b);
109 
110  if (b && m_ec->sampleItem()->layers().size() < 2)
111  m_moveButton->setVisible(false);
112 }
QVector< LayerItem * > layers() const
MultiLayerItem * sampleItem() const
The item on which this controller operates.

References MultiLayerItem::layers(), m_ec, m_moveButton, m_removeAction, m_structureEditingWidgets, and SampleEditorController::sampleItem().

Here is the call graph for this function:

◆ expand()

void LayerForm::expand ( )

Definition at line 127 of file LayerForm.cpp.

128 {
129  m_collapser->setExpanded(true);
130 }
void setExpanded(bool expanded=true)
Expand/collapse the content area.

References m_collapser, and GroupBoxCollapser::setExpanded().

Here is the call graph for this function:

◆ layerItem()

LayerItem * LayerForm::layerItem ( ) const

◆ onAboutToRemoveLayout()

void LayerForm::onAboutToRemoveLayout ( ParticleLayoutItem layoutItem)

Definition at line 179 of file LayerForm.cpp.

180 {
181  int index = m_layer->layouts().indexOf(layoutItem);
182  const int rowInLayout =
183  m_layouter->layout()->rowCount() - m_layer->layouts().size() - 1 + index; // -1: btn
184 
185  m_layouter->removeRow(rowInLayout);
186 }

References LayerItem::layouts(), m_layer, and m_layouter.

Referenced by SampleEditorController::removeLayout().

Here is the call graph for this function:

◆ onLayoutAdded()

void LayerForm::onLayoutAdded ( ParticleLayoutItem layoutItem)

Definition at line 171 of file LayerForm.cpp.

172 {
173  int index = m_layer->layouts().indexOf(newLayoutItem);
174  const int rowInLayout = m_layouter->layout()->rowCount() - m_layer->layouts().size() + index;
175 
176  m_layouter->insertRow(rowInLayout, new ParticleLayoutForm(this, newLayoutItem, m_ec));
177 }

References LayerItem::layouts(), m_ec, m_layer, and m_layouter.

Referenced by SampleEditorController::addLayout().

Here is the call graph for this function:

◆ updateColor()

void LayerForm::updateColor ( )
private

Definition at line 114 of file LayerForm.cpp.

115 {
116  QColor bckgroundCol = m_layer->color();
117  setStyleSheet("QGroupBox {background-color: " + bckgroundCol.name(QColor::HexRgb) + "}");
118 }

References LayerItem::color(), and m_layer.

Referenced by LayerForm().

Here is the call graph for this function:

◆ updateLayerPositionDependentElements()

void LayerForm::updateLayerPositionDependentElements ( )

Definition at line 132 of file LayerForm.cpp.

133 {
134  if (m_roughnessRow == -1)
135  return;
136 
137  updateTitle();
138 
139  const auto* sample = m_ec->sampleItem();
140  const bool isFirstLayer = sample->layers().first() == m_layer;
141  const bool isLastLayer = sample->layers().last() == m_layer;
142  const bool thicknessIsSemiInfinite =
143  (isFirstLayer || isLastLayer) && (sample->layers().size() != 1);
144  const bool thicknessIsInfinite = sample->layers().size() == 1;
145 
146  m_layouter->setRowVisible(m_roughnessRow, !isFirstLayer);
147 
148  if (m_thicknessRow == -1)
149  return;
150  QWidget* w = m_layouter->layout()->itemAt(m_thicknessRow, QFormLayout::FieldRole)->widget();
151  if (thicknessIsSemiInfinite || thicknessIsInfinite) {
152  auto* info = qobject_cast<QLineEdit*>(w);
153  if (info == nullptr) {
154  m_layouter->removeRow(m_thicknessRow);
155  info = new QLineEdit(this);
156  info->setEnabled(false);
157  info->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
158  m_layouter->insertRow(m_thicknessRow, m_layer->thickness().label, info);
159  }
160  info->setText(thicknessIsSemiInfinite ? "Semi-infinite" : "Infinite");
161  } else if (!thicknessIsSemiInfinite && !thicknessIsInfinite
162  && (qobject_cast<QLineEdit*>(w) != nullptr)) {
163  m_layouter->removeRow(m_thicknessRow);
164  m_layouter->insertValue(m_thicknessRow, m_layer->thickness());
165  }
166 
167  if (m_ec->sampleItem()->layers().size() < 2)
168  m_moveButton->setVisible(false);
169 }
QString label
A label text (short, no trailing colon)

References DoubleDescriptor::label, MultiLayerItem::layers(), m_ec, m_layer, m_layouter, m_moveButton, m_roughnessRow, m_thicknessRow, SampleEditorController::sampleItem(), LayerItem::thickness(), and updateTitle().

Referenced by LayerForm().

Here is the call graph for this function:

◆ updateTitle()

void LayerForm::updateTitle ( )

Definition at line 120 of file LayerForm.cpp.

121 {
122  int i = m_ec->sampleItem()->layers().indexOf(m_layer);
123  m_collapser->setTitle("Layer " + QString::number(i)
124  + " Material: " + m_layer->materialName());
125 }
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...
QString materialName() const

References MultiLayerItem::layers(), m_collapser, m_ec, m_layer, ItemWithMaterial::materialName(), SampleEditorController::sampleItem(), and GroupBoxCollapser::setTitle().

Referenced by LayerForm(), and updateLayerPositionDependentElements().

Here is the call graph for this function:

Member Data Documentation

◆ m_collapser

GroupBoxCollapser* LayerForm::m_collapser
private

Definition at line 46 of file LayerForm.h.

Referenced by LayerForm(), expand(), and updateTitle().

◆ m_ec

◆ m_layer

◆ m_layouter

std::unique_ptr<FormLayouter> LayerForm::m_layouter
private

◆ m_moveButton

WidgetMoverButton* LayerForm::m_moveButton
private

◆ m_removeAction

QAction* LayerForm::m_removeAction
private

Definition at line 49 of file LayerForm.h.

Referenced by LayerForm(), and enableStructureEditing().

◆ m_roughnessRow

int LayerForm::m_roughnessRow = -1
private

Definition at line 50 of file LayerForm.h.

Referenced by LayerForm(), and updateLayerPositionDependentElements().

◆ m_structureEditingWidgets

QList<QWidget*> LayerForm::m_structureEditingWidgets
private

Definition at line 53 of file LayerForm.h.

Referenced by LayerForm(), and enableStructureEditing().

◆ m_thicknessRow

int LayerForm::m_thicknessRow = -1
private

Definition at line 51 of file LayerForm.h.

Referenced by LayerForm(), and updateLayerPositionDependentElements().


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