Skip to content
Permalink
Browse files

Simplify server config parser by using layer information (alias, excl…

…uded attributes) directly
  • Loading branch information
mhugent committed Oct 19, 2012
1 parent 4358e8e commit 14de54316bfa621cc88ab8d74c99b9826114cfc4
@@ -572,6 +572,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
@note added in version 1.2*/
QString attributeDisplayName( int attributeIndex ) const;

const QMap< QString, QString >& attributeAliases() const { return mAttributeAliasMap; }

const QSet<QString>& excludeAttributesWMS() const { return mExcludeAttributesWMS; }
void setExcludeAttributesWMS( const QSet<QString>& att ) { mExcludeAttributesWMS = att; }

@@ -108,13 +108,6 @@ class QgsConfigParser
/**True if the feature info response should contain the wkt geometry for vector features*/
virtual bool featureInfoWithWktGeometry() const { return false; }

/**Returns information about vector layer aliases. First key is the layer id, (second) key is the field id, value the alias.
Default implementation returns an empty map*/
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const { return QMap< QString, QMap<int, QString> > (); }

/**Returns attributes excluded from WFS publication. Key is layer id, value is a set containing the names of the hidden attributes*/
virtual QMap< QString, QSet<QString> > wfsExcludedAttributes() const { return QMap< QString, QSet<QString> >(); }

/**Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/
QgsComposition* createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap ) const;

@@ -243,8 +243,6 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
}

QStringList wfsLayersId = wfsLayers();
QMap< QString, QMap< int, QString > > aliasInfo = layerAliasInfo();
QMap< QString, QSet<QString> > excludedAttrs = wfsExcludedAttributes();

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

//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
QMap< QString, QMap< int, QString > >::const_iterator aliasIt = aliasInfo.find( mLayer->id() );
if ( aliasIt != aliasInfo.constEnd() )
{
layerAliasInfo = aliasIt.value();
}

//hidden attributes for this layer
QSet<QString> layerExcludedAttributes;
QMap< QString, QSet<QString> >::const_iterator exclIt = excludedAttrs.find( mLayer->id() );
if ( exclIt != excludedAttrs.constEnd() )
{
layerExcludedAttributes = exclIt.value();
}
const QSet<QString>& layerExcludedAttributes = layer->excludeAttributesWFS();

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

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

sequenceElem.appendChild( geomElem );

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

QMap< QString, QMap< int, QString > > QgsProjectParser::layerAliasInfo() const
{
QMap< QString, QMap< int, QString > > resultMap;

QList<QDomElement>::const_iterator layerIt = mProjectLayerElements.constBegin();
for ( ; layerIt != mProjectLayerElements.constEnd(); ++layerIt )
{
QDomNodeList aNodeList = layerIt->elementsByTagName( "aliases" );
if ( aNodeList.size() > 0 )
{
QMap<int, QString> aliasMap;
QDomNodeList aliasNodeList = aNodeList.at( 0 ).toElement().elementsByTagName( "alias" );
for ( int i = 0; i < aliasNodeList.size(); ++i )
{
QDomElement aliasElem = aliasNodeList.at( i ).toElement();
aliasMap.insert( aliasElem.attribute( "index" ).toInt(), aliasElem.attribute( "name" ) );
}
resultMap.insert( layerId( *layerIt ) , aliasMap );
}
}

return resultMap;
}

/**Returns attributes excluded from WFS publication. Key is layer id, value is a set containing the names of the hidden attributes*/
QMap< QString, QSet<QString> > QgsProjectParser::wfsExcludedAttributes() const
{
QMap< QString, QSet<QString> > resultMap;
QList<QDomElement>::const_iterator layerIt = mProjectLayerElements.constBegin();
for ( ; layerIt != mProjectLayerElements.constEnd(); ++layerIt )
{
QDomElement excludeWMSElem = layerIt->firstChildElement( "excludeAttributesWFS" );
QDomNodeList attributeNodeList = excludeWMSElem.elementsByTagName( "attribute" );
if ( attributeNodeList.size() > 0 )
{
QSet<QString> layerExcludedAttributes;
for ( int i = 0; i < attributeNodeList.size(); ++i )
{
layerExcludedAttributes.insert( attributeNodeList.at( i ).toElement().text() );
}
resultMap.insert( layerId( *layerIt ), layerExcludedAttributes );
}
}
return resultMap;
}

QgsRectangle QgsProjectParser::mapRectangle() const
{
if ( !mXMLDoc )
@@ -86,13 +86,6 @@ class QgsProjectParser: public QgsConfigParser
/**True if the feature info response should contain the wkt geometry for vector features*/
virtual bool featureInfoWithWktGeometry() const;

/**Returns information about vector layer aliases. First key is the layer id, (second) key is the field id, value the alias.
Default implementation returns an empty map*/
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const;

/**Returns attributes excluded from WFS publication. Key is layer id, value is a set containing the names of the hidden attributes*/
virtual QMap< QString, QSet<QString> > wfsExcludedAttributes() const;

/**Returns map rectangle for the project file*/
QgsRectangle mapRectangle() const;

@@ -304,8 +304,6 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}

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

QList<QgsMapLayer*> layerList;
QgsMapLayer* currentLayer = 0;
@@ -318,19 +316,19 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
{
//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
QMap< QString, QMap< int, QString > >::const_iterator aliasIt = aliasInfo.find( currentLayer->id() );
if ( aliasIt != aliasInfo.constEnd() )
const QMap< QString, QString >& aliasMap = layer->attributeAliases();
QMap< QString, QString >::const_iterator aliasIt = aliasMap.constBegin();
for ( ; aliasIt != aliasMap.constEnd(); ++aliasIt )
{
layerAliasInfo = aliasIt.value();
int attrIndex = layer->fieldNameIndex( aliasIt.key() );
if ( attrIndex != -1 )
{
layerAliasInfo.insert( attrIndex, aliasIt.value() );
}
}

//excluded attributes for this layer
QSet<QString> layerExcludedAttributes;
QMap< QString, QSet<QString> >::const_iterator exclIt = excludedAttributes.find( currentLayer->id() );
if ( exclIt != excludedAttributes.constEnd() )
{
layerExcludedAttributes = exclIt.value();
}
const QSet<QString>& layerExcludedAttributes = layer->excludeAttributesWFS();

//do a select with searchRect and go through all the features
QgsVectorDataProvider* provider = layer->dataProvider();
@@ -733,7 +733,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
result.appendChild( getFeatureInfoElement );

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

//Render context is needed to determine feature visibility for vector layers
QgsRenderContext renderContext;
@@ -782,14 +781,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( vectorLayer )
{
//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
QMap< QString, QMap< int, QString > >::const_iterator aliasIt = aliasInfo.find( currentLayer->id() );
if ( aliasIt != aliasInfo.constEnd() )
{
layerAliasInfo = aliasIt.value();
}

if ( featureInfoFromVectorLayer( vectorLayer, infoPoint, featureCount, result, layerElement, mMapRenderer, renderContext,
version, featuresRect ) != 0 )
{

0 comments on commit 14de543

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