Skip to content

Commit d663599

Browse files
committedNov 20, 2014
Update cache
1 parent 4a4dc6b commit d663599

File tree

5 files changed

+36
-33
lines changed

5 files changed

+36
-33
lines changed
 

‎src/mapserver/qgsconfigcache.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,24 @@ QgsConfigCache::~QgsConfigCache()
4242

4343
QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
4444
{
45-
QgsServerProjectParser* p = mServerConfigCache.object( filePath );
46-
if ( !p )
45+
QDomDocument* doc = xmlDocument( filePath );
46+
if ( !doc )
4747
{
48-
QDomDocument* doc = xmlDocument( filePath );
49-
if ( !doc )
50-
{
51-
return 0;
52-
}
53-
p = new QgsServerProjectParser( doc, filePath );
54-
mServerConfigCache.insert( filePath, p );
55-
mFileSystemWatcher.addPath( filePath );
48+
return 0;
5649
}
57-
return p;
50+
return new QgsServerProjectParser( doc, filePath );
5851
}
5952

6053
QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
6154
{
6255
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
6356
if ( !p )
6457
{
58+
QDomDocument* doc = xmlDocument( filePath );
59+
if ( !doc )
60+
{
61+
return 0;
62+
}
6563
p = new QgsWCSProjectParser( filePath );
6664
mWCSConfigCache.insert( filePath, p );
6765
mFileSystemWatcher.addPath( filePath );
@@ -76,6 +74,11 @@ QgsWFSProjectParser* QgsConfigCache::wfsConfiguration( const QString& filePath )
7674
QgsWFSProjectParser* p = mWFSConfigCache.object( filePath );
7775
if ( !p )
7876
{
77+
QDomDocument* doc = xmlDocument( filePath );
78+
if ( !doc )
79+
{
80+
return 0;
81+
}
7982
p = new QgsWFSProjectParser( filePath );
8083
mWFSConfigCache.insert( filePath, p );
8184
mFileSystemWatcher.addPath( filePath );
@@ -117,12 +120,6 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c
117120

118121
QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
119122
{
120-
// first get cache
121-
QDomDocument* xmlDoc = mXmlDocumentCache.object( filePath );
122-
if ( xmlDoc )
123-
return xmlDoc;
124-
125-
// i it's first access
126123
//first open file
127124
QFile configFile( filePath );
128125
if ( !configFile.exists() )
@@ -136,26 +133,31 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
136133
QgsMessageLog::logMessage( "Error, cannot open configuration file '" + filePath + "'", "Server", QgsMessageLog::CRITICAL );
137134
return 0;
138135
}
139-
140-
//then create xml document
141-
xmlDoc = new QDomDocument();
142-
QString errorMsg;
143-
int line, column;
144-
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )
136+
137+
// first get cache
138+
QDomDocument* xmlDoc = mXmlDocumentCache.object( filePath );
139+
if ( !xmlDoc )
145140
{
146-
QgsMessageLog::logMessage( "Error parsing file '" + filePath +
147-
QString( "': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), "Server", QgsMessageLog::CRITICAL );
148-
delete xmlDoc;
149-
return 0;
141+
//then create xml document
142+
xmlDoc = new QDomDocument();
143+
QString errorMsg;
144+
int line, column;
145+
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )
146+
{
147+
QgsMessageLog::logMessage( "Error parsing file '" + filePath +
148+
QString( "': parse error %1 at row %2, column %3" ).arg( errorMsg ).arg( line ).arg( column ), "Server", QgsMessageLog::CRITICAL );
149+
delete xmlDoc;
150+
return 0;
151+
}
152+
mXmlDocumentCache.insert( filePath, xmlDoc );
153+
mFileSystemWatcher.addPath( filePath );
150154
}
151-
mXmlDocumentCache.insert( filePath, xmlDoc );
152155
return xmlDoc;
153156
}
154157

155158
void QgsConfigCache::removeChangedEntry( const QString& path )
156159
{
157160
mXmlDocumentCache.remove( path );
158-
mServerConfigCache.remove( path );
159161
mWMSConfigCache.remove( path );
160162
mWFSConfigCache.remove( path );
161163
mWCSConfigCache.remove( path );

‎src/mapserver/qgsconfigcache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class QgsConfigCache: public QObject
5353
QDomDocument* xmlDocument( const QString& filePath );
5454

5555
QCache<QString, QDomDocument> mXmlDocumentCache;
56-
QCache<QString, QgsServerProjectParser> mServerConfigCache;
5756
QCache<QString, QgsWMSConfigParser> mWMSConfigCache;
5857
QCache<QString, QgsWFSProjectParser> mWFSConfigCache;
5958
QCache<QString, QgsWCSProjectParser> mWCSConfigCache;

‎src/mapserver/qgswcsprojectparser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
***************************************************************************/
1717

1818
#include "qgswcsprojectparser.h"
19+
#include "qgsconfigcache.h"
1920
#include "qgsconfigparserutils.h"
2021
#include "qgsconfigcache.h"
2122
#include "qgsrasterlayer.h"
2223

2324
QgsWCSProjectParser::QgsWCSProjectParser( const QString& filePath )
2425
{
25-
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
26+
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
2627
}
2728

2829
QgsWCSProjectParser::~QgsWCSProjectParser()

‎src/mapserver/qgswfsprojectparser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
***************************************************************************/
1717

1818
#include "qgswfsprojectparser.h"
19+
#include "qgsconfigcache.h"
1920
#include "qgsconfigparserutils.h"
2021
#include "qgsconfigcache.h"
2122
#include "qgsmaplayerregistry.h"
2223
#include "qgsvectordataprovider.h"
2324

2425
QgsWFSProjectParser::QgsWFSProjectParser( const QString& filePath )
2526
{
26-
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
27+
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
2728
}
2829

2930
QgsWFSProjectParser::~QgsWFSProjectParser()

‎src/mapserver/qgswmsprojectparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
QgsWMSProjectParser::QgsWMSProjectParser( const QString& filePath )
4343
: QgsWMSConfigParser()
4444
{
45-
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
45+
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
4646
mLegendLayerFont.fromString( mProjectParser->firstComposerLegendElement().attribute( "layerFont" ) );
4747
mLegendItemFont.fromString( mProjectParser->firstComposerLegendElement().attribute( "itemFont" ) );
4848
createTextAnnotationItems();

0 commit comments

Comments
 (0)
Please sign in to comment.