Skip to content

Commit 62a5679

Browse files
committed
Port item model from composer to layouts
1 parent b494a71 commit 62a5679

16 files changed

+2609
-9
lines changed

python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@
405405
%Include layout/qgslayoutitempage.sip
406406
%Include layout/qgslayoutitemregistry.sip
407407
%Include layout/qgslayoutitemshape.sip
408+
%Include layout/qgslayoutmodel.sip
408409
%Include layout/qgslayoutpagecollection.sip
409410
%Include layout/qgslayoutobject.sip
410411
%Include symbology/qgscptcityarchive.sip

python/core/layout/qgslayout.sip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
4141
called on the new layout.
4242
%End
4343

44+
~QgsLayout();
45+
4446
void initializeDefaults();
4547
%Docstring
4648
Initializes an empty layout, e.g. by adding a default page to the layout. This should be called after creating
@@ -54,6 +56,12 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
5456
:rtype: QgsProject
5557
%End
5658

59+
QgsLayoutModel *itemsModel();
60+
%Docstring
61+
Returns the items model attached to the layout.
62+
:rtype: QgsLayoutModel
63+
%End
64+
5765
QString name() const;
5866
%Docstring
5967
Returns the layout's name.
@@ -291,6 +299,12 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
291299
method. Ownership of the item is transferred to the layout.
292300
%End
293301

302+
void removeLayoutItem( QgsLayoutItem *item );
303+
%Docstring
304+
Removes an ``item`` from the layout. This should be called instead of the base class removeItem()
305+
method.
306+
%End
307+
294308
QDomElement writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const;
295309
%Docstring
296310
Returns the layout's state encapsulated in a DOM element.

python/core/layout/qgslayoutitem.sip

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
5252
LowerRight,
5353
};
5454

55-
explicit QgsLayoutItem( QgsLayout *layout );
55+
explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
5656
%Docstring
5757
Constructor for QgsLayoutItem, with the specified parent ``layout``.
58+
59+
If ``manageZValue`` is true, the z-Value of this item will be managed by the layout.
60+
Generally this is the desired behavior.
5861
%End
5962

60-
virtual int type() const = 0;
63+
~QgsLayoutItem();
64+
65+
virtual int type() const;
66+
6167
%Docstring
6268
Return correct graphics item type
6369
.. seealso:: stringType()

