Skip to content

Commit f4ca526

Browse files
committedOct 12, 2013
use static locals instead of global pointers for some ^Cngletons (proably more valgrind happyness; followup 572bda8)
1 parent e73718e commit f4ca526

24 files changed

+44
-114
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,6 @@ QgisApp::~QgisApp()
837837
// cancel request for FileOpen events
838838
QgsApplication::setFileOpenEventReceiver( 0 );
839839

840-
// delete map layer registry and provider registry
841840
QgsApplication::exitQgis();
842841

843842
delete QgsProject::instance();

‎src/app/qgsfieldsproperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ QgsVectorLayer::EditType QgsFieldsProperties::editTypeFromButton( QPushButton* b
734734

735735
QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent )
736736
{
737-
QgsAttributeEditorElement* widgetDef;
737+
QgsAttributeEditorElement *widgetDef = 0;
738738

739739
DesignerTreeItemData itemData = item->data( 0, DesignerTreeRole ).value<DesignerTreeItemData>();
740740
switch ( itemData.type() )

‎src/app/qgsshortcutsmanager.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717

1818
#include <QSettings>
1919

20+
QgsShortcutsManager* QgsShortcutsManager::mInstance = NULL;
21+
2022
QgsShortcutsManager::QgsShortcutsManager( QObject *parent ) : QObject( parent )
2123
{
2224
}
2325

24-
QgsShortcutsManager* QgsShortcutsManager::mInstance = NULL;
26+
QgsShortcutsManager::~QgsShortcutsManager()
27+
{
28+
mInstance = 0;
29+
}
2530

2631
QgsShortcutsManager* QgsShortcutsManager::instance( QObject *parent )
2732
{

‎src/app/qgsshortcutsmanager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class APP_EXPORT QgsShortcutsManager : public QObject
2828
{
29-
Q_OBJECT;
29+
Q_OBJECT
3030
public:
3131

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

59+
~QgsShortcutsManager();
60+
5961
public slots:
6062
void actionDestroyed();
6163

‎src/core/gps/qgsgpsconnectionregistry.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
#include "qgsgpsconnectionregistry.h"
1919
#include "qgsgpsconnection.h"
2020

21-
QgsGPSConnectionRegistry* QgsGPSConnectionRegistry::mInstance = 0;
22-
2321
QgsGPSConnectionRegistry::QgsGPSConnectionRegistry()
2422
{
25-
2623
}
2724

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

3734
QgsGPSConnectionRegistry* QgsGPSConnectionRegistry::instance()
3835
{
39-
if ( !mInstance )
40-
{
41-
mInstance = new QgsGPSConnectionRegistry();
42-
}
43-
return mInstance;
36+
static QgsGPSConnectionRegistry mInstance;
37+
return &mInstance;
4438
}
4539

4640
void QgsGPSConnectionRegistry::registerConnection( QgsGPSConnection* c )

‎src/core/qgsapplication.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ void QgsApplication::initQgis()
592592
void QgsApplication::exitQgis()
593593
{
594594
delete QgsMapLayerRegistry::instance();
595-
delete QgsProviderRegistry::instance();
596595
}
597596

598597
QString QgsApplication::showSettings()

‎src/core/qgscrscache.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@
1818
#include "qgscrscache.h"
1919
#include "qgscoordinatetransform.h"
2020

21-
QgsCoordinateTransformCache* QgsCoordinateTransformCache::mInstance = 0;
2221

2322
QgsCoordinateTransformCache* QgsCoordinateTransformCache::instance()
2423
{
25-
if ( !mInstance )
26-
{
27-
mInstance = new QgsCoordinateTransformCache();
28-
}
29-
return mInstance;
24+
static QgsCoordinateTransformCache mInstance;
25+
return &mInstance;
3026
}
3127

3228
QgsCoordinateTransformCache::~QgsCoordinateTransformCache()
@@ -36,7 +32,6 @@ QgsCoordinateTransformCache::~QgsCoordinateTransformCache()
3632
{
3733
delete tIt.value();
3834
}
39-
delete mInstance;
4035
}
4136

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

82-
QgsCRSCache* QgsCRSCache::mInstance = 0;
8377

8478
QgsCRSCache* QgsCRSCache::instance()
8579
{
86-
if ( !mInstance )
87-
{
88-
mInstance = new QgsCRSCache();
89-
}
90-
return mInstance;
80+
static QgsCRSCache mInstance;
81+
return &mInstance;
9182
}
9283

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

9788
QgsCRSCache::~QgsCRSCache()
9889
{
99-
delete mInstance;
10090
}
10191

10292
void QgsCRSCache::updateCRSCache( const QString& authid )

‎src/core/qgscrscache.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class CORE_EXPORT QgsCoordinateTransformCache
3838
void invalidateCrs( const QString& crsAuthId );
3939

4040
private:
41-
static QgsCoordinateTransformCache* mInstance;
4241
QHash< QPair< QString, QString >, QgsCoordinateTransform* > mTransforms;
4342
};
4443

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

5958
private:
60-
static QgsCRSCache* mInstance;
6159
QHash< QString, QgsCoordinateReferenceSystem > mCRS;
6260
/**CRS that is not initialised (returned in case of error)*/
6361
QgsCoordinateReferenceSystem mInvalidCRS;

‎src/core/qgsmaplayerregistry.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,9 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
245245
void connectNotify( const char * signal );
246246

247247
private:
248-
249-
static QgsMapLayerRegistry* mInstance;
250-
248+
static QgsMapLayerRegistry *mInstance;
251249
QMap<QString, QgsMapLayer*> mMapLayers;
252250
QSet<QgsMapLayer*> mOwnedLayers;
253-
254-
255-
256251
}; // class QgsMapLayerRegistry
257252

