Skip to content
Permalink
Browse files

Fix min/lowest and add decimal constructor

  • Loading branch information
elpaso committed Nov 5, 2020
1 parent c96f02f commit 72fe36354a4955ba22f794a66813768faf16a6fc
@@ -28,7 +28,7 @@ const QString PERMISSIVE_DOUBLE = R"(-?[\d]{0,1000}([\.%1][\d]{0,1000})?(e[+-]?[

QgsDoubleValidator::QgsDoubleValidator( QObject *parent )
: QRegularExpressionValidator( parent )
, mMinimum( std::numeric_limits<qreal>::min() )
, mMinimum( std::numeric_limits<qreal>::lowest() )
, mMaximum( std::numeric_limits<qreal>::max() )
{
// The regular expression accept double with point as decimal point but also the locale decimal point
@@ -64,6 +64,16 @@ QgsDoubleValidator::QgsDoubleValidator( double bottom, double top, int decimal,
setRegularExpression( reg );
}

QgsDoubleValidator::QgsDoubleValidator( int decimal, QObject *parent )
: QRegularExpressionValidator( parent )
, mMinimum( std::numeric_limits<qreal>::lowest() )
, 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( QString::number( decimal ) ) );
setRegularExpression( reg );
}

QValidator::State QgsDoubleValidator::validate( QString &input, int & ) const
{
if ( input.isEmpty() )
@@ -70,11 +70,19 @@ class GUI_EXPORT QgsDoubleValidator : public QRegularExpressionValidator
*
* \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
* \param decimal the number of decimals accepted by the validator
* \param parent parent object
*/
QgsDoubleValidator( double bottom, double top, int decimal, QObject *parent );

/**
* Constructor for QgsDoubleValidator.
*
* \param decimal the number of decimals accepted by the validator
* \param parent parent object
* \since QGIS 3.16
*/
QgsDoubleValidator( int decimal, QObject *parent );

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

@@ -0,0 +1,21 @@
/***************************************************************************
qgslocaleawarenumericlineeditdelegate.cpp - QgsLocaleAwareNumericLineEditDelegate
---------------------
begin : 5.11.2020
copyright : (C) 2020 by Alessandro Pasotti
email : elpaso at itopen dot it
***************************************************************************
* *
* 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 "qgslocaleawarenumericlineeditdelegate.h"

QgsLocaleAwareNumericLineEditDelegate::QgsLocaleAwareNumericLineEditDelegate()
{

}
@@ -0,0 +1,26 @@
/***************************************************************************
qgslocaleawarenumericlineeditdelegate.h - QgsLocaleAwareNumericLineEditDelegate
---------------------
begin : 5.11.2020
copyright : (C) 2020 by Alessandro Pasotti
email : elpaso at itopen dot it
***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef QGSLOCALEAWARENUMERICLINEEDITDELEGATE_H
#define QGSLOCALEAWARENUMERICLINEEDITDELEGATE_H


class QgsLocaleAwareNumericLineEditDelegate
{
public:
QgsLocaleAwareNumericLineEditDelegate();
};

#endif // QGSLOCALEAWARENUMERICLINEEDITDELEGATE_H

0 comments on commit 72fe363

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