python/core/layout/qgslayoutmodel.sip

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutmodel.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
15+
class QgsLayoutModel: QAbstractItemModel
16+
{
17+
%Docstring
18+
19+
A model for items attached to a layout. The model also maintains the z-order for the
20+
layout, and must be notified whenever item stacking changes.
21+
22+
Internally, QgsLayoutModel maintains two lists. One contains a complete list of all items for
23+
the layout, ordered by their position within the z-order stack.
24+
25+
The second list contains only items which are currently displayed in the layout's scene.
26+
It is used as a cache of the last known stacking order, so that the model can compare the current
27+
stacking of items in the layout to the last known state, and emit the corresponding signals
28+
as required.
29+
30+
.. versionadded:: 3.0
31+
%End
32+
33+
%TypeHeaderCode
34+
#include "qgslayoutmodel.h"
35+
%End
36+
public:
37+
38+
enum Columns
39+
{
40+
Visibility,
41+
LockStatus,
42+
ItemId,
43+
};
44+
45+
explicit QgsLayoutModel( QgsLayout *layout, QObject *parent /TransferThis/ = 0 );
46+
%Docstring
47+
Constructor for a QgsLayoutModel attached to the specified ``layout``.
48+
%End
49+
50+
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
51+
52+
virtual QModelIndex parent( const QModelIndex &index ) const;
53+
54+
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
55+
56+
virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
57+
58+
virtual QVariant data( const QModelIndex &index, int role ) const;
59+
60+
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
61+
62+
virtual bool setData( const QModelIndex &index, const QVariant &value, int role );
63+
64+
virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
65+
66+
virtual Qt::DropActions supportedDropActions() const;
67+
68+
virtual QStringList mimeTypes() const;
69+
virtual QMimeData *mimeData( const QModelIndexList &indexes ) const;
70+
virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
71+
72+
virtual bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
73+
74+
75+
void clear();
76+
%Docstring
77+
Clears all items from z-order list and resets the model
78+
%End
79+
80+
int zOrderListSize() const;
81+
%Docstring
82+
Returns the size of the z-order list.
83+
:rtype: int
84+
%End
85+
86+
void rebuildZList();
87+
%Docstring
88+
Rebuilds the z-order list, based on the current stacking of items in the layout.
89+
This method should be called after adding multiple items to the layout.
90+
%End
91+
92+
void addItemAtTop( QgsLayoutItem *item );
93+
%Docstring
94+
Adds an ``item`` to the top of the layout z stack. The item must not already exist in the z-order list.
95+
.. seealso:: reorderItemToTop()
96+
%End
97+
98+
void removeItem( QgsLayoutItem *item );
99+
%Docstring
100+
Removes an ``item`` from the z-order list.
101+
%End
102+
103+
bool reorderItemUp( QgsLayoutItem *item );
104+
%Docstring
105+
Moves an ``item`` up the z-order list.
106+
107+
Returns true if ``item`` was moved. Returns false if ``item`` was not found
108+
in z-order list or was already at the top of the z-order list.
109+
110+
.. seealso:: reorderItemDown()
111+
.. seealso:: reorderItemToTop()
112+
.. seealso:: reorderItemToBottom()
113+
:rtype: bool
114+
%End
115+
116+
bool reorderItemDown( QgsLayoutItem *item );
117+
%Docstring
118+
Moves an ``item`` down the z-order list.
119+
120+
Returns true if ``item`` was moved. Returns false if ``item`` was not found
121+
in z-order list or was already at the bottom of the z-order list.
122+
123+
.. seealso:: reorderItemUp()
124+
.. seealso:: reorderItemToTop()
125+
.. seealso:: reorderItemToBottom()
126+
:rtype: bool
127+
%End
128+
129+
bool reorderItemToTop( QgsLayoutItem *item );
130+
%Docstring
131+
Moves an ``item`` to the top of the z-order list.
132+
133+
Returns true if ``item`` was moved. Returns false if ``item`` was not found
134+
in z-order list or was already at the top of the z-order list.
135+
136+
.. seealso:: reorderItemUp()
137+
.. seealso:: reorderItemDown()
138+
.. seealso:: reorderItemToBottom()
139+
:rtype: bool
140+
%End
141+
142+
bool reorderItemToBottom( QgsLayoutItem *item );
143+
%Docstring
144+
Moves an ``item`` to the bottom of the z-order list.
145+
146+
Returns true if ``item`` was moved. Returns false if ``item`` was not found
147+
in z-order list or was already at the bottom of the z-order list.
148+
149+
.. seealso:: reorderItemUp()
150+
.. seealso:: reorderItemDown()
151+
.. seealso:: reorderItemToTop()
152+
:rtype: bool
153+
%End
154+
155+
QgsLayoutItem *findItemAbove( QgsLayoutItem *item ) const;
156+
%Docstring
157+
Finds the next layout item above an ``item``, where ``item`` is
158+
the item to search above.
159+
160+
If no items were found, a None will be returned.
161+
162+
.. seealso:: findItemBelow()
163+
:rtype: QgsLayoutItem
164+
%End
165+
166+
QgsLayoutItem *findItemBelow( QgsLayoutItem *item ) const;
167+
%Docstring
168+
Finds the next layout item below an ``item``, where ``item``
169+
is the item to search below.
170+
171+
If no items were found, a None will be returned.
172+
173+
.. seealso:: findItemAbove()
174+
:rtype: QgsLayoutItem
175+
%End
176+
177+
QList<QgsLayoutItem *> &zOrderList();
178+
%Docstring
179+
Returns the item z-order list.
180+
:rtype: list of QgsLayoutItem
181+
%End
182+
183+
void setItemRemoved( QgsLayoutItem *item );
184+
%Docstring
185+
Marks an ``item`` as removed from the layout. This must be called whenever an item
186+
is about to be removed from the layout.
187+
%End
188+
189+
190+
void updateItemDisplayName( QgsLayoutItem *item );
191+
%Docstring
192+
Must be called when an ``item``'s display name is modified.
193+
194+
.. seealso:: updateItemLockStatus()
195+
.. seealso:: updateItemVisibility()
196+
.. seealso:: updateItemSelectStatus()
197+
%End
198+
199+
void updateItemLockStatus( QgsLayoutItem *item );
200+
%Docstring
201+
Must be called when an ``item``'s lock status changes.
202+
.. seealso:: updateItemDisplayName()
203+
.. seealso:: updateItemVisibility()
204+
.. seealso:: updateItemSelectStatus()
205+
%End
206+
207+
void updateItemVisibility( QgsLayoutItem *item );
208+
%Docstring
209+
Must be called when an ``item``'s visibility changes.
210+
.. seealso:: updateItemDisplayName()
211+
.. seealso:: updateItemLockStatus()
212+
.. seealso:: updateItemSelectStatus()
213+
%End
214+
215+
void updateItemSelectStatus( QgsLayoutItem *item );
216+
%Docstring
217+
Must be called when an ``item``'s selection status changes.
218+
.. seealso:: updateItemDisplayName()
219+
.. seealso:: updateItemVisibility()
220+
.. seealso:: updateItemLockStatus()
221+
%End
222+
223+
QModelIndex indexForItem( QgsLayoutItem *item, const int column = 0 );
224+
%Docstring
225+
Returns the QModelIndex corresponding to a QgsLayoutItem ``item`` and \column, if possible.
226+
:rtype: QModelIndex
227+
%End
228+
229+
public slots:
230+
231+
void setSelected( const QModelIndex &index );
232+
%Docstring
233+
Sets an item as the current selection from a QModelIndex ``index``.
234+
%End
235+
236+
};
237+
238+
239+
class QgsLayoutProxyModel: QSortFilterProxyModel
240+
{
241+
%Docstring
242+
Allows for filtering a QgsLayoutModel by item type.
243+
.. versionadded:: 3.0
244+
%End
245+
246+
%TypeHeaderCode
247+
#include "qgslayoutmodel.h"
248+
%End
249+
public:
250+
251+
QgsLayoutProxyModel( QgsLayout *layout, QObject *parent /TransferThis/ = 0 );
252+
%Docstring
253+
Constructor for QgsLayoutProxyModelm, attached to the specified ``layout``.
254+
%End
255+
256+
QgsLayoutItemRegistry::ItemType filterType() const;
257+
%Docstring
258+
Returns the current item type filter, or QgsLayoutItemRegistry.LayoutItem if no
259+
item type filter is set.
260+
.. seealso:: setFilterType()
261+
:rtype: QgsLayoutItemRegistry.ItemType
262+
%End
263+
264+
void setFilterType( QgsLayoutItemRegistry::ItemType filter );
265+
%Docstring
266+
Sets the item type ``filter``. Only matching item types will be shown.
267+
Set ``filter`` to QgsLayoutItemRegistry.LayoutItem to show all
268+
item types.
269+
.. seealso:: filterType()
270+
%End
271+
272+
void setExceptedItemList( const QList< QgsLayoutItem * > &items );
273+
%Docstring
274+
Sets a list of specific ``items`` to exclude from the model.
275+
.. seealso:: exceptedItemList()
276+
%End
277+
278+
QList< QgsLayoutItem * > exceptedItemList() const;
279+
%Docstring
280+
Returns the list of specific items excluded from the model.
281+
.. seealso:: setExceptedItemList()
282+
:rtype: list of QgsLayoutItem
283+
%End
284+
285+
QgsLayoutModel *sourceLayerModel() const;
286+
%Docstring
287+
Returns the QgsLayoutModel used in this proxy model.
288+
:rtype: QgsLayoutModel
289+
%End
290+
291+
QgsLayoutItem *itemFromSourceIndex( const QModelIndex &sourceIndex ) const;
292+
%Docstring
293+
Returns the QgsLayoutItem corresponding to an index from the source
294+
QgsLayoutModel model.
295+
:rtype: QgsLayoutItem
296+
%End
297+
298+
protected:
299+
virtual bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;
300+
301+
virtual bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
302+
303+
304+
};
305+
306+
307+
308+
/************************************************************************
309+
* This file has been generated automatically from *
310+
* *
311+
* src/core/layout/qgslayoutmodel.h *
312+
* *
313+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
314+
************************************************************************/

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ SET(QGIS_CORE_SRCS
370370
layout/qgslayoutitemundocommand.cpp
371371
layout/qgslayoutmeasurement.cpp
372372
layout/qgslayoutmeasurementconverter.cpp
373+
layout/qgslayoutmodel.cpp
373374
layout/qgslayoutobject.cpp
374375
layout/qgslayoutpagecollection.cpp
375376
layout/qgslayoutserializableobject.cpp
@@ -714,6 +715,7 @@ SET(QGIS_CORE_MOC_HDRS
714715
layout/qgslayoutitempage.h
715716
layout/qgslayoutitemregistry.h
716717
layout/qgslayoutitemshape.h
718+
layout/qgslayoutmodel.h
717719
layout/qgslayoutpagecollection.h
718720
layout/qgslayoutobject.h
719721

0 commit comments

Comments
 (0)