]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/QY2CharValidator.cc
unhide some virtual overloads - fixing Huha's only complaint :)
[duncan/yast2-qt4.git] / src / QY2CharValidator.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                          contributed Qt objects                      |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       QY2CharValidator.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   This is a pure Qt object - it can be used independently of YaST2.
18
19 /-*/
20
21
22 #include <stdio.h>
23 #include <qvalidator.h>
24 #include "QY2CharValidator.h"
25
26
27
28 QY2CharValidator::QY2CharValidator( const QString &     initialValidChars,
29                                     QObject *           parent,
30                                     const char *        name )
31     : QValidator( parent, name )
32     , _validChars( initialValidChars )
33 {
34 }
35
36
37 QY2CharValidator::~QY2CharValidator()
38 {
39     // NOP
40 }
41
42
43 QValidator::State
44 QY2CharValidator::validate( QString & fieldContents, int & pos ) const
45 {
46     if ( validChars().isEmpty() || fieldContents.isEmpty() )
47         return QValidator::Acceptable;
48
49
50     // Check the entire field contents.
51     //
52     // There might be more than one new character - the user might have copied
53     // some longer text via the X clipboard.
54
55     for ( int i=0; i < fieldContents.length(); i++ )
56     {
57         if ( ! validChars().contains( fieldContents[i] ) )
58             return QValidator::Invalid;
59     }
60
61     return QValidator::Acceptable;
62 }
63
64
65 #include "QY2CharValidator.moc"