27#include <QRegularExpression>
28#include <QRegularExpressionValidator>
30#include "moc_qgsdoublevalidator.cpp"
32const QString
PERMISSIVE_DOUBLE = R
"([+\-%3]?[\d]{0,1000}([\.%1][\d]{0,1000})?([eE%4][+\-%3]?[\d]{0,%2})?)";
35 : QRegularExpressionValidator( parent )
36 , mMinimum( std::numeric_limits<qreal>::lowest() )
37 , mMaximum( std::numeric_limits<qreal>::max() )
40 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() ).arg( 1000 ).arg( QLocale().negativeSign() ).arg( QLocale().exponential() ) );
41 setRegularExpression( reg );
45 : QRegularExpressionValidator( parent )
49 setRegularExpression( expression );
53 : QRegularExpressionValidator( parent )
58 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() ).arg( 1000 ).arg( QLocale().negativeSign() ).arg( QLocale().exponential() ) );
59 setRegularExpression( reg );
63 : QRegularExpressionValidator( parent )
68 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() ).arg( QString::number( decimal ) ).arg( QLocale().negativeSign() ).arg( QLocale().exponential() ) );
69 setRegularExpression( reg );
73 : QRegularExpressionValidator( parent )
74 , mMinimum( std::numeric_limits<qreal>::lowest() )
75 , mMaximum( std::numeric_limits<qreal>::max() )
78 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() ).arg( QString::number( decimal ) ).arg( QLocale().negativeSign() ).arg( QLocale().exponential() ) );
79 setRegularExpression( reg );
84 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() ).arg( QString::number( maxDecimals ) ).arg( QLocale().negativeSign() ).arg( QLocale().exponential() ) );
85 setRegularExpression( reg );
90 if ( input.isEmpty() )
98 if ( regularExpression().match( input ).captured( 0 ) == input )
104 if ( entered >= mMinimum && entered <= mMaximum && regularExpression().match( input ).captured( 0 ) == input )
112 if ( input.isEmpty() )
120 if ( regularExpression().match( input ).captured( 0 ) == input )
126 if ( entered >= mMinimum && entered <= mMaximum && regularExpression().match( input ).captured( 0 ) == input )
140 double value = QLocale().toDouble( input, ok );
144 value = QLocale( QLocale::C ).toDouble( input, ok );
147 if ( !*ok && !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
149 value = QLocale().toDouble( QString( input ).replace( QLocale().groupSeparator(), QString() ), ok );
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
QgsDoubleValidator(QObject *parent)
Constructor for QgsDoubleValidator.
double top() const
Returns top range limit.
QValidator::State validate(QString &input, int &) const override
void setMaxDecimals(int maxDecimals)
Sets the number of decimals accepted by the validator to maxDecimals.
double bottom() const
Returns top range limit.
const QString PERMISSIVE_DOUBLE