kexi

validator.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004, 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 #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 
00034 
00045 class KEXIUTILS_EXPORT Validator : public QValidator
00046 {
00047     public:
00048         typedef enum Result { Error = 0, Ok = 1, Warning = 2 };
00049 
00050         Validator(QObject * parent = 0, const char * name = 0);
00051         virtual ~Validator();
00052 
00055         void setAcceptsEmptyValue( bool set ) { m_acceptsEmptyValue = set; }
00056 
00059         bool acceptsEmptyValue() const { return m_acceptsEmptyValue; }
00060 
00070         Result check(const QString &valueName, const QVariant& v, QString &message,
00071             QString &details);
00072 
00074         virtual QValidator::State validate ( QString & input, int & pos ) const;
00075 
00077         static const QString msgColumnNotEmpty() {
00078             return I18N_NOOP("\"%1\" value has to be entered.");
00079         }
00080 
00082         void addChildValidator( Validator* v );
00083 
00084     protected:
00085         /* Used by check(), for reimplementation, by default returns \a Error.*/
00086         virtual Result internalCheck(const QString &valueName, const QVariant& v, 
00087             QString &message, QString &details);
00088 
00089         bool m_acceptsEmptyValue : 1;
00090 
00091     friend class MultiValidator;
00092 };
00093 
00095 
00120 class KEXIUTILS_EXPORT MultiValidator : public Validator
00121 {
00122     public:
00125         MultiValidator(QObject * parent = 0, const char * name = 0);
00126 
00130         MultiValidator(QValidator *validator, QObject * parent = 0, const char * name = 0);
00131 
00135         void addSubvalidator( QValidator* validator, bool owned = true );
00136 
00138         virtual QValidator::State validate ( QString & input, int & pos ) const;
00139 
00143         virtual void fixup ( QString & input ) const;
00144 
00145     private:
00146         virtual Validator::Result internalCheck(
00147             const QString &valueName, const QVariant& v, 
00148             QString &message, QString &details);
00149 
00150 
00151     protected:
00152         QPtrList<QValidator> m_ownedSubValidators;
00153         QValueList<QValidator*> m_subValidators;
00154 };
00155 
00156 }
00157 
00158 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys