Skip to content
Permalink
Browse files
QgsShortcutsManager is no longer a singleton
Move the global instance to QgsGui::shortcutsManager()
  • Loading branch information
nyalldawson committed May 14, 2017
1 parent 4a5c9a7 commit 711f6dcc500bf30dcc70164f1b6c153a9e60ed86
@@ -1910,6 +1910,10 @@ QgsServer {#qgis_api_break_3_0_QgsServer}
- QgsServer::handleRequest( const QString &urlstr ) has been removed in favour of the new
- QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &response ) has been added

QgsShortcutsManager {#qgis_api_break_3_0_QgsShortcutsManager}
-------------------

- QgsShortcutsManager::instance() was removed. Use QgsGui::shortcutsManager() instead.


QgsSimpleMarkerSymbolLayer {#qgis_api_break_3_0_QgsSimpleMarkerSymbolLayer}
@@ -34,10 +34,15 @@ class QgsGui
static QgsEditorWidgetRegistry *editorWidgetRegistry();
%Docstring
Returns the global editor widget registry, used for managing all known edit widget factories.
.. versionadded:: 3.0
:rtype: QgsEditorWidgetRegistry
%End

static QgsShortcutsManager *shortcutsManager();
%Docstring
Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
:rtype: QgsShortcutsManager
%End

~QgsGui();

private:
@@ -13,9 +13,6 @@ class QgsShortcutsManager: QObject

public:

//! Return the singleton instance of the manager.
static QgsShortcutsManager *instance();

/** Constructor for QgsShortcutsManager.
* @param parent parent object
* @param settingsRoot root QgsSettings path for storing settings, e.g., "/myplugin/shortcuts". Leave
@@ -1160,7 +1160,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
#endif

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

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

@@ -31,6 +31,7 @@
#include "qgsapplayertreeviewmenuprovider.h"
#include "qgscomposer.h"
#include "qgscomposerview.h"
#include "qgsgui.h"
#include "qgsmaplayer.h"
#include "qgsmaptooladvanceddigitizing.h"
#include "qgsmapcanvas.h"
@@ -491,12 +492,12 @@ void QgisAppInterface::removeWindow( QAction *action )

bool QgisAppInterface::registerMainWindowAction( QAction *action, const QString &defaultShortcut )
{
return QgsShortcutsManager::instance()->registerAction( action, defaultShortcut );
return QgsGui::shortcutsManager()->registerAction( action, defaultShortcut );
}

bool QgisAppInterface::unregisterMainWindowAction( QAction *action )
{
return QgsShortcutsManager::instance()->unregisterAction( action );
return QgsGui::shortcutsManager()->unregisterAction( action );
}

void QgisAppInterface::registerMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory *factory )
@@ -18,6 +18,7 @@
#include "qgsshortcutsmanager.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgsgui.h"

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

if ( !mManager )
mManager = QgsShortcutsManager::instance();
mManager = QgsGui::shortcutsManager();

connect( btnChangeShortcut, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::changeShortcut );
connect( btnResetShortcut, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::resetShortcut );
@@ -17,6 +17,7 @@

#include "qgsgui.h"
#include "qgseditorwidgetregistry.h"
#include "qgsshortcutsmanager.h"

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

QgsShortcutsManager *QgsGui::shortcutsManager()
{
return instance()->mShortcutsManager;
}

QgsGui::~QgsGui()
{
delete mEditorWidgetRegistry;
delete mShortcutsManager;
}

QgsGui::QgsGui()
{
mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
mShortcutsManager = new QgsShortcutsManager();
}
@@ -21,6 +21,7 @@
#include "qgis_gui.h"

class QgsEditorWidgetRegistry;
class QgsShortcutsManager;

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

/**
* Returns the global editor widget registry, used for managing all known edit widget factories.
* \since QGIS 3.0
*/
static QgsEditorWidgetRegistry *editorWidgetRegistry();

/**
* Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
*/
static QgsShortcutsManager *shortcutsManager();

~QgsGui();

private:

QgsGui();

QgsEditorWidgetRegistry *mEditorWidgetRegistry = nullptr;
QgsShortcutsManager *mShortcutsManager = nullptr;

#ifdef SIP_RUN
QgsGui( const QgsGui &other );
@@ -19,16 +19,6 @@

#include <QShortcut>

QgsShortcutsManager *QgsShortcutsManager::sInstance = nullptr;


QgsShortcutsManager *QgsShortcutsManager::instance()
{
if ( !sInstance )
sInstance = new QgsShortcutsManager( nullptr );
return sInstance;
}

QgsShortcutsManager::QgsShortcutsManager( QObject *parent, const QString &settingsRoot )
: QObject( parent )
, mSettingsPath( settingsRoot )
@@ -26,7 +26,10 @@ class QShortcut;
/** \ingroup gui
* \class QgsShortcutsManager
* Shortcuts manager is a class that contains a list of QActions and QShortcuts
that have been registered and their shortcuts can be changed.
* that have been registered and their shortcuts can be changed.
*
* QgsShortcutsManager is not usually directly created, but rather accessed through
* QgsGui::shortcutsManager().
* \since QGIS 2.16
*/
class GUI_EXPORT QgsShortcutsManager : public QObject
@@ -35,9 +38,6 @@ class GUI_EXPORT QgsShortcutsManager : public QObject

public:

//! Return the singleton instance of the manager.
static QgsShortcutsManager *instance();

/** Constructor for QgsShortcutsManager.
* \param parent parent object
* \param settingsRoot root QgsSettings path for storing settings, e.g., "/myplugin/shortcuts". Leave
@@ -230,7 +230,6 @@ class GUI_EXPORT QgsShortcutsManager : public QObject
ActionsHash mActions;
ShortcutsHash mShortcuts;
QString mSettingsPath;
static QgsShortcutsManager *sInstance;

/**
* Updates the action to include the shortcut keys. Shortcut keys are
@@ -15,7 +15,7 @@
import qgis # NOQA

from qgis.core import QgsSettings
from qgis.gui import QgsShortcutsManager
from qgis.gui import QgsShortcutsManager, QgsGui
from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtWidgets import QWidget, QAction, QShortcut

@@ -35,13 +35,13 @@ def setUpClass(cls):

def testInstance(self):
""" test retrieving global instance """
self.assertTrue(QgsShortcutsManager.instance())
self.assertTrue(QgsGui.shortcutsManager())

# register an action to the singleton
action = QAction('test', None)
QgsShortcutsManager.instance().registerAction(action)
QgsGui.shortcutsManager().registerAction(action)
# check that the same instance is returned
self.assertEqual(QgsShortcutsManager.instance().listActions(), [action])
self.assertEqual(QgsGui.shortcutsManager().listActions(), [action])
s2 = QgsShortcutsManager()
self.assertEqual(s2.listActions(), [])

0 comments on commit 711f6dc

Please sign in to comment.