25 template <
class Key, 
class T> 
void mapToReversedLists( 
const QMap< Key, T > &map, QList<Key> &ks, QList<T> &vs )
    27   ks.reserve( map.size() );
    28   vs.reserve( map.size() );
    29   typename QMap<Key, T>::const_iterator i = map.constEnd();
    30   while ( i-- != map.constBegin() )
    33     vs.append( i.value() );
    52   QgsDebugMsgLevel( QStringLiteral( 
"undo index changed %1" ).arg( index ), 4 );
    70     fields.
rename( renameIt.key(), renameIt.value() );
   105     for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it )
   106       attrs[it.key()] = it.value();
   137   for ( QgsFeatureList::iterator iter = features.begin(); iter != features.end(); ++iter )
   152     QgsDebugMsg( QStringLiteral( 
"Cannot delete features (missing DeleteFeature capability)" ) );
   160       QgsDebugMsg( QStringLiteral( 
"Cannot delete features (in the list of added features)" ) );
   168       QgsDebugMsg( QStringLiteral( 
"Cannot delete features (in the list of deleted features)" ) );
   181     QgsDebugMsg( QStringLiteral( 
"Cannot delete features (missing DeleteFeatures capability)" ) );
   217   for ( 
auto it = newValues.constBegin() ; it != newValues.constEnd(); ++it )
   219     const int field = it.key();
   220     const QVariant newValue = it.value();
   223     if ( oldValues.contains( field ) )
   224       oldValue = oldValues[field];
   259   if ( field.
name().isEmpty() )
   263   for ( 
const QgsField &updatedField : fields )
   265     if ( updatedField.name() == field.
name() )
   304   if ( newName.isEmpty() )
   311   for ( 
const QgsField &updatedField : fields )
   313     if ( updatedField.name() == newName )
   325   commitErrors.clear();
   347           if ( ( ! f.hasGeometry() ) ||
   348                ( f.geometry().wkbType() == provider->
wkbType() ) )
   353             commitErrors << tr( 
"ERROR: %n feature(s) not added - geometry type is not compatible with the current layer.", 
"not added features count", 
mAddedFeatures.size() );
   362       commitErrors << tr( 
"ERROR: %n feature(s) not added - provider doesn't support adding features.", 
"not added features count", 
mAddedFeatures.size() );
   374       commitErrors << tr( 
"SUCCESS: %n geometries were changed.", 
"changed geometries count", 
mChangedGeometries.size() );
   381       commitErrors << tr( 
"ERROR: %n geometries not changed.", 
"not changed geometries count", 
mChangedGeometries.size() );
   391   bool attributesChanged = 
false;
   396       commitErrors << tr( 
"SUCCESS: %n attribute(s) deleted.", 
"deleted attributes count", 
mDeletedAttributeIds.size() );
   401       attributesChanged = 
true;
   405       commitErrors << tr( 
"ERROR: %n attribute(s) not deleted.", 
"not deleted attributes count", 
mDeletedAttributeIds.size() );
   407       QString list = 
"ERROR: Pending attribute deletes:";
   412       commitErrors << list;
   423       commitErrors << tr( 
"SUCCESS: %n attribute(s) renamed.", 
"renamed attributes count", 
mRenamedAttributes.size() );
   428       attributesChanged = 
true;
   432       commitErrors << tr( 
"ERROR: %n attribute(s) not renamed", 
"not renamed attributes count", 
mRenamedAttributes.size() );
   444       commitErrors << tr( 
"SUCCESS: %n attribute(s) added.", 
"added attributes count", 
mAddedAttributes.size() );
   449       attributesChanged = 
true;
   453       commitErrors << tr( 
"ERROR: %n new attribute(s) not added", 
"not added attributes count", 
mAddedAttributes.size() );
   455       QString list = 
"ERROR: Pending adds:";
   458         list.append( 
' ' + f.
name() );
   460       commitErrors << list;
   469   bool attributeChangesOk = 
true;
   470   if ( attributesChanged )
   477       commitErrors << tr( 
"ERROR: the count of fields is incorrect after addition/removal of fields!" );
   478       attributeChangesOk = 
