Skip to content

Commit

Permalink
Added changeGeometry() method as have been suggested on mailing list.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@10701 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed May 2, 2009
1 parent cbc57dc commit c245c64
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -316,6 +316,10 @@ public:
/** Make layer editable */
bool startEditing();

/** change feature's geometry
@note added in version 1.2 */
bool changeGeometry(int fid, QgsGeometry* geom);

/** changed an attribute value (but does not commit it */
bool changeAttributeValue(int fid, int field, QVariant value, bool emitSignal = true);

Expand Down
3 changes: 1 addition & 2 deletions src/app/qgsmaptooldeletehole.cpp
Expand Up @@ -111,8 +111,7 @@ void QgsMapToolDeleteHole::deleteHole( int fId, int beforeVertexNr, QgsVectorLay

if (g->deleteHole( ringNum, partNum ))
{
vlayer->deleteFeature( fId );
vlayer->addFeature(f);
vlayer->changeGeometry( fId, g );
mCanvas->refresh();
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/qgsmaptooldeletepart.cpp
Expand Up @@ -106,8 +106,7 @@ void QgsMapToolDeletePart::deletePart( int fId, int beforeVertexNr, QgsVectorLay

if (g->deletePart( partNum ))
{
vlayer->deleteFeature( fId );
vlayer->addFeature(f);
vlayer->changeGeometry( fId, g );
mCanvas->refresh();
}
else
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgsmaptoolsimplify.cpp
Expand Up @@ -90,9 +90,8 @@ void QgsMapToolSimplify::storeSimplified()
{
QgsVectorLayer * vlayer = currentVectorLayer();
QgsSimplifyFeature::simplifyLine(mSelectedFeature, mTolerance);
// TODO(md): change geometry of feature instead of delete+add
vlayer->deleteFeature( mSelectedFeature.id() );
vlayer->addFeature(mSelectedFeature);

vlayer->changeGeometry( mSelectedFeature.id(), mSelectedFeature.geometry() );

mCanvas->refresh();
}
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2553,6 +2553,20 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
return true;
}


bool QgsVectorLayer::changeGeometry(int fid, QgsGeometry* geom)
{
if ( !mEditable || !mDataProvider )
{
return false;
}

mChangedGeometries[ fid ] = *geom;
setModified( true, true );
return true;
}


bool QgsVectorLayer::changeAttributeValue( int fid, int field, QVariant value, bool emitSignal )
{
if ( !isEditable() )
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -378,6 +378,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Make layer editable */
bool startEditing();

/** change feature's geometry
@note added in version 1.2 */
bool changeGeometry(int fid, QgsGeometry* geom);

/** changed an attribute value (but does not commit it) */
bool changeAttributeValue( int fid, int field, QVariant value, bool emitSignal = true );

Expand Down

0 comments on commit c245c64

Please sign in to comment.