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@7065 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2007-07-07 06:58:10 +00:00
parent 29a524f3aa
commit c9da10c13f
5 changed files with 50 additions and 54 deletions

View File

@ -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<QString>& deleted,
bool commitAttributeChanges(const QSet<int>& deleted,
const QMap<QString, QString>& added,
const QMap<int, QMap<int, QVariant> >& changed);

View File

@ -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<QString>::const_iterator it = mDeletedAttributes.constBegin();
for(; it != mDeletedAttributes.constEnd(); ++it)
{
deletedIds.insert(provider->indexFromFieldName(*it));
}
isSuccessful = layer->commitAttributeChanges(deletedIds,
mAddedAttributes,
mChangedValues);
}
}
if (isSuccessful)

View File

@ -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<QString> 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;

View File

@ -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;
}

View File

@ -56,8 +56,6 @@ typedef QSet<int> QgsAttributeIds;
// key = attribute name, value = attribute type
typedef QMap<QString, QString> QgsNewAttributesMap;
typedef QSet<QString> QgsDeletedAttributesSet;
typedef QMap<int, QgsField> 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);