35 : QValidator( parent )
37 , mDefaultValue( defaultValue )
38 , mDateFormat( dateFormat )
40 switch ( mField.
type() )
42 case QMetaType::Type::Int:
46 const QString re = QStringLiteral(
"-?\\d{0,%1}" ).arg( mField.
length() );
47 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
51 mValidator =
new QIntValidator( parent );
56 case QMetaType::Type::Double:
62 if ( QLocale().decimalPoint() !=
'.' )
64 re = QStringLiteral(
"-?\\d{0,%1}([\\.%2]\\d{0,%3})?" ).arg( mField.
length() - mField.
precision() ).arg( QLocale().decimalPoint() ).arg( mField.
precision() );
68 re = QStringLiteral(
"-?\\d{0,%1}([\\.,]\\d{0,%2})?" ).arg( mField.
length() - mField.
precision() ).arg( mField.
precision() );
70 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
74 const QString re = QStringLiteral(
"-?\\d{0,%1}" ).arg( mField.
length() );
75 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
81 if ( QLocale().decimalPoint() !=
'.' )
83 re = QStringLiteral(
"-?\\d*([\\.%1]\\d{0,%2})?" ).arg( QLocale().decimalPoint(), mField.
precision() );
87 re = QStringLiteral(
"-?\\d*([\\.]\\d{0,%1})?" ).arg( mField.
precision() );
89 mValidator =
new QRegularExpressionValidator( QRegularExpression( re ), parent );
93 mValidator =
new QDoubleValidator( parent );
98 case QMetaType::Type::LongLong :
103 mValidator =
nullptr;
118 ( mField.
type() == QMetaType::Type::Double
119 || mField.
type() == QMetaType::Type::Int
120 || mField.
type() == QMetaType::Type::LongLong
121 || mField.
type() == QMetaType::Type::QDate
128 if ( s == mDefaultValue )
134 const QValidator::State result = mValidator->validate( s, i );
137 else if ( mField.
type() == QMetaType::Type::QString )
139 if ( s == mNullValue )
143 if ( mField.
length() > 0 && s.size() > mField.
length() )
145 if ( !mNullValue.isEmpty() && !s.isEmpty() && s.size() < mNullValue.size() && s == mNullValue.left( s.size() ) )
148 if ( !mDefaultValue.isEmpty() && !s.isEmpty() && s.size() < mDefaultValue.size() && s == mDefaultValue.left( s.size() ) )
154 else if ( mField.
type() == QMetaType::Type::QDate )
156 return QDate::fromString( s, mDateFormat ).isValid() ? Acceptable : Intermediate;
158 else if ( mField.
type() == QMetaType::Type::QVariantMap )
162 else if ( mField.
type() == QMetaType::Type::User && mField.
typeName().compare( QLatin1String(
"geometry" ), Qt::CaseInsensitive ) == 0 )
169 QStringLiteral(
"unsupported type %1 (%2) for validation" )
170 .arg( mField.
type() )