Skip to content

Commit

Permalink
List published WFS layers in GetProjectSettings result
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Oct 1, 2012
1 parent 0fb66fc commit 2dd6e54
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/mapserver/qgsconfigparser.h
Expand Up @@ -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 ); }
Expand Down
60 changes: 41 additions & 19 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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( "../" ) )
Expand Down Expand Up @@ -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 );
}
}
}
5 changes: 5 additions & 0 deletions src/mapserver/qgsprojectparser.h
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
};
Expand Down
17 changes: 16 additions & 1 deletion src/mapserver/qgswmsserver.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 2dd6e54

Please sign in to comment.