Back to index

salome-gui  6.5.0
QtxValidator.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File:      QtxValidator.cxx
00021 // Author:    Alexandre SOLOVYOV
00022 //
00023 #include "QtxValidator.h"
00024 
00034 QtxIntValidator::QtxIntValidator( QObject* parent )
00035 : QIntValidator( parent )
00036 {
00037 }
00038 
00045 QtxIntValidator::QtxIntValidator( const int bot, const int top, QObject* parent )
00046 : QIntValidator( bot, top, parent )
00047 {
00048 }
00049 
00053 QtxIntValidator::~QtxIntValidator()
00054 {
00055 }
00056 
00066 void QtxIntValidator::fixup( QString& str ) const
00067 {
00068   bool ok = false;
00069   int i = str.toInt( &ok );
00070   if ( ok )
00071   {
00072     if ( i < bottom() )
00073       str = QString::number( bottom() );
00074     else if( i > top() )
00075       str = QString::number( top() );
00076   }
00077   else
00078     str = QString ( "0" );
00079 }
00080 
00090 QtxDoubleValidator::QtxDoubleValidator( QObject* parent )
00091 : QDoubleValidator( parent )
00092 {
00093 }
00094 
00102 QtxDoubleValidator::QtxDoubleValidator( const double bot, const double top,
00103                                         const int dec, QObject* parent )
00104 : QDoubleValidator( bot, top, dec, parent )
00105 {
00106 }
00107 
00111 QtxDoubleValidator::~QtxDoubleValidator()
00112 {
00113 }
00114 
00124 void QtxDoubleValidator::fixup( QString& str ) const
00125 {
00126   bool ok = false;
00127   double d = str.toDouble( &ok );
00128   if ( ok )
00129   {
00130     if ( d < bottom() )
00131       str = QString::number( bottom() );
00132     else if ( d > top() )
00133       str = QString::number( top() );
00134   }
00135   else
00136     str = QString( "0" );
00137 }