Skip to content
Snippets Groups Projects
Commit 17d9de8a authored by Matthias Puchner's avatar Matthias Puchner
Browse files

add some getters/setters

parent 2aa0b997
No related branches found
No related tags found
1 merge request!469Harmonized & less generic UI for intensity properties widget
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "GUI/Model/Data/AxesItems.h" #include "GUI/Model/Data/AxesItems.h"
#include "Base/Axis/FixedBinAxis.h" #include "Base/Axis/FixedBinAxis.h"
#include "GUI/Model/Types/DoubleDescriptor.h"
const int max_detector_pixels = 65536; const int max_detector_pixels = 65536;
...@@ -34,9 +35,9 @@ SessionItem* BasicAxisItem::binsItem() const ...@@ -34,9 +35,9 @@ SessionItem* BasicAxisItem::binsItem() const
return getItem(P_NBINS); 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) void BasicAxisItem::setLowerBound(double value)
...@@ -49,9 +50,9 @@ SessionItem* BasicAxisItem::lowerBoundItem() const ...@@ -49,9 +50,9 @@ SessionItem* BasicAxisItem::lowerBoundItem() const
return getItem(P_MIN_DEG); 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) void BasicAxisItem::setUpperBound(double value)
...@@ -115,6 +116,11 @@ bool BasicAxisItem::visibilityValue() const ...@@ -115,6 +116,11 @@ bool BasicAxisItem::visibilityValue() const
return visibilityItem()->value().toBool(); return visibilityItem()->value().toBool();
} }
void BasicAxisItem::setVisibilityValue(bool b)
{
setItemValue(P_IS_VISIBLE, b);
}
bool BasicAxisItem::isVisibilityPropertyName(const QString& name) bool BasicAxisItem::isVisibilityPropertyName(const QString& name)
{ {
return name == P_IS_VISIBLE; return name == P_IS_VISIBLE;
...@@ -167,6 +173,11 @@ void AmplitudeAxisItem::setLogScale(bool value) ...@@ -167,6 +173,11 @@ void AmplitudeAxisItem::setLogScale(bool value)
setItemValue(P_IS_LOGSCALE, value); setItemValue(P_IS_LOGSCALE, value);
} }
SessionItem* AmplitudeAxisItem::logScaleItem() const
{
return getItem(P_IS_LOGSCALE);
}
bool AmplitudeAxisItem::isLogScalePropertyName(const QString& name) bool AmplitudeAxisItem::isLogScalePropertyName(const QString& name)
{ {
return name == P_IS_LOGSCALE; return name == P_IS_LOGSCALE;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define BORNAGAIN_GUI_MODEL_DATA_AXESITEMS_H #define BORNAGAIN_GUI_MODEL_DATA_AXESITEMS_H
#include "GUI/Model/Session/SessionItem.h" #include "GUI/Model/Session/SessionItem.h"
#include "GUI/Model/Types/DoubleDescriptor.h"
#include <memory> #include <memory>
class IAxis; class IAxis;
...@@ -39,11 +40,11 @@ public: ...@@ -39,11 +40,11 @@ public:
void setBinCount(int value); void setBinCount(int value);
SessionItem* binsItem() const; SessionItem* binsItem() const;
double lowerBound() const; DoubleDescriptor lowerBound() const;
void setLowerBound(double value); void setLowerBound(double value);
SessionItem* lowerBoundItem() const; SessionItem* lowerBoundItem() const;
double upperBound() const; DoubleDescriptor upperBound() const;
void setUpperBound(double value); void setUpperBound(double value);
SessionItem* upperBoundItem() const; SessionItem* upperBoundItem() const;
...@@ -61,6 +62,7 @@ public: ...@@ -61,6 +62,7 @@ public:
SessionItem* visibilityItem() const; SessionItem* visibilityItem() const;
bool visibilityValue() const; bool visibilityValue() const;
void setVisibilityValue(bool b);
static bool isVisibilityPropertyName(const QString& name); static bool isVisibilityPropertyName(const QString& name);
protected: protected:
...@@ -80,6 +82,7 @@ public: ...@@ -80,6 +82,7 @@ public:
bool isLogScale() const; bool isLogScale() const;
void setLogScale(bool value); void setLogScale(bool value);
SessionItem* logScaleItem() const;
static bool isLogScalePropertyName(const QString& name); static bool isLogScalePropertyName(const QString& name);
bool isLocked() const; bool isLocked() const;
......
...@@ -96,6 +96,11 @@ SessionItem* DataItem::getAxesUnitsItem() const ...@@ -96,6 +96,11 @@ SessionItem* DataItem::getAxesUnitsItem() const
return getItem(P_AXES_UNITS); return getItem(P_AXES_UNITS);
} }
SelectionDescriptor<QString> DataItem::axesUnits() const
{
return SelectionDescriptor<QString>(getItem(P_AXES_UNITS));
}
bool DataItem::isAxesUnitsPropertyName(const QString& name) bool DataItem::isAxesUnitsPropertyName(const QString& name)
{ {
return name == P_AXES_UNITS; return name == P_AXES_UNITS;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define BORNAGAIN_GUI_MODEL_DATA_DATAITEM_H #define BORNAGAIN_GUI_MODEL_DATA_DATAITEM_H
#include "Device/Data/OutputData.h" #include "Device/Data/OutputData.h"
#include "GUI/Model/Group/SelectionDescriptor.h"
#include "GUI/Model/IO/SaveLoadInterface.h" #include "GUI/Model/IO/SaveLoadInterface.h"
#include "GUI/Model/Session/SessionItem.h" #include "GUI/Model/Session/SessionItem.h"
#include <QDateTime> #include <QDateTime>
...@@ -60,6 +61,7 @@ public: ...@@ -60,6 +61,7 @@ public:
void setAxesUnits(const ComboProperty& units); void setAxesUnits(const ComboProperty& units);
SessionItem* getAxesUnitsItem() const; SessionItem* getAxesUnitsItem() const;
SelectionDescriptor<QString> axesUnits() const;
static bool isAxesUnitsPropertyName(const QString& name); static bool isAxesUnitsPropertyName(const QString& name);
virtual void setXaxisTitle(const QString& title) = 0; virtual void setXaxisTitle(const QString& title) = 0;
......
...@@ -165,6 +165,11 @@ void IntensityDataItem::setGradient(const ComboProperty& gradient) ...@@ -165,6 +165,11 @@ void IntensityDataItem::setGradient(const ComboProperty& gradient)
setItemValue(P_GRADIENT, gradient.variant()); setItemValue(P_GRADIENT, gradient.variant());
} }
SelectionDescriptor<QString> IntensityDataItem::gradient() const
{
return SelectionDescriptor<QString>(getItem(P_GRADIENT));
}
bool IntensityDataItem::isLogz() const bool IntensityDataItem::isLogz() const
{ {
return zAxisItem()->isLogScale(); return zAxisItem()->isLogScale();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define BORNAGAIN_GUI_MODEL_DATA_INTENSITYDATAITEM_H #define BORNAGAIN_GUI_MODEL_DATA_INTENSITYDATAITEM_H
#include "GUI/Model/Data/DataItem.h" #include "GUI/Model/Data/DataItem.h"
#include "GUI/Model/Group/SelectionDescriptor.h"
class BasicAxisItem; class BasicAxisItem;
class AmplitudeAxisItem; class AmplitudeAxisItem;
...@@ -69,6 +70,7 @@ public: ...@@ -69,6 +70,7 @@ public:
QString getGradientValue() const; QString getGradientValue() const;
ComboProperty getGradient() const; ComboProperty getGradient() const;
void setGradient(const ComboProperty& gradient); void setGradient(const ComboProperty& gradient);
SelectionDescriptor<QString> gradient() const;
bool isLogz() const; bool isLogz() const;
bool isInterpolated() const; bool isInterpolated() const;
......
...@@ -41,11 +41,15 @@ public: ...@@ -41,11 +41,15 @@ public:
//! Right now with SessionModel still in place, in most cases a selection changes the current item //! 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. //! of a group item, i.e. it changes the class of a certain child item (e.g.
//! XRotationItem*/YRotationItem*/...). //! 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 //! 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 //! 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 //! no dedicated common base class exists (like for the roughness items LayerZeroRoughnessItem and
//! LayerBasicRoughnessItem). //! 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. //! 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 //! eases SessionItem migration. The underlying implementation can be a GroupItem, a simple pointer
...@@ -54,14 +58,16 @@ template <typename T> class SelectionDescriptor : public AbstractSelectionDescri ...@@ -54,14 +58,16 @@ template <typename T> class SelectionDescriptor : public AbstractSelectionDescri
public: public:
SelectionDescriptor() = default; 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 //! 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 //! 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. //! caller. Only for easier migration. Should be removed after SessionItem refactoring.
explicit SelectionDescriptor(GroupItem* item) explicit SelectionDescriptor(SessionItem* item)
{ {
label = item->displayName(); label = item->displayName();
tooltip = item->toolTip();
options = item->value().value<ComboProperty>().getValues(); options = item->value().value<ComboProperty>().getValues();
currentIndexSetter = [=](int index) { currentIndexSetter = [=](int index) {
auto comboProperty = item->value().value<ComboProperty>(); auto comboProperty = item->value().value<ComboProperty>();
...@@ -73,8 +79,11 @@ public: ...@@ -73,8 +79,11 @@ public:
}; };
currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); }; currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); };
if constexpr (std::is_pointer<T>::value) if constexpr (std::is_pointer<T>::value) {
currentItem = [=] { return dynamic_cast<T>(item->currentItem()); }; 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); } void setCurrentIndex(int newIndex) const override { currentIndexSetter(newIndex); }
......
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