kexi

fieldvalidator.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "fieldvalidator.h"
21#include "field.h"
22
23#include <kexiutils/longlongvalidator.h>
24#include <knumvalidator.h>
25#include <tqwidget.h>
26
27using namespace KexiDB;
28
29FieldValidator::FieldValidator( const Field &field, TQWidget * parent, const char * name )
30 : KexiUtils::MultiValidator(parent, name)
31{
35 const Field::Type t = field.type();
36 if (field.isIntegerType()) {
37 TQValidator *validator = 0;
38 const bool u = field.isUnsigned();
39 int bottom = 0, top = 0;
40 if (t==Field::Byte) {
41 bottom = u ? 0 : -0x80;
42 top = u ? 0xff : 0x7f;
43 }
44 else if (t==Field::ShortInteger) {
45 bottom = u ? 0 : -0x8000;
46 top = u ? 0xffff : 0x7fff;
47 }
48 else if (t==Field::Integer) {
49 bottom = u ? 0 : -0x7fffffff-1;
50 top = u ? 0xffffffff : 0x7fffffff;
51 }
52 else if (t==Field::BigInteger) {
54 validator = new KexiUtils::LongLongValidator(0);
55 }
56
57 if (!validator)
58 validator = new KIntValidator(bottom, top, 0); //the default
59 addSubvalidator( validator );
60 }
61 else if (field.isFPNumericType()) {
62 TQValidator *validator;
63 if (t==Field::Float) {
64 if (field.isUnsigned()) //ok?
65 validator = new KDoubleValidator(0, 3.4e+38, field.scale(), 0);
66 else
67 validator = new KDoubleValidator(this);
68 }
69 else {//double
70 if (field.isUnsigned()) //ok?
71 validator = new KDoubleValidator(0, 1.7e+308, field.scale(), 0);
72 else
73 validator = new KDoubleValidator(this);
74 }
75 addSubvalidator( validator );
76 }
77 else if (t==Field::Date) {
79// TQValidator *validator = new KDateValidator(this);
80// setValidator( validator );
81//moved setInputMask( dateFormatter()->inputMask() );
82 }
83 else if (t==Field::Time) {
85//moved setInputMask( timeFormatter()->inputMask() );
86 }
87 else if (t==Field::DateTime) {
88//moved setInputMask(
89//moved dateTimeInputMask( *dateFormatter(), *timeFormatter() ) );
90 }
91 else if (t==Field::Boolean) {
93 addSubvalidator( new KIntValidator(0, 1) );
94 }
95}
96
97FieldValidator::~FieldValidator()
98{
99}
100
FieldValidator(const Field &field, TQWidget *parent, const char *name=0)
Setups the validator for field. Does not keep a pointer to field.
Meta-data for a field.
Definition field.h:73
Type type() const
Definition field.cpp:134
@ ShortInteger
Definition field.h:86
bool isFPNumericType() const
Definition field.h:266
bool isIntegerType() const
Definition field.h:259
uint scale() const
Definition field.h:343
bool isUnsigned() const
if the type has the unsigned attribute
Definition field.h:384
A validator for longlong data type.
void addSubvalidator(TQValidator *validator, bool owned=true)
Definition validator.cpp:74
High-level database connectivity library with database backend drivers.
General Utils.
Definition identifier.h:27