Skip to content
Permalink
Browse files

[FEATURE]: Replace value relation strings in GetFeatureInfo output. M…

…ove adding layers for joins and relations to a central place
  • Loading branch information
mhugent committed Mar 11, 2014
1 parent 0fb435e commit 21941215bec062b2d5158a4bcf46e72331855813
@@ -125,9 +125,9 @@ void QgsMapLayerRegistry::removeMapLayers( QStringList theLayerIds )
foreach ( const QString &myId, theLayerIds )
{
QgsMapLayer* lyr = mMapLayers[myId];
emit layerWillBeRemoved( myId );
if ( mOwnedLayers.contains( lyr ) )
{
emit layerWillBeRemoved( myId );
delete lyr;
mOwnedLayers.remove( lyr );
}
@@ -245,6 +245,8 @@ int main( int argc, char * argv[] )
QgsFontUtils::loadStandardTestFonts( QStringList() << "Roman" << "Bold" );
#endif


//for( int i = 0; i < 2; ++i )
while ( fcgi_accept() >= 0 )
{
printRequestInfos(); //print request infos if in debug mode
@@ -68,7 +68,7 @@ class QgsConfigParser
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache = true ) const = 0;

/**Returns maplayers for a layer Id.*/
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId ) const = 0;
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId, bool useCache = true ) const = 0;

