QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
36class GUI_EXPORT QgsShortcutsManager : public QObject
37{
38 Q_OBJECT
39
40 public:
48 QgsShortcutsManager( QObject *parent SIP_TRANSFERTHIS = nullptr, const QString &settingsRoot = "/shortcuts/" );
49
59 void registerAllChildren( QObject *object, bool recursive = false, const QString &section = QString() );
60
70 void registerAllChildActions( QObject *object, bool recursive = false, const QString &section = QString() );
71
81 void registerAllChildShortcuts( QObject *object, bool recursive = false, const QString &section = QString() );
82
94 bool registerAction( QAction *action, const QString &defaultShortcut = QString(), const QString &section = QString() );
95
106 bool registerShortcut( QShortcut *shortcut, const QString &defaultSequence = QString(), const QString &section = QString() );
107
116 bool unregisterAction( QAction *action );
117
126 bool unregisterShortcut( QShortcut *shortcut );
127
133 QList<QAction *> listActions() const;
134
140 QList<QShortcut *> listShortcuts() const;
141
147 QList<QObject *> listAll() const;
148
155 QString objectDefaultKeySequence( QObject *object ) const;
156
163 QString defaultKeySequence( QAction *action ) const;
164
171 QString defaultKeySequence( QShortcut *shortcut ) const;
172
180 bool setKeySequence( const QString &name, const QString &sequence );
181
188 bool setObjectKeySequence( QObject *object, const QString &sequence );
189
196 bool setKeySequence( QAction *action, const QString &sequence );
197
204 bool setKeySequence( QShortcut *shortcut, const QString &sequence );
205
213 QObject *objectForSequence( const QKeySequence &sequence ) const;
214
221 QAction *actionForSequence( const QKeySequence &sequence ) const;
222
229 QShortcut *shortcutForSequence( const QKeySequence &sequence ) const;
230
236 QAction *actionByName( const QString &name ) const;
237
243 QShortcut *shortcutByName( const QString &name ) const;
244
246 QString settingsPath() const { return mSettingsPath; }
247
254 QString objectSettingKey( QObject *object ) const;
255
262 QObject *objectForSettingKey( const QString &name ) const;
263
264 private slots:
265
266 void actionDestroyed( QAction *action );
267 void shortcutDestroyed( QShortcut *shortcut );
268
269 private:
270 typedef QHash<QAction *, QPair<QString, QString>> ActionsHash;
271 typedef QHash<QShortcut *, QPair<QString, QString>> ShortcutsHash;
272
273 ActionsHash mActions;
274 ShortcutsHash mShortcuts;
275 QString mSettingsPath;
276
283 void updateActionToolTip( QAction *action, const QString &sequence );
284};
285
286// clazy:excludeall=qstring-allocations
287
288#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