Skip to content
Snippets Groups Projects
Commit e1ac7a24 authored by t.knopff's avatar t.knopff
Browse files

New DetectorEditor for selecting and editing the detector

parent 99369efb
No related branches found
No related tags found
1 merge request!279Overhaul UI: instrument view (cont.)
// ************************************************************************************************
//
// 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);
}
}
// ************************************************************************************************
//
// 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
......@@ -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))
{
......
......@@ -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;
};
......
......@@ -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))
......
......@@ -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;
};
......
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