From 50c9c9171f15bfbf69d56d53b447422a806a7fe7 Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 25 May 2007 09:22:13 +0000 Subject: [PATCH] no message --- src/Qtx/QtxValidator.cxx | 125 +++++++++++++++++++++++++++++++++++++++ src/Qtx/QtxValidator.h | 59 ++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 src/Qtx/QtxValidator.cxx create mode 100644 src/Qtx/QtxValidator.h diff --git a/src/Qtx/QtxValidator.cxx b/src/Qtx/QtxValidator.cxx new file mode 100644 index 000000000..bdc34d2c6 --- /dev/null +++ b/src/Qtx/QtxValidator.cxx @@ -0,0 +1,125 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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. +// +// 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. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxValidator.cxx +// Author: Alexandre SOLOVYOV + +#include "QtxValidator.h" + +/*! + \class QtxIntValidator + Validator for integer numbers with possibility to fix up the invalid value +*/ + +/*! + Constructor +*/ +QtxIntValidator::QtxIntValidator( QObject* parent ) +: QIntValidator( parent ) +{ +} + +/*! + Constructor + \param bot - minimal possible value + \param top - maximal possible value + \param parent - parent object +*/ +QtxIntValidator::QtxIntValidator( const int bot, const int top, QObject* parent ) +: QIntValidator( bot, top, parent ) +{ +} + +/*! + Destructor +*/ +QtxIntValidator::~QtxIntValidator() +{ +} + +/*! + Corrects string: if it represent integer value less then bottom, it becomes equal to bottom, + if it is more then top, it becomes equal to top, if it isn't number is becomes '0' +*/ +void QtxIntValidator::fixup( QString& str ) const +{ + bool ok = false; + int i = str.toInt( &ok ); + if ( ok ) + { + if ( i < bottom() ) + str = QString::number( bottom() ); + else if( i > top() ) + str = QString::number( top() ); + } + else + str = QString ( "0" ); +} + +/*! + \class QtxDoubleValidator + Validator for double numbers with possibility to fix up the invalid value +*/ + +/*! + Constructor + \param parent - parent object +*/ +QtxDoubleValidator::QtxDoubleValidator( QObject* parent ) +: QDoubleValidator( parent ) +{ +} + +/*! + Constructor + \param bot - minimal possible value + \param top - maximal possible value + \param dec - number of digits + \param parent - parent object +*/ +QtxDoubleValidator::QtxDoubleValidator( const double bot, const double top, + const int dec, QObject* parent ) +: QDoubleValidator( bot, top, dec, parent ) +{ +} + +/*! + Destructor +*/ +QtxDoubleValidator::~QtxDoubleValidator() +{ +} + +/*! + Corrects string: if it represent double value less then bottom, it becomes equal to bottom, + if it is more then top, it becomes equal to top, if it isn't number is becomes '0' +*/ +void QtxDoubleValidator::fixup( QString& str ) const +{ + bool ok = false; + double d = str.toDouble( &ok ); + if ( ok ) + { + if ( d < bottom() ) + str = QString::number( bottom() ); + else if ( d > top() ) + str = QString::number( top() ); + } + else + str = QString( "0" ); +} diff --git a/src/Qtx/QtxValidator.h b/src/Qtx/QtxValidator.h new file mode 100644 index 000000000..069a339c4 --- /dev/null +++ b/src/Qtx/QtxValidator.h @@ -0,0 +1,59 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// 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. +// +// 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. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxValidator.h +// Author: Alexandre SOLOVYOV + +#ifndef QTX_VALIDATOR_H +#define QTX_VALIDATOR_H + +#include "Qtx.h" + +#include + +/*! + \class QtxIntValidator +*/ +class QTX_EXPORT QtxIntValidator : public QIntValidator +{ + Q_OBJECT + +public: + QtxIntValidator( QObject* ); + QtxIntValidator( const int, const int, QObject* ); + virtual ~QtxIntValidator(); + + virtual void fixup( QString& ) const; +}; + +/*! + \class QtxDoubleValidator +*/ +class QTX_EXPORT QtxDoubleValidator : public QDoubleValidator +{ + Q_OBJECT + +public: + QtxDoubleValidator( QObject* ); + QtxDoubleValidator( const double, const double, const int, QObject* ); + virtual ~QtxDoubleValidator(); + + virtual void fixup( QString& ) const; +}; + +#endif -- 2.39.2