Skip to content

Commit

Permalink
Start work on undo/redo support for layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 4, 2017
1 parent 1589b4e commit 62dcd0d
Show file tree
Hide file tree
Showing 37 changed files with 1,292 additions and 16 deletions.
3 changes: 3 additions & 0 deletions python/core/core_auto.sip
Expand Up @@ -156,13 +156,16 @@
%Include composer/qgspaperitem.sip
%Include layout/qgslayoutcontext.sip
%Include layout/qgslayoutgridsettings.sip
%Include layout/qgslayoutitemundocommand.sip
%Include layout/qgslayoutmeasurement.sip
%Include layout/qgslayoutmeasurementconverter.sip
%Include layout/qgspagesizeregistry.sip
%Include layout/qgslayoutpoint.sip
%Include layout/qgslayoutserializableobject.sip
%Include layout/qgslayoutsize.sip
%Include layout/qgslayoutsnapper.sip
%Include layout/qgslayoutundocommand.sip
%Include layout/qgslayoutundostack.sip
%Include layout/qgslayoututils.sip
%Include metadata/qgslayermetadata.sip
%Include metadata/qgslayermetadatavalidator.sip
Expand Down
13 changes: 12 additions & 1 deletion python/core/layout/qgslayout.sip
Expand Up @@ -8,7 +8,7 @@



class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoObjectInterface
{
%Docstring
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Expand Down Expand Up @@ -269,6 +269,17 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
:rtype: bool
%End

QgsLayoutUndoStack *undoStack();
%Docstring
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout
and it's associated objects.
:rtype: QgsLayoutUndoStack
%End


virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id = 0, QUndoCommand *parent = 0 ) /Factory/;



public slots:

Expand Down
5 changes: 4 additions & 1 deletion python/core/layout/qgslayoutitem.sip
Expand Up @@ -9,7 +9,7 @@



class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInterface
{
%Docstring
Base class for graphical items within a QgsLayout.
Expand Down Expand Up @@ -219,6 +219,9 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
:rtype: bool
%End

virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = 0 ) /Factory/;


public slots:

virtual void refresh();
Expand Down
3 changes: 3 additions & 0 deletions python/core/layout/qgslayoutitempage.sip
Expand Up @@ -90,6 +90,9 @@ class QgsLayoutItemPage : QgsLayoutItem
virtual void attemptResize( const QgsLayoutSize &size );


virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = 0 ) /Factory/;


public slots:

virtual void redraw();
Expand Down
83 changes: 83 additions & 0 deletions python/core/layout/qgslayoutitemundocommand.sip
@@ -0,0 +1,83 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemundocommand.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsLayoutItemUndoCommand: QgsAbstractLayoutUndoCommand
{
%Docstring
*************************************************************************
*
This program is free software; you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by *
the Free Software Foundation; either version 2 of the License, or *
(at your option) any later version. *
*
**************************************************************************
%End

%TypeHeaderCode
#include "qgslayoutitemundocommand.h"
%End
public:

QgsLayoutItemUndoCommand( QgsLayoutItem *item, const QString &text, int id = 0, QUndoCommand *parent /TransferThis/ = 0 );

virtual bool mergeWith( const QUndoCommand *command );


QgsLayout *layout() const;
%Docstring
:rtype: QgsLayout
%End

QString itemUuid() const;
%Docstring
:rtype: str
%End

protected:

virtual void saveState( QDomDocument &stateDoc ) const;

virtual void restoreState( QDomDocument &stateDoc );


virtual QgsLayoutItem *recreateItem( int itemType, QgsLayout *layout ) /Factory/;
%Docstring
:rtype: QgsLayoutItem
%End

};

class QgsLayoutItemDeleteUndoCommand: QgsLayoutItemUndoCommand
{

%TypeHeaderCode
#include "qgslayoutitemundocommand.h"
%End
public:

QgsLayoutItemDeleteUndoCommand( QgsLayoutItem *item, const QString &text, int id = 0, QUndoCommand *parent /TransferThis/ = 0 );
virtual bool mergeWith( const QUndoCommand *command );

virtual void redo();


};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemundocommand.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
5 changes: 4 additions & 1 deletion python/core/layout/qgslayoutserializableobject.sip
Expand Up @@ -10,7 +10,7 @@



