102 for ( QgsAttributeMap::const_iterator it = map.
begin(); it != map.
end(); ++it )
103 attrs[it.key()] = it.
value();
218 for (
int idx = 0; idx < updatedFields.
count(); ++idx )
220 if ( updatedFields[idx].
name() == field.
name() )
258 commitErrors.
clear();
268 bool attributesChanged =
false;
278 attributesChanged =
true;
284 QString list =
"ERROR: Pending attribute deletes:";
289 commitErrors << list;
302 commitErrors <<
tr(
"SUCCESS: %n attribute(s) added.",
"added attributes count",
mAddedAttributes.
size() );
307 attributesChanged =
true;
311 commitErrors <<
tr(
"ERROR: %n new attribute(s) not added",
"not added attributes count",
mAddedAttributes.
size() );
313 QString list =
"ERROR: Pending adds:";
318 commitErrors << list;
327 bool attributeChangesOk =
true;
328 if ( attributesChanged )
335 commitErrors <<
tr(
"ERROR: the count of fields is incorrect after addition/removal of fields!" );
336 attributeChangesOk =
false;
339 for (
int i = 0; i < qMin( oldFields.
count(), newFields.
count() ); ++i )
341 const QgsField& oldField = oldFields[i];
342 const QgsField& newField = newFields[i];
343 if ( attributeChangesOk && oldField != newField )
346 <<
tr(
"ERROR: field with index %1 is not the same!" ).
arg( i )
349 <<
QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
350 .
arg(
tr(
"expected field" ) )
356 <<
QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
357 .
arg(
tr(
"retrieved field" ) )
363 attributeChangesOk =
false;
368 if ( attributeChangesOk )
385 commitErrors <<
tr(
"ERROR: %n attribute value change(s) not applied.",
"not changed attribute values count",
mChangedAttributeValues.
size() );
387 QString list =
"ERROR: pending changes:";
397 commitErrors << list;
426 QString list =
"ERROR: pending deletes:";
431 commitErrors << list;
452 commitErrors <<
tr(
"SUCCESS: %n feature(s) added.",
"added features count", featuresToAdd.
size() );
457 for (
int i = 0; i < featuresToAdd.
count(); ++i )
459 if ( featuresToAdd[i].
id() != ids[i] )
462 if (
L->mSelectedFeatureIds.
contains( ids[i] ) )
464 L->mSelectedFeatureIds.
remove( ids[i] );
465 L->mSelectedFeatureIds.
insert( featuresToAdd[i].
id() );
476 commitErrors <<
tr(
"ERROR: %n feature(s) not added.",
"not added features count",
mAddedFeatures.
size() );
478 QString list =
"ERROR: pending adds:";
488 commitErrors << list;
495 commitErrors <<
tr(
"ERROR: %n feature(s) not added - provider doesn't support adding features.",
"not added features count",
mAddedFeatures.
size() );
512 commitErrors <<
tr(
"SUCCESS: %n geometries were changed.",
"changed geometries count",
mChangedGeometries.
size() );
520 commitErrors <<
tr(
"ERROR: %n geometries not changed.",
"not changed geometries count",
mChangedGeometries.
size() );
527 commitErrors <<
tr(
"\n Provider errors:" );
530 commitErrors <<
" " + e.
replace(
"\n",
"\n " );
556 QString QgsVectorLayerEditBuffer::dumpEditBuffer()
561 msg +=
"CHANGED GEOMETRIES:\n";
565 msg +=
QString(
"- FID %1: %2" ).
arg( it.key() ).arg( it.value().to );
586 featureIt->setAttributes( attrs );
610 featureIt->setAttributes( attrs );
619 for ( QgsAttributeMap::const_iterator it = map.
begin(); it != map.
end(); ++it )
621 int attrIndex = it.
key();
622 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.
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)
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
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
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.
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values 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.
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.
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
virtual bool changeGeometryValues(QgsGeometryMap &geometry_map)
Changes geometries of existing features.
bool contains(const T &value) const
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)
const QString & typeName() const
Gets the field type.
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.
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.
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.
int remove(const Key &key)
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.