Skip to content
Permalink
Browse files

Remove some singletons by moving instances to QgsApplication

- QgsColorSchemeRegistry
- QgsDataItemProviderRegistry
- QgsGPSConnectionRegistry
- QgsMessageLog
- QgsPaintEffectRegistry
- QgsPluginLayerRegistry
- QgsRasterRendererRegistry
- QgsRendererRegistry
- QgsSvgCache
- QgsSymbolLayerRegistry
  • Loading branch information
nyalldawson committed Dec 28, 2016
1 parent 4b1cf80 commit 9d4adc1c70dfe84c3c4ddfbe5f358b57fd50d032
Showing with 561 additions and 407 deletions.
  1. +45 −0 doc/api_break.dox
  2. +1 −1 python/core/__init__.py
  3. +2 −7 python/core/effects/qgspainteffectregistry.sip
  4. +1 −4 python/core/gps/qgsgpsconnectionregistry.sip
  5. +56 −0 python/core/qgsapplication.sip
  6. +0 −4 python/core/qgscolorschemeregistry.sip
  7. +2 −3 python/core/qgsdataitemproviderregistry.sip
  8. +1 −3 python/core/qgsmessagelog.sip
  9. +1 −4 python/core/qgspluginlayerregistry.sip
  10. +2 −7 python/core/symbology-ng/qgsrendererregistry.sip
  11. +2 −3 python/core/symbology-ng/qgssvgcache.sip
  12. +2 −6 python/core/symbology-ng/qgssymbollayerregistry.sip
  13. +3 −3 src/app/composer/qgscomposerpicturewidget.cpp
  14. +2 −2 src/app/gps/qgsgpsinformationwidget.cpp
  15. +1 −0 src/app/ogr/qgsnewogrconnection.cpp
  16. +1 −0 src/app/ogr/qgsopenvectorlayerdialog.cpp
  17. +3 −3 src/app/qgisapp.cpp
  18. +2 −2 src/app/qgsapplayertreeviewmenuprovider.cpp
  19. +1 −1 src/app/qgslayerstylingwidget.cpp
  20. +1 −1 src/app/qgsoptions.cpp
  21. +1 −1 src/app/qgsprojectproperties.cpp
  22. +10 −10 src/app/qgsrasterlayerproperties.cpp
  23. +1 −1 src/app/qgsversioninfo.cpp
  24. +0 −2 src/browser/main.cpp
  25. +1 −1 src/core/composer/qgscomposerarrow.cpp
  26. +1 −1 src/core/composer/qgscomposerpicture.cpp
  27. +1 −1 src/core/effects/qgseffectstack.cpp
  28. +1 −7 src/core/effects/qgspainteffectregistry.cpp
  29. +8 −10 src/core/effects/qgspainteffectregistry.h
  30. +0 −6 src/core/gps/qgsgpsconnectionregistry.cpp
  31. +10 −9 src/core/gps/qgsgpsconnectionregistry.h
  32. +83 −2 src/core/qgsapplication.cpp
  33. +83 −0 src/core/qgsapplication.h
  34. +1 −1 src/core/qgsbrowsermodel.cpp
  35. +1 −23 src/core/qgscolorschemeregistry.cpp
  36. +1 −7 src/core/qgscolorschemeregistry.h
  37. +2 −2 src/core/qgsdataitem.cpp
  38. +0 −6 src/core/qgsdataitemproviderregistry.cpp
  39. +6 −3 src/core/qgsdataitemproviderregistry.h
  40. +1 −1 src/core/qgsmaplayer.cpp
  41. +5 −19 src/core/qgsmessagelog.cpp
  42. +5 −3 src/core/qgsmessagelog.h
  43. +3 −13 src/core/qgspluginlayerregistry.cpp
  44. +5 −8 src/core/qgspluginlayerregistry.h
  45. +1 −1 src/core/qgsproject.cpp
  46. +3 −2 src/core/qgsprojectbadlayerhandler.cpp
  47. +1 −0 src/core/raster/qgsrasterdataprovider.cpp
  48. +2 −2 src/core/raster/qgsrasterlayer.cpp
  49. +0 −6 src/core/raster/qgsrasterrendererregistry.cpp
  50. +6 −5 src/core/raster/qgsrasterrendererregistry.h
  51. +4 −4 src/core/symbology-ng/qgsfillsymbollayer.cpp
  52. +6 −6 src/core/symbology-ng/qgsmarkersymbollayer.cpp
  53. +3 −3 src/core/symbology-ng/qgsrenderer.cpp
  54. +0 −7 src/core/symbology-ng/qgsrendererregistry.cpp
  55. +8 −11 src/core/symbology-ng/qgsrendererregistry.h
  56. +0 −6 src/core/symbology-ng/qgssvgcache.cpp
  57. +8 −3 src/core/symbology-ng/qgssvgcache.h
  58. +0 −6 src/core/symbology-ng/qgssymbollayerregistry.cpp
  59. +8 −10 src/core/symbology-ng/qgssymbollayerregistry.h
  60. +18 −18 src/core/symbology-ng/qgssymbollayerutils.cpp
  61. +2 −2 src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
  62. +3 −3 src/gui/editorwidgets/qgsdatetimeeditwrapper.cpp
  63. +1 −1 src/gui/effects/qgseffectstackpropertieswidget.cpp
  64. +4 −4 src/gui/effects/qgspainteffectpropertieswidget.cpp
  65. +1 −1 src/gui/qgscolorbutton.cpp
  66. +7 −7 src/gui/qgscompoundcolorwidget.cpp
  67. +1 −0 src/gui/qgsfiledownloader.cpp
  68. +1 −1 src/gui/qgsmessagelogviewer.cpp
  69. +1 −0 src/gui/qgsowssourceselect.cpp
  70. +1 −0 src/gui/qgsprojectbadlayerguihandler.cpp
  71. +1 −1 src/gui/qgstextformatwidget.cpp
  72. +10 −10 src/gui/raster/qgsrendererrasterpropertieswidget.cpp
  73. +3 −3 src/gui/symbology-ng/qgsinvertedpolygonrendererwidget.cpp
  74. +7 −7 src/gui/symbology-ng/qgslayerpropertieswidget.cpp
  75. +4 −4 src/gui/symbology-ng/qgspointclusterrendererwidget.cpp
  76. +4 −4 src/gui/symbology-ng/qgspointdisplacementrendererwidget.cpp
  77. +3 −3 src/gui/symbology-ng/qgsrendererpropertiesdialog.cpp
  78. +2 −2 src/gui/symbology-ng/qgssvgselectorwidget.cpp
  79. +2 −2 src/gui/symbology-ng/qgssymbollayerwidget.cpp
  80. +2 −2 src/gui/symbology-ng/qgssymbolselectordialog.cpp
  81. +1 −1 src/plugins/grass/qgsgrasseditrenderer.cpp
  82. +2 −2 src/plugins/grass/qgsgrassplugin.cpp
  83. +1 −0 src/providers/wfs/qgswfsrequest.cpp
  84. +1 −1 src/providers/wms/qgstilecache.cpp
  85. +1 −0 src/providers/wms/qgswmscapabilities.cpp
  86. +1 −0 src/providers/wms/qgswmssourceselect.cpp
  87. +1 −1 src/server/qgsmslayerbuilder.cpp
  88. +2 −1 src/server/qgsserverlogger.cpp
  89. +3 −3 tests/src/core/testqgscolorschemeregistry.cpp
  90. +5 −5 tests/src/core/testqgspainteffect.cpp
  91. +6 −6 tests/src/core/testqgspainteffectregistry.cpp
  92. +3 −3 tests/src/python/test_provider_wfs.py
  93. +4 −4 tests/src/python/test_qgscolorschemeregistry.py
  94. +3 −3 tests/src/python/test_qgsdelimitedtextprovider.py
  95. +2 −2 tests/src/python/test_qgsproject.py
  96. +38 −37 tests/src/python/test_qgsrenderer.py
