QCheckBox: deprecate stateChanged()

[ChangeLog][QtWidgets][Deprecation Notices][QCheckBox]
stateChanged(int) has been deprecated in favor of
checkStateChanged(Qt:CheckState).

Found in API-review. Amends 5a96d13bb5abd5339cf21dd1de7a17152c71f0fc.

Change-Id: I6ff4aa38c2f43622ba4b127420aff83790785455
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit 3512fb1ec5ff088772170540c4e91b1886fbea45)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-01-18 10:38:25 +01:00 committed by Qt Cherry-pick Bot
parent 15aec9a37d
commit 02ba4b14dc
3 changed files with 22 additions and 3 deletions

View File

@ -92,9 +92,7 @@ public:
/*!
\fn void QCheckBox::stateChanged(int state)
\obsolete
Use checkStateChanged(Qt::CheckState) instead.
\deprecated [6.9] Use checkStateChanged(Qt::CheckState) instead.
*/
/*!
@ -236,7 +234,11 @@ void QCheckBox::setCheckState(Qt::CheckState state)
if (state != d->publishedState) {
d->publishedState = state;
emit checkStateChanged(state);
#if QT_DEPRECATED_SINCE(6, 9)
QT_IGNORE_DEPRECATIONS(
emit stateChanged(state);
)
#endif
}
#if QT_CONFIG(accessibility)
@ -332,7 +334,11 @@ void QCheckBox::checkStateSet()
if (state != d->publishedState) {
d->publishedState = state;
emit checkStateChanged(state);
#if QT_DEPRECATED_SINCE(6, 9)
QT_IGNORE_DEPRECATIONS(
emit stateChanged(state);
)
#endif
}
}

View File

@ -36,7 +36,10 @@ public:
void setCheckState(Qt::CheckState state);
Q_SIGNALS:
#if QT_DEPRECATED_SINCE(6, 9)
QT_MOC_COMPAT QT_DEPRECATED_VERSION_X_6_9("Use checkStateChanged() instead")
void stateChanged(int);
#endif
void checkStateChanged(Qt::CheckState);
protected:

View File

@ -215,32 +215,42 @@ void tst_QCheckBox::checkStateChanged()
Qt::CheckState cur_state = Qt::Unchecked;
QSignalSpy checkStateChangedSpy(&testWidget, &QCheckBox::checkStateChanged);
#if QT_DEPRECATED_SINCE(6, 9)
QT_IGNORE_DEPRECATIONS(
QSignalSpy stateChangedSpy(&testWidget, &QCheckBox::stateChanged);
)
#endif
connect(&testWidget, &QCheckBox::checkStateChanged, this, [&](auto state) { cur_state = state; });
testWidget.setChecked(true);
QTRY_COMPARE(checkStateChangedSpy.size(), 1);
#if QT_DEPRECATED_SINCE(6, 9)
QCOMPARE(stateChangedSpy.size(), 1);
#endif
QCOMPARE(cur_state, Qt::Checked);
QCOMPARE(testWidget.checkState(), Qt::Checked);
testWidget.setChecked(false);
QTRY_COMPARE(checkStateChangedSpy.size(), 2);
#if QT_DEPRECATED_SINCE(6, 9)
QCOMPARE(stateChangedSpy.size(), 2);
#endif
QCOMPARE(cur_state, Qt::Unchecked);
QCOMPARE(testWidget.checkState(), Qt::Unchecked);
testWidget.setCheckState(Qt::PartiallyChecked);
QTRY_COMPARE(checkStateChangedSpy.size(), 3);
#if QT_DEPRECATED_SINCE(6, 9)
QCOMPARE(stateChangedSpy.size(), 3);
#endif
QCOMPARE(cur_state, Qt::PartiallyChecked);
QCOMPARE(testWidget.checkState(), Qt::PartiallyChecked);
testWidget.setCheckState(Qt::PartiallyChecked);
QCoreApplication::processEvents();
QCOMPARE(checkStateChangedSpy.size(), 3);
#if QT_DEPRECATED_SINCE(6, 9)
QCOMPARE(stateChangedSpy.size(), 3);
#endif
}
void tst_QCheckBox::isToggleButton()