diff --git a/python/core/qgsvectorlayer.sip b/python/core/qgsvectorlayer.sip index dd6ce23e7f3..0a603a55a42 100644 --- a/python/core/qgsvectorlayer.sip +++ b/python/core/qgsvectorlayer.sip @@ -244,13 +244,13 @@ existing rings, 5 no feature found where ring can be inserted*/ \todo Need to indicate at which stage the failed commit occurred, for better cleanup and recovery from the error. - \param deleted Set of attribute names (i.e. columns) to delete + \param deleted Set of attribute indices (i.e. columns) to delete \param added Map (name, type) of attribute names (i.e. columns) to add \param changed Map (feature ID, Map (attribute name, new value) ) of attribute values to change */ - bool commitAttributeChanges(const QSet& deleted, + bool commitAttributeChanges(const QSet& deleted, const QMap& added, const QMap >& changed); diff --git a/src/app/qgsattributetable.cpp b/src/app/qgsattributetable.cpp index 31813eee375..cadf849260d 100644 --- a/src/app/qgsattributetable.cpp +++ b/src/app/qgsattributetable.cpp @@ -412,10 +412,25 @@ bool QgsAttributeTable::commitChanges(QgsVectorLayer* layer) if(layer) { - isSuccessful = layer->commitAttributeChanges( - mDeletedAttributes, - mAddedAttributes, - mChangedValues); + //convert strings of deleted attributes to ids + + QgsVectorDataProvider* provider = layer->getDataProvider(); + + if(provider) + { + + QgsAttributeIds deletedIds; + QSet::const_iterator it = mDeletedAttributes.constBegin(); + + for(; it != mDeletedAttributes.constEnd(); ++it) + { + deletedIds.insert(provider->indexFromFieldName(*it)); + } + + isSuccessful = layer->commitAttributeChanges(deletedIds, + mAddedAttributes, + mChangedValues); + } } if (isSuccessful) diff --git a/src/app/qgsattributetable.h b/src/app/qgsattributetable.h index 200d9e3d6ac..a91acce4fd4 100644 --- a/src/app/qgsattributetable.h +++ b/src/app/qgsattributetable.h @@ -130,7 +130,7 @@ class QgsAttributeTable:public Q3Table and the value the attribute type*/ QgsNewAttributesMap mAddedAttributes; /**Set containing the attribute names of deleted attributes*/ - QgsDeletedAttributesSet mDeletedAttributes; + QSet mDeletedAttributes; /**Nested map containing the changed attribute values. The int is the feature id, the first QString the attribute name and the second QString the new value*/ QgsChangedAttributesMap mChangedValues; diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 0663bc95adc..36b5e9e145a 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -2878,73 +2878,56 @@ void QgsVectorLayer::setCoordinateSystem() } -bool QgsVectorLayer::commitAttributeChanges(const QgsDeletedAttributesSet& deleted, +bool QgsVectorLayer::commitAttributeChanges(const QgsAttributeIds& deleted, const QgsNewAttributesMap& added, const QgsChangedAttributesMap& changed) { bool returnvalue=true; - - if(mDataProvider) - { - - QgsAttributeIds attIds; - QgsDeletedAttributesSet::const_iterator att_it = deleted.constBegin(); - - for(; att_it != deleted.constEnd(); ++att_it) - { - attIds.insert(mDataProvider->indexFromFieldName(*att_it)); - } - - if(mDataProvider->capabilities()&QgsVectorDataProvider::DeleteAttributes) + if(mDataProvider->capabilities()&QgsVectorDataProvider::DeleteAttributes) { //delete attributes in all not commited features for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter) - { - for (QgsAttributeIds::const_iterator it = attIds.begin(); it != attIds.end(); ++it) - { - (*iter).deleteAttribute(*it); - } - } - + { + for (QgsAttributeIds::const_iterator it = deleted.begin(); it != deleted.end(); ++it) + { + (*iter).deleteAttribute(*it); + } + } + //and then in the provider - if(!mDataProvider->deleteAttributes(attIds)) - { - returnvalue=false; - } + if(!mDataProvider->deleteAttributes(deleted)) + { + returnvalue=false; + } } - - if(mDataProvider->capabilities()&QgsVectorDataProvider::AddAttributes) + + if(mDataProvider->capabilities()&QgsVectorDataProvider::AddAttributes) { //add attributes in all not commited features // TODO: is it necessary? [MD] /*for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter) - { + { for (QgsNewAttributesMap::const_iterator it = added.begin(); it != added.end(); ++it) { - (*iter).addAttribute(, QgsFeatureAttribute(it.key(), "")); + (*iter).addAttribute(, QgsFeatureAttribute(it.key(), "")); } - }*/ + }*/ //and then in the provider if(!mDataProvider->addAttributes(added)) - { - returnvalue=false; - } + { + returnvalue=false; + } } - - if(mDataProvider->capabilities()&QgsVectorDataProvider::ChangeAttributeValues) + + if(mDataProvider->capabilities()&QgsVectorDataProvider::ChangeAttributeValues) { //and then those of the commited ones if(!mDataProvider->changeAttributeValues(changed)) - { - returnvalue=false; - } + { + returnvalue=false; + } } - } - else - { - returnvalue=false; - } return returnvalue; } diff --git a/src/core/qgsvectorlayer.h b/src/core/qgsvectorlayer.h index b1647507362..61c9fd8e51b 100644 --- a/src/core/qgsvectorlayer.h +++ b/src/core/qgsvectorlayer.h @@ -56,8 +56,6 @@ typedef QSet QgsAttributeIds; // key = attribute name, value = attribute type typedef QMap QgsNewAttributesMap; -typedef QSet QgsDeletedAttributesSet; - typedef QMap QgsFieldMap; @@ -310,13 +308,13 @@ existing rings, 5 no feature found where ring can be inserted*/ \todo Need to indicate at which stage the failed commit occurred, for better cleanup and recovery from the error. - \param deleted Set of attribute names (i.e. columns) to delete + \param deleted Set of attribute indices (i.e. columns) to delete \param added Map (name, type) of attribute names (i.e. columns) to add \param changed Map (feature ID, Map (attribute name, new value) ) of attribute values to change */ - bool commitAttributeChanges(const QgsDeletedAttributesSet& deleted, + bool commitAttributeChanges(const QgsAttributeIds& deleted, const QgsNewAttributesMap& added, const QgsChangedAttributesMap& changed);