20
20
#include " qgsmslayercache.h"
21
21
#include " qgsprojectparser.h"
22
22
#include " qgssldparser.h"
23
+ #include < QCoreApplication>
23
24
24
25
QgsConfigCache::QgsConfigCache ()
25
26
{
27
+ QObject::connect ( &mFileSystemWatcher , SIGNAL ( fileChanged ( const QString& ) ), this , SLOT ( removeChangedEntry ( const QString& ) ) );
26
28
}
27
29
28
30
QgsConfigCache::~QgsConfigCache ()
@@ -36,6 +38,7 @@ QgsConfigCache::~QgsConfigCache()
36
38
37
39
QgsConfigParser* QgsConfigCache::searchConfiguration ( const QString& filePath )
38
40
{
41
+ QCoreApplication::processEvents (); // check for updates from file system watcher
39
42
QgsConfigParser* p = 0 ;
40
43
QHash<QString, QgsConfigParser*>::const_iterator configIt = mCachedConfigurations .find ( filePath );
41
44
if ( configIt == mCachedConfigurations .constEnd () )
@@ -63,7 +66,12 @@ QgsConfigParser* QgsConfigCache::insertConfiguration( const QString& filePath )
63
66
{
64
67
// remove a cache entry to avoid memory problems
65
68
QHash<QString, QgsConfigParser*>::iterator configIt = mCachedConfigurations .begin ();
66
- mCachedConfigurations .erase ( configIt );
69
+ if ( configIt != mCachedConfigurations .end () )
70
+ {
71
+ mFileSystemWatcher .removePath ( configIt.key () );
72
+ delete configIt.value ();
73
+ mCachedConfigurations .erase ( configIt );
74
+ }
67
75
}
68
76
69
77
// first open file
@@ -107,6 +115,19 @@ QgsConfigParser* QgsConfigCache::insertConfiguration( const QString& filePath )
107
115
}
108
116
109
117
mCachedConfigurations .insert ( filePath, configParser );
118
+ mFileSystemWatcher .addPath ( filePath );
110
119
delete configFile;
111
120
return configParser;
112
121
}
122
+
123
+ void QgsConfigCache::removeChangedEntry ( const QString& path )
124
+ {
125
+ QgsMSDebugMsg ( " Remove config cache entry because file changed" );
126
+ QHash<QString, QgsConfigParser*>::iterator configIt = mCachedConfigurations .find ( path );
127
+ if ( configIt != mCachedConfigurations .end () )
128
+ {
129
+ delete configIt.value ();
130
+ mCachedConfigurations .erase ( configIt );
131
+ }
132
+ mFileSystemWatcher .removePath ( path );
133
+ }
0 commit comments