IntValidator.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2010 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef INTVALIDATOR_H
00011 #define INTVALIDATOR_H
00012 
00013 #include <QtGui/QValidator>
00014 
00015 /**
00016  *  An integer validator for text strings.
00017  *
00018  *  The IntValidator class extends the QValidator class to provide a validator
00019  *  for integer data types, including large integer types.  The following data
00020  *  types are supported:
00021  *  - char
00022  *  - signed char
00023  *  - unsigned char
00024  *  - short
00025  *  - unsigned short
00026  *  - int
00027  *  - unsigned int
00028  *  - long
00029  *  - unsigned long
00030  *  - int64_t
00031  *  - uint64_t
00032  *  - Int64
00033  *  - UInt64
00034  *
00035  *  The behavior of IntValidator is similar to that of QIntValidator, except
00036  *  integer types larger than int are supported.  The class defines a validation
00037  *  range bounded by a minimum and maximum value that is checked during the
00038  *  validation sequence.
00039  */
00040 template <typename T>
00041 class IntValidator : public QValidator
00042 {
00043 public:
00044    /**
00045     *  Creates an IntValidator object with a default range.
00046     *
00047     *  This constructor creates a default validator with the default minimum
00048     *  and maximum values set to std::numeric_limits<T>::min() and
00049     *  std::numeric_limits<T>::max().
00050     *
00051     *  @param   pParent
00052     *           The parent object.
00053     *
00054     *  @see     IntValidator(T, T, QObject*)
00055     */
00056    IntValidator(QObject* pParent);
00057 
00058    /**
00059     *  Creates an IntValidator object with a given range.
00060     *
00061     *  This constructor creates a validator with the validation range set to
00062     *  the given minimum and maximum values.
00063     *
00064     *  @param   minimum
00065     *           The minimum value for the validation range.
00066     *  @param   maximum
00067     *           The maximum value for the validation range.
00068     *  @param   pParent
00069     *           The parent object.
00070     *
00071     *  @see     IntValidator(QObject*)
00072     */
00073    IntValidator(T minimum, T maximum, QObject* pParent);
00074 
00075    /**
00076     *  Destroys the validator object.
00077     */
00078    virtual ~IntValidator();
00079 
00080    /**
00081     *  Sets the minimum value of the validation range.
00082     *
00083     *  @param   minimum
00084     *           The minimum value.
00085     *
00086     *  @see     setMaximum(), setRange()
00087     */
00088    void setMinimum(T minimum);
00089 
00090    /**
00091     *  Returns the minimum value of the validation range.
00092     *
00093     *  @return  The minimum value.
00094     *
00095     *  @see     maximum()
00096     */
00097    T minimum() const;
00098 
00099    /**
00100     *  Sets the maximum value of the validation range.
00101     *
00102     *  @param   maximum
00103     *           The maximum value.
00104     *
00105     *  @see     setMinimum(), setRange()
00106     */
00107    void setMaximum(T maximum);
00108 
00109    /**
00110     *  Returns the maximum value of the validation range.
00111     *
00112     *  @return  The maximum value.
00113     *
00114     *  @see     minimum()
00115     */
00116    T maximum() const;
00117 
00118    /**
00119     *  Sets the minimum and maximum values of the validation range.
00120     *
00121     *  @param   minimum
00122     *           The minimum value.
00123     *  @param   maximum
00124     *           The maximum value.
00125     *
00126     *  @see     setMinimum(), setMaximum()
00127     */
00128    void setRange(T minimum, T maximum);
00129 
00130    /**
00131     *  Validates the given text against the minimum and maximum integer values.
00132     *
00133     *  This method is typically called automatically by the widget containing
00134     *  the validator.  The implementation converts the given string to an
00135     *  integer using the QString text conversion methods (e.g. QString::toInt())
00136     *  and returns whether the string is or is not a valid integer within the
00137     *  validation range or if the string could be a valid integer with
00138     *  additional input.
00139     *
00140     *  @param   input
00141     *           The text to validate.
00142     *  @param   pos
00143     *           The cursor position.  This parameter is ignored.
00144     *
00145     *  @return  Returns QValidator::Intermediate if the input string is empty
00146     *           or if the input string contains only a positive (+) sign or
00147     *           negative (-) sign and a positive or negative value is allowed
00148     *           in the range. Returns QValidator::Acceptable if the string
00149     *           converts to a valid integer and is contained within the
00150     *           validation range. Returns QValidator::Invalid in all other
00151     *           cases.
00152     */
00153    virtual QValidator::State validate(QString& input, int& pos) const;
00154 
00155 private:
00156    IntValidator(const IntValidator& rhs);
00157    IntValidator& operator=(const IntValidator& rhs);
00158 
00159    T mMinimum;
00160    T mMaximum;
00161 };
00162 
00163 #endif

Software Development Kit - Opticks 4.9.0 Build 16218