X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FQDS%2FQDS_Validator.cxx;h=9ea4300d3d930ea498073130292d233ec18d9b7e;hb=e70f3c39;hp=37b2ea658d1c506bc27308a710b227838323ab98;hpb=f830c97c748d8f8a6a7eccc8e3a58e19066a1181;p=modules%2Fgui.git diff --git a/src/QDS/QDS_Validator.cxx b/src/QDS/QDS_Validator.cxx index 37b2ea658..9ea4300d3 100644 --- a/src/QDS/QDS_Validator.cxx +++ b/src/QDS/QDS_Validator.cxx @@ -1,11 +1,14 @@ -// Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful +// This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. @@ -16,19 +19,25 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "QDS_Validator.h" /*! \class QDS_IntegerValidator + \brief A validator for integer values. - This class to provide validation of user inputted string for datum with 'Integer' + This class provides validation of the strings entered by the user for datum with 'Integer' value type according to datum properties: minimum value, maximum value, filter. - Inherits from QIntValidator. + Inherits QIntValidator. */ /*! - Constructor. Create empty validator object. + \brief Constructor. + + Create empty validator object. + + \param p parent object */ QDS_IntegerValidator::QDS_IntegerValidator( QObject* p ) : QIntValidator( p ) @@ -36,29 +45,42 @@ QDS_IntegerValidator::QDS_IntegerValidator( QObject* p ) } /*! - Constructor. Create validator object with filter string \af. + \brief Constructor. + + Create validator object with filter string \a f. + + \param f filter string + \param p parent object */ QDS_IntegerValidator::QDS_IntegerValidator( const QString& f, QObject* p ) : QIntValidator( p ), -myFilter( f ) + myFilter( f ) { } /*! - Destructor. + \brief Destructor. */ QDS_IntegerValidator::~QDS_IntegerValidator() { } /*! - Validate the inputed string \ainput. Reimplemented from QIntValidator. Perform - standard check by QIntValidator::validate(). If returned state is not Invalid and - filter specified then perform validation with filter by QRegExpValidator. + \brief Validate the entered string \a input. - Returns Invalid if input is invalid according to this validator's rules, - Intermediate if it is likely that a little more editing will make the input acceptable - and Acceptable if the input is valid. + Reimplemented from QIntValidator. + + Perform standard check by QIntValidator::validate(). If returned state + is not \c QValidator::Invalid and filter is specified then perform validation + with filter by QRegExpValidator. + + Returns \c QValidator::Invalid if input is invalid according to this validator's rules, + \c QValidator::Intermediate if it is likely that a little more editing will make the + input acceptable and \c QValidator::Acceptable if the input is valid. + + \param input string being validated + \param pos cursor position + \return validation state (\c QValidator::State) */ QValidator::State QDS_IntegerValidator::validate( QString& input, int& pos ) const { @@ -67,22 +89,27 @@ QValidator::State QDS_IntegerValidator::validate( QString& input, int& pos ) con if ( ivState != Invalid && !myFilter.isEmpty() ) rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos ); - ivState = QMIN( ivState, rgState ); + ivState = qMin( ivState, rgState ); return ivState; } /*! \class QDS_DoubleValidator + \brief A validator for floating point values. - This class to provide validation of user inputted string for datum with 'Float' + This class provides validation of the strings entered by the user for datum with 'Float' value type according to datum properties: minimum value, maximum value, precision, filter. - Inherits from QDoubleValidator. + Inherits QDoubleValidator. */ /*! - Constructor. Create empty validator object. + \brief Constructor. + + Create empty validator object. + + \param p parent object */ QDS_DoubleValidator::QDS_DoubleValidator( QObject* p ) : QDoubleValidator( p ) @@ -90,29 +117,42 @@ QDS_DoubleValidator::QDS_DoubleValidator( QObject* p ) } /*! - Constructor. Create validator object with filter string \af. + \brief Constructor. + + Create validator object with filter string \a f. + + \param f filter string + \param p parent object */ QDS_DoubleValidator::QDS_DoubleValidator( const QString& f, QObject* p ) : QDoubleValidator( p ), -myFilter( f ) + myFilter( f ) { } /*! - Destructor. + \brief Destructor. */ QDS_DoubleValidator::~QDS_DoubleValidator() { } /*! - Validate the inputed string \ainput. Reimplemented from QDoubleValidator. Perform - standard check by QDoubleValidator::validate(). If returned state is not Invalid and - filter specified then perform validation with filter by QRegExpValidator. + \brief Validate the entered string \a input. + + Reimplemented from QDoubleValidator. + + Perform standard check by QDoubleValidator::validate(). If returned state + is not \c QValidator::Invalid and filter is specified then perform validation + with filter by QRegExpValidator. - Returns Invalid if input is invalid according to this validator's rules, - Intermediate if it is likely that a little more editing will make the input acceptable - and Acceptable if the input is valid. + Returns \c QValidator::Invalid if input is invalid according to this validator's rules, + \c QValidator::Intermediate if it is likely that a little more editing will make the + input acceptable and \c QValidator::Acceptable if the input is valid. + + \param input string being validated + \param pos cursor position + \return validation state (\c QValidator::State) */ QValidator::State QDS_DoubleValidator::validate( QString& input, int& pos ) const { @@ -121,59 +161,78 @@ QValidator::State QDS_DoubleValidator::validate( QString& input, int& pos ) cons if ( dvState != Invalid && !myFilter.isEmpty() ) rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos ); - dvState = QMIN( dvState, rgState ); + dvState = qMin( dvState, rgState ); return dvState; } /*! \class QDS_StringValidator + \brief A validator for string values. - This class to provide validation of user inputted string for datum with 'String' + This class provides validation of the strings entered by the user for datum with 'String' value type according to datum properties: format, filter. - Inherits from QDoubleValidator. + Inherits from QValidator. */ /*! - Constructor. Create empty validator object. + \brief Constructor. + + Create empty validator object. + + \param p parent object */ QDS_StringValidator::QDS_StringValidator( QObject* p ) : QValidator( p ), -myLen( -1 ) + myLen( -1 ) { } /*! - Constructor. Create validator object with filter string \af. + \brief Constructor. + + Create validator object with filter string \a f. + + \param f filter string + \param p parent object */ QDS_StringValidator::QDS_StringValidator( const QString& f, QObject* p ) : QValidator( p ), -myFlags( f ), -myLen( -1 ) + myFlags( f ), + myLen( -1 ) { } /*! - Constructor. Create validator object with filter string \aft and format flags \afg. + \brief Constructor. + + Create validator object with filter string \a ft and format flags \a fg. + \param ft filter string + \param fg format string + \param p parent object */ QDS_StringValidator::QDS_StringValidator( const QString& ft, const QString& fg, QObject* p ) : QValidator( p ), -myLen( -1 ), -myFilter( ft ), -myFlags( fg ) + myLen( -1 ), + myFilter( ft ), + myFlags( fg ) { } /*! - Destructor. + \brief Destructor. */ QDS_StringValidator::~QDS_StringValidator() { } /*! - Returns valid string length. If length not specified -1 returned. + \brief Get maximum valid string length. + + If maximum length is not specified, -1 is returned. + + \return maximum string length */ int QDS_StringValidator::length() const { @@ -181,8 +240,12 @@ int QDS_StringValidator::length() const } /*! - Sets the valid string length \al. If value less than zero valid string - length not specified. + \brief Set maximum valid string length. + + If l <= 0 is not specified, maximum valid length is reset + (any string length is valid). + + \param l maximum strin length */ void QDS_StringValidator::setLength( const int l ) { @@ -190,14 +253,22 @@ void QDS_StringValidator::setLength( const int l ) } /*! - Validate the inputed string \ainput. Reimplemented from QValidator. Convert specified - string to upper/lower case if the format flags contains specificator 'u'/'l'. - If valid string lenght is specified then check given string length. If - filter specified then perform validation with filter by QRegExpValidator. - - Returns Invalid if input is invalid according to this validator's rules, - Intermediate if it is likely that a little more editing will make the input acceptable - and Acceptable if the input is valid. + \brief Validate the entered string \a input. + + Reimplemented from QValidator. + + Convert specified string to the upper/lower case if the format flags contains + specificator 'u'/'l' correspondingly. If valid string length is specified, + then check given string length. If filter is specified, then perform also + validation with filter by QRegExpValidator. + + Returns \c QValidator::Invalid if input is invalid according to this validator's rules, + \c QValidator::Intermediate if it is likely that a little more editing will make the + input acceptable and \c QValidator::Acceptable if the input is valid. + + \param input string being validated + \param pos cursor position + \return validation state (\c QValidator::State) */ QValidator::State QDS_StringValidator::validate( QString& input, int& pos ) const { @@ -205,10 +276,10 @@ QValidator::State QDS_StringValidator::validate( QString& input, int& pos ) cons return Acceptable; QString orig = input; - if ( myFlags.contains( 'u', false ) ) - input = input.upper(); - if ( myFlags.contains( 'l', false ) ) - input = input.lower(); + if ( myFlags.contains( 'u', Qt::CaseInsensitive ) ) + input = input.toUpper(); + if ( myFlags.contains( 'l', Qt::CaseInsensitive ) ) + input = input.toLower(); State rgState = Acceptable; State svState = orig == input ? Acceptable : Intermediate; @@ -219,7 +290,7 @@ QValidator::State QDS_StringValidator::validate( QString& input, int& pos ) cons if ( !myFilter.isEmpty() ) rgState = QRegExpValidator( QRegExp( myFilter ), 0 ).validate( input, pos ); - svState = QMIN( svState, rgState ); + svState = qMin( svState, rgState ); return svState; }