home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qvalidator.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  5KB  |  165 lines

  1. /****************************************************************************
  2. ** $Id$
  3. **
  4. ** Definition of validator classes
  5. **
  6. ** Created : 970610
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the widgets module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QVALIDATOR_H
  39. #define QVALIDATOR_H
  40.  
  41. #ifndef QT_H
  42. #include "qobject.h"
  43. #include "qstring.h" // char*->QString conversion
  44. #include "qregexp.h" // QString->QRegExp conversion
  45. #endif // QT_H
  46.  
  47. #ifndef QT_NO_VALIDATOR
  48.  
  49.  
  50. class Q_EXPORT QValidator : public QObject
  51. {
  52.     Q_OBJECT
  53. public:
  54.     QValidator( QObject * parent, const char *name = 0 );
  55.     ~QValidator();
  56.  
  57.     enum State { Invalid, Intermediate, Valid=Intermediate, Acceptable };
  58.  
  59.     virtual State validate( QString &, int & ) const = 0;
  60.     virtual void fixup( QString & ) const;
  61.  
  62. private:
  63. #if defined(Q_DISABLE_COPY)
  64.     QValidator( const QValidator & );
  65.     QValidator& operator=( const QValidator & );
  66. #endif
  67. };
  68.  
  69.  
  70. class Q_EXPORT QIntValidator : public QValidator
  71. {
  72.     Q_OBJECT
  73.     Q_PROPERTY( int bottom READ bottom WRITE setBottom )
  74.     Q_PROPERTY( int top READ top WRITE setTop )
  75.  
  76. public:
  77.     QIntValidator( QObject * parent, const char *name = 0 );
  78.     QIntValidator( int bottom, int top,
  79.            QObject * parent, const char *name = 0 );
  80.     ~QIntValidator();
  81.  
  82.     QValidator::State validate( QString &, int & ) const;
  83.  
  84.     void setBottom( int );
  85.     void setTop( int );
  86.     virtual void setRange( int bottom, int top );
  87.  
  88.     int bottom() const { return b; }
  89.     int top() const { return t; }
  90.  
  91. private:
  92. #if defined(Q_DISABLE_COPY)
  93.     QIntValidator( const QIntValidator & );
  94.     QIntValidator& operator=( const QIntValidator & );
  95. #endif
  96.  
  97.     int b, t;
  98. };
  99.  
  100.  
  101. class Q_EXPORT QDoubleValidator : public QValidator
  102. {
  103.     Q_OBJECT
  104.     Q_PROPERTY( double bottom READ bottom WRITE setBottom )
  105.     Q_PROPERTY( double top READ top WRITE setTop )
  106.     Q_PROPERTY( int decimals READ decimals WRITE setDecimals )
  107.  
  108. public:
  109.     QDoubleValidator( QObject * parent, const char *name = 0 );
  110.     QDoubleValidator( double bottom, double top, int decimals,
  111.               QObject * parent, const char *name = 0 );
  112.     ~QDoubleValidator();
  113.  
  114.     QValidator::State validate( QString &, int & ) const;
  115.  
  116.     virtual void setRange( double bottom, double top, int decimals = 0 );
  117.     void setBottom( double );
  118.     void setTop( double );
  119.     void setDecimals( int );
  120.  
  121.     double bottom() const { return b; }
  122.     double top() const { return t; }
  123.     int decimals() const { return d; }
  124.  
  125. private:
  126. #if defined(Q_DISABLE_COPY)
  127.     QDoubleValidator( const QDoubleValidator & );
  128.     QDoubleValidator& operator=( const QDoubleValidator & );
  129. #endif
  130.  
  131.     double b, t;
  132.     int d;
  133. };
  134.  
  135.  
  136. class Q_EXPORT QRegExpValidator : public QValidator
  137. {
  138.     Q_OBJECT
  139.     // Q_PROPERTY( QRegExp regExp READ regExp WRITE setRegExp )
  140.  
  141. public:
  142.     QRegExpValidator( QObject *parent, const char *name = 0 );
  143.     QRegExpValidator( const QRegExp& rx, QObject *parent,
  144.               const char *name = 0 );
  145.     ~QRegExpValidator();
  146.  
  147.     virtual QValidator::State validate( QString& input, int& pos ) const;
  148.  
  149.     void setRegExp( const QRegExp& rx );
  150.     const QRegExp& regExp() const { return r; }
  151.  
  152. private:
  153. #if defined(Q_DISABLE_COPY)
  154.     QRegExpValidator( const QRegExpValidator& );
  155.     QRegExpValidator& operator=( const QRegExpValidator& );
  156. #endif
  157.  
  158.     QRegExp r;
  159. };
  160.  
  161.  
  162. #endif // QT_NO_VALIDATOR
  163.  
  164. #endif // QVALIDATOR_H
  165.