kexi

validator.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 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 #ifndef KEXI_VALIDATOR_H
00021 #define KEXI_VALIDATOR_H
00022 
00023 #include "kexiutils_export.h"
00024 
00025 #include <qvalidator.h>
00026 #include <qvariant.h>
00027 #include <qstring.h>
00028 
00029 #include <klocale.h>
00030 
00031 namespace KexiUtils {
00032 
00044 class KEXIUTILS_EXPORT Validator : public QValidator
00045 {
00046     public:
00047         typedef enum Result { Error = 0, Ok = 1, Warning = 2 };
00048 
00049         Validator(QObject * parent = 0, const char * name = 0);
00050         virtual ~Validator();
00051 
00054         void setAcceptsEmptyValue( bool set ) { m_acceptsEmptyValue = set; }
00055 
00057         bool acceptsEmptyValue() const { return m_acceptsEmptyValue; }
00058 
00067         Result check(const QString &valueName, const QVariant& v, QString &message,
00068             QString &details);
00069 
00071         virtual QValidator::State validate ( QString & input, int & pos ) const;
00072 
00074         static const QString msgColumnNotEmpty() {
00075             return I18N_NOOP("\"%1\" value has to be entered.");
00076         }
00077 
00078         void addChildValidator( Validator* v );
00079 
00080     protected:
00081         /* Used by check(), for reimplementation, 
00082          by default always returns \a Error.*/
00083         virtual Result internalCheck(const QString &valueName, const QVariant& v, 
00084             QString &message, QString &details);
00085 
00086         bool m_acceptsEmptyValue : 1;
00087 
00088     friend class MultiValidator;
00089 };
00090 
00113 class KEXIUTILS_EXPORT MultiValidator : public Validator
00114 {
00115     public:
00118         MultiValidator(QObject * parent = 0, const char * name = 0);
00119 
00123         MultiValidator(Validator *validator, QObject * parent = 0, const char * name = 0);
00124 
00128         void addSubvalidator( Validator* validator, bool owned = true );
00129 
00131         virtual QValidator::State validate ( QString & input, int & pos ) const;
00132 
00136         virtual void fixup ( QString & input ) const;
00137 
00138     private:
00139         virtual Validator::Result internalCheck(
00140             const QString &valueName, const QVariant& v, 
00141             QString &message, QString &details);
00142 
00143 
00144     protected:
00145         QPtrList<Validator> m_ownedSubValidators;
00146         QValueList<Validator*> m_subValidators;
00147 };
00148 
00149 }
00150 
00151 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys