diff --git a/GUI/Model/Data/AxesItems.cpp b/GUI/Model/Data/AxesItems.cpp index 040f5276ea139aa325da24d51849bd30350a6750..08bcae56edc41afc4bc44f2ce1a8612bfbbd3a9b 100644 --- a/GUI/Model/Data/AxesItems.cpp +++ b/GUI/Model/Data/AxesItems.cpp @@ -14,6 +14,7 @@ #include "GUI/Model/Data/AxesItems.h" #include "Base/Axis/FixedBinAxis.h" +#include "GUI/Model/Types/DoubleDescriptor.h" const int max_detector_pixels = 65536; @@ -34,9 +35,9 @@ SessionItem* BasicAxisItem::binsItem() const return getItem(P_NBINS); } -double BasicAxisItem::lowerBound() const +DoubleDescriptor BasicAxisItem::lowerBound() const { - return getItemValue(P_MIN_DEG).toDouble(); + return DoubleDescriptor(getItem(P_MIN_DEG), Unit::other); } void BasicAxisItem::setLowerBound(double value) @@ -49,9 +50,9 @@ SessionItem* BasicAxisItem::lowerBoundItem() const return getItem(P_MIN_DEG); } -double BasicAxisItem::upperBound() const +DoubleDescriptor BasicAxisItem::upperBound() const { - return getItemValue(P_MAX_DEG).toDouble(); + return DoubleDescriptor(getItem(P_MAX_DEG), Unit::other); } void BasicAxisItem::setUpperBound(double value) @@ -115,6 +116,11 @@ bool BasicAxisItem::visibilityValue() const return visibilityItem()->value().toBool(); } +void BasicAxisItem::setVisibilityValue(bool b) +{ + setItemValue(P_IS_VISIBLE, b); +} + bool BasicAxisItem::isVisibilityPropertyName(const QString& name) { return name == P_IS_VISIBLE; @@ -167,6 +173,11 @@ void AmplitudeAxisItem::setLogScale(bool value) setItemValue(P_IS_LOGSCALE, value); } +SessionItem* AmplitudeAxisItem::logScaleItem() const +{ + return getItem(P_IS_LOGSCALE); +} + bool AmplitudeAxisItem::isLogScalePropertyName(const QString& name) { return name == P_IS_LOGSCALE; diff --git a/GUI/Model/Data/AxesItems.h b/GUI/Model/Data/AxesItems.h index 2571a54a028b7b14317a55f33f76da6f9666d308..356a51cca02a903f3c5fd9efd50e3d542a5291b7 100644 --- a/GUI/Model/Data/AxesItems.h +++ b/GUI/Model/Data/AxesItems.h @@ -16,6 +16,7 @@ #define BORNAGAIN_GUI_MODEL_DATA_AXESITEMS_H #include "GUI/Model/Session/SessionItem.h" +#include "GUI/Model/Types/DoubleDescriptor.h" #include <memory> class IAxis; @@ -39,11 +40,11 @@ public: void setBinCount(int value); SessionItem* binsItem() const; - double lowerBound() const; + DoubleDescriptor lowerBound() const; void setLowerBound(double value); SessionItem* lowerBoundItem() const; - double upperBound() const; + DoubleDescriptor upperBound() const; void setUpperBound(double value); SessionItem* upperBoundItem() const; @@ -61,6 +62,7 @@ public: SessionItem* visibilityItem() const; bool visibilityValue() const; + void setVisibilityValue(bool b); static bool isVisibilityPropertyName(const QString& name); protected: @@ -80,6 +82,7 @@ public: bool isLogScale() const; void setLogScale(bool value); + SessionItem* logScaleItem() const; static bool isLogScalePropertyName(const QString& name); bool isLocked() const; diff --git a/GUI/Model/Data/DataItem.cpp b/GUI/Model/Data/DataItem.cpp index 65f942c70b9eb44e7e233e64fe8d1d0ccceb02ee..805ebe736a496ba124cb52876620c1ec692a4d31 100644 --- a/GUI/Model/Data/DataItem.cpp +++ b/GUI/Model/Data/DataItem.cpp @@ -96,6 +96,11 @@ SessionItem* DataItem::getAxesUnitsItem() const return getItem(P_AXES_UNITS); } +SelectionDescriptor<QString> DataItem::axesUnits() const +{ + return SelectionDescriptor<QString>(getItem(P_AXES_UNITS)); +} + bool DataItem::isAxesUnitsPropertyName(const QString& name) { return name == P_AXES_UNITS; diff --git a/GUI/Model/Data/DataItem.h b/GUI/Model/Data/DataItem.h index 648006ee0e594045415fa3515d5ff39b71c9b8e1..517a3087df7f6cece1306c30b694e7df52a923a3 100644 --- a/GUI/Model/Data/DataItem.h +++ b/GUI/Model/Data/DataItem.h @@ -16,6 +16,7 @@ #define BORNAGAIN_GUI_MODEL_DATA_DATAITEM_H #include "Device/Data/OutputData.h" +#include "GUI/Model/Group/SelectionDescriptor.h" #include "GUI/Model/IO/SaveLoadInterface.h" #include "GUI/Model/Session/SessionItem.h" #include <QDateTime> @@ -60,6 +61,7 @@ public: void setAxesUnits(const ComboProperty& units); SessionItem* getAxesUnitsItem() const; + SelectionDescriptor<QString> axesUnits() const; static bool isAxesUnitsPropertyName(const QString& name); virtual void setXaxisTitle(const QString& title) = 0; diff --git a/GUI/Model/Data/IntensityDataItem.cpp b/GUI/Model/Data/IntensityDataItem.cpp index 5a6321767b4d0cdbb941c36e3c4f3732d011ee2a..6e4083c9122adbbb62c37168ac9d97422ee3acec 100644 --- a/GUI/Model/Data/IntensityDataItem.cpp +++ b/GUI/Model/Data/IntensityDataItem.cpp @@ -165,6 +165,11 @@ void IntensityDataItem::setGradient(const ComboProperty& gradient) setItemValue(P_GRADIENT, gradient.variant()); } +SelectionDescriptor<QString> IntensityDataItem::gradient() const +{ + return SelectionDescriptor<QString>(getItem(P_GRADIENT)); +} + bool IntensityDataItem::isLogz() const { return zAxisItem()->isLogScale(); diff --git a/GUI/Model/Data/IntensityDataItem.h b/GUI/Model/Data/IntensityDataItem.h index 08f256990c12cd4ee14d83cfb46a27d0a69252e3..058ccaad529f988a54afd95b227eac72e2d2fb9b 100644 --- a/GUI/Model/Data/IntensityDataItem.h +++ b/GUI/Model/Data/IntensityDataItem.h @@ -16,6 +16,7 @@ #define BORNAGAIN_GUI_MODEL_DATA_INTENSITYDATAITEM_H #include "GUI/Model/Data/DataItem.h" +#include "GUI/Model/Group/SelectionDescriptor.h" class BasicAxisItem; class AmplitudeAxisItem; @@ -69,6 +70,7 @@ public: QString getGradientValue() const; ComboProperty getGradient() const; void setGradient(const ComboProperty& gradient); + SelectionDescriptor<QString> gradient() const; bool isLogz() const; bool isInterpolated() const; diff --git a/GUI/Model/Group/SelectionDescriptor.h b/GUI/Model/Group/SelectionDescriptor.h index 9f4f34fd8e9a5b15bdbbf31d2389bb60d241430c..0ab6ffff99efec923acd763814c333ac1ae1a916 100644 --- a/GUI/Model/Group/SelectionDescriptor.h +++ b/GUI/Model/Group/SelectionDescriptor.h @@ -41,11 +41,15 @@ public: //! Right now with SessionModel still in place, in most 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. //! //! 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. //! //! 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 @@ -54,14 +58,16 @@ template <typename T> class SelectionDescriptor : public AbstractSelectionDescri public: SelectionDescriptor() = default; - //! Initialize the members by means of a GroupItem. + //! 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(GroupItem* item) + explicit SelectionDescriptor(SessionItem* item) { label = item->displayName(); + tooltip = item->toolTip(); options = item->value().value<ComboProperty>().getValues(); currentIndexSetter = [=](int index) { auto comboProperty = item->value().value<ComboProperty>(); @@ -73,8 +79,11 @@ public: }; currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); }; - if constexpr (std::is_pointer<T>::value) - currentItem = [=] { return dynamic_cast<T>(item->currentItem()); }; + if constexpr (std::is_pointer<T>::value) { + if (auto* groupItem = dynamic_cast<GroupItem*>(item)) + currentItem = [=] { return dynamic_cast<T>(groupItem->currentItem()); }; + } else if constexpr (std::is_same<T, QString>::value) + currentItem = [=] { return item->value().value<ComboProperty>().getValue(); }; } void setCurrentIndex(int newIndex) const override { currentIndexSetter(newIndex); }