Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9112 from m-kuhn/sip-keep-reference-to-registry
Sip keep reference to registry
  • Loading branch information
m-kuhn committed Feb 6, 2019
2 parents 87a1cb5 + b2aed60 commit db15057
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion python/analysis/auto_generated/qgsanalysis.sip.in
Expand Up @@ -32,7 +32,7 @@ related to analysis classes.
Returns a pointer to the singleton instance.
%End

static QgsGeometryCheckRegistry *geometryCheckRegistry();
static QgsGeometryCheckRegistry *geometryCheckRegistry() /KeepReference/;
%Docstring
Returns the global geometry checker registry, used for managing all geometry check factories.
%End
Expand Down
20 changes: 10 additions & 10 deletions python/core/auto_generated/qgsapplication.sip.in
Expand Up @@ -613,29 +613,29 @@ wide background task handling.
.. versionadded:: 3.0
%End

static QgsColorSchemeRegistry *colorSchemeRegistry();
static QgsColorSchemeRegistry *colorSchemeRegistry() /KeepReference/;
%Docstring
Returns the application's color scheme registry, used for managing color schemes.

.. versionadded:: 3.0
%End

static QgsPaintEffectRegistry *paintEffectRegistry();
static QgsPaintEffectRegistry *paintEffectRegistry() /KeepReference/;
%Docstring
Returns the application's paint effect registry, used for managing paint effects.

.. versionadded:: 3.0
%End

static QgsRendererRegistry *rendererRegistry();
static QgsRendererRegistry *rendererRegistry() /KeepReference/;
%Docstring
Returns the application's renderer registry, used for managing vector layer renderers.

.. versionadded:: 3.0
%End


static QgsDataItemProviderRegistry *dataItemProviderRegistry();
static QgsDataItemProviderRegistry *dataItemProviderRegistry() /KeepReference/;
%Docstring
Returns the application's data item provider registry, which keeps a list of data item
providers that may add items to the browser tree.
Expand All @@ -662,14 +662,14 @@ Returns the application's image cache, used for caching resampled versions of ra
.. versionadded:: 3.6
%End

static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry();
static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() /KeepReference/;
%Docstring
Returns the application's network content registry used for fetching temporary files during QGIS session

.. versionadded:: 3.2
%End

static QgsValidityCheckRegistry *validityCheckRegistry();
static QgsValidityCheckRegistry *validityCheckRegistry() /KeepReference/;
%Docstring
Returns the application's validity check registry, used for managing validity checks.

Expand Down Expand Up @@ -740,7 +740,7 @@ Returns the application's page size registry, used for managing layout page size
%End


static QgsActionScopeRegistry *actionScopeRegistry();
static QgsActionScopeRegistry *actionScopeRegistry() /KeepReference/;
%Docstring
Returns the action scope registry.

Expand All @@ -754,19 +754,19 @@ Returns the application runtime profiler.
.. versionadded:: 3.0
%End

static QgsFieldFormatterRegistry *fieldFormatterRegistry();
static QgsFieldFormatterRegistry *fieldFormatterRegistry() /KeepReference/;
%Docstring
Gets the registry of available field formatters.
%End

static Qgs3DRendererRegistry *renderer3DRegistry();
static Qgs3DRendererRegistry *renderer3DRegistry() /KeepReference/;
%Docstring
Returns registry of available 3D renderers.

.. versionadded:: 3.0
%End

static QgsProjectStorageRegistry *projectStorageRegistry();
static QgsProjectStorageRegistry *projectStorageRegistry() /KeepReference/;
%Docstring
Returns registry of available project storage implementations.

Expand Down
14 changes: 7 additions & 7 deletions python/gui/auto_generated/qgsgui.sip.in
Expand Up @@ -32,12 +32,12 @@ Returns a pointer to the singleton instance.
%End


static QgsEditorWidgetRegistry *editorWidgetRegistry();
static QgsEditorWidgetRegistry *editorWidgetRegistry() /KeepReference/;
%Docstring
Returns the global editor widget registry, used for managing all known edit widget factories.
%End

static QgsSourceSelectProviderRegistry *sourceSelectProviderRegistry();
static QgsSourceSelectProviderRegistry *sourceSelectProviderRegistry() /KeepReference/;
%Docstring
Returns the global source select provider registry, used for managing all known source select widget factories.
%End
Expand All @@ -47,22 +47,22 @@ Returns the global source select provider registry, used for managing all known
Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
%End

