Skip to content

Commit

Permalink
[Server] Various code cleaning for server cache manager and WMTS service
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Aug 21, 2018
1 parent d0041a2 commit 7633d2a
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 160 deletions.
2 changes: 1 addition & 1 deletion python/server/auto_generated/qgsservercachemanager.sip.in
Expand Up @@ -33,7 +33,7 @@ Constructor

QgsServerCacheManager( const QgsServerCacheManager &copy );
%Docstring
Constructor
Copy constructor
%End


Expand Down
4 changes: 4 additions & 0 deletions python/server/auto_generated/qgsserverinterface.sip.in
Expand Up @@ -91,11 +91,15 @@ Register a server cache filter

:param serverCache: the server cache to register
:param priority: the priority used to order them

.. versionadded:: 3.4
%End

virtual QgsServerCacheManager *cacheManager() const = 0;
%Docstring
Gets the registered server cache filters

.. versionadded:: 3.4
%End

virtual QString getEnv( const QString &name ) const = 0;
Expand Down
36 changes: 19 additions & 17 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -672,30 +672,27 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
QStringList wmtsPngLayerIdList = QgsProject::instance()->readListEntry( QStringLiteral( "WMTSPngLayers" ), QStringLiteral( "Layer" ) );
QStringList wmtsJpegLayerIdList = QgsProject::instance()->readListEntry( QStringLiteral( "WMTSJpegLayers" ), QStringLiteral( "Layer" ) );

