1
|
Index: src/gui/CMakeLists.txt
|
2
|
===================================================================
|
3
|
--- src/gui/CMakeLists.txt (revision 15494)
|
4
|
+++ src/gui/CMakeLists.txt (working copy)
|
5
|
@@ -89,6 +89,7 @@
|
6
|
qgslegendinterface.h
|
7
|
qgisinterface.h
|
8
|
qgsencodingfiledialog.h
|
9
|
+qgsfieldvalidator.h
|
10
|
qgsformannotationitem.h
|
11
|
qgsgenericprojectionselector.h
|
12
|
qgsmapcanvas.h
|
13
|
Index: src/gui/qgsattributeeditor.cpp
|
14
|
===================================================================
|
15
|
--- src/gui/qgsattributeeditor.cpp (revision 15494)
|
16
|
+++ src/gui/qgsattributeeditor.cpp (working copy)
|
17
|
@@ -23,6 +23,7 @@
|
18
|
#include <qgscategorizedsymbolrendererv2.h>
|
19
|
#include <qgssymbol.h>
|
20
|
#include <qgslonglongvalidator.h>
|
21
|
+#include <qgsfieldvalidator.h>
|
22
|
|
23
|
#include <QPushButton>
|
24
|
#include <QLineEdit>
|
25
|
@@ -357,20 +358,9 @@
|
26
|
le->setCompleter( c );
|
27
|
}
|
28
|
|
29
|
- if ( myFieldType == QVariant::Int )
|
30
|
- {
|
31
|
- le->setValidator( new QIntValidator( le ) );
|
32
|
- }
|
33
|
- else if ( myFieldType == QVariant::LongLong )
|
34
|
- {
|
35
|
- le->setValidator( new QgsLongLongValidator( le ) );
|
36
|
- }
|
37
|
- else if ( myFieldType == QVariant::Double )
|
38
|
- {
|
39
|
- le->setValidator( new QDoubleValidator( le ) );
|
40
|
- }
|
41
|
-
|
42
|
+ le->setValidator( new QgsFieldValidator( le, field ) );
|
43
|
myWidget = le;
|
44
|
+
|
45
|
}
|
46
|
|
47
|
if ( te )
|
48
|
Index: qgsfieldvalidator.h
|
49
|
===================================================================
|
50
|
--- qgsfieldvalidator.h (revision 0)
|
51
|
+++ qgsfieldvalidator.h (revision 0)
|
52
|
@@ -0,0 +1,123 @@
|
53
|
+/***************************************************************************
|
54
|
+ qgsfieldvalidator.h - description
|
55
|
+ -------------------
|
56
|
+ begin : March 2011
|
57
|
+ copyright : (C) 2011 by SunilRajKiran-kCube
|
58
|
+ email : [email protected]
|
59
|
+
|
60
|
+ adapted version of QValidator for QgsField
|
61
|
+ ***************************************************************************/
|
62
|
+
|
63
|
+/***************************************************************************
|
64
|
+ * *
|
65
|
+ * This program is free software; you can redistribute it and/or modify *
|
66
|
+ * it under the terms of the GNU General Public License as published by *
|
67
|
+ * the Free Software Foundation; either version 2 of the License, or *
|
68
|
+ * (at your option) any later version. *
|
69
|
+ * *
|
70
|
+ ***************************************************************************/
|
71
|
+/* $Id$ */
|
72
|
+
|
73
|
+#ifndef QGSFIELDVALIDATOR_H
|
74
|
+#define QGSFIELDVALIDATOR_H
|
75
|
+
|
76
|
+#include <QMessageBox>
|
77
|
+#include <QValidator>
|
78
|
+#include <QLocale>
|
79
|
+#include <QVariant>
|
80
|
+
|
81
|
+#include "qgslogger.h"
|
82
|
+#include "qgslonglongvalidator.h"
|
83
|
+#include "qgsfield.h"
|
84
|
+
|
85
|
+class GUI_EXPORT QgsFieldValidator : public QValidator
|
86
|
+{
|
87
|
+ Q_OBJECT
|
88
|
+
|
89
|
+public:
|
90
|
+QgsFieldValidator(QObject *parent, const QgsField &field, int t, int b):QValidator(parent)
|
91
|
+{
|
92
|
+ fieldLength = field.length();
|
93
|
+ fieldPrecision = field.precision();
|
94
|
+ fieldType = field.type();
|
95
|
+
|
96
|
+ switch(fieldType)
|
97
|
+ {
|
98
|
+ case QVariant::Int :
|
99
|
+ validator = new QIntValidator(b, t, parent);
|
100
|
+ break;
|
101
|
+ case QVariant::Double :
|
102
|
+ validator = new QDoubleValidator(parent);
|
103
|
+ break;
|
104
|
+ case QVariant::LongLong :
|
105
|
+ validator = new QgsLongLongValidator(b, t, parent);
|
106
|
+ break;
|
107
|
+ default:
|
108
|
+ validator = 0;
|
109
|
+ }
|
110
|
+
|
111
|
+}
|
112
|
+
|
113
|
+QgsFieldValidator(QObject *parent, const QgsField &field):QValidator(parent)
|
114
|
+{
|
115
|
+ fieldLength = field.length();
|
116
|
+ fieldPrecision = field.precision();
|
117
|
+ fieldType = field.type();
|
118
|
+
|
119
|
+ switch(fieldType)
|
120
|
+ {
|
121
|
+ case QVariant::Int :
|
122
|
+ validator = new QIntValidator(parent);
|
123
|
+ break;
|
124
|
+ case QVariant::Double :
|
125
|
+ validator = new QDoubleValidator(parent);
|
126
|
+ break;
|
127
|
+ case QVariant::LongLong :
|
128
|
+ validator = new QgsLongLongValidator(parent);
|
129
|
+ break;
|
130
|
+ default:
|
131
|
+ validator = 0;
|
132
|
+ }
|
133
|
+}
|
134
|
+
|
135
|
+~QgsFieldValidator()
|
136
|
+{
|
137
|
+ delete validator;
|
138
|
+}
|
139
|
+
|
140
|
+QValidator::State validate(QString &s, int &i) const
|
141
|
+{
|
142
|
+ QgsDebugMsg("**********###########entering validate\n");
|
143
|
+
|
144
|
+ if(validator && validator->validate(s, i) == Invalid)
|
145
|
+ {
|
146
|
+ QgsDebugMsg("**********###########entering validate2\n");
|
147
|
+ return Invalid;
|
148
|
+ }
|
149
|
+
|
150
|
+ if(s.length() > fieldLength)
|
151
|
+ return Invalid;
|
152
|
+
|
153
|
+ if(fieldType == QVariant::Double)
|
154
|
+ {
|
155
|
+ int len = s.length();
|
156
|
+ int prec = s.indexOf(QChar('.'));
|
157
|
+ QgsDebugMsg(tr("length %1 %2") . arg(len). arg(prec));
|
158
|
+ if(s.indexOf(QChar('.')) != -1 && s.length() - (s.indexOf(QChar('.')) + 1) > fieldPrecision)
|
159
|
+ return Invalid;
|
160
|
+ }
|
161
|
+
|
162
|
+ return Acceptable;
|
163
|
+}
|
164
|
+
|
165
|
+private:
|
166
|
+ // Disables copy constructing
|
167
|
+ Q_DISABLE_COPY( QgsFieldValidator )
|
168
|
+
|
169
|
+ QValidator *validator;
|
170
|
+ int fieldLength;
|
171
|
+ QVariant::Type fieldType;
|
172
|
+ int fieldPrecision;
|
173
|
+};
|
174
|
+
|
175
|
+#endif // QGSFIELDVALIDATOR_H
|