]> SALOME platform Git repositories - modules/gui.git/blob - src/QDS/QDS_Validator.cxx
Salome HOME
120af3afc36004a527a66c6245a12d2ded0a1884
[modules/gui.git] / src / QDS / QDS_Validator.cxx
1 // Copyright (C) 2005  CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/
18 //
19 #include "QDS_Validator.h"
20
21 /*!
22     Class: QDS_IntegerValidator
23 */
24
25 QDS_IntegerValidator::QDS_IntegerValidator( QObject* p )
26 : QIntValidator( p )
27 {
28 }
29
30 QDS_IntegerValidator::QDS_IntegerValidator( const QString& f, QObject* p )
31 : QIntValidator( p ),
32 myFilter( f )
33 {
34 }
35
36 QDS_IntegerValidator::~QDS_IntegerValidator()
37 {
38 }
39
40 QValidator::State QDS_IntegerValidator::validate( QString& input, int& pos ) const
41 {
42   State rgState = Acceptable;
43   State ivState = QIntValidator::validate( input, pos );
44   if ( ivState != Invalid && !myFilter.isEmpty() )
45     rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
46
47   ivState = QMIN( ivState, rgState );
48
49   return ivState;
50 }
51
52 /*!
53     Class: QDS_DoubleValidator
54 */
55
56 QDS_DoubleValidator::QDS_DoubleValidator( QObject* p )
57 : QDoubleValidator( p )
58 {
59 }
60
61 QDS_DoubleValidator::QDS_DoubleValidator( const QString& f, QObject* p )
62 : QDoubleValidator( p ),
63 myFilter( f )
64 {
65 }
66
67 QDS_DoubleValidator::~QDS_DoubleValidator()
68 {
69 }
70
71 QValidator::State QDS_DoubleValidator::validate( QString& input, int& pos ) const
72 {
73   State rgState = Acceptable;
74   State dvState = QDoubleValidator::validate( input, pos );
75   if ( dvState != Invalid && !myFilter.isEmpty() )
76     rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
77
78   dvState = QMIN( dvState, rgState );
79
80   return dvState;
81 }
82
83 /*!
84     Class: QDS_StringValidator
85 */
86
87 QDS_StringValidator::QDS_StringValidator( QObject* p ) 
88 : QValidator( p ), 
89 myLen( -1 ) 
90 {
91 }
92
93 QDS_StringValidator::QDS_StringValidator( const QString& f, QObject* p ) 
94 : QValidator( p ), 
95 myFlags( f ), 
96 myLen( -1 ) 
97 {
98 }
99
100 QDS_StringValidator::QDS_StringValidator( const QString& ft, const QString& fg, QObject* p ) 
101 : QValidator( p ), 
102 myLen( -1 ), 
103 myFilter( ft ), 
104 myFlags( fg ) 
105 {
106 }
107
108 QDS_StringValidator::~QDS_StringValidator() 
109 {
110 }
111
112 int QDS_StringValidator::length() const 
113
114   return myLen; 
115 }
116
117 void QDS_StringValidator::setLength( const int l ) 
118
119   myLen = l; 
120 }
121
122 QValidator::State QDS_StringValidator::validate( QString& input, int& pos ) const
123 {
124   if ( input.isEmpty() )
125     return Acceptable;
126
127   QString orig = input;
128   if ( myFlags.contains( 'u', false ) )
129     input = input.upper();
130   if ( myFlags.contains( 'l', false ) )
131     input = input.lower();
132
133   State rgState = Acceptable;
134   State svState = orig == input ? Acceptable : Intermediate;
135
136   if ( myLen >= 0 && (int)input.length() > myLen )
137       svState = Intermediate;
138
139   if ( !myFilter.isEmpty() )
140     rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
141
142   svState = QMIN( svState, rgState );
143
144   return svState;
145 }