Skip to content

Commit

Permalink
This commit changes the interface of qgsvectorlayer back to the state…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
mhugent committed Jul 7, 2007
1 parent 8a408fd commit 35ee2ce
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 54 deletions.
4 changes: 2 additions & 2 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -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);

Expand Down
23 changes: 19 additions & 4 deletions src/app/qgsattributetable.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributetable.h
Expand Up @@ -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;
Expand Down
69 changes: 26 additions & 43 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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;
}

Expand Down
6 changes: 2 additions & 4 deletions src/core/qgsvectorlayer.h
Expand Up @@ -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;


Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 35ee2ce

Please sign in to comment.