Skip to content
Snippets Groups Projects
Commit 9980e141 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

Main transition from DoubleDescriptor to DoubleProperty&

parent f7ab76a0
No related branches found
No related tags found
1 merge request!1159GUI: interfaces and argument types: DoubleDescriptor ---> DoubleProperty
......@@ -121,6 +121,6 @@ public: \
// clang-format on
//using DoubleDescriptors = QList<DoubleDescriptor>;
using DoubleDescriptors = QList<DoubleDescriptor>;
using DoubleDescriptors = QList<std::reference_wrapper<DoubleProperty>>;
#endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_DOUBLEPROPERTY_H
......@@ -140,17 +140,17 @@ void ParameterTreeBuilder::addSample()
}
}
void ParameterTreeBuilder::addParameterItem(ParameterLabelItem* parent, const DoubleDescriptor& d,
void ParameterTreeBuilder::addParameterItem(ParameterLabelItem* parent, DoubleProperty& d,
const QString& label)
{
auto* parameterItem = new ParameterItem(parent);
parameterItem->setTitle(labelWithUnit(label.isEmpty() ? d.label : label, d.unit));
parameterItem->setTitle(labelWithUnit(label.isEmpty() ? d.label() : label, d.unit()));
parameterItem->linkToDescriptor(d);
if (m_recreateBackupValues)
m_jobItem->parameterContainerItem()->setBackupValue(parameterItem->link(), d.get());
}
void ParameterTreeBuilder::addParameterItem(ParameterLabelItem* parent, const VectorProperty& d)
void ParameterTreeBuilder::addParameterItem(ParameterLabelItem* parent, VectorProperty& d)
{
auto* label = new ParameterLabelItem(d.label(), parent);
addParameterItem(label, d.x());
......@@ -172,7 +172,7 @@ bool ParameterTreeBuilder::allowMagneticFields() const
void ParameterTreeBuilder::addInterference(ParameterLabelItem* layoutLabel,
const ParticleLayoutItem* layout)
{
const auto* interference = layout->interference().currentItem();
auto* interference = layout->interference().currentItem();
if (!interference)
return;
......@@ -181,7 +181,7 @@ void ParameterTreeBuilder::addInterference(ParameterLabelItem* layoutLabel,
auto* label = new ParameterLabelItem("Interference (" + title + ")", layoutLabel);
if (const auto* itf = dynamic_cast<const InterferenceRadialParacrystalItem*>(interference)) {
if (auto* itf = dynamic_cast<InterferenceRadialParacrystalItem*>(interference)) {
addParameterItem(label, itf->positionVariance());
addParameterItem(label, itf->peakDistance());
addParameterItem(label, itf->dampingLength());
......@@ -192,7 +192,7 @@ void ParameterTreeBuilder::addInterference(ParameterLabelItem* layoutLabel,
auto* pdfLabel = addLabel<Profile1DItemCatalog>(label, "PDF", pdf);
for (auto& d : pdf->valueDescriptors())
addParameterItem(pdfLabel, d);
} else if (const auto* itf = dynamic_cast<const Interference2DParacrystalItem*>(interference)) {
} else if (auto* itf = dynamic_cast<Interference2DParacrystalItem*>(interference)) {
addParameterItem(label, itf->positionVariance());
addParameterItem(label, itf->dampingLength());
addParameterItem(label, itf->domainSize1());
......@@ -211,7 +211,7 @@ void ParameterTreeBuilder::addInterference(ParameterLabelItem* layoutLabel,
addLabel<Profile2DItemCatalog>(label, samePdfTypes ? "PDF2" : "PDF", pdf2);
for (const auto& d : pdf2->valueDescriptors())
addParameterItem(pdf2Label, d);
} else if (const auto* itf = dynamic_cast<const Interference1DLatticeItem*>(interference)) {
} else if (auto* itf = dynamic_cast<Interference1DLatticeItem*>(interference)) {
addParameterItem(label, itf->positionVariance());
addParameterItem(label, itf->length());
addParameterItem(label, itf->rotationAngle());
......@@ -220,7 +220,7 @@ void ParameterTreeBuilder::addInterference(ParameterLabelItem* layoutLabel,
auto* dfLabel = addLabel<Profile1DItemCatalog>(label, "Decay function", df);
for (const auto& d : df->valueDescriptors())
addParameterItem(dfLabel, d);
} else if (const auto* itf = dynamic_cast<const Interference2DLatticeItem*>(interference)) {
} else if (auto* itf = dynamic_cast<Interference2DLatticeItem*>(interference)) {
addParameterItem(label, itf->positionVariance());
addLattice(label, itf);
......@@ -228,15 +228,15 @@ void ParameterTreeBuilder::addInterference(ParameterLabelItem* layoutLabel,
auto* dfLabel = addLabel<Profile2DItemCatalog>(label, "Decay function", df);
for (const auto& d : df->valueDescriptors())
addParameterItem(dfLabel, d);
} else if (const auto* itf =
dynamic_cast<const InterferenceFinite2DLatticeItem*>(interference)) {
} else if (auto* itf =
dynamic_cast<InterferenceFinite2DLatticeItem*>(interference)) {
// domainSize1 and domainSize2 are of type UInt (not matching the double approach for tuning
// and fitting). In BornAgain 1.18 these values have not been added to the tuning tree, and
// also not to the fitting parameters. Maybe this should be necessary, but for now this
// stays the same and the two sizes are not added
addParameterItem(label, itf->positionVariance());
addLattice(label, itf);
} else if (const auto* itf = dynamic_cast<const InterferenceHardDiskItem*>(interference)) {
} else if (auto* itf = dynamic_cast<InterferenceHardDiskItem*>(interference)) {
addParameterItem(label, itf->positionVariance());
addParameterItem(label, itf->radius());
addParameterItem(label, itf->density());
......@@ -268,7 +268,7 @@ ParameterLabelItem* ParameterTreeBuilder::addParticle(ParameterLabelItem* parent
l->setTitle(l->title() + " (Core)");
l = addParticle(label, coreShell->shell(), false, false);
l->setTitle(l->title() + " (Shell)");
} else if (const auto* meso = dynamic_cast<const MesocrystalItem*>(p)) {
} else if (auto* meso = dynamic_cast<MesocrystalItem*>(p)) {
addParameterItem(label, meso->vectorA());
addParameterItem(label, meso->vectorB());
addParameterItem(label, meso->vectorC());
......@@ -307,7 +307,7 @@ void ParameterTreeBuilder::addRotation(ParameterLabelItem* parentLabel, ItemWith
void ParameterTreeBuilder::addInstrument()
{
const auto* instrument = m_jobItem->instrumentItem();
auto* instrument = m_jobItem->instrumentItem();
auto* label = new ParameterLabelItem(instrument->instrumentType() + " instrument",
parameterContainer()->parameterTreeRoot());
......@@ -415,7 +415,7 @@ void ParameterTreeBuilder::addBackground(ParameterLabelItem* instrumentLabel,
}
void ParameterTreeBuilder::addPolarization(ParameterLabelItem* instrumentLabel,
const InstrumentItem* instrument)
InstrumentItem* instrument)
{
if (!instrument->withPolarizerAnalyzer())
return;
......
......@@ -20,20 +20,20 @@
#include <functional>
#include <variant>
class BackgroundItem;
class BeamDistributionItem;
class BeamItem;
class DetectorItem;
class DoubleProperty;
class InstrumentItem;
class Interference2DAbstractLatticeItem;
class ItemWithParticles;
class JobItem;
class ParameterContainerItem;
class ParameterItem;
class ParameterLabelItem;
class ParameterContainerItem;
class DoubleDescriptor;
class VectorProperty;
class ParticleLayoutItem;
class ItemWithParticles;
class Interference2DAbstractLatticeItem;
class BeamItem;
class BeamDistributionItem;
class DetectorItem;
class BackgroundItem;
class InstrumentItem;
class VectorProperty;
//! The ParameterTreeBuilder contains helper functions to create container
//! with ParameterItems. The ParameterItem appears in RealTimeView and provides real
......@@ -52,9 +52,9 @@ private:
//! add the job's sample
void addSample();
void addInstrument();
void addParameterItem(ParameterLabelItem* parent, const DoubleDescriptor& d,
void addParameterItem(ParameterLabelItem* parent, DoubleProperty& d,
const QString& label = QString());
void addParameterItem(ParameterLabelItem* parent, const VectorProperty& d);
void addParameterItem(ParameterLabelItem* parent, VectorProperty &d);
ParameterContainerItem* parameterContainer();
bool allowMagneticFields() const;
......@@ -72,7 +72,7 @@ private:
void addDetector(ParameterLabelItem* parentLabel, DetectorItem* detector);
void addBackground(ParameterLabelItem* instrumentLabel, BackgroundItem* backgroundItem);
void addPolarization(ParameterLabelItem* instrumentLabel, const InstrumentItem* instrument);
void addPolarization(ParameterLabelItem* instrumentLabel, InstrumentItem *instrument);
private:
JobItem* m_jobItem;
......
......@@ -89,7 +89,7 @@ int FormLayouter::addGroupOfValues(const QString& labelText, const DoubleDescrip
return addRow(labelText, w);
}
int FormLayouter::addVector(const VectorProperty& d, bool vertically /*= true*/)
int FormLayouter::addVector(VectorProperty& d, bool vertically /*= true*/)
{
auto* w = new QWidget(m_formLayout->parentWidget());
w->setObjectName("PropertyBaseWidget");
......@@ -129,28 +129,28 @@ void FormLayouter::addStructureEditingRow(QPushButton* button)
addRow(w);
}
int FormLayouter::addValue(const DoubleDescriptor& d)
int FormLayouter::addValue(DoubleProperty &d)
{
insertValue(m_formLayout->rowCount(), d);
return m_formLayout->rowCount() - 1;
}
int FormLayouter::addValue(const DoubleDescriptor& d, function<void(double)> onValueChange)
int FormLayouter::addValue(DoubleProperty &d, function<void(double)> onValueChange)
{
insertValue(m_formLayout->rowCount(), d, onValueChange);
return m_formLayout->rowCount() - 1;
}
void FormLayouter::insertValue(int row, const DoubleDescriptor& d)
void FormLayouter::insertValue(int row, DoubleProperty& d)
{
auto* ec = m_ec; // to allow copy-capture in the following lambda
insertValue(row, d, [ec, d](double newValue) { ec->setDouble(newValue, d); });
}
void FormLayouter::insertValue(int row, const DoubleDescriptor& d,
void FormLayouter::insertValue(int row, DoubleProperty &d,
function<void(double)> onValueChange)
{
auto labelText = d.label;
auto labelText = d.label();
if (!labelText.endsWith(":"))
labelText += ":";
......
......@@ -19,7 +19,6 @@
#include "GUI/View/SampleDesigner/SelectionContainerForm.h"
#include <QFormLayout>
class DoubleDescriptor;
class QPushButton;
class QString;
class QWidget;
......@@ -29,8 +28,8 @@ class VectorProperty;
//! 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
//! Helps to add edit controls which operate on Properties (DoubleProperty, VectorProperty, SelectionProperty).
//! 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.
class FormLayouter {
......@@ -79,7 +78,7 @@ public:
//!
//! 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
//! values represented by DoubleProperties. 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.
......@@ -89,7 +88,7 @@ public:
//! 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,
//! The DoubleSpinBox is initialized with the contents found in the DoubleProperty (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
......@@ -97,43 +96,43 @@ public:
//! 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.
int addValue(const DoubleDescriptor& d);
int addValue(DoubleProperty& d);
//! 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.
int addValue(const DoubleDescriptor& d, std::function<void(double)> onValueChange);
int addValue(DoubleProperty& d, std::function<void(double)> onValueChange);
//! Inserts a row with a bold printed label and a DoubleSpinBox.
//!
//! Same functionality as addValue(), please read there.
void insertValue(int row, const DoubleDescriptor& d);
void insertValue(int row, DoubleProperty &d);
//! Inserts a row with a bold printed label and a DoubleSpinBox.
//!
//! Same functionality as addValue(), please read there.
void insertValue(int row, const DoubleDescriptor& d, std::function<void(double)> onValueChange);
void insertValue(int row, DoubleProperty& d, std::function<void(double)> onValueChange);
//! 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
//! The label describes the set of the DoubleProperties and is located in the first column of the
//! layout. The DoubleSpinBoxes for each DoubleProperty 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(),
//! space to the right. For the creation, signaling, unit handling etc. of one DoubleProperty
//! the same applies as when adding a single DoubleProperty with the method addValue(),
//! therefore please read there for more details. Returns the newly added row.
int addGroupOfValues(const QString& labelText, const DoubleDescriptors& values);
//! 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.
//! Works the same as addGroupOfValues. The label is taken from the VectorProperty.
//! 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).
int addVector(const VectorProperty& d, bool vertically = true);
int addVector(VectorProperty &d, bool vertically = true);
//! Shows or hides the widgets in a row.
void setRowVisible(int row, bool visible);
......
......@@ -76,7 +76,7 @@ void InterferenceForm::createInterferenceWidgets()
// provide all the updating (data & UI), the method
// SampleEditorController::setDensityRelatedValueValue has to be called (instead of
// SampleEditorController::setDouble). For this we have the following lambda to add a value:
const auto addDensityRelatedValue = [&](DoubleDescriptor d) {
const auto addDensityRelatedValue = [this, &layouter, interference](DoubleProperty& d) {
layouter.addValue(
d, [=](double newValue) { m_ec->setDensityRelatedValue(interference, newValue, d); });
};
......
......@@ -83,9 +83,9 @@ void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int fir
bool vertically, bool addSpacer)
{
int col = firstCol;
for (const auto& valueDescriptor : valueDescriptors) {
for (const DoubleProperty& valueDescriptor : valueDescriptors) {
DoubleSpinBox* editor;
if (valueDescriptor.label == "Angle")
if (valueDescriptor.label() == "Angle")
editor = new DoubleSpinBox(valueDescriptor, false, 1, 1.0);
else
editor = new DoubleSpinBox(valueDescriptor);
......@@ -93,7 +93,7 @@ void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int fir
QObject::connect(editor, &DoubleSpinBox::baseValueChanged,
[=](double newValue) { setNewValue(newValue, valueDescriptor); });
QString labeltext = valueDescriptor.label;
QString labeltext = valueDescriptor.label();
if (!vertically && !labeltext.endsWith(":"))
labeltext += ":";
auto* label = new QLabel(labeltext, m_gridLayout->parentWidget());
......@@ -122,7 +122,7 @@ void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int fir
}
void LayerEditorUtils::addVectorToGrid(QGridLayout* m_gridLayout, int firstCol,
const VectorProperty& v, SampleEditorController* ec,
VectorProperty &v, SampleEditorController* ec,
bool vertically, bool addSpacer)
{
addMultiPropertyToGrid(m_gridLayout, firstCol, {v.x(), v.y(), v.z()}, ec, vertically,
......@@ -131,7 +131,7 @@ void LayerEditorUtils::addVectorToGrid(QGridLayout* m_gridLayout, int firstCol,
void LayerEditorUtils::addVectorToGrid(QGridLayout* m_gridLayout, int firstCol,
const VectorProperty& v,
VectorProperty& v,
function<void(double, DoubleDescriptor)> setNewValue,
bool vertically, bool addSpacer)
{
......
......@@ -61,11 +61,11 @@ void addMultiPropertyToGrid(QGridLayout* m_gridLayout, int firstCol,
//! Create DoubleSpinBoxes for the DoubeDescriptors and connect them to
//! SampleEditorController::setDouble()
void addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, const VectorProperty& v,
void addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, VectorProperty& v,
SampleEditorController* ec, bool vertically, bool addSpacer);
//! Create DoubleSpinBoxes for the DoubeDescriptors and connect them to the given setNewValue()
void addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, const VectorProperty& v,
void addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, VectorProperty &v,
std::function<void(double, DoubleDescriptor)> setNewValue, bool vertically,
bool addSpacer);
......
......@@ -99,9 +99,9 @@ void MaterialInplaceForm::createWidgets()
values << material->sldRe() << material->sldIm();
int col = 0;
for (const auto& d : values) {
for (const DoubleProperty& d : values) {
auto* editor = new DoubleLineEdit(this, d);
auto* label = new QLabel(d.label, this);
auto* label = new QLabel(d.label(), this);
label->setBuddy(editor);
QObject::connect(editor, &DoubleLineEdit::baseValueChanged,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment