QGIS API Documentation  2.99.0-Master (69af2f5)
qgscomposermodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposermodel.h
3  -----------------
4  begin : July 2014
5  copyright : (C) 2014 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 QGSCOMPOSERMODEL_H
19 #define QGSCOMPOSERMODEL_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include <QAbstractItemModel>
24 #include <QSortFilterProxyModel>
25 #include <QStringList>
26 #include <QSet>
27 #include "qgscomposeritem.h"
28 
29 class QgsComposition;
30 class QGraphicsItem;
31 
50 class CORE_EXPORT QgsComposerModel: public QAbstractItemModel
51 {
52  Q_OBJECT
53 
54  public:
55 
57  enum Columns
58  {
59  Visibility = 0,
62  };
63 
68  explicit QgsComposerModel( QgsComposition *composition, QObject *parent SIP_TRANSFERTHIS = 0 );
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  virtual QStringList mimeTypes() const override;
81  virtual 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 
88  void clear();
89 
95  int zOrderListSize() const;
96 
101  void rebuildZList();
102 
108  void addItemAtTop( QgsComposerItem *item );
109 
114  void removeItem( QgsComposerItem *item );
115 
125  bool reorderItemUp( QgsComposerItem *item );
126 
136  bool reorderItemDown( QgsComposerItem *item );
137 
147  bool reorderItemToTop( QgsComposerItem *item );
148 
158  bool reorderItemToBottom( QgsComposerItem *item );
159 
169  QgsComposerItem *getComposerItemAbove( QgsComposerItem *item ) const;
170 
180  QgsComposerItem *getComposerItemBelow( QgsComposerItem *item ) const;
181 
187  QList<QgsComposerItem *> *zOrderList();
188 
195  void setItemRemoved( QgsComposerItem *item );
196 
203  void setItemRestored( QgsComposerItem *item );
204 
212  void updateItemDisplayName( QgsComposerItem *item );
213 
221  void updateItemLockStatus( QgsComposerItem *item );
222 
230  void updateItemVisibility( QgsComposerItem *item );
231 
239  void updateItemSelectStatus( QgsComposerItem *item );
240 
246  QModelIndex indexForItem( QgsComposerItem *item, const int column = 0 );
247 
248  public slots:
249 
254  void setSelected( const QModelIndex &index );
255 
256  protected:
257 
259  QList<QgsComposerItem *> mItemZList;
260 
262  QList<QgsComposerItem *> mItemsInScene;
263 
264  private:
265 
267  QgsComposition *mComposition = nullptr;
268 
273  QgsComposerItem *itemFromIndex( const QModelIndex &index ) const;
274 
283  void refreshItemsInScene();
284 
289  void rebuildSceneItemList();
290 
291  friend class TestQgsComposerModel;
292  friend class TestQgsComposerGui;
293 };
294 
295 
302 class CORE_EXPORT QgsComposerProxyModel: public QSortFilterProxyModel
303 {
304  Q_OBJECT
305 
306  public:
307 
312  QgsComposerProxyModel( QgsComposition *composition, QObject *parent SIP_TRANSFERTHIS = 0 );
313 
318  QgsComposerItem::ItemType filterType() const { return mItemTypeFilter; }
319 
325  void setFilterType( QgsComposerItem::ItemType itemType );
326 
331  void setExceptedItemList( const QList< QgsComposerItem * > &exceptList );
332 
336  QList< QgsComposerItem * > exceptedItemList() const { return mExceptedList; }
337 
340  QgsComposerModel *sourceLayerModel() const { return static_cast< QgsComposerModel * >( sourceModel() ); }
341 
347  QgsComposerItem *itemFromSourceIndex( const QModelIndex &sourceIndex ) const;
348 
349  protected:
350  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
351  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
352 
353  private:
354  QgsComposition *mComposition = nullptr;
355  QgsComposerItem::ItemType mItemTypeFilter;
356  QList< QgsComposerItem * > mExceptedList;
357 
358 };
359 
360 
361 
362 #endif //QGSCOMPOSERMODEL
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
A item that forms part of a map composition.
Item lock status check box.
QList< QgsComposerItem * > mItemZList
Maintains z-Order of items. Starts with item at position 1 (position 0 is always paper item) ...
QList< QgsComposerItem * > mItemsInScene
Cached list of items from mItemZList which are currently in the scene.
QgsComposerItem::ItemType filterType() const
Returns the current item type filter, or QgsComposerItem::ComposerItem if no item type filter is set...
QgsComposerModel * sourceLayerModel() const
Returns the QgsComposerModel used in this proxy model.
Graphics scene for map printing.
A model for items attached to a composition.
Columns
Columns returned by the model.
QList< QgsComposerItem *> exceptedItemList() const
Returns the list of specific items excluded from the model.
Allows for filtering a QgsComposerModel by item type.