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

SelectionDescriptor: rm SessionItem

parent ae93e86a
No related branches found
No related tags found
1 merge request!1146GUI: rm SessionItem from descriptors
......@@ -25,9 +25,8 @@
//! Describes properties of a double value which are necessary to allow GUI representation, editing
//! the value, undo/redo, unit conversion.
//!
//! By using this class, the underlying data scheme is hidden from the user of the data. This e.g.
//! eases SessionItem migration. The underlying implementation can be a SessionItem, a simple double
//! member, or any other construction to hold a double value.
//! By using this class, the underlying data scheme is hidden from the user of the data. The underlying implementation can be a simple double member,
//! or any other construction to hold a double value.
//! It could also describe a value which is not even represented by an existing double, but is only
//! a calculated value. In this case it might apply that there is no setter possible, which is still
//! allowed as long as care is taken not trying to call the setter.
......
......@@ -15,7 +15,6 @@
#ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONDESCRIPTOR_H
#define BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONDESCRIPTOR_H
#include "GUI/Model/BaseItem/SessionItem.h"
#include "GUI/Util/ComboProperty.h"
#include <QString>
#include <QStringList>
......@@ -36,29 +35,18 @@ public:
//! Describes a selection (various possibilities and the current one).
//!
//! Usually a selection is presented as a combo box.
//! Right now with SessionModel still in place, in many cases a selection changes the current item
//! of a group item, i.e. it changes the class of a certain child item (e.g.
//! XRotationItem*/YRotationItem*/...).
//! Also a SessionItem holding only a ComboProperty (but not switching children like GroupItem) can
//! be wrapped. For example IntensityDataItem::gradient() is simply a list of QStrings.
//!
//! With the migration, more and more SelectionDescriptor operate on a SelectionProperty. Please
//! refer to this class for more information.
//! 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 not used with a GroupItem, but with a "normal" ComboProperty holder, the template parameter
//! can be a QString, so currentItem() returns the currently selected string.
//! 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.
//!
//! By using this class, the underlying data scheme is hidden from the user of the data. This e.g.
//! eases SessionItem migration. The underlying implementation can be a GroupItem, a simple pointer
//! member, a std::variant or any other construction to define a selection.
//!
//! For easy UI creation, there are functions like GUI:Util::createSelectionCombo() which take a
//! descriptor and fully initialize the created combo box.
//!
......@@ -69,31 +57,6 @@ class SelectionDescriptor : public AbstractSelectionDescriptor {
public:
SelectionDescriptor() = default;
//! Initialize the members by means of a SessionItem containing a ComboProperty. This can be
//! a GroupItem or any other property.
//!
//! currentItem can only be initialized if the template parameter is a pointer (like
//! RotationItem*). If it is e.g. a std::variant<>, the currentItem has to be initialized by the
//! caller. Only for easier migration. Should be removed after SessionItem refactoring.
explicit SelectionDescriptor(SessionItem* item)
{
label = item->displayName();
tooltip = item->toolTip();
options = item->value().value<ComboProperty>().values();
currentIndexSetter = [=](int index) {
auto comboProperty = item->value().value<ComboProperty>();
if (comboProperty.currentIndex() != index) {
comboProperty.setCurrentIndex(index);
item->setValue(QVariant::fromValue<ComboProperty>(comboProperty));
}
};
currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); };
if constexpr (std::is_same<T, QString>::value)
currentItem = [=] { return item->value().value<ComboProperty>().currentValue(); };
}
operator T() const { return currentItem(); }
void setCurrentIndex(int newIndex) const override { currentIndexSetter(newIndex); }
......
......@@ -12,11 +12,12 @@
//
// ************************************************************************************************
#include "GUI/Model/Device/SpecularBeamInclinationItem.h"
#include "Base/Axis/IAxis.h"
#include "Base/Const/Units.h"
#include "GUI/Model/CatDevice/DistributionItemCatalog.h"
#include "GUI/Model/Device/PointwiseAxisItem.h"
#include "GUI/Model/Device/SpecularBeamInclinationItem.h"
#include "GUI/Support/XML/Serialize.h"
#include "GUI/Support/XML/UtilXML.h"
namespace {
......
......@@ -12,14 +12,14 @@
//
// ************************************************************************************************
#include "GUI/View/SampleDesigner/FormLayouter.h"
#include "Base/Util/Assert.h"
#include "GUI/Model/Descriptor/UIntDescriptor.h"
#include "GUI/Model/Descriptor/VectorDescriptor.h"
#include "GUI/View/Common/DoubleSpinBox.h"
#include "GUI/View/SampleDesigner/FormLayouter.h"
#include "GUI/View/SampleDesigner/LayerEditorUtils.h"
#include "GUI/View/SampleDesigner/SampleEditorController.h"
#include "GUI/View/Tool/GroupBoxCollapser.h"
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
......
......@@ -15,6 +15,7 @@
#ifndef BORNAGAIN_GUI_VIEW_TOOL_WIDGETUTILS_H
#define BORNAGAIN_GUI_VIEW_TOOL_WIDGETUTILS_H
#include "Fit/Param/RealLimits.h"
#include "GUI/Model/Descriptor/SelectionDescriptor.h"
#include "GUI/Support/Type/Unit.h"
#include "GUI/View/Common/CustomEventFilters.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment