tuchulcha  0.10.1
Graphical Workflow Configuration Editor
PrefixValidator.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 Jens-Malte Gottfried
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17 */
24 #include "PrefixValidator.h"
25 #include "QParameterFile.h"
26 
28  QValidator(pp),
29  _parameterFile(data)
30 {
31 }
32 
33 QValidator::State PrefixValidator::validate(QString& input, int&) const {
34  if(input.isEmpty())
35  return QValidator::Acceptable;
36  if (_parameterFile.getKeyList(input+".").size() > 0)
37  return QValidator::Acceptable;
38  QStringList keyList = _parameterFile.getKeyList(input);
39  for (int ii=0; ii < keyList.size(); ii++)
40  if (keyList[ii].contains(QRegExp(
41  "^\\s*"+ input + ".*\\..*",Qt::CaseInsensitive)))
42  return QValidator::Intermediate;
43  return QValidator::Invalid;
44 }
45 
46 void PrefixValidator::fixup(QString& input) const {
47  // do not change empty strings
48  if(input.isEmpty())
49  return;
50 
51  QStringList keyList = _parameterFile.getKeyList(input);
52  for(int ii=0; ii < keyList.size(); ii++) {
53  if (keyList[ii].contains(QRegExp(
54  "^\\s*"+ input + ".*\\..*",Qt::CaseInsensitive))) {
55  input = keyList[ii];
56  return;
57  }
58  }
59 }
Declaration of class PrefixValidator.
virtual QValidator::State validate(QString &input, int &pos) const
Validate input string.
PrefixValidator(const QParameterFile &data, QObject *parent=0)
default constructor
Declaration of class QParameterFile.
Qt implementation for ParameterFile class.
const QParameterFile & _parameterFile
parent ParameterFile
virtual void fixup(QString &input) const
Fix given input string.
QStringList getKeyList(QString beginsWith="") const
Look for parameters beginning with a given string.