102 for ( QgsAttributeMap::const_iterator it = map.
begin(); it != map.
end(); ++it )
103 attrs[it.key()] = it.
value();
229 for (
int idx = 0; idx < updatedFields.
count(); ++idx )
231 if ( updatedFields[idx].
name() == field.
name() )
269 commitErrors.
clear();
286 commitErrors <<
tr(
"SUCCESS: %n geometries were changed.",
"changed geometries count",
mChangedGeometries.
size() );
293 commitErrors <<
tr(
"ERROR: %n geometries not changed.",
"not changed geometries count",
mChangedGeometries.
size() );
303 bool attributesChanged =
false;
313 attributesChanged =
true;
319 QString list =
"ERROR: Pending attribute deletes:";
324 commitErrors << list;
337 commitErrors <<
tr(
"SUCCESS: %n attribute(s) added.",
"added attributes count",
mAddedAttributes.
size() );
342 attributesChanged =
true;
346 commitErrors <<
tr(
"ERROR: %n new attribute(s) not added",
"not added attributes count",
mAddedAttributes.
size() );
348 QString list =
"ERROR: Pending adds:";
353 commitErrors << list;
362 bool attributeChangesOk =
true;
363 if ( attributesChanged )
370 commitErrors <<
tr(
"ERROR: the count of fields is incorrect after addition/removal of fields!" );
371 attributeChangesOk =
false;
374 for (
int i = 0; i < qMin( oldFields.
count(), newFields.
count() ); ++i )
378 if ( attributeChangesOk && oldField != newField )
381 <<
tr(
"ERROR: field with index %1 is not the same!" ).
arg( i )
384 <<
QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
385 .
arg(
tr(
"expected field" ),
391 <<
QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
392 .
arg(
tr(
"retrieved field" ),
398 attributeChangesOk =
false;
403 if ( attributeChangesOk )
439 commitErrors <<
tr(
"ERROR: %n attribute value change(s) not applied.",
"not changed attribute values count",
mChangedAttributeValues.
size() );
441 QString list =
"ERROR: pending changes:";
451 commitErrors << list;
481 QString list =
"ERROR: pending deletes:";
486 commitErrors << list;
507 commitErrors <<
tr(
"SUCCESS: %n feature(s) added.",
"added features count", featuresToAdd.
size() );
512 for (
int i = 0; i < featuresToAdd.
count(); ++i )
514 if ( featuresToAdd[i].
id() != ids[i] )
517 if (
L->mSelectedFeatureIds.
contains( ids[i] ) )
519 L->mSelectedFeatureIds.
remove( ids[i] );
520 L->mSelectedFeatureIds.
insert( featuresToAdd[i].
id() );
531 commitErrors <<
tr(
"ERROR: %n feature(s) not added.",
"not added features count",
mAddedFeatures.
size() );
533 QString list =
"ERROR: pending adds:";
543 commitErrors << list;
550 commitErrors <<
tr(
"ERROR: %n feature(s) not added - provider doesn't support adding features.",
"not added features count",
mAddedFeatures.
size() );
562 commitErrors <<
tr(
"\n Provider errors:" );
565 commitErrors <<
" " + e.
replace(
'\n',
"\n " );
591 QString QgsVectorLayerEditBuffer::dumpEditBuffer()
596 msg +=
"CHANGED GEOMETRIES:\n";
600 msg +=
QString(
"- FID %1: %2" ).
arg( it.key() ).arg( it.value().to );
622 featureIt->setAttributes( attrs );
647 featureIt->setAttributes( attrs );
656 for ( QgsAttributeMap::const_iterator it = map.
begin(); it != map.
end(); ++it )
658 int attrIndex = it.
key();
659 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.
QString & append(QChar ch)
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...
virtual 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)
bool contains(const Key &key) const
QgsVectorLayerEditBuffer()
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.
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)
QgsFields fields() const
Returns the list of fields of this layer.
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features.
const_iterator constBegin() const
int precision() const
Gets the precision of the field.
void insert(int i, const T &value)
#define FID_TO_STRING(fid)
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.
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 ...
const_iterator insert(const T &value)
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.
QString tr(const char *sourceText, const char *disambiguation, int n)
friend class QgsVectorLayerUndoCommandDeleteAttribute
virtual void updateExtents()
Update the extents for the layer.
QList< Key > keys() const
void featureAdded(QgsFeatureId fid)
const char * name() const
QgsFields pendingFields() const
Returns the list of fields of this layer.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object.
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
int count(const T &value) const
void append(const T &value)
bool supportedType(const QgsField &field) const
check if provider supports type of field
QString typeName() const
Gets the field type.
Allows addition of new attributes (fields)
QgsAttributes attributes() const
Returns the feature's attributes.
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.
QString name() const
Gets the name of the field.
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.
const_iterator constEnd() const
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.
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.
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
Return number of items.
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not commited.
Encapsulate a field in an attribute table or data source.
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
void remove(int fieldIdx)
Remove 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
bool contains(const T &value) const
Supports joint updates for attributes and geometry Providers supporting this should still define Chan...
bool contains(const T &value) const
const char * typeToName(Type typ)
const Key key(const T &value) const
QString providerType() const
Return the provider type for this layer.
QString & replace(int position, int n, QChar after)
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()
bool remove(const T &value)
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
int length() const
Gets the length of the field.
int count(const T &value) const
int size() const
Return number of items.
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes.
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.
iterator insert(const Key &key, const T &value)
QUndoStack * undoStack()
Return pointer to layer's undo stack.
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.
QgsFeatureMap mAddedFeatures
New features which are not commited.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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) ...
virtual bool changeGeometry(QgsFeatureId fid, QgsGeometry *geom)
Change feature's geometry.
void featureDeleted(QgsFeatureId fid)
void push(QUndoCommand *cmd)
friend class QgsVectorLayerUndoCommandChangeAttribute
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
const T value(const Key &key) const
int remove(const Key &key)
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.