1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: QtxValidator.cxx
21 // Author: Alexandre SOLOVYOV
23 #include "QtxValidator.h"
26 \class QtxIntValidator
27 \brief Validator for integer numbers with possibility to fix up the invalid value.
32 \param parent parent object
34 QtxIntValidator::QtxIntValidator( QObject* parent )
35 : QIntValidator( parent )
41 \param bot minimum possible value
42 \param top maximum possible value
43 \param parent parent object
45 QtxIntValidator::QtxIntValidator( const int bot, const int top, QObject* parent )
46 : QIntValidator( bot, top, parent )
53 QtxIntValidator::~QtxIntValidator()
58 \brief Validate the input and fixup it if necessary.
60 If the string represents integer value less then minimum value, it becomes equal to the minimum.
61 if the string represents integer value more then mazimum value, it becomes equal to the maximum.
62 If the string is not evaluated as integer it becomes equal to \c 0.
64 \param str the string to be validated
66 void QtxIntValidator::fixup( QString& str ) const
69 int i = str.toInt( &ok );
73 str = QString::number( bottom() );
75 str = QString::number( top() );
78 str = QString ( "0" );
82 \class QtxDoubleValidator
83 \brief Validator for double numbers with possibility to fix up the invalid value.
88 \param parent parent object
90 QtxDoubleValidator::QtxDoubleValidator( QObject* parent )
91 : QDoubleValidator( parent )
97 \param bot minimum possible value
98 \param top maximum possible value
99 \param dec precision (number of digits after dot)
100 \param parent parent object
102 QtxDoubleValidator::QtxDoubleValidator( const double bot, const double top,
103 const int dec, QObject* parent )
104 : QDoubleValidator( bot, top, dec, parent )
111 QtxDoubleValidator::~QtxDoubleValidator()
116 \brief Validate the input and fixup it if necessary.
118 If the string represents double value less then minimum value, it becomes equal to the minimum.
119 if the string represents double value more then mazimum value, it becomes equal to the maximum.
120 If the string is not evaluated as double it becomes equal to \c 0.
122 \param str the string to be validated
124 void QtxDoubleValidator::fixup( QString& str ) const
127 double d = str.toDouble( &ok );
131 str = QString::number( bottom() );
132 else if ( d > top() )
133 str = QString::number( top() );
136 str = QString( "0" );