QSpinBox: add new signal textChanged(QString)

Add a new signal textChanged(QString) as a replacement for
valueChanged(QString) so valueChanged(QString) can be removed with Qt6.
This removes the ambiguous valueChanged() signal and also matches the
'text' property naming.

Change-Id: I0676a7112f70add20a3a7ef9381268cd9b8a5851
Reviewed-by: Konstantin Shegunov <kshegunov@gmail.com>
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
bb10
Christian Ehrlicher 2019-02-18 22:18:24 +01:00 committed by Shawn Rutledge
parent b33eb93891
commit 9eb50751b8
4 changed files with 59 additions and 16 deletions

View File

@ -252,7 +252,7 @@ QString QAbstractSpinBox::text() const
All values are displayed with the prefix and suffix (if set), \e
except for the special value, which only shows the special value
text. This special text is passed in the QSpinBox::valueChanged()
text. This special text is passed in the QSpinBox::textChanged()
signal that passes a QString.
To turn off the special-value text display, call this function
@ -342,18 +342,18 @@ void QAbstractSpinBox::setReadOnly(bool enable)
\since 4.3
If keyboard tracking is enabled (the default), the spinbox
emits the valueChanged() signal while the new value is being
entered from the keyboard.
emits the valueChanged() and textChanged() signals while the
new value is being entered from the keyboard.
E.g. when the user enters the value 600 by typing 6, 0, and 0,
the spinbox emits 3 signals with the values 6, 60, and 600
respectively.
If keyboard tracking is disabled, the spinbox doesn't emit the
valueChanged() signal while typing. It emits the signal later,
when the return key is pressed, when keyboard focus is lost, or
when other spinbox functionality is used, e.g. pressing an arrow
key.
valueChanged() and textChanged() signals while typing. It emits
the signals later, when the return key is pressed, when keyboard
focus is lost, or when other spinbox functionality is used, e.g.
pressing an arrow key.
*/
bool QAbstractSpinBox::keyboardTracking() const

View File

@ -128,9 +128,10 @@ public:
manually. The spin box supports integer values but can be extended to
use different strings with validate(), textFromValue() and valueFromText().
Every time the value changes QSpinBox emits two valueChanged() signals,
one providing an int and the other a QString. The QString overload
provides the value with both prefix() and suffix().
Every time the value changes QSpinBox emits valueChanged() and
textChanged() signals, the former providing a int and the latter
a QString. The textChanged() signal provides the value with both
prefix() and suffix().
The current value can be fetched with value() and set with setValue().
Clicking the up/down buttons or using the keyboard accelerator's
@ -182,13 +183,24 @@ public:
The new value's integer value is passed in \a i.
*/
/*!
\fn void QSpinBox::textChanged(const QString &text)
\since 5.14
This signal is emitted whenever the spin box's text is changed.
The new text is passed in \a text with prefix() and suffix().
*/
#if QT_DEPRECATED_SINCE(5, 14)
/*!
\fn void QSpinBox::valueChanged(const QString &text)
\overload
\obsolete Use textChanged(QString) instead
The new value is passed in \a text with prefix() and suffix().
*/
#endif
/*!
Constructs a spin box with 0 as minimum value and 99 as maximum value, a
@ -594,9 +606,9 @@ void QSpinBox::fixup(QString &input) const
values but can be extended to use different strings with
validate(), textFromValue() and valueFromText().
Every time the value changes QDoubleSpinBox emits two
valueChanged() signals, one taking providing a double and the other
a QString. The QString overload provides the value with both
Every time the value changes QDoubleSpinBox emits valueChanged() and
textChanged() signals, the former providing a double and the latter
a QString. The textChanged() signal provides the value with both
prefix() and suffix(). The current value can be fetched with
value() and set with setValue().
@ -643,13 +655,24 @@ void QSpinBox::fixup(QString &input) const
The new value is passed in \a d.
*/
/*!
\fn void QDoubleSpinBox::textChanged(const QString &text)
\since 5.14
This signal is emitted whenever the spin box's text is changed.
The new text is passed in \a text with prefix() and suffix().
*/
#if QT_DEPRECATED_SINCE(5, 14)
/*!
\fn void QDoubleSpinBox::valueChanged(const QString &text);
\overload
\obsolete Use textChanged(QString) instead
The new value is passed in \a text with prefix() and suffix().
*/
#endif
/*!
Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value,
@ -1068,7 +1091,13 @@ void QSpinBoxPrivate::emitSignals(EmitPolicy ep, const QVariant &old)
if (ep != NeverEmit) {
pendingEmit = false;
if (ep == AlwaysEmit || value != old) {
#if QT_DEPRECATED_SINCE(5, 14)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit q->valueChanged(edit->displayText());
QT_WARNING_POP
#endif
emit q->textChanged(edit->displayText());
emit q->valueChanged(value.toInt());
}
}
@ -1219,7 +1248,13 @@ void QDoubleSpinBoxPrivate::emitSignals(EmitPolicy ep, const QVariant &old)
if (ep != NeverEmit) {
pendingEmit = false;
if (ep == AlwaysEmit || value != old) {
#if QT_DEPRECATED_SINCE(5, 14)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit q->valueChanged(edit->displayText());
QT_WARNING_POP
#endif
emit q->textChanged(edit->displayText());
emit q->valueChanged(value.toDouble());
}
}

View File

@ -106,7 +106,11 @@ public Q_SLOTS:
Q_SIGNALS:
void valueChanged(int);
void textChanged(const QString &);
#if QT_DEPRECATED_SINCE(5, 14)
QT_DEPRECATED_X("Use textChanged(QString) instead")
void valueChanged(const QString &);
#endif
private:
Q_DISABLE_COPY(QSpinBox)
@ -168,7 +172,11 @@ public Q_SLOTS:
Q_SIGNALS:
void valueChanged(double);
void textChanged(const QString &);
#if QT_DEPRECATED_SINCE(5, 14)
QT_DEPRECATED_X("Use textChanged(QString) instead")
void valueChanged(const QString &);
#endif
private:
Q_DISABLE_COPY(QDoubleSpinBox)

View File

@ -206,7 +206,7 @@ private slots:
void stepModifierPressAndHold_data();
void stepModifierPressAndHold();
public slots:
void valueChangedHelper(const QString &);
void textChangedHelper(const QString &);
void valueChangedHelper(int);
private:
QStringList actualTexts;
@ -474,7 +474,7 @@ void tst_QSpinBox::setPrefixSuffix()
QCOMPARE(spin.cleanText(), expectedCleanText);
}
void tst_QSpinBox::valueChangedHelper(const QString &text)
void tst_QSpinBox::textChangedHelper(const QString &text)
{
actualTexts << text;
}
@ -552,7 +552,7 @@ void tst_QSpinBox::setTracking()
QSpinBox spin(0);
spin.setKeyboardTracking(tracking);
spin.show();
connect(&spin, SIGNAL(valueChanged(QString)), this, SLOT(valueChangedHelper(QString)));
connect(&spin, &QSpinBox::textChanged, this, &tst_QSpinBox::textChangedHelper);
keys.simulate(&spin);
QCOMPARE(actualTexts, texts);