From c1184fc0845ed9fa4f969906b7e53dac9634dd23 Mon Sep 17 00:00:00 2001 From: Tobias Knopff <t.knopff@fz-juelich.de> Date: Wed, 29 Sep 2021 09:45:13 +0200 Subject: [PATCH 1/2] Add checkbox to polarizer and analyzer form for (de)activating the polarizer and analyzer of an instrument --- GUI/Models/InstrumentItems.cpp | 11 +++++ GUI/Models/InstrumentItems.h | 4 ++ .../PolarizationAnalysisEditor.cpp | 41 +++++++++++++++++-- .../PolarizationAnalysisEditor.h | 6 +++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/GUI/Models/InstrumentItems.cpp b/GUI/Models/InstrumentItems.cpp index 053820686c8..82fad6f0aaf 100644 --- a/GUI/Models/InstrumentItems.cpp +++ b/GUI/Models/InstrumentItems.cpp @@ -131,6 +131,16 @@ bool InstrumentItem::alignedWith(const RealDataItem* item) const return shape() == item->shape(); } +bool InstrumentItem::withPolarizerAnalyzer() const +{ + return getItemValue(P_WITH_POLARIZER_ANALYZER).toBool(); +} + +void InstrumentItem::setWithPolarizerAnalyzer(bool with) +{ + setItemValue(P_WITH_POLARIZER_ANALYZER, with); +} + const R3 InstrumentItem::polarization() const { return item<VectorItem>(P_POLARIZATION)->getVector(); @@ -186,6 +196,7 @@ InstrumentItem::InstrumentItem(const QString& modelType) : SessionItem(modelType setItemName(modelType); addProperty(P_IDENTIFIER, GUI::Helpers::createUuid())->setVisible(false); addProperty(P_DESCRIPTION, QString())->setVisible(false); + addProperty(P_WITH_POLARIZER_ANALYZER, false); addProperty<VectorItem>(P_POLARIZATION); addProperty<VectorItem>(P_ANALYZER_DIRECTION); addProperty(P_ANALYZER_EFFICIENCY, 0.0)->setLimits(RealLimits::limitless()); diff --git a/GUI/Models/InstrumentItems.h b/GUI/Models/InstrumentItems.h index f8f036afc93..43fd0812097 100644 --- a/GUI/Models/InstrumentItems.h +++ b/GUI/Models/InstrumentItems.h @@ -35,6 +35,7 @@ private: static constexpr auto P_BEAM{"Beam"}; static constexpr auto P_BACKGROUND{"Background"}; static constexpr auto P_DESCRIPTION{"Description"}; + static constexpr auto P_WITH_POLARIZER_ANALYZER{"WithPolarizerAnalyzer"}; static constexpr auto P_POLARIZATION{"Polarization"}; static constexpr auto P_ANALYZER_DIRECTION{"Analyzer direction"}; static constexpr auto P_ANALYZER_EFFICIENCY{"Efficiency"}; @@ -66,6 +67,9 @@ public: virtual ICoordSystem* createCoordSystem() const = 0; + bool withPolarizerAnalyzer() const; + void setWithPolarizerAnalyzer(bool with); + const R3 polarization() const; void setPolarization(const R3& value); VectorItem* polarizationItem() const; diff --git a/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.cpp b/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.cpp index 0aa6f994f63..986b6298ac7 100644 --- a/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.cpp +++ b/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.cpp @@ -18,6 +18,7 @@ #include "GUI/Models/VectorItem.h" #include "GUI/Views/InstrumentWidgets/VectorEditor.h" +#include <QCheckBox> #include <QDoubleSpinBox> #include <QFormLayout> #include <QGridLayout> @@ -117,22 +118,39 @@ void AnalyzerPropertiesEditor::onTransmissionValueChanged(double transmission) // PolarizationAnalysisEditor //================================================================================================== +//-------------------------------------------------------------------------------------------------- +// public member functions +//-------------------------------------------------------------------------------------------------- + PolarizationAnalysisEditor::PolarizationAnalysisEditor(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f), m_item(nullptr) { - QGridLayout* grid = new QGridLayout(this); + QVBoxLayout* layout = new QVBoxLayout(this); + + m_checkbox = new QCheckBox("add polarizer and analyzer to instrument"); + connect(m_checkbox, &QCheckBox::toggled, this, &PolarizationAnalysisEditor::onCheckBoxToggled); + layout->addWidget(m_checkbox); + + m_polarizerAnalyzerWidget = new QWidget(this); + QGridLayout* grid = new QGridLayout(m_polarizerAnalyzerWidget); + grid->setMargin(0); m_polarizerEditor = new VectorEditor("Polarizer (Bloch vector)", - "Polarization of the beam, given as the Bloch vector (%1)", this); + "Polarization of the beam, given as the Bloch vector (%1)", + m_polarizerAnalyzerWidget); grid->addWidget(m_polarizerEditor, 0, 0); m_analyzerEditor = new VectorEditor("Analyzer orientation", - "Direction of the polarization analysis (%1)", this); + "Direction of the polarization analysis (%1)", + m_polarizerAnalyzerWidget); grid->addWidget(m_analyzerEditor, 0, 1); - m_propertiesEditor = new AnalyzerPropertiesEditor(this); + m_propertiesEditor = new AnalyzerPropertiesEditor(m_polarizerAnalyzerWidget); grid->addWidget(m_propertiesEditor, 0, 2); + layout->addWidget(m_polarizerAnalyzerWidget); + + onCheckBoxToggled(); } void PolarizationAnalysisEditor::setItem(InstrumentItem* item) @@ -140,12 +158,27 @@ void PolarizationAnalysisEditor::setItem(InstrumentItem* item) m_item = item; setEnabled(m_item); if (m_item) { + m_checkbox->setChecked(m_item->withPolarizerAnalyzer()); m_polarizerEditor->setItem(m_item->polarizationItem()); m_analyzerEditor->setItem(m_item->analyzerDirectionItem()); m_propertiesEditor->setItem(m_item); } else { + m_checkbox->setChecked(false); m_polarizerEditor->clearItem(); m_analyzerEditor->clearItem(); m_propertiesEditor->clearItem(); } } + +//-------------------------------------------------------------------------------------------------- +// private slots +//-------------------------------------------------------------------------------------------------- + +void PolarizationAnalysisEditor::onCheckBoxToggled() +{ + bool enabled = m_checkbox->isChecked(); + + m_polarizerAnalyzerWidget->setEnabled(enabled); + if (m_item) + m_item->setWithPolarizerAnalyzer(enabled); +} diff --git a/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.h b/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.h index e97cb6fd64e..4510699cc44 100644 --- a/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.h +++ b/GUI/Views/InstrumentWidgets/PolarizationAnalysisEditor.h @@ -20,6 +20,7 @@ class AnalyzerPropertiesEditor; class DetectorItem; class InstrumentItem; +class QCheckBox; class VectorEditor; class VectorItem; @@ -33,7 +34,12 @@ public: PolarizationAnalysisEditor(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); void setItem(InstrumentItem* item); +private slots: + void onCheckBoxToggled(); + private: + QCheckBox* m_checkbox; + QWidget* m_polarizerAnalyzerWidget; VectorEditor* m_polarizerEditor; VectorEditor* m_analyzerEditor; AnalyzerPropertiesEditor* m_propertiesEditor; -- GitLab From 23315cb7e644226aa81813c82b9f792ac04d09d0 Mon Sep 17 00:00:00 2001 From: Tobias Knopff <t.knopff@fz-juelich.de> Date: Wed, 29 Sep 2021 12:49:05 +0200 Subject: [PATCH 2/2] Fix bug that no instrument is selected after loading a project --- GUI/Views/InstrumentWidgets/InstrumentListView.cpp | 14 ++++++++++---- GUI/Views/InstrumentWidgets/InstrumentListView.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/GUI/Views/InstrumentWidgets/InstrumentListView.cpp b/GUI/Views/InstrumentWidgets/InstrumentListView.cpp index f4e3f2d8cee..04545dc1c6c 100644 --- a/GUI/Views/InstrumentWidgets/InstrumentListView.cpp +++ b/GUI/Views/InstrumentWidgets/InstrumentListView.cpp @@ -125,6 +125,7 @@ InstrumentListView::InstrumentListView(ProjectDocument* document, QWidget* paren updateFunctionalityNarrowing(); updateActions(); + ensureItemSelected(); } QSize InstrumentListView::sizeHint() const @@ -192,10 +193,7 @@ void InstrumentListView::onRemove() if (!indexes.empty()) { m_model->removeInstrument(indexes.front()); - if (!m_listView->selectionModel()->hasSelection() && m_model->rowCount()) { - QModelIndex last = m_model->index(m_model->rowCount() - 1, 0, QModelIndex()); - m_listView->selectionModel()->select(last, QItemSelectionModel::ClearAndSelect); - } + ensureItemSelected(); } } @@ -265,3 +263,11 @@ void InstrumentListView::updateActions() m_copyAction->setEnabled(enabled); m_storeInLibraryAction->setEnabled(enabled); } + +void InstrumentListView::ensureItemSelected() +{ + if (!m_listView->selectionModel()->hasSelection() && m_model->rowCount()) { + QModelIndex last = m_model->index(m_model->rowCount() - 1, 0, QModelIndex()); + m_listView->selectionModel()->select(last, QItemSelectionModel::ClearAndSelect); + } +} diff --git a/GUI/Views/InstrumentWidgets/InstrumentListView.h b/GUI/Views/InstrumentWidgets/InstrumentListView.h index 3f0a6be80e6..3619741f41a 100644 --- a/GUI/Views/InstrumentWidgets/InstrumentListView.h +++ b/GUI/Views/InstrumentWidgets/InstrumentListView.h @@ -62,6 +62,7 @@ private: void updateFunctionalityNarrowing(); void updateActions(); + void ensureItemSelected(); private: ProjectDocument* m_document; -- GitLab