QButtonGroup: remove deprecated signals

Task-number: QTBUG-80906
Change-Id: I6f697b0a070ba4c401117fe7cdf02429b47d9a11
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
Vitaly Fanaskov 2020-01-31 15:20:41 +01:00
parent 511cb760ee
commit 0b325602b1
7 changed files with 22 additions and 132 deletions

View File

@ -67,7 +67,7 @@ Window::Window(QWidget *parent)
connect(m_ui.easingCurvePicker, &QListWidget::currentRowChanged,
this, &Window::curveChanged);
connect(m_ui.buttonGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
connect(m_ui.buttonGroup, &QButtonGroup::buttonClicked,
this, &Window::pathChanged);
connect(m_ui.periodSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &Window::periodChanged);

View File

@ -172,15 +172,16 @@ void MainWindow::changeStyle(bool checked)
//! [4]
//! [5]
void MainWindow::changeSize(int id, bool checked)
void MainWindow::changeSize(QAbstractButton *button, bool checked)
{
if (!checked)
return;
const bool other = id == int(OtherSize);
const int index = sizeButtonGroup->id(button);
const bool other = index == int(OtherSize);
const int extent = other
? otherSpinBox->value()
: QApplication::style()->pixelMetric(static_cast<QStyle::PixelMetric>(id));
: QApplication::style()->pixelMetric(static_cast<QStyle::PixelMetric>(index));
previewArea->setSize(QSize(extent, extent));
otherSpinBox->setEnabled(other);
@ -188,7 +189,7 @@ void MainWindow::changeSize(int id, bool checked)
void MainWindow::triggerChangeSize()
{
changeSize(sizeButtonGroup->checkedId(), true);
changeSize(sizeButtonGroup->checkedButton(), true);
}
//! [5]
@ -372,7 +373,7 @@ QWidget *MainWindow::createIconSizeGroupBox()
sizeButtonGroup = new QButtonGroup(this);
sizeButtonGroup->setExclusive(true);
connect(sizeButtonGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled),
connect(sizeButtonGroup, &QButtonGroup::buttonToggled,
this, &MainWindow::changeSize);
QRadioButton *smallRadioButton = new QRadioButton;

View File

@ -62,6 +62,7 @@ class QActionGroup;
class QLabel;
class QButtonGroup;
class QTableWidget;
class QAbstractButton;
QT_END_NAMESPACE
class IconPreviewArea;
class IconSizeSpinBox;
@ -81,7 +82,7 @@ public:
private slots:
void about();
void changeStyle(bool checked);
void changeSize(int, bool);
void changeSize(QAbstractButton *button, bool);
void triggerChangeSize();
void changeIcon();
void addSampleImages();

View File

@ -413,16 +413,8 @@ void QAbstractButtonPrivate::emitClicked()
QPointer<QAbstractButton> guard(q);
emit q->clicked(checked);
#if QT_CONFIG(buttongroup)
if (guard && group) {
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit group->buttonClicked(group->id(q));
if (guard && group)
QT_WARNING_POP
#endif
emit group->buttonClicked(q);
}
if (guard && group)
emit group->buttonClicked(q);
#endif
}
@ -432,16 +424,8 @@ void QAbstractButtonPrivate::emitPressed()
QPointer<QAbstractButton> guard(q);
emit q->pressed();
#if QT_CONFIG(buttongroup)
if (guard && group) {
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit group->buttonPressed(group->id(q));
if (guard && group)
QT_WARNING_POP
#endif
emit group->buttonPressed(q);
}
if (guard && group)
emit group->buttonPressed(q);
#endif
}
@ -451,16 +435,8 @@ void QAbstractButtonPrivate::emitReleased()
QPointer<QAbstractButton> guard(q);
emit q->released();
#if QT_CONFIG(buttongroup)
if (guard && group) {
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit group->buttonReleased(group->id(q));
if (guard && group)
QT_WARNING_POP
#endif
emit group->buttonReleased(q);
}
if (guard && group)
emit group->buttonReleased(q);
#endif
}
@ -470,16 +446,8 @@ void QAbstractButtonPrivate::emitToggled(bool checked)
QPointer<QAbstractButton> guard(q);
emit q->toggled(checked);
#if QT_CONFIG(buttongroup)
if (guard && group) {
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit group->buttonToggled(group->id(q), checked);
if (guard && group)
QT_WARNING_POP
#endif
emit group->buttonToggled(q, checked);
}
if (guard && group)
emit group->buttonToggled(q, checked);
#endif
}

