Skip to content

Commit d9095e0

Browse files
committed
[Server] Various code cleaning for server cache manager and WMTS service
1 parent 1bae625 commit d9095e0

5 files changed

+86
-28
lines changed

src/server/services/wmts/qgswmtsgetcapabilities.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ namespace QgsWmts
147147
if ( !keywords.isEmpty() )
148148
{
149149
QDomElement keywordsElem = doc.createElement( QStringLiteral( "ows:Keywords" ) );
150-
for ( int i = 0; i < keywords.size(); ++i )
150+
for ( const QString k : keywords )
151151
{
152152
QDomElement keywordElem = doc.createElement( QStringLiteral( "ows:Keyword" ) );
153-
QDomText keywordText = doc.createTextNode( keywords.at( i ) );
153+
QDomText keywordText = doc.createTextNode( k );
154154
keywordElem.appendChild( keywordText );
155155
keywordsElem.appendChild( keywordElem );
156156
}
@@ -389,7 +389,7 @@ namespace QgsWmts
389389
QStringList wmtsPngGroupNameList = project->readListEntry( QStringLiteral( "WMTSPngLayers" ), QStringLiteral( "Group" ) );
390390
QStringList wmtsJpegGroupNameList = project->readListEntry( QStringLiteral( "WMTSJpegLayers" ), QStringLiteral( "Group" ) );
391391

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

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

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

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

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

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

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

705705
//wmts:TileMatrix
706706
int tmIdx = 0;
707-
for ( tileMatrixDef tm : tms.tileMatrixList )
707+
for ( const tileMatrixDef tm : tms.tileMatrixList )
708708
{
709709
QDomElement tmElement = doc.createElement( QStringLiteral( "TileMatrix" )/*wmts:TileMatrix*/ );
710710

src/server/services/wmts/qgswmtsgetfeatureinfo.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ namespace QgsWmts
3434
QUrlQuery query = translateWmtsParamToWmsQueryItem( QStringLiteral( "GetFeatureInfo" ), params, project, serverIface );
3535

3636
// GetFeatureInfo query items
37-
query.addQueryItem( QStringLiteral( "query_layers" ), params.layer() );
38-
query.addQueryItem( QgsWmtsParameter::name( QgsWmtsParameter::I ), params.i() );
39-
query.addQueryItem( QgsWmtsParameter::name( QgsWmtsParameter::J ), params.j() );
40-
query.addQueryItem( QStringLiteral( "info_format" ), params.infoFormatAsString() );
37+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::QUERY_LAYERS ), params.layer() );
38+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::I ), params.i() );
39+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::J ), params.j() );
40+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::INFO_FORMAT ), params.infoFormatAsString() );
4141

4242
QgsServerParameters wmsParams( query );
4343
QgsServerRequest wmsRequest( "?" + query.query( QUrl::FullyDecoded ) );

src/server/services/wmts/qgswmtsparameters.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121

2222
namespace QgsWmts
2323
{
24+
//
25+
// QgsWmsParameter
26+
//
27+
QString QgsWmsParameter::name( const QgsWmsParameter::Name name )
28+
{
29+
const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
30+
return metaEnum.valueToKey( name );
31+
}
32+
33+
QgsWmsParameter::Name QgsWmsParameter::name( const QString &name )
34+
{
35+
const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
36+
return ( QgsWmsParameter::Name ) metaEnum.keyToValue( name.toUpper().toStdString().c_str() );
37+
}
38+
2439
//
2540
// QgsWmtsParameter
2641
//

src/server/services/wmts/qgswmtsparameters.h

+43
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,49 @@
3030
namespace QgsWmts
3131
{
3232

33+
/**
34+
* \ingroup server
35+
* \class QgsWmts::QgsWmsParameter
36+
* \brief WMS parameter used by WMTS service.
37+
* \since QGIS 3.4
38+
*/
39+
class QgsWmsParameter : public QgsServerParameterDefinition
40+
{
41+
Q_GADGET
42+
43+
public:
44+
//! Available parameters for translating WMTS requests to WMS requests
45+
enum Name
46+
{
47+
UNKNOWN,
48+
LAYERS,
49+
STYLES,
50+
CRS,
51+
BBOX,
52+
WIDTH,
53+
HEIGHT,
54+
FORMAT,
55+
TRANSPARENT,
56+
DPI,
57+
QUERY_LAYERS,
58+
I,
59+
J,
60+
INFO_FORMAT
61+
};
62+
Q_ENUM( Name )
63+
64+
/**
65+
* Converts a parameter's name into its string representation.
66+
*/
67+
static QString name( const QgsWmsParameter::Name );
68+
69+
/**
70+
* Converts a string into a parameter's name (UNKNOWN in case of an
71+
* invalid string).
72+
*/
73+
static QgsWmsParameter::Name name( const QString &name );
74+
};
75+
3376
/**
3477
* \ingroup server
3578
* \class QgsWmts::QgsWmtsParameter

src/server/services/wmts/qgswmtsutils.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -378,23 +378,23 @@ namespace QgsWmts
378378
QUrlQuery query;
379379
if ( !params.value( QStringLiteral( "MAP" ) ).isEmpty() )
380380
{
381-
query.addQueryItem( QStringLiteral( "map" ), params.value( QStringLiteral( "MAP" ) ) );
381+
query.addQueryItem( QgsServerParameter::name( QgsServerParameter::MAP ), params.value( QStringLiteral( "MAP" ) ) );
382382
}
383-
query.addQueryItem( QStringLiteral( "service" ), QStringLiteral( "WMS" ) );
384-
query.addQueryItem( QStringLiteral( "version" ), QStringLiteral( "1.3.0" ) );
385-
query.addQueryItem( QStringLiteral( "request" ), request );
386-
query.addQueryItem( QStringLiteral( "layers" ), layer );
387-
query.addQueryItem( QStringLiteral( "styles" ), QString() );
388-
query.addQueryItem( QStringLiteral( "crs" ), tms.ref );
389-
query.addQueryItem( QStringLiteral( "bbox" ), bbox );
390-
query.addQueryItem( QStringLiteral( "width" ), QStringLiteral( "256" ) );
391-
query.addQueryItem( QStringLiteral( "height" ), QStringLiteral( "256" ) );
392-
query.addQueryItem( QStringLiteral( "format" ), format );
383+
query.addQueryItem( QgsServerParameter::name( QgsServerParameter::SERVICE ), QStringLiteral( "WMS" ) );
384+
query.addQueryItem( QgsServerParameter::name( QgsServerParameter::VERSION_SERVICE ), QStringLiteral( "1.3.0" ) );
385+
query.addQueryItem( QgsServerParameter::name( QgsServerParameter::REQUEST ), request );
386+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::LAYERS ), layer );
387+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::STYLES ), QString() );
388+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::CRS ), tms.ref );
389+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::BBOX ), bbox );
390+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::WIDTH ), QStringLiteral( "256" ) );
391+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::HEIGHT ), QStringLiteral( "256" ) );
392+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::FORMAT ), format );
393393
if ( params.format() == QgsWmtsParameters::Format::PNG )
394394
{
395-
query.addQueryItem( QStringLiteral( "transparent" ), QStringLiteral( "true" ) );
395+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::TRANSPARENT ), QStringLiteral( "true" ) );
396396
}
397-
query.addQueryItem( QStringLiteral( "dpi" ), QStringLiteral( "96" ) );
397+
query.addQueryItem( QgsWmsParameter::name( QgsWmsParameter::DPI ), QStringLiteral( "96" ) );
398398

399399
return query;
400400
}

0 commit comments

Comments
 (0)