Skip to content
Permalink
Browse files

Merge branch 'ows_attribute_exclude'

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Oct 17, 2012
2 parents df85492 + bacf0bd commit b6ec976aa8b96c0856f5235307f7e896b2445907
@@ -195,19 +195,6 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mDiagramFrame->setLayout( new QVBoxLayout( mDiagramFrame ) );
mDiagramFrame->layout()->addWidget( diagramPropertiesDialog );

//for each overlay plugin create a new tab
int position;
QList<QgsVectorOverlayPlugin*> overlayPluginList = overlayPlugins();
QList<QgsVectorOverlayPlugin*>::const_iterator it = overlayPluginList.constBegin();

for ( ; it != overlayPluginList.constEnd(); ++it )
{
QgsApplyDialog* d = ( *it )->dialog( lyr );
position = tabWidget->insertTab( tabWidget->count(), qobject_cast<QDialog*>( d ), QgsApplication::getThemeIcon( "propertyicons/diagram.png" ), tr( "Overlay" ) );
tabWidget->setCurrentIndex( position ); //ugly, but otherwise the properties dialog is a mess
mOverlayDialogs.push_back( d );
}

//layer title and abstract
if ( layer )
{
@@ -266,6 +253,8 @@ void QgsVectorLayerProperties::loadRows()
tblAttributes->setHorizontalHeaderItem( attrPrecCol, new QTableWidgetItem( tr( "Precision" ) ) );
tblAttributes->setHorizontalHeaderItem( attrCommentCol, new QTableWidgetItem( tr( "Comment" ) ) );
tblAttributes->setHorizontalHeaderItem( attrEditTypeCol, new QTableWidgetItem( tr( "Edit widget" ) ) );
tblAttributes->setHorizontalHeaderItem( attrWMSCol, new QTableWidgetItem( "WMS" ) );
tblAttributes->setHorizontalHeaderItem( attrWFSCol, new QTableWidgetItem( "WFS" ) );
tblAttributes->setHorizontalHeaderItem( attrAliasCol, new QTableWidgetItem( tr( "Alias" ) ) );

tblAttributes->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );
@@ -301,6 +290,16 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )

//set the alias for the attribute
tblAttributes->setItem( row, attrAliasCol, new QTableWidgetItem( layer->attributeAlias( idx ) ) );

//published WMS/WFS attributes
QTableWidgetItem* wmsAttrItem = new QTableWidgetItem();
wmsAttrItem->setCheckState( layer->excludeAttributesWMS().contains( field.name() ) ? Qt::Unchecked : Qt::Checked );
wmsAttrItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
tblAttributes->setItem( row, attrWMSCol, wmsAttrItem );
QTableWidgetItem* wfsAttrItem = new QTableWidgetItem();
wfsAttrItem->setCheckState( layer->excludeAttributesWFS().contains( field.name() ) ? Qt::Unchecked : Qt::Checked );
wfsAttrItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
tblAttributes->setItem( row, attrWFSCol, wfsAttrItem );
}

void QgsVectorLayerProperties::attributeTypeDialog( )
@@ -757,6 +756,8 @@ void QgsVectorLayerProperties::apply()
layer->enableLabels( labelCheckBox->isChecked() );
layer->setLayerName( displayName() );

QSet<QString> excludeAttributesWMS, excludeAttributesWFS;

for ( int i = 0; i < tblAttributes->rowCount(); i++ )
{
int idx = tblAttributes->item( i, attrIdCol )->text().toInt();
@@ -815,8 +816,20 @@ void QgsVectorLayerProperties::apply()
case QgsVectorLayer::UuidGenerator:
break;
}

if ( tblAttributes->item( i, attrWMSCol )->checkState() == Qt::Unchecked )
{
excludeAttributesWMS.insert( tblAttributes->item( i, attrNameCol )->text() );
}
if ( tblAttributes->item( i, attrWFSCol )->checkState() == Qt::Unchecked )
{
excludeAttributesWFS.insert( tblAttributes->item( i, attrNameCol )->text() );
}
}

layer->setExcludeAttributesWMS( excludeAttributesWMS );
layer->setExcludeAttributesWFS( excludeAttributesWFS );

if ( layer->isUsingRendererV2() )
{
QgsRendererV2PropertiesDialog* dlg =
@@ -163,6 +163,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
attrCommentCol,
attrEditTypeCol,
attrAliasCol,
attrWMSCol,
attrWFSCol,
attrColCount,
};

@@ -3236,6 +3236,28 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
}
}

//Attributes excluded from WMS and WFS
mExcludeAttributesWMS.clear();
QDomNode excludeWMSNode = node.namedItem( "excludeAttributesWMS" );
if ( !excludeWMSNode.isNull() )
{
QDomNodeList attributeNodeList = excludeWMSNode.toElement().elementsByTagName( "attribute" );
for ( int i = 0; i < attributeNodeList.size(); ++i )
{
mExcludeAttributesWMS.insert( attributeNodeList.at( i ).toElement().text() );
}
}

mExcludeAttributesWFS.clear();
QDomNode excludeWFSNode = node.namedItem( "excludeAttributesWFS" );
if ( !excludeWFSNode.isNull() )
{
QDomNodeList attributeNodeList = excludeWFSNode.toElement().elementsByTagName( "attribute" );
for ( int i = 0; i < attributeNodeList.size(); ++i )
{
mExcludeAttributesWFS.insert( attributeNodeList.at( i ).toElement().text() );
}
}
return true;
}

@@ -3451,6 +3473,30 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
node.appendChild( aliasElem );
}

