1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "QDS_Validator.h"
25 \class QDS_IntegerValidator
26 \brief A validator for integer values.
28 This class provides validation of the strings entered by the user for datum with 'Integer'
29 value type according to datum properties: minimum value, maximum value, filter.
31 Inherits QIntValidator.
37 Create empty validator object.
39 \param p parent object
41 QDS_IntegerValidator::QDS_IntegerValidator( QObject* p )
49 Create validator object with filter string \a f.
51 \param f filter string
52 \param p parent object
54 QDS_IntegerValidator::QDS_IntegerValidator( const QString& f, QObject* p )
63 QDS_IntegerValidator::~QDS_IntegerValidator()
68 \brief Validate the entered string \a input.
70 Reimplemented from QIntValidator.
72 Perform standard check by QIntValidator::validate(). If returned state
73 is not \c QValidator::Invalid and filter is specified then perform validation
74 with filter by QRegExpValidator.
76 Returns \c QValidator::Invalid if input is invalid according to this validator's rules,
77 \c QValidator::Intermediate if it is likely that a little more editing will make the
78 input acceptable and \c QValidator::Acceptable if the input is valid.
80 \param input string being validated
81 \param pos cursor position
82 \return validation state (\c QValidator::State)
84 QValidator::State QDS_IntegerValidator::validate( QString& input, int& pos ) const
86 State rgState = Acceptable;
87 State ivState = QIntValidator::validate( input, pos );
88 if ( ivState != Invalid && !myFilter.isEmpty() )
89 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
91 ivState = qMin( ivState, rgState );
97 \class QDS_DoubleValidator
98 \brief A validator for floating point values.
100 This class provides validation of the strings entered by the user for datum with 'Float'
101 value type according to datum properties: minimum value, maximum value, precision, filter.
103 Inherits QDoubleValidator.
109 Create empty validator object.
111 \param p parent object
113 QDS_DoubleValidator::QDS_DoubleValidator( QObject* p )
114 : QDoubleValidator( p )
121 Create validator object with filter string \a f.
123 \param f filter string
124 \param p parent object
126 QDS_DoubleValidator::QDS_DoubleValidator( const QString& f, QObject* p )
127 : QDoubleValidator( p ),
135 QDS_DoubleValidator::~QDS_DoubleValidator()
140 \brief Validate the entered string \a input.
142 Reimplemented from QDoubleValidator.
144 Perform standard check by QDoubleValidator::validate(). If returned state
145 is not \c QValidator::Invalid and filter is specified then perform validation
146 with filter by QRegExpValidator.
148 Returns \c QValidator::Invalid if input is invalid according to this validator's rules,
149 \c QValidator::Intermediate if it is likely that a little more editing will make the
150 input acceptable and \c QValidator::Acceptable if the input is valid.
152 \param input string being validated
153 \param pos cursor position
154 \return validation state (\c QValidator::State)
156 QValidator::State QDS_DoubleValidator::validate( QString& input, int& pos ) const
158 State rgState = Acceptable;
159 State dvState = QDoubleValidator::validate( input, pos );
160 if ( dvState != Invalid && !myFilter.isEmpty() )
161 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
163 dvState = qMin( dvState, rgState );
169 \class QDS_StringValidator
170 \brief A validator for string values.
172 This class provides validation of the strings entered by the user for datum with 'String'
173 value type according to datum properties: format, filter.
175 Inherits from QValidator.
181 Create empty validator object.
183 \param p parent object
185 QDS_StringValidator::QDS_StringValidator( QObject* p )
194 Create validator object with filter string \a f.
196 \param f filter string
197 \param p parent object
199 QDS_StringValidator::QDS_StringValidator( const QString& f, QObject* p )
209 Create validator object with filter string \a ft and format flags \a fg.
210 \param ft filter string
211 \param fg format string
212 \param p parent object
214 QDS_StringValidator::QDS_StringValidator( const QString& ft, const QString& fg, QObject* p )
225 QDS_StringValidator::~QDS_StringValidator()
230 \brief Get maximum valid string length.
232 If maximum length is not specified, -1 is returned.
234 \return maximum string length
236 int QDS_StringValidator::length() const
242 \brief Set maximum valid string length.
244 If l <= 0 is not specified, maximum valid length is reset
245 (any string length is valid).
247 \param l maximum strin length
249 void QDS_StringValidator::setLength( const int l )
255 \brief Validate the entered string \a input.
257 Reimplemented from QValidator.
259 Convert specified string to the upper/lower case if the format flags contains
260 specificator 'u'/'l' correspondingly. If valid string length is specified,
261 then check given string length. If filter is specified, then perform also
262 validation with filter by QRegExpValidator.
264 Returns \c QValidator::Invalid if input is invalid according to this validator's rules,
265 \c QValidator::Intermediate if it is likely that a little more editing will make the
266 input acceptable and \c QValidator::Acceptable if the input is valid.
268 \param input string being validated
269 \param pos cursor position
270 \return validation state (\c QValidator::State)
272 QValidator::State QDS_StringValidator::validate( QString& input, int& pos ) const
274 if ( input.isEmpty() )
277 QString orig = input;
278 if ( myFlags.contains( 'u', Qt::CaseInsensitive ) )
279 input = input.toUpper();
280 if ( myFlags.contains( 'l', Qt::CaseInsensitive ) )
281 input = input.toLower();
283 State rgState = Acceptable;
284 State svState = orig == input ? Acceptable : Intermediate;
286 if ( myLen >= 0 && (int)input.length() > myLen )
287 svState = Intermediate;
289 if ( !myFilter.isEmpty() )
290 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
292 svState = qMin( svState, rgState );