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();
270 commitErrors <<
tr(
"SUCCESS: %n geometries were changed.",
"changed geometries count",
mChangedGeometries.
size() );
278 commitErrors <<
tr(
"ERROR: %n geometries not changed.",
"not changed geometries count",
mChangedGeometries.
size() );
288 bool attributesChanged =
false;
298 attributesChanged =
true;
304 QString list =
"ERROR: Pending attribute deletes:";
309 commitErrors << list;
322 commitErrors <<
tr(
"SUCCESS: %n attribute(s) added.",
"added attributes count",
mAddedAttributes.
size() );
327 attributesChanged =
true;
331 commitErrors <<
tr(
"ERROR: %n new attribute(s) not added",
"not added attributes count",
mAddedAttributes.
size() );
333 QString list =
"ERROR: Pending adds:";
338 commitErrors << list;
347 bool attributeChangesOk =
true;
348 if ( attributesChanged )
355 commitErrors <<
tr(
"ERROR: the count of fields is incorrect after addition/removal of fields!" );
356 attributeChangesOk =
false;
359 for (
int i = 0; i < qMin( oldFields.
count(), newFields.
count() ); ++i )
363 if ( attributeChangesOk && oldField != newField )
366 <<
tr(
"ERROR: field with index %1 is not the same!" ).
arg( i )
369 <<
QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
370 .
arg(
tr(
"expected field" ),
376 <<
QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
377 .
arg(
tr(
"retrieved field" ),
383 attributeChangesOk =
false;
388 if ( attributeChangesOk )
405 commitErrors <<
tr(
"ERROR: %n attribute value change(s) not applied.",
"not changed attribute values count",
mChangedAttributeValues.
size() );
407 QString list =
"ERROR: pending changes:";
417 commitErrors << list;
446 QString list =
"ERROR: pending deletes:";
451 commitErrors << list;
472 commitErrors <<
tr(
"SUCCESS: %n feature(s) added.",
"added features count", featuresToAdd.
size() );
477 for (
int i = 0; i < featuresToAdd.
count(); ++i )
479 if ( featuresToAdd[i].
id() != ids[i] )
482 if (
L->mSelectedFeatureIds.
contains( ids[i] ) )
484 L->mSelectedFeatureIds.
remove( ids[i] );
485 L->mSelectedFeatureIds.
insert( featuresToAdd[i].
id() );
496 commitErrors <<
tr(
"ERROR: %n feature(s) not added.",
"not added features count",
mAddedFeatures.
size() );
498 QString list =
"ERROR: pending adds:";
508 commitErrors << list;
515 commitErrors <<
tr(
"ERROR: %n feature(s) not added - provider doesn't support adding features.",
"not added features count",
mAddedFeatures.
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.
Allows modification of attribute values.
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...
Allows modifications of geometries.
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.
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
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.
Allows deletion of attributes (fields)
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.
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.
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.
Allows deletion of features.
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)
iterator insert(const Key &key, const T &value)
Allows addition of new attributes (fields)
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.
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.