Skip to content

Commit cea7eb8

Browse files
authored
Merge pull request #5119 from nyalldawson/layout_next3
[layouts] Undo/redo framework
2 parents 1caaa2e + 6471876 commit cea7eb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2491
-60
lines changed

python/console/console_settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131

3232
class optionsDialog(QDialog, Ui_SettingsDialogPythonConsole):
33+
3334
def __init__(self, parent):
3435
QDialog.__init__(self, parent)
3536
self.setWindowTitle(QCoreApplication.translate(

python/core/core_auto.sip

+3
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@
160160
%Include layout/qgslayoutmeasurementconverter.sip
161161
%Include layout/qgspagesizeregistry.sip
162162
%Include layout/qgslayoutpoint.sip
163+
%Include layout/qgslayoutserializableobject.sip
163164
%Include layout/qgslayoutsize.sip
164165
%Include layout/qgslayoutsnapper.sip
166+
%Include layout/qgslayoutundocommand.sip
167+
%Include layout/qgslayoutundostack.sip
165168
%Include layout/qgslayoututils.sip
166169
%Include metadata/qgslayermetadata.sip
167170
%Include metadata/qgslayermetadatavalidator.sip

python/core/layout/qgslayout.sip

+35-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010

11-
class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
11+
class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoObjectInterface
1212
{
1313
%Docstring
1414
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
@@ -39,8 +39,6 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
3939
called on the new layout.
4040
%End
4141

42-
~QgsLayout();
43-
4442
void initializeDefaults();
4543
%Docstring
4644
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
6765
.. seealso:: name()
6866
%End
6967

68+
69+
QgsLayoutItem *itemByUuid( const QString &uuid );
70+
%Docstring
71+
Returns the layout item with matching ``uuid`` unique identifier, or a None
72+
if a matching item could not be found.
73+
:rtype: QgsLayoutItem
74+
%End
75+
7076
void setUnits( QgsUnitTypes::LayoutUnit units );
7177
%Docstring
7278
Sets the native measurement ``units`` for the layout. These also form the default unit
@@ -247,6 +253,32 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
247253
method. Ownership of the item is transferred to the layout.
248254
%End
249255

256+
QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const;
257+
%Docstring
258+
Returns the layout's state encapsulated in a DOM element.
259+
.. seealso:: readXml()
260+
:rtype: QDomElement
261+
%End
262+
263+
bool readXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context );
264+
%Docstring
265+
Sets the collection's state from a DOM element. ``layoutElement`` is the DOM node corresponding to the layout.
266+
.. seealso:: writeXml()
267+
:rtype: bool
268+
%End
269+
270+
QgsLayoutUndoStack *undoStack();
271+
%Docstring
272+
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout
273+
and it's associated objects.
274+
:rtype: QgsLayoutUndoStack
275+
%End
276+
277+
278+
virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id = 0, QUndoCommand *parent = 0 ) /Factory/;
279+
280+
281+
250282
public slots:
251283

252284
void updateBounds();

python/core/layout/qgslayoutgridsettings.sip

+22-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010

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

30-
QgsLayoutGridSettings();
30+
QgsLayoutGridSettings( QgsLayout *layout );
3131
%Docstring
3232
Constructor for QgsLayoutGridSettings.
3333
%End
3434

35+
virtual QString stringType() const;
36+
virtual QgsLayout *layout();
37+
38+
3539
void setResolution( const QgsLayoutMeasurement &resolution );
3640
%Docstring
3741
Sets the page/snap grid ``resolution``.
@@ -92,6 +96,22 @@ class QgsLayoutGridSettings
9296
:rtype: Style
9397
%End
9498

99+
virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
100+
101+
%Docstring
102+
Stores the grid's state in a DOM element. The ``parentElement`` should refer to the parent layout's DOM element.
103+
.. seealso:: readXml()
104+
:rtype: bool
105+
%End
106+
107+
virtual bool readXml( const QDomElement &gridElement, const QDomDocument &document, const QgsReadWriteContext &context );
108+
109+
%Docstring
110+
Sets the grid's state from a DOM element. gridElement is the DOM node corresponding to the grid.
111+
.. seealso:: writeXml()
112+
:rtype: bool
113+
%End
114+
95115
};
96116

