QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "qgis_gui.h"
20#include "qgis_sip.h"
21
22#include <QAction>
23#include <QHash>
24#include <QList>
25
26class QShortcut;
27
37class GUI_EXPORT QgsShortcutsManager : public QObject
38{
39 Q_OBJECT
40
41 public:
46 enum class CommonAction
47 {
48 CodeToggleComment,
49 CodeReformat,
50 CodeRunScript,
51 CodeRunSelection,
52 };
53 Q_ENUM( CommonAction )
54
55
62 QgsShortcutsManager( QObject *parent SIP_TRANSFERTHIS = nullptr, const QString &settingsRoot = "/shortcuts/" );
63
64 ~QgsShortcutsManager() override;
65
75 void registerAllChildren( QObject *object, bool recursive = false, const QString &section = QString() );
76
86 void registerAllChildActions( QObject *object, bool recursive = false, const QString &section = QString() );
87
97 void registerAllChildShortcuts( QObject *object, bool recursive = false, const QString &section = QString() );
98
110 bool registerAction( QAction *action, const QString &defaultShortcut = QString(), const QString &section = QString() );
111
120 void initializeCommonAction( QAction *action, CommonAction commonAction );
121
132 bool registerShortcut( QShortcut *shortcut, const QString &defaultSequence = QString(), const QString &section = QString() );
133
142 bool unregisterAction( QAction *action );
143
152 bool unregisterShortcut( QShortcut *shortcut );
153
159 QList<QAction *> listActions() const;
160
166 QList<QShortcut *> listShortcuts() const;
167
173 QList<QObject *> listAll() const;
174
181 QString objectDefaultKeySequence( QObject *object ) const;
182
189 QString defaultKeySequence( QAction *action ) const;
190
197 QString defaultKeySequence( QShortcut *shortcut ) const;
198
206 bool setKeySequence( const QString &name, const QString &sequence );
207
214 bool setObjectKeySequence( QObject *object, const QString &sequence );
215
222 bool setKeySequence( QAction *action, const QString &sequence );
223
230 bool setKeySequence( QShortcut *shortcut, const QString &sequence );
231
239 QObject *objectForSequence( const QKeySequence &sequence ) const;
240
247 QAction *actionForSequence( const QKeySequence &sequence ) const;
248
255 QShortcut *shortcutForSequence( const QKeySequence &sequence ) const;
256
261 QKeySequence sequenceForCommonAction( CommonAction action ) const;
262
268 QAction *actionByName( const QString &name ) const;
269
275 QShortcut *shortcutByName( const QString &name ) const;
276
278 QString settingsPath() const { return mSettingsPath; }
279
286 QString objectSettingKey( QObject *object ) const;
287
294 QObject *objectForSettingKey( const QString &name ) const;
295
296 private slots:
297
298 void actionDestroyed( QAction *action );
299 void shortcutDestroyed( QShortcut *shortcut );
300
301 private:
302 typedef QHash<QAction *, QPair<QString, QString>> ActionsHash;
303 typedef QHash<QShortcut *, QPair<QString, QString>> ShortcutsHash;
304
305 ActionsHash mActions;
306 ShortcutsHash mShortcuts;
307 QString mSettingsPath;
308 QHash< int, QAction * > mCommonActions;
309 QHash< QAction *, CommonAction > mLinkedCommonActions;
310
311 static QString formatActionToolTip( const QString &toolTip );
312
319 void updateActionToolTip( QAction *action, const QString &sequence );
320};
321
322// clazy:excludeall=qstring-allocations
323
324#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.
QgsShortcutsManager(QObject *parent=nullptr, const QString &settingsRoot="/shortcuts/")
Constructor for QgsShortcutsManager.
CommonAction
Contains common actions which are used across a variety of classes.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53