Skip to content

Commit

Permalink
const correctness QgsVectorLayer::deleteAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nyalldawson committed May 29, 2018
1 parent 04e779a commit b202d60
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion python/core/auto_generated/qgsvectorlayer.sip.in
Expand Up @@ -1679,7 +1679,7 @@ Deletes an attribute field (but does not commit it).
changes can be discarded by calling rollBack().
%End

bool deleteAttributes( QList<int> attrs );
bool deleteAttributes( const QList<int> &attrs );
%Docstring
Deletes a list of attribute fields (but does not commit it)

Expand Down Expand Up @@ -2559,6 +2559,8 @@ Sets the extent
};




/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2677,16 +2677,16 @@ bool QgsVectorLayer::deleteAttribute( int index )
return mEditBuffer->deleteAttribute( index );
}

bool QgsVectorLayer::deleteAttributes( QList<int> attrs )
bool QgsVectorLayer::deleteAttributes( const QList<int> &attrs )
{
bool deleted = false;

// Remove multiple occurrences of same attribute
attrs = attrs.toSet().toList();
QList<int> attrList = attrs.toSet().toList();

std::sort( attrs.begin(), attrs.end(), std::greater<int>() );
std::sort( attrList.begin(), attrList.end(), std::greater<int>() );

Q_FOREACH ( int attr, attrs )
for ( int attr : qgis::as_const( attrList ) )
{
if ( deleteAttribute( attr ) )
{
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -1546,7 +1546,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \returns true if at least one attribute has been deleted
*
*/
bool deleteAttributes( QList<int> attrs );
bool deleteAttributes( const QList<int> &attrs );

bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override;

Expand Down Expand Up @@ -2457,6 +2457,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
friend class QgsVectorLayerFeatureSource;
};



// clazy:excludeall=qstring-allocations

#endif

0 comments on commit b202d60

Please sign in to comment.