BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
LayerEditorUtils Namespace Reference

Description

Utility functions to support layer oriented sample editor.

Functions

void addMultiPropertyToGrid (QGridLayout *m_gridLayout, int firstCol, const DoubleDescriptors &valueDescriptors, function< void(double, DoubleDescriptor)> setNewValue, bool vertically, bool addSpacer)
 Create DoubleSpinBoxes for the DoubeDescriptors and connect them to the given setNewValue() More...
 
void addMultiPropertyToGrid (QGridLayout *m_gridLayout, int firstCol, const DoubleDescriptors &valueDescriptors, SampleEditorController *ec, bool addSpacer)
 
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() More...
 
void addVectorToGrid (QGridLayout *m_gridLayout, int firstCol, const VectorDescriptor &v, function< void(double, DoubleDescriptor)> setNewValue, bool vertically, bool addSpacer)
 Create DoubleSpinBoxes for the DoubeDescriptors and connect them to the given setNewValue() More...
 
void addVectorToGrid (QGridLayout *m_gridLayout, int firstCol, const VectorDescriptor &v, SampleEditorController *ec, bool vertically, bool addSpacer)
 Create DoubleSpinBoxes for the DoubeDescriptors and connect them to SampleEditorController::setDouble() More...
 
QPushButton * createAddParticleButton (QWidget *parentWidget, std::function< void(FormFactorItemCatalog::Type t)> slotAddFormFactor, std::function< void(ItemWithParticlesCatalog::Type t)> slotAddParticle)
 
QLabel * createBoldLabel (const QString &text)
 
QWidget * createWidgetForItemWithParticles (QWidget *parentWidget, ItemWithParticles *itemWithParticles, bool allowAbundance, SampleEditorController *ec, bool allowRemove=true)
 
DoubleDescriptors doubleDescriptorsOfItem (FormFactorItem *item)
 
DoubleDescriptors doubleDescriptorsOfItem (LayerBasicRoughnessItem *item)
 
DoubleDescriptors doubleDescriptorsOfItem (Profile1DItem *item)
 
DoubleDescriptors doubleDescriptorsOfItem (Profile2DItem *item)
 
DoubleDescriptors doubleDescriptorsOfItem (RotationItem *item)
 
QList< QColor > predefinedLayerColors ()
 
void updateLabelUnit (QLabel *label)
 
void updateLabelUnit (QLabel *label, DoubleSpinBox *editor)
 

Function Documentation

◆ addMultiPropertyToGrid() [1/3]

void LayerEditorUtils::addMultiPropertyToGrid ( QGridLayout *  m_gridLayout,
int  firstCol,
const DoubleDescriptors valueDescriptors,
function< void(double, DoubleDescriptor)>  setNewValue,
bool  vertically,
bool  addSpacer 
)

Create DoubleSpinBoxes for the DoubeDescriptors and connect them to the given setNewValue()

Definition at line 79 of file LayerEditorUtils.cpp.

83 {
84  int col = firstCol;
85  for (const auto& valueDescriptor : valueDescriptors) {
86  auto* editor = new DoubleSpinBox(m_gridLayout->parentWidget(), valueDescriptor);
87  QObject::connect(editor, &DoubleSpinBox::baseValueChanged,
88  [=](double newValue) { setNewValue(newValue, valueDescriptor); });
89 
90  QString labeltext = valueDescriptor.label;
91  if (!vertically && !labeltext.endsWith(":"))
92  labeltext += ":";
93  auto* label = new QLabel(labeltext, m_gridLayout->parentWidget());
94  label->setBuddy(editor); // necessary for unit-updating
95  LayerEditorUtils::updateLabelUnit(label, editor);
96 
97  if (vertically) {
98  m_gridLayout->addWidget(label, 0, col);
99  m_gridLayout->addWidget(editor, 1, col);
100  col++;
101  } else {
102  m_gridLayout->addWidget(label, 1, col++);
103  m_gridLayout->addWidget(editor, 1, col++);
104  }
105  }
106  if (addSpacer)
107  m_gridLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding), 0, col);
108 }
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
void updateLabelUnit(QLabel *label)

