QGIS API Documentation  2.12.0-Lyon
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 <QStringList>
23 #include <QSet>
24 
25 class QgsComposition;
26 class QgsComposerItem;
27 class QGraphicsItem;
28 
47 class CORE_EXPORT QgsComposerModel: public QAbstractItemModel
48 {
49  Q_OBJECT
50 
51  public:
52 
57  explicit QgsComposerModel( QgsComposition* composition, QObject* parent = 0 );
58 
60 
61  //reimplemented QAbstractItemModel methods
62  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
63  QModelIndex parent( const QModelIndex &index ) const override;
64  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
65  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
66  QVariant data( const QModelIndex &index, int role ) const override;
67  Qt::ItemFlags flags( const QModelIndex & index ) const override;
68  bool setData( const QModelIndex & index, const QVariant & value, int role ) override;
69  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
70  Qt::DropActions supportedDropActions() const override;
71  virtual QStringList mimeTypes() const override;
72  virtual QMimeData* mimeData( const QModelIndexList &indexes ) const override;
73  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
74  bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() ) override;
75 
79  void clear();
80 
86  int zOrderListSize() const;
87 
92  void rebuildZList();
93 
99  void addItemAtTop( QgsComposerItem *item );
100 
105  void removeItem( QgsComposerItem *item );
106 
116  bool reorderItemUp( QgsComposerItem *item );
117 
127  bool reorderItemDown( QgsComposerItem *item );
128 
138  bool reorderItemToTop( QgsComposerItem *item );
139 
149  bool reorderItemToBottom( QgsComposerItem *item );
150 
160  QgsComposerItem* getComposerItemAbove( QgsComposerItem *item ) const;
161 
171  QgsComposerItem* getComposerItemBelow( QgsComposerItem *item ) const;
172 
178  QList<QgsComposerItem *>* zOrderList();
179 
186  void setItemRemoved( QgsComposerItem *item );
187 
194  void setItemRestored( QgsComposerItem *item );
195 
203  void updateItemDisplayName( QgsComposerItem *item );
204 
212  void updateItemLockStatus( QgsComposerItem *item );
213 
221  void updateItemVisibility( QgsComposerItem *item );
222 
230  void updateItemSelectStatus( QgsComposerItem *item );
231 
232  public slots:
233 
238  void setSelected( const QModelIndex &index );
239 
240  protected:
241 
244 
247 
248  private:
249 
250  enum Columns
251  {
252  Visibility = 0,
253  LockStatus,
254  ItemId
255  };
256 
258  QgsComposition* mComposition;
259 
264  QgsComposerItem* itemFromIndex( const QModelIndex &index ) const;
265 
271  QModelIndex indexForItem( QgsComposerItem *item, const int column = 0 );
272 
281  void refreshItemsInScene();
282 
287  void rebuildSceneItemList();
288 
289  friend class TestQgsComposerModel;
290 };
291 
292 #endif //QGSCOMPOSERMODEL
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.
virtual Qt::DropActions supportedDropActions() const
virtual QVariant data(const QModelIndex &index, int role) const =0
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)
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
QObject * parent() const
typedef ItemFlags