1
/* This file is part of the KDE project
2
Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
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.
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.
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., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
20
#include "kexivalidator.h"
22
KexiValidator::KexiValidator(QObject * parent, const char * name)
23
: QValidator(parent,name)
24
, m_acceptsEmptyValue(false)
28
KexiValidator::~KexiValidator()
32
KexiValidator::Result KexiValidator::check(const QString &valueName, const QVariant& v,
33
QString &message, QString &details)
35
if (v.isNull() || v.type()==QVariant::String && v.toString().isEmpty()) {
36
if (!m_acceptsEmptyValue) {
37
message = KexiValidator::msgColumnNotEmpty().arg(valueName);
42
return internalCheck(valueName, v, message, details);
45
KexiValidator::Result KexiValidator::internalCheck(const QString & /*valueName*/,
46
const QVariant& /*v*/, QString & /*message*/, QString & /*details*/)
51
QValidator::State KexiValidator::validate ( QString & , int & ) const
53
return QValidator::Acceptable;
56
//-----------------------------------------------------------
58
KexiMultiValidator::KexiMultiValidator(QObject* parent, const char * name)
59
: KexiValidator(parent, name)
61
m_ownedSubValidators.setAutoDelete(true);
64
KexiMultiValidator::KexiMultiValidator(KexiValidator *validator,
65
QObject * parent, const char * name)
66
: KexiValidator(parent, name)
68
addSubvalidator(validator);
72
void KexiMultiValidator::addSubvalidator( KexiValidator* validator, bool owned )
76
m_subValidators.append(validator);
77
if (owned && !validator->parent())
78
m_ownedSubValidators.append(validator);
81
QValidator::State KexiMultiValidator::validate( QString & input, int & pos ) const
83
if (m_subValidators.isEmpty())
86
QValueList<KexiValidator*>::const_iterator it;
87
for ( it=m_subValidators.constBegin(); it!=m_subValidators.constEnd(); ++it) {
88
s = (*it)->validate(input, pos);
89
if (s==Intermediate || s==Invalid)
95
void KexiMultiValidator::fixup ( QString & input ) const
97
QValueList<KexiValidator*>::const_iterator it;
98
for ( it=m_subValidators.constBegin(); it!=m_subValidators.constEnd(); ++it) {
103
KexiValidator::Result KexiMultiValidator::internalCheck(
104
const QString &valueName, const QVariant& v,
105
QString &message, QString &details)
107
if (m_subValidators.isEmpty())
110
bool warning = false;
111
QValueList<KexiValidator*>::const_iterator it;
112
for ( it=m_subValidators.begin(); it!=m_subValidators.end(); ++it) {
113
r = (*it)->internalCheck(valueName, v, message, details);
119
return warning ? Warning : Ok;