1 // Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "QDS_Validator.h"
22 \class QDS_IntegerValidator
24 This class to provide validation of user inputted string for datum with 'Integer'
25 value type according to datum properties: minimum value, maximum value, filter.
27 Inherits from QIntValidator.
31 Constructor. Create empty validator object.
33 QDS_IntegerValidator::QDS_IntegerValidator( QObject* p )
39 Constructor. Create validator object with filter string \af.
41 QDS_IntegerValidator::QDS_IntegerValidator( const QString& f, QObject* p )
50 QDS_IntegerValidator::~QDS_IntegerValidator()
55 Validate the inputed string \ainput. Reimplemented from QIntValidator. Perform
56 standard check by QIntValidator::validate(). If returned state is not Invalid and
57 filter specified then perform validation with filter by QRegExpValidator.
59 Returns Invalid if input is invalid according to this validator's rules,
60 Intermediate if it is likely that a little more editing will make the input acceptable
61 and Acceptable if the input is valid.
63 QValidator::State QDS_IntegerValidator::validate( QString& input, int& pos ) const
65 State rgState = Acceptable;
66 State ivState = QIntValidator::validate( input, pos );
67 if ( ivState != Invalid && !myFilter.isEmpty() )
68 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
70 ivState = QMIN( ivState, rgState );
76 \class QDS_DoubleValidator
78 This class to provide validation of user inputted string for datum with 'Float'
79 value type according to datum properties: minimum value, maximum value, precision, filter.
81 Inherits from QDoubleValidator.
85 Constructor. Create empty validator object.
87 QDS_DoubleValidator::QDS_DoubleValidator( QObject* p )
88 : QDoubleValidator( p )
93 Constructor. Create validator object with filter string \af.
95 QDS_DoubleValidator::QDS_DoubleValidator( const QString& f, QObject* p )
96 : QDoubleValidator( p ),
104 QDS_DoubleValidator::~QDS_DoubleValidator()
109 Validate the inputed string \ainput. Reimplemented from QDoubleValidator. Perform
110 standard check by QDoubleValidator::validate(). If returned state is not Invalid and
111 filter specified then perform validation with filter by QRegExpValidator.
113 Returns Invalid if input is invalid according to this validator's rules,
114 Intermediate if it is likely that a little more editing will make the input acceptable
115 and Acceptable if the input is valid.
117 QValidator::State QDS_DoubleValidator::validate( QString& input, int& pos ) const
119 State rgState = Acceptable;
120 State dvState = QDoubleValidator::validate( input, pos );
121 if ( dvState != Invalid && !myFilter.isEmpty() )
122 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
124 dvState = QMIN( dvState, rgState );
130 \class QDS_StringValidator
132 This class to provide validation of user inputted string for datum with 'String'
133 value type according to datum properties: format, filter.
135 Inherits from QDoubleValidator.
139 Constructor. Create empty validator object.
141 QDS_StringValidator::QDS_StringValidator( QObject* p )
148 Constructor. Create validator object with filter string \af.
150 QDS_StringValidator::QDS_StringValidator( const QString& f, QObject* p )
158 Constructor. Create validator object with filter string \aft and format flags \afg.
160 QDS_StringValidator::QDS_StringValidator( const QString& ft, const QString& fg, QObject* p )
171 QDS_StringValidator::~QDS_StringValidator()
176 Returns valid string length. If length not specified -1 returned.
178 int QDS_StringValidator::length() const
184 Sets the valid string length \al. If value less than zero valid string
185 length not specified.
187 void QDS_StringValidator::setLength( const int l )
193 Validate the inputed string \ainput. Reimplemented from QValidator. Convert specified
194 string to upper/lower case if the format flags contains specificator 'u'/'l'.
195 If valid string lenght is specified then check given string length. If
196 filter specified then perform validation with filter by QRegExpValidator.
198 Returns Invalid if input is invalid according to this validator's rules,
199 Intermediate if it is likely that a little more editing will make the input acceptable
200 and Acceptable if the input is valid.
202 QValidator::State QDS_StringValidator::validate( QString& input, int& pos ) const
204 if ( input.isEmpty() )
207 QString orig = input;
208 if ( myFlags.contains( 'u', false ) )
209 input = input.upper();
210 if ( myFlags.contains( 'l', false ) )
211 input = input.lower();
213 State rgState = Acceptable;
214 State svState = orig == input ? Acceptable : Intermediate;
216 if ( myLen >= 0 && (int)input.length() > myLen )
217 svState = Intermediate;
219 if ( !myFilter.isEmpty() )
220 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
222 svState = QMIN( svState, rgState );