Skip to content

Commit 9156371

Browse files
author
wonder
committed
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
1 parent d88e175 commit 9156371

9 files changed

+718
-49
lines changed

python/core/qgsmaplayer.sip

+3
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ public:
249249
*/
250250
virtual QString saveNamedStyle( const QString theURI, bool & theResultFlag );
251251

252+
/** Return pointer to layer's undo stack */
253+
QUndoStack* undoStack();
254+
252255
public slots:
253256

254257
/** Event handler for when a coordinate transform fails due to bad vertex error */

python/core/qgsvectorlayer.sip

+19
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,25 @@ public:
389389
*/
390390
QgsVectorOverlay* findOverlayByType( const QString& typeName );
391391

392+
393+
/**
394+
* Create edit command for undo/redo operations
395+
* @param text text which is to be displayed in undo window
396+
*/
397+
void beginEditCommand(QString text);
398+
399+
/** Finish edit command and add it to undo/redo stack */
400+
void endEditCommand();
401+
402+
/** Destroy active command and deletes all changes in it */
403+
void destroyEditCommand();
404+
405+
/** Execute undo operation. To be called only from QgsVectorLayerUndoCommand. */
406+
// (not necessary) void undoEditCommand(QgsUndoCommand* cmd);
407+
408+
/** Execute redo operation. To be called only from QgsVectorLayerUndoCommand. */
409+
// (not necessary) void redoEditCommand(QgsUndoCommand* cmd);
410+
392411
public slots:
393412

394413
/** Select feature by its ID, optionally emit signal selectionChanged() */

src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SET(QGIS_CORE_SRCS
5151
qgsvectordataprovider.cpp
5252
qgsvectorfilewriter.cpp
5353
qgsvectorlayer.cpp
54+
qgsvectorlayerundocommand.cpp
5455
qgsvectoroverlay.cpp
5556

5657
composer/qgscomposeritem.cpp

src/core/qgsmaplayer.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,11 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
715715

716716
return myErrorMessage;
717717
}
718+
719+
720+
721+
722+
QUndoStack* QgsMapLayer::undoStack()
723+
{
724+
return &mUndoStack;
725+
}

src/core/qgsmaplayer.h

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <map>
2424

2525
#include <QObject>
26+
#include <QUndoStack>
2627

2728
#include "qgsrectangle.h"
2829

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

263+
/** Return pointer to layer's undo stack */
264+
QUndoStack* undoStack();
265+
262266
public slots:
263267

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

363+
QUndoStack mUndoStack;
364+
359365
};
360366

361367
#endif

0 commit comments

Comments
 (0)