Skip to content
Permalink
Browse files

fix suggested by reviewers

  • Loading branch information
speillet
speillet committed Jul 14, 2020
1 parent 893bfff commit 887d544309d677937305d554bbbc09e6910780b1
Showing with 68 additions and 93 deletions.
  1. +14 −33 python/gui/auto_generated/qgsdoublevalidator.sip.in
  2. +22 −22 src/gui/qgsdoublevalidator.cpp
  3. +32 −38 src/gui/qgsdoublevalidator.h
@@ -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
@@ -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 );
@@ -87,8 +78,6 @@ Set top range limit
.. seealso:: :py:func:`setTop`

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

.. versionadded:: 3.14
%End

void setTop( double top );
@@ -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 );
@@ -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

};
@@ -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() )
, 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
@@ -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 )
@@ -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 )
@@ -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 );
@@ -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 );

0 comments on commit 887d544

Please sign in to comment.
You can’t perform that action at this time.