add method toFormat to get number format from character
This commit is contained in:
@@ -63,6 +63,22 @@ struct QuantityFormat {
|
||||
return 'g';
|
||||
}
|
||||
}
|
||||
static inline NumberFormat toFormat(char c, bool* ok = 0) {
|
||||
if (ok)
|
||||
*ok = true;
|
||||
switch (c) {
|
||||
case 'f':
|
||||
return Fixed;
|
||||
case 'e':
|
||||
return Scientific;
|
||||
case 'g':
|
||||
return Default;
|
||||
default:
|
||||
if (ok)
|
||||
*ok = false;
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -631,19 +631,11 @@ void QuantityPy::setFormat(Py::Tuple arg)
|
||||
#endif
|
||||
if (fmtstr.size() != 1)
|
||||
throw Py::ValueError("Invalid format character");
|
||||
switch (fmtstr.front()) {
|
||||
case 'f':
|
||||
fmt.format = QuantityFormat::Fixed;
|
||||
break;
|
||||
case 'e':
|
||||
fmt.format = QuantityFormat::Scientific;
|
||||
break;
|
||||
case 'g':
|
||||
fmt.format = QuantityFormat::Default;
|
||||
break;
|
||||
default:
|
||||
|
||||
bool ok;
|
||||
fmt.format = Base::QuantityFormat::toFormat(fmtstr.front(), &ok);
|
||||
if (!ok)
|
||||
throw Py::ValueError("Invalid format character");
|
||||
}
|
||||
|
||||
getQuantityPtr()->setFormat(fmt);
|
||||
}
|
||||
|
||||
@@ -535,13 +535,11 @@ QString InputField::getFormat() const
|
||||
|
||||
void InputField::setFormat(const QString& format)
|
||||
{
|
||||
if (format.isEmpty())
|
||||
return;
|
||||
QChar c = format[0];
|
||||
Base::QuantityFormat f = this->actQuantity.getFormat();
|
||||
if (format == QString::fromLatin1("f"))
|
||||
f.format = Base::QuantityFormat::NumberFormat::Fixed;
|
||||
else if (format == QString::fromLatin1("e"))
|
||||
f.format = Base::QuantityFormat::NumberFormat::Scientific;
|
||||
else
|
||||
f.format = Base::QuantityFormat::NumberFormat::Default;
|
||||
f.format = Base::QuantityFormat::toFormat(c.toLatin1());
|
||||
actQuantity.setFormat(f);
|
||||
updateText(actQuantity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user