Allow entering localized lengths with unit (#11852)

This commit is contained in:
Juergen Spitzmueller 2022-08-08 18:34:34 +02:00
parent 4296df9960
commit 1487b19803
3 changed files with 23 additions and 2 deletions

View File

@ -72,8 +72,12 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const
GlueLength gl;
if (unsigned_ && gl.len().value() < 0)
return QValidator::Invalid;
return (isValidGlueLength(text, &gl)) ?
QValidator::Acceptable : QValidator::Intermediate;
if (isValidGlueLength(text, &gl))
return QValidator::Acceptable;
// Also check for localized variant
if (isValidGlueLength(fromqstr(unlocString(qtext)), &gl))
return QValidator::Acceptable;
return QValidator::Intermediate;
}
Length l;

View File

@ -99,6 +99,9 @@ string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
// Don't return unit-from-choice if the input(field) contains a unit
if (isValidGlueLength(fromqstr(length)))
return fromqstr(length);
// Also try with localized version
if (isValidGlueLength(fromqstr(unlocString(length))))
return fromqstr(unlocString(length));
Length::UNIT const unit = combo->currentLengthItem();
@ -115,6 +118,9 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo)
// don't return unit-from-choice if the input(field) contains a unit
if (isValidGlueLength(fromqstr(length)))
return Length(fromqstr(length));
// Also try with localized version
if (isValidGlueLength(fromqstr(unlocString(length))))
return Length(fromqstr(unlocString(length)));
Length::UNIT unit = Length::UNIT_NONE;
QString const item = combo->currentText();
@ -208,6 +214,14 @@ QString formatLocFPNumber(double d)
}
QString unlocString(QString const & str)
{
QLocale loc;
QString res = str;
return res.replace(loc.decimalPoint(), QString("."));
}
bool SortLocaleAware(QString const & lhs, QString const & rhs)
{
return QString::localeAwareCompare(lhs, rhs) < 0;

View File

@ -72,6 +72,9 @@ void doubleToWidget(QLineEdit * input, std::string const & value,
*/
QString formatLocFPNumber(double d);
// Method to replace localized decimal separator by dot
QString unlocString(QString const & str);
/// Method to sort QStrings locale-aware (e.g. in combo widgets)
bool SortLocaleAware(QString const & lhs, QString const & rhs);