From b43c42eb0d29fc525ace650e5c4dc1927e4c3596 Mon Sep 17 00:00:00 2001 From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de> Date: Wed, 7 Dec 2022 16:52:18 +0100 Subject: [PATCH] delete SelectionDescriptor --- GUI/Model/Descriptor/SelectionDescriptor.h | 76 ------------------- GUI/Model/Descriptor/SelectionProperty.h | 1 - GUI/Model/Device/InstrumentItems.h | 1 - GUI/Model/Device/RectangularDetectorItem.h | 1 + GUI/View/Common/DoubleLineEdit.h | 2 +- GUI/View/Common/DoubleSpinBox.h | 4 +- GUI/View/SampleDesigner/FormLayouter.h | 2 +- .../LatticeTypeSelectionForm.cpp | 6 +- GUI/View/SampleDesigner/LayerEditorUtils.cpp | 14 ++-- GUI/View/SampleDesigner/LayerEditorUtils.h | 14 ++-- .../SampleDesigner/SelectionContainerForm.h | 18 ++--- GUI/View/Tool/WidgetUtils.cpp | 3 +- GUI/View/Tool/WidgetUtils.h | 1 + 13 files changed, 34 insertions(+), 109 deletions(-) delete mode 100644 GUI/Model/Descriptor/SelectionDescriptor.h diff --git a/GUI/Model/Descriptor/SelectionDescriptor.h b/GUI/Model/Descriptor/SelectionDescriptor.h deleted file mode 100644 index 697ea680ed7..00000000000 --- a/GUI/Model/Descriptor/SelectionDescriptor.h +++ /dev/null @@ -1,76 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/Model/Descriptor/SelectionDescriptor.h -//! @brief Defines class SelectionDescriptor -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONDESCRIPTOR_H -#define BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONDESCRIPTOR_H - -#include "GUI/Util/ComboProperty.h" -#include <QString> -#include <QStringList> -#include <functional> - -//! Abstract base class for SelectionDescriptor to ease referencing. -class AbstractSelectionDescriptor { -public: - virtual ~AbstractSelectionDescriptor() = default; - - //! Set currently selected option - virtual void setCurrentIndex(int newIndex) const = 0; - - //! Get currently selected option - virtual int currentIndex() const = 0; -}; - -//! Describes a selection (various possibilities and the current one). -//! -//! Usually a selection is presented as a combo box. -//! -//! SelectionDescriptor operate on a SelectionProperty. Please refer to this class for more -//! information. -//! -//! The template parameter defines the type of the current item. This can be a pointer to a common -//! base class (like RotationItem*), but it also can be a std::variant<...>, which is useful if -//! no dedicated common base class exists (like for the roughness items LayerZeroRoughnessItem and -//! LayerBasicRoughnessItem). -//! If used with a ComboProperty holder, the template parameter can be a QString, so currentItem() -//! returns the currently selected string. -//! -//! Note that this class does not provide (*implement*) a selection, but *provide -//! information* about a selection. For implementing a selection, please see SelectionProperty. -//! -//! For easy UI creation, there are functions like GUI:Util::createSelectionCombo() which take a -//! descriptor and fully initialize the created combo box. -//! -//! \sa SelectionProperty -//! -template <typename T> -class SelectionDescriptor : public AbstractSelectionDescriptor { -public: - SelectionDescriptor() = default; - - operator T() const { return currentItem(); } - - void setCurrentIndex(int newIndex) const override { currentIndexSetter(newIndex); } - - int currentIndex() const override { return currentIndexGetter(); } - - QString label; //!< A label text (short, no trailing colon) - QString tooltip; //!< Tooltip text - QStringList options; //!< List of options, usually presented as combo entries - std::function<void(int)> currentIndexSetter; //!< Function to set currently selected option - std::function<int()> currentIndexGetter; //!< Function to get currently selected option - std::function<T()> currentItem; //!< Function to get currently selected item -}; - -#endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONDESCRIPTOR_H diff --git a/GUI/Model/Descriptor/SelectionProperty.h b/GUI/Model/Descriptor/SelectionProperty.h index 59db19da3a3..ed3193a00ef 100644 --- a/GUI/Model/Descriptor/SelectionProperty.h +++ b/GUI/Model/Descriptor/SelectionProperty.h @@ -15,7 +15,6 @@ #ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONPROPERTY_H #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONPROPERTY_H -#include "GUI/Model/Descriptor/SelectionDescriptor.h" #include "GUI/Support/XML/Streamer.h" //! Abstract base class for SelectionProperty to ease referencing. diff --git a/GUI/Model/Device/InstrumentItems.h b/GUI/Model/Device/InstrumentItems.h index 5e6bda34b90..21540d7ad04 100644 --- a/GUI/Model/Device/InstrumentItems.h +++ b/GUI/Model/Device/InstrumentItems.h @@ -18,7 +18,6 @@ #include "GUI/Model/CatDevice/BackgroundItemCatalog.h" #include "GUI/Model/CatDevice/DetectorItemCatalog.h" #include "GUI/Model/Descriptor/AxisProperty.h" -#include "GUI/Model/Descriptor/SelectionDescriptor.h" #include "GUI/Model/Descriptor/SelectionProperty.h" #include "GUI/Model/Descriptor/VectorProperty.h" #include "GUI/Model/Device/BackgroundItems.h" diff --git a/GUI/Model/Device/RectangularDetectorItem.h b/GUI/Model/Device/RectangularDetectorItem.h index 71a1a4ace12..9e271576ce6 100644 --- a/GUI/Model/Device/RectangularDetectorItem.h +++ b/GUI/Model/Device/RectangularDetectorItem.h @@ -18,6 +18,7 @@ #include "Device/Detector/RectangularDetector.h" #include "GUI/Model/Descriptor/VectorProperty.h" #include "GUI/Model/Device/DetectorItems.h" +#include "GUI/Util/ComboProperty.h" class RectangularDetectorItem : public DetectorItem { public: diff --git a/GUI/View/Common/DoubleLineEdit.h b/GUI/View/Common/DoubleLineEdit.h index d41b2fa0711..2b77ef94d36 100644 --- a/GUI/View/Common/DoubleLineEdit.h +++ b/GUI/View/Common/DoubleLineEdit.h @@ -38,7 +38,7 @@ public: signals: //! Emitted whenever the value changes. //! - //! newBaseValue is in the unit of the valueDescriptor. + //! newBaseValue is in the unit of the valueProperty. void baseValueChanged(double newBaseValue); private slots: diff --git a/GUI/View/Common/DoubleSpinBox.h b/GUI/View/Common/DoubleSpinBox.h index 5a298fde617..ee036ebefa7 100644 --- a/GUI/View/Common/DoubleSpinBox.h +++ b/GUI/View/Common/DoubleSpinBox.h @@ -47,7 +47,7 @@ public: //! Returns the unit of the contained DoubleProperty. //! //! If the unit is defined as a string, this method returns Unit::other. To get the string, use - //! valueDescriptor().unit + //! valueProperty().unit Unit baseUnit() const; //! Update the shown value to the one contained in the value descriptor. @@ -58,7 +58,7 @@ public: signals: //! Emitted whenever the value changes. //! - //! newBaseValue is in the unit of the valueDescriptor. + //! newBaseValue is in the unit of the valueProperty. void baseValueChanged(double newBaseValue); protected: diff --git a/GUI/View/SampleDesigner/FormLayouter.h b/GUI/View/SampleDesigner/FormLayouter.h index 4bcdcba9818..d98fb41e2ea 100644 --- a/GUI/View/SampleDesigner/FormLayouter.h +++ b/GUI/View/SampleDesigner/FormLayouter.h @@ -115,7 +115,7 @@ public: //! Same functionality as addValue(), please read there. void insertValue(int row, DoubleProperty& d, std::function<void(double)> onValueChange); - //! Adds a row with a bold printed label and a set of DoubleDescriptors. + //! Adds a row with a bold printed label and a set of DoubleProperties. //! //! 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 diff --git a/GUI/View/SampleDesigner/LatticeTypeSelectionForm.cpp b/GUI/View/SampleDesigner/LatticeTypeSelectionForm.cpp index 6055e19267e..277988b7e6b 100644 --- a/GUI/View/SampleDesigner/LatticeTypeSelectionForm.cpp +++ b/GUI/View/SampleDesigner/LatticeTypeSelectionForm.cpp @@ -30,13 +30,13 @@ LatticeTypeSelectionForm::LatticeTypeSelectionForm( void LatticeTypeSelectionForm::createContent() { auto* currentLatticeType = m_interferenceItem->latticeType().currentItem(); - const auto valueDescriptors = currentLatticeType->geometryValues(false); - const bool vertical = valueDescriptors.size() > 2; + const auto valueProperties = currentLatticeType->geometryValues(false); + const bool vertical = valueProperties.size() > 2; const auto onValueChange = [this](double newValue, DoubleProperty& d) { m_ec->setDensityRelatedValue(m_interferenceItem, newValue, d); }; - LayerEditorUtils::addMultiPropertyToGrid(m_gridLayout, 1, valueDescriptors, onValueChange, + LayerEditorUtils::addMultiPropertyToGrid(m_gridLayout, 1, valueProperties, onValueChange, vertical, false); m_integrateOverXiCheckBox = new QCheckBox("Integrate over Xi", this); diff --git a/GUI/View/SampleDesigner/LayerEditorUtils.cpp b/GUI/View/SampleDesigner/LayerEditorUtils.cpp index a332500f84d..865d3dd1f5a 100644 --- a/GUI/View/SampleDesigner/LayerEditorUtils.cpp +++ b/GUI/View/SampleDesigner/LayerEditorUtils.cpp @@ -65,7 +65,7 @@ void LayerEditorUtils::updateLabelUnit(QLabel* label) } void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int firstCol, - const DoublePropertyRefs& valueDescriptors, + const DoublePropertyRefs& valueProperties, SampleEditorController* ec, bool vertically, bool addSpacer) { @@ -73,17 +73,17 @@ void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int fir ec->setDouble(newValue, d); }; - addMultiPropertyToGrid(m_gridLayout, firstCol, valueDescriptors, setNewValue, vertically, + addMultiPropertyToGrid(m_gridLayout, firstCol, valueProperties, setNewValue, vertically, addSpacer); } void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int firstCol, - const DoublePropertyRefs& valueDescriptors, + const DoublePropertyRefs& valueProperties, function<void(double, DoubleProperty&)> setNewValue, bool vertically, bool addSpacer) { int col = firstCol; - for (DoubleProperty& d : valueDescriptors) { + for (DoubleProperty& d : valueProperties) { DoubleSpinBox* editor; if (d.label() == "Angle") editor = new DoubleSpinBox(d, false, 1, 1.0); @@ -114,11 +114,11 @@ void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int fir } void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int firstCol, - const DoublePropertyRefs& valueDescriptors, + const DoublePropertyRefs& valueProperties, SampleEditorController* ec, bool addSpacer) { - addMultiPropertyToGrid(m_gridLayout, firstCol, valueDescriptors, ec, - valueDescriptors.size() > 1, addSpacer); + addMultiPropertyToGrid(m_gridLayout, firstCol, valueProperties, ec, + valueProperties.size() > 1, addSpacer); } void LayerEditorUtils::addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, VectorProperty& v, diff --git a/GUI/View/SampleDesigner/LayerEditorUtils.h b/GUI/View/SampleDesigner/LayerEditorUtils.h index eadd0180559..9e7c88cddc6 100644 --- a/GUI/View/SampleDesigner/LayerEditorUtils.h +++ b/GUI/View/SampleDesigner/LayerEditorUtils.h @@ -43,28 +43,28 @@ namespace LayerEditorUtils { void updateLabelUnit(QLabel* label); void updateLabelUnit(QLabel* label, DoubleSpinBox* editor); -//! Create DoubleSpinBoxes for the DoubeDescriptors and connect them to +//! Create DoubleSpinBoxes for the DoubleProperties and connect them to //! SampleEditorController::setDouble() void addMultiPropertyToGrid(QGridLayout* m_gridLayout, int firstCol, - const DoublePropertyRefs& valueDescriptors, SampleEditorController* ec, + const DoublePropertyRefs& valueProperties, SampleEditorController* ec, bool vertically, bool addSpacer); -//! Create DoubleSpinBoxes for the DoubeDescriptors and connect them to the given setNewValue() +//! Create DoubleSpinBoxes for the DoubleProperties and connect them to the given setNewValue() void addMultiPropertyToGrid(QGridLayout* m_gridLayout, int firstCol, - const DoublePropertyRefs& valueDescriptors, + const DoublePropertyRefs& valueProperties, std::function<void(double, DoubleProperty&)> setNewValue, bool vertically, bool addSpacer); void addMultiPropertyToGrid(QGridLayout* m_gridLayout, int firstCol, - const DoublePropertyRefs& valueDescriptors, SampleEditorController* ec, + const DoublePropertyRefs& valueProperties, SampleEditorController* ec, bool addSpacer); -//! Create DoubleSpinBoxes for the DoubeDescriptors and connect them to +//! Create DoubleSpinBoxes for the DoubleProperties and connect them to //! SampleEditorController::setDouble() 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() +//! Create DoubleSpinBoxes for the DoubleProperties and connect them to the given setNewValue() void addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, VectorProperty& v, std::function<void(double, DoubleProperty&)> setNewValue, bool vertically, bool addSpacer); diff --git a/GUI/View/SampleDesigner/SelectionContainerForm.h b/GUI/View/SampleDesigner/SelectionContainerForm.h index e38b51bdbeb..c869a97b39f 100644 --- a/GUI/View/SampleDesigner/SelectionContainerForm.h +++ b/GUI/View/SampleDesigner/SelectionContainerForm.h @@ -62,7 +62,7 @@ protected: } private: - //! Remove all descriptors from the layout + //! Remove all properties from the layout void clear() { auto* layoutItemOfComboBox = m_gridLayout->itemAtPosition(1, 0); @@ -77,22 +77,22 @@ protected: SampleEditorController* m_ec; }; -//! A widget to contain a selection, defined by a SelectionDescriptor. +//! A widget to contain a selection, defined by a SelectionProperty. //! //! 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, +//! values represented by DoubleProperties. The list of DoubleProperties is queried by calling +//! LayerEditorUtils::doublePropertiesOfItem(). To have the correct DoubleProperties 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. +//! expect the template type you defined for SelectionProperty. //! //! Example: -//! SelectionDescriptor<RotationItem*> => LayerEditorUtils::doubleDescriptorsOfItem(RotationItem*) +//! SelectionProperty<RotationItemCatalog> => LayerEditorUtils::doublePropertiesOfItem(RotationItem*) //! -//! The connection from selection combo -> SelectionDescriptor is made via +//! The connection from selection combo -> SelectionProperty 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 +//! For each DoubleProperty, a unit-aware DoubleSpinBox is created. The connection from each +//! spinbox to the DoubleProperty 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 diff --git a/GUI/View/Tool/WidgetUtils.cpp b/GUI/View/Tool/WidgetUtils.cpp index 2888eeb8b3d..7a1f9168a22 100644 --- a/GUI/View/Tool/WidgetUtils.cpp +++ b/GUI/View/Tool/WidgetUtils.cpp @@ -12,10 +12,11 @@ // // ************************************************************************************************ -#include "GUI/View/Tool/WidgetUtils.h" +#include "GUI/Util/ComboProperty.h" #include "GUI/View/Common/DoubleSpinBox.h" #include "GUI/View/Common/ScientificSpinBox.h" #include "GUI/View/Tool/EditUtil.h" +#include "GUI/View/Tool/WidgetUtils.h" #include <QCheckBox> #include <QFormLayout> #include <QLabel> diff --git a/GUI/View/Tool/WidgetUtils.h b/GUI/View/Tool/WidgetUtils.h index c7ff84f1a84..a813d7d3a29 100644 --- a/GUI/View/Tool/WidgetUtils.h +++ b/GUI/View/Tool/WidgetUtils.h @@ -22,6 +22,7 @@ #include <QComboBox> #include <variant> +class ComboProperty; class QSpinBox; class QCheckBox; class DoubleSpinBox; -- GitLab