Skip to content

Commit

Permalink
GetMap refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed May 30, 2017
1 parent a53f660 commit 438ffd2
Show file tree
Hide file tree
Showing 19 changed files with 1,951 additions and 301 deletions.
5 changes: 5 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -1980,6 +1980,11 @@ QgsAnnotationManager *QgsProject::annotationManager()
return mAnnotationManager.get();
}

const QgsAnnotationManager *QgsProject::annotationManager() const
{
return mAnnotationManager.get();
}

void QgsProject::setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers )
{
QStringList currentLayers = nonIdentifiableLayers();
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsproject.h
Expand Up @@ -419,6 +419,12 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
QgsAnnotationManager *annotationManager();

/**
* Returns a const pointer to the project's annotation manager.
* \since QGIS 3.0
*/
const QgsAnnotationManager *annotationManager() const SIP_SKIP;

/**
* Set a list of layers which should not be taken into account on map identification
*/
Expand Down
14 changes: 14 additions & 0 deletions src/server/qgsconfigcache.cpp
Expand Up @@ -40,6 +40,20 @@ QgsConfigCache::QgsConfigCache()
QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged, this, &QgsConfigCache::removeChangedEntry );
}

const QgsProject *QgsConfigCache::project( const QString &path )
{
if ( ! mProjectCache[ path ] )
{
std::unique_ptr<QgsProject> prj( new QgsProject() );
if ( prj->read( path ) )
{
mProjectCache.insert( path, prj.release() );
}
}

return mProjectCache[ path ];
}

QgsServerProjectParser *QgsConfigCache::serverConfiguration( const QString &filePath )
{
QgsMessageLog::logMessage(
Expand Down
10 changes: 10 additions & 0 deletions src/server/qgsconfigcache.h
Expand Up @@ -31,6 +31,7 @@

class QgsServerProjectParser;
class QgsAccessControl;
class QgsProject;

class SERVER_EXPORT QgsConfigCache : public QObject
{
Expand All @@ -47,6 +48,14 @@ class SERVER_EXPORT QgsConfigCache : public QObject

void removeEntry( const QString &path );

/** If the project is not cached yet, then the project is read thank to the
* path. If the project is not available, then a nullptr is returned.
* \param path the filename of the QGIS project
* \returns the project or nullptr if an error happened
* \since QGIS 3.0
*/
const QgsProject *project( const QString &path );

private:
QgsConfigCache();

Expand All @@ -58,6 +67,7 @@ class SERVER_EXPORT QgsConfigCache : public QObject

QCache<QString, QDomDocument> mXmlDocumentCache;
QCache<QString, QgsWmsConfigParser> mWMSConfigCache;
QCache<QString, QgsProject> mProjectCache;

private slots:
//! Removes changed entry from this cache
Expand Down
26 changes: 25 additions & 1 deletion src/server/qgsfilterrestorer.cpp
Expand Up @@ -40,8 +40,32 @@ void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccess
}
if ( !layer->subsetString().isEmpty() )
{
sql.prepend( " AND " );
sql.prepend( ") AND (" );
sql.append( ")" );
sql.prepend( layer->subsetString() );
sql.prepend( "(" );
}
if ( !layer->setSubsetString( sql ) )
{
QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
}
}
}
}

void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccessControl *accessControl, QgsMapLayer *mapLayer )
{
if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer ) )
{
QString sql = accessControl->extraSubsetString( layer );
if ( !sql.isEmpty() )
{
if ( !layer->subsetString().isEmpty() )
{
sql.prepend( ") AND (" );
sql.append( ")" );
sql.prepend( layer->subsetString() );
sql.prepend( "(" );
}
if ( !layer->setSubsetString( sql ) )
{
Expand Down
7 changes: 7 additions & 0 deletions src/server/qgsfilterrestorer.h
Expand Up @@ -53,6 +53,13 @@ class SERVER_EXPORT QgsOWSServerFilterRestorer
static void applyAccessControlLayerFilters( const QgsAccessControl *accessControl, QgsMapLayer *mapLayer,
QHash<QgsMapLayer *, QString> &originalLayerFilters );

/** Applies filters from access control on layer.
* \param accessControl The access control instance
* \param mapLayer The layer on which the filter has to be applied
* \since QGIS 3.0
*/
static void applyAccessControlLayerFilters( const QgsAccessControl *accessControl, QgsMapLayer *mapLayer );

private:
const QgsAccessControl *mAccessControl = nullptr;
QHash<QgsMapLayer *, QString> mOriginalLayerFilters;
Expand Down
19 changes: 5 additions & 14 deletions src/server/qgsserver.cpp
Expand Up @@ -76,6 +76,7 @@ QgsServer::QgsServer( )
abort();
}
init();
mConfigCache = QgsConfigCache::instance();
}

QString &QgsServer::serverName()
Expand Down Expand Up @@ -353,20 +354,10 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
QString configFilePath = configPath( *sConfigFilePath, parameterMap );

// load the project if needed and not empty
auto projectIt = mProjectRegistry.find( configFilePath );
if ( projectIt == mProjectRegistry.constEnd() )
const QgsProject *project = mConfigCache->project( configFilePath );
if ( ! project )
{
// load the project
QgsProject *project = new QgsProject();
project->setFileName( configFilePath );
if ( project->read() )
{
projectIt = mProjectRegistry.insert( configFilePath, project );
}
else
{
throw QgsServerException( QStringLiteral( "Project file error" ) );
}
throw QgsServerException( QStringLiteral( "Project file error" ) );
}

sServerInterface->setConfigFilePath( configFilePath );
Expand Down Expand Up @@ -397,7 +388,7 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
QgsService *service = sServiceRegistry.getService( serviceString, versionString );
if ( service )
{
service->executeRequest( request, responseDecorator, projectIt.value() );
service->executeRequest( request, responseDecorator, project );
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsserver.h
Expand Up @@ -124,8 +124,8 @@ class SERVER_EXPORT QgsServer

static QgsServerSettings sSettings;

// map of QgsProject
QMap<QString, const QgsProject *> mProjectRegistry;
//! cache
QgsConfigCache *mConfigCache;
};
#endif // QGSSERVER_H

0 comments on commit 438ffd2

Please sign in to comment.