Skip to content
Permalink
Browse files

use static locals instead of global pointers for some ^Cngletons (pro…

…ably more valgrind happyness; followup 572bda8)
  • Loading branch information
jef-n committed Oct 12, 2013
1 parent e73718e commit f4ca526ab409c2088ce9077d4adbd439eb6ac69e
@@ -837,7 +837,6 @@ QgisApp::~QgisApp()
// cancel request for FileOpen events
QgsApplication::setFileOpenEventReceiver( 0 );

// delete map layer registry and provider registry
QgsApplication::exitQgis();

delete QgsProject::instance();
@@ -734,7 +734,7 @@ QgsVectorLayer::EditType QgsFieldsProperties::editTypeFromButton( QPushButton* b

QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent )
{
QgsAttributeEditorElement* widgetDef;
QgsAttributeEditorElement *widgetDef = 0;

DesignerTreeItemData itemData = item->data( 0, DesignerTreeRole ).value<DesignerTreeItemData>();
switch ( itemData.type() )
@@ -17,11 +17,16 @@

#include <QSettings>

QgsShortcutsManager* QgsShortcutsManager::mInstance = NULL;

QgsShortcutsManager::QgsShortcutsManager( QObject *parent ) : QObject( parent )
{
}

QgsShortcutsManager* QgsShortcutsManager::mInstance = NULL;
QgsShortcutsManager::~QgsShortcutsManager()
{
mInstance = 0;
}

QgsShortcutsManager* QgsShortcutsManager::instance( QObject *parent )
{
@@ -26,7 +26,7 @@
*/
class APP_EXPORT QgsShortcutsManager : public QObject
{
Q_OBJECT;
Q_OBJECT
public:

//! return instance of the manager
@@ -56,6 +56,8 @@ class APP_EXPORT QgsShortcutsManager : public QObject
// return action by it's name. NULL if nothing found
QAction* actionByName( QString name );

~QgsShortcutsManager();

public slots:
void actionDestroyed();

@@ -18,11 +18,8 @@
#include "qgsgpsconnectionregistry.h"
#include "qgsgpsconnection.h"

QgsGPSConnectionRegistry* QgsGPSConnectionRegistry::mInstance = 0;

QgsGPSConnectionRegistry::QgsGPSConnectionRegistry()
{

}

QgsGPSConnectionRegistry::~QgsGPSConnectionRegistry()
@@ -36,11 +33,8 @@ QgsGPSConnectionRegistry::~QgsGPSConnectionRegistry()

QgsGPSConnectionRegistry* QgsGPSConnectionRegistry::instance()
{
if ( !mInstance )
{
mInstance = new QgsGPSConnectionRegistry();
}
return mInstance;
static QgsGPSConnectionRegistry mInstance;
return &mInstance;
}

void QgsGPSConnectionRegistry::registerConnection( QgsGPSConnection* c )
@@ -592,7 +592,6 @@ void QgsApplication::initQgis()
void QgsApplication::exitQgis()
{
delete QgsMapLayerRegistry::instance();
delete QgsProviderRegistry::instance();
}

QString QgsApplication::showSettings()
@@ -18,15 +18,11 @@
#include "qgscrscache.h"
#include "qgscoordinatetransform.h"

QgsCoordinateTransformCache* QgsCoordinateTransformCache::mInstance = 0;

QgsCoordinateTransformCache* QgsCoordinateTransformCache::instance()
{
if ( !mInstance )
{
mInstance = new QgsCoordinateTransformCache();
}
return mInstance;
static QgsCoordinateTransformCache mInstance;
return &mInstance;
}

QgsCoordinateTransformCache::~QgsCoordinateTransformCache()
@@ -36,7 +32,6 @@ QgsCoordinateTransformCache::~QgsCoordinateTransformCache()
{
delete tIt.value();
}
delete mInstance;
}

const QgsCoordinateTransform* QgsCoordinateTransformCache::transform( const QString& srcAuthId, const QString& destAuthId )
@@ -79,15 +74,11 @@ void QgsCoordinateTransformCache::invalidateCrs( const QString& crsAuthId )
}
}

QgsCRSCache* QgsCRSCache::mInstance = 0;

