QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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;
63  QModelIndex parent( const QModelIndex &index ) const;
64  int rowCount( const QModelIndex &parent = QModelIndex() ) const;
65  int columnCount( const QModelIndex &parent = QModelIndex() ) const;
66  QVariant data( const QModelIndex &index, int role ) const;
67  Qt::ItemFlags flags( const QModelIndex & index ) const;
68  bool setData( const QModelIndex & index, const QVariant & value, int role );
69  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
70  Qt::DropActions supportedDropActions() const;
71  virtual QStringList mimeTypes() const;
72  virtual QMimeData* mimeData( const QModelIndexList &indexes ) const;
73  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
74  bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() );
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 
243  QList<QgsComposerItem*> mItemZList;
244 
246  QList<QgsComposerItem*> mItemsInScene;
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
static unsigned index
Definition: mersenne-twister.cpp:36
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
QList< QgsComposerItem * > mItemZList
Maintains z-Order of items.
Definition: qgscomposermodel.h:243
QList< QgsComposerItem * > mItemsInScene
Cached list of items from mItemZList which are currently in the scene.
Definition: qgscomposermodel.h:246
Graphics scene for map printing.
Definition: qgscomposition.h:73
A model for items attached to a composition.
Definition: qgscomposermodel.h:47