validator.h
1/* This file is part of the KDE project
2 Copyright (C) 2004, 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#ifndef KEXI_VALIDATOR_H
21#define KEXI_VALIDATOR_H
22
23#include "kexiutils_export.h"
24
25#include <tqvalidator.h>
26#include <tqvariant.h>
27#include <tqstring.h>
28
29#include <tdelocale.h>
30
31namespace KexiUtils {
32
34
45class KEXIUTILS_EXPORT Validator : public TQValidator
46{
47 public:
48 enum Result { Error = 0, Ok = 1, Warning = 2 };
49
50 Validator(TQObject * parent = 0, const char * name = 0);
51 virtual ~Validator();
52
55 void setAcceptsEmptyValue( bool set ) { m_acceptsEmptyValue = set; }
56
59 bool acceptsEmptyValue() const { return m_acceptsEmptyValue; }
60
70 Result check(const TQString &valueName, const TQVariant& v, TQString &message,
71 TQString &details);
72
74 virtual TQValidator::State validate ( TQString & input, int & pos ) const;
75
77 static const TQString msgColumnNotEmpty() {
78 return I18N_NOOP("\"%1\" value has to be entered.");
79 }
80
83
84 protected:
85 /* Used by check(), for reimplementation, by default returns \a Error.*/
86 virtual Result internalCheck(const TQString &valueName, const TQVariant& v,
87 TQString &message, TQString &details);
88
89 bool m_acceptsEmptyValue : 1;
90
91 friend class MultiValidator;
92};
93
95
120class KEXIUTILS_EXPORT MultiValidator : public Validator
121{
122 public:
125 MultiValidator(TQObject * parent = 0, const char * name = 0);
126
130 MultiValidator(TQValidator *validator, TQObject * parent = 0, const char * name = 0);
131
135 void addSubvalidator( TQValidator* validator, bool owned = true );
136
138 virtual TQValidator::State validate ( TQString & input, int & pos ) const;
139
143 virtual void fixup ( TQString & input ) const;
144
145 private:
146 virtual Validator::Result internalCheck(
147 const TQString &valueName, const TQVariant& v,
148 TQString &message, TQString &details);
149
150
151 protected:
152 TQPtrList<TQValidator> m_ownedSubValidators;
153 TQValueList<TQValidator*> m_subValidators;
154};
155
156}
157
158#endif
A validator groupping multiple TQValidators.
Definition validator.h:121
A validator extending TQValidator with offline-checking for value's validity.
Definition validator.h:46
void addChildValidator(Validator *v)
Adds a child validator v.
static const TQString msgColumnNotEmpty()
A generic error/warning message.
Definition validator.h:77
bool acceptsEmptyValue() const
Definition validator.h:59
void setAcceptsEmptyValue(bool set)
Definition validator.h:55
General Utils.
Definition identifier.h:27