static QgsLayerTreeEmbeddedWidgetRegistry *layerTreeEmbeddedWidgetRegistry();
static QgsLayerTreeEmbeddedWidgetRegistry *layerTreeEmbeddedWidgetRegistry() /KeepReference/;
%Docstring
Returns the global layer tree embedded widget registry, used for registering widgets that may be embedded into layer tree view.
%End

static QgsMapLayerActionRegistry *mapLayerActionRegistry();
static QgsMapLayerActionRegistry *mapLayerActionRegistry() /KeepReference/;
%Docstring
Returns the global map layer action registry, used for registering map layer actions.
%End

static QgsLayoutItemGuiRegistry *layoutItemGuiRegistry();
static QgsLayoutItemGuiRegistry *layoutItemGuiRegistry() /KeepReference/;
%Docstring
Returns the global layout item GUI registry, used for registering the GUI behavior of layout items.
%End

static QgsProcessingGuiRegistry *processingGuiRegistry();
static QgsProcessingGuiRegistry *processingGuiRegistry() /KeepReference/;
%Docstring
Returns the global processing gui registry, used for registering the GUI behavior of processing algorithms.

Expand All @@ -76,7 +76,7 @@ Returns the global processing recent algorithm log, used for tracking recently u
.. versionadded:: 3.4
%End

static QgsDataItemGuiProviderRegistry *dataItemGuiProviderRegistry();
static QgsDataItemGuiProviderRegistry *dataItemGuiProviderRegistry() /KeepReference/;
%Docstring
Returns the global data item GUI provider registry, used for tracking providers which affect the browser
GUI.
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/qgsanalysis.h
Expand Up @@ -49,7 +49,7 @@ class ANALYSIS_EXPORT QgsAnalysis
/**
* Returns the global geometry checker registry, used for managing all geometry check factories.
*/
static QgsGeometryCheckRegistry *geometryCheckRegistry();
static QgsGeometryCheckRegistry *geometryCheckRegistry() SIP_KEEPREFERENCE;

private:

Expand Down
20 changes: 10 additions & 10 deletions src/core/qgsapplication.h
Expand Up @@ -549,19 +549,19 @@ class CORE_EXPORT QgsApplication : public QApplication
* Returns the application's color scheme registry, used for managing color schemes.
* \since QGIS 3.0
*/
static QgsColorSchemeRegistry *colorSchemeRegistry();
static QgsColorSchemeRegistry *colorSchemeRegistry() SIP_KEEPREFERENCE;

/**
* Returns the application's paint effect registry, used for managing paint effects.
* \since QGIS 3.0
*/
static QgsPaintEffectRegistry *paintEffectRegistry();
static QgsPaintEffectRegistry *paintEffectRegistry() SIP_KEEPREFERENCE;

/**
* Returns the application's renderer registry, used for managing vector layer renderers.
* \since QGIS 3.0
*/
static QgsRendererRegistry *rendererRegistry();
static QgsRendererRegistry *rendererRegistry() SIP_KEEPREFERENCE;

/**
* Returns the application's raster renderer registry, used for managing raster layer renderers.
Expand All @@ -575,7 +575,7 @@ class CORE_EXPORT QgsApplication : public QApplication
* providers that may add items to the browser tree.
* \since QGIS 3.0
*/
static QgsDataItemProviderRegistry *dataItemProviderRegistry();
static QgsDataItemProviderRegistry *dataItemProviderRegistry() SIP_KEEPREFERENCE;

/**
* Returns the application's SVG cache, used for caching SVG images and handling parameter replacement
Expand All @@ -598,13 +598,13 @@ class CORE_EXPORT QgsApplication : public QApplication
* Returns the application's network content registry used for fetching temporary files during QGIS session
* \since QGIS 3.2
*/
static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry();
static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry() SIP_KEEPREFERENCE;

/**
* Returns the application's validity check registry, used for managing validity checks.
* \since QGIS 3.6
*/
static QgsValidityCheckRegistry *validityCheckRegistry();
static QgsValidityCheckRegistry *validityCheckRegistry() SIP_KEEPREFERENCE;

/**
* Returns the application's symbol layer registry, used for managing symbol layers.
Expand Down Expand Up @@ -669,7 +669,7 @@ class CORE_EXPORT QgsApplication : public QApplication
*
* \since QGIS 3.0
*/
static QgsActionScopeRegistry *actionScopeRegistry();
static QgsActionScopeRegistry *actionScopeRegistry() SIP_KEEPREFERENCE;