class QgsLayoutSerializableObject
class QgsLayoutSerializableObject : QgsLayoutUndoObjectInterface
{
%Docstring
An interface for layout objects which can be stored and read from DOM elements.
Expand Down Expand Up @@ -52,6 +52,9 @@ class QgsLayoutSerializableObject
:rtype: bool
%End

virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = 0 ) /Factory/;


};

/************************************************************************
Expand Down
132 changes: 132 additions & 0 deletions python/core/layout/qgslayoutundocommand.sip
@@ -0,0 +1,132 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutundocommand.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsAbstractLayoutUndoCommand: QUndoCommand
{
%Docstring
Base class for commands to undo/redo layout and layout object changes.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutundocommand.h"
%End
public:

QgsAbstractLayoutUndoCommand( const QString &text, int id = 0, QUndoCommand *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsLayoutUndoCommand.
The ``id`` argument can be used to specify an id number for the source event - this is used to determine whether QUndoCommand
command compression can apply to the command.
%End

virtual void undo();

virtual void redo();

virtual int id() const;

void saveBeforeState();
%Docstring
Saves current layout state as before state.
.. seealso:: beforeState()
.. seealso:: saveAfterState()
%End

void saveAfterState();
%Docstring
Saves current layout state as after state.
.. seealso:: afterState()
.. seealso:: saveBeforeState()
%End

QDomDocument beforeState() const;
%Docstring
Returns the before state for the layout.
.. seealso:: saveBeforeState()
.. seealso:: afterState()
:rtype: QDomDocument
%End

QDomDocument afterState() const;
%Docstring
Returns the after state for the layout.
.. seealso:: saveAfterState()
.. seealso:: beforeState()
:rtype: QDomDocument
%End

virtual bool containsChange() const;
%Docstring
Returns true if both the before and after states are valid and different.
:rtype: bool
%End

protected:

virtual void saveState( QDomDocument &stateDoc ) const = 0;
%Docstring
Saves the state of the object to the specified ``stateDoc``.

Subclasses must implement this to handle encapsulating their current state into a DOM document.

.. seealso:: restoreState()
%End

virtual void restoreState( QDomDocument &stateDoc ) = 0;
%Docstring
Restores the state of the object from the specified ``stateDoc``.

Subclasses must implement this to handle restoring their current state from the encapsulated state.

.. seealso:: saveState()
%End

void setAfterState( const QDomDocument &stateDoc );
%Docstring
Manually sets the after state for the command. Generally this should not be called directly.
%End


};

class QgsLayoutUndoObjectInterface
{
%Docstring
Interface for layout objects which support undo/redo commands.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutundocommand.h"
%End
public:

virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id = 0, QUndoCommand *parent = 0 ) = 0 /Factory/;
%Docstring
Creates a new layout undo command with the specified ``text`` and ``parent``.

The ``id`` argument can be used to specify an id number for the source event - this is used to determine whether QUndoCommand
command compression can apply to the command.
:rtype: QgsAbstractLayoutUndoCommand
%End
};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutundocommand.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
78 changes: 78 additions & 0 deletions python/core/layout/qgslayoutundostack.sip
@@ -0,0 +1,78 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutundostack.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsLayoutUndoStack
{
%Docstring
An undo stack for QgsLayouts.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutundostack.h"
%End
public:

QgsLayoutUndoStack( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutUndoStack, for the specified parent ``layout``.
%End

void beginMacro( const QString &commandText );

void endMacro();

void beginCommand( QgsLayoutUndoObjectInterface *object, const QString &commandText, int id = 0 );
%Docstring
Begins a new undo command for the specified ``object``.

This must be followed by a call to endCommand() or cancelCommand() after the desired changes
have been made to ``object``.

The ``id`` argument can be used to specify an id number for the source event - this is used to determine whether QUndoCommand
command compression can apply to the command.

.. seealso:: endCommand()
.. seealso:: cancelCommand()
%End

void endCommand();
%Docstring
Saves final state of an object and pushes the active command to the undo history.
.. seealso:: beginCommand()
.. seealso:: cancelCommand()
%End

void cancelCommand();
%Docstring
Cancels the active command, discarding it without pushing to the undo history.
.. seealso:: endCommand()
.. seealso:: cancelCommand()
%End

QUndoStack *stack();
%Docstring
Returns a pointer to the internal QUndoStack.
:rtype: QUndoStack
%End

private:
QgsLayoutUndoStack( const QgsLayoutUndoStack &other );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutundostack.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

0 comments on commit 62dcd0d

Please sign in to comment.