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

more ctors for descriptors

parent f4538e12
No related branches found
No related tags found
1 merge request!494Remove SessionModel/SessionItem from MaterialModel/MaterialItem
......@@ -70,6 +70,14 @@ DoubleDescriptor::DoubleDescriptor(const QString& label, const QString& tooltip,
{
}
DoubleDescriptor::DoubleDescriptor(const QString& label, double* var,
const variant<QString, Unit>& unit)
: label(label), decimals(3), limits(RealLimits::nonnegative()), unit(unit)
{
set = [=](double v) { *var = v; };
get = [=]() { return *var; };
}
DoubleDescriptor::operator double() const
{
return get();
......
......@@ -35,6 +35,8 @@ using std::variant;
class DoubleDescriptor {
public:
DoubleDescriptor(const DoubleDescriptor& other) = default;
//! Operates on a session item. The settings (like decimals, limits) are taken from the session
//! item.
//! Only for easier migration. Should be removed after SessionItem refactoring.
......@@ -45,6 +47,15 @@ public:
//! Only for easier migration. Should be removed after SessionItem refactoring.
DoubleDescriptor(const QString& label, SessionItem* item, const variant<QString, Unit>& unit);
DoubleDescriptor(const QString& label, double* var, const variant<QString, Unit>& unit);
//! Operates on any kind of storage (e.g. session items), by using setter/getter methods
DoubleDescriptor(QString label, QString tooltip, int decimals, const RealLimits& limits,
function<void(double)> setter, function<double()> getter,
const variant<QString, Unit>& unit);
DoubleDescriptor() = default;
private: // private as long as path initialization is not included in params (to be done after
// SessionItem migration)
//! Operates on a double value (e.g a member variable).
......@@ -56,11 +67,6 @@ private: // private as long as path initialization is not included in params (to
DoubleDescriptor(const QString& label, const QString& tooltip, double* var,
const variant<QString, Unit>& unit);
//! Operates on any kind of storage (e.g. session items), by using setter/getter methods
DoubleDescriptor(QString label, QString tooltip, int decimals, const RealLimits& limits,
function<void(double)> setter, function<double()> getter,
const variant<QString, Unit>& unit);
//! Operates on any kind of storage (e.g. session items), by using setter/getter methods
//! decimals is set to 3, limits is set to nonnegative
DoubleDescriptor(const QString& label, const QString& tooltip, function<void(double)> setter,
......
......@@ -38,6 +38,39 @@ public:
{
}
VectorDescriptor(const QString& label, const QString& tooltip, double* xVar, double* yVar,
double* zVar, const variant<QString, Unit>& unit)
: label(label), tooltip(tooltip), x("X", xVar, unit), y("Y", yVar, unit), z("Z", zVar, unit)
{
x.limits = RealLimits::limitless();
y.limits = RealLimits::limitless();
z.limits = RealLimits::limitless();
x.decimals = 3;
y.decimals = 3;
z.decimals = 3;
x.tooltip = tooltip;
y.tooltip = tooltip;
z.tooltip = tooltip;
}
VectorDescriptor(const QString& label, const QString& tooltip,
const variant<QString, Unit>& unit)
: label(label), tooltip(tooltip)
{
x.limits = RealLimits::limitless();
y.limits = RealLimits::limitless();
z.limits = RealLimits::limitless();
x.decimals = 3;
y.decimals = 3;
z.decimals = 3;
x.tooltip = tooltip;
y.tooltip = tooltip;
z.tooltip = tooltip;
x.unit = unit;
y.unit = unit;
z.unit = unit;
}
QString label; //!< A label text (short, no trailing colon)
QString tooltip; //!< Tooltip text
DoubleDescriptor x;
......
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