Skip to content
Permalink
Browse files

Merge pull request #5119 from nyalldawson/layout_next3

[layouts] Undo/redo framework
  • Loading branch information
nyalldawson committed Sep 10, 2017
2 parents 1caaa2e + 6471876 commit cea7eb8be551feb622a6597a9bcf41a720ccdc80
Showing with 2,491 additions and 60 deletions.
  1. +1 −0 python/console/console_settings.py
  2. +3 −0 python/core/core_auto.sip
  3. +35 −3 python/core/layout/qgslayout.sip
  4. +22 −2 python/core/layout/qgslayoutgridsettings.sip
  5. +26 −1 python/core/layout/qgslayoutguidecollection.sip
  6. +4 −1 python/core/layout/qgslayoutitem.sip
  7. +13 −0 python/core/layout/qgslayoutitempage.sip
  8. +33 −6 python/core/layout/qgslayoutpagecollection.sip
  9. +66 −0 python/core/layout/qgslayoutserializableobject.sip
  10. +21 −1 python/core/layout/qgslayoutsnapper.sip
  11. +132 −0 python/core/layout/qgslayoutundocommand.sip
  12. +99 −0 python/core/layout/qgslayoutundostack.sip
  13. +31 −0 src/app/layout/qgslayoutdesignerdialog.cpp
  14. +4 −0 src/app/layout/qgslayoutdesignerdialog.h
  15. +6 −0 src/app/layout/qgslayoutguidewidget.cpp
  16. +2 −4 src/app/layout/qgslayoutpagepropertieswidget.cpp
  17. +9 −0 src/core/CMakeLists.txt
  18. +1 −1 src/core/composer/qgscomposerlabel.cpp
  19. +1 −1 src/core/composer/qgscomposerlabel.h
  20. +125 −9 src/core/layout/qgslayout.cpp
  21. +60 −4 src/core/layout/qgslayout.h
  22. +66 −1 src/core/layout/qgslayoutgridsettings.cpp
  23. +31 −4 src/core/layout/qgslayoutgridsettings.h
  24. +108 −0 src/core/layout/qgslayoutguidecollection.cpp
  25. +34 −1 src/core/layout/qgslayoutguidecollection.h
  26. +6 −0 src/core/layout/qgslayoutitem.cpp
  27. +4 −1 src/core/layout/qgslayoutitem.h
  28. +38 −0 src/core/layout/qgslayoutitempage.cpp
  29. +11 −0 src/core/layout/qgslayoutitempage.h
  30. +2 −1 src/core/layout/qgslayoutitemregistry.cpp
  31. +123 −0 src/core/layout/qgslayoutitemundocommand.cpp
  32. +112 −0 src/core/layout/qgslayoutitemundocommand.h
  33. +118 −1 src/core/layout/qgslayoutpagecollection.cpp
  34. +38 −5 src/core/layout/qgslayoutpagecollection.h
  35. +81 −0 src/core/layout/qgslayoutserializableobject.cpp
  36. +73 −0 src/core/layout/qgslayoutserializableobject.h
  37. +55 −0 src/core/layout/qgslayoutsnapper.cpp
  38. +31 −4 src/core/layout/qgslayoutsnapper.h
  39. +59 −0 src/core/layout/qgslayoutundocommand.cpp
  40. +142 −0 src/core/layout/qgslayoutundocommand.h
  41. +74 −0 src/core/layout/qgslayoutundostack.cpp
  42. +114 −0 src/core/layout/qgslayoutundostack.h
  43. +7 −4 src/gui/layout/qgslayoutruler.cpp
  44. +41 −0 src/ui/layout/qgslayoutdesignerbase.ui
  45. +57 −0 tests/src/core/testqgslayout.cpp
  46. +1 −0 tests/src/python/CMakeLists.txt
  47. +83 −0 tests/src/python/test_qgslayout.py
  48. +72 −2 tests/src/python/test_qgslayoutgridsettings.py
  49. +51 −1 tests/src/python/test_qgslayoutguides.py
  50. +127 −1 tests/src/python/test_qgslayoutpagecollection.py
  51. +38 −1 tests/src/python/test_qgslayoutsnapper.py
