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;
122 if ( s.isEmpty() && ( mField.type() == QMetaType::Type::Double || mField.type() == QMetaType::Type::Int || mField.type() == QMetaType::Type::LongLong || mField.type() == QMetaType::Type::QDate ) )
127 if ( s == mDefaultValue )
133 const QValidator::State result = mValidator->validate( s, i );
136 else if ( mField.type() == QMetaType::Type::QString )
138 if ( s == mNullValue )
142 if ( mField.length() > 0 && s.size() > mField.length() )
144 if ( !mNullValue.isEmpty() && !s.isEmpty() && s.size() < mNullValue.size() && s == mNullValue.left( s.size() ) )
147 if ( !mDefaultValue.isEmpty() && !s.isEmpty() && s.size() < mDefaultValue.size() && s == mDefaultValue.left( s.size() ) )
153 else if ( mField.type() == QMetaType::Type::QDate )
155 return QDate::fromString( s, mDateFormat ).isValid() ? Acceptable : Intermediate;
157 else if ( mField.type() == QMetaType::Type::QVariantMap )
161 else if ( mField.type() == QMetaType::Type::User && mField.typeName().compare(
"geometry"_L1, Qt::CaseInsensitive ) == 0 )
168 u
"unsupported type %1 (%2) for validation"_s
169 .arg( mField.type() )
170 .arg( mField.typeName() )