Skip to content
Permalink
Browse files

[Server] Various code cleaning for server cache manager and WMTS service

  • Loading branch information
rldhont committed Aug 23, 2018
1 parent 1bae625 commit d9095e0b1eea7f6780ea689c0ff24d4aef4f6168
@@ -147,10 +147,10 @@ namespace QgsWmts
if ( !keywords.isEmpty() )
{
QDomElement keywordsElem = doc.createElement( QStringLiteral( "ows:Keywords" ) );
for ( int i = 0; i < keywords.size(); ++i )
for ( const QString k : keywords )
{
QDomElement keywordElem = doc.createElement( QStringLiteral( "ows:Keyword" ) );
QDomText keywordText = doc.createTextNode( keywords.at( i ) );
QDomText keywordText = doc.createTextNode( k );
keywordElem.appendChild( keywordText );
keywordsElem.appendChild( keywordElem );
}
@@ -389,7 +389,7 @@ namespace QgsWmts
QStringList wmtsPngGroupNameList = project->readListEntry( QStringLiteral( "WMTSPngLayers" ), QStringLiteral( "Group" ) );
QStringList wmtsJpegGroupNameList = project->readListEntry( QStringLiteral( "WMTSJpegLayers" ), QStringLiteral( "Group" ) );

for ( QString gName : wmtsGroupNameList )
for ( const QString gName : wmtsGroupNameList )
{
QgsLayerTreeGroup *treeGroup = treeRoot->findGroup( gName );
if ( !treeGroup )
@@ -450,7 +450,7 @@ namespace QgsWmts
QStringList wmtsPngLayerIdList = project->readListEntry( QStringLiteral( "WMTSPngLayers" ), QStringLiteral( "Layer" ) );
QStringList wmtsJpegLayerIdList = project->readListEntry( QStringLiteral( "WMTSJpegLayers" ), QStringLiteral( "Layer" ) );

for ( QString lId : wmtsLayerIdList )
for ( const QString lId : wmtsLayerIdList )
{
QgsMapLayer *l = project->mapLayer( lId );
if ( !l )
@@ -511,7 +511,7 @@ namespace QgsWmts
elem.appendChild( formatElem );
};

for ( layerDef wmtsLayer : wmtsLayers )
for ( const layerDef wmtsLayer : wmtsLayers )
{
if ( wmtsLayer.id.isEmpty() )
continue;
@@ -554,7 +554,7 @@ namespace QgsWmts
layerElem.appendChild( wgs84BBoxElement );

// Other bounding boxes
for ( tileMatrixSetDef tms : tmsList )
for ( const tileMatrixSetDef tms : tmsList )
{
if ( tms.ref == QLatin1String( "EPSG:4326" ) )
continue;
@@ -597,7 +597,7 @@ namespace QgsWmts
layerStyleElem.appendChild( layerStyleTitleElem );
layerElem.appendChild( layerStyleElem );

for ( QString format : wmtsLayer.formats )
for ( const QString format : wmtsLayer.formats )
{
QDomElement layerFormatElem = doc.createElement( QStringLiteral( "Format" ) );
QDomText layerFormatText = doc.createTextNode( format );
@@ -614,7 +614,7 @@ namespace QgsWmts
appendInfoFormat( layerElem, QStringLiteral( "application/vnd.ogc.gml/3.1.1" ) );
}

for ( tileMatrixSetDef tms : tmsList )
for ( const tileMatrixSetDef tms : tmsList )
{
if ( tms.ref != QLatin1String( "EPSG:4326" ) )
{
@@ -642,7 +642,7 @@ namespace QgsWmts
//wmts:TileMatrixSetLimits
QDomElement tmsLimitsElement = doc.createElement( QStringLiteral( "TileMatrixSetLimits" )/*wmts:TileMatrixSetLimits*/ );
int tmIdx = 0;
for ( tileMatrixDef tm : tms.tileMatrixList )
for ( const tileMatrixDef tm : tms.tileMatrixList )
{
QDomElement tmLimitsElement = doc.createElement( QStringLiteral( "TileMatrixLimits" )/*wmts:TileMatrixLimits*/ );

@@ -687,7 +687,7 @@ namespace QgsWmts
void appendTileMatrixSetElements( QDomDocument &doc, QDomElement &contentsElement,
QList< tileMatrixSetDef > tmsList )
{
for ( tileMatrixSetDef tms : tmsList )
for ( const tileMatrixSetDef tms : tmsList )
{
//wmts:TileMatrixSet
QDomElement tmsElement = doc.createElement( QStringLiteral( "TileMatrixSet" )/*wmts:TileMatrixSet*/ );
@@ -704,7 +704,7 @@ namespace QgsWmts

//wmts:TileMatrix
int tmIdx = 0;
for ( tileMatrixDef tm : tms.tileMatrixList )
for ( const tileMatrixDef tm : tms.tileMatrixList )
{
QDomElement tmElement = doc.createElement( QStringLiteral( "TileMatrix" )/*wmts:TileMatrix*/ );

@@ -34,10 +34,10 @@ namespace QgsWmts
QUrlQuery query = translateWmtsParamToWmsQueryItem( QStringLiteral( "GetFeatureInfo" ), params, project, serverIface );

// GetFeatureInfo query items
query.addQueryItem( QStringLiteral( "query_layers" ), params.layer() );
query.addQueryItem( QgsWmtsParameter::name( QgsWmtsParameter::I ), params.i() );
query.addQueryItem( QgsWmtsParameter::name( QgsWmtsParameter::J ), params.j() );
query.addQueryItem( QStringLiteral( "info_format" ), params.infoFormatAsString() );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::QUERY_LAYERS ), params.layer() );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::I ), params.i() );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::J ), params.j() );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::INFO_FORMAT ), params.infoFormatAsString() );

QgsServerParameters wmsParams( query );
QgsServerRequest wmsRequest( "?" + query.query( QUrl::FullyDecoded ) );
@@ -21,6 +21,21 @@

namespace QgsWmts
{
//
// QgsWmsParameter
//
QString QgsWmsParameter::name( const QgsWmsParameter::Name name )
{
const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
return metaEnum.valueToKey( name );
}

QgsWmsParameter::Name QgsWmsParameter::name( const QString &name )
{
const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
return ( QgsWmsParameter::Name ) metaEnum.keyToValue( name.toUpper().toStdString().c_str() );
}

//
// QgsWmtsParameter
//
@@ -30,6 +30,49 @@
namespace QgsWmts
{

/**
* \ingroup server
* \class QgsWmts::QgsWmsParameter
* \brief WMS parameter used by WMTS service.
* \since QGIS 3.4
*/
class QgsWmsParameter : public QgsServerParameterDefinition
{
Q_GADGET

public:
//! Available parameters for translating WMTS requests to WMS requests
enum Name
{
UNKNOWN,
LAYERS,
STYLES,
CRS,
BBOX,
WIDTH,
HEIGHT,
FORMAT,
TRANSPARENT,
DPI,
QUERY_LAYERS,
I,
J,
INFO_FORMAT
};
Q_ENUM( Name )

/**
* Converts a parameter's name into its string representation.
*/
static QString name( const QgsWmsParameter::Name );

/**
* Converts a string into a parameter's name (UNKNOWN in case of an
* invalid string).
*/
static QgsWmsParameter::Name name( const QString &name );
};

/**
* \ingroup server
* \class QgsWmts::QgsWmtsParameter
@@ -378,23 +378,23 @@ namespace QgsWmts
QUrlQuery query;
if ( !params.value( QStringLiteral( "MAP" ) ).isEmpty() )
{
query.addQueryItem( QStringLiteral( "map" ), params.value( QStringLiteral( "MAP" ) ) );
query.addQueryItem( QgsServerParameter::name( QgsServerParameter::MAP ), params.value( QStringLiteral( "MAP" ) ) );
}
query.addQueryItem( QStringLiteral( "service" ), QStringLiteral( "WMS" ) );
query.addQueryItem( QStringLiteral( "version" ), QStringLiteral( "1.3.0" ) );
query.addQueryItem( QStringLiteral( "request" ), request );
query.addQueryItem( QStringLiteral( "layers" ), layer );
query.addQueryItem( QStringLiteral( "styles" ), QString() );
query.addQueryItem( QStringLiteral( "crs" ), tms.ref );
query.addQueryItem( QStringLiteral( "bbox" ), bbox );
query.addQueryItem( QStringLiteral( "width" ), QStringLiteral( "256" ) );
query.addQueryItem( QStringLiteral( "height" ), QStringLiteral( "256" ) );
query.addQueryItem( QStringLiteral( "format" ), format );
query.addQueryItem( QgsServerParameter::name( QgsServerParameter::SERVICE ), QStringLiteral( "WMS" ) );
query.addQueryItem( QgsServerParameter::name( QgsServerParameter::VERSION_SERVICE ), QStringLiteral( "1.3.0" ) );
query.addQueryItem( QgsServerParameter::name( QgsServerParameter::REQUEST ), request );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::LAYERS ), layer );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::STYLES ), QString() );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::CRS ), tms.ref );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::BBOX ), bbox );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::WIDTH ), QStringLiteral( "256" ) );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::HEIGHT ), QStringLiteral( "256" ) );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::FORMAT ), format );
if ( params.format() == QgsWmtsParameters::Format::PNG )
{
query.addQueryItem( QStringLiteral( "transparent" ), QStringLiteral( "true" ) );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::TRANSPARENT ), QStringLiteral( "true" ) );
}
query.addQueryItem( QStringLiteral( "dpi" ), QStringLiteral( "96" ) );
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::DPI ), QStringLiteral( "96" ) );

return query;
}

0 comments on commit d9095e0

Please sign in to comment.
You can’t perform that action at this time.