Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added infrastructure for vector editing undo/redo functionality.
Note - when implementing edit tools for vector layer:
All editation should be done between beginEditCommand() and endEditCommand()
calls so that the operation are stored. 

Note - when doing changes inside QgsVectorLayer code:
When doing any changes inside QgsVectorLayer they should be done using edit*() functions
and _not_ directly e.g. mChangedGeometries[fid] = (...) otherwise the change won't be
stored in the undo stack and it would lead to invalid behaviour of undo.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10920 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 14, 2009
1 parent d88e175 commit 9156371
Show file tree
Hide file tree
Showing 9 changed files with 718 additions and 49 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsmaplayer.sip
Expand Up @@ -249,6 +249,9 @@ public:
*/
virtual QString saveNamedStyle( const QString theURI, bool & theResultFlag );

/** Return pointer to layer's undo stack */
QUndoStack* undoStack();

public slots:

/** Event handler for when a coordinate transform fails due to bad vertex error */
Expand Down
19 changes: 19 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -389,6 +389,25 @@ public:
*/
QgsVectorOverlay* findOverlayByType( const QString& typeName );


/**
* Create edit command for undo/redo operations
* @param text text which is to be displayed in undo window
*/
void beginEditCommand(QString text);

/** Finish edit command and add it to undo/redo stack */
void endEditCommand();

/** Destroy active command and deletes all changes in it */
void destroyEditCommand();

/** Execute undo operation. To be called only from QgsVectorLayerUndoCommand. */
// (not necessary) void undoEditCommand(QgsUndoCommand* cmd);

/** Execute redo operation. To be called only from QgsVectorLayerUndoCommand. */
// (not necessary) void redoEditCommand(QgsUndoCommand* cmd);

public slots:

/** Select feature by its ID, optionally emit signal selectionChanged() */
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -51,6 +51,7 @@ SET(QGIS_CORE_SRCS
qgsvectordataprovider.cpp
qgsvectorfilewriter.cpp
qgsvectorlayer.cpp
qgsvectorlayerundocommand.cpp
qgsvectoroverlay.cpp

composer/qgscomposeritem.cpp
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -715,3 +715,11 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag

return myErrorMessage;
}




QUndoStack* QgsMapLayer::undoStack()
{
return &mUndoStack;
}
6 changes: 6 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -23,6 +23,7 @@
#include <map>

#include <QObject>
#include <QUndoStack>

#include "qgsrectangle.h"

Expand Down Expand Up @@ -259,6 +260,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
virtual bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const = 0;

/** Return pointer to layer's undo stack */
QUndoStack* undoStack();

public slots:

/** Event handler for when a coordinate transform fails due to bad vertex error */
Expand Down Expand Up @@ -356,6 +360,8 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** A flag that tells us whether to use the above vars to restrict layer visibility */
bool mScaleBasedVisibility;

QUndoStack mUndoStack;

};

#endif

0 comments on commit 9156371

Please sign in to comment.