Skip to content
Permalink
Browse files

Merge pull request #37136 from SebastienPeillet/several_fix_locale_ra…

…ster_properties

Fix decimal point issues on raster properties forms,  Fixes #33859
  • Loading branch information
elpaso committed Jul 14, 2020
2 parents 5d3201e + 887d544 commit 15a4c3928c26a77509629047edbee14140b39784
@@ -0,0 +1,123 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsdoublevalidator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsDoubleValidator : QRegularExpressionValidator
{
%Docstring

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

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsdoublevalidator.h"
%End
public:

explicit QgsDoubleValidator( QObject *parent );
%Docstring
Constructor for QgsDoubleValidator.
%End

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

: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.

: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 decimal, QObject *parent );
%Docstring
Constructor for QgsDoubleValidator.

: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



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


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

void setBottom( double bottom );
%Docstring
Set top range limit

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

.. seealso:: :py:func:`setRange`
%End

void setTop( double top );
%Docstring
Set top range limit

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

.. seealso:: :py:func:`setRange`
%End

virtual void setRange( double bottom, double top );
%Docstring
Set bottom and top range limits

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

.. seealso:: :py:func:`setTop`
%End

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

.. seealso:: :py:func:`setBottom`
%End

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

.. seealso:: :py:func:`setTop`
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsdoublevalidator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -70,6 +70,7 @@
%Include auto_generated/qgsdial.sip
%Include auto_generated/qgsdialog.sip
%Include auto_generated/qgsdockwidget.sip
%Include auto_generated/qgsdoublevalidator.sip
%Include auto_generated/qgsencodingfiledialog.sip
%Include auto_generated/qgserrordialog.sip
%Include auto_generated/qgsexpressionbuilderdialog.sip
@@ -499,7 +499,7 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRas
int count = histogram.histogramVector.at( idx );
if ( count > 0 )
{
data << Class( currentValue, QColor(), QString::number( currentValue ) );
data << Class( currentValue, QColor(), QLocale().toString( currentValue ) );
presentValues++;
}
currentValue += interval;
@@ -393,6 +393,7 @@ SET(QGIS_GUI_SRCS
qgsdetaileditemwidget.cpp
qgsdial.cpp
qgsdialog.cpp
qgsdoublevalidator.cpp
qgsdockwidget.cpp
qgsencodingfiledialog.cpp
qgserrordialog.cpp
@@ -626,6 +627,7 @@ SET(QGIS_GUI_HDRS
qgsdial.h
qgsdialog.h
qgsdockwidget.h
qgsdoublevalidator.h
qgsencodingfiledialog.h
qgserrordialog.h
qgsexpressionbuilderdialog.h
@@ -0,0 +1,131 @@
/***************************************************************************
qgsdoublevalidator.cpp - description
-------------------
begin : June 2020
copyright : (C) 2020 by Sebastien Peillet
email : sebastien.peillet@oslandia.com
adapted version of Qgslonglongvalidator + QgsFieldValidator
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <limits>
#include <QRegExpValidator>
#include <QLocale>
#include "qgis_gui.h"

#include "qgsdoublevalidator.h"

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

QgsDoubleValidator::QgsDoubleValidator( QObject *parent )
: QRegularExpressionValidator( parent )
, 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 ) );
setRegularExpression( reg );
}

QgsDoubleValidator::QgsDoubleValidator( const QRegularExpression &expression, double bottom, double top, QObject *parent )
: QRegularExpressionValidator( parent )
, mMinimum( bottom )
, mMaximum( top )
{
setRegularExpression( expression );
}

QgsDoubleValidator::QgsDoubleValidator( double bottom, double top, QObject *parent )
: QRegularExpressionValidator( parent )
, 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 ) );
setRegularExpression( reg );
}

QgsDoubleValidator::QgsDoubleValidator( double bottom, double top, int decimal, QObject *parent )
: QRegularExpressionValidator( parent )
, 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( decimal ) ) );
setRegularExpression( reg );
}

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


bool ok = false;
const double entered = QgsDoubleValidator::toDouble( input, &ok );
if ( ! ok )
{
if ( regularExpression().match( input ).captured( 0 ) == input )
return Intermediate;
else
return Invalid;
}

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

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


bool ok = false;
const double entered = QgsDoubleValidator::toDouble( input, &ok );
if ( ! ok )
{
if ( regularExpression().match( input ).captured( 0 ) == input )
return Intermediate;
else
return Invalid;
}

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

double QgsDoubleValidator::toDouble( const QString &input )
{
bool ok = false;
double value = QLocale().toDouble( input, &ok );
if ( ! ok )
{
value = QLocale( QLocale::C ).toDouble( input, &ok );
}
return value;
}

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

if ( ! *ok )
{
value = QLocale( QLocale::C ).toDouble( input, ok );
}
return value ;
}

0 comments on commit 15a4c39

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