|
@@ -20,9 +20,6 @@ |
|
|
#include "qgslogger.h" |
|
|
#include <QFile> |
|
|
|
|
|
//maximum number of layers in the cache |
|
|
#define DEFAULT_MAX_N_LAYERS 100 |
|
|
|
|
|
QgsMSLayerCache* QgsMSLayerCache::mInstance = 0; |
|
|
|
|
|
QgsMSLayerCache* QgsMSLayerCache::instance() |
|
@@ -36,6 +33,18 @@ QgsMSLayerCache* QgsMSLayerCache::instance() |
|
|
|
|
|
QgsMSLayerCache::QgsMSLayerCache() |
|
|
{ |
|
|
mDefaultMaxLayers = 100; |
|
|
//max layer from environment variable overrides default |
|
|
char* maxLayerEnv = getenv( "MAX_CACHE_LAYERS" ); |
|
|
if ( maxLayerEnv ) |
|
|
{ |
|
|
bool conversionOk = false; |
|
|
int maxLayerInt = QString( maxLayerEnv ).toInt( &conversionOk ); |
|
|
if ( conversionOk ) |
|
|
{ |
|
|
mDefaultMaxLayers = maxLayerInt; |
|
|
} |
|
|
} |
|
|
QObject::connect( &mFileSystemWatcher, SIGNAL( fileChanged( const QString& ) ), this, SLOT( removeProjectFileLayers( const QString& ) ) ); |
|
|
} |
|
|
|
|
@@ -52,7 +61,7 @@ QgsMSLayerCache::~QgsMSLayerCache() |
|
|
void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName, QgsMapLayer* layer, const QString& configFile, const QList<QString>& tempFiles ) |
|
|
{ |
|
|
QgsDebugMsg( "inserting layer" ); |
|
|
if ( mEntries.size() > std::max( DEFAULT_MAX_N_LAYERS, mProjectMaxLayers ) ) //force cache layer examination after 10 inserted layers |
|
|
if ( mEntries.size() > std::max( mDefaultMaxLayers, mProjectMaxLayers ) ) //force cache layer examination after 10 inserted layers |
|
|
{ |
|
|
updateEntries(); |
|
|
} |
|
@@ -131,7 +140,7 @@ void QgsMSLayerCache::removeProjectFileLayers( const QString& project ) |
|
|
void QgsMSLayerCache::updateEntries() |
|
|
{ |
|
|
QgsDebugMsg( "updateEntries" ); |
|
|
int entriesToDelete = mEntries.size() - std::max( DEFAULT_MAX_N_LAYERS, mProjectMaxLayers ); |
|
|
int entriesToDelete = mEntries.size() - std::max( mDefaultMaxLayers, mProjectMaxLayers ); |
|
|
if ( entriesToDelete < 1 ) |
|
|
{ |
|
|
return; |
|
|