From 8c93a758b560ceefc27f0fde0522aa70f6dc0e70 Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 30 Dec 2005 08:18:14 +0000 Subject: [PATCH] Implementation of fixup method for standard Qt double validator, this method corrects string such way, that she satisfies inequality: bottom<=user data<=top --- src/Qtx/Makefile.in | 9 ++++++--- src/Qtx/QtxDblValidator.cxx | 27 +++++++++++++++++++++++++++ src/Qtx/QtxDblValidator.h | 19 +++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/Qtx/QtxDblValidator.cxx create mode 100644 src/Qtx/QtxDblValidator.h 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 -- 2.39.2