Skip to content

Commit

Permalink
Revert "Streamline singleton behavior in a class QgsSingleton"
Browse files Browse the repository at this point in the history
This reverts commit e1f6edb as it breaks tests
  • Loading branch information
m-kuhn committed Nov 24, 2014
1 parent e1f6edb commit e61d27e
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 81 deletions.
1 change: 0 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ SET(QGIS_CORE_HDRS
qgssimplifymethod.h
qgssnapper.h
qgsspatialindex.h
qgssingleton.h
qgstolerance.h
qgsvectordataprovider.h
qgsvectorlayercache.h
Expand Down
15 changes: 6 additions & 9 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
***************************************************************************/

#include "qgsapplication.h"
#include "qgscrscache.h"
#include "qgsexception.h"
#include "qgsgeometry.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsproviderregistry.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsexception.h"
#include "qgsgeometry.h"

#include <QDir>
#include <QFile>
Expand Down Expand Up @@ -608,13 +607,11 @@ void QgsApplication::initQgis()

void QgsApplication::exitQgis()
{
// Cleanup providers
delete QgsMapLayerRegistry::instance();

delete QgsProviderRegistry::instance();

// Cleanup known singletons
QgsMapLayerRegistry::cleanup();
QgsNetworkAccessManager::cleanup();
QgsCoordinateTransformCache::cleanup();
delete QgsNetworkAccessManager::instance();
}

QString QgsApplication::showSettings()
Expand Down
9 changes: 7 additions & 2 deletions src/core/qgscrscache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@
#include "qgscrscache.h"
#include "qgscoordinatetransform.h"


QgsCoordinateTransformCache* QgsCoordinateTransformCache::instance()
{
static QgsCoordinateTransformCache mInstance;
return &mInstance;
}

QgsCoordinateTransformCache::~QgsCoordinateTransformCache()
{
QHash< QPair< QString, QString >, QgsCoordinateTransform* >::const_iterator tIt = mTransforms.constBegin();
for ( ; tIt != mTransforms.constEnd(); ++tIt )
{
delete tIt.value();
}

mTransforms.clear();
}

const QgsCoordinateTransform* QgsCoordinateTransformCache::transform( const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform )
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgscrscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
#define QGSCRSCACHE_H

#include "qgscoordinatereferencesystem.h"
#include "qgssingleton.h"
#include <QHash>

class QgsCoordinateTransform;

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

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

Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsmaplayerregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
#include "qgsmaplayer.h"
#include "qgslogger.h"

//
// Static calls to enforce singleton behaviour
//
QgsMapLayerRegistry *QgsMapLayerRegistry::mInstance = 0;
QgsMapLayerRegistry *QgsMapLayerRegistry::instance()
{
if ( mInstance == 0 )
{
mInstance = new QgsMapLayerRegistry();
}
return mInstance;
}

//
// Main class begins now...
//
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsmaplayerregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@
#include <QSet>
#include <QObject>
#include <QStringList>

#include "qgssingleton.h"
class QString;
class QgsMapLayer;

/** \ingroup core
* This class tracks map layers that are currently loaded and provides
* a means to fetch a pointer to a map layer and delete it.
*/
class CORE_EXPORT QgsMapLayerRegistry : public QObject, public QgsSingleton<QgsMapLayerRegistry>
class CORE_EXPORT QgsMapLayerRegistry : public QObject
{
Q_OBJECT

public:
//! Returns the instance pointer, creating the object on the first call
static QgsMapLayerRegistry * instance();

//! Return the number of registered layers.
int count();

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

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

friend class QgsSingleton; // Let QgsSingleton access private constructor
}; // class QgsMapLayerRegistry

#endif //QgsMapLayerRegistry_H
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ class QgsNetworkProxyFactory : public QNetworkProxyFactory
}
};

//
// Static calls to enforce singleton behaviour
//
QgsNetworkAccessManager* QgsNetworkAccessManager::sInstance = 0;
QgsNetworkAccessManager* QgsNetworkAccessManager::instance()
{
if ( sInstance == 0 )
{
sInstance = new QgsNetworkAccessManager();
}
return sInstance;
}

QgsNetworkAccessManager::QgsNetworkAccessManager( QObject *parent )
: QNetworkAccessManager( parent )
, mUseSystemProxy( false )
Expand Down
9 changes: 6 additions & 3 deletions src/core/qgsnetworkaccessmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <QNetworkProxy>
#include <QNetworkRequest>

#include "qgssingleton.h"

/*
* \class QgsNetworkAccessManager
* \brief network access manager for QGIS
Expand All @@ -43,11 +41,15 @@
* that the fallback proxy should not be used for, then no proxy will be used.
*
*/
class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager, public QgsSingleton<QgsNetworkAccessManager>
class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT

public:
//! returns a pointer to the single instance
// and creates that instance on the first call.
static QgsNetworkAccessManager* instance();

QgsNetworkAccessManager( QObject *parent = 0 );

//! destructor
Expand Down Expand Up @@ -98,6 +100,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager, public
QNetworkProxy mFallbackProxy;
QStringList mExcludedURLs;
bool mUseSystemProxy;
static QgsNetworkAccessManager* sInstance;
};

#endif // QGSNETWORKACCESSMANAGER_H
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsproviderregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ QgsProviderRegistry::~QgsProviderRegistry()

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

#if QT_VERSION >= 0x050000
QFunctionPointer QgsProviderRegistry::function( QString const & providerKey,
QString const & functionName )
QString const & functionName )
{
QLibrary myLib( library( providerKey ) );

Expand Down
57 changes: 0 additions & 57 deletions src/core/qgssingleton.h

This file was deleted.

0 comments on commit e61d27e

Please sign in to comment.