Skip to content

Commit 14de543

Browse files
committed
Simplify server config parser by using layer information (alias, excluded attributes) directly
1 parent 4358e8e commit 14de543

File tree

6 files changed

+16
-101
lines changed

6 files changed

+16
-101
lines changed

src/core/qgsvectorlayer.h

+2
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
572572
@note added in version 1.2*/
573573
QString attributeDisplayName( int attributeIndex ) const;
574574

575+
const QMap< QString, QString >& attributeAliases() const { return mAttributeAliasMap; }
576+
575577
const QSet<QString>& excludeAttributesWMS() const { return mExcludeAttributesWMS; }
576578
void setExcludeAttributesWMS( const QSet<QString>& att ) { mExcludeAttributesWMS = att; }
577579

src/mapserver/qgsconfigparser.h

-7
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ class QgsConfigParser
108108
/**True if the feature info response should contain the wkt geometry for vector features*/
109109
virtual bool featureInfoWithWktGeometry() const { return false; }
110110

111-
/**Returns information about vector layer aliases. First key is the layer id, (second) key is the field id, value the alias.
112-
Default implementation returns an empty map*/
113-
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const { return QMap< QString, QMap<int, QString> > (); }
114-
115-
/**Returns attributes excluded from WFS publication. Key is layer id, value is a set containing the names of the hidden attributes*/
116-
virtual QMap< QString, QSet<QString> > wfsExcludedAttributes() const { return QMap< QString, QSet<QString> >(); }
117-
118111
/**Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/
119112
QgsComposition* createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap ) const;
120113

src/mapserver/qgsprojectparser.cpp

+5-67
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
243243
}
244244

245245
QStringList wfsLayersId = wfsLayers();
246-
QMap< QString, QMap< int, QString > > aliasInfo = layerAliasInfo();
247-
QMap< QString, QSet<QString> > excludedAttrs = wfsExcludedAttributes();
248246

249247
foreach ( const QDomElement &elem, mProjectLayerElements )
250248
{
@@ -262,21 +260,8 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
262260
continue;
263261
}
264262

265-
//is there alias info for this vector layer?
266-
QMap< int, QString > layerAliasInfo;
267-
QMap< QString, QMap< int, QString > >::const_iterator aliasIt = aliasInfo.find( mLayer->id() );
268-
if ( aliasIt != aliasInfo.constEnd() )
269-
{
270-
layerAliasInfo = aliasIt.value();
271-
}
272-
273263
//hidden attributes for this layer
274-
QSet<QString> layerExcludedAttributes;
275-
QMap< QString, QSet<QString> >::const_iterator exclIt = excludedAttrs.find( mLayer->id() );
276-
if ( exclIt != excludedAttrs.constEnd() )
277-
{
278-
layerExcludedAttributes = exclIt.value();
279-
}
264+
const QSet<QString>& layerExcludedAttributes = layer->excludeAttributesWFS();
280265

281266
QString typeName = layer->name();
282267
typeName = typeName.replace( QString( " " ), QString( "_" ) );
@@ -349,7 +334,7 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
349334
{
350335

351336
QString attributeName = it.value().name();
352-
//skip attribute if it has edit type 'hidden'
337+
//skip attribute if excluded from WFS publication
353338
if ( layerExcludedAttributes.contains( attributeName ) )
354339
{
355340
continue;
@@ -367,11 +352,10 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
367352

368353
sequenceElem.appendChild( geomElem );
369354

370-
//check if the attribute name should be replaced with an alias
371-
QMap<int, QString>::const_iterator aliasIt = layerAliasInfo.find( it.key() );
372-
if ( aliasIt != layerAliasInfo.constEnd() )
355+
QString alias = layer->attributeAlias( it.key() );
356+
if ( !alias.isEmpty() )
373357
{
374-
geomElem.setAttribute( "alias", aliasIt.value() );
358+
geomElem.setAttribute( "alias", alias );
375359
}
376360
}
377361
}
@@ -1185,52 +1169,6 @@ bool QgsProjectParser::featureInfoWithWktGeometry() const
11851169
return ( wktElem.text().compare( "true", Qt::CaseInsensitive ) == 0 );
11861170
}
11871171

1188-
QMap< QString, QMap< int, QString > > QgsProjectParser::layerAliasInfo() const
1189-
{
1190-
QMap< QString, QMap< int, QString > > resultMap;
1191-
1192-
QList<QDomElement>::const_iterator layerIt = mProjectLayerElements.constBegin();
1193-
for ( ; layerIt != mProjectLayerElements.constEnd(); ++layerIt )
1194-
{
1195-
QDomNodeList aNodeList = layerIt->elementsByTagName( "aliases" );
1196-
if ( aNodeList.size() > 0 )
1197-
{
1198-
QMap<int, QString> aliasMap;
1199-
QDomNodeList aliasNodeList = aNodeList.at( 0 ).toElement().elementsByTagName( "alias" );
1200-
for ( int i = 0; i < aliasNodeList.size(); ++i )
1201-
{
1202-
QDomElement aliasElem = aliasNodeList.at( i ).toElement();
1203-
aliasMap.insert( aliasElem.attribute( "index" ).toInt(), aliasElem.attribute( "name" ) );
1204-
}
1205-
resultMap.insert( layerId( *layerIt ) , aliasMap );
1206-
}
1207-
}
1208-
1209-
return resultMap;
1210-
}
1211-
1212-
/**Returns attributes excluded from WFS publication. Key is layer id, value is a set containing the names of the hidden attributes*/
1213-
QMap< QString, QSet<QString> > QgsProjectParser::wfsExcludedAttributes() const
1214-
{
1215-
QMap< QString, QSet<QString> > resultMap;
1216-
QList<QDomElement>::const_iterator layerIt = mProjectLayerElements.constBegin();
1217-
for ( ; layerIt != mProjectLayerElements.constEnd(); ++layerIt )
1218-
{
1219-
QDomElement excludeWMSElem = layerIt->firstChildElement( "excludeAttributesWFS" );
1220-
QDomNodeList attributeNodeList = excludeWMSElem.elementsByTagName( "attribute" );
1221-
if ( attributeNodeList.size() > 0 )
1222-
{
1223-
QSet<QString> layerExcludedAttributes;
1224-
for ( int i = 0; i < attributeNodeList.size(); ++i )
1225-
{
1226-
layerExcludedAttributes.insert( attributeNodeList.at( i ).toElement().text() );
1227-
}
1228-
resultMap.insert( layerId( *layerIt ), layerExcludedAttributes );
1229-
}
1230-
}
1231-
return resultMap;
1232-
}
1233-
12341172
QgsRectangle QgsProjectParser::mapRectangle() const
12351173
{
12361174
if ( !mXMLDoc )

src/mapserver/qgsprojectparser.h

-7
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ class QgsProjectParser: public QgsConfigParser
8686
/**True if the feature info response should contain the wkt geometry for vector features*/
8787
virtual bool featureInfoWithWktGeometry() const;
8888

89-
/**Returns information about vector layer aliases. First key is the layer id, (second) key is the field id, value the alias.
90-
Default implementation returns an empty map*/
91-
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const;
92-
93-
/**Returns attributes excluded from WFS publication. Key is layer id, value is a set containing the names of the hidden attributes*/
94-
virtual QMap< QString, QSet<QString> > wfsExcludedAttributes() const;
95-
9689
/**Returns map rectangle for the project file*/
9790
QgsRectangle mapRectangle() const;
9891

src/mapserver/qgswfsserver.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
304304
}
305305

