You can assign a QAction as "action", this way you can just pass it e.g. plasmoid.action("configure").
However, when assigning a null action as can happen with kiosk restrictions, it would crash as it assigns m_action the nullptr but never checks for that.
This patch ensures we always have a QAction, creating a new empty one, if neccessary.
Also deletes our own action if an external one is assigned
Details
Details
- Reviewers
davidedmundson - Group Reviewers
Plasma - Commits
- R242:21f954d94dc5: [PlasmaComponents Menu] Don't crash on null action
Created a menu and applied plasma/plasmashell/unlockedDesktop=false and opened it, no longer crashes:
PlasmaComponents.ContextMenu { id: contextMenu PlasmaComponents.MenuItem { action: plasmoid.action("configure") } }
Manual test has a new button to test this.
Diff Detail
Diff Detail
- Repository
- R242 Plasma Framework (Library)
- Lint
Lint Skipped - Unit
Unit Tests Skipped
src/declarativeimports/plasmacomponents/qmenuitem.cpp | ||
---|---|---|
29 ↗ | (On Diff #16449) | Another approach I've seen done before is: if (action->parent() == this) we delete it, else it's the client's problem. IMHO cleaner, but up to you. |
46 ↗ | (On Diff #16449) | you need a setVisible(true); otherwise setAction(null); setAction(something) will still be hidden. |
src/declarativeimports/plasmacomponents/qmenuitem.cpp | ||
---|---|---|
47 ↗ | (On Diff #16449) | Why delete it? if (!a) { setVisible(false); return; } // m_action stays last one, but disconnected. And we want to have last one "inactive"? |
Comment Actions
- For simplicitly just always delete the current action if it's ours before proceeding. Then either use the one passed in or create a new one. As a (neat) side-effect, explicitly assigning null to an action will also clear the menu item