36 : QValidator( parent )
38 , mDefaultValue( defaultValue )
39 , mDateFormat( dateFormat )
41 switch ( mField.
type() )
43 case QMetaType::Type::Int:
47 const QString re = QStringLiteral(
"-?\\d{0,%1}" ).arg( mField.
length() );
48 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
52 mValidator =
new QIntValidator( parent );
57 case QMetaType::Type::Double:
63 if ( QLocale().decimalPoint() !=
'.' )
65 re = QStringLiteral(
"-?\\d{0,%1}([\\.%2]\\d{0,%3})?" ).arg( mField.
length() - mField.
precision() ).arg( QLocale().decimalPoint() ).arg( mField.
precision() );
69 re = QStringLiteral(
"-?\\d{0,%1}([\\.,]\\d{0,%2})?" ).arg( mField.
length() - mField.
precision() ).arg( mField.
precision() );
71 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
75 const QString re = QStringLiteral(
"-?\\d{0,%1}" ).arg( mField.
length() );
76 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
82 if ( QLocale().decimalPoint() !=
'.' )
84 re = QStringLiteral(
"-?\\d*([\\.%1]\\d{0,%2})?" ).arg( QLocale().decimalPoint(), mField.
precision() );
88 re = QStringLiteral(
"-?\\d*([\\.]\\d{0,%1})?" ).arg( mField.
precision() );
90 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
94 mValidator =
new QDoubleValidator( parent );
99 case QMetaType::Type::LongLong:
104 mValidator =
nullptr;
118 if ( s.isEmpty() && ( mField.
type() == QMetaType::Type::Double || mField.
type() == QMetaType::Type::Int || mField.
type() == QMetaType::Type::LongLong || mField.
type() == QMetaType::Type::QDate ) )
123 if ( s == mDefaultValue )
129 const QValidator::State result = mValidator->validate( s, i );
132 else if ( mField.
type() == QMetaType::Type::QString )
134 if ( s == mNullValue )
138 if ( mField.
length() > 0 && s.size() > mField.
length() )
140 if ( !mNullValue.isEmpty() && !s.isEmpty() && s.size() < mNullValue.size() && s == mNullValue.left( s.size() ) )
143 if ( !mDefaultValue.isEmpty() && !s.isEmpty() && s.size() < mDefaultValue.size() && s == mDefaultValue.left( s.size() ) )
149 else if ( mField.
type() == QMetaType::Type::QDate )
151 return QDate::fromString( s, mDateFormat ).isValid() ? Acceptable : Intermediate;
153 else if ( mField.
type() == QMetaType::Type::QVariantMap )
157 else if ( mField.
type() == QMetaType::Type::User && mField.
typeName().compare( QLatin1String(
"geometry" ), Qt::CaseInsensitive ) == 0 )
164 QStringLiteral(
"unsupported type %1 (%2) for validation" )
165 .arg( mField.
type() )