From 16ae8b9e69955dadab22b381963c69e2c55a9b3d Mon Sep 17 00:00:00 2001 From: David Redondo Date: Tue, 15 Jun 2021 14:27:20 +0200 Subject: [PATCH] appmenu: Use existing menu in compact represenation There's no need to reconstruct the entire menu, when it exists already. Also shows correct behavior on Wayland because the imported menues have correct parents compared to the new one. BUG:438467 --- applets/appmenu/lib/appmenuapplet.cpp | 10 +++------- applets/appmenu/plugin/appmenumodel.cpp | 12 ++++++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/applets/appmenu/lib/appmenuapplet.cpp b/applets/appmenu/lib/appmenuapplet.cpp index 3ba9c95ab..734387f86 100644 --- a/applets/appmenu/lib/appmenuapplet.cpp +++ b/applets/appmenu/lib/appmenuapplet.cpp @@ -125,14 +125,10 @@ QMenu *AppMenuApplet::createMenu(int idx) const QAction *action = nullptr; if (view() == CompactView) { - menu = new QMenu(); - for (int i = 0; i < m_model->rowCount(); i++) { - const QModelIndex index = m_model->index(i, 0); - const QVariant data = m_model->data(index, AppMenuModel::ActionRole); - action = (QAction *)data.value(); - menu->addAction(action); + auto menuAction = static_cast(m_model->data(QModelIndex(), AppMenuModel::ActionRole).value()); + if (menuAction) { + menu = menuAction->menu(); } - menu->setAttribute(Qt::WA_DeleteOnClose); } else if (view() == FullView) { const QModelIndex index = m_model->index(idx, 0); const QVariant data = m_model->data(index, AppMenuModel::ActionRole); diff --git a/applets/appmenu/plugin/appmenumodel.cpp b/applets/appmenu/plugin/appmenumodel.cpp index fa9748e76..857c81e40 100644 --- a/applets/appmenu/plugin/appmenumodel.cpp +++ b/applets/appmenu/plugin/appmenumodel.cpp @@ -234,12 +234,20 @@ QList AppMenuModel::flatActionList() QVariant AppMenuModel::data(const QModelIndex &index, int role) const { - const int row = index.row(); - if (row < 0 || !m_menuAvailable || !m_menu) { + if (!m_menuAvailable || !m_menu) { return QVariant(); } + if (!index.isValid()) { + if (role == MenuRole) { + return QString(); + } else if (role == ActionRole) { + return QVariant::fromValue((void *)(m_menu->menuAction())); + } + } + const auto actions = m_menu->actions(); + const int row = index.row(); if (row == actions.count() && KWindowSystem::isPlatformWayland()) { if (role == MenuRole) { return m_searchAction->text();