From 3909cac4e9e8fbc812c694ff45b7f071e362502f Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <svechnikovmv@gmail.com>
Date: Thu, 1 Aug 2024 18:14:58 +0200
Subject: [PATCH] save collapsed state

---
 GUI/Model/Sample/LayerItem.cpp    | 4 ++++
 GUI/Model/Sample/LayerItem.h      | 1 +
 GUI/View/Sample/LayerForm.cpp     | 3 ++-
 GUI/View/Sample/RoughnessForm.cpp | 2 +-
 GUI/View/Sample/RoughnessForm.h   | 4 +---
 5 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/GUI/Model/Sample/LayerItem.cpp b/GUI/Model/Sample/LayerItem.cpp
index 540a95e53dc..5867651ae50 100644
--- a/GUI/Model/Sample/LayerItem.cpp
+++ b/GUI/Model/Sample/LayerItem.cpp
@@ -34,6 +34,7 @@ const QString Thickness("Thickness");
 const QString Roughness("Roughness");
 const QString Layout("Layout");
 const QString ExpandLayerGroupbox("ExpandLayerGroupbox");
+const QString ExpandRoughnessGroupbox("ExpandRoughnessGroupbox");
 
 } // namespace Tag
 
@@ -118,6 +119,7 @@ void LayerItem::writeTo(QXmlStreamWriter* w) const
     for (const auto* layout : m_layouts)
         XML::writeTaggedElement(w, Tag::Layout, *layout);
     XML::writeTaggedValue(w, Tag::ExpandLayerGroupbox, expandLayer);
+    XML::writeTaggedValue(w, Tag::ExpandRoughnessGroupbox, expandRoughness);
 }
 
 void LayerItem::readFrom(QXmlStreamReader* r)
@@ -139,6 +141,8 @@ void LayerItem::readFrom(QXmlStreamReader* r)
             XML::readTaggedElement(r, tag, *addLayoutItem());
         else if (tag == Tag::ExpandLayerGroupbox)
             expandLayer = XML::readTaggedBool(r, tag);
+        else if (tag == Tag::ExpandRoughnessGroupbox)
+            expandRoughness = XML::readTaggedBool(r, tag);
         else
             r->skipCurrentElement();
     }
diff --git a/GUI/Model/Sample/LayerItem.h b/GUI/Model/Sample/LayerItem.h
index 28649fcb817..40a93d21719 100644
--- a/GUI/Model/Sample/LayerItem.h
+++ b/GUI/Model/Sample/LayerItem.h
@@ -61,6 +61,7 @@ public:
     void readFrom(QXmlStreamReader* r);
 
     bool expandLayer = false;
+    bool expandRoughness = true;
 
 private:
     uint m_num_slices = 1;
diff --git a/GUI/View/Sample/LayerForm.cpp b/GUI/View/Sample/LayerForm.cpp
index 23961505355..47463750fe4 100644
--- a/GUI/View/Sample/LayerForm.cpp
+++ b/GUI/View/Sample/LayerForm.cpp
@@ -113,7 +113,8 @@ LayerForm::LayerForm(QWidget* parent, LayerItem* layerItem, SampleEditorControll
                                                   "when corresponding simulation option is set."));
 
     //    m_layout->addSelection(m_layer->roughnessSelection());
-    m_layout->addRow(new RoughnessForm(this, m_layer->roughnessSelection(), m_ec));
+    m_layout->addRow(
+        new RoughnessForm(this, m_layer->roughnessSelection(), m_layer->expandRoughness, m_ec));
     m_roughness_row = m_layout->rowCount() - 1;
 
     // -- layouts
diff --git a/GUI/View/Sample/RoughnessForm.cpp b/GUI/View/Sample/RoughnessForm.cpp
index 467153dbba2..b1fef4297db 100644
--- a/GUI/View/Sample/RoughnessForm.cpp
+++ b/GUI/View/Sample/RoughnessForm.cpp
@@ -19,7 +19,7 @@
 
 RoughnessForm::RoughnessForm(QWidget* parent,
                              PolyPtr<RoughnessItem, RoughnessCatalog>& roughnessSelection,
-                             SampleEditorController* ec)
+                             bool& expandRoughness, SampleEditorController* ec)
     : CollapsibleGroupBox(parent, expandRoughness)
     , m_cb(new QComboBox(this))
     , m_rs(roughnessSelection)
diff --git a/GUI/View/Sample/RoughnessForm.h b/GUI/View/Sample/RoughnessForm.h
index 660cb2dcf1d..e15fd930961 100644
--- a/GUI/View/Sample/RoughnessForm.h
+++ b/GUI/View/Sample/RoughnessForm.h
@@ -27,7 +27,7 @@ class SampleEditorController;
 class RoughnessForm : public CollapsibleGroupBox {
 public:
     RoughnessForm(QWidget* parent, PolyPtr<RoughnessItem, RoughnessCatalog>& roughnessSelection,
-                  SampleEditorController* ec);
+                  bool& expandRoughness, SampleEditorController* ec);
 
     void onRoughnessTypeChanged();
 
@@ -38,8 +38,6 @@ private:
     HeinzFormLayout* m_layout;
     QComboBox* m_cb;
     PolyPtr<RoughnessItem, RoughnessCatalog>& m_rs;
-
-    bool expandRoughness = true;
 };
 
 #endif // BORNAGAIN_GUI_VIEW_SAMPLE_ROUGHNESSFORM_H
-- 
GitLab