Commit 6790b66c authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇 Committed by Nate Graham
Browse files

[Global Menu] Fix breakage caused by variant type change

`void *` casts into anything but `QVariant::value()` (most of the time)
does a metatype check which needs to match.

Also, we need to unwrap the `QPointer`.

BUG: 453301
parent d2dabf12
Pipeline #174444 passed with stage
in 5 minutes and 46 seconds
......@@ -122,18 +122,14 @@ void AppMenuApplet::setButtonGrid(QQuickItem *buttonGrid)
QMenu *AppMenuApplet::createMenu(int idx) const
{
QMenu *menu = nullptr;
QAction *action = nullptr;
if (view() == CompactView) {
auto menuAction = static_cast<QAction*>(m_model->data(QModelIndex(), AppMenuModel::ActionRole).value<void *>());
if (menuAction) {
if (QAction *menuAction = m_model->data(QModelIndex(), AppMenuModel::ActionRole).value<QAction *>()) {
menu = menuAction->menu();
}
} else if (view() == FullView) {
const QModelIndex index = m_model->index(idx, 0);
const QVariant data = m_model->data(index, AppMenuModel::ActionRole);
action = (QAction *)data.value<void *>();
if (action) {
if (QAction *action = m_model->data(index, AppMenuModel::ActionRole).value<QAction *>()) {
menu = action->menu();
}
}
......@@ -221,9 +217,7 @@ void AppMenuApplet::trigger(QQuickItem *ctx, int idx)
// FIXME TODO connect only once
connect(actionMenu, &QMenu::aboutToHide, this, &AppMenuApplet::onMenuAboutToHide, Qt::UniqueConnection);
} else { // is it just an action without a menu?
const QVariant data = m_model->index(idx, 0).data(AppMenuModel::ActionRole);
QAction *action = static_cast<QAction *>(data.value<void *>());
if (action) {
if (QAction *action = m_model->index(idx, 0).data(AppMenuModel::ActionRole).value<QAction *>()) {
Q_ASSERT(!action->menu());
action->trigger();
}
......
......@@ -251,7 +251,7 @@ QVariant AppMenuModel::data(const QModelIndex &index, int role) const
if (role == MenuRole) {
return m_searchAction->text();
} else if (role == ActionRole) {
return QVariant::fromValue((void *)m_searchAction);
return QVariant::fromValue(m_searchAction.data());
}
}
if (row >= actions.count()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment