37 : QValidator( parent )
39 , mDefaultValue( defaultValue )
42 switch ( mField.type() )
44 case QMetaType::Type::Int:
46 if ( mField.length() > 0 )
48 const QString re = QStringLiteral(
"-?\\d{0,%1}" ).arg( mField.length() );
49 mValidator = new QRegularExpressionValidator( QRegularExpression( re ), parent );
53 mValidator = new QIntValidator( parent );
58 case QMetaType::Type::Double:
60 if ( mField.length() > 0 && mField.precision() > 0 )
64 if ( QLocale().decimalPoint() !=
'.' )
66 re = QStringLiteral(
"-?\\d{0,%1}([\\.%2]\\d{0,%3})?" ).arg( mField.length() - mField.precision() ).arg( QLocale().decimalPoint() ).arg( mField.precision() );
70 re = QStringLiteral(
"-?\\d{0,%1}([\\.,]\\d{0,%2})?" ).arg( mField.length() - mField.precision() ).arg( mField.precision() );
72 mValidator = new QRegularExpressionValidator( QRegularExpression( re ), parent );
74 else if ( mField.length() > 0 && mField.precision() == 0 )
76 const QString re = QStringLiteral(
"-?\\d{0,%1}" ).arg( mField.length() );
77 mValidator = new QRegularExpressionValidator( QRegularExpression( re ), parent );
79 else if ( mField.precision() > 0 )
83 if ( QLocale().decimalPoint() !=
'.' )
85 re = QStringLiteral(
"-?\\d*([\\.%1]\\d{0,%2})?" ).arg( QLocale().decimalPoint(), mField.precision() );
89 re = QStringLiteral(
"-?\\d*([\\.]\\d{0,%1})?" ).arg( mField.precision() );
91 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
95 mValidator =
new QDoubleValidator( parent );
100 case QMetaType::Type::LongLong:
105 mValidator =
nullptr;
119 if ( s.isEmpty() && ( mField.type() == QMetaType::Type::Double || mField.type() == QMetaType::Type::Int || mField.type() == QMetaType::Type::LongLong || mField.type() == QMetaType::Type::QDate ) )
124 if ( s == mDefaultValue )
130 const QValidator::State result = mValidator->validate( s, i );
133 else if ( mField.type() == QMetaType::Type::QString )
135 if ( s == mNullValue )
139 if ( mField.length() > 0 && s.size() > mField.length() )
141 if ( !mNullValue.isEmpty() && !s.isEmpty() && s.size() < mNullValue.size() && s == mNullValue.left( s.size() ) )
144 if ( !mDefaultValue.isEmpty() && !s.isEmpty() && s.size() < mDefaultValue.size() && s == mDefaultValue.left( s.size() ) )
150 else if ( mField.type() == QMetaType::Type::QDate )
152 return QDate::fromString( s, mDateFormat ).isValid() ? Acceptable : Intermediate;
154 else if ( mField.type() == QMetaType::Type::QVariantMap )
158 else if ( mField.type() == QMetaType::Type::User && mField.typeName().compare( QLatin1String(
"geometry" ), Qt::CaseInsensitive ) == 0 )
165 QStringLiteral(
"unsupported type %1 (%2) for validation" )
166 .arg( mField.type() )
167 .arg( mField.typeName() )