QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
23 class QShortcut;
24 
31 class GUI_EXPORT QgsShortcutsManager : public QObject
32 {
33  Q_OBJECT
34 
35  public:
36 
38  static QgsShortcutsManager* instance();
39 
46  QgsShortcutsManager( QObject *parent = nullptr, const QString& settingsRoot = "/shortcuts/" );
47 
55  void registerAllChildren( QObject* object, bool recursive = false );
56 
64  void registerAllChildActions( QObject* object, bool recursive = false );
65 
73  void registerAllChildShortcuts( QObject* object, bool recursive = false );
74 
84  bool registerAction( QAction *action, const QString &defaultShortcut = QString() );
85 
94  bool registerShortcut( QShortcut* shortcut, const QString& defaultSequence = QString() );
95 
103  bool unregisterAction( QAction* action );
104 
112  bool unregisterShortcut( QShortcut* shortcut );
113 
118  QList<QAction*> listActions() const;
119 
124  QList<QShortcut*> listShortcuts() const;
125 
130  QList<QObject*> listAll() const;
131 
137  QString objectDefaultKeySequence( QObject* object ) const;
138 
144  QString defaultKeySequence( QAction* action ) const;
145 
151  QString defaultKeySequence( QShortcut* shortcut ) const;
152 
159  bool setKeySequence( const QString& name, const QString& sequence );
160 
166  bool setObjectKeySequence( QObject* object, const QString& sequence );
167 
173  bool setKeySequence( QAction* action, const QString& sequence );
174 
180  bool setKeySequence( QShortcut* shortcut, const QString& sequence );
181 
188  QObject* objectForSequence( const QKeySequence& sequence ) const;
189 
195  QAction* actionForSequence( const QKeySequence& sequence ) const;
196 
202  QShortcut* shortcutForSequence( const QKeySequence& sequence ) const;
203 
208  QAction* actionByName( const QString& name ) const;
209 
214  QShortcut* shortcutByName( const QString& name ) const;
215 
217  QString settingsPath() const { return mSettingsPath; }
218 
219  private slots:
220 
221  void actionDestroyed();
222  void shortcutDestroyed();
223 
224  private:
225 
228 
229  ActionsHash mActions;
230  ShortcutsHash mShortcuts;
231  QString mSettingsPath;
232  static QgsShortcutsManager* mInstance;
233 };
234 
235 #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 customisation.