References DoubleSpinBox::baseValueChanged(), and updateLabelUnit().

Here is the call graph for this function:

◆ addMultiPropertyToGrid() [2/3]

void LayerEditorUtils::addMultiPropertyToGrid ( QGridLayout *  m_gridLayout,
int  firstCol,
const DoubleDescriptors valueDescriptors,
SampleEditorController ec,
bool  addSpacer 
)

Definition at line 110 of file LayerEditorUtils.cpp.

113 {
114  addMultiPropertyToGrid(m_gridLayout, firstCol, valueDescriptors, ec,
115  valueDescriptors.size() > 1, addSpacer);
116 }
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 addMultiPropertyToGrid().

Here is the call graph for this function:

◆ addMultiPropertyToGrid() [3/3]

void LayerEditorUtils::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()

Definition at line 66 of file LayerEditorUtils.cpp.

70 {
71  const auto setNewValue = [=](double newValue, DoubleDescriptor d) {
72  ec->setDouble(newValue, d);
73  };
74 
75  addMultiPropertyToGrid(m_gridLayout, firstCol, valueDescriptors, setNewValue, vertically,
76  addSpacer);
77 }
Describes properties of a double value which are necessary to allow GUI representation,...
void setDouble(double newValue, DoubleDescriptor d)

References SampleEditorController::setDouble().

Referenced by FormLayouter::addGroupOfValues(), addMultiPropertyToGrid(), FormLayouter::addVector(), addVectorToGrid(), SelectionContainerForm::createContent(), and LatticeTypeSelectionForm::createContent().

Here is the call graph for this function:

◆ addVectorToGrid() [1/2]

void LayerEditorUtils::addVectorToGrid ( QGridLayout *  m_gridLayout,
int  firstCol,
const VectorDescriptor v,
function< void(double, DoubleDescriptor)>  setNewValue,
bool  vertically,
bool  addSpacer 
)

Create DoubleSpinBoxes for the DoubeDescriptors and connect them to the given setNewValue()

Definition at line 126 of file LayerEditorUtils.cpp.

130 {
131  addMultiPropertyToGrid(m_gridLayout, firstCol, {v.x, v.y, v.z}, setNewValue, vertically,
132  addSpacer);
133 }
DoubleDescriptor y
DoubleDescriptor x
DoubleDescriptor z

References addMultiPropertyToGrid(), VectorDescriptor::x, VectorDescriptor::y, and VectorDescriptor::z.

Here is the call graph for this function:

◆ addVectorToGrid() [2/2]

void LayerEditorUtils::addVectorToGrid ( QGridLayout *  m_gridLayout,
int  firstCol,
const VectorDescriptor v,
SampleEditorController ec,
bool  vertically,
bool  addSpacer 
)

Create DoubleSpinBoxes for the DoubeDescriptors and connect them to SampleEditorController::setDouble()

Definition at line 118 of file LayerEditorUtils.cpp.

121 {
122  addMultiPropertyToGrid(m_gridLayout, firstCol, {v.x, v.y, v.z}, ec, vertically, addSpacer);
123 }

References addMultiPropertyToGrid(), VectorDescriptor::x, VectorDescriptor::y, and VectorDescriptor::z.

Referenced by MaterialInplaceForm::createWidgets().

Here is the call graph for this function:

◆ createAddParticleButton()

QPushButton * LayerEditorUtils::createAddParticleButton ( QWidget *  parentWidget,
std::function< void(FormFactorItemCatalog::Type t)>  slotAddFormFactor,
std::function< void(ItemWithParticlesCatalog::Type t)>  slotAddParticle 
)

Definition at line 197 of file LayerEditorUtils.cpp.

