Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #4594 from boundlessgeo/postgis_merge_features_fix…
Browse files Browse the repository at this point in the history
…#15741

Fix Postgis Merge selected features regression (fix #15741)
  • Loading branch information
alexbruy committed Jun 12, 2017
2 parents e5b2843 + 53d90b5 commit 57e122b
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -52,6 +52,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
Q_OBJECT

friend class QgsTransaction;
friend class QgsVectorLayerEditBuffer;

public:

Expand Down
29 changes: 29 additions & 0 deletions src/core/qgsvectorlayereditbuffer.cpp
Expand Up @@ -302,6 +302,35 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList& commitErrors )
// no yes => changeAttributeValues
// yes yes => changeFeatures

// to fix https://issues.qgis.org/issues/15741
// first of all check if feature to add is compatible with provider type
// this check have to be done before all checks to avoid to clear internal
// buffer if some of next steps success.
if ( success && !mAddedFeatures.isEmpty() )
{
if ( cap & QgsVectorDataProvider::AddFeatures )
{
for ( QgsFeature f : mAddedFeatures )
{
if (( ! f.geometry() ) || ( f.geometry()->isEmpty() ) ||
( f.geometry()->wkbType() == provider->geometryType() ) )
continue;

if ( ! provider->convertToProviderType( f.geometry() ) )
{
commitErrors << tr( "ERROR: %n feature(s) not added - geometry type is not compatible with the current layer.", "not added features count", mAddedFeatures.size() );
success = false;
break;
}
}
}
else
{
commitErrors << tr( "ERROR: %n feature(s) not added - provider doesn't support adding features.", "not added features count", mAddedFeatures.size() );
success = false;
}
}

//
// update geometries
//
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -106,6 +106,7 @@ ADD_PYTHON_TEST(PyQgsUnitTypes test_qgsunittypes.py)
ADD_PYTHON_TEST(PyQgsVectorColorRamp test_qgsvectorcolorramp.py)
ADD_PYTHON_TEST(PyQgsVectorFileWriter test_qgsvectorfilewriter.py)
ADD_PYTHON_TEST(PyQgsVectorLayer test_qgsvectorlayer.py)
ADD_PYTHON_TEST(PyQgsVectorLayerEditBuffer test_qgsvectorlayereditbuffer.py)
ADD_PYTHON_TEST(PyQgsZonalStatistics test_qgszonalstatistics.py)
ADD_PYTHON_TEST(PyQgsMapLayerRegistry test_qgsmaplayerregistry.py)
ADD_PYTHON_TEST(PyQgsVirtualLayerProvider test_provider_virtual.py)
Expand Down

0 comments on commit 57e122b

Please sign in to comment.