QgsCRSCache* QgsCRSCache::instance()
{
if ( !mInstance )
{
mInstance = new QgsCRSCache();
}
return mInstance;
static QgsCRSCache mInstance;
return &mInstance;
}

QgsCRSCache::QgsCRSCache()
@@ -96,7 +87,6 @@ QgsCRSCache::QgsCRSCache()

QgsCRSCache::~QgsCRSCache()
{
delete mInstance;
}

void QgsCRSCache::updateCRSCache( const QString& authid )
@@ -38,7 +38,6 @@ class CORE_EXPORT QgsCoordinateTransformCache
void invalidateCrs( const QString& crsAuthId );

private:
static QgsCoordinateTransformCache* mInstance;
QHash< QPair< QString, QString >, QgsCoordinateTransform* > mTransforms;
};

@@ -57,7 +56,6 @@ class CORE_EXPORT QgsCRSCache
QgsCRSCache();

private:
static QgsCRSCache* mInstance;
QHash< QString, QgsCoordinateReferenceSystem > mCRS;
/**CRS that is not initialised (returned in case of error)*/
QgsCoordinateReferenceSystem mInvalidCRS;
@@ -245,14 +245,9 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
void connectNotify( const char * signal );

private:

static QgsMapLayerRegistry* mInstance;

static QgsMapLayerRegistry *mInstance;
QMap<QString, QgsMapLayer*> mMapLayers;
QSet<QgsMapLayer*> mOwnedLayers;



}; // class QgsMapLayerRegistry

#endif //QgsMapLayerRegistry_H
@@ -41,7 +41,7 @@
#include <QTextStream>

// canonical project instance
QgsProject * QgsProject::theProject_;
QgsProject *QgsProject::theProject_ = 0;

/**
Take the given scope and key and convert them to a string list of key
@@ -304,8 +304,8 @@ struct QgsProject::Imp
bool dirty;

Imp()
: title( "" ),
dirty( false )
: title( "" )
, dirty( false )
{ // top property node is the root
// "properties" that contains all plug-in
// and extra property keys and values
@@ -359,18 +359,14 @@ QgsProject::~QgsProject()



QgsProject * QgsProject::instance()
QgsProject *QgsProject::instance()
{
if ( !QgsProject::theProject_ )
if ( !theProject_ )
{
QgsProject::theProject_ = new QgsProject;
theProject_ = new QgsProject;
}

return QgsProject::theProject_;
} // QgsProject * instance()



return theProject_;
} // QgsProject *instance()

void QgsProject::title( QString const &title )
{
@@ -43,17 +43,12 @@ typedef QString protocolDrivers_t();
//typedef int dataCapabilities_t();
//typedef QgsDataItem * dataItem_t(QString);

QgsProviderRegistry *QgsProviderRegistry::_instance = 0;


QgsProviderRegistry *QgsProviderRegistry::instance( QString pluginPath )
{
if ( _instance == 0 )
{
_instance = new QgsProviderRegistry( pluginPath );
}

return _instance;

static QgsProviderRegistry mInstance( pluginPath );
return &mInstance;
} // QgsProviderRegistry::instance


@@ -155,13 +155,9 @@ class CORE_EXPORT QgsProviderRegistry
typedef std::map<QString, QgsProviderMetadata*> Providers;

private:

/** ctor private since instance() creates it */
QgsProviderRegistry( QString pluginPath );

/** pointer to canonical Singleton object */
static QgsProviderRegistry* _instance;

/** associative container of provider metadata handles */
Providers mProviders;

@@ -35,15 +35,10 @@ QgsRasterRendererRegistryEntry::QgsRasterRendererRegistryEntry(): rendererCreate
{
}

QgsRasterRendererRegistry* QgsRasterRendererRegistry::mInstance = 0;

QgsRasterRendererRegistry* QgsRasterRendererRegistry::instance()
{
if ( !mInstance )
{
mInstance = new QgsRasterRendererRegistry();
}
return mInstance;
static QgsRasterRendererRegistry mInstance;
return &mInstance;
}

QgsRasterRendererRegistry::QgsRasterRendererRegistry()
@@ -21,8 +21,6 @@
#include "qgsrulebasedrendererv2.h"
#include "qgspointdisplacementrenderer.h"

