QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgslonglongvalidator.h
Go to the documentation of this file.
1
/***************************************************************************
2
qgslonglongvalidator.h - description
3
-------------------
4
begin : August 2010
5
copyright : (C) 2010 by Jürgen E. Fischer
6
email : jef@norbit.de
7
8
adapted version of QIntValidator for qint64
9
***************************************************************************/
10
11
/***************************************************************************
12
* *
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
17
* *
18
***************************************************************************/
19
20
#ifndef QGSLONGLONGVALIDATOR_H
21
#define QGSLONGLONGVALIDATOR_H
22
23
#include <limits>
24
25
#include "qgis_gui.h"
26
27
#include <QLocale>
28
#include <QString>
29
#include <QValidator>
30
31
using namespace
Qt::StringLiterals;
32
38
class
GUI_EXPORT
QgsLongLongValidator
:
public
QValidator
39
{
40
Q_OBJECT
41
42
public
:
43
explicit
QgsLongLongValidator
( QObject *parent )
44
: QValidator( parent )
45
, b( std::numeric_limits<qint64>::min() )
46
, t( std::numeric_limits<qint64>::max() )
47
{}
48
49
QgsLongLongValidator
( qint64
bottom
, qint64
top
, QObject *parent )
50
: QValidator( parent )
51
, b(
bottom
)
52
, t(
top
)
53
{}
54
55
QValidator::State
validate
( QString &input,
int
& )
const override
56
{
57
if
( input.isEmpty() )
58
return
Intermediate;
59
60
if
( b >= 0 && input.startsWith(
'-'
) )
61
return
Invalid;
62
63
if
( t < 0 && input.startsWith(
'+'
) )
64
return
Invalid;
65
66
if
( input ==
"-"
_L1 || input ==
"+"
_L1 )
67
return
Intermediate;
68
69
70
bool
ok;
71
const
qlonglong entered = input.toLongLong( &ok );
72
if
( !ok )
73
return
Invalid;
74
75
if
( entered >= b && entered <= t )
76
return
Acceptable;
77
78
if
( entered >= 0 )
79
{
80
// the -entered < b condition is necessary to allow people to type
81
// the minus last (e.g. for right-to-left languages)
82
return
( entered > t && -entered < b ) ? Invalid : Intermediate;
83
}
84
else
85
{
86
return
( entered < b ) ? Invalid : Intermediate;
87
}
88
}
89
90
void
setBottom
( qint64
bottom
) { b =
bottom
; }
91
void
setTop
( qint64
top
) { t =
top
; }
92
93
virtual
void
setRange
( qint64
bottom
, qint64
top
)
94
{
95
b =
bottom
;
96
t =
top
;
97
}
98
99
qint64
bottom
()
const
{
return
b; }
100
qint64
top
()
const
{
return
t; }
101
102
private
:
103
Q_DISABLE_COPY(
QgsLongLongValidator
)
104
105
qint64 b;
106
qint64 t;
107
};
108
109
#endif
// QGSLONGLONGVALIDATOR_H
QgsLongLongValidator
A QValidator which allows validation of long long values.
Definition
qgslonglongvalidator.h:39
QgsLongLongValidator::setRange
virtual void setRange(qint64 bottom, qint64 top)
Definition
qgslonglongvalidator.h:93
QgsLongLongValidator::top
qint64 top() const
Definition
qgslonglongvalidator.h:100
QgsLongLongValidator::QgsLongLongValidator
QgsLongLongValidator(QObject *parent)
Definition
qgslonglongvalidator.h:43
QgsLongLongValidator::setTop
void setTop(qint64 top)
Definition
qgslonglongvalidator.h:91
QgsLongLongValidator::QgsLongLongValidator
QgsLongLongValidator(qint64 bottom, qint64 top, QObject *parent)
Definition
qgslonglongvalidator.h:49
QgsLongLongValidator::setBottom
void setBottom(qint64 bottom)
Definition
qgslonglongvalidator.h:90
QgsLongLongValidator::bottom
qint64 bottom() const
Definition
qgslonglongvalidator.h:99
QgsLongLongValidator::validate
QValidator::State validate(QString &input, int &) const override
Definition
qgslonglongvalidator.h:55
Generated on
for QGIS API Documentation by
1.17.0