Skip to content

Commit e61d27e

Browse files
committed
Revert "Streamline singleton behavior in a class QgsSingleton"
This reverts commit e1f6edb as it breaks tests
1 parent e1f6edb commit e61d27e

10 files changed

+55
-81
lines changed

src/core/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ SET(QGIS_CORE_HDRS
557557
qgssimplifymethod.h
558558
qgssnapper.h
559559
qgsspatialindex.h
560-
qgssingleton.h
561560
qgstolerance.h
562561
qgsvectordataprovider.h
563562
qgsvectorlayercache.h

src/core/qgsapplication.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
***************************************************************************/
1515

1616
#include "qgsapplication.h"
17-
#include "qgscrscache.h"
18-
#include "qgsexception.h"
19-
#include "qgsgeometry.h"
2017
#include "qgslogger.h"
2118
#include "qgsmaplayerregistry.h"
22-
#include "qgsnetworkaccessmanager.h"
2319
#include "qgsproviderregistry.h"
20+
#include "qgsnetworkaccessmanager.h"
21+
#include "qgsexception.h"
22+
#include "qgsgeometry.h"
2423

2524
#include <QDir>
2625
#include <QFile>
@@ -608,13 +607,11 @@ void QgsApplication::initQgis()
608607

609608
void QgsApplication::exitQgis()
610609
{
611-
// Cleanup providers
610+
delete QgsMapLayerRegistry::instance();
611+
612612
delete QgsProviderRegistry::instance();
613613

614-
// Cleanup known singletons
615-
QgsMapLayerRegistry::cleanup();
616-
QgsNetworkAccessManager::cleanup();
617-
QgsCoordinateTransformCache::cleanup();
614+
delete QgsNetworkAccessManager::instance();
618615
}
619616

620617
QString QgsApplication::showSettings()

src/core/qgscrscache.cpp

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

21+
22+
QgsCoordinateTransformCache* QgsCoordinateTransformCache::instance()
23+
{
24+
static QgsCoordinateTransformCache mInstance;
25+
return &mInstance;
26+
}
27+
2128
QgsCoordinateTransformCache::~QgsCoordinateTransformCache()
2229
{
2330
QHash< QPair< QString, QString >, QgsCoordinateTransform* >::const_iterator tIt = mTransforms.constBegin();
2431
for ( ; tIt != mTransforms.constEnd(); ++tIt )
2532
{
2633
delete tIt.value();
2734
}
28-
29-
mTransforms.clear();
3035
}
3136

3237
const QgsCoordinateTransform* QgsCoordinateTransformCache::transform( const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform )

src/core/qgscrscache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
#define QGSCRSCACHE_H
2020

2121
#include "qgscoordinatereferencesystem.h"
22-
#include "qgssingleton.h"
2322
#include <QHash>
2423

2524
class QgsCoordinateTransform;
2625

2726
/**Cache coordinate transform by authid of source/dest transformation to avoid the
2827
overhead of initialisation for each redraw*/
29-
class CORE_EXPORT QgsCoordinateTransformCache : public QgsSingleton<QgsCoordinateTransformCache>
28+
class CORE_EXPORT QgsCoordinateTransformCache
3029
{
3130
public:
31+
static QgsCoordinateTransformCache* instance();
3232
~QgsCoordinateTransformCache();
3333
/**Returns coordinate transformation. Cache keeps ownership
3434
@param srcAuthId auth id string of source crs
@@ -41,6 +41,7 @@ class CORE_EXPORT QgsCoordinateTransformCache : public QgsSingleton<QgsCoordinat
4141
void invalidateCrs( const QString& crsAuthId );
4242

4343
private:
44+
static QgsCoordinateTransformCache* mInstance;
4445
QMultiHash< QPair< QString, QString >, QgsCoordinateTransform* > mTransforms; //same auth_id pairs might have different datum transformations
4546
};
4647

src/core/qgsmaplayerregistry.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
#include "qgsmaplayer.h"
2020
#include "qgslogger.h"
2121

22+
//
23+
// Static calls to enforce singleton behaviour
24+
//
25+
QgsMapLayerRegistry *QgsMapLayerRegistry::mInstance = 0;
26+
QgsMapLayerRegistry *QgsMapLayerRegistry::instance()
27+
{
28+
if ( mInstance == 0 )
29+
{
30+
mInstance = new QgsMapLayerRegistry();
31+
}
32+
return mInstance;
33+
}
34+
2235
//
2336
// Main class begins now...
2437
//

src/core/qgsmaplayerregistry.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@
2323
#include <QSet>
2424
#include <QObject>
2525
#include <QStringList>
26-
27-
#include "qgssingleton.h"
2826
class QString;
2927
class QgsMapLayer;
3028

3129
/** \ingroup core
3230
* This class tracks map layers that are currently loaded and provides
3331
* a means to fetch a pointer to a map layer and delete it.
3432
*/
35-
class CORE_EXPORT QgsMapLayerRegistry : public QObject, public QgsSingleton<QgsMapLayerRegistry>
33+
class CORE_EXPORT QgsMapLayerRegistry : public QObject
3634
{
3735
Q_OBJECT
3836

3937
public:
38+
//! Returns the instance pointer, creating the object on the first call
39+
static QgsMapLayerRegistry * instance();
40+
4041
//! Return the number of registered layers.
4142
int count();
4243

@@ -238,10 +239,9 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject, public QgsSingleton<QgsM
238239
//! private singleton constructor
239240
QgsMapLayerRegistry( QObject * parent = 0 );
240241

242+
static QgsMapLayerRegistry *mInstance;
241243
QMap<QString, QgsMapLayer*> mMapLayers;
242244
QSet<QgsMapLayer*> mOwnedLayers;
243-
244-
friend class QgsSingleton; // Let QgsSingleton access private constructor
245245
}; // class QgsMapLayerRegistry
246246

247247
#endif //QgsMapLayerRegistry_H

src/core/qgsnetworkaccessmanager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ class QgsNetworkProxyFactory : public QNetworkProxyFactory
8686
}
8787
};
8888