false;   
   481     for ( 
int i = 0; i < std::min( oldFields.
count(), newFields.
count() ); ++i )
   485       if ( attributeChangesOk && oldField != newField )
   488             << tr( 
"ERROR: field with index %1 is not the same!" ).arg( i )
   491             << QStringLiteral( 
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
   492             .arg( tr( 
"expected field" ),
   494                   QVariant::typeToName( oldField.
type() ),
   498             << QStringLiteral( 
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
   499             .arg( tr( 
"retrieved field" ),
   501                   QVariant::typeToName( newField.
type() ),
   505         attributeChangesOk = 
false;   
   510   if ( attributeChangesOk )
   539           commitErrors << tr( 
"SUCCESS: %n attribute value(s) changed.", 
"changed attribute values count", 
mChangedAttributeValues.size() );
   546           commitErrors << tr( 
"ERROR: %n attribute value change(s) not applied.", 
"not changed attribute values count", 
mChangedAttributeValues.size() );
   548           QString list = 
"ERROR: pending changes:";
   558           commitErrors << list;
   572         commitErrors << tr( 
"SUCCESS: %n feature(s) deleted.", 
"deleted features count", 
mDeletedFeatureIds.size() );
   586         commitErrors << tr( 
"ERROR: %n feature(s) not deleted.", 
"not deleted features count", 
mDeletedFeatureIds.size() );
   588         QString list = 
"ERROR: pending deletes:";
   593         commitErrors << list;
   606         QList<QgsFeatureId> ids;
   614         for ( 
int i = 0; i < featuresToAdd.count(); ++i )
   621           commitErrors << tr( 
"SUCCESS: %n feature(s) added.", 
"added features count", featuresToAdd.size() );
   626           for ( 
int i = 0; i < featuresToAdd.count(); ++i )
   628             if ( featuresToAdd[i].
id() != ids[i] )
   631               if ( 
L->mSelectedFeatureIds.contains( ids[i] ) )
   633                 L->mSelectedFeatureIds.remove( ids[i] );
   634                 L->mSelectedFeatureIds.insert( featuresToAdd[i].
id() );
   645           commitErrors << tr( 
"ERROR: %n feature(s) not added.", 
"not added features count", 
mAddedFeatures.size() );
   647           QString list = 
"ERROR: pending adds:";
   657           commitErrors << list;
   664         commitErrors << tr( 
"ERROR: %n feature(s) not added - provider doesn't support adding features.", 
"not added features count", 
mAddedFeatures.size() );
   676     commitErrors << tr( 
"\n  Provider errors:" );
   677     Q_FOREACH ( QString e, provider->
errors() )
   679       commitErrors << 
"    " + e.replace( 
'\n', QLatin1String( 
"\n    " ) );
   705 QString QgsVectorLayerEditBuffer::dumpEditBuffer()
   710     msg += 
"CHANGED GEOMETRIES:\n";
   714       msg += QString( 
"- FID %1: %2" ).arg( it.key() ).arg( it.value().to );
   735     attrs.insert( index, QVariant() );
   736     featureIt->setAttributes( attrs );
   742   std::sort( sortedRenamedIndices.begin(), sortedRenamedIndices.end(), std::greater< int >() );
   743   Q_FOREACH ( 
int renameIndex, sortedRenamedIndices )
   745     if ( renameIndex >= index )
   762     if ( attrMap.contains( index ) )
   763       attrMap.remove( index );
   774     attrs.remove( index );
   775     featureIt->setAttributes( attrs );
   781   std::sort( sortedRenamedIndices.begin(), sortedRenamedIndices.end() );
   784   Q_FOREACH ( 
int renameIndex, sortedRenamedIndices )
   786     if ( renameIndex > index )
   802   for ( QgsAttributeMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
   804     int attrIndex = it.key();
   805     updatedMap.insert( attrIndex < index ? attrIndex : attrIndex + offset, it.value() );
 void updateFields()
Will regenerate the fields property of this layer by obtaining all fields from the dataProvider...
 
void updateChangedAttributes(QgsFeature &f)
Update feature with uncommitted attribute updates. 
 
void handleAttributeDeleted(int index)
Update added and changed features after removal of an attribute. 
 
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
 
QSet< QgsFeatureId > QgsFeatureIds
 
virtual bool renameAttribute(int attr, const QString &newName)
Renames an attribute field (but does not commit it) 
 
virtual bool addAttribute(const QgsField &field)
Add an attribute field (but does not commit it) returns true if the field was added. 
 
QgsWkbTypes::Type wkbType() const override=0
Returns the geometry type which is returned by this layer. 
 
void undoIndexChanged(int index)
 
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Signals emitted after committing changes. 
 
void mapToReversedLists(const QMap< Key, T > &map, QList< Key > &ks, QList< T > &vs)
populate two lists (ks, vs) from map - in reverse order 
 
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes to the provider. 
 
virtual bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it) 
 
virtual bool addFeature(QgsFeature &f)
Adds a feature. 
 
Field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
 
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
 
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=nullptr) override
Adds a list of features to the sink. 
 
QList< QgsFeature > QgsFeatureList
 
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features from the provider. 
 
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes. 
 
friend class QgsVectorLayerUndoCommandChangeGeometry
 
Container of fields for a vector layer. 
 
virtual void rollBack()
Stop editing and discard the edits. 
 
A geometry is the spatial representation of a feature. 
 
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes. 
 
friend class QgsVectorLayerUndoCommandAddAttribute
 
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not committed. 
 
void updateFeatureGeometry(QgsFeature &f)
Update feature with uncommitted geometry updates. 
 
Allows deletion of attributes (fields) 
 
Field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
 
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
 
QgsFieldNameMap mRenamedAttributes
Renamed attributes which are not committed. 
 
bool rename(int fieldIdx, const QString &name)
Renames a name of field. 
 
friend class QgsVectorLayerUndoCommandRenameAttribute
 
QgsField at(int i) const 
Gets field at particular index (must be in range 0..N-1) 
 
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
 
friend class QgsVectorLayerUndoCommandDeleteAttribute
 
QgsGeometry convertToProviderType(const QgsGeometry &geom) const 
Converts the geometry to the provider type if possible / necessary. 
 
void featureAdded(QgsFeatureId fid)
 
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
 
virtual void updateExtents(bool force=false)
Update the extents for the layer. 
 
bool supportedType(const QgsField &field) const 
check if provider supports type of field 
 
QString typeName() const 
Gets the field type. 
 
QgsFields fields() const FINAL
Returns the list of fields of this layer. 
 
static void matchAttributesToFields(QgsFeature &feature, const QgsFields &fields)
Matches the attributes in feature to the specified fields. 
 
Allows addition of new attributes (fields) 
 
#define QgsDebugMsgLevel(str, level)
 
QgsFields fields() const override=0
Returns the fields associated with this data provider. 
 
friend class QgsVectorLayerUndoCommandAddFeature
 
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features. 
 
virtual bool changeFeatures(const QgsChangedAttributesMap &attr_map, const QgsGeometryMap &geometry_map)
Changes attribute values and geometries of existing features. 
 
int fieldOriginIndex(int fieldIdx) const 
Gets field's origin index (its meaning is specific to each type of origin) 
 
QMap< int, QVariant > QgsAttributeMap
 
QgsGeometryMap mChangedGeometries
Changed geometries which are not committed. 
 
bool hasErrors() const 
Provider has errors to report. 
 
virtual bool changeGeometry(QgsFeatureId fid, const QgsGeometry &geom)
Change feature's geometry. 
 
void handleAttributeAdded(int index)
Update added and changed features after addition of an attribute. 
 
Allows modifications of geometries. 
 
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
 
QString id() const 
Returns the layer's unique ID, which is used to access this layer from QgsProject. 
 
virtual bool deleteFeatures(const QgsFeatureIds &fid)
Deletes a set of features from the layer (but does not commit it) 
 
void clearErrors()
Clear recorded errors. 
 
int count() const 
Returns number of items. 
 
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not committed. 
 
Encapsulate a field in an attribute table or data source. 
 
virtual bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues)
Changes values of attributes (but does not commit it). 
 
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features. 
 
void remove(int fieldIdx)
Removes a field with the given index. 
 
virtual bool commitChanges(QStringList &commitErrors)
Attempts to commit any changes to disk. 
 
virtual bool deleteAttribute(int attr)
Delete an attribute field (but does not commit it) 
 
friend class QgsVectorLayerUndoCommandDeleteFeature
 
QgsVectorLayerEditBuffer()=default
Constructor for QgsVectorLayerEditBuffer. 
 
QString providerType() const 
Returns the provider type for this layer. 
 
QList< QgsField > mAddedAttributes
Added attributes fields which are not committed. 
 
#define FID_TO_STRING(fid)
 
virtual QgsVectorDataProvider::Capabilities capabilities() const 
Returns flags containing the supported capabilities. 
 
virtual bool doesStrictFeatureTypeCheck() const 
Returns true if the provider is strict about the type of inserted features (e.g. 
 
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
 
void committedAttributesRenamed(const QString &layerId, const QgsFieldNameMap &renamedAttributes)
Emitted after committing an attribute rename. 
 
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry. 
 
int size() const 
Returns number of items. 
 
FieldOrigin fieldOrigin(int fieldIdx) const 
Gets field's origin (value from an enumeration) 
 
QStringList errors() const 
Gets recorded errors. 
 
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes from the provider. 
 
virtual bool deleteFeature(QgsFeatureId fid)
Delete a feature from the layer (but does not commit it) 
 
virtual bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
Changed an attribute value (but does not commit it) 
 
Allows deletion of features. 
 
QUndoStack * undoStack()
Returns pointer to layer's undo stack. 
 
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
 
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider. 
 
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
 
This is the base class for vector data providers. 
 
QgsFeatureMap mAddedFeatures
New features which are not committed. 
 
void updateFields(QgsFields &fields)
 
void layerModified()
This signal is emitted when modifications has been done on layer. 
 
Represents a vector layer which manages a vector based data sets. 
 
virtual bool isModified() const 
Returns true if the provider has been modified since the last commit. 
 
Field is calculated from an expression. 
 
QgsAttributeList mDeletedAttributeIds
Deleted attributes fields which are not committed. The list is kept sorted. 
 
Allows modification of attribute values. 
 
void updateAttributeMapIndex(QgsAttributeMap &attrs, int index, int offset) const 
Updates an index in an attribute map to a new value (for updates of changed attributes) ...
 
void featureDeleted(QgsFeatureId fid)
 
Supports joint updates for attributes and geometry Providers supporting this should still define Chan...
 
friend class QgsVectorLayerUndoCommandChangeAttribute
 
QString storageType() const 
Returns the permanent storage type for this layer as a friendly name.