Skip to content

Commit 711f6dc

Browse files
committed
QgsShortcutsManager is no longer a singleton
Move the global instance to QgsGui::shortcutsManager()
1 parent 4a5c9a7 commit 711f6dc

File tree

11 files changed

+39
-28
lines changed

11 files changed

+39
-28
lines changed

doc/api_break.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,10 @@ QgsServer {#qgis_api_break_3_0_QgsServer}
19101910
- QgsServer::handleRequest( const QString &urlstr ) has been removed in favour of the new
19111911
- QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &response ) has been added
19121912

1913+
QgsShortcutsManager {#qgis_api_break_3_0_QgsShortcutsManager}
1914+
-------------------
1915+
1916+
- QgsShortcutsManager::instance() was removed. Use QgsGui::shortcutsManager() instead.
19131917

19141918

19151919
QgsSimpleMarkerSymbolLayer {#qgis_api_break_3_0_QgsSimpleMarkerSymbolLayer}

python/gui/qgsgui.sip

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ class QgsGui
3434
static QgsEditorWidgetRegistry *editorWidgetRegistry();
3535
%Docstring
3636
Returns the global editor widget registry, used for managing all known edit widget factories.
37-
.. versionadded:: 3.0
3837
:rtype: QgsEditorWidgetRegistry
3938
%End
4039

40+
static QgsShortcutsManager *shortcutsManager();
41+
%Docstring
42+
Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
43+
:rtype: QgsShortcutsManager
44+
%End
45+
4146
~QgsGui();
4247

4348
private:

python/gui/qgsshortcutsmanager.sip

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ class QgsShortcutsManager: QObject
1313

1414
public:
1515

16-
//! Return the singleton instance of the manager.
17-
static QgsShortcutsManager *instance();
18-
1916
/** Constructor for QgsShortcutsManager.
2017
* @param parent parent object
2118
* @param settingsRoot root QgsSettings path for storing settings, e.g., "/myplugin/shortcuts". Leave

src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
11601160
#endif
11611161

11621162
// supposedly all actions have been added, now register them to the shortcut manager
1163-
QgsShortcutsManager::instance()->registerAllChildren( this );
1163+
QgsGui::shortcutsManager()->registerAllChildren( this );
11641164

11651165
QgsProviderRegistry::instance()->registerGuis( this );
11661166

src/app/qgisappinterface.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "qgsapplayertreeviewmenuprovider.h"
3232
#include "qgscomposer.h"
3333
#include "qgscomposerview.h"
34+
#include "qgsgui.h"
3435
#include "qgsmaplayer.h"
3536
#include "qgsmaptooladvanceddigitizing.h"
3637
#include "qgsmapcanvas.h"
@@ -491,12 +492,12 @@ void QgisAppInterface::removeWindow( QAction *action )
491492

492493
bool QgisAppInterface::registerMainWindowAction( QAction *action, const QString &defaultShortcut )
493494
{
494-
return QgsShortcutsManager::instance()->registerAction( action, defaultShortcut );
495+
return QgsGui::shortcutsManager()->registerAction( action, defaultShortcut );
495496
}
496497

497498
bool QgisAppInterface::unregisterMainWindowAction( QAction *action )
498499
{
499-
return QgsShortcutsManager::instance()->unregisterAction( action );
500+
return QgsGui::shortcutsManager()->unregisterAction( action );
500501
}
501502

502503
void QgisAppInterface::registerMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory *factory )

src/gui/qgsconfigureshortcutsdialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsshortcutsmanager.h"
1919
#include "qgslogger.h"
2020
#include "qgssettings.h"
21+
#include "qgsgui.h"
2122

2223
#include <QKeyEvent>
2324
#include <QKeySequence>
@@ -38,7 +39,7 @@ QgsConfigureShortcutsDialog::QgsConfigureShortcutsDialog( QWidget *parent, QgsSh
3839
setupUi( this );
3940

4041
if ( !mManager )
41-
mManager = QgsShortcutsManager::instance();
42+
mManager = QgsGui::shortcutsManager();
4243

4344
connect( btnChangeShortcut, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::changeShortcut );
4445
connect( btnResetShortcut, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::resetShortcut );

src/gui/qgsgui.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgsgui.h"
1919
#include "qgseditorwidgetregistry.h"
20+
#include "qgsshortcutsmanager.h"
2021

2122
QgsGui *QgsGui::instance()
2223
{
@@ -29,12 +30,19 @@ QgsEditorWidgetRegistry *QgsGui::editorWidgetRegistry()
2930
return instance()->mEditorWidgetRegistry;
3031
}
3132

33+
QgsShortcutsManager *QgsGui::shortcutsManager()
34+
{
35+
return instance()->mShortcutsManager;
36+
}
37+
3238
QgsGui::~QgsGui()
3339
{
3440
delete mEditorWidgetRegistry;
41+
delete mShortcutsManager;
3542
}
3643

3744
QgsGui::QgsGui()
3845
{
3946
mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
47+
mShortcutsManager = new QgsShortcutsManager();
4048
}

src/gui/qgsgui.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgis_gui.h"
2222

2323
class QgsEditorWidgetRegistry;
24+
class QgsShortcutsManager;
2425

2526
/**
2627
* \ingroup gui
@@ -45,17 +46,22 @@ class GUI_EXPORT QgsGui
4546

4647
/**
4748
* Returns the global editor widget registry, used for managing all known edit widget factories.
48-
* \since QGIS 3.0
4949
*/
5050
static QgsEditorWidgetRegistry *editorWidgetRegistry();
5151

52+
/**
53+
* Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
54+
*/
55+
static QgsShortcutsManager *shortcutsManager();
56+
5257
~QgsGui();
5358

5459
private:
5560

5661
QgsGui();
5762

5863
QgsEditorWidgetRegistry *mEditorWidgetRegistry = nullptr;
64+
QgsShortcutsManager *mShortcutsManager = nullptr;
5965

6066
#ifdef SIP_RUN
6167
QgsGui( const QgsGui &other );

src/gui/qgsshortcutsmanager.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@
1919

2020
#include <QShortcut>
2121

22-
QgsShortcutsManager *QgsShortcutsManager::sInstance = nullptr;
23-
24-
25-
QgsShortcutsManager *QgsShortcutsManager::instance()
26-
{
27-
if ( !sInstance )
28-
sInstance = new QgsShortcutsManager( nullptr );
29-
return sInstance;
30-
}
31-
3222
QgsShortcutsManager::QgsShortcutsManager( QObject *parent, const QString &settingsRoot )
3323
: QObject( parent )
3424
, mSettingsPath( settingsRoot )

src/gui/qgsshortcutsmanager.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class QShortcut;
2626
/** \ingroup gui
2727
* \class QgsShortcutsManager
2828
* Shortcuts manager is a class that contains a list of QActions and QShortcuts
29-
that have been registered and their shortcuts can be changed.
29+
* that have been registered and their shortcuts can be changed.
30+
*
31+
* QgsShortcutsManager is not usually directly created, but rather accessed through
32+
* QgsGui::shortcutsManager().
3033
* \since QGIS 2.16
3134
*/
3235
class GUI_EXPORT QgsShortcutsManager : public QObject
@@ -35,9 +38,6 @@ class GUI_EXPORT QgsShortcutsManager : public QObject
3538

3639
public:
3740

38-
//! Return the singleton instance of the manager.
39-
static QgsShortcutsManager *instance();
40-
4141
/** Constructor for QgsShortcutsManager.
4242
* \param parent parent object
4343
* \param settingsRoot root QgsSettings path for storing settings, e.g., "/myplugin/shortcuts". Leave
@@ -230,7 +230,6 @@ class GUI_EXPORT QgsShortcutsManager : public QObject
230230
ActionsHash mActions;
231231
ShortcutsHash mShortcuts;
232232
QString mSettingsPath;
233-
static QgsShortcutsManager *sInstance;
234233

235234
/**
236235
* Updates the action to include the shortcut keys. Shortcut keys are

0 commit comments

Comments
 (0)