From 1369bca36f6ced7d7c64899d1664469d32699f96 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 26 Sep 2016 17:54:45 +0200 Subject: [PATCH] Add removeMenuItem to PlasmaComponents.ContextMenu REVIEW: 128999 --- src/declarativeimports/plasmacomponents/qmenu.cpp | 10 ++++++++++ src/declarativeimports/plasmacomponents/qmenu.h | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/declarativeimports/plasmacomponents/qmenu.cpp b/src/declarativeimports/plasmacomponents/qmenu.cpp index b7037da2a..c6b59a87e 100644 --- a/src/declarativeimports/plasmacomponents/qmenu.cpp +++ b/src/declarativeimports/plasmacomponents/qmenu.cpp @@ -226,6 +226,16 @@ void QMenuProxy::addSection(const QString &text) m_menu->addSection(text); } +void QMenuProxy::removeMenuItem(QMenuItem *item) +{ + if (!item) { + return; + } + + m_menu->removeAction(item->action()); + m_items.removeOne(item); +} + void QMenuProxy::itemTriggered(QAction *action) { QMenuItem *item = qobject_cast(action); diff --git a/src/declarativeimports/plasmacomponents/qmenu.h b/src/declarativeimports/plasmacomponents/qmenu.h index 6eb4d8955..7b4360cc2 100644 --- a/src/declarativeimports/plasmacomponents/qmenu.h +++ b/src/declarativeimports/plasmacomponents/qmenu.h @@ -147,6 +147,13 @@ public: */ Q_INVOKABLE void addSection(const QString &text); + /** + * This removes MenuItem 'item' + * + * @since 5.27 + */ + Q_INVOKABLE void removeMenuItem(QMenuItem *item); + protected: bool event(QEvent *event) Q_DECL_OVERRIDE;