QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
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
61 void registerAllChildren( QObject *object, bool recursive = false, const QString &section = QString() );
62
72 void registerAllChildActions( QObject *object, bool recursive = false, const QString &section = QString() );
73
83 void registerAllChildShortcuts( QObject *object, bool recursive = false, const QString &section = QString() );
84
96 bool registerAction( QAction *action, const QString &defaultShortcut = QString(), const QString &section = QString() );
97
108 bool registerShortcut( QShortcut *shortcut, const QString &defaultSequence = QString(), const QString &section = QString() );
109
118 bool unregisterAction( QAction *action );
119
128 bool unregisterShortcut( QShortcut *shortcut );
129
135 QList<QAction *> listActions() const;
136
142 QList<QShortcut *> listShortcuts() const;
143
149 QList<QObject *> listAll() const;
150
157 QString objectDefaultKeySequence( QObject *object ) const;
158
165 QString defaultKeySequence( QAction *action ) const;
166
173 QString defaultKeySequence( QShortcut *shortcut ) const;
174
182 bool setKeySequence( const QString &name, const QString &sequence );
183
190 bool setObjectKeySequence( QObject *object, const QString &sequence );
191
198 bool setKeySequence( QAction *action, const QString &sequence );
199
206 bool setKeySequence( QShortcut *shortcut, const QString &sequence );
207
215 QObject *objectForSequence( const QKeySequence &sequence ) const;
216
223 QAction *actionForSequence( const QKeySequence &sequence ) const;
224
231 QShortcut *shortcutForSequence( const QKeySequence &sequence ) const;
232
238 QAction *actionByName( const QString &name ) const;
239
245 QShortcut *shortcutByName( const QString &name ) const;
246
248 QString settingsPath() const { return mSettingsPath; }
249
256 QString objectSettingKey( QObject *object ) const;
257
264 QObject *objectForSettingKey( const QString &name ) const;
265
266 private slots:
267
268 void actionDestroyed( QAction *action );
269 void shortcutDestroyed( QShortcut *shortcut );
270
271 private:
272 typedef QHash<QAction *, QPair<QString, QString>> ActionsHash;
273 typedef QHash<QShortcut *, QPair<QString, QString>> ShortcutsHash;
274
275 ActionsHash mActions;
276 ShortcutsHash mShortcuts;
277 QString mSettingsPath;
278
285 void updateActionToolTip( QAction *action, const QString &sequence );
286};
287
288// clazy:excludeall=qstring-allocations
289
290#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