97117
/************************************************************************

python/core/layout/qgslayoutguidecollection.sip

+26-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class QgsLayoutGuide : QObject
132132

133133
};
134134

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

163+
virtual QString stringType() const;
164+
virtual QgsLayout *layout();
165+
166+
163167
virtual int rowCount( const QModelIndex & ) const;
164168

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

195+
void setGuideLayoutPosition( QgsLayoutGuide *guide, double position );
196+
%Docstring
197+
Sets the absolute ``position`` (in layout coordinates) for ``guide`` within the layout.
198+
%End
199+
191200
void clear();
192201
%Docstring
193202
Removes all guides from the collection.
@@ -233,6 +242,22 @@ class QgsLayoutGuideCollection : QAbstractTableModel
233242
.. seealso:: visible()
234243
%End
235244

245+
virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
246+
247+
%Docstring
248+
Stores the collection's state in a DOM element. The ``parentElement`` should refer to the parent layout's DOM element.
249+
.. seealso:: readXml()
250+
:rtype: bool
251+
%End
252+
253+
virtual bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context );
254+
255+
%Docstring
256+
Sets the collection's state from a DOM element. collectionElement is the DOM node corresponding to the collection.
257+
.. seealso:: writeXml()
258+
:rtype: bool
259+
%End
260+
236261
};
237262

238263

python/core/layout/qgslayoutitem.sip

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111

12-
class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
12+
class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInterface
1313
{
1414
%Docstring
1515
Base class for graphical items within a QgsLayout.
@@ -219,6 +219,9 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
219219
:rtype: bool
220220
%End
221221

222+
virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = 0 ) /Factory/;
223+
224+
222225
public slots:
223226

224227
virtual void refresh();

python/core/layout/qgslayoutitempage.sip

+13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ class QgsLayoutItemPage : QgsLayoutItem
3232
%Docstring
3333
Constructor for QgsLayoutItemPage, with the specified parent ``layout``.
3434
%End
35+
36+
static QgsLayoutItemPage *create( QgsLayout *layout, const QVariantMap &settings ) /Factory/;
37+
%Docstring
38+
Returns a new page item for the specified ``layout``.
39+
40+
The caller takes responsibility for deleting the returned object.
41+
:rtype: QgsLayoutItemPage
42+
%End
43+
44+
3545
virtual int type() const;
3646
virtual QString stringType() const;
3747

@@ -80,6 +90,9 @@ class QgsLayoutItemPage : QgsLayoutItem
8090
virtual void attemptResize( const QgsLayoutSize &size );
8191

8292

93+
virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = 0 ) /Factory/;
94+
95+
8396
public slots:
8497

8598
virtual void redraw();

python/core/layout/qgslayoutpagecollection.sip

+33-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111

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

2929
~QgsLayoutPageCollection();
3030

31-
QgsLayout *layout() const;
32-
%Docstring
33-
Returns the layout this collection belongs to.
34-
:rtype: QgsLayout
35-
%End
31+
virtual QString stringType() const;
32+
virtual QgsLayout *layout();
33+
3634

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

131+
QgsLayoutItemPage *takePage( QgsLayoutItemPage *page ) /TransferBack/;
132+
%Docstring
133+
Takes a ``page`` from the collection, returning ownership of the page to the caller.
134+
:rtype: QgsLayoutItemPage
135+
%End
136+
133137
void setPageStyleSymbol( QgsFillSymbol *symbol );
134138
%Docstring
135139
Sets the ``symbol`` to use for drawing pages in the collection.
@@ -211,6 +215,29 @@ class QgsLayoutPageCollection : QObject
211215
:rtype: float
212216
%End
213217

218+
virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
219+
220+
%Docstring
221+
Stores the collection's state in a DOM element. The ``parentElement`` should refer to the parent layout's DOM element.
222+
.. seealso:: readXml()
223+
:rtype: bool
224+
%End
225+
226+
virtual bool readXml( const QDomElement &collectionElement, const QDomDocument &document, const QgsReadWriteContext &context );
227+
228+
%Docstring
229+
Sets the collection's state from a DOM element. collectionElement is the DOM node corresponding to the collection.
230+
.. seealso:: writeXml()
231+
:rtype: bool
232+
%End
233+
234+
QgsLayoutGuideCollection &guides();
235+
%Docstring
236+
Returns a reference to the collection's guide collection, which manages page snap guides.
237+
:rtype: QgsLayoutGuideCollection
238+
%End
239+
240+
214241
public slots:
215242

216243
void redraw();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutserializableobject.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsLayoutSerializableObject : QgsLayoutUndoObjectInterface
14+
{
15+
%Docstring
16+
An interface for layout objects which can be stored and read from DOM elements.
17+
.. versionadded:: 3.0
18+
%End
19+
20+
%TypeHeaderCode
21+
#include "qgslayoutserializableobject.h"
22+
%End
23+
public:
24+
25+
virtual ~QgsLayoutSerializableObject();
26+
27+
virtual QString stringType() const = 0;
28+
%Docstring
29+
Return the object type as a string.
30+
31+
This string must be a unique, single word, character only representation of the item type, eg "LayoutScaleBar"
32+
:rtype: str
33+
%End
34+
35+
virtual QgsLayout *layout() = 0;
36+
%Docstring
37+
Returns the layout the object belongs to.
38+
:rtype: QgsLayout
39+
%End
40+
41+
virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
42+
%Docstring
43+
Stores the objects's state in a DOM element. The ``parentElement`` should refer to the parent layout's DOM element.
44+
.. seealso:: readXml()
45+
:rtype: bool
46+
%End
47+
48+
virtual bool readXml( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) = 0;
49+
%Docstring
50+
Sets the objects's state from a DOM element. ``element`` is the DOM node corresponding to the object.
51+
.. seealso:: writeXml()
52+
:rtype: bool
53+
%End
54+
55+
virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = 0 ) /Factory/;
56+
57+
58+
};
59+
60+
/************************************************************************
61+
* This file has been generated automatically from *
62+
* *
63+
* src/core/layout/qgslayoutserializableobject.h *
64+
* *
65+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
66+
************************************************************************/

0 commit comments

Comments
 (0)