From b123ce5d3412e81e545574cf6f206b2db313760a Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 21 Dec 2023 17:32:31 +0100
Subject: [PATCH] common signal from IComponentEditor

---
 .../Instrument/DepthprobeInstrumentEditor.cpp | 11 +++----
 .../Instrument/DepthprobeInstrumentEditor.h   | 10 ++-----
 GUI/View/Instrument/GISASInstrumentEditor.cpp | 13 ++++----
 GUI/View/Instrument/GISASInstrumentEditor.h   |  9 ++----
 GUI/View/Instrument/InstrumentView.cpp        |  8 ++---
 .../Instrument/OffspecInstrumentEditor.cpp    | 11 ++++---
 GUI/View/Instrument/OffspecInstrumentEditor.h | 10 ++-----
 .../Instrument/SpecularInstrumentEditor.cpp   | 13 ++++----
 .../Instrument/SpecularInstrumentEditor.h     | 10 ++-----
 GUI/View/Widget/IComponentEditor.cpp          | 17 +++++++++++
 GUI/View/Widget/IComponentEditor.h            | 30 +++++++++++++++++++
 11 files changed, 82 insertions(+), 60 deletions(-)
 create mode 100644 GUI/View/Widget/IComponentEditor.cpp
 create mode 100644 GUI/View/Widget/IComponentEditor.h

diff --git a/GUI/View/Instrument/DepthprobeInstrumentEditor.cpp b/GUI/View/Instrument/DepthprobeInstrumentEditor.cpp
index 0eaf771804f..8680fddf8c2 100644
--- a/GUI/View/Instrument/DepthprobeInstrumentEditor.cpp
+++ b/GUI/View/Instrument/DepthprobeInstrumentEditor.cpp
@@ -19,11 +19,9 @@
 #include "GUI/View/Instrument/ScanEditor.h"
 #include <QVBoxLayout>
 
