COPASI API  4.16.103
CQValidator.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include <QtGui/QLineEdit>
16 
17 #include <limits>
18 
19 #include "CQValidator.h"
20 
21 CQValidatorNotEmpty::CQValidatorNotEmpty(QLineEdit * parent, const char * name):
22  CQValidator< QLineEdit >(parent, &QLineEdit::text, name)
23 {}
24 
25 QValidator::State CQValidatorNotEmpty::validate(QString & input, int & pos) const
26 {
27  if (input != "")
28  return CQValidator< QLineEdit >::validate(input, pos);
29 
30  setColor(Invalid);
31  return Intermediate;
32 }
33 
34 CQValidatorBound::CQValidatorBound(QLineEdit * parent, const QString & sign):
35  CQValidator< QLineEdit >(parent, &QLineEdit::text, NULL),
36  mpDoubleValidator(new QDoubleValidator(-std::numeric_limits< C_FLOAT64 >::max(), std::numeric_limits< C_FLOAT64 >::max(), std::numeric_limits< C_FLOAT64 >::digits10, this)),
37  mSign(sign),
38  mValidBound("\t") // It is not possible to insert a tab.
39 {}
40 
41 QValidator::State CQValidatorBound::validate(QString & input, int & pos) const
42 {
43  QString Input;
44 
45  if (input == mValidBound ||
46  mpDoubleValidator->validate(input, pos) == Acceptable ||
47  (input.startsWith(mSign) &&
48  input.endsWith("%") &&
49  mpDoubleValidator->validate(Input = input.mid(1, input.length() - 2), pos)))
50  {
51  force(input);
52  return Acceptable;
53  }
54 
55  setColor(Invalid);
56  return Intermediate;
57 }
58 
59 void CQValidatorBound::force(const QString & input) const
60 {
61  const_cast<CQValidatorBound *>(this)->mValidBound = input;
62 
64 }
65 
66 CQValidatorDouble::CQValidatorDouble(QLineEdit * parent, const char * name):
67  CQValidator< QLineEdit >(parent, &QLineEdit::text, name),
68  mpDoubleValidator(new QDoubleValidator(-std::numeric_limits< C_FLOAT64 >::max(), std::numeric_limits< C_FLOAT64 >::max(), std::numeric_limits< C_FLOAT64 >::digits10, this))
69 {}
70 
71 QValidator::State CQValidatorDouble::validate(QString & input, int & pos) const
72 {
73  if (mpDoubleValidator->validate(input, pos) == Acceptable)
74  return CQValidator< QLineEdit >::validate(input, pos);
75 
76  setColor(Invalid);
77  return Intermediate;
78 }
79 
80 void CQValidatorDouble::setRange(const C_FLOAT64 & lowerBound, const C_FLOAT64 & upperBound)
81 {mpDoubleValidator->setRange(lowerBound, upperBound, std::numeric_limits< C_FLOAT64 >::digits10);}
82 
83 CQValidatorInt::CQValidatorInt(QLineEdit * parent, const char * name):
84  CQValidator< QLineEdit >(parent, &QLineEdit::text, name),
85  mpIntValidator(new QIntValidator(std::numeric_limits< int >::min(),
86  std::numeric_limits< int >::max(), this))
87 {}
88 
89 QValidator::State CQValidatorInt::validate(QString & input, int & pos) const
90 {
91  if (mpIntValidator->validate(input, pos) == Acceptable)
92  return CQValidator< QLineEdit >::validate(input, pos);
93 
94  setColor(Invalid);
95  return Intermediate;
96 }
97 
98 void CQValidatorInt::setRange(const int & lowerBound, const int & upperBound)
99 {mpIntValidator->setRange(lowerBound, upperBound);}
CQValidatorInt(QLineEdit *parent, const char *name=0)
Definition: CQValidator.cpp:83
virtual State validate(QString &input, int &pos) const
Definition: CQValidator.cpp:89
QIntValidator * mpIntValidator
Definition: CQValidator.h:171
CQValidatorNotEmpty(QLineEdit *parent, const char *name=0)
Definition: CQValidator.cpp:21
QDoubleValidator * mpDoubleValidator
Definition: CQValidator.h:156
virtual void force(const QString &input) const
Definition: CQValidator.cpp:59
QString mValidBound
Definition: CQValidator.h:141
virtual State validate(QString &input, int &pos) const
Definition: CQValidator.cpp:71
QDoubleValidator * mpDoubleValidator
Definition: CQValidator.h:137
virtual void force(const QString &input) const
Definition: CQValidator.h:77
#define C_FLOAT64
Definition: copasi.h:92
void setRange(const C_FLOAT64 &lowerBound, const C_FLOAT64 &upperBound)
Definition: CQValidator.cpp:80
void setRange(const int &lowerBound, const int &upperBound)
Definition: CQValidator.cpp:98
CQValidatorBound(QLineEdit *parent, const QString &sign)
Definition: CQValidator.cpp:34
virtual State validate(QString &input, int &pos) const
Definition: CQValidator.cpp:41
virtual State validate(QString &input, int &pos) const
Definition: CQValidator.cpp:25
virtual State validate(QString &input, int &) const
Definition: CQValidator.h:51
CQValidatorDouble(QLineEdit *parent, const char *name=0)
Definition: CQValidator.cpp:66
State setColor(const State &state) const
Definition: CQValidator.h:84
#define min(a, b)
Definition: f2c.h:175
#define max(a, b)
Definition: f2c.h:176