258253
#endif //QgsMapLayerRegistry_H

‎src/core/qgsproject.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include <QTextStream>
4242

4343
// canonical project instance
44-
QgsProject * QgsProject::theProject_;
44+
QgsProject *QgsProject::theProject_ = 0;
4545

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

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

360360

361361

362-
QgsProject * QgsProject::instance()
362+
QgsProject *QgsProject::instance()
363363
{
364-
if ( !QgsProject::theProject_ )
364+
if ( !theProject_ )
365365
{
366-
QgsProject::theProject_ = new QgsProject;
366+
theProject_ = new QgsProject;
367367
}
368-
369-
return QgsProject::theProject_;
370-
} // QgsProject * instance()
371-
372-
373-
368+
return theProject_;
369+
} // QgsProject *instance()
374370

375371
void QgsProject::title( QString const &title )
376372
{

‎src/core/qgsproviderregistry.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,12 @@ typedef QString protocolDrivers_t();
4343
//typedef int dataCapabilities_t();
4444
//typedef QgsDataItem * dataItem_t(QString);
4545

46-
QgsProviderRegistry *QgsProviderRegistry::_instance = 0;
46+
4747

4848
QgsProviderRegistry *QgsProviderRegistry::instance( QString pluginPath )
4949
{
50-
if ( _instance == 0 )
51-
{
52-
_instance = new QgsProviderRegistry( pluginPath );
53-
}
54-
55-
return _instance;
56-
50+
static QgsProviderRegistry mInstance( pluginPath );
51+
return &mInstance;
5752
} // QgsProviderRegistry::instance
5853

5954

‎src/core/qgsproviderregistry.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,9 @@ class CORE_EXPORT QgsProviderRegistry
155155
typedef std::map<QString, QgsProviderMetadata*> Providers;
156156

157157
private:
158-
159158
/** ctor private since instance() creates it */
160159
QgsProviderRegistry( QString pluginPath );
161160

162-
/** pointer to canonical Singleton object */
163-
static QgsProviderRegistry* _instance;
164-
165161
/** associative container of provider metadata handles */
166162
Providers mProviders;
167163

‎src/core/raster/qgsrasterrendererregistry.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ QgsRasterRendererRegistryEntry::QgsRasterRendererRegistryEntry(): rendererCreate
3535
{
3636
}
3737

38-
QgsRasterRendererRegistry* QgsRasterRendererRegistry::mInstance = 0;
39-
4038
QgsRasterRendererRegistry* QgsRasterRendererRegistry::instance()
4139
{
42-
if ( !mInstance )
43-
{
44-
mInstance = new QgsRasterRendererRegistry();
45-
}
46-
return mInstance;
40+
static QgsRasterRendererRegistry mInstance;
41+
return &mInstance;
4742
}
4843

4944
QgsRasterRendererRegistry::QgsRasterRendererRegistry()

‎src/core/symbology-ng/qgsrendererv2registry.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "qgsrulebasedrendererv2.h"
2222
#include "qgspointdisplacementrenderer.h"
2323

24-
QgsRendererV2Registry* QgsRendererV2Registry::mInstance = NULL;
25-
2624
QgsRendererV2Registry::QgsRendererV2Registry()
2725
{
2826
// add default renderers
@@ -59,10 +57,8 @@ QgsRendererV2Registry::~QgsRendererV2Registry()
5957

6058
QgsRendererV2Registry* QgsRendererV2Registry::instance()
6159
{
62-
if ( !mInstance )
63-
mInstance = new QgsRendererV2Registry();
64-
65-
return mInstance;
60+
static QgsRendererV2Registry mInstance;
61+
return &mInstance;
6662
}
6763

6864

‎src/core/symbology-ng/qgsrendererv2registry.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ class CORE_EXPORT QgsRendererV2Registry
156156
QgsRendererV2Registry();
157157
~QgsRendererV2Registry();
158158

159-
static QgsRendererV2Registry* mInstance;
160-
161159
QMap<QString, QgsRendererV2AbstractMetadata*> mRenderers;
162160

163161
//! list to keep order in which renderers have been added

‎src/core/symbology-ng/qgssvgcache.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,10 @@ double rasterScaleFactor;
7979
QColor fill;
8080
QColor outline;
8181

82-
QgsSvgCache* QgsSvgCache::mInstance = 0;
83-
8482
QgsSvgCache* QgsSvgCache::instance()
8583
{
86-
if ( !mInstance )
87-
{
88-
mInstance = new QgsSvgCache();
89-
}
90-
return mInstance;
84+
static QgsSvgCache mInstance;
85+
return &mInstance;
9186
}
9287

9388
QgsSvgCache::QgsSvgCache( QObject *parent )

‎src/core/symbology-ng/qgssvgcache.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ class CORE_EXPORT QgsSvgCache : public QObject
111111
void downloadProgress( qint64, qint64 );
112112

113113
private:
114-
static QgsSvgCache* mInstance;
115-
116114
/**Entry pointers accessible by file name*/
117115
QMultiHash< QString, QgsSvgCacheEntry* > mEntryLookup;
118116
/**Estimated total size of all images, pictures and svgContent*/

‎src/core/symbology-ng/qgssymbollayerv2registry.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "qgsfillsymbollayerv2.h"
2222
#include "qgsvectorfieldsymbollayer.h"
2323

24-
QgsSymbolLayerV2Registry* QgsSymbolLayerV2Registry::mInstance = NULL;
25-
2624
QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
2725
{
2826
// init registry with known symbol layers
@@ -83,9 +81,8 @@ QgsSymbolLayerV2AbstractMetadata* QgsSymbolLayerV2Registry::symbolLayerMetadata(
8381

8482
QgsSymbolLayerV2Registry* QgsSymbolLayerV2Registry::instance()
8583
{
86-
if ( !mInstance )
87-
mInstance = new QgsSymbolLayerV2Registry();
88-
return mInstance;
84+
static QgsSymbolLayerV2Registry mInstance;
85+
return &mInstance;
8986
}
9087

9188
QgsSymbolLayerV2* QgsSymbolLayerV2Registry::defaultSymbolLayer( QgsSymbolV2::SymbolType type )

‎src/core/symbology-ng/qgssymbollayerv2registry.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ class CORE_EXPORT QgsSymbolLayerV2Registry
140140
QgsSymbolLayerV2Registry();
141141
~QgsSymbolLayerV2Registry();
142142

143-
static QgsSymbolLayerV2Registry* mInstance;
144143
QMap<QString, QgsSymbolLayerV2AbstractMetadata*> mMetadata;
145144

146145
};

‎src/mapserver/qgsconfigcache.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
#include "qgssldparser.h"
2424
#include <QCoreApplication>
2525

26-
QgsConfigCache* QgsConfigCache::mInstance = 0;
2726

2827
QgsConfigCache* QgsConfigCache::instance()
2928
{
30-
if ( !mInstance )
31-
{
32-
mInstance = new QgsConfigCache();
33-
}
34-
return mInstance;
29+
static QgsConfigCache mInstance;
30+
return &mInstance;
3531
}
3632

3733
QgsConfigCache::QgsConfigCache()

‎src/mapserver/qgsmslayercache.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@
2020
#include "qgslogger.h"
2121
#include <QFile>
2222

23-
QgsMSLayerCache* QgsMSLayerCache::mInstance = 0;
24-
2523
QgsMSLayerCache* QgsMSLayerCache::instance()
2624
{
27-
if ( !mInstance )
28-
{
29-
mInstance = new QgsMSLayerCache();
30-
}
31-
return mInstance;
25+
static QgsMSLayerCache mInstance;
26+
return &mInstance;
3227
}
3328

3429
QgsMSLayerCache::QgsMSLayerCache()
@@ -55,7 +50,6 @@ QgsMSLayerCache::~QgsMSLayerCache()
5550
{
5651
delete entry.layerPointer;
5752
}
58-
delete mInstance;
5953
}
6054

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

0 commit comments

Comments
 (0)