-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgsgeorefvalidators.cpp
95 lines (82 loc) · 2.61 KB
/
qgsgeorefvalidators.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/***************************************************************************
qgsgeorefvalidators.cpp
--------------------------------------
Date : 14-Feb-2010
Copyright : (C) 2010 by Jack R, Maxim Dubinin (GIS-Lab)
Email : [email protected]
***************************************************************************
* *
* 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$ */
#include <QStringList>
#include "qgsgeorefvalidators.h"
QgsDMSAndDDValidator::QgsDMSAndDDValidator(QObject *parent)
: QValidator(parent)
{
}
QValidator::State QgsDMSAndDDValidator::validate(QString &input, int &pos) const
{
Q_UNUSED(pos);
QRegExp rx("-?\\d*");
if (rx.exactMatch(input))
{
return Acceptable;
}
if (input.length() == 4)
{
if (input.toInt() > 179)
return Invalid;
}
else if (input.startsWith("-") && input.length() == 5)
{
if (input.toInt() <= -180)
return Invalid;
}
if (!input.contains(" "))
{
rx.setPattern("-?\\d*(\\.|,)(\\d+)?");
if (rx.exactMatch(input))
return Acceptable;
}
else
{
rx.setPattern("-?\\d{1,3}\\s(\\d{1,2}(\\s(\\d{1,2}((\\.|,)(\\d{1,3})?)?)?)?)?");
if (rx.exactMatch(input))
{
rx.setPattern("-?\\d{1,3}\\s60");
if (rx.exactMatch(input))
{
int in = input.left(input.indexOf(" ")).toInt();
int grad = input.startsWith("-") ? in - 1 : in + 1;
if (grad <= 180)
input = QString::number(grad);
return Acceptable;
}
rx.setPattern("-?\\d{1,3}\\s\\d{1,2}\\s60");
if (rx.exactMatch(input))
{
int min = input.split(" ").at(1).toInt() + 1;
if (min <= 60)
input = input.left(input.indexOf(" ")) + " " + QString::number(min);
return Acceptable;
}
if (input.at(input.size() - 1) == ' ')
return Intermediate;
int pos = input.lastIndexOf(' ');
QString valStr = input.mid(pos + 1, input.size() - 1);
int val = valStr.toInt();
if (val <= 60)
return Acceptable;
else
return Invalid;
}
else
return Invalid;
}
return Invalid;
}