simplify handling of locale specific with InputField from Python

This commit is contained in:
wmayer
2019-01-17 02:57:00 +01:00
parent fdf8fe7bc6
commit 0cc8efa105
3 changed files with 29 additions and 3 deletions

View File

@@ -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
{

View File

@@ -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)

View File

@@ -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: