Skip to content
Snippets Groups Projects
Commit 5daf4adc authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

integrate ResolutionForm in DetectorEditor, and make it a non collapsible group box

parent 1daacf98
No related branches found
No related tags found
1 merge request!2058GUI instrument editor: detector section made more compact
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Device/ResolutionForm.cpp
//! @brief Implements class ResolutionForm
//!
//! @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/Device/ResolutionForm.h"
#include "GUI/Model/Detector/DetectorItem.h"
#include "GUI/Model/Detector/ResolutionFunctionItems.h"
#include "GUI/Support/Style/GroupBoxCollapser.h"
#include "GUI/View/Numeric/ComboUtil.h"
#include "GUI/View/Numeric/DoubleSpinBox.h"
#include "GUI/View/Numeric/NumWidgetUtil.h"
ResolutionForm::ResolutionForm(QWidget* parent, DetectorItem* item)
: QGroupBox("Resolution function", parent)
{
ASSERT(item);
auto formLayout = new QFormLayout(this);
formLayout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
auto updateResolutionForm = [parent = this, layout = formLayout, item]() -> void {
while (layout->rowCount() > 1)
layout->removeRow(1);
auto* resFunction = item->resolutionFunctionSelection().currentItem();
if (auto* p = dynamic_cast<ResolutionFunction2DGaussianItem*>(resFunction)) {
auto* sigmaXSpinBox = GUI::Util::createDoubleSpinBoxRow(layout, p->sigmaX());
auto* sigmaYSpinBox = GUI::Util::createDoubleSpinBoxRow(layout, p->sigmaY());
connect(sigmaXSpinBox, qOverload<double>(&DoubleSpinBox::baseValueChanged),
[parent, p](double newValue) {
p->setSigmaX(newValue);
emit parent->dataChanged();
});
connect(sigmaYSpinBox, qOverload<double>(&DoubleSpinBox::baseValueChanged),
[parent, p](double newValue) {
p->setSigmaY(newValue);
emit parent->dataChanged();
});
}
};
auto* typeCombo = GUI::Util::createComboBoxFromProperty(item->resolutionFunctionSelection(),
[this, updateResolutionForm](int) {
updateResolutionForm();
emit dataChanged();
});
formLayout->addRow("Type:", typeCombo);
auto* collapser = GroupBoxCollapser::installIntoGroupBox(this);
collapser->setExpanded(item->isExpandResolutionFunc());
connect(collapser, &GroupBoxCollapser::toggled, this,
[item](bool b) { item->setExpandResolutionFunc(b); });
updateResolutionForm();
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Device/ResolutionForm.h
//! @brief A widget for editing the alignment of a detector
//!
//! @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_DEVICE_RESOLUTIONFORM_H
#define BORNAGAIN_GUI_VIEW_DEVICE_RESOLUTIONFORM_H
#include <QGroupBox>
class DetectorItem;
class QFormLayout;
//! Widget for selecting the resolution function of a detector (combo box) and input of the
//! corresponding values
class ResolutionForm : public QGroupBox {
Q_OBJECT
public:
ResolutionForm(QWidget* parent, DetectorItem* item);
signals:
void dataChanged();
};
#endif // BORNAGAIN_GUI_VIEW_DEVICE_RESOLUTIONFORM_H
...@@ -14,10 +14,11 @@ ...@@ -14,10 +14,11 @@
#include "GUI/View/Instrument/DetectorEditor.h" #include "GUI/View/Instrument/DetectorEditor.h"
#include "GUI/Model/Detector/DetectorItem.h" #include "GUI/Model/Detector/DetectorItem.h"
#include "GUI/Model/Detector/ResolutionFunctionItems.h"
#include "GUI/Model/Device/InstrumentItems.h" #include "GUI/Model/Device/InstrumentItems.h"
#include "GUI/Support/Style/GroupBoxCollapser.h" #include "GUI/Support/Style/GroupBoxCollapser.h"
#include "GUI/View/Device/DetectorAlignmentForm.h" #include "GUI/View/Device/DetectorAlignmentForm.h"
#include "GUI/View/Device/ResolutionForm.h" #include "GUI/View/Numeric/ComboUtil.h"
#include "GUI/View/Numeric/DoubleSpinBox.h" #include "GUI/View/Numeric/DoubleSpinBox.h"
#include "GUI/View/Numeric/NumWidgetUtil.h" #include "GUI/View/Numeric/NumWidgetUtil.h"
#include "GUI/View/Numeric/SafeSpinBox.h" #include "GUI/View/Numeric/SafeSpinBox.h"
...@@ -74,7 +75,7 @@ DetectorEditor::DetectorEditor(QWidget* parent, GISASInstrumentItem* instrItem) ...@@ -74,7 +75,7 @@ DetectorEditor::DetectorEditor(QWidget* parent, GISASInstrumentItem* instrItem)
grid->setColumnStretch(1, 1); grid->setColumnStretch(1, 1);
grid->setColumnStretch(2, 1); grid->setColumnStretch(2, 1);
// -- x-axis controls //... x-axis controls
auto* xAxisFormLayout = new QFormLayout; auto* xAxisFormLayout = new QFormLayout;
auto* xAxisGroupBox = new GroupBox("X axis", xAxisFormLayout, this); auto* xAxisGroupBox = new GroupBox("X axis", xAxisFormLayout, this);
...@@ -99,7 +100,7 @@ DetectorEditor::DetectorEditor(QWidget* parent, GISASInstrumentItem* instrItem) ...@@ -99,7 +100,7 @@ DetectorEditor::DetectorEditor(QWidget* parent, GISASInstrumentItem* instrItem)
grid->addWidget(xAxisGroupBox, 1, 0); grid->addWidget(xAxisGroupBox, 1, 0);
// -- y-axis controls //... y-axis controls
auto* yAxisFormLayout = new QFormLayout; auto* yAxisFormLayout = new QFormLayout;
auto* yAxisGroupBox = new GroupBox("Y axis", yAxisFormLayout, this); auto* yAxisGroupBox = new GroupBox("Y axis", yAxisFormLayout, this);
...@@ -123,17 +124,51 @@ DetectorEditor::DetectorEditor(QWidget* parent, GISASInstrumentItem* instrItem) ...@@ -123,17 +124,51 @@ DetectorEditor::DetectorEditor(QWidget* parent, GISASInstrumentItem* instrItem)
}); });
grid->addWidget(yAxisGroupBox, 1, 1); grid->addWidget(yAxisGroupBox, 1, 1);
// -- resolution function //... detector alignment controls
auto* resolutionForm = new ResolutionForm(this, detectorItem);
grid->addWidget(resolutionForm, 1, 2);
connect(resolutionForm, &ResolutionForm::dataChanged, this, &DetectorEditor::dataChanged);
// alignment selector editors
auto* alignmentForm = new DetectorAlignmentForm(this, detectorItem); auto* alignmentForm = new DetectorAlignmentForm(this, detectorItem);
grid->addWidget(alignmentForm, 2, 0, 1, 3); grid->addWidget(alignmentForm, 2, 0, 1, 3);
connect(alignmentForm, &DetectorAlignmentForm::dataChanged, this, &DetectorEditor::dataChanged); connect(alignmentForm, &DetectorAlignmentForm::dataChanged, this, &DetectorEditor::dataChanged);
formLayout->addRow(grid); formLayout->addRow(grid);
//... resolution controls
auto resolutionLayout = new QFormLayout;
resolutionLayout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
auto* resolutionForm = new GroupBox("Resolution function", resolutionLayout, this);
auto updateResolutionForm = [parent = this, layout = resolutionLayout, item = detectorItem]() -> void {
while (layout->rowCount() > 1)
layout->removeRow(1);
auto* resFunction = item->resolutionFunctionSelection().currentItem();
if (auto* p = dynamic_cast<ResolutionFunction2DGaussianItem*>(resFunction)) {
auto* sigmaXSpinBox = GUI::Util::createDoubleSpinBoxRow(layout, p->sigmaX());
auto* sigmaYSpinBox = GUI::Util::createDoubleSpinBoxRow(layout, p->sigmaY());
connect(sigmaXSpinBox, qOverload<double>(&DoubleSpinBox::baseValueChanged),
[parent, p](double newValue) {
p->setSigmaX(newValue);
emit parent->dataChanged();
});
connect(sigmaYSpinBox, qOverload<double>(&DoubleSpinBox::baseValueChanged),
[parent, p](double newValue) {
p->setSigmaY(newValue);
emit parent->dataChanged();
});
}
};
auto* typeCombo = GUI::Util::createComboBoxFromProperty(detectorItem->resolutionFunctionSelection(),
[this, updateResolutionForm](int) {
updateResolutionForm();
emit dataChanged();
});
resolutionLayout->addRow("Type:", typeCombo);
updateResolutionForm();
grid->addWidget(resolutionForm, 1, 2);
} }
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