From bab43eb300f3f673675360d4352433e23bb99d63 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Sun, 29 Oct 2023 18:16:12 +0100 Subject: [PATCH] wip --- GUI/View/Project/SimulationView.cpp | 120 ++++++++++++++-------------- GUI/View/Project/SimulationView.h | 6 -- 2 files changed, 60 insertions(+), 66 deletions(-) diff --git a/GUI/View/Project/SimulationView.cpp b/GUI/View/Project/SimulationView.cpp index 539222b6825..be0cca3a15b 100644 --- a/GUI/View/Project/SimulationView.cpp +++ b/GUI/View/Project/SimulationView.cpp @@ -27,17 +27,17 @@ #include "GUI/View/Project/ProjectManager.h" #include "GUI/View/Project/PythonScriptWidget.h" #include "GUI/View/Widget/GroupBoxes.h" -#include "ui_SimulationView.h" #include <QButtonGroup> #include <QMessageBox> #include <thread> SimulationView::SimulationView(QWidget* parent, ProjectDocument* document) : QWidget(parent) - , m_ui(new Ui::SimulationView) , m_document(document) { - m_ui->setupUi(this); + auto* layout = new QVBoxLayout; + setLayout(layout); + m_ambientLayerRadio = m_ui->ambientLayerRadio; m_analyticalRadio = m_ui->analyticalRadio; m_averageLayerRadio = m_ui->averageLayerRadio; @@ -57,55 +57,55 @@ SimulationView::SimulationView(QWidget* parent, ProjectDocument* document) m_sampleCombo = m_ui->sampleCombo; m_simulateButton = m_ui->simulateButton; - GroupBoxCollapser::installIntoGroupBox(m_ui->groupBox_3); - GroupBoxCollapser::installIntoGroupBox(m_ui->groupBox_2); - GroupBoxCollapser::installIntoGroupBox(m_ui->groupBox); + GroupBoxCollapser::installIntoGroupBox(m_groupBox_3); + GroupBoxCollapser::installIntoGroupBox(m_groupBox_2); + GroupBoxCollapser::installIntoGroupBox(m_groupBox); auto* buttonGroup = new QButtonGroup(this); - buttonGroup->addButton(m_ui->runPolicyImmediatelyRadio); - buttonGroup->addButton(m_ui->runPolicyBackgroundRadio); + buttonGroup->addButton(m_runPolicyImmediatelyRadio); + buttonGroup->addButton(m_runPolicyBackgroundRadio); auto* computationButtonGroup = new QButtonGroup(this); - computationButtonGroup->addButton(m_ui->analyticalRadio); - computationButtonGroup->addButton(m_ui->monteCarloRadio); + computationButtonGroup->addButton(m_analyticalRadio); + computationButtonGroup->addButton(m_monteCarloRadio); buttonGroup = new QButtonGroup(this); - buttonGroup->addButton(m_ui->ambientLayerRadio); - buttonGroup->addButton(m_ui->averageLayerRadio); + buttonGroup->addButton(m_ambientLayerRadio); + buttonGroup->addButton(m_averageLayerRadio); // -- fill combo for "number of threads" const int nthreads = static_cast<int>(std::thread::hardware_concurrency()); - m_ui->numberOfThreadsCombo->addItem(QString("Max (%1 threads)").arg(nthreads), nthreads); + m_numberOfThreadsCombo->addItem(QString("Max (%1 threads)").arg(nthreads), nthreads); for (int i = nthreads - 1; i > 1; i--) - m_ui->numberOfThreadsCombo->addItem(QString("%1 threads").arg(i), i); - m_ui->numberOfThreadsCombo->addItem("1 thread", 1); + m_numberOfThreadsCombo->addItem(QString("%1 threads").arg(i), i); + m_numberOfThreadsCombo->addItem("1 thread", 1); updateFunctionalityNarrowing(); - connect(m_ui->instrumentCombo, &QComboBox::currentTextChanged, [this] { updateStateFromUI(); }); - connect(m_ui->sampleCombo, &QComboBox::currentTextChanged, [this] { updateStateFromUI(); }); - connect(m_ui->realDataCombo, &QComboBox::currentTextChanged, [this] { updateStateFromUI(); }); + connect(m_instrumentCombo, &QComboBox::currentTextChanged, [this] { updateStateFromUI(); }); + connect(m_sampleCombo, &QComboBox::currentTextChanged, [this] { updateStateFromUI(); }); + connect(m_realDataCombo, &QComboBox::currentTextChanged, [this] { updateStateFromUI(); }); - connect(m_ui->simulateButton, &QPushButton::clicked, this, &SimulationView::simulate); - connect(m_ui->exportToPyScriptButton, &QPushButton::clicked, this, + connect(m_simulateButton, &QPushButton::clicked, this, &SimulationView::simulate); + connect(m_exportToPyScriptButton, &QPushButton::clicked, this, &SimulationView::exportPythonScript); connect(computationButtonGroup, &QButtonGroup::buttonClicked, this, &SimulationView::updateEnabling); - connect(m_ui->runPolicyImmediatelyRadio, &QRadioButton::toggled, + connect(m_runPolicyImmediatelyRadio, &QRadioButton::toggled, [this]() { updateStateFromUI(); }); - connect(m_ui->analyticalRadio, &QRadioButton::toggled, [this]() { updateStateFromUI(); }); + connect(m_analyticalRadio, &QRadioButton::toggled, [this]() { updateStateFromUI(); }); - connect(m_ui->averageLayerRadio, &QRadioButton::toggled, [this]() { updateStateFromUI(); }); + connect(m_averageLayerRadio, &QRadioButton::toggled, [this]() { updateStateFromUI(); }); - connect(m_ui->numberOfThreadsCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), + connect(m_numberOfThreadsCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [this]() { updateStateFromUI(); }); - connect(m_ui->numberOfMonteCarloPoints, QOverload<int>::of(&QSpinBox::valueChanged), + connect(m_numberOfMonteCarloPoints, QOverload<int>::of(&QSpinBox::valueChanged), [this]() { updateStateFromUI(); }); - connect(m_ui->includeSpecularCheck, &QCheckBox::toggled, [this]() { updateStateFromUI(); }); + connect(m_includeSpecularCheck, &QCheckBox::toggled, [this]() { updateStateFromUI(); }); connect(m_document, &ProjectDocument::modifiedStateChanged, this, &SimulationView::updateFunctionalityNarrowing); @@ -118,35 +118,35 @@ void SimulationView::showEvent(QShowEvent*) void SimulationView::writeOptionsToUI() { - QSignalBlocker b1(m_ui->runPolicyImmediatelyRadio); - QSignalBlocker b2(m_ui->analyticalRadio); - QSignalBlocker b3(m_ui->averageLayerRadio); - QSignalBlocker b4(m_ui->numberOfThreadsCombo); - QSignalBlocker b5(m_ui->numberOfMonteCarloPoints); - QSignalBlocker b6(m_ui->includeSpecularCheck); + QSignalBlocker b1(m_runPolicyImmediatelyRadio); + QSignalBlocker b2(m_analyticalRadio); + QSignalBlocker b3(m_averageLayerRadio); + QSignalBlocker b4(m_numberOfThreadsCombo); + QSignalBlocker b5(m_numberOfMonteCarloPoints); + QSignalBlocker b6(m_includeSpecularCheck); // -- selection group - updateSelection(m_ui->instrumentCombo, m_document->instrumentModel()->instrumentNames(), + updateSelection(m_instrumentCombo, m_document->instrumentModel()->instrumentNames(), optionsItem()->selectedInstrumentIndex()); - updateSelection(m_ui->sampleCombo, m_document->sampleModel()->sampleNames(), + updateSelection(m_sampleCombo, m_document->sampleModel()->sampleNames(), optionsItem()->selectedSampleIndex()); - updateSelection(m_ui->realDataCombo, m_document->realModel()->realItemNames(), + updateSelection(m_realDataCombo, m_document->realModel()->realItemNames(), optionsItem()->selectedDataIndex(), true); // -- options group - optionsItem()->runImmediately() ? m_ui->runPolicyImmediatelyRadio->setChecked(true) - : m_ui->runPolicyBackgroundRadio->setChecked(true); + optionsItem()->runImmediately() ? m_runPolicyImmediatelyRadio->setChecked(true) + : m_runPolicyBackgroundRadio->setChecked(true); - optionsItem()->useAnalytical() ? m_ui->analyticalRadio->setChecked(true) - : m_ui->monteCarloRadio->setChecked(true); + optionsItem()->useAnalytical() ? m_analyticalRadio->setChecked(true) + : m_monteCarloRadio->setChecked(true); - optionsItem()->useAverageMaterials() ? m_ui->averageLayerRadio->setChecked(true) - : m_ui->ambientLayerRadio->setChecked(true); + optionsItem()->useAverageMaterials() ? m_averageLayerRadio->setChecked(true) + : m_ambientLayerRadio->setChecked(true); - m_ui->numberOfThreadsCombo->setCurrentIndex( - m_ui->numberOfThreadsCombo->findData(optionsItem()->numberOfThreads())); - m_ui->numberOfMonteCarloPoints->setValue(optionsItem()->numberOfMonteCarloPoints()); - m_ui->includeSpecularCheck->setChecked(optionsItem()->includeSpecularPeak()); + m_numberOfThreadsCombo->setCurrentIndex( + m_numberOfThreadsCombo->findData(optionsItem()->numberOfThreads())); + m_numberOfMonteCarloPoints->setValue(optionsItem()->numberOfMonteCarloPoints()); + m_includeSpecularCheck->setChecked(optionsItem()->includeSpecularPeak()); updateEnabling(); } @@ -196,23 +196,23 @@ void SimulationView::exportPythonScript() void SimulationView::readOptionsFromUI() { - optionsItem()->setSelectedInstrumentIndex(m_ui->instrumentCombo->currentIndex()); - optionsItem()->setSelectedSampleIndex(m_ui->sampleCombo->currentIndex()); - optionsItem()->setSelectedDataIndex(m_ui->realDataCombo->currentIndex()); + optionsItem()->setSelectedInstrumentIndex(m_instrumentCombo->currentIndex()); + optionsItem()->setSelectedSampleIndex(m_sampleCombo->currentIndex()); + optionsItem()->setSelectedDataIndex(m_realDataCombo->currentIndex()); - optionsItem()->setRunImmediately(m_ui->runPolicyImmediatelyRadio->isChecked()); - optionsItem()->setNumberOfThreads(m_ui->numberOfThreadsCombo->currentData().toInt()); - if (m_ui->analyticalRadio->isChecked()) + optionsItem()->setRunImmediately(m_runPolicyImmediatelyRadio->isChecked()); + optionsItem()->setNumberOfThreads(m_numberOfThreadsCombo->currentData().toInt()); + if (m_analyticalRadio->isChecked()) optionsItem()->setUseAnalytical(); else - optionsItem()->setUseMonteCarloIntegration(m_ui->numberOfMonteCarloPoints->value()); - optionsItem()->setUseAverageMaterials(m_ui->averageLayerRadio->isChecked()); - optionsItem()->setIncludeSpecularPeak(m_ui->includeSpecularCheck->isChecked()); + optionsItem()->setUseMonteCarloIntegration(m_numberOfMonteCarloPoints->value()); + optionsItem()->setUseAverageMaterials(m_averageLayerRadio->isChecked()); + optionsItem()->setIncludeSpecularPeak(m_includeSpecularCheck->isChecked()); } void SimulationView::updateEnabling() { - m_ui->numberOfMonteCarloPoints->setEnabled(m_ui->monteCarloRadio->isChecked()); + m_numberOfMonteCarloPoints->setEnabled(m_monteCarloRadio->isChecked()); } void SimulationView::updateSelection(QComboBox* comboBox, QStringList itemList, int currentIndex, @@ -268,8 +268,8 @@ QString SimulationView::validateSimulationSetup(bool validateRealData) const void SimulationView::updateFunctionalityNarrowing() { - m_ui->instrumentCombo->setVisible(!m_document->singleInstrumentMode()); - m_ui->instrumentLabel->setVisible(!m_document->singleInstrumentMode()); + m_instrumentCombo->setVisible(!m_document->singleInstrumentMode()); + m_instrumentLabel->setVisible(!m_document->singleInstrumentMode()); } SimulationOptionsItem* SimulationView::optionsItem() const @@ -279,18 +279,18 @@ SimulationOptionsItem* SimulationView::optionsItem() const const SampleItem* SimulationView::selectedSampleItem() const { - return m_document->sampleModel()->sampleItems().value(m_ui->sampleCombo->currentIndex(), + return m_document->sampleModel()->sampleItems().value(m_sampleCombo->currentIndex(), nullptr); } const InstrumentItem* SimulationView::selectedInstrumentItem() const { return m_document->instrumentModel()->instrumentItems().value( - m_ui->instrumentCombo->currentIndex(), nullptr); + m_instrumentCombo->currentIndex(), nullptr); } const RealItem* SimulationView::selectedRealItem() const { - return m_document->realModel()->realItems().value(m_ui->realDataCombo->currentIndex() - 1, + return m_document->realModel()->realItems().value(m_realDataCombo->currentIndex() - 1, nullptr); // -1: "None" } diff --git a/GUI/View/Project/SimulationView.h b/GUI/View/Project/SimulationView.h index 47dfdd82620..7adaf1de32b 100644 --- a/GUI/View/Project/SimulationView.h +++ b/GUI/View/Project/SimulationView.h @@ -30,11 +30,6 @@ class RealItem; class SampleItem; class SimulationOptionsItem; -namespace Ui { - -class SimulationView; -} - //! Widget to define a simulation. //! Contains: //! * Elements to select instrument, sample and real data. @@ -88,7 +83,6 @@ private: //! Show/hide UI elements according to settings in current project void updateFunctionalityNarrowing(); - Ui::SimulationView* m_ui; ProjectDocument* m_document; QRadioButton* m_ambientLayerRadio; -- GitLab