From 9eb50751b859cf46aa69ca5707346bd4a74a5f90 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 18 Feb 2019 22:18:24 +0100 Subject: QSpinBox: add new signal textChanged(QString) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Luca Beldi Reviewed-by: André Hartmann Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qabstractspinbox.cpp | 14 +++---- src/widgets/widgets/qspinbox.cpp | 47 +++++++++++++++++++--- src/widgets/widgets/qspinbox.h | 8 ++++ .../auto/widgets/widgets/qspinbox/tst_qspinbox.cpp | 6 +-- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 6a35dbe274..da4c2f98cf 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -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 diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index 7624b1ed3c..40044223e2 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -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()); } } diff --git a/src/widgets/widgets/qspinbox.h b/src/widgets/widgets/qspinbox.h index d2eac903fb..762dd4a46a 100644 --- a/src/widgets/widgets/qspinbox.h +++ b/src/widgets/widgets/qspinbox.h @@ -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) diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 1d106f94f3..7174c274f9 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -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); -- cgit v1.2.3