//exclude attributes WMS
QDomElement excludeWMSElem = doc.createElement( "excludeAttributesWMS" );
QSet<QString>::const_iterator attWMSIt = mExcludeAttributesWMS.constBegin();
for ( ; attWMSIt != mExcludeAttributesWMS.constEnd(); ++attWMSIt )
{
QDomElement attrElem = doc.createElement( "attribute" );
QDomText attrText = doc.createTextNode( *attWMSIt );
attrElem.appendChild( attrText );
excludeWMSElem.appendChild( attrElem );
}
node.appendChild( excludeWMSElem );

//exclude attributes WFS
QDomElement excludeWFSElem = doc.createElement( "excludeAttributesWFS" );
QSet<QString>::const_iterator attWFSIt = mExcludeAttributesWFS.constBegin();
for ( ; attWFSIt != mExcludeAttributesWFS.constEnd(); ++attWFSIt )
{
QDomElement attrElem = doc.createElement( "attribute" );
QDomText attrText = doc.createTextNode( *attWFSIt );
attrElem.appendChild( attrText );
excludeWFSElem.appendChild( attrElem );
}
node.appendChild( excludeWFSElem );

// add attribute actions
mActions->writeXML( node, doc );

@@ -572,6 +572,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
@note added in version 1.2*/
QString attributeDisplayName( int attributeIndex ) const;

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

const QSet<QString>& excludeAttributesWFS() const { return mExcludeAttributesWFS; }
void setExcludeAttributesWFS( const QSet<QString>& att ) { mExcludeAttributesWFS = att; }

/** delete an attribute field (but does not commit it) */
bool deleteAttribute( int attr );

@@ -966,6 +972,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/**Map that stores the aliases for attributes. Key is the attribute name and value the alias for that attribute*/
QMap< QString, QString > mAttributeAliasMap;

/**Attributes which are not published in WMS*/
QSet<QString> mExcludeAttributesWMS;
/**Attributes which are not published in WFS*/
QSet<QString> mExcludeAttributesWFS;

/** max field index */
int mMaxUpdatedIndex;

@@ -109,8 +109,11 @@ class QgsConfigParser
Default implementation returns an empty map*/
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const { return QMap< QString, QMap<int, QString> > (); }

/**Returns information about vector attributes with hidden edit type. Key is layer id, value is a set containing the names of the hidden attributes*/
virtual QMap< QString, QSet<QString> > hiddenAttributes() const { return QMap< QString, QSet<QString> >(); }
/**Returns attributes excluded from WMS publication. Key is layer id, value is a set containing the names of the hidden attributes*/
virtual QMap< QString, QSet<QString> > wmsExcludedAttributes() const { return QMap< QString, QSet<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;
@@ -210,7 +210,7 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen

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

foreach ( const QDomElement &elem, mProjectLayerElements )
{
@@ -237,11 +237,11 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen
}

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

QString typeName = layer->name();
@@ -316,7 +316,7 @@ void QgsProjectParser::describeFeatureType( const QString& aTypeName, QDomElemen

QString attributeName = it.value().name();
//skip attribute if it has edit type 'hidden'
if ( layerHiddenAttributes.contains( attributeName ) )
if ( layerExcludedAttributes.contains( attributeName ) )
{
continue;
}
@@ -1053,34 +1053,46 @@ QMap< QString, QMap< int, QString > > QgsProjectParser::layerAliasInfo() const
return resultMap;
}

QMap< QString, QSet<QString> > QgsProjectParser::hiddenAttributes() const
QMap< QString, QSet<QString> > QgsProjectParser::wmsExcludedAttributes() const
{
QMap< QString, QSet<QString> > resultMap;
QList<QDomElement>::const_iterator layerIt = mProjectLayerElements.constBegin();
for ( ; layerIt != mProjectLayerElements.constEnd(); ++layerIt )
{
QDomNodeList editTypesList = layerIt->elementsByTagName( "edittypes" );
if ( editTypesList.size() > 0 )
QDomElement excludeWMSElem = layerIt->firstChildElement( "excludeAttributesWMS" );
QDomNodeList attributeNodeList = excludeWMSElem.elementsByTagName( "attribute" );
if ( attributeNodeList.size() > 0 )
{
QSet< QString > hiddenAttributes;
QDomElement editTypesElem = editTypesList.at( 0 ).toElement();
QDomNodeList editTypeList = editTypesElem.elementsByTagName( "edittype" );
for ( int i = 0; i < editTypeList.size(); ++i )
QSet<QString> layerExcludedAttributes;
for ( int i = 0; i < attributeNodeList.size(); ++i )
{
QDomElement editTypeElem = editTypeList.at( i ).toElement();
if ( editTypeElem.attribute( "type" ).toInt() == QgsVectorLayer::Hidden )
{
hiddenAttributes.insert( editTypeElem.attribute( "name" ) );
}
layerExcludedAttributes.insert( attributeNodeList.at( i ).toElement().text() );
}
resultMap.insert( layerId( *layerIt ), layerExcludedAttributes );
}
}
return resultMap;
}

if ( hiddenAttributes.size() > 0 )
/**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 )
{
resultMap.insert( layerId( *layerIt ), hiddenAttributes );
layerExcludedAttributes.insert( attributeNodeList.at( i ).toElement().text() );
}
resultMap.insert( layerId( *layerIt ), layerExcludedAttributes );
}
}

return resultMap;
}

@@ -87,8 +87,11 @@ class QgsProjectParser: public QgsConfigParser
Default implementation returns an empty map*/
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const;

/**Returns a stringlist containing the names of the attributes with hidden edit types*/
virtual QMap< QString, QSet<QString> > hiddenAttributes() const;
/**Returns attributes excluded from WMS publication. Key is layer id, value is a set containing the names of the hidden attributes*/
virtual QMap< QString, QSet<QString> > wmsExcludedAttributes() 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;

0 comments on commit b6ec976

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