qgis/Quantum-GIS — pull request #673 by matthias-kuhn (2013-06-22 16:58:39+00:00)
Title: Copy On Write for EditBuffer in QgsVectorLayerFeatureIterator

This introduces quite a bit of SmartPointer and constness magic, so I would be very happy to have some of the experienced devs in here ( @jef @sk-wonder @mhugent and of course anybody else feeling qualified) to have a look at it if you find time

Problem:
The VectorLayerFeatureIterator works with the edit buffer, which can change, disappear or appear while the iterator is active.
For an iterator which does
a) not fail unexpectedly due to concurrent changes and
b) still works on the same dataset that was active when constructed and
c) does not copy all the edit buffer
I introduced Copy On Write (COW) here.

Qt does COW on their collections (QMap et al) when using a ConstIterator. Nice: We don't have to care! Downside: QgsGeometry has no const-ness and it's not that easy to achieve, because it caches the geometry in WKB and GEOS format and only transforms when necessary. Therefore I made both of them mutable, so they are allowed to change in const-methods only. I think this is valid because if you want to change the "true" geometry of the object you will have to call a non-const method still.

As the QgsEditBuffer also can disappear anytime, (layer editing stopped) I introduced a smart pointer (QSharedPointer) which deletes it only after the last reference has been deleted. But as smart pointers are not yet widely used in QGIS and opinions of these are different, please let me know if you disagree with this approach.

IMHO it works quite fine, but YMMV.