QGIS API Documentation 3.41.0-Master (3440c17df1d)
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:
41
49 QgsShortcutsManager( QObject *parent SIP_TRANSFERTHIS = nullptr, const QString &settingsRoot = "/shortcuts/" );
50
60 void registerAllChildren( QObject *object, bool recursive = false, const QString &section = QString() );
61
71 void registerAllChildActions( QObject *object, bool recursive = false, const QString &section = QString() );
72
82 void registerAllChildShortcuts( QObject *object, bool recursive = false, const QString &section = QString() );
83
95 bool registerAction( QAction *action, const QString &defaultShortcut = QString(), const QString &section = QString() );
96
107 bool registerShortcut( QShortcut *shortcut, const QString &defaultSequence = QString(), const QString &section = QString() );
108
117 bool unregisterAction( QAction *action );
118
127 bool unregisterShortcut( QShortcut *shortcut );
128
134 QList<QAction *> listActions() const;
135
141 QList<QShortcut *> listShortcuts() const;
142
148 QList<QObject *> listAll() const;
149
156 QString objectDefaultKeySequence( QObject *object ) const;
157
164 QString defaultKeySequence( QAction *action ) const;
165
172 QString defaultKeySequence( QShortcut *shortcut ) const;
173
181 bool setKeySequence( const QString &name, const QString &sequence );
182
189 bool setObjectKeySequence( QObject *object, const QString &sequence );
190
197 bool setKeySequence( QAction *action, const QString &sequence );
198
205 bool setKeySequence( QShortcut *shortcut, const QString &sequence );
206
214 QObject *objectForSequence( const QKeySequence &sequence ) const;
215
222 QAction *actionForSequence( const QKeySequence &sequence ) const;
223
230 QShortcut *shortcutForSequence( const QKeySequence &sequence ) const;
231
237 QAction *actionByName( const QString &name ) const;
238
244 QShortcut *shortcutByName( const QString &name ) const;
245
247 QString settingsPath() const { return mSettingsPath; }
248
255 QString objectSettingKey( QObject *object ) const;
256
263 QObject *objectForSettingKey( const QString &name ) const;
264
265 private slots:
266
267 void actionDestroyed( QAction *action );
268 void shortcutDestroyed( QShortcut *shortcut );
269
270 private:
271 typedef QHash<QAction *, QPair<QString, QString>> ActionsHash;
272 typedef QHash<QShortcut *, QPair<QString, QString>> ShortcutsHash;
273
274 ActionsHash mActions;
275 ShortcutsHash mShortcuts;
276 QString mSettingsPath;
277
284 void updateActionToolTip( QAction *action, const QString &sequence );
285};
286
287// clazy:excludeall=qstring-allocations
288
289#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