89+
//
90+
// Static calls to enforce singleton behaviour
91+
//
92+
QgsNetworkAccessManager* QgsNetworkAccessManager::sInstance = 0;
93+
QgsNetworkAccessManager* QgsNetworkAccessManager::instance()
94+
{
95+
if ( sInstance == 0 )
96+
{
97+
sInstance = new QgsNetworkAccessManager();
98+
}
99+
return sInstance;
100+
}
101+
89102
QgsNetworkAccessManager::QgsNetworkAccessManager( QObject *parent )
90103
: QNetworkAccessManager( parent )
91104
, mUseSystemProxy( false )

src/core/qgsnetworkaccessmanager.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include <QNetworkProxy>
2525
#include <QNetworkRequest>
2626

27-
#include "qgssingleton.h"
28-
2927
/*
3028
* \class QgsNetworkAccessManager
3129
* \brief network access manager for QGIS
@@ -43,11 +41,15 @@
4341
* that the fallback proxy should not be used for, then no proxy will be used.
4442
*
4543
*/
46-
class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager, public QgsSingleton<QgsNetworkAccessManager>
44+
class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
4745
{
4846
Q_OBJECT
4947

5048
public:
49+
//! returns a pointer to the single instance
50+
// and creates that instance on the first call.
51+
static QgsNetworkAccessManager* instance();
52+
5153
QgsNetworkAccessManager( QObject *parent = 0 );
5254

5355
//! destructor
@@ -98,6 +100,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager, public
98100
QNetworkProxy mFallbackProxy;
99101
QStringList mExcludedURLs;
100102
bool mUseSystemProxy;
103+
static QgsNetworkAccessManager* sInstance;
101104
};
102105

103106
#endif // QGSNETWORKACCESSMANAGER_H

src/core/qgsproviderregistry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ QgsProviderRegistry::~QgsProviderRegistry()
208208

209209
while ( it != mProviders.end() )
210210
{
211-
QgsDebugMsg( QString( "cleanup: %1" ).arg( it->first ) );
211+
QgsDebugMsg( QString( "cleanup:%1" ).arg( it->first ) );
212212
QString lib = it->second->library();
213213
QLibrary myLib( lib );
214214
if ( myLib.isLoaded() )
@@ -405,7 +405,7 @@ QWidget* QgsProviderRegistry::selectWidget( const QString & providerKey,
405405

406406
#if QT_VERSION >= 0x050000
407407
QFunctionPointer QgsProviderRegistry::function( QString const & providerKey,
408-
QString const & functionName )
408+
QString const & functionName )
409409
{
410410
QLibrary myLib( library( providerKey ) );
411411

src/core/qgssingleton.h

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)