Skip to content

Commit 35ee2ce

Browse files
author
mhugent
committedJul 7, 2007
This commit changes the interface of qgsvectorlayer back to the state before r7063 and keeps the fix to allow deletion of postgis columns
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7065 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

5 files changed

+50
-54
lines changed

5 files changed

+50
-54
lines changed
 

‎python/core/qgsvectorlayer.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,13 @@ existing rings, 5 no feature found where ring can be inserted*/
244244
\todo Need to indicate at which stage the failed commit occurred,
245245
for better cleanup and recovery from the error.
246246

247-
\param deleted Set of attribute names (i.e. columns) to delete
247+
\param deleted Set of attribute indices (i.e. columns) to delete
248248
\param added Map (name, type) of attribute names (i.e. columns) to add
249249
\param changed Map (feature ID, Map (attribute name, new value) )
250250
of attribute values to change
251251

252252
*/
253-
bool commitAttributeChanges(const QSet<QString>& deleted,
253+
bool commitAttributeChanges(const QSet<int>& deleted,
254254
const QMap<QString, QString>& added,
255255
const QMap<int, QMap<int, QVariant> >& changed);
256256

‎src/app/qgsattributetable.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,25 @@ bool QgsAttributeTable::commitChanges(QgsVectorLayer* layer)
412412

413413
if(layer)
414414
{
415-
isSuccessful = layer->commitAttributeChanges(
416-
mDeletedAttributes,
417-
mAddedAttributes,
418-
mChangedValues);
415+
//convert strings of deleted attributes to ids
416+
417+
QgsVectorDataProvider* provider = layer->getDataProvider();
418+
419+
if(provider)
420+
{
421+
422+
QgsAttributeIds deletedIds;
423+
QSet<QString>::const_iterator it = mDeletedAttributes.constBegin();
424+
425+
for(; it != mDeletedAttributes.constEnd(); ++it)
426+
{
427+
deletedIds.insert(provider->indexFromFieldName(*it));
428+
}
429+
430+
isSuccessful = layer->commitAttributeChanges(deletedIds,
431+
mAddedAttributes,
432+
mChangedValues);
433+
}
419434
}
420435

421436
if (isSuccessful)

‎src/app/qgsattributetable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class QgsAttributeTable:public Q3Table
130130
and the value the attribute type*/
131131
QgsNewAttributesMap mAddedAttributes;
132132
/**Set containing the attribute names of deleted attributes*/
133-
QgsDeletedAttributesSet mDeletedAttributes;
133+
QSet<QString> mDeletedAttributes;
134134
/**Nested map containing the changed attribute values. The int is the feature id,
135135
the first QString the attribute name and the second QString the new value*/
136136
QgsChangedAttributesMap mChangedValues;

‎src/core/qgsvectorlayer.cpp

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,73 +2878,56 @@ void QgsVectorLayer::setCoordinateSystem()
28782878

28792879
}
28802880

2881-
bool QgsVectorLayer::commitAttributeChanges(const QgsDeletedAttributesSet& deleted,
2881+
bool QgsVectorLayer::commitAttributeChanges(const QgsAttributeIds& deleted,
28822882
const QgsNewAttributesMap& added,
28832883
const QgsChangedAttributesMap& changed)
28842884
{
28852885
bool returnvalue=true;
2886-
2887-
if(mDataProvider)
2888-
{
2889-
2890-
QgsAttributeIds attIds;
2891-
QgsDeletedAttributesSet::const_iterator att_it = deleted.constBegin();
2892-
2893-
for(; att_it != deleted.constEnd(); ++att_it)
2894-
{
2895-
attIds.insert(mDataProvider->indexFromFieldName(*att_it));
2896-
}
2897-
2898-
if(mDataProvider->capabilities()&QgsVectorDataProvider::DeleteAttributes)
2886+
if(mDataProvider->capabilities()&QgsVectorDataProvider::DeleteAttributes)
28992887
{
29002888
//delete attributes in all not commited features
29012889
for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
2902-
{
2903-
for (QgsAttributeIds::const_iterator it = attIds.begin(); it != attIds.end(); ++it)
2904-
{
2905-
(*iter).deleteAttribute(*it);
2906-
}
2907-
}
2908-
2890+
{
2891+
for (QgsAttributeIds::const_iterator it = deleted.begin(); it != deleted.end(); ++it)
2892+
{
2893+
(*iter).deleteAttribute(*it);
2894+
}
2895+
}
2896+
29092897
//and then in the provider
2910-
if(!mDataProvider->deleteAttributes(attIds))
2911-
{
2912-
returnvalue=false;
2913-
}
2898+
if(!mDataProvider->deleteAttributes(deleted))
2899+
{
2900+
returnvalue=false;
2901+
}
29142902
}
2915-
2916-
if(mDataProvider->capabilities()&QgsVectorDataProvider::AddAttributes)
2903+
2904+
if(mDataProvider->capabilities()&QgsVectorDataProvider::AddAttributes)
29172905
{
29182906
//add attributes in all not commited features
29192907
// TODO: is it necessary? [MD]
29202908
/*for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
2921-
{
2909+
{
29222910
for (QgsNewAttributesMap::const_iterator it = added.begin(); it != added.end(); ++it)
29232911
{
2924-
(*iter).addAttribute(, QgsFeatureAttribute(it.key(), ""));
2912+
(*iter).addAttribute(, QgsFeatureAttribute(it.key(), ""));
29252913
}
2926-
}*/
2914+
}*/
29272915

29282916
//and then in the provider
29292917
if(!mDataProvider->addAttributes(added))
2930-
{
2931-
returnvalue=false;
2932-
}
2918+
{
2919+
returnvalue=false;
2920+
}
29332921
}
2934-
2935-
if(mDataProvider->capabilities()&QgsVectorDataProvider::ChangeAttributeValues)
2922+
2923+
if(mDataProvider->capabilities()&QgsVectorDataProvider::ChangeAttributeValues)
29362924
{
29372925
//and then those of the commited ones
29382926
if(!mDataProvider->changeAttributeValues(changed))
2939-
{
2940-
returnvalue=false;
2941-
}
2927+
{
2928+
returnvalue=false;
2929+
}
29422930
}
2943-
}
2944-
else
2945-
{
2946-
returnvalue=false;
2947-
}
29482931
return returnvalue;
29492932
}
29502933

‎src/core/qgsvectorlayer.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ typedef QSet<int> QgsAttributeIds;
5656
// key = attribute name, value = attribute type
5757
typedef QMap<QString, QString> QgsNewAttributesMap;
5858

59-
typedef QSet<QString> QgsDeletedAttributesSet;
60-
6159
typedef QMap<int, QgsField> QgsFieldMap;
6260

6361

@@ -310,13 +308,13 @@ existing rings, 5 no feature found where ring can be inserted*/
310308
\todo Need to indicate at which stage the failed commit occurred,
311309
for better cleanup and recovery from the error.
312310
313-
\param deleted Set of attribute names (i.e. columns) to delete
311+
\param deleted Set of attribute indices (i.e. columns) to delete
314312
\param added Map (name, type) of attribute names (i.e. columns) to add
315313
\param changed Map (feature ID, Map (attribute name, new value) )
316314
of attribute values to change
317315
318316
*/
319-
bool commitAttributeChanges(const QgsDeletedAttributesSet& deleted,
317+
bool commitAttributeChanges(const QgsAttributeIds& deleted,
320318
const QgsNewAttributesMap& added,
321319
const QgsChangedAttributesMap& changed);
322320

0 commit comments

Comments
 (0)
Please sign in to comment.