Skip to content

Commit

Permalink
Rename edit buffer methods to is..., add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 14, 2016
1 parent dc10c8f commit 0736bf7
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 23 deletions.
44 changes: 36 additions & 8 deletions python/core/qgsvectorlayereditbuffer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,70 @@ class QgsVectorLayerEditBuffer : QObject
/** Stop editing and discard the edits */
virtual void rollBack();

/** Returns a map of new features which are not committed. */
/** Returns a map of new features which are not committed.
* @see isFeatureAdded()
*/
QgsFeatureMap addedFeatures() const;

/** Returns true if the specified feature ID has been added but not committed.
* @param id feature ID
* @note added in QGIS 3.0
* @see addedFeatures()
*/
bool featureIsAdded( QgsFeatureId id ) const;
bool isFeatureAdded( QgsFeatureId id ) const;

/** Returns a map of features with changed attributes values which are not committed */
/** Returns a map of features with changed attributes values which are not committed.
* @see isFeatureAttributesChanged()
*/
QgsChangedAttributesMap changedAttributeValues() const;

/** Returns true if the specified feature ID has had an attribute changed but not committed.
* @param id feature ID
* @note added in QGIS 3.0
* @see changedAttributeValues()
*/
bool featureHasAttributeChanges( QgsFeatureId id ) const;
bool isFeatureAttributesChanged( QgsFeatureId id ) const;

/** Returns a list of deleted attributes fields which are not committed. The list is kept sorted. */
/** Returns a list of deleted attributes fields which are not committed. The list is kept sorted.
* @see isAttributeDeleted()
*/
QgsAttributeList deletedAttributeIds() const;

/** Returns true if the specified attribute has been deleted but not committed.
* @param index attribute index
* @note added in QGIS 3.0
* @see deletedAttributeIds()
*/
bool isAttributeDeleted( int index ) const;

/** Returns a list of added attributes fields which are not committed */
QList<QgsField> addedAttributes() const;

/** Returns a map of features with changed geometries which are not committed. */
/** Returns a map of features with changed geometries which are not committed.
* @see hasFeatureGeometryChange()
*/
QgsGeometryMap changedGeometries() const;

/** Returns true if the specified feature ID has had its geometry changed but not committed.
* @param id feature ID
* @note added in QGIS 3.0
* @see changedGeometries()
*/
bool featureHasGeometryChange( QgsFeatureId id ) const;
bool isFeatureGeometryChanged( QgsFeatureId id ) const;

/** Returns a list of deleted feature IDs which are not committed. */
/** Returns a list of deleted feature IDs which are not committed.
* @see isFeatureDeleted()
*/
QgsFeatureIds deletedFeatureIds() const;

/** Returns true if the specified feature ID has been deleted but not committed.
* @param id feature ID
* @note added in QGIS 3.0
* @see deletedFeatureIds()
*/
bool isFeatureDeleted( QgsFeatureId id ) const;


//QString dumpEditBuffer();

protected slots:
Expand Down
46 changes: 37 additions & 9 deletions src/core/qgsvectorlayereditbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,70 @@ class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
/** Stop editing and discard the edits */
virtual void rollBack();

/** Returns a map of new features which are not committed. */
/** Returns a map of new features which are not committed.
* @see isFeatureAdded()
*/
QgsFeatureMap addedFeatures() const { return mAddedFeatures; }

/** Returns true if the specified feature ID has been added but not committed.
* @param id feature ID
* @note added in QGIS 3.0
* @see addedFeatures()
*/
bool featureIsAdded( QgsFeatureId id ) const { return mAddedFeatures.contains( id ); }
bool isFeatureAdded( QgsFeatureId id ) const { return mAddedFeatures.contains( id ); }

/** Returns a map of features with changed attributes values which are not committed */
/** Returns a map of features with changed attributes values which are not committed.
* @see isFeatureAttributesChanged()
*/
QgsChangedAttributesMap changedAttributeValues() const { return mChangedAttributeValues; }

/** Returns true if the specified feature ID has had an attribute changed but not committed.
* @param id feature ID
* @note added in QGIS 3.0
* @see changedAttributeValues()
*/
bool featureHasAttributeChanges( QgsFeatureId id ) const { return mChangedAttributeValues.contains( id ); }
bool isFeatureAttributesChanged( QgsFeatureId id ) const { return mChangedAttributeValues.contains( id ); }

