kexi

fieldvalidator.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "fieldvalidator.h"
00021 #include "field.h"
00022 
00023 #include <kexiutils/longlongvalidator.h>
00024 #include <knumvalidator.h>
00025 #include <qwidget.h>
00026 
00027 using namespace KexiDB;
00028 
00029 FieldValidator::FieldValidator( const Field &field, QWidget * parent, const char * name )
00030  : KexiUtils::MultiValidator(parent, name)
00031 {
00035     const Field::Type t = field.type();
00036     if (field.isIntegerType()) {
00037         QValidator *validator = 0;
00038         const bool u = field.isUnsigned();
00039         int bottom, top;
00040         if (t==Field::Byte) {
00041             bottom = u ? 0 : -0x80;
00042             top = u ? 0xff : 0x7f;
00043         }
00044         else if (t==Field::ShortInteger) {
00045             bottom = u ? 0 : -0x8000;
00046             top = u ? 0xffff : 0x7fff;
00047         }
00048         else if (t==Field::Integer) {
00049             bottom = u ? 0 : -0x7fffffff-1;
00050             top = u ? 0xffffffff : 0x7fffffff;
00051         }
00052         else if (t==Field::BigInteger) {
00054             validator = new KexiUtils::LongLongValidator(0);
00055         }
00056 
00057         if (!validator)
00058             validator = new KIntValidator(bottom, top, 0); //the default
00059         addSubvalidator( validator );
00060     }
00061     else if (field.isFPNumericType()) {
00062         QValidator *validator;
00063         if (t==Field::Float) {
00064             if (field.isUnsigned()) //ok?
00065                 validator = new KDoubleValidator(0, 3.4e+38, field.scale(), 0);
00066             else
00067                 validator = new KDoubleValidator(this);
00068         }
00069         else {//double
00070             if (field.isUnsigned()) //ok?
00071                 validator = new KDoubleValidator(0, 1.7e+308, field.scale(), 0);
00072             else
00073                 validator = new KDoubleValidator(this);
00074         }
00075         addSubvalidator( validator );
00076     }
00077     else if (t==Field::Date) {
00079 //      QValidator *validator = new KDateValidator(this);
00080 //      setValidator( validator );
00081 //moved     setInputMask( dateFormatter()->inputMask() );
00082     }
00083     else if (t==Field::Time) {
00085 //moved     setInputMask( timeFormatter()->inputMask() );
00086     }
00087     else if (t==Field::DateTime) {
00088 //moved     setInputMask( 
00089 //moved         dateTimeInputMask( *dateFormatter(), *timeFormatter() ) );
00090     }
00091     else if (t==Field::Boolean) {
00093         addSubvalidator( new KIntValidator(0, 1) );
00094     }
00095 }
00096 
00097 FieldValidator::~FieldValidator()
00098 {
00099 }
00100 
KDE Home | KDE Accessibility Home | Description of Access Keys