KMoreToolsMenuItem

Search for usage in LXR

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.

Definition at line 655 of file kmoretools.h.

Member Function Documentation

◆ action()

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 731 of file kmoretools.cpp.

◆ defaultLocation()

KMoreTools::MenuSection KMoreToolsMenuItem::defaultLocation ( ) const

see KMoreToolsMenuBuilder::addMenuItem

Definition at line 716 of file kmoretools.cpp.

◆ id()

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 701 of file kmoretools.cpp.

◆ initialItemText()

QString KMoreToolsMenuItem::initialItemText ( ) const

see setInitialItemText()

Definition at line 721 of file kmoretools.cpp.

◆ registeredService()

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 711 of file kmoretools.cpp.

◆ setId()

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 706 of file kmoretools.cpp.

◆ setInitialItemText()

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 726 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-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.