Some minor changes

- QgsVectorLayer *
- make a const copy of a const container
- typo and comments
This commit is contained in:
Alessandro Pasotti 2018-09-24 16:17:52 +02:00
parent fb47dd930d
commit a8dbb5395c
3 changed files with 18 additions and 15 deletions

View File

@ -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
@ -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

View File

@ -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 !=
@ -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 );
}
@ -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 );
}
}
@ -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 );
}

View File

@ -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
@ -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
@ -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 );
};