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
wilder-5.25
David Redondo 5 years ago committed by Nate Graham
parent 28537cf3ff
commit 16ae8b9e69
  1. 10
      applets/appmenu/lib/appmenuapplet.cpp
  2. 12
      applets/appmenu/plugin/appmenumodel.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<void *>();
menu->addAction(action);
auto menuAction = static_cast<QAction*>(m_model->data(QModelIndex(), AppMenuModel::ActionRole).value<void *>());
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);

@ -234,12 +234,20 @@ QList<QAction *> 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();

Loading…
Cancel
Save