Skip to content

Commit

Permalink
fix Postgis Merge selected features regression: port 2.18 fixes #15741
Browse files Browse the repository at this point in the history
  • Loading branch information
luipir committed Jun 12, 2017
1 parent 9626d2f commit 53d90b5
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 53d90b5

Please sign in to comment.