File indexing completed on 2024-04-28 04:49:51
0001 /* 0002 SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 0007 #ifndef _K3B_INT_VALIDATOR_H_ 0008 #define _K3B_INT_VALIDATOR_H_ 0009 0010 #include "k3b_export.h" 0011 #include <QValidator> 0012 class QWidget; 0013 class QString; 0014 0015 namespace K3b { 0016 /** 0017 * QValidator for integers. 0018 * 0019 * It differs from QIntValidator and KIntValidator in the fact that 0020 * it also accepts hex numbers prefixed with 0x. 0021 */ 0022 class LIBK3B_EXPORT IntValidator : public QValidator 0023 { 0024 public: 0025 /** 0026 * Constructor. Also sets the base value. 0027 */ 0028 explicit IntValidator ( QWidget * parent ); 0029 0030 /** 0031 * Constructor. Also sets the minimum, maximum, and numeric base values. 0032 */ 0033 IntValidator ( int bottom, int top, QWidget * parent ); 0034 0035 /** 0036 * Destructs the validator. 0037 */ 0038 ~IntValidator () override; 0039 0040 /** 0041 * Validates the text, and return the result. Does not modify the parameters. 0042 */ 0043 State validate ( QString &, int & ) const override; 0044 0045 /** 0046 * Fixes the text if possible, providing a valid string. The parameter may be modified. 0047 */ 0048 void fixup ( QString & ) const override; 0049 0050 /** 0051 * Sets the minimum and maximum values allowed. 0052 */ 0053 virtual void setRange ( int bottom, int top ); 0054 0055 /** 0056 * Returns the current minimum value allowed. 0057 */ 0058 virtual int bottom () const; 0059 0060 /** 0061 * Returns the current maximum value allowed. 0062 */ 0063 virtual int top () const; 0064 0065 /** 0066 * If the string starts with 0x it's assumed to be a hex number. 0067 */ 0068 static int toInt( const QString&, bool* ok = 0 ); 0069 0070 private: 0071 int m_min; 0072 int m_max; 0073 }; 0074 } 0075 0076 #endif