From 5fddaae9bb014520d22091ffc2380cb9ffb7b5cd Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Tue, 5 Dec 2023 12:55:39 +0100 Subject: [PATCH] rm DoubleLineEdit; MaterialInplaceForm use DoubleSpinBox --- GUI/View/Numeric/DoubleLineEdit.cpp | 52 ------------------------- GUI/View/Numeric/DoubleLineEdit.h | 50 ------------------------ GUI/View/Sample/MaterialInplaceForm.cpp | 9 +---- 3 files changed, 2 insertions(+), 109 deletions(-) delete mode 100644 GUI/View/Numeric/DoubleLineEdit.cpp delete mode 100644 GUI/View/Numeric/DoubleLineEdit.h diff --git a/GUI/View/Numeric/DoubleLineEdit.cpp b/GUI/View/Numeric/DoubleLineEdit.cpp deleted file mode 100644 index 26dcea58d8a..00000000000 --- a/GUI/View/Numeric/DoubleLineEdit.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/Numeric/DoubleLineEdit.cpp -//! @brief Implements class DoubleLineEdit. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/Numeric/DoubleLineEdit.h" - -DoubleLineEdit::DoubleLineEdit(QWidget* parent, const DoubleProperty& d) - : QLineEdit(parent) - , m_validator(new QDoubleValidator(0.0, 1e200, 1000, this)) - , m_valueProperty(d) -{ - m_validator->setNotation(QDoubleValidator::ScientificNotation); - const double minimum = - d.limits().hasLowerLimit() ? std::max(d.limits().lowerLimit(), -1e200) : -1e200; - const double maximum = - d.limits().hasUpperLimit() ? std::min(d.limits().upperLimit(), +1e200) : +1e200; - m_validator->setRange(minimum, maximum, 1000); - setValidator(m_validator); - - setToolTip(d.tooltip()); - - updateBaseValue(); - - connect(this, &QLineEdit::editingFinished, this, &DoubleLineEdit::onEditingFinished); -} - -void DoubleLineEdit::setBaseValue(double value) -{ - setText(QString::number(value, 'g')); -} - -void DoubleLineEdit::updateBaseValue() -{ - setBaseValue(m_valueProperty.value()); -} - -void DoubleLineEdit::onEditingFinished() -{ - const double new_value = text().toDouble(); - if (new_value != m_valueProperty.value()) - emit baseValueChanged(new_value); -} diff --git a/GUI/View/Numeric/DoubleLineEdit.h b/GUI/View/Numeric/DoubleLineEdit.h deleted file mode 100644 index fd612a7bb8e..00000000000 --- a/GUI/View/Numeric/DoubleLineEdit.h +++ /dev/null @@ -1,50 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/Numeric/DoubleLineEdit.h -//! @brief Defines class DoubleLineEdit. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_NUMERIC_DOUBLELINEEDIT_H -#define BORNAGAIN_GUI_VIEW_NUMERIC_DOUBLELINEEDIT_H - -#include "GUI/Model/Descriptor/DoubleProperty.h" -#include <QDoubleValidator> -#include <QLineEdit> - -//! LineEdit to edit values in a scientific notation, operating on a DoubleProperty. -//! -//! In the future it can be enhanced to support units. At the moment, no DoubleProperty with units -//! is used with a DoubleLineEdit, therefore the handling of units is not implemented yet. Only the -//! naming is prepared already (also to have a naming alike to DoubleSpinBox). -class DoubleLineEdit : public QLineEdit { - Q_OBJECT -public: - DoubleLineEdit(QWidget* parent, const DoubleProperty& d); - - //! Set the base value (unit is the one of the contained descriptor). - void setBaseValue(double value); - - void updateBaseValue(); - -signals: - //! Emitted whenever the value changes. - void baseValueChanged(double value); - -private slots: - void onEditingFinished(); - -private: - QDoubleValidator* m_validator; - const DoubleProperty& m_valueProperty; -}; - - -#endif // BORNAGAIN_GUI_VIEW_NUMERIC_DOUBLELINEEDIT_H diff --git a/GUI/View/Sample/MaterialInplaceForm.cpp b/GUI/View/Sample/MaterialInplaceForm.cpp index 74835f1a7fc..368de35d651 100644 --- a/GUI/View/Sample/MaterialInplaceForm.cpp +++ b/GUI/View/Sample/MaterialInplaceForm.cpp @@ -21,7 +21,6 @@ #include "GUI/Model/Sample/SampleItem.h" #include "GUI/Support/XML/Backup.h" #include "GUI/View/MaterialEditor/MaterialEditorDialog.h" -#include "GUI/View/Numeric/DoubleLineEdit.h" #include "GUI/View/Numeric/DoubleSpinBox.h" #include "GUI/View/Sample/LayerEditorUtil.h" #include "GUI/View/Sample/SampleEditorController.h" @@ -54,10 +53,6 @@ void MaterialInplaceForm::updateValues() QSignalBlocker b(editor); editor->updateValue(); } - for (auto* editor : findChildren<DoubleLineEdit*>()) { - QSignalBlocker b(editor); - editor->updateBaseValue(); - } } void MaterialInplaceForm::selectMaterial() @@ -98,11 +93,11 @@ void MaterialInplaceForm::createWidgets() int col = 0; for (DoubleProperty* d : values) { - auto* editor = new DoubleLineEdit(this, *d); + auto* editor = new DoubleSpinBox(*d); auto* label = new QLabel(d->label(), this); label->setBuddy(editor); - QObject::connect(editor, &DoubleLineEdit::baseValueChanged, [this, d](double newValue) { + QObject::connect(editor, &DoubleSpinBox::valueChanged, [this, d](double newValue) { m_ec->setMaterialValue(m_item, newValue, *d); }); -- GitLab