Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix QgsDoubleValidator for positive sign
Allow the positive sign in front of a positive number
  • Loading branch information
agiudiceandrea authored and github-actions[bot] committed May 5, 2023
1 parent 721f4a1 commit b281204
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gui/qgsdoublevalidator.cpp
Expand Up @@ -25,7 +25,7 @@

#include "qgsdoublevalidator.h"

const QString PERMISSIVE_DOUBLE = R"([-%3]?[\d]{0,1000}([\.%1][\d]{0,1000})?(e[+\-%3]?[\d]{0,%2})?)";
const QString PERMISSIVE_DOUBLE = R"([+\-%3]?[\d]{0,1000}([\.%1][\d]{0,1000})?(e[+\-%3]?[\d]{0,%2})?)";

QgsDoubleValidator::QgsDoubleValidator( QObject *parent )
: QRegularExpressionValidator( parent )
Expand Down
4 changes: 4 additions & 0 deletions tests/src/gui/testqgsdoublevalidator.cpp
Expand Up @@ -68,6 +68,8 @@ void TestQgsDoubleValidator::validate_data()
QTest::newRow( "locale negative locale decimal" ) << QString( "ln4ld6" ) << int( QValidator::Acceptable ) << true;
QTest::newRow( "locale negative locale decimal" ) << QString( "ln4444ld6" ) << int( QValidator::Acceptable ) << true;

QTest::newRow( "positive sign C decimal" ) << QString( "+4cd6" ) << int( QValidator::Acceptable ) << false;

// QgsDoubleValidator doesn't expect group separator but it tolerates it,
// so the result will be QValidator::Intermediate and not QValidator::Acceptable
QTest::newRow( "locale group separator + locale decimal" ) << QString( "4lg444ld6" ) << int( QValidator::Intermediate ) << false;
Expand Down Expand Up @@ -95,6 +97,8 @@ void TestQgsDoubleValidator::toDouble_data()
QTest::newRow( "locale negative locale decimal" ) << QString( "ln4ld6" ) << -4.6;
QTest::newRow( "locale negative locale decimal" ) << QString( "ln4444ld6" ) << -4444.6;

QTest::newRow( "positive sign C decimal" ) << QString( "+4cd6" ) << 4.6;

// QgsDoubleValidator doesn't expect group separator but it tolerates it,
// so the result will be QValidator::Intermediate and not QValidator::Acceptable
QTest::newRow( "locale group separator + locale decimal" ) << QString( "4lg444ld6" ) << 4444.6;
Expand Down

0 comments on commit b281204

Please sign in to comment.