diff --git a/GUI/Views/InstrumentWidgets/DetectorEditor.cpp b/GUI/Views/InstrumentWidgets/DetectorEditor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49a044867d0c4a1e2ba0f16b045248fe06bcc2f5 --- /dev/null +++ b/GUI/Views/InstrumentWidgets/DetectorEditor.cpp @@ -0,0 +1,92 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file GUI/Views/InstrumentWidgets/DetectorEditor.cpp +//! @brief Implements class DetectorEditor +//! +//! @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/Views/InstrumentWidgets/DetectorEditor.h" +#include "GUI/Models/InstrumentItems.h" +#include "GUI/Models/RectangularDetectorItem.h" +#include "GUI/Models/SphericalDetectorItem.h" +#include "GUI/Views/InstrumentWidgets/RectangularDetectorEditor.h" +#include "GUI/Views/InstrumentWidgets/SphericalDetectorEditor.h" + +#include <QComboBox> +#include <QFormLayout> +#include <QStackedLayout> + + +//================================================================================================== +// DetectorEditor +//================================================================================================== + +//-------------------------------------------------------------------------------------------------- +// public member functions +//-------------------------------------------------------------------------------------------------- + +DetectorEditor::DetectorEditor(QWidget* parent, Qt::WindowFlags f) + : QWidget(parent, f) +{ + QFormLayout* layout = new QFormLayout(this); + + m_combo = new QComboBox(this); + m_combo->addItem("Rectangular", RectangularDetectorItem::M_TYPE); + m_combo->addItem("Spherical", SphericalDetectorItem::M_TYPE); + layout->addRow( "Detector:", m_combo); + connect(m_combo, qOverload<int>(&QComboBox::currentIndexChanged), + this, &DetectorEditor::onDetectorSelected); + + m_stack = new QStackedLayout(); + layout->addRow(m_stack); + + m_editor_rectangular = new RectangularDetectorEditor(this); + m_stack->addWidget(m_editor_rectangular); + + m_editor_spherical = new SphericalDetectorEditor(this); + m_stack->addWidget(m_editor_spherical); +} + +void DetectorEditor::setItem(Instrument2DItem* item) +{ + m_item = item; + setEnabled(m_item); + if (m_item) { + int idx = m_combo->findData(m_item->detector()->modelType()); + ASSERT(idx != -1); + if (idx != m_combo->currentIndex()) + m_combo->setCurrentIndex(idx); + else + onDetectorSelected(idx); // trigger update manually + } +} + +void DetectorEditor::clearItem() +{ + setItem(nullptr); +} + +//-------------------------------------------------------------------------------------------------- +// private slots +//-------------------------------------------------------------------------------------------------- + +void DetectorEditor::onDetectorSelected(int) +{ + + const QString model_type = m_combo->currentData().toString(); + DetectorItem* detector = m_item->setDetectorType(model_type); + if (model_type == RectangularDetectorItem::M_TYPE) { + m_editor_rectangular->setItem(detector); + m_stack->setCurrentWidget(m_editor_rectangular); + } else { + m_editor_spherical->setItem(detector); + m_stack->setCurrentWidget(m_editor_spherical); + } +} diff --git a/GUI/Views/InstrumentWidgets/DetectorEditor.h b/GUI/Views/InstrumentWidgets/DetectorEditor.h new file mode 100644 index 0000000000000000000000000000000000000000..2b09f36dd6638fc97379c5724508e201918f636d --- /dev/null +++ b/GUI/Views/InstrumentWidgets/DetectorEditor.h @@ -0,0 +1,49 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file GUI/Views/InstrumentWidgets/DetectorEditor.h +//! @brief Defines class DetectorEditor +//! +//! @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_VIEWS_INSTRUMENTWIDGETS_DETECTOREDITOR_H +#define BORNAGAIN_GUI_VIEWS_INSTRUMENTWIDGETS_DETECTOREDITOR_H + +#include <QWidget> + +class QComboBox; +class QStackedLayout; +class Instrument2DItem; +class RectangularDetectorEditor; +class SphericalDetectorEditor; + + +//! Contains stack of detector editors and the logic to show proper editor for certain type +//! of detector item (SphericalDetectorEditor or RectangularDetectorEditor). + +class DetectorEditor : public QWidget { + Q_OBJECT + +public: + DetectorEditor(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + void setItem(Instrument2DItem* item); + void clearItem(); + +private slots: + void onDetectorSelected(int index); + +private: + QComboBox* m_combo; + QStackedLayout* m_stack; + RectangularDetectorEditor* m_editor_rectangular; + SphericalDetectorEditor* m_editor_spherical; + Instrument2DItem* m_item; +}; + +#endif // BORNAGAIN_GUI_VIEWS_INSTRUMENTWIDGETS_DETECTOREDITOR_H diff --git a/GUI/Views/InstrumentWidgets/GISASInstrumentEditor.cpp b/GUI/Views/InstrumentWidgets/GISASInstrumentEditor.cpp index 0cdec0865f1933bbf9a3d86f474d9270ae725ada..0d57cec2b3477b1201c3753aea6769b66095c3de 100644 --- a/GUI/Views/InstrumentWidgets/GISASInstrumentEditor.cpp +++ b/GUI/Views/InstrumentWidgets/GISASInstrumentEditor.cpp @@ -16,9 +16,9 @@ #include "GUI/Models/InstrumentItems.h" #include "GUI/Views/CommonWidgets/ColumnResizer.h" #include "GUI/Views/CommonWidgets/StyleUtils.h" +#include "GUI/Views/InstrumentWidgets/DetectorEditor.h" #include "GUI/Views/InstrumentWidgets/EnvironmentEditor.h" #include "GUI/Views/InstrumentWidgets/GISASBeamEditor.h" -#include "GUI/Views/InstrumentWidgets/GISASDetectorEditor.h" #include "GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.h" #include <QVBoxLayout> @@ -26,7 +26,7 @@ GISASInstrumentEditor::GISASInstrumentEditor(QWidget* parent) : SessionItemWidget(parent) , m_columnResizer(new ColumnResizer(this)) , m_beamEditor(new GISASBeamEditor(m_columnResizer)) - , m_detectorEditor(new GISASDetectorEditor) + , m_detectorEditor(new DetectorEditor(this)) , m_environmentEditor(new EnvironmentEditor(this)) , m_polpairAnalysisEditor(new PolarizationAnalysisEditor(m_columnResizer)) { diff --git a/GUI/Views/InstrumentWidgets/GISASInstrumentEditor.h b/GUI/Views/InstrumentWidgets/GISASInstrumentEditor.h index 22a55902fd8a68aa6bfdfd9a693f29e873ea1606..9421f21785297a8b6466a25771aa4546c919f5cc 100644 --- a/GUI/Views/InstrumentWidgets/GISASInstrumentEditor.h +++ b/GUI/Views/InstrumentWidgets/GISASInstrumentEditor.h @@ -19,7 +19,7 @@ class GISASInstrumentItem; class GISASBeamEditor; -class GISASDetectorEditor; +class DetectorEditor; class EnvironmentEditor; class PolarizationAnalysisEditor; class ColumnResizer; @@ -37,7 +37,7 @@ private: GISASInstrumentItem* instrumentItem(); ColumnResizer* m_columnResizer; GISASBeamEditor* m_beamEditor; - GISASDetectorEditor* m_detectorEditor; + DetectorEditor* m_detectorEditor; EnvironmentEditor* m_environmentEditor; PolarizationAnalysisEditor* m_polpairAnalysisEditor; }; diff --git a/GUI/Views/InstrumentWidgets/OffSpecularInstrumentEditor.cpp b/GUI/Views/InstrumentWidgets/OffSpecularInstrumentEditor.cpp index 88a2976599ad89db9a7f87ac6c2889e8e6b94000..3861a52bb6e2ce8fd7b0d8d685fb38914ad370f3 100644 --- a/GUI/Views/InstrumentWidgets/OffSpecularInstrumentEditor.cpp +++ b/GUI/Views/InstrumentWidgets/OffSpecularInstrumentEditor.cpp @@ -16,7 +16,7 @@ #include "GUI/Models/InstrumentItems.h" #include "GUI/Views/CommonWidgets/ColumnResizer.h" #include "GUI/Views/CommonWidgets/StyleUtils.h" -#include "GUI/Views/InstrumentWidgets/GISASDetectorEditor.h" +#include "GUI/Views/InstrumentWidgets/DetectorEditor.h" #include "GUI/Views/InstrumentWidgets/OffSpecularBeamEditor.h" #include <QVBoxLayout> @@ -24,7 +24,7 @@ OffSpecularInstrumentEditor::OffSpecularInstrumentEditor(QWidget* parent) : SessionItemWidget(parent) , m_columnResizer(new ColumnResizer(this)) , m_beamEditor(new OffSpecularBeamEditor(m_columnResizer)) - , m_detectorEditor(new GISASDetectorEditor) + , m_detectorEditor(new DetectorEditor(this)) // temporary switched off to avoid memory leakage //, m_environmentEditor(new EnvironmentEditor(m_columnResizer)) //, m_polpairAnalysisEditor(new PolarizationAnalysisEditor(m_columnResizer)) diff --git a/GUI/Views/InstrumentWidgets/OffSpecularInstrumentEditor.h b/GUI/Views/InstrumentWidgets/OffSpecularInstrumentEditor.h index 91f0280eed83a78f4cb03a578f62eb0adcd1ce61..aae7ee0f415c43774980bd1676169ca3748867da 100644 --- a/GUI/Views/InstrumentWidgets/OffSpecularInstrumentEditor.h +++ b/GUI/Views/InstrumentWidgets/OffSpecularInstrumentEditor.h @@ -19,7 +19,7 @@ class OffSpecularInstrumentItem; class OffSpecularBeamEditor; -class GISASDetectorEditor; +class DetectorEditor; class EnvironmentEditor; class PolarizationAnalysisEditor; class ColumnResizer; @@ -37,7 +37,7 @@ private: OffSpecularInstrumentItem* instrumentItem(); ColumnResizer* m_columnResizer; OffSpecularBeamEditor* m_beamEditor; - GISASDetectorEditor* m_detectorEditor; + DetectorEditor* m_detectorEditor; EnvironmentEditor* m_environmentEditor; PolarizationAnalysisEditor* m_polpairAnalysisEditor; };