@@ -30,6 +30,7 @@


class optionsDialog(QDialog, Ui_SettingsDialogPythonConsole):

def __init__(self, parent):
QDialog.__init__(self, parent)
self.setWindowTitle(QCoreApplication.translate(
@@ -160,8 +160,11 @@
%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.
@@ -39,8 +39,6 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
called on the new layout.
%End

~QgsLayout();

void initializeDefaults();
%Docstring
Initializes an empty layout, e.g. by adding a default page to the layout. This should be called after creating
@@ -67,6 +65,14 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
.. seealso:: name()
%End


QgsLayoutItem *itemByUuid( const QString &uuid );
%Docstring
Returns the layout item with matching ``uuid`` unique identifier, or a None
if a matching item could not be found.
:rtype: QgsLayoutItem
%End

void setUnits( QgsUnitTypes::LayoutUnit units );
%Docstring
Sets the native measurement ``units`` for the layout. These also form the default unit
@@ -247,6 +253,32 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
method. Ownership of the item is transferred to the layout.
%End

QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const;
%Docstring
Returns the layout's state encapsulated in a DOM element.
.. seealso:: readXml()
:rtype: QDomElement
%End

bool readXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context );
%Docstring
Sets the collection's state from a DOM element. ``layoutElement`` is the DOM node corresponding to the layout.
.. seealso:: writeXml()
: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:

void updateBounds();
@@ -8,7 +8,7 @@



class QgsLayoutGridSettings
class QgsLayoutGridSettings : QgsLayoutSerializableObject
{
%Docstring
Contains settings relating to the appearance, spacing and offset for layout grids.
@@ -27,11 +27,15 @@ class QgsLayoutGridSettings
StyleCrosses
};

QgsLayoutGridSettings();
QgsLayoutGridSettings( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutGridSettings.
%End

virtual QString stringType() const;
virtual QgsLayout *layout();


void setResolution( const QgsLayoutMeasurement &resolution );
%Docstring
Sets the page/snap grid ``resolution``.
@@ -92,6 +96,22 @@ class QgsLayoutGridSettings
:rtype: Style
%End

virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;

%Docstring
Stores the grid's state in a DOM element. The ``parentElement`` should refer to the parent layout's DOM element.
.. seealso:: readXml()
:rtype: bool
%End

virtual bool readXml( const QDomElement &gridElement, const QDomDocument &document, const QgsReadWriteContext &context );

%Docstring
Sets the grid's state from a DOM element. gridElement is the DOM node corresponding to the grid.
.. seealso:: writeXml()
:rtype: bool
%End

};

/************************************************************************
@@ -132,7 +132,7 @@ class QgsLayoutGuide : QObject

};

class QgsLayoutGuideCollection : QAbstractTableModel
class QgsLayoutGuideCollection : QAbstractTableModel, QgsLayoutSerializableObject
{
%Docstring
Stores and manages the snap guides used by a layout.
@@ -160,6 +160,10 @@ class QgsLayoutGuideCollection : QAbstractTableModel
%End
~QgsLayoutGuideCollection();

virtual QString stringType() const;
virtual QgsLayout *layout();


virtual int rowCount( const QModelIndex & ) const;

virtual int columnCount( const QModelIndex & ) const;
@@ -188,6 +192,11 @@ class QgsLayoutGuideCollection : QAbstractTableModel
.. seealso:: clear()
%End

void setGuideLayoutPosition( QgsLayoutGuide *guide, double position );
%Docstring
Sets the absolute ``position`` (in layout coordinates) for ``guide`` within the layout.
%End

void clear();
%Docstring
Removes all guides from the collection.
@@ -233,6 +242,22 @@ class QgsLayoutGuideCollection : QAbstractTableModel
.. seealso:: visible()
%End

virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;

%Docstring
Stores the collection's state in a DOM element. The ``parentElement`` should refer to the parent layout's DOM element.
.. seealso:: readXml()
:rtype: bool
%End

virtual bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context );

%Docstring
Sets the collection's state from a DOM element. collectionElement is the DOM node corresponding to the collection.
.. seealso:: writeXml()
:rtype: bool
%End

};


@@ -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();
@@ -32,6 +32,16 @@ class QgsLayoutItemPage : QgsLayoutItem
%Docstring
Constructor for QgsLayoutItemPage, with the specified parent ``layout``.
%End

static QgsLayoutItemPage *create( QgsLayout *layout, const QVariantMap &settings ) /Factory/;
%Docstring
Returns a new page item for the specified ``layout``.

The caller takes responsibility for deleting the returned object.
:rtype: QgsLayoutItemPage
%End


virtual int type() const;
virtual QString stringType() const;

@@ -80,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();
@@ -9,7 +9,7 @@



class QgsLayoutPageCollection : QObject
class QgsLayoutPageCollection : QObject, QgsLayoutSerializableObject
{
%Docstring
A manager for a collection of pages in a layout.
@@ -28,11 +28,9 @@ class QgsLayoutPageCollection : QObject

~QgsLayoutPageCollection();

QgsLayout *layout() const;
%Docstring
Returns the layout this collection belongs to.
:rtype: QgsLayout
%End
virtual QString stringType() const;
virtual QgsLayout *layout();


QList< QgsLayoutItemPage * > pages();
%Docstring
@@ -130,6 +128,12 @@ class QgsLayoutPageCollection : QObject
Calling deletePage() automatically triggers a reflow() of pages.
%End

QgsLayoutItemPage *takePage( QgsLayoutItemPage *page ) /TransferBack/;
%Docstring
Takes a ``page`` from the collection, returning ownership of the page to the caller.
:rtype: QgsLayoutItemPage
%End

void setPageStyleSymbol( QgsFillSymbol *symbol );
%Docstring
Sets the ``symbol`` to use for drawing pages in the collection.
@@ -211,6 +215,29 @@ class QgsLayoutPageCollection : QObject
:rtype: float
%End

virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;

%Docstring
Stores the collection's state in a DOM element. The ``parentElement`` should refer to the parent layout's DOM element.
.. seealso:: readXml()
:rtype: bool
%End

virtual bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context );

%Docstring
Sets the collection's state from a DOM element. collectionElement is the DOM node corresponding to the collection.
.. seealso:: writeXml()
:rtype: bool
%End

QgsLayoutGuideCollection &guides();
%Docstring
Returns a reference to the collection's guide collection, which manages page snap guides.
:rtype: QgsLayoutGuideCollection
%End


public slots:

void redraw();
@@ -0,0 +1,66 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutserializableobject.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsLayoutSerializableObject : QgsLayoutUndoObjectInterface
{
%Docstring
An interface for layout objects which can be stored and read from DOM elements.
.. versionadded:: 3.0
%End

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

virtual ~QgsLayoutSerializableObject();

virtual QString stringType() const = 0;
%Docstring
Return the object type as a string.

This string must be a unique, single word, character only representation of the item type, eg "LayoutScaleBar"
:rtype: str
%End

virtual QgsLayout *layout() = 0;
%Docstring
Returns the layout the object belongs to.
:rtype: QgsLayout
%End

virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
%Docstring
Stores the objects's state in a DOM element. The ``parentElement`` should refer to the parent layout's DOM element.
.. seealso:: readXml()
:rtype: bool
%End

virtual bool readXml( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) = 0;
%Docstring
Sets the objects's state from a DOM element. ``element`` is the DOM node corresponding to the object.
.. seealso:: writeXml()
:rtype: bool
%End

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


};

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

0 comments on commit cea7eb8

Please sign in to comment.
You can’t perform that action at this time.