Corrected_patch_for_bug__2534.diff

Corrected patch contains all corrections mentioned by jef - sunilkcube -, 2011-03-22 03:50 AM

Download (5.12 KB)

View differences:

src/gui/CMakeLists.txt (working copy)
89 89
qgslegendinterface.h
90 90
qgisinterface.h
91 91
qgsencodingfiledialog.h
92
qgsfieldvalidator.h
92 93
qgsformannotationitem.h
93 94
qgsgenericprojectionselector.h
94 95
qgsmapcanvas.h
src/gui/qgsattributeeditor.cpp (working copy)
23 23
#include <qgscategorizedsymbolrendererv2.h>
24 24
#include <qgssymbol.h>
25 25
#include <qgslonglongvalidator.h>
26
#include <qgsfieldvalidator.h>
26 27

  
27 28
#include <QPushButton>
28 29
#include <QLineEdit>
......
357 358
          le->setCompleter( c );
358 359
        }
359 360

  
360
        if ( myFieldType == QVariant::Int )
361
        {
362
          le->setValidator( new QIntValidator( le ) );
363
        }
364
        else if ( myFieldType == QVariant::LongLong )
365
        {
366
          le->setValidator( new QgsLongLongValidator( le ) );
367
        }
368
        else if ( myFieldType == QVariant::Double )
369
        {
370
          le->setValidator( new QDoubleValidator( le ) );
371
        }
372

  
361
        le->setValidator( new QgsFieldValidator( le, field ) );
373 362
        myWidget = le;
363

  
374 364
      }
375 365

  
376 366
      if ( te )
qgsfieldvalidator.h (revision 0)
1
/***************************************************************************
2
                         qgsfieldvalidator.h  -  description
3
                             -------------------
4
    begin                : March 2011
5
    copyright            : (C) 2011 by SunilRajKiran-kCube
6
    email                : [email protected]
7

  
8
  adapted version of QValidator for QgsField
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
/* $Id$ */
20

  
21
#ifndef QGSFIELDVALIDATOR_H
22
#define QGSFIELDVALIDATOR_H
23

  
24
#include <QMessageBox>
25
#include <QValidator>
26
#include <QLocale>
27
#include <QVariant>
28
#include <QSettings>
29

  
30
#include "qgslogger.h"
31
#include "qgslonglongvalidator.h"
32
#include "qgsfield.h"
33

  
34
class GUI_EXPORT QgsFieldValidator : public QValidator
35
{
36
   Q_OBJECT     
37

  
38
public:
39
QgsFieldValidator(QObject *parent,  const QgsField &field, int t, int b):QValidator(parent)
40
{
41
	fieldLength = field.length();
42
	fieldPrecision = field.precision();
43
	fieldType = field.type();
44
	
45
	switch(fieldType)
46
	{
47
		case QVariant::Int :
48
			validator = new QIntValidator(b, t, parent);
49
			break;
50
		case QVariant::Double :
51
			validator = new QDoubleValidator(parent);
52
			break;
53
		case QVariant::LongLong :
54
			validator = new QgsLongLongValidator(b, t, parent);
55
			break;
56
		default:
57
			validator = 0;
58
	}
59

  
60
}
61

  
62
QgsFieldValidator(QObject *parent, const QgsField &field):QValidator(parent)
63
{
64
	fieldLength = field.length();
65
	fieldPrecision = field.precision();
66
	fieldType = field.type();
67
	
68
	switch(fieldType)
69
	{
70
		case QVariant::Int :
71
			validator = new QIntValidator(parent);
72
			break;
73
		case QVariant::Double :
74
			validator = new QDoubleValidator(parent);
75
			break;
76
		case QVariant::LongLong :
77
			validator = new QgsLongLongValidator(parent);
78
			break;
79
		default:
80
			validator = 0;
81
	}	
82
}
83

  
84
~QgsFieldValidator()
85
{
86
  delete validator;	
87
}
88

  
89
QValidator::State validate(QString &s, int &i) const
90
{
91
	QSettings settings;
92
	
93
	QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
94
		
95
	if(validator && validator->validate(s, i) == Invalid)
96
	{
97
		return Invalid;
98
	}
99
	
100
	if(validator && validator->validate(s, i) == Intermediate)
101
	{
102
		if(s.length() > fieldLength)
103
		return Invalid;
104
		return Intermediate;
105
	}
106
	
107
	if(fieldType == QVariant::String)
108
	{
109
	if ( s.size()>0 && (s.size() <=  nullValue.size()) && s == nullValue.left( s.size() ) ) 
110
	return Intermediate;
111
  }
112
  
113
	if(s.length() > fieldLength)
114
		return Invalid;
115
	
116
	if(fieldType == QVariant::Double)
117
	{
118
		int len = s.length();
119
		int prec = s.indexOf(QChar('.'));
120
		QgsDebugMsg(tr("length %1 %2") . arg(len). arg(prec));
121
		if(s.indexOf(QChar('.')) != -1 && s.length() - (s.indexOf(QChar('.')) + 1) > fieldPrecision)
122
			return Invalid;
123
	}
124
	
125
	return Acceptable;
126
}
127

  
128
private:
129
    // Disables copy constructing
130
    Q_DISABLE_COPY( QgsFieldValidator )   
131
     
132
    QValidator *validator;
133
    int fieldLength;
134
    QVariant::Type fieldType;
135
    int fieldPrecision;
136
};
137

  
138
#endif // QGSFIELDVALIDATOR_H