Skip to content
Permalink
Browse files
followup r14006: add QgsLongLongValidator
git-svn-id: http://svn.osgeo.org/qgis/trunk@14009 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 4, 2010
1 parent 35dd014 commit 912724918264f2487f20dc06826fbb3dab3143ea
Showing with 109 additions and 1 deletion.
  1. +1 −0 src/gui/CMakeLists.txt
  2. +6 −1 src/gui/qgsattributeeditor.cpp
  3. +102 −0 src/gui/qgslonglongvalidator.h
@@ -95,6 +95,7 @@ qgsprojectionselector.h
qgsquickprint.h
qgsludialog.h
qgsprojectbadlayerguihandler.h
qgslonglongvalidator.h
)

QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
@@ -22,6 +22,7 @@
#include <qgsuniquevaluerenderer.h>
#include <qgscategorizedsymbolrendererv2.h>
#include <qgssymbol.h>
#include <qgslonglongvalidator.h>

#include <QPushButton>
#include <QLineEdit>
@@ -354,10 +355,14 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
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 ) );
@@ -0,0 +1,102 @@
/***************************************************************************
qgslonglongvalidator.h - description
-------------------
begin : August 2010
copyright : (C) 2010 by Jürgen E. Fischer
email : jef@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

0 comments on commit 9127249

Please sign in to comment.