From 0cc8efa105d1875c821be9cf91611c71ec040714 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 17 Jan 2019 02:57:00 +0100 Subject: [PATCH] simplify handling of locale specific with InputField from Python --- src/Gui/InputField.cpp | 19 +++++++++++++++++++ src/Gui/InputField.h | 7 +++++++ .../_ViewProviderFemResultMechanical.py | 6 +++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index ad070b03ae..6691045abc 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -457,6 +457,25 @@ void InputField::setQuantityString(const QString& text) updateText(actQuantity); } +/// return the quantity in C locale, i.e. decimal separator is a dot. +QString InputField::rawText(void) const +{ + double factor; + QString unit; + double value = actQuantity.getValue(); + actQuantity.getUserString(factor, unit); + return QString::fromLatin1("%1 %2").arg(value / factor).arg(unit); +} + +/// expects the string in C locale and internally converts it into the OS-specific locale +void InputField::setRawText(const QString& text) +{ + Base::Quantity quant = Base::Quantity::parse(text); + // Input and then format the quantity + newInput(quant.getUserString()); + updateText(actQuantity); +} + /// get the value of the singleStep property double InputField::singleStep(void)const { diff --git a/src/Gui/InputField.h b/src/Gui/InputField.h index 4278c2994b..b9eb1f6bfc 100644 --- a/src/Gui/InputField.h +++ b/src/Gui/InputField.h @@ -72,6 +72,7 @@ class GuiExport InputField : public ExpressionLineEdit, public ExpressionBinding Q_PROPERTY(QString format READ getFormat WRITE setFormat ) Q_PROPERTY(Base::Quantity quantity READ getQuantity WRITE setValue ) Q_PROPERTY(QString quantityString READ getQuantityString WRITE setQuantityString ) + Q_PROPERTY(QString rawText READ rawText WRITE setRawText ) public: @@ -92,6 +93,12 @@ public: /// set, validate and display quantity from a string. Must match existing units. void setQuantityString(const QString& text); + /// return the quantity in C locale, i.e. decimal separator is a dot. + QString rawText(void) const; + + /// expects the string in C locale and internally converts it into the OS-specific locale + void setRawText(const QString& text); + /// gives the current state of the user input, gives true if it is a valid input with correct quantity /// (shown by the green pixmap), returns false if the input is a unparsable string or has a wrong unit /// (shown by the red pixmap in the gui) diff --git a/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py b/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py index 30b2667717..27cd3d1dc2 100644 --- a/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py +++ b/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py @@ -380,11 +380,11 @@ class _TaskPanelFemResultShow: def set_result_stats(self, unit, minm, avg, maxm): self.form.le_min.setProperty("unit", unit) - self.form.le_min.setText("{:.6} {}".format(minm, unit)) + self.form.le_min.setProperty("rawText", "{:.6} {}".format(minm, unit)) self.form.le_avg.setProperty("unit", unit) - self.form.le_avg.setText("{:.6} {}".format(avg, unit)) + self.form.le_avg.setProperty("rawText", "{:.6} {}".format(avg, unit)) self.form.le_max.setProperty("unit", unit) - self.form.le_max.setText("{:.6} {}".format(maxm, unit)) + self.form.le_max.setProperty("rawText", "{:.6} {}".format(maxm, unit)) def update_displacement(self, factor=None): if factor is None: