From 0480d60c3b599db2df96394c50c2dfa9cb6cd22f Mon Sep 17 00:00:00 2001
From: Matthias Puchner <github@mpuchner.de>
Date: Thu, 16 Dec 2021 09:38:40 +0100
Subject: [PATCH] enhance VectorDescriptor to support R3 and a uid

---
 GUI/Model/Types/VectorDescriptor.h | 31 ++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/GUI/Model/Types/VectorDescriptor.h b/GUI/Model/Types/VectorDescriptor.h
index 7ba93f750f1..921a2ab4b1c 100644
--- a/GUI/Model/Types/VectorDescriptor.h
+++ b/GUI/Model/Types/VectorDescriptor.h
@@ -74,11 +74,42 @@ public:
         z.label = label + " (z)";
     }
 
+    VectorDescriptor(const QString& label, const QString& tooltip, const R3* vec,
+                     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;
+        x.label = label + " (x)";
+        y.label = label + " (y)";
+        z.label = label + " (z)";
+        x.set = [=](double v) { const_cast<R3*>(vec)->setX(v); };
+        x.get = [=]() { return vec->x(); };
+        x.path = [=] { return uid() + "x"; };
+        y.set = [=](double v) { const_cast<R3*>(vec)->setY(v); };
+        y.get = [=]() { return vec->y(); };
+        y.path = [=] { return uid() + "y"; };
+        z.set = [=](double v) { const_cast<R3*>(vec)->setZ(v); };
+        z.get = [=]() { return vec->z(); };
+        z.path = [=] { return uid() + "z"; };
+    }
+
     QString label;   //!< A label text (short, no trailing colon)
     QString tooltip; //!< Tooltip text
     DoubleDescriptor x;
     DoubleDescriptor y;
     DoubleDescriptor z;
+    function<QString()> uid; //<! unique id describing  this value. Used e.g. for undo/redo
 };
 
 #endif // BORNAGAIN_GUI_MODEL_TYPES_VECTORDESCRIPTOR_H
-- 
GitLab