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() );
57 QgsDebugMsg( QString(
"undo index changed %1" ).arg( index ) );
102 for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it )
103 attrs[it.key()] = it.value();
131 for ( QgsFeatureList::iterator iter = features.begin(); iter != features.end(); ++iter )
212 if ( field.
name().isEmpty() )
216 for (
int idx = 0; idx < updatedFields.
count(); ++idx )
218 if ( updatedFields[idx].name() == field.
name() )
256 commitErrors.clear();
268 commitErrors <<
tr(
"SUCCESS: %n geometries were changed.",
"changed geometries count",
mChangedGeometries.size() );
276 commitErrors <<
tr(
"ERROR: %n geometries not changed.",
"not changed geometries count",
mChangedGeometries.size() );
286 bool attributesChanged =
false;
291 commitErrors <<
tr(
"SUCCESS: %n attribute(s) deleted.",
"deleted attributes count",
mDeletedAttributeIds.size() );
296 attributesChanged =
true;
300 commitErrors <<
tr(
"ERROR: %n attribute(s) not deleted.",
"not deleted attributes count",
mDeletedAttributeIds.size() );
302 QString list =
"ERROR: Pending attribute deletes:";
307 commitErrors << list;
320 commitErrors <<
tr(
"SUCCESS: %n attribute(s) added.",
"added attributes count",
mAddedAttributes.size() );
325 attributesChanged =
true;
329 commitErrors <<
tr(
"ERROR: %n new attribute(s) not added",
"not added attributes count",
mAddedAttributes.size() );
331 QString list =
"ERROR: Pending adds:";
334 list.append(
" " + f.
name() );
336 commitErrors << list;
345 bool attributeChangesOk =
true;
346 if ( attributesChanged )
353 commitErrors <<
tr(
"ERROR: the count of fields is incorrect after addition/removal of fields!" );
354 attributeChangesOk =
false;
357 for (
int i = 0; i < qMin( oldFields.
count(), newFields.
count() ); ++i )
359 const QgsField& oldField = oldFields[i];
360 const QgsField& newField = newFields[i];
361 if ( attributeChangesOk && oldField != newField )
364 <<
tr(
"ERROR: field with index %1 is not the same!" ).arg( i )
367 << QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
368 .arg(
tr(
"expected field" ) )
369 .arg( oldField.
name() )
370 .arg( QVariant::typeToName( oldField.
type() ) )
374 << QString(
"%1: name=%2 type=%3 typeName=%4 len=%5 precision=%6" )
375 .arg(
tr(
"retrieved field" ) )
376 .arg( newField.
name() )
377 .arg( QVariant::typeToName( newField.
type() ) )
381 attributeChangesOk =
false;
386 if ( attributeChangesOk )
395 commitErrors <<
tr(
"SUCCESS: %n attribute value(s) changed.",
"changed attribute values count",
mChangedAttributeValues.size() );
403 commitErrors <<
tr(
"ERROR: %n attribute value change(s) not applied.",
"not changed attribute values count",
mChangedAttributeValues.size() );
405 QString list =
"ERROR: pending changes:";
415 commitErrors << list;
428 commitErrors <<
tr(
"SUCCESS: %n feature(s) deleted.",
"deleted features count",
mDeletedFeatureIds.size() );
442 commitErrors <<
tr(
"ERROR: %n feature(s) not deleted.",
"not deleted features count",
mDeletedFeatureIds.size() );
444 QString list =
"ERROR: pending deletes:";
449 commitErrors << list;
462 QList<QgsFeatureId> ids;
470 commitErrors <<
tr(
"SUCCESS: %n feature(s) added.",
"added features count", featuresToAdd.size() );
475 for (
int i = 0; i < featuresToAdd.count(); ++i )
477 if ( featuresToAdd[i].
id() != ids[i] )
480 if (
L->mSelectedFeatureIds.contains( ids[i] ) )
482 L->mSelectedFeatureIds.remove( ids[i] );
483 L->mSelectedFeatureIds.insert( featuresToAdd[i].
id() );
494 commitErrors <<
tr(
"ERROR: %n feature(s) not added.",
"not added features count",
mAddedFeatures.size() );
496 QString list =
"ERROR: pending adds:";
506 commitErrors << list;
513 commitErrors <<
tr(
"ERROR: %n feature(s) not added - provider doesn't support adding features.",
"not added features count",
mAddedFeatures.size() );
525 commitErrors <<
tr(
"\n Provider errors:" );
526 foreach ( QString e, provider->
errors() )
528 commitErrors <<
" " + e.replace(
"\n",
"\n " );
554 QString QgsVectorLayerEditBuffer::dumpEditBuffer()
559 msg +=
"CHANGED GEOMETRIES:\n";
563 msg += QString(
"- FID %1: %2" ).arg( it.key() ).arg( it.value().to );
583 attrs.insert( index, QVariant() );
594 if ( attrMap.contains( index ) )
595 attrMap.remove( index );
606 attrs.remove( index );
615 for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it )
617 int attrIndex = it.key();
618 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...
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)
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
QMap< int, QVariant > QgsAttributeMap
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)
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.
virtual 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
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.
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.
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()
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.
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
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.
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 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)
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.