KMoreToolsMenuItem

KMoreToolsMenuItem Class Reference

#include <kmoretools.h>

Public Member Functions

 KMoreToolsMenuItem (const KMoreToolsMenuItem &)=delete
 
QActionaction () const
 
KMoreTools::MenuSection defaultLocation () const
 
QString id () const
 
QString initialItemText () const
 
KMoreToolsMenuItemoperator= (const KMoreToolsMenuItem &)=delete
 
KMoreToolsServiceregisteredService () const
 
void setId (const QString &id)
 
void setInitialItemText (const QString &itemText)
 

Detailed Description

Represents a menu item of a service (application, tool or variant of the same service with different parameters).

The service might be installed or not.

The corresponding QAction will be created for installed services.

Note
that for not-installed services action() returns nullptr.
Since
5.10

Definition at line 671 of file kmoretools.h.

Member Function Documentation

QAction * KMoreToolsMenuItem::action ( ) const

Case 1

KMoreToolsMenuBuilder::addMenuItem was called with KKmoreToolsService* argument.

the corresponding QAction which will be added to the actual menu when underlying service is installed or else - if not installed - nullptr.

So you can change the created action as you desire.

We return nullptr because not-installed services will get a submenu with other items like opening a website instead of an single action.

To change the item's text even for not-installed services use initialItemText()

Note, that once the method was invoked the first time the action is created an then reused.

Case 2

KMoreToolsMenuBuilder::addMenuItem was called with QAction* argument. The added action will be returned.

See also
KMoreToolsService::isInstalled

Definition at line 782 of file kmoretools.cpp.

KMoreTools::MenuSection KMoreToolsMenuItem::defaultLocation ( ) const

see KMoreToolsMenuBuilder::addMenuItem

Definition at line 767 of file kmoretools.cpp.

QString KMoreToolsMenuItem::id ( ) const

Auto-generated unique id that tries to be as stable as possible even if the menu gets restructured after the user did some customization that was persisted in a config file.

Note
It is possible to add the same service more than once (and then hopefully change the action text). When the order of those are changed, the id will not be consistent (because internally an increasing number is used) If you have issues with this you can solve this by manually calling setId (e.g. 'desktopEntryName' + 'x').

Definition at line 752 of file kmoretools.cpp.

QString KMoreToolsMenuItem::initialItemText ( ) const

see setInitialItemText()

Definition at line 772 of file kmoretools.cpp.

KMoreToolsService * KMoreToolsMenuItem::registeredService ( ) const
Returns
the underlying KMoreToolsService instance, see KMoreToolsMenuBuilder::addMenuItem (with KKmoreToolsService* argument). Or nullptr when KMoreToolsMenuBuilder::addMenuItem (with QAction* argument was used).

Definition at line 762 of file kmoretools.cpp.

void KMoreToolsMenuItem::setId ( const QString id)

(Optional) to help with stable ids (see id())

todo: make sure that if this is called, uniqueness of ids will be assured. todo: make sure to show error if the id contains characters other than alphanumerica, dashes and underscores etc.

Definition at line 757 of file kmoretools.cpp.

void KMoreToolsMenuItem::setInitialItemText ( const QString itemText)

Sets the initial text of a menu item.

Menu items of a non-installed service will get this text. If the service is installed and you would like to change the item text, you can retrieve the created QAction (action()) and modify the text using QAction's methods (QAction::setText()).

See also

Definition at line 777 of file kmoretools.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 22:42:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.