Add widgetAdded signal for QStackedWidget and QStackedLayout
Currently, there is no signal provided when a widget is added or inserted into QStackedWidget or QStackedLayout. Emit a signal whenever a widget is added or inserted into QStackedWidget or QStackedLayout. [ChangeLog][QtWidgets][QStackedWidget] The widgetAdded() signal emits whenever a widget is added or inserted into QStackedWidget or QStackedLayout. Fixes: QTBUG-122748 Change-Id: I3bf658346a5881665214a8d8f77975aa10e497c0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
ea1409afc1
commit
2ebca8cde1
@ -113,6 +113,17 @@ QLayoutItem* QStackedLayoutPrivate::replaceAt(int idx, QLayoutItem *newitem)
|
|||||||
\sa removeWidget()
|
\sa removeWidget()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void QStackedLayout::widgetAdded(int index)
|
||||||
|
|
||||||
|
\since 6.9
|
||||||
|
|
||||||
|
This signal is emitted whenever a widget is added or inserted.
|
||||||
|
The widget's \a index is passed as parameter.
|
||||||
|
|
||||||
|
\sa addWidget(), insertWidget()
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Constructs a QStackedLayout with no parent.
|
Constructs a QStackedLayout with no parent.
|
||||||
|
|
||||||
@ -204,6 +215,7 @@ int QStackedLayout::insertWidget(int index, QWidget *widget)
|
|||||||
widget->hide();
|
widget->hide();
|
||||||
widget->lower();
|
widget->lower();
|
||||||
}
|
}
|
||||||
|
emit widgetAdded(index);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ public:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void widgetRemoved(int index);
|
void widgetRemoved(int index);
|
||||||
void currentChanged(int index);
|
void currentChanged(int index);
|
||||||
|
void widgetAdded(int index);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setCurrentIndex(int index);
|
void setCurrentIndex(int index);
|
||||||
|
@ -88,6 +88,18 @@ public:
|
|||||||
\sa removeWidget()
|
\sa removeWidget()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void QStackedWidget::widgetAdded(int index)
|
||||||
|
|
||||||
|
\since 6.9
|
||||||
|
|
||||||
|
This signal is emitted whenever a widget is added or inserted.
|
||||||
|
The widget's \a index is passed as parameter.
|
||||||
|
|
||||||
|
\sa addWidget(), insertWidget()
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Constructs a QStackedWidget with the given \a parent.
|
Constructs a QStackedWidget with the given \a parent.
|
||||||
|
|
||||||
@ -102,6 +114,8 @@ QStackedWidget::QStackedWidget(QWidget *parent)
|
|||||||
this, &QStackedWidget::widgetRemoved);
|
this, &QStackedWidget::widgetRemoved);
|
||||||
connect(d->layout, &QStackedLayout::currentChanged,
|
connect(d->layout, &QStackedLayout::currentChanged,
|
||||||
this, &QStackedWidget::currentChanged);
|
this, &QStackedWidget::currentChanged);
|
||||||
|
connect(d->layout, &QStackedLayout::widgetAdded,
|
||||||
|
this, &QStackedWidget::widgetAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -41,6 +41,7 @@ public Q_SLOTS:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void currentChanged(int);
|
void currentChanged(int);
|
||||||
void widgetRemoved(int index);
|
void widgetRemoved(int index);
|
||||||
|
void widgetAdded(int index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *e) override;
|
bool event(QEvent *e) override;
|
||||||
|
@ -31,6 +31,7 @@ private slots:
|
|||||||
void keepFocusAfterSetCurrent();
|
void keepFocusAfterSetCurrent();
|
||||||
void heigthForWidth();
|
void heigthForWidth();
|
||||||
void replaceWidget();
|
void replaceWidget();
|
||||||
|
void widgetAdded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *testWidget;
|
QWidget *testWidget;
|
||||||
@ -353,6 +354,27 @@ void tst_QStackedLayout::replaceWidget()
|
|||||||
QCOMPARE(stackLayout->currentWidget(), replaceTo);
|
QCOMPARE(stackLayout->currentWidget(), replaceTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void tst_QStackedLayout::widgetAdded()
|
||||||
|
{
|
||||||
|
QStackedLayout stackedLayout;
|
||||||
|
QSignalSpy addSpy(&stackedLayout, &QStackedLayout::widgetAdded);
|
||||||
|
QVERIFY(addSpy.isValid());
|
||||||
|
|
||||||
|
stackedLayout.addWidget(new QWidget);
|
||||||
|
QCOMPARE(addSpy.count(), 1);
|
||||||
|
QCOMPARE(addSpy.at(0).at(0).toInt(), 0);
|
||||||
|
|
||||||
|
stackedLayout.insertWidget(1, new QWidget);
|
||||||
|
QCOMPARE(addSpy.count(), 2);
|
||||||
|
QCOMPARE(addSpy.at(1).at(0).toInt(), 1);
|
||||||
|
|
||||||
|
stackedLayout.insertWidget(100, new QWidget);
|
||||||
|
QCOMPARE(addSpy.count(), 3);
|
||||||
|
QCOMPARE(addSpy.at(2).at(0).toInt(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_QStackedLayout)
|
QTEST_MAIN(tst_QStackedLayout)
|
||||||
#include "tst_qstackedlayout.moc"
|
#include "tst_qstackedlayout.moc"
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <qpushbutton.h>
|
#include <qpushbutton.h>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <qlineedit.h>
|
#include <qlineedit.h>
|
||||||
|
#include <QSignalSpy>
|
||||||
|
|
||||||
#include <QtWidgets/private/qapplication_p.h>
|
#include <QtWidgets/private/qapplication_p.h>
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ private slots:
|
|||||||
void getSetCheck();
|
void getSetCheck();
|
||||||
void testMinimumSize();
|
void testMinimumSize();
|
||||||
void dynamicPages();
|
void dynamicPages();
|
||||||
|
void widgetAdded();
|
||||||
};
|
};
|
||||||
|
|
||||||
tst_QStackedWidget::tst_QStackedWidget()
|
tst_QStackedWidget::tst_QStackedWidget()
|
||||||
@ -172,5 +174,24 @@ void tst_QStackedWidget::dynamicPages()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QStackedWidget::widgetAdded()
|
||||||
|
{
|
||||||
|
QStackedWidget stackedWidget;
|
||||||
|
QSignalSpy addSpy(&stackedWidget, &QStackedWidget::widgetAdded);
|
||||||
|
QVERIFY(addSpy.isValid());
|
||||||
|
|
||||||
|
stackedWidget.addWidget(new QWidget);
|
||||||
|
QCOMPARE(addSpy.count(), 1);
|
||||||
|
QCOMPARE(addSpy.at(0).at(0).toInt(), 0);
|
||||||
|
|
||||||
|
stackedWidget.insertWidget(1, new QWidget);
|
||||||
|
QCOMPARE(addSpy.count(), 2);
|
||||||
|
QCOMPARE(addSpy.at(1).at(0).toInt(), 1);
|
||||||
|
|
||||||
|
stackedWidget.insertWidget(100, new QWidget);
|
||||||
|
QCOMPARE(addSpy.count(), 3);
|
||||||
|
QCOMPARE(addSpy.at(2).at(0).toInt(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QStackedWidget)
|
QTEST_MAIN(tst_QStackedWidget)
|
||||||
#include "tst_qstackedwidget.moc"
|
#include "tst_qstackedwidget.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user