]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/QY2CharValidator.cc
don't reset the changes file
[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 )
32     , _validChars( initialValidChars )
33 {
34   setObjectName(name);
35 }
36
37
38 QY2CharValidator::~QY2CharValidator()
39 {
40     // NOP
41 }
42
43
44 QValidator::State
45 QY2CharValidator::validate( QString & fieldContents, int & pos ) const
46 {
47     if ( validChars().isEmpty() || fieldContents.isEmpty() )
48         return QValidator::Acceptable;
49
50
51     // Check the entire field contents.
52     //
53     // There might be more than one new character - the user might have copied
54     // some longer text via the X clipboard.
55
56     for ( int i=0; i < fieldContents.length(); i++ )
57     {
58         if ( ! validChars().contains( fieldContents[i] ) )
59             return QValidator::Invalid;
60     }
61
62     return QValidator::Acceptable;
63 }
64
65
66 #include "QY2CharValidator.moc"