QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 <QAbstractItemModel>
22 #include <QSortFilterProxyModel>
23 #include <QStringList>
24 #include <QSet>
25 #include "qgscomposeritem.h"
26 
27 class QgsComposition;
28 class QGraphicsItem;
29 
48 class CORE_EXPORT QgsComposerModel: public QAbstractItemModel
49 {
50  Q_OBJECT
51 
52  public:
53 
55  enum Columns
56  {
57  Visibility = 0,
60  };
61 
66  explicit QgsComposerModel( QgsComposition* composition, QObject* parent = nullptr );
67 
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 
260 
263 
264  private:
265 
267  QgsComposition* mComposition;
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 
303 {
304  Q_OBJECT
305 
306  public:
307 
312  QgsComposerProxyModel( QgsComposition* composition, QObject *parent = nullptr );
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 
352  private:
353  QgsComposition* mComposition;
354  QgsComposerItem::ItemType mItemTypeFilter;
355  QList< QgsComposerItem* > mExceptedList;
356 
357 };
358 
359 
360 
361 #endif //QGSCOMPOSERMODEL
static unsigned index
virtual int rowCount(const QModelIndex &parent) const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const=0
A item that forms part of a map composition.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual QStringList mimeTypes() const
QList< QgsComposerItem * > mItemZList
Maintains z-Order of items.
QgsComposerItem::ItemType filterType() const
Returns the current item type filter, or QgsComposerItem::ComposerItem if no item type filter is set...
virtual Qt::DropActions supportedDropActions() const
QList< QgsComposerItem *> exceptedItemList() const
Returns the list of specific items excluded from the model.
virtual QVariant data(const QModelIndex &index, int role) const=0
QgsComposerModel * sourceLayerModel() const
Returns the QgsComposerModel used in this proxy model.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
QList< QgsComposerItem * > mItemsInScene
Cached list of items from mItemZList which are currently in the scene.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Graphics scene for map printing.
A model for items attached to a composition.
virtual bool removeRows(int row, int count, const QModelIndex &parent)
Columns
Columns returned by the model.
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
QAbstractItemModel * sourceModel() const
typedef DropActions
virtual int columnCount(const QModelIndex &parent) const=0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Allows for filtering a QgsComposerModel by item type.
QObject * parent() const
typedef ItemFlags