@@ -477,6 +477,11 @@ QgsColorRampShader {#qgis_api_break_3_0_QgsColorRampShader}
- maximumColorCacheSize() and setMaximumColorCacheSize() were no longer used and are removed.
- ColorRamp_TYPE enum was renamed to Type, and its value names decapitalized

QgsColorSchemeRegistry {#qgis_api_break_3_0_QgsColorSchemeRegistry}
----------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::colorSchemeRegistry() to access an application-wide registry.


QgsComposerArrow {#qgis_api_break_3_0_QgsComposerArrow}
----------------
@@ -727,6 +732,12 @@ QgsDataItem {#qgis_api_break_3_0_QgsDataItem}
- emitBeginInsertItems(), emitEndInsertItems(), emitBeginRemoveItems(), emitEndRemoveItems(), emitDataChanged(), emitStateChanged() have been removed.
- Favourites was renamed to Favorites

QgsDataItemProviderRegistry {#qgis_api_break_3_0_QgsDataItemProviderRegistry}
---------------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::dataItemProviderRegistry() to access an application-wide registry.


QgsDataProvider {#qgis_api_break_3_0_QgsDataProvider}
---------------

@@ -986,6 +997,11 @@ QgsEditorWidgetFactory {#qgis_api_break_3_0_QgsEditorWidgetFactory}
- `alignmentFlag` has been removed. Use QgsFieldFormatter::representValue() instead
- `createCache` has been removed. Use QgsFieldFormatter::representValue() instead

QgsGPSConnectionRegistry {#qgis_api_break_3_0_QgsGPSConnectionRegistry}
------------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::gpsConnectionRegistry() to access an application-wide registry.


QgsGraduatedRenderer {#qgis_api_break_3_0_QgsGraduatedRenderer}
--------------------
@@ -1208,6 +1224,12 @@ QgsMarkerSymbolLayer {#qgis_api_break_3_0_QgsMarkerSymbolLayer}
- bounds() is now pure virtual and must be implemented in all subclasses.


QgsMessageLog {#qgis_api_break_3_0_QgsMessageLog}
---------------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::messageLog() to access an application-wide log.


QgsMimeDataUtils {#qgis_api_break_3_0_QgsMimeDataUtils}
----------------

@@ -1258,6 +1280,11 @@ QgsNumericSortTreeWidgetItem {#qgis_api_break_3_0_QgsNumericSortTreeWidge
has improved sort capabilities including the ability to set custom sort values for items
and for forcing certain items to always sort on top.

QgsPaintEffectRegistry {#qgis_api_break_3_0_QgsPaintEffectRegistry}
----------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::paintEffectRegistry() to access an application-wide registry.


QgsPalettedRasterRenderer {#qgis_api_break_3_0_QgsPalettedRasterRenderer}
-------------------------
@@ -1300,6 +1327,12 @@ QgsPluginLayer {#qgis_api_break_3_0_QgsPluginLayer}
- createMapRenderer(): default implementation (which called plugin's draw() method) has been removed. Plugin layers must implement createMapRenderer().


QgsPluginLayerRegistry {#qgis_api_break_3_0_QgsPluginLayerRegistry}
----------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::pluginLayerRegistry() to access an application-wide registry.


QgsPointDisplacementRenderer {#qgis_api_break_3_0_QgsPointDisplacementRenderer}
----------------------------

@@ -1405,6 +1438,12 @@ be returned instead of a null pointer if no transformation is required.
- setCoordinateTransform() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should be used instead of a null pointer if no transformation is required.


QgsRendererRegistry {#qgis_api_break_3_0_QgsRendererRegistry}
----------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::rendererRegistry() to access an application-wide registry.


QgsRendererWidget {#qgis_api_break_3_0_QgsRendererWidget}
-----------------

@@ -1486,6 +1525,7 @@ QgsSublayersDialog {#qgis_api_break_3_0_QgsSublayersDialog}
QgsSvgCache {#qgis_api_break_3_0_QgsSvgCache}
-----------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::svgCache() to access an application-wide cache.
- containsParamsV2() was removed. Use containsParamsV3() instead.

QgsStyle (renamed from QgsStyleV2) {#qgis_api_break_3_0_QgsStyle}
@@ -1519,6 +1559,11 @@ the variant which takes QgsSymbolRenderContext instead.
- evaluateDataDefinedProperty( const QString& property, const QgsFeature* feature ) was removed. Use the variant which takes QgsSymbolRenderContext instead.
- expression() was removed. Use getDataDefinedProperty or evaluateDataDefinedProperty instead.

QgsSymbolLayerRegistry {#qgis_api_break_3_0_QgsSymbolLayerRegistry}
----------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::symbolLayerRegistry() to access an application-wide registry.


QgsSymbolLayerWidget {#qgis_api_break_3_0_QgsSymbolLayerWidget}
--------------------
@@ -246,7 +246,7 @@ def calculation_finished(exception, value=None):
task = QgsTask.fromFunction('my task', calculate,
on_finished=calculation_finished)
QgsTaskManager.instance().addTask(task)
QgsApplication.taskManager().addTask(task)
"""

@@ -67,9 +67,8 @@ class QgsPaintEffectRegistry

public:

/** Returns a reference to the singleton instance of the paint effect registry.
*/
static QgsPaintEffectRegistry* instance();
QgsPaintEffectRegistry();
~QgsPaintEffectRegistry();

/** Returns the metadata for a specific effect.
* @param name unique string name for paint effect class
@@ -120,10 +119,6 @@ class QgsPaintEffectRegistry
*/
static bool isDefaultStack( QgsPaintEffect* effect );

protected:
QgsPaintEffectRegistry();
~QgsPaintEffectRegistry();

private:
QgsPaintEffectRegistry( const QgsPaintEffectRegistry& rh );
};
@@ -6,7 +6,7 @@ class QgsGPSConnectionRegistry
#include <qgsgpsconnectionregistry.h>
%End
public:
static QgsGPSConnectionRegistry* instance();
QgsGPSConnectionRegistry();
~QgsGPSConnectionRegistry();

/** Inserts a connection into the registry. The connection is owned by the registry class until it is unregistered again*/
@@ -16,9 +16,6 @@ class QgsGPSConnectionRegistry

QList< QgsGPSConnection *> connectionList() const;

protected:
QgsGPSConnectionRegistry();

private:

QgsGPSConnectionRegistry( const QgsGPSConnectionRegistry& rh );
@@ -381,6 +381,62 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
*/
static QgsTaskManager* taskManager();

/**
* Returns the application's color scheme registry, used for managing color schemes.
* @note added in QGIS 3.0
*/
static QgsColorSchemeRegistry* colorSchemeRegistry();

/**
* Returns the application's paint effect registry, used for managing paint effects.
* @note added in QGIS 3.0
*/
static QgsPaintEffectRegistry* paintEffectRegistry();

/**
* Returns the application's renderer registry, used for managing vector layer renderers.
* @note added in QGIS 3.0
*/
static QgsRendererRegistry* rendererRegistry();

/**
* Returns the application's data item provider registry, which keeps a list of data item
* providers that may add items to the browser tree.
* @note added in QGIS 3.0
*/
static QgsDataItemProviderRegistry* dataItemProviderRegistry();

/**
* Returns the application's SVG cache, used for caching SVG images and handling parameter replacement
* within SVG files.
* @note added in QGIS 3.0
*/
static QgsSvgCache* svgCache();

/**
* Returns the application's symbol layer registry, used for managing symbol layers.
* @note added in QGIS 3.0
*/
static QgsSymbolLayerRegistry* symbolLayerRegistry();

/**
* Returns the application's GPS connection registry, used for managing GPS connections.
* @note added in QGIS 3.0
*/
static QgsGPSConnectionRegistry* gpsConnectionRegistry();

/**
* Returns the application's plugin layer registry, used for managing plugin layer types.
* @note added in QGIS 3.0
*/
static QgsPluginLayerRegistry* pluginLayerRegistry();

/**
* Returns the application's message log.
* @note added in QGIS 3.0
*/
static QgsMessageLog* messageLog();

%If(ANDROID)
//dummy method to workaround sip generation issue issue
bool x11EventFilter ( XEvent * event );
@@ -14,10 +14,6 @@ class QgsColorSchemeRegistry
%End
public:

/** Returns the global instance pointer, creating the object on the first call.
*/
static QgsColorSchemeRegistry * instance();

/** Constructor for an empty color scheme registry
*/
QgsColorSchemeRegistry();
@@ -11,8 +11,7 @@ class QgsDataItemProviderRegistry
#include <qgsdataitemproviderregistry.h>
%End
public:
static QgsDataItemProviderRegistry * instance();

QgsDataItemProviderRegistry();
~QgsDataItemProviderRegistry();

//! Get list of available providers
@@ -25,7 +24,7 @@ class QgsDataItemProviderRegistry
void removeProvider( QgsDataItemProvider* provider );

private:
QgsDataItemProviderRegistry();

QgsDataItemProviderRegistry( const QgsDataItemProviderRegistry& rh );

};
@@ -5,7 +5,7 @@ class QgsMessageLog : QObject
%End

public:
static QgsMessageLog *instance();
QgsMessageLog();

enum MessageLevel
{
@@ -20,8 +20,6 @@ class QgsMessageLog : QObject
signals:
void messageReceived( const QString& message, const QString& tag, MessageLevel level );

private:
QgsMessageLog();
};


@@ -37,8 +37,7 @@ class QgsPluginLayerRegistry

public:

/** Means of accessing canonical single instance */
static QgsPluginLayerRegistry* instance();
QgsPluginLayerRegistry();

~QgsPluginLayerRegistry();

@@ -62,8 +61,6 @@ class QgsPluginLayerRegistry

private:

/** Private since instance() creates it */
QgsPluginLayerRegistry();
QgsPluginLayerRegistry( const QgsPluginLayerRegistry& rh );

};
@@ -100,8 +100,8 @@ class QgsRendererRegistry

public:

//! Returns a pointer to the QgsRendererRegistry singleton
static QgsRendererRegistry* instance();
QgsRendererRegistry();
~QgsRendererRegistry();

//! Adds a renderer to the registry. Takes ownership of the metadata object.
//! @param metadata renderer metadata
@@ -128,11 +128,6 @@ class QgsRendererRegistry
//! @note added in QGIS 2.16
QStringList renderersList( const QgsVectorLayer* layer ) const;

protected:
//! protected constructor
QgsRendererRegistry();
~QgsRendererRegistry();

private:
QgsRendererRegistry( const QgsRendererRegistry& rh );
//QgsRendererRegistry& operator=( const QgsRendererRegistry& rh );
@@ -65,7 +65,8 @@ class QgsSvgCache : QObject

public:

static QgsSvgCache* instance();
QgsSvgCache( QObject * parent /TransferThis/ = 0 );

~QgsSvgCache();

/** Get SVG as QImage.
@@ -151,8 +152,6 @@ class QgsSvgCache : QObject
void statusChanged( const QString& theStatusQString );

protected:
//! protected constructor
QgsSvgCache( QObject * parent /TransferThis/ = 0 );

/** Creates new cache entry and returns pointer to it
* @param file Absolute or relative path to SVG file. If the path is relative the file is searched by QgsSymbolLayerUtils::symbolNameToPath() in SVG paths.
@@ -54,8 +54,8 @@ class QgsSymbolLayerRegistry

public:

//! return the single instance of this class (instantiate it if not exists)
static QgsSymbolLayerRegistry* instance();
QgsSymbolLayerRegistry();
~QgsSymbolLayerRegistry();

//! return metadata for specified symbol layer. Returns NULL if not found
QgsSymbolLayerAbstractMetadata* symbolLayerMetadata( const QString& name ) const;
@@ -75,10 +75,6 @@ class QgsSymbolLayerRegistry
//! create a new instance of symbol layer for specified symbol type with default settings
static QgsSymbolLayer* defaultSymbolLayer( QgsSymbol::SymbolType type ) /Factory/;

protected:
QgsSymbolLayerRegistry();
~QgsSymbolLayerRegistry();

private:
QgsSymbolLayerRegistry( const QgsSymbolLayerRegistry& rh );

@@ -417,7 +417,7 @@ QIcon QgsComposerPictureWidget::svgToIcon( const QString& filePath ) const
bool fillParam, fillOpacityParam, outlineParam, outlineWidthParam, outlineOpacityParam;
bool hasDefaultFillColor = false, hasDefaultFillOpacity = false, hasDefaultOutlineColor = false,
hasDefaultOutlineWidth = false, hasDefaultOutlineOpacity = false;
QgsSvgCache::instance()->containsParams( filePath, fillParam, hasDefaultFillColor, fill,
QgsApplication::svgCache()->containsParams( filePath, fillParam, hasDefaultFillColor, fill,
fillOpacityParam, hasDefaultFillOpacity, fillOpacity,
outlineParam, hasDefaultOutlineColor, outline,
outlineWidthParam, hasDefaultOutlineWidth, outlineWidth,
@@ -434,7 +434,7 @@ QIcon QgsComposerPictureWidget::svgToIcon( const QString& filePath ) const
outlineWidth = 0.6;

bool fitsInCache; // should always fit in cache at these sizes (i.e. under 559 px ^ 2, or half cache size)
const QImage& img = QgsSvgCache::instance()->svgAsImage( filePath, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );
const QImage& img = QgsApplication::svgCache()->svgAsImage( filePath, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );

return QIcon( QPixmap::fromImage( img ) );
}
@@ -458,7 +458,7 @@ void QgsComposerPictureWidget::updateSvgParamGui( bool resetValues )
QColor defaultFill, defaultOutline;
double defaultOutlineWidth, defaultFillOpacity, defaultOutlineOpacity;
bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultOutlineColor, hasDefaultOutlineWidth, hasDefaultOutlineOpacity;
QgsSvgCache::instance()->containsParams( picturePath, hasFillParam, hasDefaultFillColor, defaultFill,
QgsApplication::svgCache()->containsParams( picturePath, hasFillParam, hasDefaultFillColor, defaultFill,
hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth,
@@ -441,7 +441,7 @@ void QgsGPSInformationWidget::connected( QgsGPSConnection *conn )
mGPSPlainTextEdit->appendPlainText( tr( "Connected!" ) );
mConnectButton->setText( tr( "Dis&connect" ) );
//insert connection into registry such that it can also be used by other dialogs or plugins
QgsGPSConnectionRegistry::instance()->registerConnection( mNmea );
QgsApplication::gpsConnectionRegistry()->registerConnection( mNmea );
showStatusBarMessage( tr( "Connected to GPS device." ) );

if ( mLogFileGroupBox->isChecked() && ! mTxtLogFile->text().isEmpty() )
@@ -481,7 +481,7 @@ void QgsGPSInformationWidget::disconnectGps()
mLogFile = nullptr;
}

QgsGPSConnectionRegistry::instance()->unregisterConnection( mNmea );
QgsApplication::gpsConnectionRegistry()->unregisterConnection( mNmea );
delete mNmea;
mNmea = nullptr;
if ( mpMapMarker ) // marker should not be shown on GPS disconnected - not current position

0 comments on commit 9d4adc1

Please sign in to comment.
You can’t perform that action at this time.