306306
QStringList wfsLayersId = mConfigParser->wfsLayers();
307-
QMap< QString, QMap< int, QString > > aliasInfo = mConfigParser->layerAliasInfo();
308-
QMap< QString, QSet<QString> > excludedAttributes = mConfigParser->wfsExcludedAttributes();
309307

310308
QList<QgsMapLayer*> layerList;
311309
QgsMapLayer* currentLayer = 0;
@@ -318,19 +316,19 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
318316
{
319317
//is there alias info for this vector layer?
320318
QMap< int, QString > layerAliasInfo;
321-
QMap< QString, QMap< int, QString > >::const_iterator aliasIt = aliasInfo.find( currentLayer->id() );
322-
if ( aliasIt != aliasInfo.constEnd() )
319+
const QMap< QString, QString >& aliasMap = layer->attributeAliases();
320+
QMap< QString, QString >::const_iterator aliasIt = aliasMap.constBegin();
321+
for ( ; aliasIt != aliasMap.constEnd(); ++aliasIt )
323322
{
324-
layerAliasInfo = aliasIt.value();
323+
int attrIndex = layer->fieldNameIndex( aliasIt.key() );
324+
if ( attrIndex != -1 )
325+
{
326+
layerAliasInfo.insert( attrIndex, aliasIt.value() );
327+
}
325328
}
326329

327330
//excluded attributes for this layer
328-
QSet<QString> layerExcludedAttributes;
329-
QMap< QString, QSet<QString> >::const_iterator exclIt = excludedAttributes.find( currentLayer->id() );
330-
if ( exclIt != excludedAttributes.constEnd() )
331-
{
332-
layerExcludedAttributes = exclIt.value();
333-
}
331+
const QSet<QString>& layerExcludedAttributes = layer->excludeAttributesWFS();
334332

335333
//do a select with searchRect and go through all the features
336334
QgsVectorDataProvider* provider = layer->dataProvider();

src/mapserver/qgswmsserver.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
733733
result.appendChild( getFeatureInfoElement );
734734

735735
QStringList nonIdentifiableLayers = mConfigParser->identifyDisabledLayers();
736-
QMap< QString, QMap< int, QString > > aliasInfo = mConfigParser->layerAliasInfo();
737736

738737
//Render context is needed to determine feature visibility for vector layers
739738
QgsRenderContext renderContext;
@@ -782,14 +781,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
782781
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
783782
if ( vectorLayer )
784783
{
785-
//is there alias info for this vector layer?
786-
QMap< int, QString > layerAliasInfo;
787-
QMap< QString, QMap< int, QString > >::const_iterator aliasIt = aliasInfo.find( currentLayer->id() );
788-
if ( aliasIt != aliasInfo.constEnd() )
789-
{
790-
layerAliasInfo = aliasIt.value();
791-
}
792-
793784
if ( featureInfoFromVectorLayer( vectorLayer, infoPoint, featureCount, result, layerElement, mMapRenderer, renderContext,
794785
version, featuresRect ) != 0 )
795786
{

0 commit comments

Comments
 (0)