libyui-qt  2.49.2
QY2CharValidator.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: QY2CharValidator.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23  This is a pure Qt object - it can be used independently of YaST2.
24 
25 /-*/
26 
27 
28 #include <stdio.h>
29 #include <QValidator>
30 #include "QY2CharValidator.h"
31 
32 
33 
34 QY2CharValidator::QY2CharValidator( const QString & initialValidChars,
35  QObject * parent,
36  const char * name )
37  : QValidator( parent )
38  , _validChars( initialValidChars )
39 {
40  setObjectName(name);
41 }
42 
43 
45 {
46  // NOP
47 }
48 
49 
50 QValidator::State
51 QY2CharValidator::validate( QString & fieldContents, int & pos ) const
52 {
53  if ( validChars().isEmpty() || fieldContents.isEmpty() )
54  return QValidator::Acceptable;
55 
56 
57  // Check the entire field contents.
58  //
59  // There might be more than one new character - the user might have copied
60  // some longer text via the X clipboard.
61 
62  for ( int i=0; i < fieldContents.length(); i++ )
63  {
64  if ( ! validChars().contains( fieldContents[i] ) )
65  return QValidator::Invalid;
66  }
67 
68  return QValidator::Acceptable;
69 }
70 
71 
72 #include "QY2CharValidator.moc"
QY2CharValidator(const QString &initialValidChars, QObject *parent=0, const char *name=0)
Constructor.
QString validChars() const
Retrieve the valid input characters.
~QY2CharValidator()
Destructor.
virtual State validate(QString &input, int &pos) const
Check user input.