/**Returns number of layers in configuration*/
virtual int numberOfLayers() const = 0;
@@ -157,7 +157,7 @@ void QgsProjectParser::featureTypeList( QDomElement& parentElement, QDomDocument
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
//QgsMapLayer *layer = createLayerFromElement( *layerIt );
addJoinLayersForElement( elem );
QgsMapLayer *layer = createLayerFromElement( elem );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
@@ -293,7 +293,6 @@ void QgsProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDocum
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
//QgsMapLayer *layer = createLayerFromElement( *layerIt );
QgsMapLayer *layer = createLayerFromElement( elem );
if ( layer && wcsLayersId.contains( layer->id() ) )
{
@@ -491,6 +490,7 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
addJoinLayersForElement( elem );
QgsMapLayer *mLayer = createLayerFromElement( elem );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
@@ -507,23 +507,6 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
{
continue;
}
if ( layer->vectorJoins().size() > 0 )
{
QList<QgsMapLayer *> joinLayers;
//JoinBuffer is based on qgsmaplayerregistry!!!!!
//insert existing join info
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
for ( int i = 0; i < joins.size(); ++i )
{
QgsMapLayer* joinLayer = mapLayerFromLayerId( joins[i].joinLayerId );
if ( joinLayer )
{
joinLayers << joinLayer;
}
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
}
layer->updateFields();
}

//hidden attributes for this layer
const QSet<QString>& layerExcludedAttributes = layer->excludeAttributesWFS();
@@ -659,7 +642,6 @@ void QgsProjectParser::describeCoverage( const QString& aCoveName, QDomElement&
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
//QgsMapLayer *layer = createLayerFromElement( *layerIt );
QgsMapLayer *layer = createLayerFromElement( elem );
if ( !layer )
continue;
@@ -864,6 +846,7 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromTypeName( const QString& aType
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
addJoinLayersForElement( elem, useCache );
QgsMapLayer *mLayer = createLayerFromElement( elem );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
@@ -975,6 +958,7 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
QList<QDomElement> embeddedProjectLayerElements = p->mProjectLayerElements;
foreach ( const QDomElement &elem, embeddedProjectLayerElements )
{
p->addJoinLayersForElement( elem );
pLayerMap.insert( layerId( elem ), p->createLayerFromElement( elem ) );
}

@@ -1010,16 +994,6 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
{
continue;
}
//vector layer without geometry
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
QGis::WkbType wkbType = vectorLayer->wkbType();
if ( wkbType == QGis::WKBNoGeometry )
{
continue;
}
}
// queryable layer
if ( nonIdentifiableLayers.contains( currentLayer->id() ) )
{
@@ -1077,12 +1051,29 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
layerElem.appendChild( keywordListElem );
}

//vector layer without geometry
bool geometryLayer = true;
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( vLayer )
{
if ( vLayer->wkbType() == QGis::WKBNoGeometry )
{
geometryLayer = false;
}
}
}

//CRS
QStringList crsList = createCRSListForLayer( currentLayer );
appendCRSElementsToLayer( layerElem, doc, crsList );
if ( geometryLayer )
{
QStringList crsList = createCRSListForLayer( currentLayer );
appendCRSElementsToLayer( layerElem, doc, crsList );

//Ex_GeographicBoundingBox
appendLayerBoundingBoxes( layerElem, doc, currentLayer->extent(), currentLayer->crs() );
//Ex_GeographicBoundingBox
appendLayerBoundingBoxes( layerElem, doc, currentLayer->extent(), currentLayer->crs() );
}

//only one default style in project file mode
QDomElement styleElem = doc.createElement( "Style" );
@@ -1325,6 +1316,7 @@ void QgsProjectParser::addOWSLayers( QDomDocument &doc,
QList<QDomElement> embeddedProjectLayerElements = p->mProjectLayerElements;
foreach ( const QDomElement &elem, embeddedProjectLayerElements )
{
p->addJoinLayersForElement( elem );
pLayerMap.insert( layerId( elem ), p->createLayerFromElement( elem ) );
}

@@ -1712,6 +1704,8 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
QHash< QString, QDomElement >::const_iterator layerElemIt = mProjectLayerElementsByName.find( lName );
if ( layerElemIt != mProjectLayerElementsByName.constEnd() )
{
addJoinLayersForElement( layerElemIt.value(), useCache );
addValueRelationLayersForElement( layerElemIt.value(), useCache );
QgsMapLayer* layer = createLayerFromElement( layerElemIt.value(), useCache );
if ( layer )
{
@@ -1794,6 +1788,8 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
QHash< QString, QDomElement >::const_iterator pLayerNameIt = pLayerByName.find( lName );
if ( pLayerNameIt != pLayerByName.constEnd() )
{
p->addJoinLayersForElement( pLayerNameIt.value(), useCache );
p->addValueRelationLayersForElement( pLayerNameIt.value(), useCache );
layerList.push_back( p->createLayerFromElement( pLayerNameIt.value(), useCache ) );
break;
}
@@ -1814,12 +1810,12 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
return layerList;
}

QgsMapLayer* QgsProjectParser::mapLayerFromLayerId( const QString& lId ) const
QgsMapLayer* QgsProjectParser::mapLayerFromLayerId( const QString& lId, bool useCache ) const
{
QHash< QString, QDomElement >::const_iterator layerIt = mProjectLayerElementsById.find( lId );
if ( layerIt != mProjectLayerElementsById.constEnd() )
{
return createLayerFromElement( layerIt.value(), true );
return createLayerFromElement( layerIt.value(), useCache );
}
return 0;
}
@@ -1894,6 +1890,8 @@ void QgsProjectParser::addLayerFromLegendLayer( const QDomElement& legendLayerEl
QHash< QString, QDomElement >::const_iterator layerIt = mProjectLayerElementsById.find( id );
if ( layerIt != mProjectLayerElementsById.constEnd() )
{
addJoinLayersForElement( layerIt.value(), useCache );
addValueRelationLayersForElement( layerIt.value(), useCache );
QgsMapLayer* layer = createLayerFromElement( layerIt.value(), useCache );
if ( layer )
{
@@ -3737,6 +3735,8 @@ void QgsProjectParser::projectLayerMap( QMap<QString, QgsMapLayer*>& layerMap )
layerMap.clear();
foreach ( const QDomElement &elem, mProjectLayerElements )
{
addJoinLayersForElement( elem );
addValueRelationLayersForElement( elem );
QgsMapLayer *layer = createLayerFromElement( elem );
if ( layer )
{
@@ -4268,3 +4268,57 @@ QList< QPair< QString, QgsLayerCoordinateTransform > > QgsProjectParser::layerCo
}
return layerTransformList;
}

void QgsProjectParser::addJoinLayersForElement( const QDomElement& layerElem, bool useCache ) const
{
QDomElement vectorJoinsElem = layerElem.firstChildElement( "vectorjoins" );
if ( vectorJoinsElem.isNull() )
{
return;
}

QDomNodeList joinNodeList = vectorJoinsElem.elementsByTagName( "join" );
if ( joinNodeList.size() > 1 )
{
return;
}

for ( int i = 0; i < joinNodeList.size(); ++i )
{
QString id = joinNodeList.at( i ).toElement().attribute( "joinLayerId" );
QgsMapLayer* layer = mapLayerFromLayerId( id, useCache );
if ( layer )
{
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
}
}
}

void QgsProjectParser::addValueRelationLayersForElement( const QDomElement& layerElem, bool useCache ) const
{
QDomElement editTypesElem = layerElem.firstChildElement( "edittypes" );
if ( editTypesElem.isNull() )
{
return;
}

QDomNodeList editTypeNodeList = editTypesElem.elementsByTagName( "edittype" );
for ( int i = 0; i < editTypeNodeList.size(); ++i )
{
QDomElement editTypeElem = editTypeNodeList.at( i ).toElement();
int type = editTypeElem.attribute( "type" ).toInt();
if ( type == QgsVectorLayer::ValueRelation )
{
QString layerId = editTypeElem.attribute( "layer" );
/*QString keyAttribute = editTypeEleml.attribute( "id" ); //relation attribute in other layer
QString valueAttribute = editTypeElem.attribute( "value" ); //value attribute in other layer
QString relationAttribute = editTypeElem.attribute( "name" );*/

QgsMapLayer* layer = mapLayerFromLayerId( layerId, useCache );
if ( layer )
{
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
}
}
}
}
@@ -64,7 +64,7 @@ class QgsProjectParser: public QgsConfigParser
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& lName, const QString& styleName, bool useCache = true ) const;

/**Returns maplayers for a layer Id.*/
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId ) const;
virtual QgsMapLayer* mapLayerFromLayerId( const QString& lId, bool useCache = true ) const;

/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
virtual int layersAndStyles( QStringList& layers, QStringList& styles ) const;
@@ -160,6 +160,11 @@ class QgsProjectParser: public QgsConfigParser

QList< QPair< QString, QgsLayerCoordinateTransform > > layerCoordinateTransforms() const;

/**Makes sure the join layers needed for a layer are in the layer cache / maplayer registry*/
void addJoinLayersForElement( const QDomElement& layerElem, bool useCache = true ) const;
/**Makes sure the value relation layers are in the layer cache / maplayer registry*/
void addValueRelationLayersForElement( const QDomElement& layerElem, bool useCache = true ) const;

private:

//forbidden
@@ -70,7 +70,7 @@ class QgsSLDParser: public QgsConfigParser
QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool useCache = true ) const;

/**Returns maplayers for a layer Id.*/
QgsMapLayer* mapLayerFromLayerId( const QString& ) const { return 0;};
QgsMapLayer* mapLayerFromLayerId( const QString& lId, bool useCache = true ) const { Q_UNUSED( lId ); Q_UNUSED( useCache ); return 0; }

/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
int layersAndStyles( QStringList& layers, QStringList& styles ) const;
@@ -339,22 +339,6 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
if ( layer->vectorJoins().size() > 0 )
{
QList<QgsMapLayer *> joinLayers;
//insert existing join info
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
for ( int i = 0; i < joins.size(); ++i )
{
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
if ( joinLayer )
{
joinLayers << joinLayer;
}
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
}
layer->updateFields();
}
//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
const QMap< QString, QString >& aliasMap = layer->attributeAliases();
@@ -697,22 +681,6 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
if ( layer->vectorJoins().size() > 0 )
{
QList<QgsMapLayer *> joinLayers;
//insert existing join info
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
for ( int i = 0; i < joins.size(); ++i )
{
QgsMapLayer* joinLayer = mConfigParser->mapLayerFromLayerId( joins[i].joinLayerId );
if ( joinLayer )
{
joinLayers << joinLayer;
}
QgsMapLayerRegistry::instance()->addMapLayers( joinLayers, false, true );
}
layer->updateFields();
}
//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
const QMap< QString, QString >& aliasMap = layer->attributeAliases();

0 comments on commit 2194121

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