QGIS API Documentation  2.99.0-Master (25b0421)
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 
69  explicit QgsComposerModel( QgsComposition *composition, QObject *parent SIP_TRANSFERTHIS = 0 );
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  virtual QStringList mimeTypes() const override;
82  virtual 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 
90  void clear();
91 
98  int zOrderListSize() const;
99 
105  void rebuildZList();
106 
113  void addItemAtTop( QgsComposerItem *item );
114 
120  void removeItem( QgsComposerItem *item );
121 
132  bool reorderItemUp( QgsComposerItem *item );
133 
144  bool reorderItemDown( QgsComposerItem *item );
145 
156  bool reorderItemToTop( QgsComposerItem *item );
157 
168  bool reorderItemToBottom( QgsComposerItem *item );
169 
180  QgsComposerItem *getComposerItemAbove( QgsComposerItem *item ) const;
181 
192  QgsComposerItem *getComposerItemBelow( QgsComposerItem *item ) const;
193 
200  QList<QgsComposerItem *> *zOrderList();
201 
209  void setItemRemoved( QgsComposerItem *item );
210 
218  void setItemRestored( QgsComposerItem *item );
219 
228  void updateItemDisplayName( QgsComposerItem *item );
229 
238  void updateItemLockStatus( QgsComposerItem *item );
239 
248  void updateItemVisibility( QgsComposerItem *item );
249 
258  void updateItemSelectStatus( QgsComposerItem *item );
259 
266  QModelIndex indexForItem( QgsComposerItem *item, const int column = 0 );
267 
268  public slots:
269 
275  void setSelected( const QModelIndex &index );
276 
277  protected:
278 
280  QList<QgsComposerItem *> mItemZList;
281 
283  QList<QgsComposerItem *> mItemsInScene;
284 
285  private:
286 
288  QgsComposition *mComposition = nullptr;
289 
295  QgsComposerItem *itemFromIndex( const QModelIndex &index ) const;
296 
306  void refreshItemsInScene();
307 
313  void rebuildSceneItemList();
314 
315  friend class TestQgsComposerModel;
316  friend class TestQgsComposerGui;
317 };
318 
319 
326 class CORE_EXPORT QgsComposerProxyModel: public QSortFilterProxyModel
327 {
328  Q_OBJECT
329 
330  public:
331 
337  QgsComposerProxyModel( QgsComposition *composition, QObject *parent SIP_TRANSFERTHIS = 0 );
338 
344  QgsComposerItem::ItemType filterType() const { return mItemTypeFilter; }
345 
352  void setFilterType( QgsComposerItem::ItemType itemType );
353 
359  void setExceptedItemList( const QList< QgsComposerItem * > &exceptList );
360 
365  QList< QgsComposerItem * > exceptedItemList() const { return mExceptedList; }
366 
370  QgsComposerModel *sourceLayerModel() const { return static_cast< QgsComposerModel * >( sourceModel() ); }
371 
378  QgsComposerItem *itemFromSourceIndex( const QModelIndex &sourceIndex ) const;
379 
380  protected:
381  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
382  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
383 
384  private:
385  QgsComposition *mComposition = nullptr;
386  QgsComposerItem::ItemType mItemTypeFilter;
387  QList< QgsComposerItem * > mExceptedList;
388 
389 };
390 
391 
392 
393 #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.