43 QgsDebugMsg( QString(
"undo index changed %1" ).arg( index ) );
88 for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it )
89 attrs[it.key()] = it.value();
117 for ( QgsFeatureList::iterator iter = features.begin(); iter != features.end(); ++iter )
197 if ( field.
name().isEmpty() )
201 for (
int idx = 0; idx < updatedFields.
count(); ++idx )
203 if ( updatedFields[idx].name() == field.
name() )
241 commitErrors.clear();
251 bool attributesChanged =
false;
256 commitErrors <<
tr(
"SUCCESS: %n attribute(s) deleted.",
"deleted attributes count",
mDeletedAttributeIds.size() );
261 attributesChanged =
true;
265 commitErrors <<
tr(
"ERROR: %n attribute(s) not deleted.",
"not deleted attributes count",
mDeletedAttributeIds.size() );
267 QString list =
"ERROR: Pending attribute deletes:";
272 commitErrors << list;
285 commitErrors <<
tr(
"SUCCESS: %n attribute(s) added.",
"added attributes count",
mAddedAttributes.size() );
290 attributesChanged =
true;
294 commitErrors <<
tr(
"ERROR: %n new attribute(s) not added",
"not added attributes count",
mAddedAttributes.size() );
296 QString list =
"ERROR: Pending adds:";
299 list.append(
" " + f.
name() );
301 commitErrors << list;
310 bool attributeChangesOk =
true;
311 if ( attributesChanged )
318 commitErrors <<
tr(
"ERROR: the count of fields is incorrect after addition/removal of fields!" );
319 attributeChangesOk =
false;
322 for (
int i = 0; i < qMin( oldFields.
count(), newFields.
count() ); ++i )
324 const QgsField& oldField = oldFields[i];
325 const QgsField& newField = newFields[i];
326 if ( attributeChangesOk && oldField != newField )
329 <<
tr(
"ERROR: field with index %1 is not the same!" ).arg( i )
332 << QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
333 .arg(
tr(
"expected field" ) )
334 .arg( oldField.
name() )
335 .arg( QVariant::typeToName( oldField.
type() ) )
339 << QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
340 .arg(
tr(
"retrieved field" ) )
341 .arg( newField.
name() )
342 .arg( QVariant::typeToName( newField.
type() ) )
346 attributeChangesOk =
false;
351 if ( attributeChangesOk )
360 commitErrors <<
tr(
"SUCCESS: %n attribute value(s) changed.",
"changed attribute values count",
mChangedAttributeValues.size() );
368 commitErrors <<
tr(
"ERROR: %n attribute value change(s) not applied.",
"not changed attribute values count",
mChangedAttributeValues.size() );
370 QString list =
"ERROR: pending changes:";
380 commitErrors << list;
393 commitErrors <<
tr(
"SUCCESS: %n feature(s) deleted.",
"deleted features count",
mDeletedFeatureIds.size() );
407 commitErrors <<
tr(
"ERROR: %n feature(s) not deleted.",
"not deleted features count",
mDeletedFeatureIds.size() );
409 QString list =
"ERROR: pending deletes:";
414 commitErrors << list;
432 commitErrors <<
tr(
"SUCCESS: %n feature(s) added.",
"added features count", featuresToAdd.size() );
437 for (
int i = 0; i < featuresToAdd.count(); ++i )
439 if ( featuresToAdd[i].
id() != ids[i] )
456 commitErrors <<
tr(
"ERROR: %n feature(s) not added.",
"not added features count",
mAddedFeatures.size() );
458 QString list =
"ERROR: pending adds:";
468 commitErrors << list;
475 commitErrors <<
tr(
"ERROR: %n feature(s) not added - provider doesn't support adding features.",
"not added features count",
mAddedFeatures.size() );
492 commitErrors <<
tr(
"SUCCESS: %n geometries were changed.",
"changed geometries count",
mChangedGeometries.size() );
500 commitErrors <<
tr(
"ERROR: %n geometries not changed.",
"not changed geometries count",
mChangedGeometries.size() );
507 commitErrors <<
tr(
"\n Provider errors:" );
508 foreach ( QString e, provider->
errors() )
510 commitErrors <<
" " + e.replace(
"\n",
"\n " );
536 QString QgsVectorLayerEditBuffer::dumpEditBuffer()
541 msg +=
"CHANGED GEOMETRIES:\n";
545 msg += QString(
"- FID %1: %2" ).arg( it.key() ).arg( it.value().to );
565 attrs.insert( index, QVariant() );
576 if ( attrMap.contains( index ) )
577 attrMap.remove( index );
588 attrs.remove( index );
597 for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it )
599 int attrIndex = it.key();
600 updatedMap.insert( attrIndex < index ? attrIndex : attrIndex + offset, it.value() );
QgsFeatureId id() const
Get the feature id for this feature.
void updateFields()
Assembles mUpdatedFields considering provider fields, joined fields and added fields.
void updateChangedAttributes(QgsFeature &f)
Update feature with uncommited attribute updates.
const QString & name() const
Gets the name of the field.
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...
bool addAttribute(const QgsField &field)
add an attribute field (but does not commit it) returns true if the field was added ...
void undoIndexChanged(int index)
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Signals emitted after committing changes.
QMap< int, QVariant > QgsAttributeMap
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes.
bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it)
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)
QList< QgsFeature > QgsFeatureList
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features.
int precision() const
Gets the precision of the field.
#define FID_TO_STRING(fid)
friend class QgsVectorLayerUndoCommandChangeGeometry
Container of fields for a vector layer.
void rollBack()
Stop editing and discard the edits.
QStringList errors()
Get recorded errors.
friend class QgsVectorLayerUndoCommandAddAttribute
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not commited.
void updateFeatureGeometry(QgsFeature &f)
Update feature with uncommited 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...
virtual bool addFeatures(QgsFeatureList &flist)
Adds a list of features.
friend class QgsVectorLayerUndoCommandDeleteAttribute
QgsVectorLayerEditBuffer(QgsVectorLayer *layer)
virtual void updateExtents()
Update the extents for the layer.
void featureAdded(QgsFeatureId fid)
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object (deep copy)
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
bool supportedType(const QgsField &field) const
check if provider supports type of field
allows addition of new attributes (fields)
friend class QgsVectorLayerUndoCommandAddFeature
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
bool hasErrors()
Provider has errors to report.
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
int fieldOriginIndex(int fieldIdx) const
Get field's origin index (its meaning is specific to each type of origin)
QgsGeometryMap mChangedGeometries
Changed geometries which are not commited.
void handleAttributeAdded(int index)
update added and changed features after addition of an attribute
const QgsAttributes & attributes() const
allows modifications of geometries
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
void clearErrors()
Clear recorded errors.
int count() const
Return number of items.
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not commited.
Encapsulate a field in an attribute table or data source.
void remove(int fieldIdx)
Remove a field with the given index.
bool commitChanges(QStringList &commitErrors)
Attempts to commit any changes to disk.
bool deleteAttribute(int attr)
delete an attribute field (but does not commit it)
friend class QgsVectorLayerUndoCommandDeleteFeature
virtual bool changeGeometryValues(QgsGeometryMap &geometry_map)
Changes geometries of existing features.
QString providerType() const
Return the provider type for this layer.
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QList< QgsField > mAddedAttributes
added attributes fields which are not commited
~QgsVectorLayerEditBuffer()
QVector< QVariant > QgsAttributes
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
const QString & typeName() const
Gets the field type.
int length() const
Gets the length of the field.
int size() const
Return number of items.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes.
bool deleteFeature(QgsFeatureId fid)
delete a feature from the layer (but does not commit it)
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()
Return pointer to layer's undo stack.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
QgsVectorDataProvider * dataProvider()
Returns the data provider.
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
This is the base class for vector data providers.
QgsFields mUpdatedFields
field map to commit
QgsFeatureMap mAddedFeatures
New features which are not commited.
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.
bool isModified() const
Returns true if the provider has been modified since the last commit.
QgsFeatureIds mSelectedFeatureIds
Set holding the feature IDs that are activated.
QgsAttributeList mDeletedAttributeIds
deleted attributes fields which are not commited.
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) ...
bool changeGeometry(QgsFeatureId fid, QgsGeometry *geom)
change feature's geometry
void featureDeleted(QgsFeatureId fid)
friend class QgsVectorLayerUndoCommandChangeAttribute
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.