Skip to content

Commit

Permalink
Move creation of datasource uri for external wms layers to QgsWMSPara…
Browse files Browse the repository at this point in the history
…meters
  • Loading branch information
mhugent committed Oct 20, 2017
1 parent 288d2ee commit c993888
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
28 changes: 28 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "qgswmsparameters.h"
#include "qgsdatasourceuri.h"
#include "qgsmessagelog.h"
#include <iostream>

Expand Down Expand Up @@ -512,6 +513,16 @@ namespace QgsWms
raiseError( name );
}
}
else //maybe an external wms parameter?
{
int separator = key.indexOf( ":" );
if ( separator >= 1 )
{
QString id = key.left( separator );
QString param = key.right( key.length() - separator - 1 );
mExternalWMSParameters[id].insert( param, parameters[key] );
}
}
}
}
}
Expand Down Expand Up @@ -1874,6 +1885,23 @@ namespace QgsWms
return param;
}

QString QgsWmsParameters::externalWMSUri( const QString &id ) const
{
if ( !mExternalWMSParameters.contains( id ) )
{
return QString();
}

QgsDataSourceUri wmsUri;
const QMap<QString, QString> &paramMap = mExternalWMSParameters[ id ];
QMap<QString, QString>::const_iterator paramIt = paramMap.constBegin();
for ( ; paramIt != paramMap.constEnd(); ++paramIt )
{
wmsUri.setParam( paramIt.key().toLower(), paramIt.value() );
}
return wmsUri.encodedUri();
}

QString QgsWmsParameters::name( ParameterName name ) const
{
const QMetaEnum metaEnum( QMetaEnum::fromType<ParameterName>() );
Expand Down
8 changes: 8 additions & 0 deletions src/server/services/wms/qgswmsparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,13 @@ namespace QgsWms
*/
QgsWmsParametersComposerMap composerMapParameters( int mapId ) const;

/**
* @brief externalWMSUri
* @param id the id of the external wms
* @return uri string or an empty string if the external wms id does not exist
*/
QString externalWMSUri( const QString &id ) const;

private:
QString name( ParameterName name ) const;
void raiseError( ParameterName name ) const;
Expand Down Expand Up @@ -955,6 +962,7 @@ namespace QgsWms
QgsServerRequest::Parameters mRequestParameters;
QMap<ParameterName, Parameter> mParameters;
QMap<int, QMap<ParameterName, Parameter>> mComposerParameters;
QMap<QString, QMap<QString, QString> > mExternalWMSParameters;
QList<QgsProjectVersion> mVersions;
};
}
Expand Down
20 changes: 2 additions & 18 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2653,24 +2653,8 @@ namespace QgsWms

QgsMapLayer *QgsRenderer::createExternalWMSLayer( const QString &externalLayerId ) const
{
QgsMapLayer *wmsLayer = 0;
QgsDataSourceUri wmsUri;

QgsServerRequest::Parameters::const_iterator it = mParameters.lowerBound( externalLayerId.toUpper() + ":" );
while ( it != mParameters.constEnd() )
{
if ( !it.key().startsWith( externalLayerId.toUpper() + ":" ) )
{
break;
}

QString paramKey = it.key();
paramKey.remove( 0, externalLayerId.size() + 1 );
wmsUri.setParam( paramKey.toLower(), it.value() );
++it;
}

wmsLayer = new QgsRasterLayer( wmsUri.encodedUri(), externalLayerId, QStringLiteral( "wms" ) );
QString wmsUri = mWmsParameters.externalWMSUri( externalLayerId.toUpper() );
QgsMapLayer *wmsLayer = new QgsRasterLayer( wmsUri, externalLayerId, QStringLiteral( "wms" ) );
if ( !wmsLayer->isValid() )
{
delete wmsLayer;
Expand Down

0 comments on commit c993888

Please sign in to comment.