mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Changed data structure for added features from list to map to allow efficient lookups
This commit is contained in:
parent
9317ffd89a
commit
31f6ce07c3
@ -14,7 +14,7 @@ which are not wrapped by PyQt:
|
|||||||
- QMap<TYPE1, TYPE2*>
|
- QMap<TYPE1, TYPE2*>
|
||||||
- QMap<double, TYPE>
|
- QMap<double, TYPE>
|
||||||
- QMultiMap<double, TYPE2>
|
- QMultiMap<double, TYPE2>
|
||||||
- QMap<qint64, QgsGeometry>
|
- QMap<qint64, TYPE>
|
||||||
- QMap<qint64, QgsOverlayObject*>
|
- QMap<qint64, QgsOverlayObject*>
|
||||||
- QList< QPair< QString, QList<QString> > >
|
- QList< QPair< QString, QList<QString> > >
|
||||||
- QVector<TYPE*>
|
- QVector<TYPE*>
|
||||||
@ -661,94 +661,117 @@ template<TYPE>
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// copied from PyQt4 QMap<int, TYPE> and adapted to qint64
|
||||||
|
//
|
||||||
|
|
||||||
%MappedType QMap<qint64, QgsGeometry>
|
// QMap<qint64, TYPE> is implemented as a Python dictionary.
|
||||||
|
template<TYPE>
|
||||||
|
%MappedType QMap<qint64, TYPE> /DocType="dict-of-qint64-TYPE"/
|
||||||
{
|
{
|
||||||
%TypeHeaderCode
|
%TypeHeaderCode
|
||||||
#include <QMap>
|
#include <qmap.h>
|
||||||
%End
|
%End
|
||||||
|
|
||||||
%ConvertFromTypeCode
|
%ConvertFromTypeCode
|
||||||
// Create the list.
|
// Create the dictionary.
|
||||||
PyObject *d;
|
PyObject *d = PyDict_New();
|
||||||
|
|
||||||
if ((d = PyDict_New()) == NULL)
|
if (!d)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// Set the list elements.
|
// Set the dictionary elements.
|
||||||
for (QMap<qint64, QgsGeometry>::iterator it = sipCpp->begin(); it != sipCpp->end(); ++it)
|
QMap<qint64, TYPE>::const_iterator i = sipCpp->constBegin();
|
||||||
{
|
|
||||||
PyObject *kobj = PyLong_FromLongLong(it.key());
|
|
||||||
PyObject *tobj = sipConvertFromInstance( &it.value(), sipClass_QgsGeometry, sipTransferObj);
|
|
||||||
|
|
||||||
if (kobj == NULL || tobj == NULL || PyDict_SetItem(d, kobj, tobj) < 0)
|
while (i != sipCpp->constEnd())
|
||||||
{
|
{
|
||||||
Py_DECREF(d);
|
TYPE *t = new TYPE(i.value());
|
||||||
|
|
||||||
|
PyObject *kobj = PyLong_FromLongLong(i.key());
|
||||||
|
//PyObject *kobj = SIPLong_FromLong(i.key());
|
||||||
|
PyObject *tobj = sipConvertFromNewType(t, sipType_TYPE, sipTransferObj);
|
||||||
|
|
||||||
|
if (kobj == NULL || tobj == NULL || PyDict_SetItem(d, kobj, tobj) < 0)
|
||||||
|
{
|
||||||
|
Py_DECREF(d);
|
||||||
|
|
||||||
|
if (kobj)
|
||||||
|
{
|
||||||
|
Py_DECREF(kobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tobj)
|
||||||
|
{
|
||||||
|
Py_DECREF(tobj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete t;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (kobj)
|
|
||||||
{
|
|
||||||
Py_DECREF(kobj);
|
Py_DECREF(kobj);
|
||||||
}
|
|
||||||
|
|
||||||
if (tobj)
|
|
||||||
{
|
|
||||||
Py_DECREF(tobj);
|
Py_DECREF(tobj);
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF(tobj);
|
return d;
|
||||||
}
|
|
||||||
|
|
||||||
return d;
|
|
||||||
%End
|
%End
|
||||||
|
|
||||||
%ConvertToTypeCode
|
%ConvertToTypeCode
|
||||||
PyObject *kobj, *tobj;
|
PyObject *kobj, *tobj;
|
||||||
|
SIP_SSIZE_T i = 0;
|
||||||
|
|
||||||
// Check the type if that is all that is required.
|
// Check the type if that is all that is required.
|
||||||
if (sipIsErr == NULL)
|
if (sipIsErr == NULL)
|
||||||
{
|
{
|
||||||
if (!PyDict_Check(sipPy))
|
if (!PyDict_Check(sipPy))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
|
||||||
|
if (!sipCanConvertToType(tobj, sipType_TYPE, SIP_NOT_NONE))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<qint64, TYPE> *qm = new QMap<qint64, TYPE>;
|
||||||
|
|
||||||
Py_ssize_t i = 0;
|
|
||||||
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
|
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
|
||||||
{
|
{
|
||||||
if (!sipCanConvertToInstance(tobj, sipClass_QgsGeometry, SIP_NOT_NONE))
|
int state;
|
||||||
return 0;
|
//, k = SIPLong_AsLong(kobj);
|
||||||
}
|
qint64 k = PyLong_AsLongLong(kobj);
|
||||||
return 1;
|
TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(tobj, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
|
||||||
}
|
|
||||||
|
|
||||||
QMap<qint64, QgsGeometry> *qm = new QMap<qint64, QgsGeometry>;
|
if (*sipIsErr)
|
||||||
|
{
|
||||||
|
sipReleaseType(t, sipType_TYPE, state);
|
||||||
|
|
||||||
Py_ssize_t i = 0;
|
delete qm;
|
||||||
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
|
return 0;
|
||||||
{
|
}
|
||||||
int state;
|
|
||||||
qint64 k = PyLong_AsLongLong(kobj);
|
|
||||||
QgsGeometry * t = reinterpret_cast<QgsGeometry*>(sipConvertToInstance(tobj, sipClass_QgsGeometry, sipTransferObj,SIP_NOT_NONE,&state,sipIsErr));
|
|
||||||
|
|
||||||
if (*sipIsErr)
|
qm->insert(k, *t);
|
||||||
{
|
|
||||||
sipReleaseInstance(t, sipClass_QgsGeometry, state);
|
sipReleaseType(t, sipType_TYPE, state);
|
||||||
delete qm;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qm->insert(k, *t);
|
*sipCppPtr = qm;
|
||||||
sipReleaseInstance(t, sipClass_QgsGeometry, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
*sipCppPtr = qm;
|
return sipGetState(sipTransferObj);
|
||||||
return sipGetState(sipTransferObj);
|
|
||||||
%End
|
%End
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%MappedType QMap<QString, QVariant::Type>
|
%MappedType QMap<QString, QVariant::Type>
|
||||||
{
|
{
|
||||||
%TypeHeaderCode
|
%TypeHeaderCode
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
typedef QMap<qint64, QgsFeature> QgsFeatureMap;
|
||||||
|
|
||||||
class QgsVectorLayerEditBuffer : QObject
|
class QgsVectorLayerEditBuffer : QObject
|
||||||
{
|
{
|
||||||
@ -65,7 +66,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/** New features which are not commited. */
|
/** New features which are not commited. */
|
||||||
const QgsFeatureList& addedFeatures();
|
const QgsFeatureMap& addedFeatures();
|
||||||
|
|
||||||
/** Changed attributes values which are not commited */
|
/** Changed attributes values which are not commited */
|
||||||
const QgsChangedAttributesMap& changedAttributeValues();
|
const QgsChangedAttributesMap& changedAttributeValues();
|
||||||
|
@ -1584,7 +1584,7 @@ QgsRectangle QgsVectorLayer::extent()
|
|||||||
rect.combineExtentWith( &r );
|
rect.combineExtentWith( &r );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( QgsFeatureList::iterator it = mEditBuffer->mAddedFeatures.begin(); it != mEditBuffer->mAddedFeatures.end(); it++ )
|
for ( QgsFeatureMap::iterator it = mEditBuffer->mAddedFeatures.begin(); it != mEditBuffer->mAddedFeatures.end(); it++ )
|
||||||
{
|
{
|
||||||
QgsRectangle r = it->geometry()->boundingBox();
|
QgsRectangle r = it->geometry()->boundingBox();
|
||||||
rect.combineExtentWith( &r );
|
rect.combineExtentWith( &r );
|
||||||
|
@ -113,16 +113,7 @@ bool QgsVectorLayerEditBuffer::deleteFeature( QgsFeatureId fid )
|
|||||||
{
|
{
|
||||||
if ( FID_IS_NEW( fid ) )
|
if ( FID_IS_NEW( fid ) )
|
||||||
{
|
{
|
||||||
bool found = false;
|
if (!mAddedFeatures.contains(fid))
|
||||||
for ( int i = 0; i < mAddedFeatures.count(); ++i )
|
|
||||||
{
|
|
||||||
if ( mAddedFeatures[i].id() == fid )
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else // existing feature
|
else // existing feature
|
||||||
@ -304,25 +295,22 @@ bool QgsVectorLayerEditBuffer::commitChanges(QStringList& commitErrors)
|
|||||||
{
|
{
|
||||||
if ( cap & QgsVectorDataProvider::AddFeatures )
|
if ( cap & QgsVectorDataProvider::AddFeatures )
|
||||||
{
|
{
|
||||||
QList<QgsFeatureId> ids;
|
QList<QgsFeatureId> ids = mAddedFeatures.keys();
|
||||||
foreach ( const QgsFeature &f, mAddedFeatures )
|
QgsFeatureList featuresToAdd = mAddedFeatures.values();
|
||||||
{
|
|
||||||
ids << f.id();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( provider->addFeatures( mAddedFeatures ) )
|
if ( provider->addFeatures( featuresToAdd ) )
|
||||||
{
|
{
|
||||||
commitErrors << tr( "SUCCESS: %n feature(s) added.", "added features count", mAddedFeatures.size() );
|
commitErrors << tr( "SUCCESS: %n feature(s) added.", "added features count", featuresToAdd.size() );
|
||||||
|
|
||||||
emit committedFeaturesAdded( L->id(), mAddedFeatures );
|
emit committedFeaturesAdded( L->id(), featuresToAdd );
|
||||||
|
|
||||||
// notify everyone that the features with temporary ids were updated with permanent ids
|
// notify everyone that the features with temporary ids were updated with permanent ids
|
||||||
for ( int i = 0; i < mAddedFeatures.size(); i++ )
|
for ( int i = 0; i < featuresToAdd.count(); ++i )
|
||||||
{
|
{
|
||||||
if ( mAddedFeatures[i].id() != ids[i] )
|
if ( featuresToAdd[i].id() != ids[i] )
|
||||||
{
|
{
|
||||||
emit featureDeleted( ids[i] );
|
emit featureDeleted( ids[i] );
|
||||||
emit featureAdded( mAddedFeatures[i].id() );
|
emit featureAdded( featuresToAdd[i].id() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +436,7 @@ void QgsVectorLayerEditBuffer::handleAttributeAdded( int index )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// go through added features and adapt attributes
|
// go through added features and adapt attributes
|
||||||
QgsFeatureList::iterator featureIt = mAddedFeatures.begin();
|
QgsFeatureMap::iterator featureIt = mAddedFeatures.begin();
|
||||||
for ( ; featureIt != mAddedFeatures.end(); ++featureIt )
|
for ( ; featureIt != mAddedFeatures.end(); ++featureIt )
|
||||||
{
|
{
|
||||||
QgsAttributes& attrs = featureIt->attributes();
|
QgsAttributes& attrs = featureIt->attributes();
|
||||||
@ -471,7 +459,7 @@ void QgsVectorLayerEditBuffer::handleAttributeDeleted( int index )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// go through added features and adapt attributes
|
// go through added features and adapt attributes
|
||||||
QgsFeatureList::iterator featureIt = mAddedFeatures.begin();
|
QgsFeatureMap::iterator featureIt = mAddedFeatures.begin();
|
||||||
for ( ; featureIt != mAddedFeatures.end(); ++featureIt )
|
for ( ; featureIt != mAddedFeatures.end(); ++featureIt )
|
||||||
{
|
{
|
||||||
QgsAttributes& attrs = featureIt->attributes();
|
QgsAttributes& attrs = featureIt->attributes();
|
||||||
|
@ -15,6 +15,7 @@ class QgsVectorLayer;
|
|||||||
|
|
||||||
typedef QList<int> QgsAttributeList;
|
typedef QList<int> QgsAttributeList;
|
||||||
typedef QSet<int> QgsAttributeIds;
|
typedef QSet<int> QgsAttributeIds;
|
||||||
|
typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
|
||||||
|
|
||||||
class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
|
class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
|
||||||
{
|
{
|
||||||
@ -79,7 +80,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/** New features which are not commited. */
|
/** New features which are not commited. */
|
||||||
inline const QgsFeatureList& addedFeatures() { return mAddedFeatures; }
|
inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
|
||||||
|
|
||||||
/** Changed attributes values which are not commited */
|
/** Changed attributes values which are not commited */
|
||||||
inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
|
inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
|
||||||
@ -161,7 +162,7 @@ protected:
|
|||||||
QgsFeatureIds mDeletedFeatureIds;
|
QgsFeatureIds mDeletedFeatureIds;
|
||||||
|
|
||||||
/** New features which are not commited. */
|
/** New features which are not commited. */
|
||||||
QgsFeatureList mAddedFeatures;
|
QgsFeatureMap mAddedFeatures;
|
||||||
|
|
||||||
/** Changed attributes values which are not commited */
|
/** Changed attributes values which are not commited */
|
||||||
QgsChangedAttributesMap mChangedAttributeValues;
|
QgsChangedAttributesMap mChangedAttributeValues;
|
||||||
|
@ -430,7 +430,7 @@ bool QgsVectorLayerFeatureIterator::nextFeatureFid( QgsFeature& f )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// added features
|
// added features
|
||||||
for ( QgsFeatureList::iterator iter = editBuffer->mAddedFeatures.begin(); iter != editBuffer->mAddedFeatures.end(); ++iter )
|
for ( QgsFeatureMap::iterator iter = editBuffer->mAddedFeatures.begin(); iter != editBuffer->mAddedFeatures.end(); ++iter )
|
||||||
{
|
{
|
||||||
if ( iter->id() == featureId )
|
if ( iter->id() == featureId )
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
|
typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
|
||||||
|
|
||||||
class QgsVectorLayer;
|
class QgsVectorLayer;
|
||||||
class QgsVectorJoinInfo;
|
class QgsVectorJoinInfo;
|
||||||
|
|
||||||
@ -40,7 +42,7 @@ protected:
|
|||||||
// only related to editing
|
// only related to editing
|
||||||
QSet<QgsFeatureId> mFetchConsidered;
|
QSet<QgsFeatureId> mFetchConsidered;
|
||||||
QgsGeometryMap::iterator mFetchChangedGeomIt;
|
QgsGeometryMap::iterator mFetchChangedGeomIt;
|
||||||
QgsFeatureList::iterator mFetchAddedFeaturesIt;
|
QgsFeatureMap::iterator mFetchAddedFeaturesIt;
|
||||||
|
|
||||||
bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
|
bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
|
||||||
|
|
||||||
|
@ -47,14 +47,9 @@ QgsVectorLayerUndoCommandAddFeature::QgsVectorLayerUndoCommandAddFeature( QgsVec
|
|||||||
|
|
||||||
void QgsVectorLayerUndoCommandAddFeature::undo()
|
void QgsVectorLayerUndoCommandAddFeature::undo()
|
||||||
{
|
{
|
||||||
for (int i = 0; mBuffer->mAddedFeatures.count(); ++i)
|
QgsFeatureMap::const_iterator it = mBuffer->mAddedFeatures.find(mFeature.id());
|
||||||
{
|
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
|
||||||
if (mBuffer->mAddedFeatures[i].id() == mFeature.id())
|
mBuffer->mAddedFeatures.remove(mFeature.id());
|
||||||
{
|
|
||||||
mBuffer->mAddedFeatures.removeAt(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mFeature.geometry() )
|
if ( mFeature.geometry() )
|
||||||
cache()->removeGeometry(mFeature.id());
|
cache()->removeGeometry(mFeature.id());
|
||||||
@ -64,7 +59,7 @@ void QgsVectorLayerUndoCommandAddFeature::undo()
|
|||||||
|
|
||||||
void QgsVectorLayerUndoCommandAddFeature::redo()
|
void QgsVectorLayerUndoCommandAddFeature::redo()
|
||||||
{
|
{
|
||||||
mBuffer->mAddedFeatures.append( mFeature );
|
mBuffer->mAddedFeatures.insert( mFeature.id(), mFeature );
|
||||||
|
|
||||||
if ( mFeature.geometry() )
|
if ( mFeature.geometry() )
|
||||||
cache()->cacheGeometry( mFeature.id(), *mFeature.geometry() );
|
cache()->cacheGeometry( mFeature.id(), *mFeature.geometry() );
|
||||||
@ -81,14 +76,9 @@ QgsVectorLayerUndoCommandDeleteFeature::QgsVectorLayerUndoCommandDeleteFeature(
|
|||||||
|
|
||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < mBuffer->mAddedFeatures.count(); ++i )
|
QgsFeatureMap::const_iterator it = mBuffer->mAddedFeatures.find( mFid );
|
||||||
{
|
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
|
||||||
if ( mBuffer->mAddedFeatures[i].id() == fid )
|
mOldAddedFeature = it.value();
|
||||||
{
|
|
||||||
mOldAddedFeature = mBuffer->mAddedFeatures[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +86,7 @@ void QgsVectorLayerUndoCommandDeleteFeature::undo()
|
|||||||
{
|
{
|
||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
mBuffer->mAddedFeatures.append( mOldAddedFeature );
|
mBuffer->mAddedFeatures.insert( mOldAddedFeature.id(), mOldAddedFeature );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -110,14 +100,7 @@ void QgsVectorLayerUndoCommandDeleteFeature::redo()
|
|||||||
{
|
{
|
||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < mBuffer->mAddedFeatures.count(); ++i )
|
mBuffer->mAddedFeatures.remove( mFid );
|
||||||
{
|
|
||||||
if ( mBuffer->mAddedFeatures[i].id() == mFid )
|
|
||||||
{
|
|
||||||
mBuffer->mAddedFeatures.removeAt(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -136,14 +119,9 @@ QgsVectorLayerUndoCommandChangeGeometry::QgsVectorLayerUndoCommandChangeGeometry
|
|||||||
|
|
||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < mBuffer->mAddedFeatures.count(); ++i )
|
QgsFeatureMap::const_iterator it = mBuffer->mAddedFeatures.find( mFid );
|
||||||
{
|
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
|
||||||
if ( mBuffer->mAddedFeatures[i].id() == mFid )
|
mOldGeom = new QgsGeometry( *it.value().geometry() );
|
||||||
{
|
|
||||||
mOldGeom = new QgsGeometry( *mBuffer->mAddedFeatures[i].geometry() );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -167,14 +145,10 @@ void QgsVectorLayerUndoCommandChangeGeometry::undo()
|
|||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
// modify added features
|
// modify added features
|
||||||
for ( int i = 0; i < mBuffer->mAddedFeatures.count(); ++i )
|
QgsFeatureMap::iterator it = mBuffer->mAddedFeatures.find( mFid );
|
||||||
{
|
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
|
||||||
if ( mBuffer->mAddedFeatures[i].id() == mFid )
|
it.value().setGeometry( *mOldGeom );
|
||||||
{
|
|
||||||
mBuffer->mAddedFeatures[i].setGeometry( *mOldGeom );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cache()->cacheGeometry( mFid, *mOldGeom );
|
cache()->cacheGeometry( mFid, *mOldGeom );
|
||||||
emit mBuffer->geometryChanged( mFid, *mOldGeom );
|
emit mBuffer->geometryChanged( mFid, *mOldGeom );
|
||||||
}
|
}
|
||||||
@ -208,14 +182,9 @@ void QgsVectorLayerUndoCommandChangeGeometry::redo()
|
|||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
// modify added features
|
// modify added features
|
||||||
for ( int i = 0; i < mBuffer->mAddedFeatures.count(); ++i )
|
QgsFeatureMap::iterator it = mBuffer->mAddedFeatures.find( mFid );
|
||||||
{
|
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
|
||||||
if ( mBuffer->mAddedFeatures[i].id() == mFid )
|
it.value().setGeometry( *mNewGeom );
|
||||||
{
|
|
||||||
mBuffer->mAddedFeatures[i].setGeometry( *mNewGeom );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -240,14 +209,12 @@ QgsVectorLayerUndoCommandChangeAttribute::QgsVectorLayerUndoCommandChangeAttribu
|
|||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
// work with added feature
|
// work with added feature
|
||||||
for ( int i = 0; i < mBuffer->mAddedFeatures.size(); i++ )
|
QgsFeatureMap::const_iterator it = mBuffer->mAddedFeatures.find( mFid );
|
||||||
|
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
|
||||||
|
if ( it.value().attribute( mFieldIndex ).isValid() )
|
||||||
{
|
{
|
||||||
if ( mBuffer->mAddedFeatures[i].id() == mFid && mBuffer->mAddedFeatures[i].attribute( mFieldIndex ).isValid() )
|
mOldValue = it.value().attribute( mFieldIndex );
|
||||||
{
|
mFirstChange = false;
|
||||||
mOldValue = mBuffer->mAddedFeatures[i].attribute( mFieldIndex );
|
|
||||||
mFirstChange = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -268,14 +235,9 @@ void QgsVectorLayerUndoCommandChangeAttribute::undo()
|
|||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
// added feature
|
// added feature
|
||||||
for ( int i = 0; i < mBuffer->mAddedFeatures.size(); i++ )
|
QgsFeatureMap::iterator it = mBuffer->mAddedFeatures.find( mFid );
|
||||||
{
|
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
|
||||||
if ( mBuffer->mAddedFeatures[i].id() == mFid )
|
it.value().setAttribute( mFieldIndex, mOldValue );
|
||||||
{
|
|
||||||
mBuffer->mAddedFeatures[i].setAttribute( mFieldIndex, mOldValue );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -310,14 +272,9 @@ void QgsVectorLayerUndoCommandChangeAttribute::redo()
|
|||||||
if ( FID_IS_NEW( mFid ) )
|
if ( FID_IS_NEW( mFid ) )
|
||||||
{
|
{
|
||||||
// updated added feature
|
// updated added feature
|
||||||
for ( int i = 0; i < mBuffer->mAddedFeatures.size(); i++ )
|
QgsFeatureMap::iterator it = mBuffer->mAddedFeatures.find( mFid );
|
||||||
{
|
Q_ASSERT( it != mBuffer->mAddedFeatures.end() );
|
||||||
if ( mBuffer->mAddedFeatures[i].id() == mFid )
|
it.value().setAttribute( mFieldIndex, mNewValue );
|
||||||
{
|
|
||||||
mBuffer->mAddedFeatures[i].setAttribute( mFieldIndex, mNewValue );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -385,9 +342,9 @@ QgsVectorLayerUndoCommandDeleteAttribute::QgsVectorLayerUndoCommandDeleteAttribu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save values of new features
|
// save values of new features
|
||||||
for (int i = 0; i < mBuffer->mAddedFeatures.count(); ++i)
|
for (QgsFeatureMap::const_iterator it = mBuffer->mAddedFeatures.begin(); it != mBuffer->mAddedFeatures.end(); ++it)
|
||||||
{
|
{
|
||||||
const QgsFeature& f = mBuffer->mAddedFeatures[i];
|
const QgsFeature& f = it.value();
|
||||||
mDeletedValues.insert(f.id(), f.attribute(mFieldIndex));
|
mDeletedValues.insert(f.id(), f.attribute(mFieldIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,9 +373,9 @@ void QgsVectorLayerUndoCommandDeleteAttribute::undo()
|
|||||||
mBuffer->handleAttributeAdded( mFieldIndex ); // update changed attributes + new features
|
mBuffer->handleAttributeAdded( mFieldIndex ); // update changed attributes + new features
|
||||||
|
|
||||||
// set previously used attributes of new features
|
// set previously used attributes of new features
|
||||||
for (int i = 0; i < mBuffer->mAddedFeatures.count(); ++i)
|
for (QgsFeatureMap::iterator it = mBuffer->mAddedFeatures.begin(); it != mBuffer->mAddedFeatures.end(); ++it)
|
||||||
{
|
{
|
||||||
QgsFeature& f = mBuffer->mAddedFeatures[i];
|
QgsFeature& f = it.value();
|
||||||
f.setAttribute( mFieldIndex, mDeletedValues.value(f.id()) );
|
f.setAttribute( mFieldIndex, mDeletedValues.value(f.id()) );
|
||||||
}
|
}
|
||||||
// set previously used changed attributes
|
// set previously used changed attributes
|
||||||
|
@ -72,7 +72,7 @@ def dumpEditBuffer(layer):
|
|||||||
print "NO EDITING!"
|
print "NO EDITING!"
|
||||||
return
|
return
|
||||||
print "ADDED:"
|
print "ADDED:"
|
||||||
for f in editBuffer.addedFeatures(): print "%d: %s | %s" % (f.id(), formatAttributes(f.attributes()), f.geometry().exportToWkt())
|
for fid,f in editBuffer.addedFeatures().iteritems(): print "%d: %s | %s" % (f.id(), formatAttributes(f.attributes()), f.geometry().exportToWkt())
|
||||||
print "CHANGED GEOM:"
|
print "CHANGED GEOM:"
|
||||||
for fid,geom in editBuffer.changedGeometries().iteritems(): print "%d | %s" % (f.id(), f.geometry().exportToWkt())
|
for fid,geom in editBuffer.changedGeometries().iteritems(): print "%d | %s" % (f.id(), f.geometry().exportToWkt())
|
||||||
|
|
||||||
@ -232,7 +232,6 @@ class TestQgsVectorLayer(TestCase):
|
|||||||
fid = feat.id()
|
fid = feat.id()
|
||||||
assert layer.deleteFeature(fid)
|
assert layer.deleteFeature(fid)
|
||||||
checkAfter2()
|
checkAfter2()
|
||||||
dumpEditBuffer(layer)
|
|
||||||
|
|
||||||
# now try undo/redo
|
# now try undo/redo
|
||||||
layer.undoStack().undo()
|
layer.undoStack().undo()
|
||||||
@ -244,7 +243,6 @@ class TestQgsVectorLayer(TestCase):
|
|||||||
layer.undoStack().redo()
|
layer.undoStack().redo()
|
||||||
checkAfter2()
|
checkAfter2()
|
||||||
|
|
||||||
dumpEditBuffer(layer)
|
|
||||||
assert layer.commitChanges()
|
assert layer.commitChanges()
|
||||||
checkAfter2()
|
checkAfter2()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user