QGIS API Documentation 3.43.0-Master (c67cf405802)
qgslayoutmodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutmodel.h
3 ----------------
4 begin : October 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSLAYOUTMODEL_H
19#define QGSLAYOUTMODEL_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
24
25#include <QAbstractItemModel>
26#include <QSortFilterProxyModel>
27#include <QStringList>
28#include <QSet>
29
30class QgsLayout;
31class QGraphicsItem;
32class QgsLayoutItem;
33
52class CORE_EXPORT QgsLayoutModel: public QAbstractItemModel
53{
54 Q_OBJECT
55
56 public:
57
60 {
61 Visibility = 0,
64 };
65
69 explicit QgsLayoutModel( QgsLayout *layout, QObject *parent SIP_TRANSFERTHIS = nullptr );
70
71 //reimplemented QAbstractItemModel methods
72 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
73 QModelIndex parent( const QModelIndex &index ) const override;
74 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
75 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
76 QVariant data( const QModelIndex &index, int role ) const override;
77 Qt::ItemFlags flags( const QModelIndex &index ) const override;
78 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
79 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
80 Qt::DropActions supportedDropActions() const override;
81 QStringList mimeTypes() const override;
82 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
83 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
84 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
85
87#ifndef SIP_RUN
88
92 void clear();
93
97 int zOrderListSize() const;
98
103 void rebuildZList();
104
109 void addItemAtTop( QgsLayoutItem *item );
110
114 void removeItem( QgsLayoutItem *item );
115
126 bool reorderItemUp( QgsLayoutItem *item );
127
138 bool reorderItemDown( QgsLayoutItem *item );
139
150 bool reorderItemToTop( QgsLayoutItem *item );
151
162 bool reorderItemToBottom( QgsLayoutItem *item );
163
172 QgsLayoutItem *findItemAbove( QgsLayoutItem *item ) const;
173
182 QgsLayoutItem *findItemBelow( QgsLayoutItem *item ) const;
183
187 QList<QgsLayoutItem *> &zOrderList();
188
193 void setItemRemoved( QgsLayoutItem *item );
194
195#if 0
196
203 void setItemRestored( QgsComposerItem *item );
204#endif
205
213 void updateItemDisplayName( QgsLayoutItem *item );
214
221 void updateItemLockStatus( QgsLayoutItem *item );
222
229 void updateItemVisibility( QgsLayoutItem *item );
230
237 void updateItemSelectStatus( QgsLayoutItem *item );
238#endif
240
245 QgsLayoutItem *itemFromIndex( const QModelIndex &index ) const;
246
251 QModelIndex indexForItem( QgsLayoutItem *item, int column = 0 );
252
253 public slots:
254
256#ifndef SIP_RUN
257
261 void setSelected( const QModelIndex &index );
262#endif
264
265 private:
266
268 QList<QgsLayoutItem *> mItemZList;
269
271 QList<QgsLayoutItem *> mItemsInScene;
272
274 QgsLayout *mLayout = nullptr;
275
285 void refreshItemsInScene();
286
292 void rebuildSceneItemList();
293
294 friend class TestQgsLayoutModel;
295 friend class TestQgsLayoutGui;
296};
297
298
304class CORE_EXPORT QgsLayoutProxyModel: public QSortFilterProxyModel
305{
306 Q_OBJECT
307
308 public:
309
313 QgsLayoutProxyModel( QgsLayout *layout, QObject *parent SIP_TRANSFERTHIS = nullptr );
314
320 QgsLayoutItemRegistry::ItemType filterType() const { return mItemTypeFilter; }
321
328 void setFilterType( QgsLayoutItemRegistry::ItemType filter );
329
334 void setExceptedItemList( const QList< QgsLayoutItem * > &items );
335
340 QList< QgsLayoutItem * > exceptedItemList() const { return mExceptedList; }
341
345 QgsLayoutModel *sourceLayerModel() const { return static_cast< QgsLayoutModel * >( sourceModel() ); }
346
351 QgsLayoutItem *itemFromSourceIndex( const QModelIndex &sourceIndex ) const;
352
357 QgsLayout *layout() { return mLayout; }
358
364 void setAllowEmptyItem( bool allowEmpty );
365
371 bool allowEmptyItem() const;
372
381 void setItemFlags( QgsLayoutItem::Flags flags );
382
391 QgsLayoutItem::Flags itemFlags() const;
392
393 protected:
394 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
395 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
396
397 private:
398 QgsLayout *mLayout = nullptr;
399 QgsLayoutItemRegistry::ItemType mItemTypeFilter;
400 QList< QgsLayoutItem * > mExceptedList;
401 bool mAllowEmpty = false;
403
404};
405
406
407
408#endif //QGSLAYOUTMODEL_H
Base class for graphical items within a QgsLayout.
QFlags< Flag > Flags
A model for items attached to a layout.
Columns
Columns returned by the model.
@ LockStatus
Item lock status checkbox.
Allows for filtering a QgsLayoutModel by item type.
QgsLayoutModel * sourceLayerModel() const
Returns the QgsLayoutModel used in this proxy model.
QgsLayout * layout()
Returns the associated layout.
QgsLayoutItemRegistry::ItemType filterType() const
Returns the current item type filter, or QgsLayoutItemRegistry::LayoutItem if no item type filter is ...
QList< QgsLayoutItem * > exceptedItemList() const
Returns the list of specific items excluded from the model.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53