/**
* Returns the application runtime profiler.
Expand All @@ -680,19 +680,19 @@ class CORE_EXPORT QgsApplication : public QApplication
/**
* Gets the registry of available field formatters.
*/
static QgsFieldFormatterRegistry *fieldFormatterRegistry();
static QgsFieldFormatterRegistry *fieldFormatterRegistry() SIP_KEEPREFERENCE;

/**
* Returns registry of available 3D renderers.
* \since QGIS 3.0
*/
static Qgs3DRendererRegistry *renderer3DRegistry();
static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;

/**
* Returns registry of available project storage implementations.
* \since QGIS 3.2
*/
static QgsProjectStorageRegistry *projectStorageRegistry();
static QgsProjectStorageRegistry *projectStorageRegistry() SIP_KEEPREFERENCE;

/**
* This string is used to represent the value `NULL` throughout QGIS.
Expand Down
14 changes: 7 additions & 7 deletions src/gui/qgsgui.h
Expand Up @@ -67,12 +67,12 @@ class GUI_EXPORT QgsGui
/**
* Returns the global editor widget registry, used for managing all known edit widget factories.
*/
static QgsEditorWidgetRegistry *editorWidgetRegistry();
static QgsEditorWidgetRegistry *editorWidgetRegistry() SIP_KEEPREFERENCE;

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

/**
* Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
Expand All @@ -82,23 +82,23 @@ class GUI_EXPORT QgsGui
/**
* Returns the global layer tree embedded widget registry, used for registering widgets that may be embedded into layer tree view.
*/
static QgsLayerTreeEmbeddedWidgetRegistry *layerTreeEmbeddedWidgetRegistry();
static QgsLayerTreeEmbeddedWidgetRegistry *layerTreeEmbeddedWidgetRegistry() SIP_KEEPREFERENCE;

/**
* Returns the global map layer action registry, used for registering map layer actions.
*/
static QgsMapLayerActionRegistry *mapLayerActionRegistry();
static QgsMapLayerActionRegistry *mapLayerActionRegistry() SIP_KEEPREFERENCE;

/**
* Returns the global layout item GUI registry, used for registering the GUI behavior of layout items.
*/
static QgsLayoutItemGuiRegistry *layoutItemGuiRegistry();
static QgsLayoutItemGuiRegistry *layoutItemGuiRegistry() SIP_KEEPREFERENCE;

/**
* Returns the global processing gui registry, used for registering the GUI behavior of processing algorithms.
* \since QGIS 3.2
*/
static QgsProcessingGuiRegistry *processingGuiRegistry();
static QgsProcessingGuiRegistry *processingGuiRegistry() SIP_KEEPREFERENCE;

/**
* Returns the global processing recent algorithm log, used for tracking recently used processing algorithms.
Expand All @@ -111,7 +111,7 @@ class GUI_EXPORT QgsGui
* GUI.
* \since QGIS 3.6
*/
static QgsDataItemGuiProviderRegistry *dataItemGuiProviderRegistry();
static QgsDataItemGuiProviderRegistry *dataItemGuiProviderRegistry() SIP_KEEPREFERENCE;

/**
* Register the widget to allow its position to be automatically saved and restored when open and closed.
Expand Down
30 changes: 29 additions & 1 deletion tests/src/python/test_qgscolorschemeregistry.py
Expand Up @@ -15,7 +15,7 @@
import qgis # NOQA

from qgis.testing import start_app, unittest
from qgis.core import QgsColorSchemeRegistry, QgsRecentColorScheme, QgsApplication
from qgis.core import QgsColorSchemeRegistry, QgsRecentColorScheme, QgsApplication, QgsColorScheme

start_app()

Expand Down Expand Up @@ -72,6 +72,34 @@ def testRemoveScheme(self):
# try removing a scheme not in the registry
self.assertFalse(registry.removeColorScheme(recentScheme))

def testOwnership(self):
"""
Test that registered color schemes do not require that a reference to them is kept.
They should be parented to the registry (on transfer) and even if there's no reference
to the registry around (see the `del` below) this childship should continue to exist.
"""
class TestColorScheme(QgsColorScheme):

def schemeName(self):
return "TestScheme"

def fetchColors(self, context, baseColors):
return None

def clone(self):
return TestColorScheme()

def flags(self):
return 1

reg = QgsApplication.instance().colorSchemeRegistry()
reg.addColorScheme(TestColorScheme())
del reg

reg = QgsApplication.instance().colorSchemeRegistry()

self.assertIn('TestScheme', [scheme.schemeName() for scheme in reg.schemes()])


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

0 comments on commit db15057

Please sign in to comment.