/** Returns a list of deleted attributes fields which are not committed. The list is kept sorted. */
/** Returns a list of deleted attributes fields which are not committed. The list is kept sorted.
* @see isAttributeDeleted()
*/
QgsAttributeList deletedAttributeIds() const { return mDeletedAttributeIds; }

/** Returns a list of added attributes fields which are not committed */
/** Returns true if the specified attribute has been deleted but not committed.
* @param index attribute index
* @note added in QGIS 3.0
* @see deletedAttributeIds()
*/
bool isAttributeDeleted( int index ) const { return mDeletedAttributeIds.contains( index ); }

/** Returns a list of added attributes fields which are not committed.
*/
QList<QgsField> addedAttributes() const { return mAddedAttributes; }

/** Returns a map of features with changed geometries which are not committed. */
/** Returns a map of features with changed geometries which are not committed.
* @see hasFeatureGeometryChange()
*/
QgsGeometryMap changedGeometries() const { return mChangedGeometries; }

/** Returns true if the specified feature ID has had its geometry changed but not committed.
* @param id feature ID
* @note added in QGIS 3.0
* @see changedGeometries()
*/
bool featureHasGeometryChange( QgsFeatureId id ) const { return mChangedGeometries.contains( id ); }
bool isFeatureGeometryChanged( QgsFeatureId id ) const { return mChangedGeometries.contains( id ); }

/** Returns a list of deleted feature IDs which are not committed. */
/** Returns a list of deleted feature IDs which are not committed.
* @see isFeatureDeleted()
*/
QgsFeatureIds deletedFeatureIds() const { return mDeletedFeatureIds; }

/** Returns true if the specified feature ID has been deleted but not committed.
* @param id feature ID
* @note added in QGIS 3.0
* @see deletedFeatureIds()
*/
bool isFeatureDeleted( QgsFeatureId id ) const { return mDeletedFeatureIds.contains( id ); }

//QString dumpEditBuffer();

protected slots:
Expand Down
6 changes: 3 additions & 3 deletions src/gui/attributetable/qgsattributetablefiltermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ bool QgsAttributeTableFilterModel::filterAcceptsRow( int sourceRow, const QModel
{
QgsFeatureId fid = masterModel()->rowToId( sourceRow );

if ( editBuffer->featureIsAdded( fid ) )
if ( editBuffer->isFeatureAdded( fid ) )
return true;

if ( editBuffer->featureHasAttributeChanges( fid ) )
if ( editBuffer->isFeatureAttributesChanged( fid ) )
return true;

if ( editBuffer->featureHasGeometryChange( fid ) )
if ( editBuffer->isFeatureGeometryChanged( fid ) )
return true;

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/attributetable/qgsfeaturelistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ QVariant QgsFeatureListModel::data( const QModelIndex &index, int role ) const

if ( editBuffer )
{
if ( editBuffer->featureIsAdded( feat.id() ) )
if ( editBuffer->isFeatureAdded( feat.id() ) )
{
featInfo.isNew = true;
}
if ( editBuffer->featureHasAttributeChanges( feat.id() ) )
if ( editBuffer->isFeatureAttributesChanged( feat.id() ) )
{
featInfo.isEdited = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
}
// geometry
const QgsAbstractGeometryV2 *geometry = 0;
if ( !mEditBuffer->featureIsAdded( fid ) )
if ( !mEditBuffer->isFeatureAdded( fid ) )
{
#ifdef QGISDEBUG
QgsDebugMsg( "the feature is missing in buffer addedFeatures :" );
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ ADD_PYTHON_TEST(PyQgsUnitTypes test_qgsunittypes.py)
ADD_PYTHON_TEST(PyQgsVectorColorRamp test_qgsvectorcolorramp.py)
ADD_PYTHON_TEST(PyQgsVectorFileWriter test_qgsvectorfilewriter.py)
ADD_PYTHON_TEST(PyQgsVectorLayer test_qgsvectorlayer.py)
ADD_PYTHON_TEST(PyQgsVectorLayerEditBuffer test_qgsvectorlayereditbuffer.py)
ADD_PYTHON_TEST(PyQgsZonalStatistics test_qgszonalstatistics.py)
ADD_PYTHON_TEST(PyQgsMapLayerRegistry test_qgsmaplayerregistry.py)
ADD_PYTHON_TEST(PyQgsVirtualLayerProvider test_provider_virtual.py)
Expand Down
Loading

0 comments on commit 0736bf7

Please sign in to comment.