Skip to content
Permalink
Browse files

List published WFS layers in GetProjectSettings result

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Oct 1, 2012
1 parent 0fb66fc commit 2dd6e542a5f08468f2fc28c39129884ec91c94e5
@@ -59,6 +59,9 @@ class QgsConfigParser
/**Returns the xml fragment of a style*/
virtual QDomDocument getStyle( const QString& styleName, const QString& layerName ) const = 0;

/**Returns the names of the published wfs layers (not the ids as in wfsLayers() )*/
virtual QStringList wfsLayerNames() const { return QStringList(); }

/**Possibility to add a parameter map to the config parser. This is used by the SLD parser. Default implementation does nothing*/
virtual void setParameterMap( const QMap<QString, QString>& parameterMap )
{ Q_UNUSED( parameterMap ); }
@@ -101,25 +101,7 @@ void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement,
}

QMap<QString, QgsMapLayer *> layerMap;

foreach ( const QDomElement &elem, mProjectLayerElements )
{
QgsMapLayer *layer = createLayerFromElement( elem );
if ( layer )
{
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
layerMap.insert( layer->id(), layer );
}
#if QGSMSDEBUG
else
{
QString buf;
QTextStream s( &buf );
elem.save( s, 0 );
QgsDebugMsg( QString( "layer %1 not found" ).arg( buf ) );
}
#endif
}
projectLayerMap( layerMap );

//According to the WMS spec, there can be only one toplevel layer.
//So we create an artificial one here to be in accordance with the schema
@@ -1554,6 +1536,32 @@ QString QgsProjectParser::serviceUrl() const
return url;
}

QStringList QgsProjectParser::wfsLayerNames() const
{
QStringList layerNameList;

QMap<QString, QgsMapLayer*> layerMap;
projectLayerMap( layerMap );

QgsMapLayer* currentLayer = 0;
QStringList wfsIdList = wfsLayers();
QStringList::const_iterator wfsIdIt = wfsIdList.constBegin();
for ( ; wfsIdIt != wfsIdList.constEnd(); ++wfsIdIt )
{
QMap<QString, QgsMapLayer*>::const_iterator layerMapIt = layerMap.find( *wfsIdIt );
if ( layerMapIt != layerMap.constEnd() )
{
currentLayer = layerMapIt.value();
if ( currentLayer )
{
layerNameList.append( currentLayer->name() );
}
}
}

return layerNameList;
}

QString QgsProjectParser::convertToAbsolutePath( const QString& file ) const
{
if ( !file.startsWith( "./" ) && !file.startsWith( "../" ) )
@@ -1803,3 +1811,17 @@ void QgsProjectParser::addDrawingOrder( QDomElement& parentElem, QDomDocument& d
layerDrawingOrderElem.appendChild( drawingOrderText );
parentElem.appendChild( layerDrawingOrderElem );
}

void QgsProjectParser::projectLayerMap( QMap<QString, QgsMapLayer*>& layerMap ) const
{
layerMap.clear();
foreach ( const QDomElement &elem, mProjectLayerElements )
{
QgsMapLayer *layer = createLayerFromElement( elem );
if ( layer )
{
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
layerMap.insert( layer->id(), layer );
}
}
}
@@ -110,6 +110,9 @@ class QgsProjectParser: public QgsConfigParser

QString serviceUrl() const;

/**Returns the names of the published wfs layers (not the ids as in wfsLayers() )*/
QStringList wfsLayerNames() const;

private:

//forbidden
@@ -179,6 +182,8 @@ class QgsProjectParser: public QgsConfigParser
void setMaxWidthHeight();
/**Reads layer drawing order from the legend section of the project file and appends it to the parent elemen (usually the <Capability> element)*/
void addDrawingOrder( QDomElement& parentElem, QDomDocument& doc ) const;
/**Returns project layers by id*/
void projectLayerMap( QMap<QString, QgsMapLayer*>& layerMap ) const;

static QString editTypeString( QgsVectorLayer::EditType type );
};
@@ -205,10 +205,25 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
appendFormats( doc, elem, QStringList() << ( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" ) );
capabilityElement.appendChild( elem );

//Insert <ComposerTemplate> elements derived from wms:_ExtendedCapabilities
if ( mConfigParser && fullProjectInformation )
{
//Insert <ComposerTemplate> elements derived from wms:_ExtendedCapabilities
mConfigParser->printCapabilities( capabilityElement, doc );

//WFS layers
QStringList wfsLayers = mConfigParser->wfsLayerNames();
if ( wfsLayers.size() > 0 )
{
QDomElement wfsLayersElem = doc.createElement( "WFSLayers" );
QStringList::const_iterator wfsIt = wfsLayers.constBegin();
for ( ; wfsIt != wfsLayers.constEnd(); ++wfsIt )
{
QDomElement wfsLayerElem = doc.createElement( "WFSLayer" );
wfsLayerElem.setAttribute( "name", *wfsIt );
wfsLayersElem.appendChild( wfsLayerElem );
}
capabilityElement.appendChild( wfsLayersElem );
}
}

//add the xml content for the individual layers/styles

0 comments on commit 2dd6e54

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