1 // Copyright (C) 2007-2023 CEA, EDF, 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, or (at your option) any later version.
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
23 #include "QDS_Validator.h"
26 \class QDS_IntegerValidator
27 \brief A validator for integer values.
29 This class provides validation of the strings entered by the user for datum with 'Integer'
30 value type according to datum properties: minimum value, maximum value, filter.
32 Inherits QIntValidator.
38 Create empty validator object.
40 \param p parent object
42 QDS_IntegerValidator::QDS_IntegerValidator( QObject* p )
50 Create validator object with filter string \a f.
52 \param f filter string
53 \param p parent object
55 QDS_IntegerValidator::QDS_IntegerValidator( const QString& f, QObject* p )
64 QDS_IntegerValidator::~QDS_IntegerValidator()
69 \brief Validate the entered string \a input.
71 Reimplemented from QIntValidator.
73 Perform standard check by QIntValidator::validate(). If returned state
74 is not \c QValidator::Invalid and filter is specified then perform validation
75 with filter by QRegExpValidator.
77 Returns \c QValidator::Invalid if input is invalid according to this validator's rules,
78 \c QValidator::Intermediate if it is likely that a little more editing will make the
79 input acceptable and \c QValidator::Acceptable if the input is valid.
81 \param input string being validated
82 \param pos cursor position
83 \return validation state (\c QValidator::State)
85 QValidator::State QDS_IntegerValidator::validate( QString& input, int& pos ) const
87 State rgState = Acceptable;
88 State ivState = QIntValidator::validate( input, pos );
89 if ( ivState != Invalid && !myFilter.isEmpty() )
90 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
92 ivState = qMin( ivState, rgState );
98 \class QDS_DoubleValidator
99 \brief A validator for floating point values.
101 This class provides validation of the strings entered by the user for datum with 'Float'
102 value type according to datum properties: minimum value, maximum value, precision, filter.
104 Inherits QDoubleValidator.
110 Create empty validator object.
112 \param p parent object
114 QDS_DoubleValidator::QDS_DoubleValidator( QObject* p )
115 : QDoubleValidator( p )
122 Create validator object with filter string \a f.
124 \param f filter string
125 \param p parent object
127 QDS_DoubleValidator::QDS_DoubleValidator( const QString& f, QObject* p )
128 : QDoubleValidator( p ),
136 QDS_DoubleValidator::~QDS_DoubleValidator()
141 \brief Validate the entered string \a input.
143 Reimplemented from QDoubleValidator.
145 Perform standard check by QDoubleValidator::validate(). If returned state
146 is not \c QValidator::Invalid and filter is specified then perform validation
147 with filter by QRegExpValidator.
149 Returns \c QValidator::Invalid if input is invalid according to this validator's rules,
150 \c QValidator::Intermediate if it is likely that a little more editing will make the
151 input acceptable and \c QValidator::Acceptable if the input is valid.
153 \param input string being validated
154 \param pos cursor position
155 \return validation state (\c QValidator::State)
157 QValidator::State QDS_DoubleValidator::validate( QString& input, int& pos ) const
159 State rgState = Acceptable;
160 State dvState = QDoubleValidator::validate( input, pos );
161 if ( dvState != Invalid && !myFilter.isEmpty() )
162 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
164 dvState = qMin( dvState, rgState );
170 \class QDS_StringValidator
171 \brief A validator for string values.
173 This class provides validation of the strings entered by the user for datum with 'String'
174 value type according to datum properties: format, filter.
176 Inherits from QValidator.
182 Create empty validator object.
184 \param p parent object
186 QDS_StringValidator::QDS_StringValidator( QObject* p )
195 Create validator object with filter string \a f.
197 \param f filter string
198 \param p parent object
200 QDS_StringValidator::QDS_StringValidator( const QString& f, QObject* p )
210 Create validator object with filter string \a ft and format flags \a fg.
211 \param ft filter string
212 \param fg format string
213 \param p parent object
215 QDS_StringValidator::QDS_StringValidator( const QString& ft, const QString& fg, QObject* p )
226 QDS_StringValidator::~QDS_StringValidator()
231 \brief Get maximum valid string length.
233 If maximum length is not specified, -1 is returned.
235 \return maximum string length
237 int QDS_StringValidator::length() const
243 \brief Set maximum valid string length.
245 If l <= 0 is not specified, maximum valid length is reset
246 (any string length is valid).
248 \param l maximum strin length
250 void QDS_StringValidator::setLength( const int l )
256 \brief Validate the entered string \a input.
258 Reimplemented from QValidator.
260 Convert specified string to the upper/lower case if the format flags contains
261 specificator 'u'/'l' correspondingly. If valid string length is specified,
262 then check given string length. If filter is specified, then perform also
263 validation with filter by QRegExpValidator.
265 Returns \c QValidator::Invalid if input is invalid according to this validator's rules,
266 \c QValidator::Intermediate if it is likely that a little more editing will make the
267 input acceptable and \c QValidator::Acceptable if the input is valid.
269 \param input string being validated
270 \param pos cursor position
271 \return validation state (\c QValidator::State)
273 QValidator::State QDS_StringValidator::validate( QString& input, int& pos ) const
275 if ( input.isEmpty() )
278 QString orig = input;
279 if ( myFlags.contains( 'u', Qt::CaseInsensitive ) )
280 input = input.toUpper();
281 if ( myFlags.contains( 'l', Qt::CaseInsensitive ) )
282 input = input.toLower();
284 State rgState = Acceptable;
285 State svState = orig == input ? Acceptable : Intermediate;
287 if ( myLen >= 0 && (int)input.length() > myLen )
288 svState = Intermediate;
290 if ( !myFilter.isEmpty() )
291 rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
293 svState = qMin( svState, rgState );