QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
51class CORE_EXPORT QgsLayoutModel: public QAbstractItemModel
52{
53 Q_OBJECT
54
55 public:
56
59 {
60 Visibility = 0,
63 };
64
68 explicit QgsLayoutModel( QgsLayout *layout, QObject *parent SIP_TRANSFERTHIS = nullptr );
69
70 //reimplemented QAbstractItemModel methods
71 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
72 QModelIndex parent( const QModelIndex &index ) const override;
73 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
74 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
75 QVariant data( const QModelIndex &index, int role ) const override;
76 Qt::ItemFlags flags( const QModelIndex &index ) const override;
77 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
78 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
79 Qt::DropActions supportedDropActions() const override;
80 QStringList mimeTypes() const override;
81 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
82 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
83 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
84
86#ifndef SIP_RUN
87
91 void clear();
92
96 int zOrderListSize() const;
97
102 void rebuildZList();
103
108 void addItemAtTop( QgsLayoutItem *item );
109
113 void removeItem( QgsLayoutItem *item );
114
125 bool reorderItemUp( QgsLayoutItem *item );
126
137 bool reorderItemDown( QgsLayoutItem *item );
138
149 bool reorderItemToTop( QgsLayoutItem *item );
150
161 bool reorderItemToBottom( QgsLayoutItem *item );
162
171 QgsLayoutItem *findItemAbove( QgsLayoutItem *item ) const;
172
181 QgsLayoutItem *findItemBelow( QgsLayoutItem *item ) const;
182
186 QList<QgsLayoutItem *> &zOrderList();
187
192 void setItemRemoved( QgsLayoutItem *item );
193
194#if 0
195
202 void setItemRestored( QgsComposerItem *item );
203#endif
204
212 void updateItemDisplayName( QgsLayoutItem *item );
213
220 void updateItemLockStatus( QgsLayoutItem *item );
221
228 void updateItemVisibility( QgsLayoutItem *item );
229
236 void updateItemSelectStatus( QgsLayoutItem *item );
237#endif
239
244 QgsLayoutItem *itemFromIndex( const QModelIndex &index ) const;
245
250 QModelIndex indexForItem( QgsLayoutItem *item, int column = 0 );
251
252 public slots:
253
255#ifndef SIP_RUN
256
260 void setSelected( const QModelIndex &index );
261#endif
263
264 private:
265
267 QList<QgsLayoutItem *> mItemZList;
268
270 QList<QgsLayoutItem *> mItemsInScene;
271
273 QgsLayout *mLayout = nullptr;
274
284 void refreshItemsInScene();
285
291 void rebuildSceneItemList();
292
293 friend class TestQgsLayoutModel;
294 friend class TestQgsLayoutGui;
295};
296
297
303class CORE_EXPORT QgsLayoutProxyModel: public QSortFilterProxyModel
304{
305 Q_OBJECT
306
307 public:
308
312 QgsLayoutProxyModel( QgsLayout *layout, QObject *parent SIP_TRANSFERTHIS = nullptr );
313
319 QgsLayoutItemRegistry::ItemType filterType() const { return mItemTypeFilter; }
320
327 void setFilterType( QgsLayoutItemRegistry::ItemType filter );
328
333 void setExceptedItemList( const QList< QgsLayoutItem * > &items );
334
339 QList< QgsLayoutItem * > exceptedItemList() const { return mExceptedList; }
340
344 QgsLayoutModel *sourceLayerModel() const { return static_cast< QgsLayoutModel * >( sourceModel() ); }
345
350 QgsLayoutItem *itemFromSourceIndex( const QModelIndex &sourceIndex ) const;
351
356 QgsLayout *layout() { return mLayout; }
357
363 void setAllowEmptyItem( bool allowEmpty );
364
370 bool allowEmptyItem() const;
371
380 void setItemFlags( QgsLayoutItem::Flags flags );
381
390 QgsLayoutItem::Flags itemFlags() const;
391
392 protected:
393 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
394 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
395
396 private:
397 QgsLayout *mLayout = nullptr;
398 QgsLayoutItemRegistry::ItemType mItemTypeFilter;
399 QList< QgsLayoutItem * > mExceptedList;
400 bool mAllowEmpty = false;
402
403};
404
405
406
407#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