[QGIS Commit] r14009 - trunk/qgis/src/gui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Aug 4 11:45:39 EDT 2010


Author: jef
Date: 2010-08-04 15:45:39 +0000 (Wed, 04 Aug 2010)
New Revision: 14009

Added:
   trunk/qgis/src/gui/qgslonglongvalidator.h
Modified:
   trunk/qgis/src/gui/CMakeLists.txt
   trunk/qgis/src/gui/qgsattributeeditor.cpp
Log:
followup r14006: add QgsLongLongValidator

Modified: trunk/qgis/src/gui/CMakeLists.txt
===================================================================
--- trunk/qgis/src/gui/CMakeLists.txt	2010-08-04 15:38:36 UTC (rev 14008)
+++ trunk/qgis/src/gui/CMakeLists.txt	2010-08-04 15:45:39 UTC (rev 14009)
@@ -95,6 +95,7 @@
 qgsquickprint.h
 qgsludialog.h
 qgsprojectbadlayerguihandler.h
+qgslonglongvalidator.h
 )
 
 QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})

Modified: trunk/qgis/src/gui/qgsattributeeditor.cpp
===================================================================
--- trunk/qgis/src/gui/qgsattributeeditor.cpp	2010-08-04 15:38:36 UTC (rev 14008)
+++ trunk/qgis/src/gui/qgsattributeeditor.cpp	2010-08-04 15:45:39 UTC (rev 14009)
@@ -22,6 +22,7 @@
 #include <qgsuniquevaluerenderer.h>
 #include <qgscategorizedsymbolrendererv2.h>
 #include <qgssymbol.h>
+#include <qgslonglongvalidator.h>
 
 #include <QPushButton>
 #include <QLineEdit>
@@ -354,10 +355,14 @@
           le->setCompleter( c );
         }
 
-        if ( myFieldType == QVariant::Int || myFieldType == QVariant::LongLong )
+        if ( myFieldType == QVariant::Int )
         {
           le->setValidator( new QIntValidator( le ) );
         }
+        else if ( myFieldType == QVariant::LongLong )
+        {
+          le->setValidator( new QgsLongLongValidator( le ) );
+        }
         else if ( myFieldType == QVariant::Double )
         {
           le->setValidator( new QDoubleValidator( le ) );

Added: trunk/qgis/src/gui/qgslonglongvalidator.h
===================================================================
--- trunk/qgis/src/gui/qgslonglongvalidator.h	                        (rev 0)
+++ trunk/qgis/src/gui/qgslonglongvalidator.h	2010-08-04 15:45:39 UTC (rev 14009)
@@ -0,0 +1,102 @@
+/***************************************************************************
+                         qgslonglongvalidator.h  -  description
+                             -------------------
+    begin                : August 2010
+    copyright            : (C) 2010 by Jürgen E. Fischer
+    email                : jef at norbit.de
+
+  adapted version of QIntValidator for qint64
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+/* $Id$ */
+
+#ifndef QGSLONGLONGVALIDATOR_H
+#define QGSLONGLONGVALIDATOR_H
+
+#include <limits>
+#include <QValidator>
+#include <QLocale>
+
+class GUI_EXPORT QgsLongLongValidator : public QValidator
+{
+    Q_OBJECT
+
+  public:
+    explicit QgsLongLongValidator( QObject *parent )
+        : QValidator( parent )
+        , b( std::numeric_limits<qint64>::min() )
+        , t( std::numeric_limits<qint64>::max() )
+    {}
+
+    QgsLongLongValidator( qint64 bottom, qint64 top, QObject *parent )
+        : QValidator( parent )
+        , b( bottom )
+        , t( top )
+    {}
+
+    ~QgsLongLongValidator()
+    {}
+
+    QValidator::State validate( QString &input, int& ) const
+    {
+      if ( input.isEmpty() )
+        return Intermediate;
+
+      if ( b >= 0 && input.startsWith( '-' ) )
+        return Invalid;
+
+      if ( t < 0 && input.startsWith( '+' ) )
+        return Invalid;
+
+      if ( input == "-" || input == "+" )
+        return Intermediate;
+
+
+      bool ok;
+      qlonglong entered = input.toLongLong( &ok );
+      if ( !ok )
+        return Invalid;
+
+      if ( entered >= b && entered <= t )
+        return Acceptable;
+
+      if ( entered >= 0 )
+      {
+        // the -entered < b condition is necessary to allow people to type
+        // the minus last (e.g. for right-to-left languages)
+        return ( entered > t && -entered < b ) ? Invalid : Intermediate;
+      }
+      else
+      {
+        return ( entered < b ) ? Invalid : Intermediate;
+      }
+    }
+
+    void setBottom( qint64 bottom ) { b = bottom; }
+    void setTop( qint64 top ) { t = top; }
+
+    virtual void setRange( qint64 bottom, qint64 top )
+    {
+      b = bottom;
+      t = top;
+    }
+
+    qint64 bottom() const { return b; }
+    qint64 top() const { return t; }
+
+  private:
+    Q_DISABLE_COPY( QgsLongLongValidator )
+
+    qint64 b;
+    qint64 t;
+};
+
+#endif // QGSLONGLONGVALIDATOR_H



More information about the QGIS-commit mailing list