Skip to content

Commit a02225c

Browse files
author
Marco Hugentobler
committedOct 17, 2012
[FEATURE]: possibility to exclude vector attributes from WMS and WFS publication
1 parent 79be949 commit a02225c

File tree

4 files changed

+85
-13
lines changed

4 files changed

+85
-13
lines changed
 

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,6 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
195195
mDiagramFrame->setLayout( new QVBoxLayout( mDiagramFrame ) );
196196
mDiagramFrame->layout()->addWidget( diagramPropertiesDialog );
197197

198-
//for each overlay plugin create a new tab
199-
int position;
200-
QList<QgsVectorOverlayPlugin*> overlayPluginList = overlayPlugins();
201-
QList<QgsVectorOverlayPlugin*>::const_iterator it = overlayPluginList.constBegin();
202-
203-
for ( ; it != overlayPluginList.constEnd(); ++it )
204-
{
205-
QgsApplyDialog* d = ( *it )->dialog( lyr );
206-
position = tabWidget->insertTab( tabWidget->count(), qobject_cast<QDialog*>( d ), QgsApplication::getThemeIcon( "propertyicons/diagram.png" ), tr( "Overlay" ) );
207-
tabWidget->setCurrentIndex( position ); //ugly, but otherwise the properties dialog is a mess
208-
mOverlayDialogs.push_back( d );
209-
}
210-
211198
//layer title and abstract
212199
if ( layer )
213200
{
@@ -266,6 +253,8 @@ void QgsVectorLayerProperties::loadRows()
266253
tblAttributes->setHorizontalHeaderItem( attrPrecCol, new QTableWidgetItem( tr( "Precision" ) ) );
267254
tblAttributes->setHorizontalHeaderItem( attrCommentCol, new QTableWidgetItem( tr( "Comment" ) ) );
268255
tblAttributes->setHorizontalHeaderItem( attrEditTypeCol, new QTableWidgetItem( tr( "Edit widget" ) ) );
256+
tblAttributes->setHorizontalHeaderItem( attrWMSCol, new QTableWidgetItem( "WMS" ) );
257+
tblAttributes->setHorizontalHeaderItem( attrWFSCol, new QTableWidgetItem( "WFS" ) );
269258
tblAttributes->setHorizontalHeaderItem( attrAliasCol, new QTableWidgetItem( tr( "Alias" ) ) );
270259

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

302291
//set the alias for the attribute
303292
tblAttributes->setItem( row, attrAliasCol, new QTableWidgetItem( layer->attributeAlias( idx ) ) );
293+
294+
//published WMS/WFS attributes
295+
QTableWidgetItem* wmsAttrItem = new QTableWidgetItem();
296+
wmsAttrItem->setCheckState( layer->excludeAttributesWMS().contains( field.name() ) ? Qt::Unchecked : Qt::Checked );
297+
wmsAttrItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
298+
tblAttributes->setItem( row, attrWMSCol, wmsAttrItem );
299+
QTableWidgetItem* wfsAttrItem = new QTableWidgetItem();
300+
wfsAttrItem->setCheckState( layer->excludeAttributesWFS().contains( field.name() ) ? Qt::Unchecked : Qt::Checked );
301+
wfsAttrItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
302+
tblAttributes->setItem( row, attrWFSCol, wfsAttrItem );
304303
}
305304

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

759+
QSet<QString> excludeAttributesWMS, excludeAttributesWFS;
760+
760761
for ( int i = 0; i < tblAttributes->rowCount(); i++ )
761762
{
762763
int idx = tblAttributes->item( i, attrIdCol )->text().toInt();
@@ -815,8 +816,20 @@ void QgsVectorLayerProperties::apply()
815816
case QgsVectorLayer::UuidGenerator:
816817
break;
817818
}
819+
820+
if ( tblAttributes->item( i, attrWMSCol )->checkState() == Qt::Unchecked )
821+
{
822+
excludeAttributesWMS.insert( tblAttributes->item( i, attrNameCol )->text() );
823+
}
824+
if ( tblAttributes->item( i, attrWFSCol )->checkState() == Qt::Unchecked )
825+
{
826+
excludeAttributesWFS.insert( tblAttributes->item( i, attrNameCol )->text() );
827+
}
818828
}
819829

