mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-04 00:30:59 -05:00
Fix errors when saving features with virtual fields present
Fixes #18784
This commit is contained in:
parent
9fcd4fd00c
commit
cc53af296c
@ -19,6 +19,7 @@
|
||||
#include "qgsvectorlayerundocommand.h"
|
||||
#include "qgsvectordataprovider.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectorlayerutils.h"
|
||||
|
||||
//! populate two lists (ks, vs) from map - in reverse order
|
||||
template <class Key, class T> void mapToReversedLists( const QMap< Key, T > &map, QList<Key> &ks, QList<T> &vs )
|
||||
@ -606,6 +607,13 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
|
||||
// this will preserve the order how they have been added e.g. (-1, -2, -3) while in the map they are ordered (-3, -2, -1)
|
||||
mapToReversedLists( mAddedFeatures, ids, featuresToAdd );
|
||||
|
||||
// we need to strip any extra attributes here -- e.g. virtual fields, which should
|
||||
// not be sent to the data provider. Refs #18784
|
||||
for ( int i = 0; i < featuresToAdd.count(); ++i )
|
||||
{
|
||||
QgsVectorLayerUtils::matchAttributesToFields( featuresToAdd[i], provider->fields() );
|
||||
}
|
||||
|
||||
if ( provider->addFeatures( featuresToAdd ) )
|
||||
{
|
||||
commitErrors << tr( "SUCCESS: %n feature(s) added.", "added features count", featuresToAdd.size() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user