21#include <QRegularExpressionValidator>
22#include <QRegularExpression>
28const QString
PERMISSIVE_DOUBLE = R
"(-?[\d]{0,1000}([\.%1][\d]{0,1000})?(e[+-]?[\d]{0,%2})?)";
31 : QRegularExpressionValidator( parent )
32 , mMinimum( std::numeric_limits<qreal>::lowest() )
33 , mMaximum( std::numeric_limits<qreal>::max() )
36 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( 1000 ) );
37 setRegularExpression( reg );
41 : QRegularExpressionValidator( parent )
45 setRegularExpression( expression );
49 : QRegularExpressionValidator( parent )
54 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( 1000 ) );
55 setRegularExpression( reg );
59 : QRegularExpressionValidator( parent )
64 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( QString::number( decimal ) ) );
65 setRegularExpression( reg );
69 : QRegularExpressionValidator( parent )
70 , mMinimum( std::numeric_limits<qreal>::lowest() )
71 , mMaximum( std::numeric_limits<qreal>::max() )
74 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( QString::number( decimal ) ) );
75 setRegularExpression( reg );
80 const QRegularExpression reg(
PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( QString::number( maxDecimals ) ) );
81 setRegularExpression( reg );
86 if ( input.isEmpty() )
94 if ( regularExpression().match( input ).captured( 0 ) == input )
100 if ( entered >= mMinimum && entered <= mMaximum && regularExpression().match( input ).captured( 0 ) == input )
108 if ( input.isEmpty() )
116 if ( regularExpression().match( input ).captured( 0 ) == input )
122 if ( entered >= mMinimum && entered <= mMaximum && regularExpression().match( input ).captured( 0 ) == input )
136 double value = QLocale().toDouble( input, ok );
140 value = QLocale( QLocale::C ).toDouble( input, ok );
143 if ( ! *ok && !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
145 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.
QValidator::State validate(QString &input, int &) const override
void setMaxDecimals(int maxDecimals)
Sets the number of decimals accepted by the validator to maxDecimals.
const QString PERMISSIVE_DOUBLE