QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsshortcutsmanager.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsshortcutsmanager.h
3 ---------------------
4 begin : May 2009
5 copyright : (C) 2009 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSSHORTCUTSMANAGER_H
17#define QGSSHORTCUTSMANAGER_H
18
19#include <QHash>
20#include <QList>
21#include <QAction>
22#include "qgis_gui.h"
23#include "qgis_sip.h"
24
25class QShortcut;
26
37class GUI_EXPORT QgsShortcutsManager : public QObject
38{
39 Q_OBJECT
40
41 public:
42
50 QgsShortcutsManager( QObject *parent SIP_TRANSFERTHIS = nullptr, const QString &settingsRoot = "/shortcuts/" );
51
60 void registerAllChildren( QObject *object, bool recursive = false );
61
70 void registerAllChildActions( QObject *object, bool recursive = false );
71
80 void registerAllChildShortcuts( QObject *object, bool recursive = false );
81
92 bool registerAction( QAction *action, const QString &defaultShortcut = QString() );
93
103 bool registerShortcut( QShortcut *shortcut, const QString &defaultSequence = QString() );
104
113 bool unregisterAction( QAction *action );
114
123 bool unregisterShortcut( QShortcut *shortcut );
124
130 QList<QAction *> listActions() const;
131
137 QList<QShortcut *> listShortcuts() const;
138
144 QList<QObject *> listAll() const;
145
152 QString objectDefaultKeySequence( QObject *object ) const;
153
160 QString defaultKeySequence( QAction *action ) const;
161
168 QString defaultKeySequence( QShortcut *shortcut ) const;
169
177 bool setKeySequence( const QString &name, const QString &sequence );
178
185 bool setObjectKeySequence( QObject *object, const QString &sequence );
186
193 bool setKeySequence( QAction *action, const QString &sequence );
194
201 bool setKeySequence( QShortcut *shortcut, const QString &sequence );
202
210 QObject *objectForSequence( const QKeySequence &sequence ) const;
211
218 QAction *actionForSequence( const QKeySequence &sequence ) const;
219
226 QShortcut *shortcutForSequence( const QKeySequence &sequence ) const;
227
233 QAction *actionByName( const QString &name ) const;
234
240 QShortcut *shortcutByName( const QString &name ) const;
241
243 QString settingsPath() const { return mSettingsPath; }
244
245 private slots:
246
247 void actionDestroyed();
248 void shortcutDestroyed();
249
250 private:
251
252 typedef QHash< QAction *, QString > ActionsHash;
253 typedef QHash< QShortcut *, QString > ShortcutsHash;
254
255 ActionsHash mActions;
256 ShortcutsHash mShortcuts;
257 QString mSettingsPath;
258
265 void updateActionToolTip( QAction *action, const QString &sequence );
266};
267
268// clazy:excludeall=qstring-allocations
269
270#endif // QGSSHORTCUTSMANAGER_H
Shortcuts manager is a class that contains a list of QActions and QShortcuts that have been registere...
QString settingsPath() const
Returns the root settings path used to store shortcut customization.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53