Skip to content

Commit

Permalink
[FEATURE]: possibility to exclude vector attributes from WMS and WFS …
Browse files Browse the repository at this point in the history
…publication
  • Loading branch information
Marco Hugentobler committed Oct 17, 2012
1 parent 79be949 commit a02225c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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( )
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -163,6 +163,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
attrCommentCol,
attrEditTypeCol,
attrAliasCol,
attrWMSCol,
attrWFSCol,
attrColCount,
};

Expand Down
46 changes: 46 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );

Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -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 );

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit a02225c

Please sign in to comment.