QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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"
23 #include "qgslayoutitemregistry.h"
24 
25 #include <QAbstractItemModel>
26 #include <QSortFilterProxyModel>
27 #include <QStringList>
28 #include <QSet>
29 
30 class QgsLayout;
31 class QGraphicsItem;
32 class QgsLayoutItem;
33 
52 class CORE_EXPORT QgsLayoutModel: public QAbstractItemModel
53 {
54  Q_OBJECT
55 
56  public:
57 
59  enum Columns
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 
204  void setItemRestored( QgsComposerItem *item );
205 #endif
206 
214  void updateItemDisplayName( QgsLayoutItem *item );
215 
222  void updateItemLockStatus( QgsLayoutItem *item );
223 
230  void updateItemVisibility( QgsLayoutItem *item );
231 
238  void updateItemSelectStatus( QgsLayoutItem *item );
239 #endif
241 
246  QgsLayoutItem *itemFromIndex( const QModelIndex &index ) const;
247 
252  QModelIndex indexForItem( QgsLayoutItem *item, int column = 0 );
253 
254  public slots:
255 
257 #ifndef SIP_RUN
258 
262  void setSelected( const QModelIndex &index );
263 #endif
265 
266  private:
267 
269  QList<QgsLayoutItem *> mItemZList;
270 
272  QList<QgsLayoutItem *> mItemsInScene;
273 
275  QgsLayout *mLayout = nullptr;
276 
286  void refreshItemsInScene();
287 
293  void rebuildSceneItemList();
294 
295  friend class TestQgsLayoutModel;
296  friend class TestQgsLayoutGui;
297 };
298 
299 
306 class CORE_EXPORT QgsLayoutProxyModel: public QSortFilterProxyModel
307 {
308  Q_OBJECT
309 
310  public:
311 
315  QgsLayoutProxyModel( QgsLayout *layout, QObject *parent SIP_TRANSFERTHIS = nullptr );
316 
322  QgsLayoutItemRegistry::ItemType filterType() const { return mItemTypeFilter; }
323 
330  void setFilterType( QgsLayoutItemRegistry::ItemType filter );
331 
336  void setExceptedItemList( const QList< QgsLayoutItem * > &items );
337 
342  QList< QgsLayoutItem * > exceptedItemList() const { return mExceptedList; }
343 
347  QgsLayoutModel *sourceLayerModel() const { return static_cast< QgsLayoutModel * >( sourceModel() ); }
348 
353  QgsLayoutItem *itemFromSourceIndex( const QModelIndex &sourceIndex ) const;
354 
359  QgsLayout *layout() { return mLayout; }
360 
366  void setAllowEmptyItem( bool allowEmpty );
367 
373  bool allowEmptyItem() const;
374 
383  void setItemFlags( QgsLayoutItem::Flags flags );
384 
393  QgsLayoutItem::Flags itemFlags() const;
394 
395  protected:
396  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
397  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
398 
399  private:
400  QgsLayout *mLayout = nullptr;
401  QgsLayoutItemRegistry::ItemType mItemTypeFilter;
402  QList< QgsLayoutItem * > mExceptedList;
403  bool mAllowEmpty = false;
404  QgsLayoutItem::Flags mItemFlags = QgsLayoutItem::Flags();
405 
406 };
407 
408 
409 
410 #endif //QGSLAYOUTMODEL_H
Base class for graphical items within a QgsLayout.
A model for items attached to a layout.
Columns
Columns returned by the model.
@ ItemId
Item ID.
@ LockStatus
Item lock status checkbox.
Allows for filtering a QgsLayoutModel by item type.
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.
QgsLayoutModel * sourceLayerModel() const
Returns the QgsLayoutModel used in this proxy model.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53