Skip to content

Commit

Permalink
Remove some singletons by moving instances to QgsApplication
Browse files Browse the repository at this point in the history
- QgsColorSchemeRegistry
- QgsDataItemProviderRegistry
- QgsGPSConnectionRegistry
- QgsMessageLog
- QgsPaintEffectRegistry
- QgsPluginLayerRegistry
- QgsRasterRendererRegistry
- QgsRendererRegistry
- QgsSvgCache
- QgsSymbolLayerRegistry
  • Loading branch information
nyalldawson committed Dec 28, 2016
1 parent 4b1cf80 commit 9d4adc1
Show file tree
Hide file tree
Showing 96 changed files with 561 additions and 407 deletions.
45 changes: 45 additions & 0 deletions doc/api_break.dox
Expand Up @@ -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}
----------------
Expand Down Expand Up @@ -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}
---------------

Expand Down Expand Up @@ -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}
--------------------
Expand Down Expand Up @@ -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}
----------------

Expand Down Expand Up @@ -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}
-------------------------
Expand Down Expand Up @@ -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}
----------------------------

Expand Down Expand Up @@ -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}
-----------------

Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
--------------------
Expand Down
2 changes: 1 addition & 1 deletion python/core/__init__.py
Expand Up @@ -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)
"""

Expand Down
9 changes: 2 additions & 7 deletions python/core/effects/qgspainteffectregistry.sip
Expand Up @@ -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
Expand Down Expand Up @@ -120,10 +119,6 @@ class QgsPaintEffectRegistry
*/
static bool isDefaultStack( QgsPaintEffect* effect );

protected:
QgsPaintEffectRegistry();
~QgsPaintEffectRegistry();

private:
QgsPaintEffectRegistry( const QgsPaintEffectRegistry& rh );
};
Expand Down
5 changes: 1 addition & 4 deletions python/core/gps/qgsgpsconnectionregistry.sip
Expand Up @@ -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*/
Expand All @@ -16,9 +16,6 @@ class QgsGPSConnectionRegistry

QList< QgsGPSConnection *> connectionList() const;

protected:
QgsGPSConnectionRegistry();

private:

QgsGPSConnectionRegistry( const QgsGPSConnectionRegistry& rh );
Expand Down
56 changes: 56 additions & 0 deletions python/core/qgsapplication.sip
Expand Up @@ -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 );
Expand Down
4 changes: 0 additions & 4 deletions python/core/qgscolorschemeregistry.sip
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions python/core/qgsdataitemproviderregistry.sip
Expand Up @@ -11,8 +11,7 @@ class QgsDataItemProviderRegistry
#include <qgsdataitemproviderregistry.h>
%End
public:
static QgsDataItemProviderRegistry * instance();

QgsDataItemProviderRegistry();
~QgsDataItemProviderRegistry();

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

private:
QgsDataItemProviderRegistry();

QgsDataItemProviderRegistry( const QgsDataItemProviderRegistry& rh );

};
4 changes: 1 addition & 3 deletions python/core/qgsmessagelog.sip
Expand Up @@ -5,7 +5,7 @@ class QgsMessageLog : QObject
%End

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

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

private:
QgsMessageLog();
};


Expand Down
5 changes: 1 addition & 4 deletions python/core/qgspluginlayerregistry.sip
Expand Up @@ -37,8 +37,7 @@ class QgsPluginLayerRegistry

public:

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

~QgsPluginLayerRegistry();

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

private:

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

};
9 changes: 2 additions & 7 deletions python/core/symbology-ng/qgsrendererregistry.sip
Expand Up @@ -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
Expand All @@ -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 );
Expand Down
5 changes: 2 additions & 3 deletions python/core/symbology-ng/qgssvgcache.sip
Expand Up @@ -65,7 +65,8 @@ class QgsSvgCache : QObject

public:

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

~QgsSvgCache();

/** Get SVG as QImage.
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions python/core/symbology-ng/qgssymbollayerregistry.sip
Expand Up @@ -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;
Expand All @@ -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 );

Expand Down
6 changes: 3 additions & 3 deletions src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -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,
Expand All @@ -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 ) );
}
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -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() )
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9d4adc1

Please sign in to comment.