]> SALOME platform Git repositories - modules/gui.git/blob - src/Qtx/QtxValidator.cxx
Salome HOME
6529d9e2df7deb0b285521d9e9141cd42eee090b
[modules/gui.git] / src / Qtx / QtxValidator.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      QtxValidator.cxx
23 // Author:    Alexandre SOLOVYOV
24 //
25 #include "QtxValidator.h"
26
27 /*!
28   \class QtxIntValidator
29   \brief Validator for integer numbers with possibility to fix up the invalid value.
30 */
31
32 /*!
33   \brief Constructor.
34   \param parent parent object
35 */
36 QtxIntValidator::QtxIntValidator( QObject* parent )
37 : QIntValidator( parent )
38 {
39 }
40
41 /*!
42   \brief Constructor.
43   \param bot minimum possible value
44   \param top maximum possible value
45   \param parent parent object
46 */
47 QtxIntValidator::QtxIntValidator( const int bot, const int top, QObject* parent )
48 : QIntValidator( bot, top, parent )
49 {
50 }
51
52 /*!
53   \brief Destructor.
54 */
55 QtxIntValidator::~QtxIntValidator()
56 {
57 }
58
59 /*!
60   \brief Validate the input and fixup it if necessary.
61
62   If the string represents integer value less then minimum value, it becomes equal to the minimum.
63   if the string represents integer value more then mazimum value, it becomes equal to the maximum.
64   If the string is not evaluated as integer it becomes equal to \c 0.
65
66   \param str the string to be validated
67 */
68 void QtxIntValidator::fixup( QString& str ) const
69 {
70   bool ok = false;
71   int i = str.toInt( &ok );
72   if ( ok )
73   {
74     if ( i < bottom() )
75       str = QString::number( bottom() );
76     else if( i > top() )
77       str = QString::number( top() );
78   }
79   else
80     str = QString ( "0" );
81 }
82
83 /*!
84   \class QtxDoubleValidator
85   \brief Validator for double numbers with possibility to fix up the invalid value.
86 */
87
88 /*!
89   \brief Constructor
90   \param parent parent object
91 */
92 QtxDoubleValidator::QtxDoubleValidator( QObject* parent )
93 : QDoubleValidator( parent )
94 {
95 }
96
97 /*!
98   \brief Constructor.
99   \param bot minimum possible value
100   \param top maximum possible value
101   \param dec precision (number of digits after dot)
102   \param parent parent object
103 */
104 QtxDoubleValidator::QtxDoubleValidator( const double bot, const double top,
105                                         const int dec, QObject* parent )
106 : QDoubleValidator( bot, top, dec, parent )
107 {
108 }
109
110 /*!
111   \brief Destructor.
112 */
113 QtxDoubleValidator::~QtxDoubleValidator()
114 {
115 }
116
117 /*!
118   \brief Validate the input and fixup it if necessary.
119
120   If the string represents double value less then minimum value, it becomes equal to the minimum.
121   if the string represents double value more then mazimum value, it becomes equal to the maximum.
122   If the string is not evaluated as double it becomes equal to \c 0.
123
124   \param str the string to be validated
125 */
126 void QtxDoubleValidator::fixup( QString& str ) const
127 {
128   bool ok = false;
129   double d = str.toDouble( &ok );
130   if ( ok )
131   {
132     if ( d < bottom() )
133       str = QString::number( bottom() );
134     else if ( d > top() )
135       str = QString::number( top() );
136   }
137   else
138     str = QString( "0" );
139 }