Skip to content
Permalink
Browse files

Start work on undo/redo support for layouts

  • Loading branch information
nyalldawson committed Sep 1, 2017
1 parent 1589b4e commit 62dcd0dad529bc35257a29e3e7d40c448fe139b4
Showing with 1,292 additions and 16 deletions.
  1. +3 −0 python/core/core_auto.sip
  2. +12 −1 python/core/layout/qgslayout.sip
  3. +4 −1 python/core/layout/qgslayoutitem.sip
  4. +3 −0 python/core/layout/qgslayoutitempage.sip
  5. +83 −0 python/core/layout/qgslayoutitemundocommand.sip
  6. +4 −1 python/core/layout/qgslayoutserializableobject.sip
  7. +132 −0 python/core/layout/qgslayoutundocommand.sip
  8. +78 −0 python/core/layout/qgslayoutundostack.sip
  9. +25 −0 src/app/layout/qgslayoutdesignerdialog.cpp
  10. +4 −0 src/app/layout/qgslayoutdesignerdialog.h
  11. +6 −0 src/app/layout/qgslayoutguidewidget.cpp
  12. +2 −0 src/app/layout/qgslayoutpagepropertieswidget.cpp
  13. +7 −0 src/core/CMakeLists.txt
  14. +1 −1 src/core/composer/qgscomposerlabel.h
  15. +73 −7 src/core/layout/qgslayout.cpp
  16. +24 −1 src/core/layout/qgslayout.h
  17. +4 −0 src/core/layout/qgslayoutgridsettings.cpp
  18. +8 −0 src/core/layout/qgslayoutgridsettings.h
  19. +28 −1 src/core/layout/qgslayoutguidecollection.cpp
  20. +9 −0 src/core/layout/qgslayoutguidecollection.h
  21. +6 −0 src/core/layout/qgslayoutitem.cpp
  22. +4 −1 src/core/layout/qgslayoutitem.h
  23. +32 −0 src/core/layout/qgslayoutitempage.cpp
  24. +2 −0 src/core/layout/qgslayoutitempage.h
  25. +120 −0 src/core/layout/qgslayoutitemundocommand.cpp
  26. +65 −0 src/core/layout/qgslayoutitemundocommand.h
  27. +59 −0 src/core/layout/qgslayoutpagecollection.cpp
  28. +2 −0 src/core/layout/qgslayoutpagecollection.h
  29. +60 −0 src/core/layout/qgslayoutserializableobject.cpp
  30. +7 −2 src/core/layout/qgslayoutserializableobject.h
  31. +6 −0 src/core/layout/qgslayoutsnapper.cpp
  32. +10 −0 src/core/layout/qgslayoutsnapper.h
  33. +59 −0 src/core/layout/qgslayoutundocommand.cpp
  34. +142 −0 src/core/layout/qgslayoutundocommand.h
  35. +74 −0 src/core/layout/qgslayoutundostack.cpp
  36. +93 −0 src/core/layout/qgslayoutundostack.h
  37. +41 −0 src/ui/layout/qgslayoutdesignerbase.ui
@@ -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
@@ -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.
@@ -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:

@@ -9,7 +9,7 @@



class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInterface
{
%Docstring
Base class for graphical items within a QgsLayout.
@@ -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();
@@ -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();
@@ -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 *
************************************************************************/
@@ -10,7 +10,7 @@



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

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


};

/************************************************************************
@@ -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 *
************************************************************************/
@@ -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.
You can’t perform that action at this time.