mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
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:
parent
29a524f3aa
commit
c9da10c13f
@ -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,
|
\todo Need to indicate at which stage the failed commit occurred,
|
||||||
for better cleanup and recovery from the error.
|
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 added Map (name, type) of attribute names (i.e. columns) to add
|
||||||
\param changed Map (feature ID, Map (attribute name, new value) )
|
\param changed Map (feature ID, Map (attribute name, new value) )
|
||||||
of attribute values to change
|
of attribute values to change
|
||||||
|
|
||||||
*/
|
*/
|
||||||
bool commitAttributeChanges(const QSet<QString>& deleted,
|
bool commitAttributeChanges(const QSet<int>& deleted,
|
||||||
const QMap<QString, QString>& added,
|
const QMap<QString, QString>& added,
|
||||||
const QMap<int, QMap<int, QVariant> >& changed);
|
const QMap<int, QMap<int, QVariant> >& changed);
|
||||||
|
|
||||||
|
@ -412,10 +412,25 @@ bool QgsAttributeTable::commitChanges(QgsVectorLayer* layer)
|
|||||||
|
|
||||||
if(layer)
|
if(layer)
|
||||||
{
|
{
|
||||||
isSuccessful = layer->commitAttributeChanges(
|
//convert strings of deleted attributes to ids
|
||||||
mDeletedAttributes,
|
|
||||||
mAddedAttributes,
|
QgsVectorDataProvider* provider = layer->getDataProvider();
|
||||||
mChangedValues);
|
|
||||||
|
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)
|
if (isSuccessful)
|
||||||
|
@ -130,7 +130,7 @@ class QgsAttributeTable:public Q3Table
|
|||||||
and the value the attribute type*/
|
and the value the attribute type*/
|
||||||
QgsNewAttributesMap mAddedAttributes;
|
QgsNewAttributesMap mAddedAttributes;
|
||||||
/**Set containing the attribute names of deleted attributes*/
|
/**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,
|
/**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*/
|
the first QString the attribute name and the second QString the new value*/
|
||||||
QgsChangedAttributesMap mChangedValues;
|
QgsChangedAttributesMap mChangedValues;
|
||||||
|
@ -2878,73 +2878,56 @@ void QgsVectorLayer::setCoordinateSystem()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsVectorLayer::commitAttributeChanges(const QgsDeletedAttributesSet& deleted,
|
bool QgsVectorLayer::commitAttributeChanges(const QgsAttributeIds& deleted,
|
||||||
const QgsNewAttributesMap& added,
|
const QgsNewAttributesMap& added,
|
||||||
const QgsChangedAttributesMap& changed)
|
const QgsChangedAttributesMap& changed)
|
||||||
{
|
{
|
||||||
bool returnvalue=true;
|
bool returnvalue=true;
|
||||||
|
if(mDataProvider->capabilities()&QgsVectorDataProvider::DeleteAttributes)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
//delete attributes in all not commited features
|
//delete attributes in all not commited features
|
||||||
for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
|
for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
|
||||||
{
|
{
|
||||||
for (QgsAttributeIds::const_iterator it = attIds.begin(); it != attIds.end(); ++it)
|
for (QgsAttributeIds::const_iterator it = deleted.begin(); it != deleted.end(); ++it)
|
||||||
{
|
{
|
||||||
(*iter).deleteAttribute(*it);
|
(*iter).deleteAttribute(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//and then in the provider
|
//and then in the provider
|
||||||
if(!mDataProvider->deleteAttributes(attIds))
|
if(!mDataProvider->deleteAttributes(deleted))
|
||||||
{
|
{
|
||||||
returnvalue=false;
|
returnvalue=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mDataProvider->capabilities()&QgsVectorDataProvider::AddAttributes)
|
if(mDataProvider->capabilities()&QgsVectorDataProvider::AddAttributes)
|
||||||
{
|
{
|
||||||
//add attributes in all not commited features
|
//add attributes in all not commited features
|
||||||
// TODO: is it necessary? [MD]
|
// TODO: is it necessary? [MD]
|
||||||
/*for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
|
/*for (QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter)
|
||||||
{
|
{
|
||||||
for (QgsNewAttributesMap::const_iterator it = added.begin(); it != added.end(); ++it)
|
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
|
//and then in the provider
|
||||||
if(!mDataProvider->addAttributes(added))
|
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
|
//and then those of the commited ones
|
||||||
if(!mDataProvider->changeAttributeValues(changed))
|
if(!mDataProvider->changeAttributeValues(changed))
|
||||||
{
|
{
|
||||||
returnvalue=false;
|
returnvalue=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
returnvalue=false;
|
|
||||||
}
|
|
||||||
return returnvalue;
|
return returnvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,8 +56,6 @@ typedef QSet<int> QgsAttributeIds;
|
|||||||
// key = attribute name, value = attribute type
|
// key = attribute name, value = attribute type
|
||||||
typedef QMap<QString, QString> QgsNewAttributesMap;
|
typedef QMap<QString, QString> QgsNewAttributesMap;
|
||||||
|
|
||||||
typedef QSet<QString> QgsDeletedAttributesSet;
|
|
||||||
|
|
||||||
typedef QMap<int, QgsField> QgsFieldMap;
|
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,
|
\todo Need to indicate at which stage the failed commit occurred,
|
||||||
for better cleanup and recovery from the error.
|
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 added Map (name, type) of attribute names (i.e. columns) to add
|
||||||
\param changed Map (feature ID, Map (attribute name, new value) )
|
\param changed Map (feature ID, Map (attribute name, new value) )
|
||||||
of attribute values to change
|
of attribute values to change
|
||||||
|
|
||||||
*/
|
*/
|
||||||
bool commitAttributeChanges(const QgsDeletedAttributesSet& deleted,
|
bool commitAttributeChanges(const QgsAttributeIds& deleted,
|
||||||
const QgsNewAttributesMap& added,
|
const QgsNewAttributesMap& added,
|
||||||
const QgsChangedAttributesMap& changed);
|
const QgsChangedAttributesMap& changed);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user