Skip to content
Permalink
Browse files

use configuration flags to save WMS/WFS from vector layer

  • Loading branch information
3nids committed Sep 14, 2020
1 parent 19d4b52 commit 4fd940a352e35f97c146bf66238f777a2a7b1478
Showing with 39 additions and 50 deletions.
  1. +5 −4 python/core/auto_generated/qgsvectorlayer.sip.in
  2. +24 −42 src/core/qgsvectorlayer.cpp
  3. +10 −4 src/core/qgsvectorlayer.h
@@ -1968,22 +1968,22 @@ Convenience function that returns the attribute alias if defined or the field na
Returns a map of field name to attribute alias
%End

QSet<QString> excludeAttributesWms() const;
QSet<QString> excludeAttributesWms() /Deprecated/ const;
%Docstring
A set of attributes that are not advertised in WMS requests with QGIS server.
%End

void setExcludeAttributesWms( const QSet<QString> &att );
void setExcludeAttributesWms( const QSet<QString> &att ) /Deprecated/;
%Docstring
A set of attributes that are not advertised in WMS requests with QGIS server.
%End

QSet<QString> excludeAttributesWfs() const;
QSet<QString> excludeAttributesWfs() /Deprecated/ const;
%Docstring
A set of attributes that are not advertised in WFS requests with QGIS server.
%End

void setExcludeAttributesWfs( const QSet<QString> &att );
void setExcludeAttributesWfs( const QSet<QString> &att ) /Deprecated/;
%Docstring
A set of attributes that are not advertised in WFS requests with QGIS server.
%End
@@ -2294,6 +2294,7 @@ can also be set. Setting an empty expression will clear any existing expression




void setEditorWidgetSetup( int index, const QgsEditorWidgetSetup &setup );
%Docstring
\copydoc editorWidgetSetup
@@ -274,8 +274,6 @@ QgsVectorLayer *QgsVectorLayer::clone() const
layer->setMapTipTemplate( mapTipTemplate() );
layer->setReadOnly( isReadOnly() );
layer->selectByIds( selectedFeatureIds() );
layer->setExcludeAttributesWms( excludeAttributesWms() );
layer->setExcludeAttributesWfs( excludeAttributesWfs() );
layer->setAttributeTableConfig( attributeTableConfig() );
layer->setFeatureBlendMode( featureBlendMode() );
layer->setOpacity( opacity() );
@@ -2306,26 +2304,25 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes

updateFields();

// Legacy reading for QGIS 3.14 and older projects
//Attributes excluded from WMS and WFS
mExcludeAttributesWMS.clear();
QDomNode excludeWMSNode = layerNode.namedItem( QStringLiteral( "excludeAttributesWMS" ) );
if ( !excludeWMSNode.isNull() )
const QList<QPair<QString, QgsField::ConfigurationFlag>> legacyConfig
{
QDomNodeList attributeNodeList = excludeWMSNode.toElement().elementsByTagName( QStringLiteral( "attribute" ) );
for ( int i = 0; i < attributeNodeList.size(); ++i )
{
mExcludeAttributesWMS.insert( attributeNodeList.at( i ).toElement().text() );
}
}

mExcludeAttributesWFS.clear();
QDomNode excludeWFSNode = layerNode.namedItem( QStringLiteral( "excludeAttributesWFS" ) );
if ( !excludeWFSNode.isNull() )
qMakePair( QStringLiteral( "excludeAttributesWMS" ), QgsField::ConfigurationFlag::Wms ),
qMakePair( QStringLiteral( "excludeAttributesWFS" ), QgsField::ConfigurationFlag::Wfs )
};
for ( const auto &config : legacyConfig )
{
QDomNodeList attributeNodeList = excludeWFSNode.toElement().elementsByTagName( QStringLiteral( "attribute" ) );
for ( int i = 0; i < attributeNodeList.size(); ++i )
QDomNode excludeNode = layerNode.namedItem( config.first );
if ( !excludeNode.isNull() )
{
mExcludeAttributesWFS.insert( attributeNodeList.at( i ).toElement().text() );
QDomNodeList attributeNodeList = excludeNode.toElement().elementsByTagName( QStringLiteral( "attribute" ) );
for ( int i = 0; i < attributeNodeList.size(); ++i )
{
QString fieldName = attributeNodeList.at( i ).toElement().text();
int index = mFields.indexFromName( fieldName );
setFieldConfigurationFlag( index, config.second, false );
}
}
}

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

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

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

//default expressions
QDomElement defaultsElem = doc.createElement( QStringLiteral( "defaults" ) );
for ( const QgsField &field : qgis::as_const( mFields ) )
@@ -5493,6 +5466,15 @@ void QgsVectorLayer::setFieldConfigurationFlags( int index, QgsField::Configurat
updateFields();
}

void QgsVectorLayer::setFieldConfigurationFlag( int index, QgsField::ConfigurationFlag flag, bool active )
{
if ( index < 0 || index >= mFields.count() )
return;
QgsField::ConfigurationFlags flags = mFields.at( index ).configurationFlags();
flags.setFlag( flag, active );
setFieldConfigurationFlags( index, flags );
}

QgsField::ConfigurationFlags QgsVectorLayer::fieldConfigurationFlags( int index ) const
{

@@ -1840,22 +1840,22 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
/**
* A set of attributes that are not advertised in WMS requests with QGIS server.
*/
QSet<QString> excludeAttributesWms() const { return mExcludeAttributesWMS; }
Q_DECL_DEPRECATED QSet<QString> excludeAttributesWms() SIP_DEPRECATED const { return mExcludeAttributesWMS; }

/**
* A set of attributes that are not advertised in WMS requests with QGIS server.
*/
void setExcludeAttributesWms( const QSet<QString> &att ) { mExcludeAttributesWMS = att; }
Q_DECL_DEPRECATED void setExcludeAttributesWms( const QSet<QString> &att ) SIP_DEPRECATED { mExcludeAttributesWMS = att; }

/**
* A set of attributes that are not advertised in WFS requests with QGIS server.
*/
QSet<QString> excludeAttributesWfs() const { return mExcludeAttributesWFS; }
Q_DECL_DEPRECATED QSet<QString> excludeAttributesWfs() SIP_DEPRECATED const { return mExcludeAttributesWFS; }

/**
* A set of attributes that are not advertised in WFS requests with QGIS server.
*/
void setExcludeAttributesWfs( const QSet<QString> &att ) { mExcludeAttributesWFS = att; }
Q_DECL_DEPRECATED void setExcludeAttributesWfs( const QSet<QString> &att ) SIP_DEPRECATED { mExcludeAttributesWFS = att; }

/**
* Deletes an attribute field (but does not commit it).
@@ -2122,6 +2122,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
void setFieldConfigurationFlags( int index, QgsField::ConfigurationFlags flags ) SIP_SKIP;

/**
* Sets the given configuration \a flag for the field at given \a index to be \a active or not.
* \since QGIS 3.16
*/
void setFieldConfigurationFlag( int index, QgsField::ConfigurationFlag flag, bool active ) SIP_SKIP;

/**
* Returns the configuration flags of the field at given index
* \see QgsField::ConfigurationFlag

0 comments on commit 4fd940a

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