830+
layer->setExcludeAttributesWMS( excludeAttributesWMS );
831+
layer->setExcludeAttributesWFS( excludeAttributesWFS );
832+
820833
if ( layer->isUsingRendererV2() )
821834
{
822835
QgsRendererV2PropertiesDialog* dlg =

‎src/app/qgsvectorlayerproperties.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
163163
attrCommentCol,
164164
attrEditTypeCol,
165165
attrAliasCol,
166+
attrWMSCol,
167+
attrWFSCol,
166168
attrColCount,
167169
};
168170

‎src/core/qgsvectorlayer.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,6 +3236,28 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
32363236
}
32373237
}
32383238

3239+
//Attributes excluded from WMS and WFS
3240+
mExcludeAttributesWMS.clear();
3241+
QDomNode excludeWMSNode = node.namedItem( "excludeAttributesWMS" );
3242+
if ( !excludeWMSNode.isNull() )
3243+
{
3244+
QDomNodeList attributeNodeList = excludeWMSNode.toElement().elementsByTagName( "attribute" );
3245+
for ( int i = 0; i < attributeNodeList.size(); ++i )
3246+
{
3247+
mExcludeAttributesWMS.insert( attributeNodeList.at( i ).toElement().text() );
3248+
}
3249+
}
3250+
3251+
mExcludeAttributesWFS.clear();
3252+
QDomNode excludeWFSNode = node.namedItem( "excludeAttributesWFS" );
3253+
if ( !excludeWFSNode.isNull() )
3254+
{
3255+
QDomNodeList attributeNodeList = excludeWFSNode.toElement().elementsByTagName( "attribute" );
3256+
for ( int i = 0; i < attributeNodeList.size(); ++i )
3257+
{
3258+
mExcludeAttributesWFS.insert( attributeNodeList.at( i ).toElement().text() );
3259+
}
3260+
}
32393261
return true;
32403262
}
32413263

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

3476+
//exclude attributes WMS
3477+
QDomElement excludeWMSElem = doc.createElement( "excludeAttributesWMS" );
3478+
QSet<QString>::const_iterator attWMSIt = mExcludeAttributesWMS.constBegin();
3479+
for ( ; attWMSIt != mExcludeAttributesWMS.constEnd(); ++attWMSIt )
3480+
{
3481+
QDomElement attrElem = doc.createElement( "attribute" );
3482+
QDomText attrText = doc.createTextNode( *attWMSIt );
3483+
attrElem.appendChild( attrText );
3484+
excludeWMSElem.appendChild( attrElem );
3485+
}
3486+
node.appendChild( excludeWMSElem );
3487+
3488+
//exclude attributes WFS
3489+
QDomElement excludeWFSElem = doc.createElement( "excludeAttributesWFS" );
3490+
QSet<QString>::const_iterator attWFSIt = mExcludeAttributesWFS.constBegin();
3491+
for ( ; attWFSIt != mExcludeAttributesWFS.constEnd(); ++attWFSIt )
3492+
{
3493+
QDomElement attrElem = doc.createElement( "attribute" );
3494+
QDomText attrText = doc.createTextNode( *attWFSIt );
3495+
attrElem.appendChild( attrText );
3496+
excludeWFSElem.appendChild( attrElem );
3497+
}
3498+
node.appendChild( excludeWFSElem );
3499+
34543500
// add attribute actions
34553501
mActions->writeXML( node, doc );
34563502

‎src/core/qgsvectorlayer.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
572572
@note added in version 1.2*/
573573
QString attributeDisplayName( int attributeIndex ) const;
574574

575+
const QSet<QString>& excludeAttributesWMS() const { return mExcludeAttributesWMS; }
576+
void setExcludeAttributesWMS( const QSet<QString>& att ) { mExcludeAttributesWMS = att; }
577+
578+
const QSet<QString>& excludeAttributesWFS() const { return mExcludeAttributesWFS; }
579+
void setExcludeAttributesWFS( const QSet<QString>& att ) { mExcludeAttributesWFS = att; }
580+
575581
/** delete an attribute field (but does not commit it) */
576582
bool deleteAttribute( int attr );
577583

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

975+
/**Attributes which are not published in WMS*/
976+
QSet<QString> mExcludeAttributesWMS;
977+
/**Attributes which are not published in WFS*/
978+
QSet<QString> mExcludeAttributesWFS;
979+
969980
/** max field index */
970981
int mMaxUpdatedIndex;
971982

0 commit comments

Comments
 (0)
Please sign in to comment.