From 680675480094b7c37cc17aba7e106159fc26f4dc Mon Sep 17 00:00:00 2001 From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de> Date: Mon, 17 Apr 2023 17:26:51 +0200 Subject: [PATCH] show SLD units --- GUI/Model/Sample/MaterialItem.cpp | 10 ++++++---- GUI/View/Numeric/DoubleLineEdit.cpp | 10 ++++++++++ GUI/View/Numeric/DoubleLineEdit.h | 1 + GUI/View/SampleDesigner/LayerEditorUtil.cpp | 3 +++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/GUI/Model/Sample/MaterialItem.cpp b/GUI/Model/Sample/MaterialItem.cpp index 7264b59ddec..de2f7b99f7c 100644 --- a/GUI/Model/Sample/MaterialItem.cpp +++ b/GUI/Model/Sample/MaterialItem.cpp @@ -46,10 +46,12 @@ MaterialItem::MaterialItem() m_beta.init("Beta", "Beta of refractive index (n = 1 - delta + i*beta)", 0.0, Unit::unitless, 3, RealLimits::limitless(), "beta"); - m_sldRe.init("SLD, real", "Real part of SLD (SLD = real - i*imag), AA^{-2}", 0.0, - Unit::unitless, 3, RealLimits::limitless(), "sldRe"); - m_sldIm.init("SLD, imaginary", "Imaginary part of SLD (SLD = real - i*imag), AA^{-2}", 0.0, - Unit::unitless, 3, RealLimits::limitless(), "sldIm"); + Unit sld_units = Unit::angstromMinus2; + QString sld_units_str = unitAsString(sld_units); + m_sldRe.init("SLD, real", "Real part of SLD (SLD = real - i*imag), " + sld_units_str, 0.0, + sld_units, 3, RealLimits::limitless(), "sldRe"); + m_sldIm.init("SLD, imaginary", "Imaginary part of SLD (SLD = real - i*imag), " + sld_units_str, + 0.0, sld_units, 3, RealLimits::limitless(), "sldIm"); m_magnetization.init("Magnetization", "Magnetization (A/m)", "A/m", "magnetization"); } diff --git a/GUI/View/Numeric/DoubleLineEdit.cpp b/GUI/View/Numeric/DoubleLineEdit.cpp index 22c8ebf3c25..122a7fc6df3 100644 --- a/GUI/View/Numeric/DoubleLineEdit.cpp +++ b/GUI/View/Numeric/DoubleLineEdit.cpp @@ -28,6 +28,8 @@ DoubleLineEdit::DoubleLineEdit(QWidget* parent, const DoubleProperty& d) m_validator->setRange(minimum, maximum, 1000); setValidator(m_validator); + setToolTip(d.tooltip()); + updateBaseValue(); connect(this, &QLineEdit::editingFinished, this, &DoubleLineEdit::onEditingFinished); @@ -43,6 +45,14 @@ void DoubleLineEdit::updateBaseValue() setBaseValue(m_valueProperty.value()); } +QString DoubleLineEdit::displayUnitAsString() const +{ + if (std::holds_alternative<QString>(m_valueProperty.unit())) + return std::get<QString>(m_valueProperty.unit()); + + return unitAsString(std::get<Unit>(m_valueProperty.unit())); +} + void DoubleLineEdit::onEditingFinished() { const double new_value = text().toDouble(); diff --git a/GUI/View/Numeric/DoubleLineEdit.h b/GUI/View/Numeric/DoubleLineEdit.h index d3b82e78364..90fdde35385 100644 --- a/GUI/View/Numeric/DoubleLineEdit.h +++ b/GUI/View/Numeric/DoubleLineEdit.h @@ -35,6 +35,7 @@ public: void updateBaseValue(); + QString displayUnitAsString() const; signals: //! Emitted whenever the value changes. //! diff --git a/GUI/View/SampleDesigner/LayerEditorUtil.cpp b/GUI/View/SampleDesigner/LayerEditorUtil.cpp index 04c75fe29cb..5602222f93b 100644 --- a/GUI/View/SampleDesigner/LayerEditorUtil.cpp +++ b/GUI/View/SampleDesigner/LayerEditorUtil.cpp @@ -21,6 +21,7 @@ #include "GUI/Model/Sample/ParticleItem.h" #include "GUI/Model/Sample/ProfileItems.h" #include "GUI/Model/Sample/RoughnessItems.h" +#include "GUI/View/Numeric/DoubleLineEdit.h" #include "GUI/View/Numeric/DoubleSpinBox.h" #include "GUI/View/SampleDesigner/CompoundForm.h" #include "GUI/View/SampleDesigner/CoreAndShellForm.h" @@ -62,6 +63,8 @@ void LayerEditorUtil::updateLabelUnit(QLabel* label) { if (auto* editor = dynamic_cast<DoubleSpinBox*>(label->buddy())) ::updateLabelUnit(label, editor->displayUnitAsString()); + else if (auto* editor = dynamic_cast<DoubleLineEdit*>(label->buddy())) + ::updateLabelUnit(label, editor->displayUnitAsString()); } void LayerEditorUtil::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int firstCol, -- GitLab