-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix QgsDoubleValidator for positive sign and for negative and exponential signs in some locales (Fix #52341) #52923
Fix QgsDoubleValidator for positive sign and for negative and exponential signs in some locales (Fix #52341) #52923
Conversation
Some locales use the − character [Unicode Character “−” (U+2212)] as negative sign, instead of the - character [Unicode Character “-” (U+002D)]
Yes, please.
Yes, please. Also, we should probably reduce the default limits to fit into a
Yes, please, make sure they are tested (I think they are not)
This is probably not necessary, the separator is removed before testing the expression: double QgsDoubleValidator::toDouble( const QString &input, bool *ok )
{
double value = QLocale().toDouble( input, ok );
if ( ! *ok )
{
value = QLocale( QLocale::C ).toDouble( input, ok );
}
// Still non ok? Try without locale's group separator
if ( ! *ok && !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
{
value = QLocale( ).toDouble( QString( input ).replace( QLocale().groupSeparator(), QString() ), ok );
}
return value ;
} |
Allow the positive sign in front of a positive number
@elpaso, while I don't know why the range
I think that even an exponent > 308 or < -308 should be allowed, since e.g. the string Anyway, I think we could safely enough restrict the number of digits for the exponent part to 3 (with a minimum of 1), i.e. with a range |
You are right, let's keep it. Maybe useful to add a few test cases for these "extreme" cases.
It makes sense. |
Also allow to use <E> and the locale exponential sign (for Ukrainian language)
dfaada8
to
7fbd26a
Compare
Hi @elpaso, I've fixed in this PR the issue reported in #52341 and also the issues I've found about the plus sign in front of a positive number and the exponential signs. I prefer to open a different PR for the issue about the max number of decimals incorrectly handled, as it could lead to a behaviour different from the current one for some widgets. I also prefer to open an issue report for the issue about the values with the group separator: it seems QgsDoubleValidator has been implemented to only "tolerate" numbers with group separators, but not "accept" them, as you can read in QGIS/tests/src/gui/testqgsdoublevalidator.cpp Lines 66 to 67 in 4df6a2b
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Description
Some locales (see #52341 (comment) for the list) use the
−
characterUnicode Character “−” (U+2212)
as negative sign, instead of the-
characterUnicode Character “-” (U+002D)
.This PR makes the QgsDoubleValidator accept also the
Unicode Character “−” (U+2212)
as negative sign in the locales in which it is used.Fixes #52341.
It also makes QgsDoubleValidator accept the plus sign in front of positive numbers and accept the
E
character as exponential sign and theUnicode Character “е” (U+0435)
as exponential sign in the locales in which it is used (uk_UA Ukranian).NOTE: looking at the original "parametrized" regex
PERMISSIVE_DOUBLE = R"(-?[\d]{0,1000}([\.%1][\d]{0,1000})?(e[+-]?[\d]{0,%2})?)";
it seems to me it has other various issues:it does not allow the plus sign in front of the value: should I also fix it?[ADDRESSED IN THIS PR]%2
parameter should be the number of allowed decimal digits but it seems to me it is in the wrong place: it should be in the second {0,1000} (which is the decimals part) and not after thee
(which is the exponent part). @SebastienPeillet could you please confirm that it is due to a typo in your PR Fix decimal point issues on raster properties forms, Fixes #33859 #37136 and that I should also fix it? [I WILL FIX IT IN A DIFFERENT PR]it is only allowed the[ADDRESSED IN THIS PR]e
exponent character, but it should be allowed also theE
character and the character returned byQLocale().exponential()
(actually it seems only uk_UA Ukranian laguage uses the characterUnicode Character “е” (U+0435)
instead ofUnicode Character “e” (U+0065)
for the exponent): should I also fix it in the same way?