42 #include <private/qabstractspinbox_p.h> 58 #ifdef QSPINBOX_QSBDEBUG 59 # define QSBDEBUG qDebug 61 # define QSBDEBUG if (false) qDebug 94 double round(
double input)
const;
265 return d->value.toInt();
309 d->cachedSizeHint =
QSize();
349 d->cachedSizeHint =
QSize();
369 return d->stripped(
d->edit->displayText());
390 return d->singleStep.toInt();
422 return d->minimum.toInt();
429 d->setRange(m, (
d->variantCompare(
d->maximum, m) > 0 ?
d->maximum : m));
453 return d->maximum.toInt();
460 d->setRange((
d->variantCompare(
d->minimum, m) < 0 ?
d->minimum : m), m);
501 if (
qAbs(value) >= 1000 || value == INT_MIN) {
531 int pos =
d->edit->cursorPosition();
533 return d->validateAndInterpret(copy, pos, state).toInt();
544 d->validateAndInterpret(text, pos, state);
670 return d->value.toDouble();
752 d->cachedSizeHint =
QSize();
772 return d->stripped(
d->edit->displayText());
791 return d->singleStep.toDouble();
827 return d->minimum.toDouble();
835 d->setRange(m, (
d->variantCompare(
d->maximum, m) > 0 ?
d->maximum : m));
861 return d->maximum.toDouble();
869 d->setRange((
d->variantCompare(
d->minimum, m) < 0 ?
d->minimum : m), m);
950 if (
qAbs(value) >= 1000.0) {
973 int pos =
d->edit->cursorPosition();
975 return d->validateAndInterpret(copy, pos, state).toDouble();
986 d->validateAndInterpret(text, pos, state);
1024 pendingEmit =
false;
1026 emit q->valueChanged(edit->displayText());
1040 return q->textFromValue(value.
toInt());
1051 return QVariant(q->valueFromText(text));
1064 if (cachedText == input && !input.
isEmpty()) {
1065 state = cachedState;
1066 QSBDEBUG() <<
"cachedText was '" << cachedText <<
"' state was " 1067 << state <<
" and value was " << cachedValue;
1071 const int max =
maximum.toInt();
1072 const int min =
minimum.toInt();
1075 QSBDEBUG() <<
"input" << input <<
"copy" << copy;
1079 if (max != min && (copy.isEmpty()
1083 QSBDEBUG() << __FILE__ << __LINE__<<
"num is set to" << num;
1084 }
else if (copy.startsWith(
QLatin1Char(
'-')) && min >= 0) {
1094 QSBDEBUG() << __FILE__ << __LINE__<<
"num is set to" << num;
1097 }
else if (num >= min && num <= max) {
1099 }
else if (max == min) {
1102 if ((num >= 0 && num > max) || (num < 0 && num < min)) {
1104 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1107 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Intermediate";
1112 num = max > 0 ? min : max;
1115 cachedState = state;
1118 QSBDEBUG() <<
"cachedText is set to '" << cachedText <<
"' state is set to " 1119 << state <<
" and value is set to " << cachedValue;
1151 pendingEmit =
false;
1153 emit q->valueChanged(edit->displayText());
1167 return QVariant(q->valueFromText(f));
1196 if (cachedText == input && !input.
isEmpty()) {
1197 state = cachedState;
1198 QSBDEBUG() <<
"cachedText was '" << cachedText <<
"' state was " 1199 << state <<
" and value was " << cachedValue;
1202 const double max =
maximum.toDouble();
1203 const double min =
minimum.toDouble();
1206 QSBDEBUG() <<
"input" << input <<
"copy" << copy;
1207 int len = copy.
size();
1209 const bool plus = max >= 0;
1210 const bool minus = min <= 0;
1235 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1238 }
else if (len > 1) {
1241 if (dec + 1 < copy.size() && copy.at(dec + 1) ==
locale.
decimalPoint() && pos == dec + 1) {
1242 copy.remove(dec + 1, 1);
1245 if (copy.size() - dec >
decimals + 1) {
1246 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1250 for (
int i=dec + 1; i<copy.size(); ++i) {
1252 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1258 const QChar &last = copy.at(len - 1);
1259 const QChar &secondLast = copy.at(len - 2);
1263 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1267 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1276 QSBDEBUG() << __FILE__ << __LINE__ <<
locale << copy << num << ok;
1282 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1286 const int len = copy.size();
1287 for (
int i=0; i<len- 1; ++i) {
1289 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1302 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1310 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1311 }
else if (num >= min && num <= max) {
1313 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Acceptable";
1314 }
else if (max == min) {
1316 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1318 if ((num >= 0 && num > max) || (num < 0 && num < min)) {
1320 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Invalid";
1323 QSBDEBUG() << __FILE__ << __LINE__<<
"state is set to Intermediate";
1330 num = max > 0 ? min : max;
1335 cachedState = state;
1348 return q->textFromValue(f.
toDouble());
1411 #endif // QT_NO_SPINBOX static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVariant class acts like a union for the most common Qt data types.
void emitSignals(EmitPolicy ep, const QVariant &)
QSpinBox(QWidget *parent=0)
Constructs a spin box with 0 as minimum value and 99 as maximum value, a step value of 1...
void setValue(double val)
bool event(QEvent *event)
Reimplemented Function
#define QT_END_NAMESPACE
This macro expands to.
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
QString cleanText() const
void setRange(double min, double max)
Convenience function to set the minimum and maximum values with a single function call...
double round(double input) const
Rounds to a double value that is restricted to decimals.
static glyph_t stripped(glyph_t glyph)
virtual QValidator::State validate(QString &input, int &pos) const
Reimplemented Function
virtual QString textFromValue(const QVariant &n) const
virtual QString textFromValue(int val) const
This virtual function is used by the spin box whenever it needs to display the given value...
QAbstractSpinBox(QWidget *parent=0)
Constructs an abstract spinbox with the given parent with default wrapping , and alignment properties...
virtual void fixup(QString &str) const
Reimplemented Function
virtual QString textFromValue(const QVariant &n) const
Virtual method called that calls the public textFromValue() functions in the subclasses.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Q_DECL_CONSTEXPR T qAbs(const T &t)
bool isPrint() const
Returns true if the character is a printable character; otherwise returns false.
void setPrefix(const QString &prefix)
void setRange(int min, int max)
Convenience function to set the minimum, and maximum values with a single function call...
The QChar class provides a 16-bit Unicode character.
QString toString(qlonglong i) const
Returns a localized string representation of i.
void setDecimals(int prec)
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
void setObjectName(const QString &name)
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
#define QT_BEGIN_NAMESPACE
This macro expands to.
QDoubleSpinBox(QWidget *parent=0)
Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value, a step value of 1...
void setSuffix(const QString &suffix)
QChar decimalPoint() const
Returns the decimal point character of this locale.
QChar groupSeparator() const
Returns the group separator character of this locale.
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
virtual QVariant valueFromText(const QString &n) const
void setSingleStep(double val)
QString cleanText() const
void setSuffix(const QString &suffix)
void setSingleStep(int val)
virtual void fixup(QString &str) const
Reimplemented Function
void emitSignals(EmitPolicy ep, const QVariant &)
void setMinimum(double min)
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
virtual QString textFromValue(double val) const
This virtual function is used by the spin box whenever it needs to display the given value...
QVariant validateAndInterpret(QString &input, int &pos, QValidator::State &state) const
QVariant validateAndInterpret(QString &input, int &pos, QValidator::State &state) const
virtual QVariant valueFromText(const QString &n) const
#define Q_DECLARE_PUBLIC(Class)
double toDouble(const QString &s, bool *ok=0) const
Returns the double represented by the localized string s, or 0.0 if the conversion failed...
The QDoubleSpinBox class provides a spin box widget that takes doubles.
QObject * parent() const
Returns a pointer to the parent object.
virtual int valueFromText(const QString &text) const
This virtual function is used by the spin box whenever it needs to interpret text entered by the user...
void setPrefix(const QString &prefix)
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
double toDouble(bool *ok=0) const
Returns the string converted to a double value.
virtual double valueFromText(const QString &text) const
This virtual function is used by the spin box whenever it needs to interpret text entered by the user...
State
This enum type defines the states in which a validated string can exist.
The QSpinBox class provides a spin box widget.
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
virtual QValidator::State validate(QString &input, int &pos) const
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
bool event(QEvent *event)
Reimplemented Function
int toInt(const QString &s, bool *ok=0, int base=0) const
Returns the int represented by the localized string s, using base base.
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
void setMaximum(double max)
static const KeyPair *const end
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
double singleStep() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.