QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
Public Member Functions | List of all members
QgsShortcutsManager Class Reference

Shortcuts manager is a class that contains a list of QActions and QShortcuts that have been registered and their shortcuts can be changed. More...

#include <qgsshortcutsmanager.h>

Inheritance diagram for QgsShortcutsManager:
Inheritance graph
[legend]

Public Member Functions

 QgsShortcutsManager (QObject *parent=nullptr, const QString &settingsRoot="/shortcuts/")
 Constructor for QgsShortcutsManager.
 
QAction * actionByName (const QString &name) const
 Returns an action by its name, or nullptr if nothing found.
 
QAction * actionForSequence (const QKeySequence &sequence) const
 Returns the action which is associated for a shortcut sequence, or nullptr if no action is associated.
 
QString defaultKeySequence (QAction *action) const
 Returns the default sequence for an action.
 
QString defaultKeySequence (QShortcut *shortcut) const
 Returns the default sequence for a shortcut.
 
QList< QAction * > listActions () const
 Returns a list of all actions in the manager.
 
QList< QObject * > listAll () const
 Returns a list of both actions and shortcuts in the manager.
 
QList< QShortcut * > listShortcuts () const
 Returns a list of shortcuts in the manager.
 
QString objectDefaultKeySequence (QObject *object) const
 Returns the default sequence for an object (either a QAction or QShortcut).
 
QObject * objectForSequence (const QKeySequence &sequence) const
 Returns the object (QAction or QShortcut) matching the specified key sequence,.
 
QObject * objectForSettingKey (const QString &name) const
 Returns the QShortcut or QAction matching the the full setting key Return nullptr if the key was not found.
 
QString objectSettingKey (QObject *object) const
 Returns the full settings key matching the QShortcut or QAction Return an empty QString if the QObject is not registered.
 
bool registerAction (QAction *action, const QString &defaultShortcut=QString(), const QString &section=QString())
 Registers an action with the manager so the shortcut can be configured in GUI.
 
void registerAllChildActions (QObject *object, bool recursive=false, const QString &section=QString())
 Automatically registers all QActions which are children of the passed object.
 
void registerAllChildren (QObject *object, bool recursive=false, const QString &section=QString())
 Automatically registers all QActions and QShortcuts which are children of the passed object.
 
void registerAllChildShortcuts (QObject *object, bool recursive=false, const QString &section=QString())
 Automatically registers all QShortcuts which are children of the passed object.
 
bool registerShortcut (QShortcut *shortcut, const QString &defaultSequence=QString(), const QString &section=QString())
 Registers a QShortcut with the manager so the shortcut can be configured in GUI.
 
bool setKeySequence (const QString &name, const QString &sequence)
 Modifies an action or shortcut's key sequence.
 
bool setKeySequence (QAction *action, const QString &sequence)
 Modifies an action's key sequence.
 
bool setKeySequence (QShortcut *shortcut, const QString &sequence)
 Modifies a shortcuts's key sequence.
 
bool setObjectKeySequence (QObject *object, const QString &sequence)
 Modifies an object's (either a QAction or a QShortcut) key sequence.
 
QString settingsPath () const
 Returns the root settings path used to store shortcut customization.
 
QShortcut * shortcutByName (const QString &name) const
 Returns a shortcut by its name, or nullptr if nothing found.
 
QShortcut * shortcutForSequence (const QKeySequence &sequence) const
 Returns the shortcut which is associated for a key sequence, or nullptr if no shortcut is associated.
 
bool unregisterAction (QAction *action)
 Removes an action from the manager.
 
bool unregisterShortcut (QShortcut *shortcut)
 Removes a shortcut from the manager.
 

Detailed Description

Shortcuts manager is a class that contains a list of QActions and QShortcuts that have been registered and their shortcuts can be changed.

QgsShortcutsManager is not usually directly created, but rather accessed through QgsGui::shortcutsManager().

Since
QGIS 2.16

Definition at line 37 of file qgsshortcutsmanager.h.

Constructor & Destructor Documentation

◆ QgsShortcutsManager()

QgsShortcutsManager::QgsShortcutsManager ( QObject *  parent = nullptr,
const QString &  settingsRoot = "/shortcuts/" 
)

Constructor for QgsShortcutsManager.

Parameters
parentparent object
settingsRootroot QgsSettings path for storing settings, e.g., "/myplugin/shortcuts". Leave as the default value to store settings alongside built in QGIS shortcuts, but care must be taken to not register actions which conflict with the built in QGIS actions.

Definition at line 24 of file qgsshortcutsmanager.cpp.

Member Function Documentation

◆ actionByName()

QAction * QgsShortcutsManager::actionByName ( const QString &  name) const

Returns an action by its name, or nullptr if nothing found.

Parameters
nameaction name. Must match QAction's text.
See also
shortcutByName()

