QGIS API Documentation  2.99.0-Master (c4aa4d0)
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 
32 #define SIP_NO_FILE
33 
54 class CORE_EXPORT QgsComposerModel: public QAbstractItemModel
55 {
56  Q_OBJECT
57 
58  public:
59 
61  enum Columns
62  {
63  Visibility = 0,
66  };
67 
73  explicit QgsComposerModel( QgsComposition *composition, QObject *parent SIP_TRANSFERTHIS = nullptr );
74 
75  //reimplemented QAbstractItemModel methods
76  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
77  QModelIndex parent( const QModelIndex &index ) const override;
78  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
79  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
80  QVariant data( const QModelIndex &index, int role ) const override;
81  Qt::ItemFlags flags( const QModelIndex &index ) const override;
82  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
83  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
84  Qt::DropActions supportedDropActions() const override;
85  QStringList mimeTypes() const override;
86  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
87  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
88  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
89 
94  void clear();
95 
102  int zOrderListSize() const;
103 
109  void rebuildZList();
110 
117  void addItemAtTop( QgsComposerItem *item );
118 
124  void removeItem( QgsComposerItem *item );
125 
136  bool reorderItemUp( QgsComposerItem *item );
137 
148  bool reorderItemDown( QgsComposerItem *item );
149 
160  bool reorderItemToTop( QgsComposerItem *item );
161 
172  bool reorderItemToBottom( QgsComposerItem *item );
173 
184  QgsComposerItem *getComposerItemAbove( QgsComposerItem *item ) const;
185 
196  QgsComposerItem *getComposerItemBelow( QgsComposerItem *item ) const;
197 
204  QList<QgsComposerItem *> *zOrderList();
205 
213  void setItemRemoved( QgsComposerItem *item );
214 
222  void setItemRestored( QgsComposerItem *item );
223 
232  void updateItemDisplayName( QgsComposerItem *item );
233 
242  void updateItemLockStatus( QgsComposerItem *item );
243 
252  void updateItemVisibility( QgsComposerItem *item );
253 
262  void updateItemSelectStatus( QgsComposerItem *item );
263 
270  QModelIndex indexForItem( QgsComposerItem *item, const int column = 0 );
271 
272  public slots:
273 
279  void setSelected( const QModelIndex &index );
280 
281  protected:
282 
284  QList<QgsComposerItem *> mItemZList;
285 
287  QList<QgsComposerItem *> mItemsInScene;
288 
289  private:
290 
292  QgsComposition *mComposition = nullptr;
293 
299  QgsComposerItem *itemFromIndex( const QModelIndex &index ) const;
300 
310  void refreshItemsInScene();
311 
317  void rebuildSceneItemList();
318 
319  friend class TestQgsComposerModel;
320  friend class TestQgsComposerGui;
321 };
322 
323 
330 class CORE_EXPORT QgsComposerProxyModel: public QSortFilterProxyModel
331 {
332  Q_OBJECT
333 
334  public:
335 
341  QgsComposerProxyModel( QgsComposition *composition, QObject *parent SIP_TRANSFERTHIS = nullptr );
342 
348  QgsComposerItem::ItemType filterType() const { return mItemTypeFilter; }
349 
356  void setFilterType( QgsComposerItem::ItemType itemType );
357 
363  void setExceptedItemList( const QList< QgsComposerItem * > &exceptList );
364 
369  QList< QgsComposerItem * > exceptedItemList() const { return mExceptedList; }
370 
374  QgsComposerModel *sourceLayerModel() const { return static_cast< QgsComposerModel * >( sourceModel() ); }
375 
382  QgsComposerItem *itemFromSourceIndex( const QModelIndex &sourceIndex ) const;
383 
384  protected:
385  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
386  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
387 
388  private:
389  QgsComposition *mComposition = nullptr;
390  QgsComposerItem::ItemType mItemTypeFilter;
391  QList< QgsComposerItem * > mExceptedList;
392 
393 };
394 
395 
396 
397 #endif //QGSCOMPOSERMODEL
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A item that forms part of a map composition.
Item lock status checkbox.
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.