200 {
201  auto* btn = new QPushButton("Add particle", parentWidget);
202 
203  auto* menu = new QMenu(btn);
204  QMenu* menuForEntries = menu;
205 
206  const auto group = [&](const QString& title) { menuForEntries = menu->addMenu(title); };
207 
208  group("Hard particles");
209  for (const auto type : FormFactorItemCatalog::hardParticleTypes()) {
210  const auto ui = FormFactorItemCatalog::uiInfo(type);
211  QAction* a = menuForEntries->addAction(QIcon(ui.iconPath), ui.menuEntry);
212  a->setToolTip(ui.description);
213  QObject::connect(a, &QAction::triggered, [=]() { slotAddFormFactor(type); });
214  }
215 
216  group("Ripples");
217  for (const auto type : FormFactorItemCatalog::rippleTypes()) {
218  const auto ui = FormFactorItemCatalog::uiInfo(type);
219  QAction* a = menuForEntries->addAction(QIcon(ui.iconPath), ui.menuEntry);
220  a->setToolTip(ui.description);
221  QObject::connect(a, &QAction::triggered, [=]() { slotAddFormFactor(type); });
222  }
223 
224  group("Particle assemblies");
225  for (const auto type :
228  const auto ui = ItemWithParticlesCatalog::uiInfo(type);
229  QAction* a = menuForEntries->addAction(QIcon(ui.iconPath), ui.menuEntry);
230  a->setToolTip(ui.description);
231  QObject::connect(a, &QAction::triggered, [=]() { slotAddParticle(type); });
232  }
233 
234  btn->setMenu(menu);
235 
236  return btn;
237 }
static QVector< Type > hardParticleTypes()
static UiInfo uiInfo(Type t)
UiInfo on the given type.
static QVector< Type > rippleTypes()
static UiInfo uiInfo(Type t)
UiInfo on the given type.

References ItemWithParticlesCatalog::Composition, ItemWithParticlesCatalog::CoreShell, FormFactorItemCatalog::hardParticleTypes(), ItemWithParticlesCatalog::MesoCrystal, FormFactorItemCatalog::rippleTypes(), FormFactorItemCatalog::uiInfo(), and ItemWithParticlesCatalog::uiInfo().

Referenced by ParticleCompositionForm::ParticleCompositionForm(), and ParticleLayoutForm::ParticleLayoutForm().

Here is the call graph for this function:

◆ createBoldLabel()

QLabel * LayerEditorUtils::createBoldLabel ( const QString &  text)

Definition at line 135 of file LayerEditorUtils.cpp.

136 {
137  auto* l = new QLabel(text);
138  QFont f = l->font();
139  f.setBold(true);
140  l->setFont(f);
141  return l;
142 }

Referenced by FormLayouter::insertRow(), and FormLayouter::insertValue().

◆ createWidgetForItemWithParticles()

QWidget * LayerEditorUtils::createWidgetForItemWithParticles ( QWidget *  parentWidget,
ItemWithParticles itemWithParticles,
bool  allowAbundance,
SampleEditorController ec,
bool  allowRemove = true 
)

Definition at line 175 of file LayerEditorUtils.cpp.

180 {
181  if (auto* composition = dynamic_cast<ParticleCompositionItem*>(itemWithParticles))
182  return new ParticleCompositionForm(parentWidget, composition, ec, allowRemove);
183 
184  if (auto* coreShell = dynamic_cast<ParticleCoreShellItem*>(itemWithParticles))
185  return new ParticleCoreShellForm(parentWidget, coreShell, ec, allowRemove);
186 
187  if (auto* meso = dynamic_cast<MesoCrystalItem*>(itemWithParticles))
188  return new MesoCrystalForm(parentWidget, meso, ec, allowRemove);
189 
190  if (auto* particle = dynamic_cast<ParticleItem*>(itemWithParticles))
191  return new ParticleForm(parentWidget, particle, allowAbundance, ec, allowRemove);
192 
193  ASSERT(false);
194  return nullptr;
195 }
Form for editing a mesocrystal.
Form for editing a particle composition.
Form for editing a core/shell particle.
Form for editing a particle.
Definition: ParticleForm.h:25

Referenced by ParticleCompositionForm::ParticleCompositionForm(), ParticleLayoutForm::ParticleLayoutForm(), MesoCrystalForm::createBasisWidgets(), ParticleCompositionForm::onParticleAdded(), and ParticleLayoutForm::onParticleAdded().

