From: asl Date: Fri, 30 Dec 2005 08:18:14 +0000 (+0000) Subject: Implementation of fixup method for standard Qt double validator, this method corrects... X-Git-Tag: T_Before_Join_BR-D5-38-2003~31 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8c93a758b560ceefc27f0fde0522aa70f6dc0e70;p=modules%2Fgui.git Implementation of fixup method for standard Qt double validator, this method corrects string such way, that she satisfies inequality: bottom<=user data<=top --- diff --git a/src/Qtx/Makefile.in b/src/Qtx/Makefile.in index 0a92974f9..aa682b59d 100755 --- a/src/Qtx/Makefile.in +++ b/src/Qtx/Makefile.in @@ -48,7 +48,8 @@ EXPORT_HEADERS= Qtx.h \ QtxWorkstack.h \ QtxResourceEdit.h \ QtxListView.h \ - QtxDirListEditor.h + QtxDirListEditor.h \ + QtxDblValidator.h # .po files to transform in .qm @@ -95,7 +96,8 @@ LIB_SRC= \ QtxResourceEdit.cxx \ QtxWorkstack.cxx \ QtxListView.cxx \ - QtxDirListEditor.cxx + QtxDirListEditor.cxx \ + QtxDblValidator.cxx LIB_MOC = \ QtxAction.h \ @@ -127,7 +129,8 @@ LIB_MOC = \ QtxWorkstack.h \ QtxListView.h \ QtxListResourceEdit.h \ - QtxDirListEditor.h + QtxDirListEditor.h \ + QtxDblValidator.h RESOURCES_FILES = \ diff --git a/src/Qtx/QtxDblValidator.cxx b/src/Qtx/QtxDblValidator.cxx new file mode 100644 index 000000000..d851653bc --- /dev/null +++ b/src/Qtx/QtxDblValidator.cxx @@ -0,0 +1,27 @@ + +#include "QtxDblValidator.h" + +QtxDblValidator::QtxDblValidator( const double bot, const double top, const int dec, + QObject* o, const char* name ) +: QDoubleValidator( bot, top, dec, o, name ) +{ +} + +QtxDblValidator::~QtxDblValidator() +{ +} + +void QtxDblValidator::fixup( QString& str ) const +{ + bool ok = false; + double d = str.toDouble( &ok ); + if( ok ) + { + if( dtop() ) + str = QString::number( top() ); + } + else + str = "0"; +} diff --git a/src/Qtx/QtxDblValidator.h b/src/Qtx/QtxDblValidator.h new file mode 100644 index 000000000..43beef90c --- /dev/null +++ b/src/Qtx/QtxDblValidator.h @@ -0,0 +1,19 @@ + +#ifndef QTX_DOUBLE_VALIDATOR +#define QTX_DOUBLE_VALIDATOR + +#include + +class QtxDblValidator : public QDoubleValidator +{ + Q_OBJECT + +public: + QtxDblValidator( const double, const double, const int, + QObject*, const char* = 0 ); + ~QtxDblValidator(); + + virtual void fixup( QString& ) const; +}; + +#endif