QgsTreeWidgetItem *projItem = new QgsTreeWidgetItem( QStringList() << QStringLiteral( "Project" ) << QLatin1String( "" ) );
QgsTreeWidgetItem *projItem = new QgsTreeWidgetItem( QStringList() << QStringLiteral( "Project" ) );
projItem->setFlags( projItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable );
projItem->setCheckState( 1, wmtsProject ? Qt::Checked : Qt::Unchecked );
projItem->setCheckState( 2, wmtsPngProject ? Qt::Checked : Qt::Unchecked );
projItem->setCheckState( 3, wmtsJpegProject ? Qt::Checked : Qt::Unchecked );
projItem->setData( 0, Qt::UserRole, "project" );
projItem->setData( 0, Qt::UserRole, QStringLiteral( "project" ) );
twWmtsLayers->addTopLevelItem( projItem );
populateWmtsTree( QgsProject::instance()->layerTreeRoot(), projItem );
projItem->setExpanded( true );
twWmtsLayers->header()->resizeSections( QHeaderView::ResizeToContents );
Q_FOREACH ( QTreeWidgetItem *item, twWmtsLayers->findItems( "", Qt::MatchContains | Qt::MatchRecursive, 1 ) )
for ( QTreeWidgetItem *item : twWmtsLayers->findItems( QString(), Qt::MatchContains | Qt::MatchRecursive, 1 ) )
{
/*if ( !item->checkState( 1 ) )
continue;*/

QString t = item->data( 0, Qt::UserRole ).toString();
if ( t == "group" )
QString itemType = item->data( 0, Qt::UserRole ).toString();
if ( itemType == QLatin1String( "group" ) )
{
QString gName = item->data( 0, Qt::UserRole + 1 ).toString();
item->setCheckState( 1, wmtsGroupNameList.contains( gName ) ? Qt::Checked : Qt::Unchecked );
item->setCheckState( 2, wmtsPngGroupNameList.contains( gName ) ? Qt::Checked : Qt::Unchecked );
item->setCheckState( 3, wmtsJpegGroupNameList.contains( gName ) ? Qt::Checked : Qt::Unchecked );
}
else if ( t == "layer" )
else if ( itemType == QLatin1String( "layer" ) )
{
QString lId = item->data( 0, Qt::UserRole + 1 ).toString();
item->setCheckState( 1, wmtsLayerIdList.contains( lId ) ? Qt::Checked : Qt::Unchecked );
Expand Down Expand Up @@ -1274,19 +1271,19 @@ void QgsProjectProperties::apply()
QStringList wmtsLayerList;
QStringList wmtsPngLayerList;
QStringList wmtsJpegLayerList;
Q_FOREACH ( const QTreeWidgetItem *item, twWmtsLayers->findItems( "", Qt::MatchContains | Qt::MatchRecursive, 1 ) )
for ( const QTreeWidgetItem *item : twWmtsLayers->findItems( QString(), Qt::MatchContains | Qt::MatchRecursive, 1 ) )
{
if ( !item->checkState( 1 ) )
continue;

QString t = item->data( 0, Qt::UserRole ).toString();
if ( t == "project" )
QString itemType = item->data( 0, Qt::UserRole ).toString();
if ( itemType == QLatin1String( "project" ) )
{
wmtsProject = true;
wmtsPngProject = item->checkState( 2 );
wmtsJpegProject = item->checkState( 3 );
}
else if ( t == "group" )
else if ( itemType == QLatin1String( "group" ) )
{
QString gName = item->data( 0, Qt::UserRole + 1 ).toString();
wmtsGroupList << gName;
Expand All @@ -1295,7 +1292,7 @@ void QgsProjectProperties::apply()
if ( item->checkState( 3 ) )
wmtsJpegGroupList << gName;
}
else if ( t == "layer" )
else if ( itemType == QLatin1String( "layer" ) )
{
QString lId = item->data( 0, Qt::UserRole + 1 ).toString();
wmtsLayerList << lId;
Expand Down Expand Up @@ -2033,7 +2030,7 @@ void QgsProjectProperties::resetPythonMacros()

void QgsProjectProperties::populateWmtsTree( const QgsLayerTreeGroup *treeGroup, QgsTreeWidgetItem *treeItem )
{
Q_FOREACH ( QgsLayerTreeNode *treeNode, treeGroup->children() )
for ( QgsLayerTreeNode *treeNode : treeGroup->children() )
{
QgsTreeWidgetItem *childItem = nullptr;
if ( treeNode->nodeType() == QgsLayerTreeNode::NodeGroup )
Expand All @@ -2044,7 +2041,7 @@ void QgsProjectProperties::populateWmtsTree( const QgsLayerTreeGroup *treeGroup,
childItem = new QgsTreeWidgetItem( QStringList() << gName );
childItem->setFlags( childItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable );

childItem->setData( 0, Qt::UserRole, "group" );
childItem->setData( 0, Qt::UserRole, QStringLiteral( "group" ) );
childItem->setData( 0, Qt::UserRole + 1, gName );

treeItem->addChild( childItem );
Expand All @@ -2058,10 +2055,15 @@ void QgsProjectProperties::populateWmtsTree( const QgsLayerTreeGroup *treeGroup,
QgsLayerTreeLayer *treeLayer = static_cast<QgsLayerTreeLayer *>( treeNode );
QgsMapLayer *l = treeLayer->layer();

if ( !l )
{
continue;
}

childItem = new QgsTreeWidgetItem( QStringList() << l->name() );
childItem->setFlags( childItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable );

childItem->setData( 0, Qt::UserRole, "layer" );
childItem->setData( 0, Qt::UserRole, QStringLiteral( "layer" ) );
childItem->setData( 0, Qt::UserRole + 1, l->id() );

treeItem->addChild( childItem );
Expand Down
13 changes: 2 additions & 11 deletions src/server/qgsservercachefilter.cpp
Expand Up @@ -21,13 +21,11 @@

#include <QDomDocument>

//! Constructor
QgsServerCacheFilter::QgsServerCacheFilter( const QgsServerInterface *serverInterface ):
mServerInterface( serverInterface )
QgsServerCacheFilter::QgsServerCacheFilter( const QgsServerInterface *serverInterface )
: mServerInterface( serverInterface )
{
}

//! Returns cached document
QByteArray QgsServerCacheFilter::getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( project );
Expand All @@ -36,7 +34,6 @@ QByteArray QgsServerCacheFilter::getCachedDocument( const QgsProject *project, c
return QByteArray();
}

//! Updates or inserts the document in cache
bool QgsServerCacheFilter::setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( doc );
Expand All @@ -46,7 +43,6 @@ bool QgsServerCacheFilter::setCachedDocument( const QDomDocument *doc, const Qgs
return false;
}

//! Deletes the cached document
bool QgsServerCacheFilter::deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( project );
Expand All @@ -55,14 +51,12 @@ bool QgsServerCacheFilter::deleteCachedDocument( const QgsProject *project, cons
return false;
}

//! Deletes all cached documents for a QGIS project
bool QgsServerCacheFilter::deleteCachedDocuments( const QgsProject *project ) const
{
Q_UNUSED( project );
return false;
}

//! Returns cached image
QByteArray QgsServerCacheFilter::getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( project );
Expand All @@ -71,7 +65,6 @@ QByteArray QgsServerCacheFilter::getCachedImage( const QgsProject *project, cons
return QByteArray();
}

//! Updates or inserts the image in cache
bool QgsServerCacheFilter::setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( img );
Expand All @@ -81,7 +74,6 @@ bool QgsServerCacheFilter::setCachedImage( const QByteArray *img, const QgsProje
return false;
}

//! Deletes the cached image
bool QgsServerCacheFilter::deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
Q_UNUSED( project );
Expand All @@ -90,7 +82,6 @@ bool QgsServerCacheFilter::deleteCachedImage( const QgsProject *project, const Q
return false;
}

//! Deletes all cached images for a QGIS project
bool QgsServerCacheFilter::deleteCachedImages( const QgsProject *project ) const
{
Q_UNUSED( project );
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsservercachefilter.h
Expand Up @@ -133,4 +133,4 @@ class SERVER_EXPORT QgsServerCacheFilter
//! The registry definition
typedef QMultiMap<int, QgsServerCacheFilter *> QgsServerCacheFilterMap;

#endif // QGSSERVERSECURITY_H
#endif // QGSSERVERCACHEPLUGIN_H
9 changes: 0 additions & 9 deletions src/server/qgsservercachemanager.cpp
Expand Up @@ -18,7 +18,6 @@

#include "qgsservercachemanager.h"

//! Returns cached document (or 0 if document not in cache) like capabilities
QByteArray QgsServerCacheManager::getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
Expand All @@ -33,7 +32,6 @@ QByteArray QgsServerCacheManager::getCachedDocument( const QgsProject *project,
return QByteArray();
}

//! Updates or inserts the document in cache like capabilities
bool QgsServerCacheManager::setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
Expand All @@ -47,7 +45,6 @@ bool QgsServerCacheManager::setCachedDocument( const QDomDocument *doc, const Qg
return false;
}

//! Deletes the cached document
bool QgsServerCacheManager::deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
Expand All @@ -61,7 +58,6 @@ bool QgsServerCacheManager::deleteCachedDocument( const QgsProject *project, con
return false;
}

//! Deletes all cached documents for a QGIS Project
bool QgsServerCacheManager::deleteCachedDocuments( const QgsProject *project ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
Expand All @@ -75,7 +71,6 @@ bool QgsServerCacheManager::deleteCachedDocuments( const QgsProject *project ) c
return false;
}

//! Returns cached image (or 0 if image not in cache) like tiles
QByteArray QgsServerCacheManager::getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
Expand All @@ -90,7 +85,6 @@ QByteArray QgsServerCacheManager::getCachedImage( const QgsProject *project, con
return QByteArray();
}

//! Updates or inserts the image in cache like tiles
bool QgsServerCacheManager::setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
Expand All @@ -104,7 +98,6 @@ bool QgsServerCacheManager::setCachedImage( const QByteArray *img, const QgsProj
return false;
}

//! Deletes the cached image
bool QgsServerCacheManager::deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
Expand All @@ -118,7 +111,6 @@ bool QgsServerCacheManager::deleteCachedImage( const QgsProject *project, const
return false;
}

//! Deletes all cached images for a QGIS Project
bool QgsServerCacheManager::deleteCachedImages( const QgsProject *project ) const
{
QgsServerCacheFilterMap::const_iterator scIterator;
Expand All @@ -132,7 +124,6 @@ bool QgsServerCacheManager::deleteCachedImages( const QgsProject *project ) cons
return false;
}

//! Register a new access control filter
void QgsServerCacheManager::registerServerCache( QgsServerCacheFilter *serverCache, int priority )
{
mPluginsServerCaches->insert( priority, serverCache );
Expand Down
34 changes: 25 additions & 9 deletions src/server/qgsservercachemanager.h
Expand Up @@ -49,21 +49,39 @@ class SERVER_EXPORT QgsServerCacheManager
//! Constructor
QgsServerCacheManager()
{
mPluginsServerCaches = new QgsServerCacheFilterMap();
mResolved = false;
mPluginsServerCaches.reset( new QgsServerCacheFilterMap() );
}

//! Constructor
//! Copy constructor
QgsServerCacheManager( const QgsServerCacheManager &copy )
{
mPluginsServerCaches = new QgsServerCacheFilterMap( *copy.mPluginsServerCaches );
mResolved = copy.mResolved;
if ( copy.mPluginsServerCaches )
{
mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
}
else
{
mPluginsServerCaches.reset( nullptr );
}
}
//! Assignment operator
QgsServerCacheManager &operator=( const QgsServerCacheManager &copy )
{
if ( copy.mPluginsServerCaches )
{
mPluginsServerCaches.reset( new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ) );
}
else
{
mPluginsServerCaches.reset( nullptr );
}
return *this;
}


~QgsServerCacheManager()
{
delete mPluginsServerCaches;
mPluginsServerCaches.reset();
}

/**
Expand Down Expand Up @@ -145,9 +163,7 @@ class SERVER_EXPORT QgsServerCacheManager

private:
//! The ServerCache plugins registry
QgsServerCacheFilterMap *mPluginsServerCaches = nullptr;

bool mResolved;
std::unique_ptr<QgsServerCacheFilterMap> mPluginsServerCaches = nullptr;
};

#endif
6 changes: 5 additions & 1 deletion src/server/qgsserverinterface.h
Expand Up @@ -126,10 +126,14 @@ class SERVER_EXPORT QgsServerInterface
* Register a server cache filter
* \param serverCache the server cache to register
* \param priority the priority used to order them
* \since QGIS 3.4
*/
virtual void registerServerCache( QgsServerCacheFilter *serverCache SIP_TRANSFER, int priority = 0 ) = 0;

//! Gets the registered server cache filters
/**
* Gets the registered server cache filters
* \since QGIS 3.4
*/
virtual QgsServerCacheManager *cacheManager() const = 0;

//! Returns an enrironment variable, used to pass environment variables to Python
Expand Down
6 changes: 2 additions & 4 deletions src/server/qgsserverinterfaceimpl.cpp
Expand Up @@ -29,10 +29,7 @@ QgsServerInterfaceImpl::QgsServerInterfaceImpl( QgsCapabilitiesCache *capCache,
mRequestHandler = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
mAccessControls = new QgsAccessControl();
mCacheManager = new QgsServerCacheManager();
#else
mAccessControls = nullptr;
mCacheManager = nullptr;
mCacheManager.reset( new QgsServerCacheManager() );
#endif
}

Expand All @@ -46,6 +43,7 @@ QgsServerInterfaceImpl::~QgsServerInterfaceImpl()
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
delete mAccessControls;
mCacheManager.reset();
#endif
}

Expand Down

0 comments on commit 7633d2a

Please sign in to comment.