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

rm DoubleLineEdit; MaterialInplaceForm use DoubleSpinBox

parent 423a4067
No related branches found
No related tags found
1 merge request!2201repair and copy edit MaterialEditorDialog (#867); get rid of class DoubleLineEdit
// ************************************************************************************************
//
// 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);
}
// ************************************************************************************************
//
// 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
......@@ -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);
});
......
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