-DepthprobeInstrumentEditor::DepthprobeInstrumentEditor(QWidget* parent,
-                                                       DepthprobeInstrumentItem* instrument,
+DepthprobeInstrumentEditor::DepthprobeInstrumentEditor(DepthprobeInstrumentItem* instrument,
                                                        MultiInstrumentNotifier* ec)
-    : QWidget(parent)
-    , m_ec(ec, instrument)
+    : m_ec(ec, instrument)
 {
     ASSERT(instrument);
     auto* layout = new QVBoxLayout(this);
@@ -38,7 +36,6 @@ DepthprobeInstrumentEditor::DepthprobeInstrumentEditor(QWidget* parent,
 
     layout->addStretch();
 
-    connect(scanEditor, &ScanEditor::dataChanged, this, &DepthprobeInstrumentEditor::dataChanged);
-    connect(depthAxisEditor, &AxisPropertyForm::dataChanged, this,
-            &DepthprobeInstrumentEditor::dataChanged);
+    connect(scanEditor, &ScanEditor::dataChanged, this, &IComponentEditor::dataChanged);
+    connect(depthAxisEditor, &AxisPropertyForm::dataChanged, this, &IComponentEditor::dataChanged);
 }
diff --git a/GUI/View/Instrument/DepthprobeInstrumentEditor.h b/GUI/View/Instrument/DepthprobeInstrumentEditor.h
index a4a5e8841eb..8983ca73f8d 100644
--- a/GUI/View/Instrument/DepthprobeInstrumentEditor.h
+++ b/GUI/View/Instrument/DepthprobeInstrumentEditor.h
@@ -16,21 +16,17 @@
 #define BORNAGAIN_GUI_VIEW_INSTRUMENT_DEPTHPROBEINSTRUMENTEDITOR_H
 
 #include "GUI/Model/Device/InstrumentNotifier.h"
-#include <QWidget>
+#include "GUI/View/Widget/IComponentEditor.h"
 
 class DepthprobeInstrumentItem;
 class MultiInstrumentNotifier;
 
 //! Depthprobe instrument editor, for use in main scroll area of InstrumentView.
 
-class DepthprobeInstrumentEditor : public QWidget {
+class DepthprobeInstrumentEditor : public IComponentEditor {
     Q_OBJECT
 public:
-    DepthprobeInstrumentEditor(QWidget* parent, DepthprobeInstrumentItem* instrument,
-                               MultiInstrumentNotifier* ec);
-
-signals:
-    void dataChanged();
+    DepthprobeInstrumentEditor(DepthprobeInstrumentItem* instrument, MultiInstrumentNotifier* ec);
 
 private:
     InstrumentNotifier m_ec;
diff --git a/GUI/View/Instrument/GISASInstrumentEditor.cpp b/GUI/View/Instrument/GISASInstrumentEditor.cpp
index 2cf3071dc04..87ab326c10d 100644
--- a/GUI/View/Instrument/GISASInstrumentEditor.cpp
+++ b/GUI/View/Instrument/GISASInstrumentEditor.cpp
@@ -20,8 +20,7 @@
 #include "GUI/View/Instrument/GISASBeamEditor.h"
 #include "GUI/View/Instrument/PolarizationAnalysisEditor.h"
 
-GISASInstrumentEditor::GISASInstrumentEditor(QWidget* parent, GISASInstrumentItem* instrument)
-    : QWidget(parent)
+GISASInstrumentEditor::GISASInstrumentEditor(GISASInstrumentItem* instrument)
 {
     ASSERT(instrument);
     auto* layout = new QVBoxLayout(this);
@@ -41,11 +40,9 @@ GISASInstrumentEditor::GISASInstrumentEditor(QWidget* parent, GISASInstrumentIte
 
     layout->addStretch();
 
-    connect(beamEditor, &GISASBeamEditor::dataChanged, this, &GISASInstrumentEditor::dataChanged);
-    connect(detectorEditor, &DetectorEditor::dataChanged, this,
-            &GISASInstrumentEditor::dataChanged);
+    connect(beamEditor, &GISASBeamEditor::dataChanged, this, &IComponentEditor::dataChanged);
+    connect(detectorEditor, &DetectorEditor::dataChanged, this, &IComponentEditor::dataChanged);
     connect(polMatricesAnalysisEditor, &PolarizationAnalysisEditor::dataChanged, this,
-            &GISASInstrumentEditor::dataChanged);
-    connect(backgroundForm, &BackgroundForm::dataChanged, this,
-            &GISASInstrumentEditor::dataChanged);
+            &IComponentEditor::dataChanged);
+    connect(backgroundForm, &BackgroundForm::dataChanged, this, &IComponentEditor::dataChanged);
 }
diff --git a/GUI/View/Instrument/GISASInstrumentEditor.h b/GUI/View/Instrument/GISASInstrumentEditor.h
index 2ed73068a62..e9797f949ed 100644
--- a/GUI/View/Instrument/GISASInstrumentEditor.h
+++ b/GUI/View/Instrument/GISASInstrumentEditor.h
@@ -15,19 +15,16 @@
 #ifndef BORNAGAIN_GUI_VIEW_INSTRUMENT_GISASINSTRUMENTEDITOR_H
 #define BORNAGAIN_GUI_VIEW_INSTRUMENT_GISASINSTRUMENTEDITOR_H
 
-#include <QWidget>
+#include "GUI/View/Widget/IComponentEditor.h"
 
 class GISASInstrumentItem;
 
 //! Editor for GISAS instruments, for use in main scroll area of InstrumentView.
 
-class GISASInstrumentEditor : public QWidget {
+class GISASInstrumentEditor : public IComponentEditor {
     Q_OBJECT
 public:
-    GISASInstrumentEditor(QWidget* parent, GISASInstrumentItem* instrument);
-
-signals:
-    void dataChanged();
+    GISASInstrumentEditor(GISASInstrumentItem* instrument);
 };
 
 #endif // BORNAGAIN_GUI_VIEW_INSTRUMENT_GISASINSTRUMENTEDITOR_H
diff --git a/GUI/View/Instrument/InstrumentView.cpp b/GUI/View/Instrument/InstrumentView.cpp
index b1de60967de..f205ff9d426 100644
--- a/GUI/View/Instrument/InstrumentView.cpp
+++ b/GUI/View/Instrument/InstrumentView.cpp
@@ -128,25 +128,25 @@ void InstrumentView::createWidgetsForCurrentInstrument()
 
     auto* ec = gDoc->multiNotifier();
     if (auto* ii = dynamic_cast<SpecularInstrumentItem*>(currentInstrument)) {
-        auto* editor = new SpecularInstrumentEditor(m_scrollArea, ii, ec);
+        auto* editor = new SpecularInstrumentEditor(ii, ec);
         connect(editor, &SpecularInstrumentEditor::dataChanged, this,
                 &InstrumentView::onInstrumentChangedByEditor);
         layout->addWidget(editor);
 
     } else if (auto* ii = dynamic_cast<OffspecInstrumentItem*>(currentInstrument)) {
-        auto* editor = new OffspecInstrumentEditor(m_scrollArea, ii, ec);
+        auto* editor = new OffspecInstrumentEditor(ii, ec);
         connect(editor, &OffspecInstrumentEditor::dataChanged, this,
                 &InstrumentView::onInstrumentChangedByEditor);
         layout->addWidget(editor);
 
     } else if (auto* ii = dynamic_cast<GISASInstrumentItem*>(currentInstrument)) {
-        auto* editor = new GISASInstrumentEditor(m_scrollArea, ii);
+        auto* editor = new GISASInstrumentEditor(ii);
         connect(editor, &GISASInstrumentEditor::dataChanged, this,
                 &InstrumentView::onInstrumentChangedByEditor);
         layout->addWidget(editor);
 
     } else if (auto* ii = dynamic_cast<DepthprobeInstrumentItem*>(currentInstrument)) {
-        auto* editor = new DepthprobeInstrumentEditor(m_scrollArea, ii, ec);
+        auto* editor = new DepthprobeInstrumentEditor(ii, ec);
         connect(editor, &DepthprobeInstrumentEditor::dataChanged, this,
                 &InstrumentView::onInstrumentChangedByEditor);
         layout->addWidget(editor);
diff --git a/GUI/View/Instrument/OffspecInstrumentEditor.cpp b/GUI/View/Instrument/OffspecInstrumentEditor.cpp
index 77ad00d0558..9af894134b5 100644
--- a/GUI/View/Instrument/OffspecInstrumentEditor.cpp
+++ b/GUI/View/Instrument/OffspecInstrumentEditor.cpp
@@ -19,11 +19,10 @@
 #include "GUI/View/Instrument/PolarizationAnalysisEditor.h"
 #include "GUI/View/Instrument/ScanEditor.h"
 
-OffspecInstrumentEditor::OffspecInstrumentEditor(QWidget* parent, OffspecInstrumentItem* instrument,
+OffspecInstrumentEditor::OffspecInstrumentEditor(OffspecInstrumentItem* instrument,
                                                  MultiInstrumentNotifier* ec)
 
-    : QWidget(parent)
-    , m_ec(ec, instrument)
+    : m_ec(ec, instrument)
 {
     ASSERT(instrument);
     auto* layout = new QVBoxLayout(this);
@@ -40,9 +39,9 @@ OffspecInstrumentEditor::OffspecInstrumentEditor(QWidget* parent, OffspecInstrum
 
     layout->addStretch();
 
-    connect(scanEditor, &ScanEditor::dataChanged, this, &OffspecInstrumentEditor::dataChanged);
+    connect(scanEditor, &ScanEditor::dataChanged, this, &IComponentEditor::dataChanged);
     connect(detectorEditor, &OffspecDetectorEditor::dataChanged, this,
-            &OffspecInstrumentEditor::dataChanged);
+            &IComponentEditor::dataChanged);
     connect(polMatricesAnalysisEditor, &PolarizationAnalysisEditor::dataChanged, this,
-            &OffspecInstrumentEditor::dataChanged);
+            &IComponentEditor::dataChanged);
 }
diff --git a/GUI/View/Instrument/OffspecInstrumentEditor.h b/GUI/View/Instrument/OffspecInstrumentEditor.h
index 14bf3203429..3c25123f051 100644
--- a/GUI/View/Instrument/OffspecInstrumentEditor.h
+++ b/GUI/View/Instrument/OffspecInstrumentEditor.h
@@ -16,21 +16,17 @@
 #define BORNAGAIN_GUI_VIEW_INSTRUMENT_OFFSPECINSTRUMENTEDITOR_H
 
 #include "GUI/Model/Device/InstrumentNotifier.h"
-#include <QWidget>
+#include "GUI/View/Widget/IComponentEditor.h"
 
 class MultiInstrumentNotifier;
 class OffspecInstrumentItem;
 
 //! Offspec instrument editor, for use in main scroll area of InstrumentView.
 
-class OffspecInstrumentEditor : public QWidget {
+class OffspecInstrumentEditor : public IComponentEditor {
     Q_OBJECT
 public:
-    OffspecInstrumentEditor(QWidget* parent, OffspecInstrumentItem* instrument,
-                            MultiInstrumentNotifier* ec);
-
-signals:
-    void dataChanged();
+    OffspecInstrumentEditor(OffspecInstrumentItem* instrument, MultiInstrumentNotifier* ec);
 
 private:
     InstrumentNotifier m_ec;
diff --git a/GUI/View/Instrument/SpecularInstrumentEditor.cpp b/GUI/View/Instrument/SpecularInstrumentEditor.cpp
index 23d26f89f9b..1ad958d3c87 100644
--- a/GUI/View/Instrument/SpecularInstrumentEditor.cpp
+++ b/GUI/View/Instrument/SpecularInstrumentEditor.cpp
@@ -19,11 +19,9 @@
 #include "GUI/View/Instrument/PolarizationAnalysisEditor.h"
 #include "GUI/View/Instrument/ScanEditor.h"
 
-SpecularInstrumentEditor::SpecularInstrumentEditor(QWidget* parent,
-                                                   SpecularInstrumentItem* instrument,
+SpecularInstrumentEditor::SpecularInstrumentEditor(SpecularInstrumentItem* instrument,
                                                    MultiInstrumentNotifier* ec)
-    : QWidget(parent)
-    , m_ec(ec, instrument)
+    : m_ec(ec, instrument)
 {
     ASSERT(instrument);
     auto* layout = new QVBoxLayout(this);
@@ -40,9 +38,8 @@ SpecularInstrumentEditor::SpecularInstrumentEditor(QWidget* parent,
 
     layout->addStretch();
 
-    connect(scanEditor, &ScanEditor::dataChanged, this, &SpecularInstrumentEditor::dataChanged);
+    connect(scanEditor, &ScanEditor::dataChanged, this, &IComponentEditor::dataChanged);
     connect(polMatricesAnalysisEditor, &PolarizationAnalysisEditor::dataChanged, this,
-            &SpecularInstrumentEditor::dataChanged);
-    connect(backgroundForm, &BackgroundForm::dataChanged, this,
-            &SpecularInstrumentEditor::dataChanged);
+            &IComponentEditor::dataChanged);
+    connect(backgroundForm, &BackgroundForm::dataChanged, this, &IComponentEditor::dataChanged);
 }
diff --git a/GUI/View/Instrument/SpecularInstrumentEditor.h b/GUI/View/Instrument/SpecularInstrumentEditor.h
index 06273e9c07b..a34dc07b4aa 100644
--- a/GUI/View/Instrument/SpecularInstrumentEditor.h
+++ b/GUI/View/Instrument/SpecularInstrumentEditor.h
@@ -16,21 +16,17 @@
 #define BORNAGAIN_GUI_VIEW_INSTRUMENT_SPECULARINSTRUMENTEDITOR_H
 
 #include "GUI/Model/Device/InstrumentNotifier.h"
-#include <QWidget>
+#include "GUI/View/Widget/IComponentEditor.h"
 
 class MultiInstrumentNotifier;
 class SpecularInstrumentItem;
 
 //! Specular instrument editor, for use in main scroll area of InstrumentView.
 
-class SpecularInstrumentEditor : public QWidget {
+class SpecularInstrumentEditor : public IComponentEditor {
     Q_OBJECT
 public:
-    SpecularInstrumentEditor(QWidget* parent, SpecularInstrumentItem* instrument,
-                             MultiInstrumentNotifier* ec);
-
-signals:
-    void dataChanged();
+    SpecularInstrumentEditor(SpecularInstrumentItem* instrument, MultiInstrumentNotifier* ec);
 
 private:
     InstrumentNotifier m_ec;
diff --git a/GUI/View/Widget/IComponentEditor.cpp b/GUI/View/Widget/IComponentEditor.cpp
new file mode 100644
index 00000000000..788f82697a1
--- /dev/null
+++ b/GUI/View/Widget/IComponentEditor.cpp
@@ -0,0 +1,17 @@
+//  ************************************************************************************************
+//
+//  BornAgain: simulate and fit reflection and scattering
+//
+//! @file      GUI/View/Widget/IComponentEditor.cpp
+//! @brief     Implements class IComponentEditor.
+//!
+//! @homepage  http://www.bornagainproject.org
+//! @license   GNU General Public License v3 or higher (see COPYING)
+//! @copyright Forschungszentrum Jülich GmbH 2018
+//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
+//
+//  ************************************************************************************************
+
+#include "GUI/View/Widget/IComponentEditor.h"
+
+IComponentEditor::IComponentEditor() = default;
diff --git a/GUI/View/Widget/IComponentEditor.h b/GUI/View/Widget/IComponentEditor.h
new file mode 100644
index 00000000000..8f05c9d763d
--- /dev/null
+++ b/GUI/View/Widget/IComponentEditor.h
@@ -0,0 +1,30 @@
+//  ************************************************************************************************
+//
+//  BornAgain: simulate and fit reflection and scattering
+//
+//! @file      GUI/View/Widget/IComponentEditor.h
+//! @brief     Defines class IComponentEditor.
+//!
+//! @homepage  http://www.bornagainproject.org
+//! @license   GNU General Public License v3 or higher (see COPYING)
+//! @copyright Forschungszentrum Jülich GmbH 2018
+//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
+//
+//  ************************************************************************************************
+
+#ifndef BORNAGAIN_GUI_VIEW_WIDGET_ICOMPONENTEDITOR_H
+#define BORNAGAIN_GUI_VIEW_WIDGET_ICOMPONENTEDITOR_H
+
+#include <QWidget>
+
+//! Base class for model component editors
+
+class IComponentEditor : public QWidget {
+    Q_OBJECT
+public:
+    IComponentEditor();
+signals:
+    void dataChanged();
+};
+
+#endif // BORNAGAIN_GUI_VIEW_WIDGET_ICOMPONENTEDITOR_H
-- 
GitLab