]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Implementation of fixup method for standard Qt double validator, this method corrects...
authorasl <asl@opencascade.com>
Fri, 30 Dec 2005 08:18:14 +0000 (08:18 +0000)
committerasl <asl@opencascade.com>
Fri, 30 Dec 2005 08:18:14 +0000 (08:18 +0000)
bottom<=user data<=top

src/Qtx/Makefile.in
src/Qtx/QtxDblValidator.cxx [new file with mode: 0644]
src/Qtx/QtxDblValidator.h [new file with mode: 0644]

index 0a92974f92963df40e355629556c4b520d711573..aa682b59d199c117ebd7c93802e53e5219770b62 100755 (executable)
@@ -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 (file)
index 0000000..d851653
--- /dev/null
@@ -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( d<bottom() )
+      str = QString::number( bottom() );
+    else if( d>top() )
+      str = QString::number( top() );
+  }
+  else
+    str = "0";
+}
diff --git a/src/Qtx/QtxDblValidator.h b/src/Qtx/QtxDblValidator.h
new file mode 100644 (file)
index 0000000..43beef9
--- /dev/null
@@ -0,0 +1,19 @@
+
+#ifndef QTX_DOUBLE_VALIDATOR
+#define QTX_DOUBLE_VALIDATOR
+
+#include <qvalidator.h>
+
+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