Skip to content
Permalink
Browse files

Revert "Streamline singleton behavior in a class QgsSingleton"

This reverts commit e1f6edb as it breaks tests
  • Loading branch information
m-kuhn committed Nov 24, 2014
1 parent e1f6edb commit e61d27e180e9e3446bed9d5dd131f1980be60bb6
@@ -557,7 +557,6 @@ SET(QGIS_CORE_HDRS
qgssimplifymethod.h
qgssnapper.h
qgsspatialindex.h
qgssingleton.h
qgstolerance.h
qgsvectordataprovider.h
qgsvectorlayercache.h
@@ -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>
@@ -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()
@@ -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 )
@@ -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
@@ -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
};

@@ -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...
//
@@ -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();

@@ -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
@@ -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 )
@@ -24,8 +24,6 @@
#include <QNetworkProxy>
#include <QNetworkRequest>

#include "qgssingleton.h"

/*
* \class QgsNetworkAccessManager
* \brief network access manager for QGIS
@@ -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
@@ -98,6 +100,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager, public
QNetworkProxy mFallbackProxy;
QStringList mExcludedURLs;
bool mUseSystemProxy;
static QgsNetworkAccessManager* sInstance;
};

#endif // QGSNETWORKACCESSMANAGER_H
@@ -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() )
@@ -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 ) );

This file was deleted.

0 comments on commit e61d27e

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