23 #include <QRegExpValidator>
33 : QValidator( parent )
35 , mDateFormat( dateFormat )
37 switch ( mField.
type() )
43 QString re = QString(
"-?\\d{0,%1}" ).arg( mField.
length() );
44 mValidator =
new QRegExpValidator( QRegExp( re ), parent );
48 mValidator =
new QIntValidator( parent );
53 case QVariant::Double:
57 QString re = QString(
"-?\\d{0,%1}(\\.\\d{0,%2})?" ).arg( mField.
length() - mField.
precision() ).arg( mField.
precision() );
58 mValidator =
new QRegExpValidator( QRegExp( re ), parent );
62 QString re = QString(
"-?\\d{0,%1}" ).arg( mField.
length() );
63 mValidator =
new QRegExpValidator( QRegExp( re ), parent );
67 QString re = QString(
"-?\\d*(\\.\\d{0,%1})?" ).arg( mField.
precision() );
68 mValidator =
new QRegExpValidator( QRegExp( re ), parent );
72 mValidator =
new QDoubleValidator( parent );
77 case QVariant::LongLong :
86 mNullValue = settings.value(
"qgis/nullValue",
"NULL" ).toString();
98 ( mField.
type() == QVariant::Double
99 || mField.
type() == QVariant::Int
100 || mField.
type() == QVariant::LongLong
101 || mField.
type() == QVariant::Date
111 QValidator::State result = mValidator->validate( s, i );
114 else if ( mField.
type() == QVariant::String )
118 if ( mNullValue.size() > 0 &&
120 s.size() < mNullValue.size() &&
121 s == mNullValue.left( s.size() ) )
124 if ( s == mNullValue )
127 if ( mField.
length() > 0 && s.size() > mField.
length() )
130 else if ( mField.
type() == QVariant::Date )
132 return QDate::fromString( s, mDateFormat ).isValid() ? Acceptable : Intermediate;
136 QgsDebugMsg( QString(
"unsupported type %1 for validation" ).arg( mField.
type() ) );
147 mValidator->fixup( s );
149 else if ( mField.
type() == QVariant::String && mField.
length() > 0 && s.size() > mField.
length() )
154 else if ( mField.
type() == QVariant::Date )