patch_for_bug_2534_new.diff

New patch file - sunilkcube -, 2011-03-22 02:26 AM

Download (5.27 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 )
......
460 450
  {
461 451
    text = le->text();
462 452
    modified = le->isModified();
463
    if ( text == nullValue )
453
    if ( text == nullValue || text == "NULL" || text == "null" )
464 454
    {
465 455
      text = QString::null;
466 456
    }
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

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

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

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

  
59
}
60

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

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

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

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

  
137
#endif // QGSFIELDVALIDATOR_H