Skip to content

Commit 2dd6e54

Browse files
author
Marco Hugentobler
committedOct 1, 2012
List published WFS layers in GetProjectSettings result
1 parent 0fb66fc commit 2dd6e54

File tree

4 files changed

+65
-20
lines changed

4 files changed

+65
-20
lines changed
 

‎src/mapserver/qgsconfigparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class QgsConfigParser
5959
/**Returns the xml fragment of a style*/
6060
virtual QDomDocument getStyle( const QString& styleName, const QString& layerName ) const = 0;
6161

62+
/**Returns the names of the published wfs layers (not the ids as in wfsLayers() )*/
63+
virtual QStringList wfsLayerNames() const { return QStringList(); }
64+
6265
/**Possibility to add a parameter map to the config parser. This is used by the SLD parser. Default implementation does nothing*/
6366
virtual void setParameterMap( const QMap<QString, QString>& parameterMap )
6467
{ Q_UNUSED( parameterMap ); }

‎src/mapserver/qgsprojectparser.cpp

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,7 @@ void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement,
101101
}
102102

103103
QMap<QString, QgsMapLayer *> layerMap;
104-
105-
foreach ( const QDomElement &elem, mProjectLayerElements )
106-
{
107-
QgsMapLayer *layer = createLayerFromElement( elem );
108-
if ( layer )
109-
{
110-
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
111-
layerMap.insert( layer->id(), layer );
112-
}
113-
#if QGSMSDEBUG
114-
else
115-
{
116-
QString buf;
117-
QTextStream s( &buf );
118-
elem.save( s, 0 );
119-
QgsDebugMsg( QString( "layer %1 not found" ).arg( buf ) );
120-
}
121-
#endif
122-
}
104+
projectLayerMap( layerMap );
123105

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

1539+
QStringList QgsProjectParser::wfsLayerNames() const
1540+
{
1541+
QStringList layerNameList;
1542+
1543+
QMap<QString, QgsMapLayer*> layerMap;
1544+
projectLayerMap( layerMap );
1545+
1546+
QgsMapLayer* currentLayer = 0;
1547+
QStringList wfsIdList = wfsLayers();
1548+
QStringList::const_iterator wfsIdIt = wfsIdList.constBegin();
1549+
for ( ; wfsIdIt != wfsIdList.constEnd(); ++wfsIdIt )
1550+
{
1551+
QMap<QString, QgsMapLayer*>::const_iterator layerMapIt = layerMap.find( *wfsIdIt );
1552+
if ( layerMapIt != layerMap.constEnd() )
1553+
{
1554+
currentLayer = layerMapIt.value();
1555+
if ( currentLayer )
1556+
{
1557+
layerNameList.append( currentLayer->name() );
1558+
}
1559+
}
1560+
}
1561+
1562+
return layerNameList;
1563+
}
1564+
15571565
QString QgsProjectParser::convertToAbsolutePath( const QString& file ) const
15581566
{
15591567
if ( !file.startsWith( "./" ) && !file.startsWith( "../" ) )
@@ -1803,3 +1811,17 @@ void QgsProjectParser::addDrawingOrder( QDomElement& parentElem, QDomDocument& d
18031811
layerDrawingOrderElem.appendChild( drawingOrderText );
18041812
parentElem.appendChild( layerDrawingOrderElem );
18051813
}
1814+
1815+
void QgsProjectParser::projectLayerMap( QMap<QString, QgsMapLayer*>& layerMap ) const
1816+
{
1817+
layerMap.clear();
1818+
foreach ( const QDomElement &elem, mProjectLayerElements )
1819+
{
1820+
QgsMapLayer *layer = createLayerFromElement( elem );
1821+
if ( layer )
1822+
{
1823+
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
1824+
layerMap.insert( layer->id(), layer );
1825+
}
1826+
}
1827+
}

‎src/mapserver/qgsprojectparser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ class QgsProjectParser: public QgsConfigParser
110110

111111
QString serviceUrl() const;
112112

113+
/**Returns the names of the published wfs layers (not the ids as in wfsLayers() )*/
114+
QStringList wfsLayerNames() const;
115+
113116
private:
114117

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

183188
static QString editTypeString( QgsVectorLayer::EditType type );
184189
};

‎src/mapserver/qgswmsserver.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,25 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
205205
appendFormats( doc, elem, QStringList() << ( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" ) );
206206
capabilityElement.appendChild( elem );
207207

208-
//Insert <ComposerTemplate> elements derived from wms:_ExtendedCapabilities
209208
if ( mConfigParser && fullProjectInformation )
210209
{
210+
//Insert <ComposerTemplate> elements derived from wms:_ExtendedCapabilities
211211
mConfigParser->printCapabilities( capabilityElement, doc );
212+
213+
//WFS layers
214+
QStringList wfsLayers = mConfigParser->wfsLayerNames();
215+
if ( wfsLayers.size() > 0 )
216+
{
217+
QDomElement wfsLayersElem = doc.createElement( "WFSLayers" );
218+
QStringList::const_iterator wfsIt = wfsLayers.constBegin();
219+
for ( ; wfsIt != wfsLayers.constEnd(); ++wfsIt )
220+
{
221+
QDomElement wfsLayerElem = doc.createElement( "WFSLayer" );
222+
wfsLayerElem.setAttribute( "name", *wfsIt );
223+
wfsLayersElem.appendChild( wfsLayerElem );
224+
}
225+
capabilityElement.appendChild( wfsLayersElem );
226+
}
212227
}
213228

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

0 commit comments

Comments
 (0)
Please sign in to comment.