Back to index

salome-gui  6.5.0
QDS_Validator.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "QDS_Validator.h"
00024 
00042 QDS_IntegerValidator::QDS_IntegerValidator( QObject* p )
00043 : QIntValidator( p )
00044 {
00045 }
00046 
00055 QDS_IntegerValidator::QDS_IntegerValidator( const QString& f, QObject* p )
00056 : QIntValidator( p ),
00057   myFilter( f )
00058 {
00059 }
00060 
00064 QDS_IntegerValidator::~QDS_IntegerValidator()
00065 {
00066 }
00067 
00085 QValidator::State QDS_IntegerValidator::validate( QString& input, int& pos ) const
00086 {
00087   State rgState = Acceptable;
00088   State ivState = QIntValidator::validate( input, pos );
00089   if ( ivState != Invalid && !myFilter.isEmpty() )
00090     rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
00091 
00092   ivState = qMin( ivState, rgState );
00093 
00094   return ivState;
00095 }
00096 
00114 QDS_DoubleValidator::QDS_DoubleValidator( QObject* p )
00115 : QDoubleValidator( p )
00116 {
00117 }
00118 
00127 QDS_DoubleValidator::QDS_DoubleValidator( const QString& f, QObject* p )
00128 : QDoubleValidator( p ),
00129   myFilter( f )
00130 {
00131 }
00132 
00136 QDS_DoubleValidator::~QDS_DoubleValidator()
00137 {
00138 }
00139 
00157 QValidator::State QDS_DoubleValidator::validate( QString& input, int& pos ) const
00158 {
00159   State rgState = Acceptable;
00160   State dvState = QDoubleValidator::validate( input, pos );
00161   if ( dvState != Invalid && !myFilter.isEmpty() )
00162     rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
00163 
00164   dvState = qMin( dvState, rgState );
00165 
00166   return dvState;
00167 }
00168 
00186 QDS_StringValidator::QDS_StringValidator( QObject* p ) 
00187 : QValidator( p ), 
00188   myLen( -1 ) 
00189 {
00190 }
00191 
00200 QDS_StringValidator::QDS_StringValidator( const QString& f, QObject* p ) 
00201 : QValidator( p ), 
00202   myFlags( f ), 
00203   myLen( -1 ) 
00204 {
00205 }
00206 
00215 QDS_StringValidator::QDS_StringValidator( const QString& ft, const QString& fg, QObject* p ) 
00216 : QValidator( p ), 
00217   myLen( -1 ), 
00218   myFilter( ft ), 
00219   myFlags( fg ) 
00220 {
00221 }
00222 
00226 QDS_StringValidator::~QDS_StringValidator() 
00227 {
00228 }
00229 
00237 int QDS_StringValidator::length() const 
00238 { 
00239   return myLen; 
00240 }
00241 
00250 void QDS_StringValidator::setLength( const int l )
00251 {
00252   myLen = l;
00253 }
00254 
00273 QValidator::State QDS_StringValidator::validate( QString& input, int& pos ) const
00274 {
00275   if ( input.isEmpty() )
00276     return Acceptable;
00277 
00278   QString orig = input;
00279   if ( myFlags.contains( 'u', Qt::CaseInsensitive ) )
00280     input = input.toUpper();
00281   if ( myFlags.contains( 'l', Qt::CaseInsensitive ) )
00282     input = input.toLower();
00283 
00284   State rgState = Acceptable;
00285   State svState = orig == input ? Acceptable : Intermediate;
00286 
00287   if ( myLen >= 0 && (int)input.length() > myLen )
00288       svState = Intermediate;
00289 
00290   if ( !myFilter.isEmpty() )
00291     rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos );
00292 
00293   svState = qMin( svState, rgState );
00294 
00295   return svState;
00296 }