QAction: add QT_DEPRECATED_VERSION_6_0 to deprecated methods

And fix all the new warnings.

Task-number: QTBUG-104857
Change-Id: I2a5791f495575d71d2344429aca3363f9922e31b
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 4b9c738185c771127eb8e7c73868f60bd31f7fce)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ivan Solovev 2022-07-18 15:10:15 +02:00 committed by Qt Cherry-pick Bot
parent 8523b68b51
commit d8e584c7a6
4 changed files with 16 additions and 5 deletions

View File

@ -514,14 +514,14 @@ QList<QObject*> QAction::associatedObjects() const
/*!
\fn QWidget *QAction::parentWidget() const
\deprecated Use parent() with qobject_cast() instead.
\deprecated [6.0] Use parent() with qobject_cast() instead.
Returns the parent widget.
*/
/*!
\fn QList<QWidget*> QAction::associatedWidgets() const
\deprecated Use associatedObjects() with qobject_cast() instead.
\deprecated [6.0] Use associatedObjects() with qobject_cast() instead.
Returns a list of widgets this action has been added to.
@ -530,7 +530,7 @@ QList<QObject*> QAction::associatedObjects() const
/*!
\fn QList<QWidget*> QAction::associatedGraphicsWidgets() const
\deprecated Use associatedObjects() with qobject_cast() instead.
\deprecated [6.0] Use associatedObjects() with qobject_cast() instead.
Returns a list of graphics widgets this action has been added to.

View File

@ -84,6 +84,7 @@ public:
QWidget, QMenu, and QGraphicsWidget can be expected to be fully defined.
*/
template<typename T = QWidget*>
QT_DEPRECATED_VERSION_X_6_0("Use parent() with qobject_cast() instead")
T parentWidget() const
{
auto result = parent();
@ -93,6 +94,7 @@ public:
}
template<typename T = QWidget*>
QT_DEPRECATED_VERSION_X_6_0("Use associatedObjects() with qobject_cast() instead")
QList<T> associatedWidgets() const
{
QList<T> result;
@ -102,6 +104,7 @@ public:
return result;
}
template<typename T = QGraphicsWidget*>
QT_DEPRECATED_VERSION_X_6_0("Use associatedObjects() with qobject_cast() instead")
QList<T> associatedGraphicsWidgets() const
{
QList<T> result;

View File

@ -215,13 +215,21 @@ void QMenuPrivate::syncPlatformMenu()
platformMenu->setEnabled(q->isEnabled());
}
static QWidget *getParentWidget(const QAction *action)
{
auto result = action->parent();
while (result && !qobject_cast<QWidget *>(result))
result = result->parent();
return static_cast<QWidget *>(result);
}
void QMenuPrivate::copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item)
{
item->setText(action->text());
item->setIsSeparator(action->isSeparator());
if (action->isIconVisibleInMenu()) {
item->setIcon(action->icon());
if (QWidget *w = action->parentWidget()) {
if (QWidget *w = getParentWidget(action)) {
QStyleOption opt;
opt.initFrom(w);
item->setIconSize(w->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, w));

View File

@ -4671,7 +4671,7 @@ void tst_QLineEdit::sideWidgets()
template <class T> T *findAssociatedWidget(const QAction *a)
{
foreach (QWidget *w, a->associatedWidgets()) {
foreach (QObject *w, a->associatedObjects()) {
if (T *result = qobject_cast<T *>(w))
return result;
}