00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef QGSLONGLONGVALIDATOR_H
00022 #define QGSLONGLONGVALIDATOR_H
00023
00024 #include <limits>
00025 #include <QValidator>
00026 #include <QLocale>
00027
00028 class GUI_EXPORT QgsLongLongValidator : public QValidator
00029 {
00030 Q_OBJECT
00031
00032 public:
00033 explicit QgsLongLongValidator( QObject *parent )
00034 : QValidator( parent )
00035 , b( std::numeric_limits<qint64>::min() )
00036 , t( std::numeric_limits<qint64>::max() )
00037 {}
00038
00039 QgsLongLongValidator( qint64 bottom, qint64 top, QObject *parent )
00040 : QValidator( parent )
00041 , b( bottom )
00042 , t( top )
00043 {}
00044
00045 ~QgsLongLongValidator()
00046 {}
00047
00048 QValidator::State validate( QString &input, int& ) const
00049 {
00050 if ( input.isEmpty() )
00051 return Intermediate;
00052
00053 if ( b >= 0 && input.startsWith( '-' ) )
00054 return Invalid;
00055
00056 if ( t < 0 && input.startsWith( '+' ) )
00057 return Invalid;
00058
00059 if ( input == "-" || input == "+" )
00060 return Intermediate;
00061
00062
00063 bool ok;
00064 qlonglong entered = input.toLongLong( &ok );
00065 if ( !ok )
00066 return Invalid;
00067
00068 if ( entered >= b && entered <= t )
00069 return Acceptable;
00070
00071 if ( entered >= 0 )
00072 {
00073
00074
00075 return ( entered > t && -entered < b ) ? Invalid : Intermediate;
00076 }
00077 else
00078 {
00079 return ( entered < b ) ? Invalid : Intermediate;
00080 }
00081 }
00082
00083 void setBottom( qint64 bottom ) { b = bottom; }
00084 void setTop( qint64 top ) { t = top; }
00085
00086 virtual void setRange( qint64 bottom, qint64 top )
00087 {
00088 b = bottom;
00089 t = top;
00090 }
00091
00092 qint64 bottom() const { return b; }
00093 qint64 top() const { return t; }
00094
00095 private:
00096 Q_DISABLE_COPY( QgsLongLongValidator )
00097
00098 qint64 b;
00099 qint64 t;
00100 };
00101
00102 #endif // QGSLONGLONGVALIDATOR_H