Skip to content

Commit

Permalink
Some minor changes
Browse files Browse the repository at this point in the history
- QgsVectorLayer *
- make a const copy of a const container
- typo and comments
  • Loading branch information
elpaso committed Sep 25, 2018
1 parent fb47dd9 commit a8dbb53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
9 changes: 5 additions & 4 deletions python/core/auto_generated/qgsvectorlayerutils.sip.in
Expand Up @@ -177,12 +177,13 @@ are padded with NULL values to match the required length).
.. versionadded:: 3.4
%End

static const QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer &layer );
static const QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer *layer );
%Docstring
Converts input ``feature`` to be compatible with the given ``layer``.

This function returns a new list of transformed features compatible with the input
layer, note that the number of features returned might be greater than one.
layer, note that the number of features returned might be greater than one when
converting a multi part geometry to single part

The following operations will be performed to convert the input features:
- convert single geometries to multi part
Expand All @@ -196,13 +197,13 @@ The following operations will be performed to convert the input features:
.. versionadded:: 3.4
%End

static const QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer &layer );
static const QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer *layer );
%Docstring
Converts input ``features`` to be compatible with the given ``layer``.

This function returns a new list of transformed features compatible with the input
layer, note that the number of features returned might be greater than the number
of input featurers.
of input features.

The following operations will be performed to convert the input features:
- convert single geometries to multi part
Expand Down
15 changes: 8 additions & 7 deletions src/core/qgsvectorlayerutils.cpp
Expand Up @@ -561,13 +561,13 @@ void QgsVectorLayerUtils::matchAttributesToFields( QgsFeature &feature, const Qg
}
}

const QgsFeatureList QgsVectorLayerUtils::makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer &layer )
const QgsFeatureList QgsVectorLayerUtils::makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer *layer )
{
QgsWkbTypes::Type inputWkbType( layer.wkbType( ) );
QgsWkbTypes::Type inputWkbType( layer->wkbType( ) );
QgsFeatureList resultFeatures;
QgsFeature newF( feature );
// Fix attributes
QgsVectorLayerUtils::matchAttributesToFields( newF, layer.fields( ) );
QgsVectorLayerUtils::matchAttributesToFields( newF, layer->fields( ) );
// Does geometry need transformations?
QgsWkbTypes::GeometryType newFGeomType( QgsWkbTypes::geometryType( newF.geometry().wkbType() ) );
bool newFHasGeom = newFGeomType !=
Expand All @@ -579,7 +579,7 @@ const QgsFeatureList QgsVectorLayerUtils::makeFeatureCompatible( const QgsFeatur
// Drop geometry if layer is geometry-less
if ( newFHasGeom && ! layerHasGeom )
{
QgsFeature _f = QgsFeature( layer.fields() );
QgsFeature _f = QgsFeature( layer->fields() );
_f.setAttributes( newF.attributes() );
resultFeatures.append( _f );
}
Expand Down Expand Up @@ -634,7 +634,7 @@ const QgsFeatureList QgsVectorLayerUtils::makeFeatureCompatible( const QgsFeatur
for ( int i = 0; i < parts->partCount( ); i++ )
{
QgsGeometry g( parts->geometryN( i )->clone() );
QgsFeature _f( createFeature( &layer, g, attrMap ) );
QgsFeature _f( createFeature( layer, g, attrMap ) );
resultFeatures.append( _f );
}
}
Expand All @@ -651,12 +651,13 @@ const QgsFeatureList QgsVectorLayerUtils::makeFeatureCompatible( const QgsFeatur
return resultFeatures;
}

const QgsFeatureList QgsVectorLayerUtils::makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer &layer )
const QgsFeatureList QgsVectorLayerUtils::makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer *layer )
{
QgsFeatureList resultFeatures;
for ( const QgsFeature &f : features )
{
for ( const auto &_f : makeFeatureCompatible( f, layer ) )
const QgsFeatureList features( makeFeatureCompatible( f, layer ) );
for ( const auto &_f : features )
{
resultFeatures.append( _f );
}
Expand Down
9 changes: 5 additions & 4 deletions src/core/qgsvectorlayerutils.h
Expand Up @@ -192,7 +192,8 @@ class CORE_EXPORT QgsVectorLayerUtils
* Converts input \a feature to be compatible with the given \a layer.
*
* This function returns a new list of transformed features compatible with the input
* layer, note that the number of features returned might be greater than one.
* layer, note that the number of features returned might be greater than one when
* converting a multi part geometry to single part
*
* The following operations will be performed to convert the input features:
* - convert single geometries to multi part
Expand All @@ -205,14 +206,14 @@ class CORE_EXPORT QgsVectorLayerUtils
*
* \since QGIS 3.4
*/
static const QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer &layer );
static const QgsFeatureList makeFeatureCompatible( const QgsFeature &feature, const QgsVectorLayer *layer );

/**
* Converts input \a features to be compatible with the given \a layer.
*
* This function returns a new list of transformed features compatible with the input
* layer, note that the number of features returned might be greater than the number
* of input featurers.
* of input features.
*
* The following operations will be performed to convert the input features:
* - convert single geometries to multi part
Expand All @@ -225,7 +226,7 @@ class CORE_EXPORT QgsVectorLayerUtils
*
* \since QGIS 3.4
*/
static const QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer &layer );
static const QgsFeatureList makeFeaturesCompatible( const QgsFeatureList &features, const QgsVectorLayer *layer );

};

Expand Down

0 comments on commit a8dbb53

Please sign in to comment.