Skip to content
Permalink
Browse files

GetMap refactoring

  • Loading branch information
pblottiere committed May 30, 2017
1 parent a53f660 commit 438ffd2e88f8534513dad82c723654d890ef480b
@@ -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();
@@ -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
*/
@@ -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(
@@ -31,6 +31,7 @@

class QgsServerProjectParser;
class QgsAccessControl;
class QgsProject;

class SERVER_EXPORT QgsConfigCache : public QObject
{
@@ -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();

@@ -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
@@ -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 ) )
{
@@ -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;
@@ -76,6 +76,7 @@ QgsServer::QgsServer( )
abort();
}
init();
mConfigCache = QgsConfigCache::instance();
}

QString &QgsServer::serverName()
@@ -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 );
@@ -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
{
@@ -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.
You can’t perform that action at this time.