◆ doubleDescriptorsOfItem() [1/5]

DoubleDescriptors LayerEditorUtils::doubleDescriptorsOfItem ( FormFactorItem item)

Definition at line 162 of file LayerEditorUtils.cpp.

163 {
164  return item->geometryValues();
165 }
virtual DoubleDescriptors geometryValues() const =0

References FormFactorItem::geometryValues().

Here is the call graph for this function:

◆ doubleDescriptorsOfItem() [2/5]

DoubleDescriptors LayerEditorUtils::doubleDescriptorsOfItem ( LayerBasicRoughnessItem item)

Definition at line 167 of file LayerEditorUtils.cpp.

168 {
169  if (r)
170  return {r->sigma(), r->hurst(), r->lateralCorrelationLength()};
171 
172  return {};
173 }

References LayerBasicRoughnessItem::hurst(), LayerBasicRoughnessItem::lateralCorrelationLength(), and LayerBasicRoughnessItem::sigma().

Referenced by SelectionContainerForm::SelectionContainerForm().

Here is the call graph for this function:

◆ doubleDescriptorsOfItem() [3/5]

DoubleDescriptors LayerEditorUtils::doubleDescriptorsOfItem ( Profile1DItem item)

Definition at line 157 of file LayerEditorUtils.cpp.

158 {
159  return item->valueDescriptors();
160 }
virtual DoubleDescriptors valueDescriptors() const

References Profile1DItem::valueDescriptors().

Here is the call graph for this function:

◆ doubleDescriptorsOfItem() [4/5]

DoubleDescriptors LayerEditorUtils::doubleDescriptorsOfItem ( Profile2DItem item)

Definition at line 152 of file LayerEditorUtils.cpp.

153 {
154  return item->valueDescriptors();
155 }
virtual DoubleDescriptors valueDescriptors() const

References Profile2DItem::valueDescriptors().

Here is the call graph for this function:

◆ doubleDescriptorsOfItem() [5/5]

DoubleDescriptors LayerEditorUtils::doubleDescriptorsOfItem ( RotationItem item)

Definition at line 144 of file LayerEditorUtils.cpp.

145 {
146  if (!item)
147  return {};
148 
149  return item->rotationValues();
150 }
virtual DoubleDescriptors rotationValues() const =0

References RotationItem::rotationValues().

Here is the call graph for this function:

◆ predefinedLayerColors()

QList< QColor > LayerEditorUtils::predefinedLayerColors ( )

Definition at line 239 of file LayerEditorUtils.cpp.

240 {
241  static QList<QColor> colors = {QColor(230, 255, 213), QColor(194, 252, 240),
242  QColor(239, 228, 176), QColor(200, 191, 231),
243  QColor(253, 205, 193), QColor(224, 193, 253)};
244 
245  return colors;
246 }

Referenced by LayerForm::LayerForm(), SampleEditorController::addLayerFromUndo(), and LayerOrientedSampleEditor::createLayerColors().

◆ updateLabelUnit() [1/2]

void LayerEditorUtils::updateLabelUnit ( QLabel *  label)

Definition at line 60 of file LayerEditorUtils.cpp.

61 {
62  if (auto* editor = dynamic_cast<DoubleSpinBox*>(label->buddy()))
63  ::updateLabelUnit(label, editor->displayUnitAsString());
64 }

Referenced by addMultiPropertyToGrid(), FormLayouter::insertValue(), updateLabelUnit(), and MultiLayerForm::updateUnits().

◆ updateLabelUnit() [2/2]

void LayerEditorUtils::updateLabelUnit ( QLabel *  label,
DoubleSpinBox editor 
)

Definition at line 55 of file LayerEditorUtils.cpp.

56 {
57  ::updateLabelUnit(label, editor->displayUnitAsString());
58 }
QString displayUnitAsString() const
The display unit as human readable string.

References DoubleSpinBox::displayUnitAsString(), and updateLabelUnit().

Here is the call graph for this function: