Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix suggested by reviewers
  • Loading branch information
speillet committed Jul 14, 2020
1 parent 893bfff commit 887d544
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 93 deletions.
47 changes: 14 additions & 33 deletions python/gui/auto_generated/qgsdoublevalidator.sip.in
Expand Up @@ -15,7 +15,7 @@ class QgsDoubleValidator : QRegularExpressionValidator

QgsDoubleValidator is a QLineEdit Validator that combines QDoubleValidator
and QRegularExpressionValidator to allow user to enter double with both
local and C interpretation.
local and C interpretation as a fallback.

.. versionadded:: 3.14
%End
Expand All @@ -28,56 +28,47 @@ local and C interpretation.
explicit QgsDoubleValidator( QObject *parent );
%Docstring
Constructor for QgsDoubleValidator.

.. versionadded:: 3.14
%End

QgsDoubleValidator( QRegularExpression reg, double bottom, double top, QObject *parent );
QgsDoubleValidator( const QRegularExpression &expression, double bottom, double top, QObject *parent );
%Docstring
Constructor for QgsDoubleValidator.

.. versionadded:: 3.14
:param bottom: the minimal range limit accepted by the validator
:param top: the maximal range limit accepted by the validator
%End

QgsDoubleValidator( double bottom, double top, QObject *parent );
%Docstring
Constructor for QgsDoubleValidator.

.. versionadded:: 3.14
:param bottom: the minimal range limit accepted by the validator
:param top: the maximal range limit accepted by the validator
%End

QgsDoubleValidator( double bottom, double top, int dec, QObject *parent );
QgsDoubleValidator( double bottom, double top, int decimal, QObject *parent );
%Docstring
Constructor for QgsDoubleValidator.

.. versionadded:: 3.14
:param bottom: the minimal range limit accepted by the validator
:param top: the maximal range limit accepted by the validator
:param decimal: the number of decimal accepted by the validator
%End

virtual QValidator::State validate( QString &input, int & ) const;

%Docstring
Evaluates input QString validity according to QRegularExpression
and ability to be converted in double value.

.. versionadded:: 3.14
%End

QValidator::State validate( QString input ) const;
QValidator::State validate( QString &input ) const;
%Docstring
Evaluates input QString validity according to QRegularExpression
Evaluates ``input`` string validity according to QRegularExpression
and ability to be converted in double value.

.. versionadded:: 3.14
%End


static double toDouble( QString input );
static double toDouble( const QString &input );
%Docstring
Converts QString to double value.
Converts ``input`` string to double value.
It used locale interpretation first
and C locale interpretation as fallback

.. versionadded:: 3.14
%End

void setBottom( double bottom );
Expand All @@ -87,8 +78,6 @@ Set top range limit
.. seealso:: :py:func:`setTop`

.. seealso:: :py:func:`setRange`

.. versionadded:: 3.14
%End

void setTop( double top );
Expand All @@ -98,8 +87,6 @@ Set top range limit
.. seealso:: :py:func:`setBottom`

.. seealso:: :py:func:`setRange`

.. versionadded:: 3.14
%End

virtual void setRange( double bottom, double top );
Expand All @@ -109,26 +96,20 @@ Set bottom and top range limits
.. seealso:: :py:func:`setBottom`

.. seealso:: :py:func:`setTop`

.. versionadded:: 3.14
%End

double bottom() const;
%Docstring
Returns top range limit

.. seealso:: :py:func:`setBottom`

.. versionadded:: 3.14
%End

double top() const;
%Docstring
Returns top range limit

.. seealso:: :py:func:`setTop`

.. versionadded:: 3.14
%End

};
Expand Down
44 changes: 22 additions & 22 deletions src/gui/qgsdoublevalidator.cpp
Expand Up @@ -28,40 +28,40 @@ const QString PERMISSIVE_DOUBLE = R"(-?[\d]{0,1000}([\.%1][\d]{0,1000})?(e[+-]?[

QgsDoubleValidator::QgsDoubleValidator( QObject *parent )
: QRegularExpressionValidator( parent )
, b( std::numeric_limits<qreal>::min() )
, t( std::numeric_limits<qreal>::max() )
, mMinimum( std::numeric_limits<qreal>::min() )

This comment has been minimized.

Copy link
@elpaso

elpaso Nov 4, 2020

Contributor

@SebastienPeillet this doesn't do what you think it does: you want lowest.

This comment has been minimized.

Copy link
@SebastienPeillet

SebastienPeillet Nov 6, 2020

Contributor

👍

, mMaximum( std::numeric_limits<qreal>::max() )
{
// The regular expression accept double with point as decimal point but also the locale decimal point
QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( 1000 ) );
this->setRegularExpression( reg );
setRegularExpression( reg );
}

QgsDoubleValidator::QgsDoubleValidator( QRegularExpression reg, double bottom, double top, QObject *parent )
QgsDoubleValidator::QgsDoubleValidator( const QRegularExpression &expression, double bottom, double top, QObject *parent )
: QRegularExpressionValidator( parent )
, b( bottom )
, t( top )
, mMinimum( bottom )
, mMaximum( top )
{
this->setRegularExpression( reg );
setRegularExpression( expression );
}

QgsDoubleValidator::QgsDoubleValidator( double bottom, double top, QObject *parent )
: QRegularExpressionValidator( parent )
, b( bottom )
, t( top )
, mMinimum( bottom )
, mMaximum( top )
{
// The regular expression accept double with point as decimal point but also the locale decimal point
QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( 1000 ) );
this->setRegularExpression( reg );
setRegularExpression( reg );
}

QgsDoubleValidator::QgsDoubleValidator( double bottom, double top, int dec, QObject *parent )
QgsDoubleValidator::QgsDoubleValidator( double bottom, double top, int decimal, QObject *parent )
: QRegularExpressionValidator( parent )
, b( bottom )
, t( top )
, mMinimum( bottom )
, mMaximum( top )
{
// The regular expression accept double with point as decimal point but also the locale decimal point
QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( QString::number( dec ) ) );
this->setRegularExpression( reg );
QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( QString::number( decimal ) ) );
setRegularExpression( reg );
}

QValidator::State QgsDoubleValidator::validate( QString &input, int & ) const
Expand All @@ -71,7 +71,7 @@ QValidator::State QgsDoubleValidator::validate( QString &input, int & ) const


bool ok = false;
double entered = QgsDoubleValidator::toDouble( input, &ok );
const double entered = QgsDoubleValidator::toDouble( input, &ok );
if ( ! ok )
{
if ( regularExpression().match( input ).captured( 0 ) == input )
Expand All @@ -80,20 +80,20 @@ QValidator::State QgsDoubleValidator::validate( QString &input, int & ) const
return Invalid;
}

if ( entered >= b && entered <= t && regularExpression().match( input ).captured( 0 ) == input )
if ( entered >= mMinimum && entered <= mMaximum && regularExpression().match( input ).captured( 0 ) == input )
return Acceptable;
else
return Intermediate;
}

QValidator::State QgsDoubleValidator::validate( QString input ) const
QValidator::State QgsDoubleValidator::validate( QString &input ) const
{
if ( input.isEmpty() )
return Intermediate;


bool ok = false;
double entered = QgsDoubleValidator::toDouble( input, &ok );
const double entered = QgsDoubleValidator::toDouble( input, &ok );
if ( ! ok )
{
if ( regularExpression().match( input ).captured( 0 ) == input )
Expand All @@ -102,13 +102,13 @@ QValidator::State QgsDoubleValidator::validate( QString input ) const
return Invalid;
}

if ( entered >= b && entered <= t && regularExpression().match( input ).captured( 0 ) == input )
if ( entered >= mMinimum && entered <= mMaximum && regularExpression().match( input ).captured( 0 ) == input )
return Acceptable;
else
return Intermediate;
}

double QgsDoubleValidator::toDouble( QString input )
double QgsDoubleValidator::toDouble( const QString &input )
{
bool ok = false;
double value = QLocale().toDouble( input, &ok );
Expand All @@ -119,7 +119,7 @@ double QgsDoubleValidator::toDouble( QString input )
return value;
}

double QgsDoubleValidator::toDouble( QString input, bool *ok )
double QgsDoubleValidator::toDouble( const QString &input, bool *ok )
{
double value = QLocale().toDouble( input, ok );

Expand Down

0 comments on commit 887d544

Please sign in to comment.