Skip to content
Permalink
Browse files
Attach QgsSourceSelectProviderRegistry to QgsGui
And make it a singleton
  • Loading branch information
elpaso committed Sep 4, 2017
1 parent e868599 commit 90f8730
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
@@ -38,6 +38,12 @@ class QgsGui
:rtype: QgsEditorWidgetRegistry
%End

static QgsSourceSelectProviderRegistry *sourceSelectProviderRegistry();
%Docstring
Returns the global source select provider registry, used for managing all known source select widget factories.
:rtype: QgsSourceSelectProviderRegistry
%End

static QgsShortcutsManager *shortcutsManager();
%Docstring
Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
@@ -14,6 +14,9 @@ class QgsSourceSelectProviderRegistry
This class keeps a list of source select providers that may add items to the QgsDataSourceManagerDialog
When created, it automatically adds providers from data provider plugins (e.g. PostGIS, WMS, ...)

QgsSourceSelectProviderRegistry is not usually directly created, but rather accessed through
QgsGui.sourceSelectProviderRegistry().

.. versionadded:: 3.0
%End

@@ -19,6 +19,7 @@
#include "qgseditorwidgetregistry.h"
#include "qgslayertreeembeddedwidgetregistry.h"
#include "qgsmaplayeractionregistry.h"
#include "qgssourceselectproviderregistry.h"
#include "qgslayoutitemregistry.h"
#include "qgslayoutitemguiregistry.h"
#include "qgslayoutviewrubberband.h"
@@ -45,6 +46,11 @@ QgsEditorWidgetRegistry *QgsGui::editorWidgetRegistry()
return instance()->mEditorWidgetRegistry;
}

QgsSourceSelectProviderRegistry *QgsGui::sourceSelectProviderRegistry()
{
return instance()->mSourceSelectProviderRegistry;
}

QgsShortcutsManager *QgsGui::shortcutsManager()
{
return instance()->mShortcutsManager;
@@ -71,6 +77,7 @@ QgsGui::~QgsGui()
delete mLayerTreeEmbeddedWidgetRegistry;
delete mEditorWidgetRegistry;
delete mMapLayerActionRegistry;
delete mSourceSelectProviderRegistry;
delete mShortcutsManager;
delete mNative;
}
@@ -87,6 +94,7 @@ QgsGui::QgsGui()
mShortcutsManager = new QgsShortcutsManager();
mLayerTreeEmbeddedWidgetRegistry = new QgsLayerTreeEmbeddedWidgetRegistry();
mMapLayerActionRegistry = new QgsMapLayerActionRegistry();
mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry();
mLayoutItemGuiRegistry = new QgsLayoutItemGuiRegistry();
mLayoutItemGuiRegistry->populate();
}
@@ -25,6 +25,7 @@ class QgsEditorWidgetRegistry;
class QgsShortcutsManager;
class QgsLayerTreeEmbeddedWidgetRegistry;
class QgsMapLayerActionRegistry;
class QgsSourceSelectProviderRegistry;
class QgsNative;
class QgsLayoutItemGuiRegistry;

@@ -61,6 +62,11 @@ class GUI_EXPORT QgsGui
*/
static QgsEditorWidgetRegistry *editorWidgetRegistry();

/**
* Returns the global source select provider registry, used for managing all known source select widget factories.
*/
static QgsSourceSelectProviderRegistry *sourceSelectProviderRegistry();

/**
* Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
*/
@@ -89,6 +95,7 @@ class GUI_EXPORT QgsGui

QgsNative *mNative = nullptr;
QgsEditorWidgetRegistry *mEditorWidgetRegistry = nullptr;
QgsSourceSelectProviderRegistry *mSourceSelectProviderRegistry = nullptr;
QgsShortcutsManager *mShortcutsManager = nullptr;
QgsLayerTreeEmbeddedWidgetRegistry *mLayerTreeEmbeddedWidgetRegistry = nullptr;
QgsMapLayerActionRegistry *mMapLayerActionRegistry = nullptr;
@@ -25,6 +25,9 @@ class QgsSourceSelectProvider;
* This class keeps a list of source select providers that may add items to the QgsDataSourceManagerDialog
* When created, it automatically adds providers from data provider plugins (e.g. PostGIS, WMS, ...)
*
* QgsSourceSelectProviderRegistry is not usually directly created, but rather accessed through
* QgsGui::sourceSelectProviderRegistry().
*
* \since QGIS 3.0
*/
class GUI_EXPORT QgsSourceSelectProviderRegistry
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""
Test the QgsSourceSelectProvider class
Test the QgsSourceSelectProvider
and QgsSourceSelectProviderRegistry classes
Run with: ctest -V -R PyQgsSourceSelectProvider
@@ -12,7 +13,7 @@

import os
import tempfile
from qgis.gui import (QgsSourceSelectProvider, QgsSourceSelectProviderRegistry, QgsAbstractDataSourceWidget)
from qgis.gui import (QgsGui, QgsSourceSelectProvider, QgsSourceSelectProviderRegistry, QgsAbstractDataSourceWidget)
from qgis.testing import start_app, unittest
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QWidget
@@ -90,9 +91,8 @@ def testConcreteClass(self):
self.assertEqual(provider.ordering(), 1)
self.assertTrue(isinstance(provider.icon(), QIcon))

def testRegistry(self):
def _testRegistry(self, registry):

registry = QgsSourceSelectProviderRegistry()
registry.addProvider(ConcreteSourceSelectProvider())
registry.addProvider(ConcreteSourceSelectProvider2())

@@ -113,13 +113,21 @@ def testRegistry(self):
# Get not existent by name
self.assertFalse(registry.providerByName('Oh This Is Missing!'))

# Get providers by provider key
# Get providers by data provider key
self.assertGreater(len(registry.providersByKey('MyTestProviderKey')), 0)
self.assertGreater(len(registry.providersByKey('MyTestProviderKey2')), 0)

# Get not existent by key
self.assertEqual(len(registry.providersByKey('Oh This Is Missing!')), 0)

def testRegistry(self):
registry = QgsSourceSelectProviderRegistry()
self._testRegistry(registry)

def testRegistrySingleton(self):
registry = QgsGui.sourceSelectProviderRegistry()
self._testRegistry(registry)


if __name__ == '__main__':
unittest.main()

0 comments on commit 90f8730

Please sign in to comment.