Definition at line 301 of file qgsshortcutsmanager.cpp.

◆ actionForSequence()

QAction * QgsShortcutsManager::actionForSequence ( const QKeySequence &  sequence) const

Returns the action which is associated for a shortcut sequence, or nullptr if no action is associated.

Parameters
sequenceshortcut key sequence
See also
objectForSequence()
shortcutForSequence()

Definition at line 273 of file qgsshortcutsmanager.cpp.

◆ defaultKeySequence() [1/2]

QString QgsShortcutsManager::defaultKeySequence ( QAction *  action) const

Returns the default sequence for an action.

An empty return string indicates no default sequence.

Parameters
actionaction to return default key sequence for
See also
objectDefaultKeySequence()

Definition at line 200 of file qgsshortcutsmanager.cpp.

◆ defaultKeySequence() [2/2]

QString QgsShortcutsManager::defaultKeySequence ( QShortcut *  shortcut) const

Returns the default sequence for a shortcut.

An empty return string indicates no default sequence.

Parameters
shortcutshortcut to return default key sequence for
See also
objectDefaultKeySequence()

Definition at line 205 of file qgsshortcutsmanager.cpp.

◆ listActions()

QList< QAction * > QgsShortcutsManager::listActions ( ) const

Returns a list of all actions in the manager.

See also
listShortcuts()
listAll()

Definition at line 164 of file qgsshortcutsmanager.cpp.

◆ listAll()

QList< QObject * > QgsShortcutsManager::listAll ( ) const

Returns a list of both actions and shortcuts in the manager.

See also
listActions()
listShortcuts()

Definition at line 174 of file qgsshortcutsmanager.cpp.

◆ listShortcuts()

QList< QShortcut * > QgsShortcutsManager::listShortcuts ( ) const

Returns a list of shortcuts in the manager.

See also
listActions()
listAll()

Definition at line 169 of file qgsshortcutsmanager.cpp.

◆ objectDefaultKeySequence()

QString QgsShortcutsManager::objectDefaultKeySequence ( QObject *  object) const

Returns the default sequence for an object (either a QAction or QShortcut).

An empty return string indicates no shortcut.

Parameters
objectQAction or QShortcut to return default key sequence for
See also
defaultKeySequence()

Definition at line 190 of file qgsshortcutsmanager.cpp.

◆ objectForSequence()

QObject * QgsShortcutsManager::objectForSequence ( const QKeySequence &  sequence) const

Returns the object (QAction or QShortcut) matching the specified key sequence,.

Parameters
sequencekey sequence to find
Returns
object with matching sequence, or nullptr if not found
See also
actionForSequence()
shortcutForSequence()

Definition at line 263 of file qgsshortcutsmanager.cpp.

◆ objectForSettingKey()

QObject * QgsShortcutsManager::objectForSettingKey ( const QString &  name) const

Returns the QShortcut or QAction matching the the full setting key Return nullptr if the key was not found.

Since
QGIS 3.30

Definition at line 348 of file qgsshortcutsmanager.cpp.

◆ objectSettingKey()

QString QgsShortcutsManager::objectSettingKey ( QObject *  object) const

Returns the full settings key matching the QShortcut or QAction Return an empty QString if the QObject is not registered.

Since
QGIS 3.30

Definition at line 335 of file qgsshortcutsmanager.cpp.

◆ registerAction()

bool QgsShortcutsManager::registerAction ( QAction *  action,
const QString &  defaultShortcut = QString(),
const QString &  section = QString() 
)

Registers an action with the manager so the shortcut can be configured in GUI.

Parameters
actionaction to register. The action must have a unique text string for identification.
defaultShortcutdefault key sequence for action
sectionAllows disambiguating shortcuts with the same objectName (since QGIS 3.32)
Returns
true if action was successfully registered
See also
registerShortcut()
unregisterAction()
registerAllChildActions()

Definition at line 70 of file qgsshortcutsmanager.cpp.

◆ registerAllChildActions()

void QgsShortcutsManager::registerAllChildActions ( QObject *  object,
bool  recursive = false,
const QString &  section = QString() 
)

Automatically registers all QActions which are children of the passed object.

Parameters
objectparent object containing actions to register
recursiveset to true to recursively add child actions
sectionAllows disambiguating shortcuts with the same objectName (since QGIS 3.32)
See also
registerAction()
registerAllChildren()
registerAllChildShortcuts()

Definition at line 36 of file qgsshortcutsmanager.cpp.

◆ registerAllChildren()

void QgsShortcutsManager::registerAllChildren ( QObject *  object,
bool  recursive = false,
const QString &  section = QString() 
)

Automatically registers all QActions and QShortcuts which are children of the passed object.