QgsRendererV2Registry* QgsRendererV2Registry::mInstance = NULL;

QgsRendererV2Registry::QgsRendererV2Registry()
{
// add default renderers
@@ -59,10 +57,8 @@ QgsRendererV2Registry::~QgsRendererV2Registry()

QgsRendererV2Registry* QgsRendererV2Registry::instance()
{
if ( !mInstance )
mInstance = new QgsRendererV2Registry();

return mInstance;
static QgsRendererV2Registry mInstance;
return &mInstance;
}


@@ -156,8 +156,6 @@ class CORE_EXPORT QgsRendererV2Registry
QgsRendererV2Registry();
~QgsRendererV2Registry();

static QgsRendererV2Registry* mInstance;

QMap<QString, QgsRendererV2AbstractMetadata*> mRenderers;

//! list to keep order in which renderers have been added
@@ -79,15 +79,10 @@ double rasterScaleFactor;
QColor fill;
QColor outline;

QgsSvgCache* QgsSvgCache::mInstance = 0;

QgsSvgCache* QgsSvgCache::instance()
{
if ( !mInstance )
{
mInstance = new QgsSvgCache();
}
return mInstance;
static QgsSvgCache mInstance;
return &mInstance;
}

QgsSvgCache::QgsSvgCache( QObject *parent )
@@ -111,8 +111,6 @@ class CORE_EXPORT QgsSvgCache : public QObject
void downloadProgress( qint64, qint64 );

private:
static QgsSvgCache* mInstance;

/**Entry pointers accessible by file name*/
QMultiHash< QString, QgsSvgCacheEntry* > mEntryLookup;
/**Estimated total size of all images, pictures and svgContent*/
@@ -21,8 +21,6 @@
#include "qgsfillsymbollayerv2.h"
#include "qgsvectorfieldsymbollayer.h"

QgsSymbolLayerV2Registry* QgsSymbolLayerV2Registry::mInstance = NULL;

QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
{
// init registry with known symbol layers
@@ -83,9 +81,8 @@ QgsSymbolLayerV2AbstractMetadata* QgsSymbolLayerV2Registry::symbolLayerMetadata(

QgsSymbolLayerV2Registry* QgsSymbolLayerV2Registry::instance()
{
if ( !mInstance )
mInstance = new QgsSymbolLayerV2Registry();
return mInstance;
static QgsSymbolLayerV2Registry mInstance;
return &mInstance;
}

QgsSymbolLayerV2* QgsSymbolLayerV2Registry::defaultSymbolLayer( QgsSymbolV2::SymbolType type )
@@ -140,7 +140,6 @@ class CORE_EXPORT QgsSymbolLayerV2Registry
QgsSymbolLayerV2Registry();
~QgsSymbolLayerV2Registry();

static QgsSymbolLayerV2Registry* mInstance;
QMap<QString, QgsSymbolLayerV2AbstractMetadata*> mMetadata;

};
@@ -23,15 +23,11 @@
#include "qgssldparser.h"
#include <QCoreApplication>

QgsConfigCache* QgsConfigCache::mInstance = 0;

QgsConfigCache* QgsConfigCache::instance()
{
if ( !mInstance )
{
mInstance = new QgsConfigCache();
}
return mInstance;
static QgsConfigCache mInstance;
return &mInstance;
}

QgsConfigCache::QgsConfigCache()
@@ -20,15 +20,10 @@
#include "qgslogger.h"
#include <QFile>

QgsMSLayerCache* QgsMSLayerCache::mInstance = 0;

QgsMSLayerCache* QgsMSLayerCache::instance()
{
if ( !mInstance )
{
mInstance = new QgsMSLayerCache();
}
return mInstance;
static QgsMSLayerCache mInstance;
return &mInstance;
}

QgsMSLayerCache::QgsMSLayerCache()
@@ -55,7 +50,6 @@ QgsMSLayerCache::~QgsMSLayerCache()
{
delete entry.layerPointer;
}
delete mInstance;
}

void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName, QgsMapLayer* layer, const QString& configFile, const QList<QString>& tempFiles )

0 comments on commit f4ca526

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