Skip to content
Snippets Groups Projects
Commit d17ff862 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

introduce DoubleLineEdit, a line edit which operates on a DoubleDescriptor

parent f9274c0e
No related branches found
No related tags found
1 merge request!412More preparations for layer oriented sample editor
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Views/CommonWidgets/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/Views/CommonWidgets/DoubleLineEdit.h"
#include "GUI/Views/CommonWidgets/GUIHelpers.h"
#include <QDoubleValidator>
DoubleLineEdit::DoubleLineEdit(QWidget* parent, const DoubleDescriptor& d)
: QLineEdit(parent), m_valueDescriptor(d)
{
m_validator = new QDoubleValidator(0.0, 1e+200, 1000, this);
m_validator->setNotation(QDoubleValidator::ScientificNotation);
const double minimum =
d.limits.hasLowerLimit() ? std::max(d.limits.lowerLimit(), -1e+200) : -1e+200;
const double maximum =
d.limits.hasUpperLimit() ? std::min(d.limits.upperLimit(), +1e+200) : +1e+200;
m_validator->setRange(minimum, maximum, 1000);
setValidator(m_validator);
setBaseValue(m_valueDescriptor.get());
connect(this, &QLineEdit::editingFinished, this, &DoubleLineEdit::onEditingFinished);
}
void DoubleLineEdit::setBaseValue(double baseValue)
{
setText(QString::number(baseValue, 'g'));
}
void DoubleLineEdit::onEditingFinished()
{
const double new_value = text().toDouble();
if (new_value != m_valueDescriptor.get())
emit baseValueChanged(new_value);
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Views/CommonWidgets/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_VIEWS_COMMONWIDGETS_DOUBLELINEEDIT_H
#define BORNAGAIN_GUI_VIEWS_COMMONWIDGETS_DOUBLELINEEDIT_H
#include "GUI/Models/DoubleDescriptor.h"
#include <QLineEdit>
class QDoubleValidator;
//! LineEdit to edit values in a scientific notation, operating on a DoubleDescriptor.
//!
//! In the future it can be enhanced to support units. At the moment, no DoubleDescriptor 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 DoubleDescriptor& d);
//! Set the base value (unit is the one of the contained descriptor).
void setBaseValue(double baseValue);
signals:
//! Emitted whenever the value changes.
//!
//! newBaseValue is in the unit of the valueDescriptor.
void baseValueChanged(double newBaseValue);
private slots:
void onEditingFinished();
private:
QDoubleValidator* m_validator;
DoubleDescriptor m_valueDescriptor;
};
#endif // BORNAGAIN_GUI_VIEWS_COMMONWIDGETS_DOUBLELINEEDIT_H
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