Parameters
objectparent object containing actions and shortcuts to register
recursiveset to true to recursively add child actions and shortcuts
sectionAllows disambiguating shortcuts with the same objectName (since QGIS 3.32)
See also
registerAllChildActions()
registerAllChildShortcuts()

Definition at line 30 of file qgsshortcutsmanager.cpp.

◆ registerAllChildShortcuts()

void QgsShortcutsManager::registerAllChildShortcuts ( QObject *  object,
bool  recursive = false,
const QString &  section = QString() 
)

Automatically registers all QShortcuts which are children of the passed object.

Parameters
objectparent object containing shortcuts to register
recursiveset to true to recursively add child shortcuts
sectionAllows disambiguating shortcuts with the same objectName (since QGIS 3.32)
See also
registerShortcut()
registerAllChildren()
registerAllChildActions()

Definition at line 53 of file qgsshortcutsmanager.cpp.

◆ registerShortcut()

bool QgsShortcutsManager::registerShortcut ( QShortcut *  shortcut,
const QString &  defaultSequence = QString(),
const QString &  section = QString() 
)

Registers a QShortcut with the manager so the shortcut can be configured in GUI.

Parameters
shortcutQShortcut to register. The shortcut must have a unique QObject::objectName() for identification.
defaultSequencedefault key sequence for shortcut
sectionAllows disambiguating shortcuts with the same objectName (since QGIS 3.32)
Returns
true if shortcut was successfully registered
See also
registerAction()
registerAllChildShortcuts()

Definition at line 122 of file qgsshortcutsmanager.cpp.

◆ setKeySequence() [1/3]

bool QgsShortcutsManager::setKeySequence ( const QString &  name,
const QString &  sequence 
)

Modifies an action or shortcut's key sequence.

Parameters
namename of action or shortcut to modify. Must match the action's QAction::text() or the shortcut's QObject::objectName()
sequencenew shortcut key sequence
See also
setObjectKeySequence()

Definition at line 210 of file qgsshortcutsmanager.cpp.

◆ setKeySequence() [2/3]

bool QgsShortcutsManager::setKeySequence ( QAction *  action,
const QString &  sequence 
)

Modifies an action's key sequence.

Parameters
actionaction to modify
sequencenew shortcut key sequence
See also
setObjectKeySequence()

Definition at line 230 of file qgsshortcutsmanager.cpp.

◆ setKeySequence() [3/3]

bool QgsShortcutsManager::setKeySequence ( QShortcut *  shortcut,
const QString &  sequence 
)

Modifies a shortcuts's key sequence.

Parameters
shortcutQShortcut to modify
sequencenew shortcut key sequence
See also
setObjectKeySequence()

Definition at line 247 of file qgsshortcutsmanager.cpp.

◆ setObjectKeySequence()

bool QgsShortcutsManager::setObjectKeySequence ( QObject *  object,
const QString &  sequence 
)

Modifies an object's (either a QAction or a QShortcut) key sequence.

Parameters
objectQAction or QShortcut to modify
sequencenew shortcut key sequence
See also
setKeySequence()

Definition at line 220 of file qgsshortcutsmanager.cpp.

◆ settingsPath()

QString QgsShortcutsManager::settingsPath ( ) const
inline

Returns the root settings path used to store shortcut customization.

Definition at line 248 of file qgsshortcutsmanager.h.

◆ shortcutByName()

QShortcut * QgsShortcutsManager::shortcutByName ( const QString &  name) const

Returns a shortcut by its name, or nullptr if nothing found.

Parameters
nameshortcut name. Must match QShortcut's QObject::objectName() property.
See also
actionByName()

Definition at line 319 of file qgsshortcutsmanager.cpp.

◆ shortcutForSequence()

QShortcut * QgsShortcutsManager::shortcutForSequence ( const QKeySequence &  sequence) const

Returns the shortcut which is associated for a key sequence, or nullptr if no shortcut is associated.

Parameters
sequenceshortcut key sequence
See also
objectForSequence()
actionForSequence()

Definition at line 287 of file qgsshortcutsmanager.cpp.

◆ unregisterAction()

bool QgsShortcutsManager::unregisterAction ( QAction *  action)

Removes an action from the manager.

Parameters
actionaction to remove
Returns
true if action was previously registered in manager and has been removed, or false if action was not previously registered in manager
See also
registerAction()
unregisterShortcut()

Definition at line 146 of file qgsshortcutsmanager.cpp.

◆ unregisterShortcut()

bool QgsShortcutsManager::unregisterShortcut ( QShortcut *  shortcut)

Removes a shortcut from the manager.

Parameters
shortcutshortcut to remove
Returns
true if shortcut was previously registered in manager and has been removed, or false if shortcut was not previously registered in manager
See also
registerShortcut()
unregisterAction()

Definition at line 155 of file qgsshortcutsmanager.cpp.


The documentation for this class was generated from the following files: