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;
119 ( mField.
type() == QMetaType::Type::Double
120 || mField.
type() == QMetaType::Type::Int
121 || mField.
type() == QMetaType::Type::LongLong
122 || mField.
type() == QMetaType::Type::QDate
129 if ( s == mDefaultValue )
135 const QValidator::State result = mValidator->validate( s, i );
138 else if ( mField.
type() == QMetaType::Type::QString )
140 if ( s == mNullValue )
144 if ( mField.
length() > 0 && s.size() > mField.
length() )
146 if ( !mNullValue.isEmpty() && !s.isEmpty() && s.size() < mNullValue.size() && s == mNullValue.left( s.size() ) )
149 if ( !mDefaultValue.isEmpty() && !s.isEmpty() && s.size() < mDefaultValue.size() && s == mDefaultValue.left( s.size() ) )
155 else if ( mField.
type() == QMetaType::Type::QDate )
157 return QDate::fromString( s, mDateFormat ).isValid() ? Acceptable : Intermediate;
159 else if ( mField.
type() == QMetaType::Type::QVariantMap )
163 else if ( mField.
type() == QMetaType::Type::User && mField.
typeName().compare( QLatin1String(
"geometry" ), Qt::CaseInsensitive ) == 0 )
170 QStringLiteral(
"unsupported type %1 (%2) for validation" )
171 .arg( mField.
type() )