40 : QValidator( parent )
42 , mDefaultValue( defaultValue )
45 switch ( mField.type() )
47 case QMetaType::Type::Int:
49 if ( mField.length() > 0 )
51 const QString re = u
"-?\\d{0,%1}"_s.arg( mField.length() );
52 mValidator = new QRegularExpressionValidator( QRegularExpression( re ), parent );
56 mValidator = new QIntValidator( parent );
61 case QMetaType::Type::Double:
63 if ( mField.length() > 0 && mField.precision() > 0 )
67 if ( QLocale().decimalPoint() !=
'.' )
69 re = u
"-?\\d{0,%1}([\\.%2]\\d{0,%3})?"_s.arg( mField.length() - mField.precision() ).arg( QLocale().decimalPoint() ).arg( mField.precision() );
73 re = u
"-?\\d{0,%1}([\\.,]\\d{0,%2})?"_s.arg( mField.length() - mField.precision() ).arg( mField.precision() );
75 mValidator = new QRegularExpressionValidator( QRegularExpression( re ), parent );
77 else if ( mField.length() > 0 && mField.precision() == 0 )
79 const QString re = u
"-?\\d{0,%1}"_s.arg( mField.length() );
80 mValidator = new QRegularExpressionValidator( QRegularExpression( re ), parent );
82 else if ( mField.precision() > 0 )
86 if ( QLocale().decimalPoint() !=
'.' )
88 re = u
"-?\\d*([\\.%1]\\d{0,%2})?"_s.arg( QLocale().decimalPoint(), mField.precision() );
92 re = u
"-?\\d*([\\.]\\d{0,%1})?"_s.arg( mField.precision() );
94 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
98 mValidator =
new QDoubleValidator( parent );
103 case QMetaType::Type::LongLong:
108 mValidator =
nullptr;
120 if ( s.isEmpty() && ( mField.type() == QMetaType::Type::Double || mField.type() == QMetaType::Type::Int || mField.type() == QMetaType::Type::LongLong || mField.type() == QMetaType::Type::QDate ) )
125 if ( s == mDefaultValue )
131 const QValidator::State result = mValidator->validate( s, i );
134 else if ( mField.type() == QMetaType::Type::QString )
136 if ( s == mNullValue )
140 if ( mField.length() > 0 && s.size() > mField.length() )
142 if ( !mNullValue.isEmpty() && !s.isEmpty() && s.size() < mNullValue.size() && s == mNullValue.left( s.size() ) )
145 if ( !mDefaultValue.isEmpty() && !s.isEmpty() && s.size() < mDefaultValue.size() && s == mDefaultValue.left( s.size() ) )
151 else if ( mField.type() == QMetaType::Type::QDate )
153 return QDate::fromString( s, mDateFormat ).isValid() ? Acceptable : Intermediate;
155 else if ( mField.type() == QMetaType::Type::QVariantMap )
159 else if ( mField.type() == QMetaType::Type::User && mField.typeName().compare(
"geometry"_L1, Qt::CaseInsensitive ) == 0 )
165 QgsDebugError( u
"unsupported type %1 (%2) for validation"_s.arg( mField.type() ).arg( mField.typeName() ) );