summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-07-19 17:50:22 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-07-21 15:44:16 +0000
commit13d256d114054292887c911312221e61719e2553 (patch)
treeb27529751f17758f4379884f7b51585fa0577936
parent68a2fb3ea9e69013f84ee71065515d7c05dfa916 (diff)
Designer: port away from the deprecated QAction APIs
The deprecation of QAction::associatedWidgets() results in a bit more code, because the list of associated objects can also contain QGraphicsWidget instances. So we need to explicitly qobject_cast them to QWidget* before using. Apart from that the changes are rather straightforward. Task-number: QTBUG-104968 Change-Id: I2e7c94de069cd5c9cde5e6d41ac86004a8bae6c9 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> (cherry picked from commit ca8a71e1997650a0ecf497d667cfab5a72858c18) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/designer/src/designer/qdesigner_workbench.cpp2
-rw-r--r--src/designer/src/lib/shared/actioneditor.cpp8
-rw-r--r--src/designer/src/lib/shared/actionrepository.cpp22
-rw-r--r--src/designer/src/lib/shared/qdesigner_command.cpp27
-rw-r--r--src/designer/src/lib/shared/qdesigner_menu.cpp15
-rw-r--r--src/designer/src/lib/shared/qdesigner_propertycommand.cpp10
-rw-r--r--src/designer/src/lib/uilib/abstractformbuilder.cpp2
-rw-r--r--src/linguist/linguist/formpreviewview.cpp6
8 files changed, 54 insertions, 38 deletions
diff --git a/src/designer/src/designer/qdesigner_workbench.cpp b/src/designer/src/designer/qdesigner_workbench.cpp
index ec4049c6a..fab3e026b 100644
--- a/src/designer/src/designer/qdesigner_workbench.cpp
+++ b/src/designer/src/designer/qdesigner_workbench.cpp
@@ -780,7 +780,7 @@ void QDesignerWorkbench::updateWindowMenu(QDesignerFormWindowInterface *fwi)
void QDesignerWorkbench::formWindowActionTriggered(QAction *a)
{
- QDesignerFormWindow *fw = qobject_cast<QDesignerFormWindow *>(a->parentWidget());
+ QDesignerFormWindow *fw = qobject_cast<QDesignerFormWindow *>(a->parent());
Q_ASSERT(fw);
if (isFormWindowMinimized(fw))
diff --git a/src/designer/src/lib/shared/actioneditor.cpp b/src/designer/src/lib/shared/actioneditor.cpp
index d1ce9804e..c8a41f40e 100644
--- a/src/designer/src/lib/shared/actioneditor.cpp
+++ b/src/designer/src/lib/shared/actioneditor.cpp
@@ -351,7 +351,13 @@ void ActionEditor::slotCurrentItemChanged(QAction *action)
QDesignerObjectInspector *oi = qobject_cast<QDesignerObjectInspector *>(core()->objectInspector());
- if (action->associatedWidgets().isEmpty()) {
+ // Check if we have at least one associated QWidget:
+ const auto associatedObjects = action->associatedObjects();
+ auto it = std::find_if(associatedObjects.cbegin(), associatedObjects.cend(),
+ [](QObject *obj) {
+ return qobject_cast<QWidget *>(obj) != nullptr;
+ });
+ if (it == associatedObjects.cend()) {
// Special case: action not in object tree. Deselect all and set in property editor
fw->clearSelection(false);
if (oi)
diff --git a/src/designer/src/lib/shared/actionrepository.cpp b/src/designer/src/lib/shared/actionrepository.cpp
index b9f60cdb6..cd2239fb3 100644
--- a/src/designer/src/lib/shared/actionrepository.cpp
+++ b/src/designer/src/lib/shared/actionrepository.cpp
@@ -139,14 +139,16 @@ QModelIndex ActionModel::addAction(QAction *action)
// Find the associated menus and toolbars, ignore toolbuttons
QWidgetList ActionModel::associatedWidgets(const QAction *action)
{
- QWidgetList rc = action->associatedWidgets();
- for (QWidgetList::iterator it = rc.begin(); it != rc.end(); )
- if (qobject_cast<const QMenu *>(*it) || qobject_cast<const QToolBar *>(*it)) {
- ++it;
- } else {
- it = rc.erase(it);
+ const QObjectList rc = action->associatedObjects();
+ QWidgetList result;
+ result.reserve(rc.size());
+ for (QObject *obj : rc) {
+ if (QWidget *w = qobject_cast<QWidget *>(obj)) {
+ if (qobject_cast<const QMenu *>(w) || qobject_cast<const QToolBar *>(w))
+ result.push_back(w);
}
- return rc;
+ }
+ return result;
}
// shortcut is a fake property, need to retrieve it via property sheet.
@@ -643,9 +645,9 @@ QPixmap ActionRepositoryMimeData::actionDragPixmap(const QAction *action)
if (!icon.isNull())
return icon.pixmap(QSize(22, 22));
- const QWidgetList &associatedWidgets = action->associatedWidgets();
- for (QWidget *w : associatedWidgets) {
- if (QToolButton *tb = qobject_cast<QToolButton *>(w))
+ const QObjectList associatedObjects = action->associatedObjects();
+ for (QObject *o : associatedObjects) {
+ if (QToolButton *tb = qobject_cast<QToolButton *>(o))
return tb->grab(QRect(0, 0, -1, -1));
}
diff --git a/src/designer/src/lib/shared/qdesigner_command.cpp b/src/designer/src/lib/shared/qdesigner_command.cpp
index 8fb723126..55117e07f 100644
--- a/src/designer/src/lib/shared/qdesigner_command.cpp
+++ b/src/designer/src/lib/shared/qdesigner_command.cpp
@@ -2653,19 +2653,20 @@ static RemoveActionCommand::ActionData findActionIn(QAction *action)
{
RemoveActionCommand::ActionData result;
// We only want menus and toolbars, no toolbuttons.
- const QWidgetList &associatedWidgets = action->associatedWidgets();
- for (QWidget *widget : associatedWidgets) {
- if (qobject_cast<const QMenu *>(widget) || qobject_cast<const QToolBar *>(widget)) {
- const auto actionList = widget->actions();
- const int size = actionList.size();
- for (int i = 0; i < size; ++i) {
- if (actionList.at(i) == action) {
- QAction *before = nullptr;
- if (i + 1 < size)
- before = actionList.at(i + 1);
- result.append(RemoveActionCommand::ActionDataItem(before, widget));
- break;
- }
+ const QObjectList associatedObjects = action->associatedObjects();
+ for (QObject *obj : associatedObjects) {
+ if (!qobject_cast<const QMenu *>(obj) && !qobject_cast<const QToolBar *>(obj))
+ continue;
+ QWidget *widget = static_cast<QWidget *>(obj);
+ const auto actionList = widget->actions();
+ const int size = actionList.size();
+ for (int i = 0; i < size; ++i) {
+ if (actionList.at(i) == action) {
+ QAction *before = nullptr;
+ if (i + 1 < size)
+ before = actionList.at(i + 1);
+ result.append(RemoveActionCommand::ActionDataItem(before, widget));
+ break;
}
}
}
diff --git a/src/designer/src/lib/shared/qdesigner_menu.cpp b/src/designer/src/lib/shared/qdesigner_menu.cpp
index a098c757c..a2c8793c7 100644
--- a/src/designer/src/lib/shared/qdesigner_menu.cpp
+++ b/src/designer/src/lib/shared/qdesigner_menu.cpp
@@ -1035,16 +1035,15 @@ QDesignerMenu *QDesignerMenu::findOrCreateSubMenu(QAction *action)
bool QDesignerMenu::canCreateSubMenu(QAction *action) const // ### improve it's a bit too slow
{
- const QWidgetList &associatedWidgets = action->associatedWidgets();
- for (const QWidget *aw : associatedWidgets) {
- if (aw != this) {
- if (const QMenu *m = qobject_cast<const QMenu *>(aw)) {
+ const QObjectList associatedObjects = action->associatedObjects();
+ for (const QObject *ao : associatedObjects) {
+ if (ao != this) {
+ if (const QMenu *m = qobject_cast<const QMenu *>(ao)) {
if (m->actions().contains(action))
return false; // sorry
- } else {
- if (const QToolBar *tb = qobject_cast<const QToolBar *>(aw))
- if (tb->actions().contains(action))
- return false; // sorry
+ } else if (const QToolBar *tb = qobject_cast<const QToolBar *>(ao)) {
+ if (tb->actions().contains(action))
+ return false; // sorry
}
}
}
diff --git a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp
index 223fd76ae..9dde361e2 100644
--- a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp
+++ b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp
@@ -651,8 +651,14 @@ PropertyHelper::PropertyHelper(QObject* object,
m_parentWidget = (qobject_cast<QWidget*>(object))->parentWidget();
m_objectType = OT_Widget;
} else {
- if (const QAction *action = qobject_cast<const QAction *>(m_object))
- m_objectType = action->associatedWidgets().isEmpty() ? OT_FreeAction : OT_AssociatedAction;
+ if (const QAction *action = qobject_cast<const QAction *>(m_object)) {
+ const QObjectList associatedObjects = action->associatedObjects();
+ auto it = std::find_if(associatedObjects.cbegin(), associatedObjects.cend(),
+ [](QObject *obj) {
+ return qobject_cast<QWidget *>(obj) != nullptr;
+ });
+ m_objectType = (it == associatedObjects.cend()) ? OT_FreeAction : OT_AssociatedAction;
+ }
}
if(debugPropertyCommands)
diff --git a/src/designer/src/lib/uilib/abstractformbuilder.cpp b/src/designer/src/lib/uilib/abstractformbuilder.cpp
index a22c2ede2..45787f9af 100644
--- a/src/designer/src/lib/uilib/abstractformbuilder.cpp
+++ b/src/designer/src/lib/uilib/abstractformbuilder.cpp
@@ -2442,7 +2442,7 @@ void QAbstractFormBuilder::setWorkingDirectory(const QDir &directory)
*/
DomAction *QAbstractFormBuilder::createDom(QAction *action)
{
- if (action->parentWidget() == action->menu() || action->isSeparator())
+ if (action->parent() == action->menu() || action->isSeparator())
return nullptr;
DomAction *ui_action = new DomAction;
diff --git a/src/linguist/linguist/formpreviewview.cpp b/src/linguist/linguist/formpreviewview.cpp
index 8aed545da..5ae1ce9d7 100644
--- a/src/linguist/linguist/formpreviewview.cpp
+++ b/src/linguist/linguist/formpreviewview.cpp
@@ -377,8 +377,10 @@ static void highlightAction(QAction *a, bool on)
a->setProperty(FONT_BACKUP_PROP, QVariant());
}
}
- for (QWidget *w : a->associatedWidgets())
- highlightWidget(w, on);
+ for (QObject *o : a->associatedObjects()) {
+ if (QWidget *w = qobject_cast<QWidget *>(o))
+ highlightWidget(w, on);
+ }
}
static void highlightWidget(QWidget *w, bool on)