View File

@ -162,16 +162,6 @@ void QButtonGroup::setExclusive(bool exclusive)
\sa checkedButton(), QAbstractButton::clicked()
*/
/*!
\fn void QButtonGroup::buttonClicked(int id)
\obsolete
This signal is emitted when a button with the given \a id is
clicked.
\sa checkedButton(), QAbstractButton::clicked()
*/
/*!
\fn void QButtonGroup::buttonPressed(QAbstractButton *button)
\since 4.2
@ -181,17 +171,6 @@ void QButtonGroup::setExclusive(bool exclusive)
\sa QAbstractButton::pressed()
*/
/*!
\fn void QButtonGroup::buttonPressed(int id)
\since 4.2
\obsolete
This signal is emitted when a button with the given \a id is
pressed down.
\sa QAbstractButton::pressed()
*/
/*!
\fn void QButtonGroup::buttonReleased(QAbstractButton *button)
\since 4.2
@ -201,17 +180,6 @@ void QButtonGroup::setExclusive(bool exclusive)
\sa QAbstractButton::released()
*/
/*!
\fn void QButtonGroup::buttonReleased(int id)
\since 4.2
\obsolete
This signal is emitted when a button with the given \a id is
released.
\sa QAbstractButton::released()
*/
/*!
\fn void QButtonGroup::buttonToggled(QAbstractButton *button, bool checked)
\since 5.2
@ -222,17 +190,6 @@ void QButtonGroup::setExclusive(bool exclusive)
\sa QAbstractButton::toggled()
*/
/*!
\fn void QButtonGroup::buttonToggled(int id, bool checked)
\since 5.2
\obsolete
This signal is emitted when a button with the given \a id is toggled.
\a checked is true if the button is checked, or false if the button is unchecked.
\sa QAbstractButton::toggled()
*/
/*!
Adds the given \a button to the button group. If \a id is -1,

View File

@ -81,16 +81,6 @@ Q_SIGNALS:
void buttonPressed(QAbstractButton *);
void buttonReleased(QAbstractButton *);
void buttonToggled(QAbstractButton *, bool);
#if QT_DEPRECATED_SINCE(5, 15)
QT_DEPRECATED_VERSION_X_5_15("Use QButtonGroup::buttonClicked(QAbstractButton *) instead")
void buttonClicked(int);
QT_DEPRECATED_VERSION_X_5_15("Use QButtonGroup::buttonPressed(QAbstractButton *) instead")
void buttonPressed(int);
QT_DEPRECATED_VERSION_X_5_15("Use QButtonGroup::buttonReleased(QAbstractButton *) instead")
void buttonReleased(int);
QT_DEPRECATED_VERSION_X_5_15("Use QButtonGroup::buttonToggled(QAbstractButton *, bool) instead")
void buttonToggled(int, bool);
#endif
private:
Q_DISABLE_COPY(QButtonGroup)

View File

@ -280,67 +280,43 @@ void tst_QButtonGroup::testSignals()
qRegisterMetaType<QAbstractButton *>("QAbstractButton *");
QSignalSpy clickedSpy(&buttons, SIGNAL(buttonClicked(QAbstractButton*)));
QSignalSpy clickedIdSpy(&buttons, SIGNAL(buttonClicked(int)));
QSignalSpy pressedSpy(&buttons, SIGNAL(buttonPressed(QAbstractButton*)));
QSignalSpy pressedIdSpy(&buttons, SIGNAL(buttonPressed(int)));
QSignalSpy releasedSpy(&buttons, SIGNAL(buttonReleased(QAbstractButton*)));
QSignalSpy releasedIdSpy(&buttons, SIGNAL(buttonReleased(int)));
pb1.animateClick();
QTestEventLoop::instance().enterLoop(1);
QCOMPARE(clickedSpy.count(), 1);
QCOMPARE(clickedIdSpy.count(), 1);
int expectedId = -2;
QCOMPARE(clickedIdSpy.takeFirst().at(0).toInt(), expectedId);
QCOMPARE(pressedSpy.count(), 1);
QCOMPARE(pressedIdSpy.count(), 1);
QCOMPARE(pressedIdSpy.takeFirst().at(0).toInt(), expectedId);
QCOMPARE(releasedSpy.count(), 1);
QCOMPARE(releasedIdSpy.count(), 1);
QCOMPARE(releasedIdSpy.takeFirst().at(0).toInt(), expectedId);
clickedSpy.clear();
clickedIdSpy.clear();
pressedSpy.clear();
pressedIdSpy.clear();
releasedSpy.clear();
releasedIdSpy.clear();
pb2.animateClick();
QTestEventLoop::instance().enterLoop(1);
QCOMPARE(clickedSpy.count(), 1);
QCOMPARE(clickedIdSpy.count(), 1);
QCOMPARE(clickedIdSpy.takeFirst().at(0).toInt(), 23);
QCOMPARE(pressedSpy.count(), 1);
QCOMPARE(pressedIdSpy.count(), 1);
QCOMPARE(pressedIdSpy.takeFirst().at(0).toInt(), 23);
QCOMPARE(releasedSpy.count(), 1);
QCOMPARE(releasedIdSpy.count(), 1);
QCOMPARE(releasedIdSpy.takeFirst().at(0).toInt(), 23);
QSignalSpy toggledSpy(&buttons, SIGNAL(buttonToggled(QAbstractButton*, bool)));
QSignalSpy toggledIdSpy(&buttons, SIGNAL(buttonToggled(int, bool)));
pb1.setCheckable(true);
pb2.setCheckable(true);
pb1.toggle();
QCOMPARE(toggledSpy.count(), 1);
QCOMPARE(toggledIdSpy.count(), 1);
pb2.toggle();
QCOMPARE(toggledSpy.count(), 3); // equals 3 since pb1 and pb2 are both toggled
QCOMPARE(toggledIdSpy.count(), 3);
pb1.setCheckable(false);
pb2.setCheckable(false);
pb1.toggle();
QCOMPARE(toggledSpy.count(), 3);
QCOMPARE(toggledIdSpy.count(), 3);
}
void tst_QButtonGroup::task106609()
@ -372,7 +348,6 @@ void tst_QButtonGroup::task106609()
qRegisterMetaType<QAbstractButton*>("QAbstractButton*");
QSignalSpy spy1(buttons, SIGNAL(buttonClicked(QAbstractButton*)));
QSignalSpy spy2(buttons, SIGNAL(buttonClicked(int)));
QApplication::setActiveWindow(&dlg);
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&dlg));
@ -381,8 +356,6 @@ void tst_QButtonGroup::task106609()
radio1->setChecked(true);
QTestEventLoop::instance().enterLoop(1);
//qDebug() << "int:" << spy2.count() << "QAbstractButton*:" << spy1.count();
QCOMPARE(spy2.count(), 2);
QCOMPARE(spy1.count(), 2);
}
@ -427,11 +400,12 @@ public:
: group(group)
, deleteButton(deleteButton)
{
connect(group, SIGNAL(buttonClicked(int)), SLOT(buttonClicked(int)));
connect(group, &QButtonGroup::buttonClicked,
this, &task209485_ButtonDeleter::buttonClicked);
}
private slots:
void buttonClicked(int)
void buttonClicked()
{
if (deleteButton)
group->removeButton(group->buttons().first());
@ -447,7 +421,7 @@ void tst_QButtonGroup::task209485_removeFromGroupInEventHandler_data()
QTest::addColumn<bool>("deleteButton");
QTest::addColumn<int>("signalCount");
QTest::newRow("buttonPress 1") << true << 1;
QTest::newRow("buttonPress 2") << false << 2;
QTest::newRow("buttonPress 2") << false << 1;
}
void tst_QButtonGroup::task209485_removeFromGroupInEventHandler()
@ -463,12 +437,11 @@ void tst_QButtonGroup::task209485_removeFromGroupInEventHandler()
task209485_ButtonDeleter buttonDeleter(&group, deleteButton);
QSignalSpy spy1(&group, SIGNAL(buttonClicked(QAbstractButton*)));
QSignalSpy spy2(&group, SIGNAL(buttonClicked(int)));
// NOTE: Reintroducing the bug of this task will cause the following line to crash:
QTest::mouseClick(button, Qt::LeftButton);
QCOMPARE(spy1.count() + spy2.count(), signalCount);
QCOMPARE(spy1.count(), signalCount);
}
void tst_QButtonGroup::autoIncrementId()