QGIS API Documentation  3.6.0-Noosa (5873452)
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
240 
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
264 
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 
355  protected:
356  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
357  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
358 
359  private:
360  QgsLayout *mLayout = nullptr;
361  QgsLayoutItemRegistry::ItemType mItemTypeFilter;
362  QList< QgsLayoutItem * > mExceptedList;
363 
364 };
365 
366 
367 
368 #endif //QGSLAYOUTMODEL_H
Base class for graphical items within a QgsLayout.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
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:49
Item lock status checkbox.
Columns
Columns returned by the model.
Allows for filtering a QgsLayoutModel by item type.
QList< QgsLayoutItem *> exceptedItemList() const
Returns the list of specific items excluded from the model.
QgsLayoutItemRegistry::ItemType filterType() const
Returns the current item type filter, or QgsLayoutItemRegistry::LayoutItem if no item type filter is ...
A model for items attached to a layout.