QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposermodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposermodel.cpp
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 #include "qgsapplication.h"
19 #include "qgscomposermodel.h"
20 #include "qgscomposition.h"
21 #include "qgscomposeritem.h"
22 #include "qgspaperitem.h"
23 #include "qgslogger.h"
24 #include <QApplication>
25 #include <QGraphicsItem>
26 #include <QDomDocument>
27 #include <QDomElement>
28 #include <QMimeData>
29 #include <QSettings>
30 #include <QMessageBox>
31 #include <QIcon>
32 
33 QgsComposerModel::QgsComposerModel( QgsComposition* composition , QObject *parent )
34  : QAbstractItemModel( parent )
35  , mComposition( composition )
36 {
37 
38 }
39 
41 {
42 }
43 
45 {
46  //try to return the QgsComposerItem corresponding to a QModelIndex
47  if ( !index.isValid() )
48  {
49  return 0;
50  }
51 
52  QgsComposerItem * item = static_cast<QgsComposerItem*>( index.internalPointer() );
53  return item;
54 }
55 
56 QModelIndex QgsComposerModel::index( int row, int column,
57  const QModelIndex &parent ) const
58 {
59  if ( column < 0 || column >= columnCount() )
60  {
61  //column out of bounds
62  return QModelIndex();
63  }
64 
65  if ( !parent.isValid() && row >= 0 && row < mItemsInScene.size() )
66  {
67  //return an index for the composer item at this position
68  return createIndex( row, column, mItemsInScene.at( row ) );
69  }
70 
71  //only top level supported for now
72  return QModelIndex();
73 }
74 
76 {
77  mItemsInScene.clear();
78 
79  //filter deleted and paper items from list
80  //TODO - correctly handle grouped item z order placement
81  QList<QgsComposerItem *>::const_iterator itemIt = mItemZList.constBegin();
82  for ( ; itemIt != mItemZList.constEnd(); ++itemIt )
83  {
84  if ((( *itemIt )->type() != QgsComposerItem::ComposerPaper ) && !( *itemIt )->isRemoved() )
85  {
86  mItemsInScene.push_back(( *itemIt ) );
87  }
88  }
89 }
90 
91 QModelIndex QgsComposerModel::parent( const QModelIndex &index ) const
92 {
93  Q_UNUSED( index );
94 
95  //all items are top level for now
96  return QModelIndex();
97 }
98 
99 int QgsComposerModel::rowCount( const QModelIndex &parent ) const
100 {
101  if ( !parent.isValid() )
102  {
103  return mItemsInScene.size();
104  }
105 
106  QGraphicsItem * parentItem = itemFromIndex( parent );
107 
108  if ( !parentItem )
109  {
110  return mItemsInScene.size();
111  }
112  else
113  {
114  //no children for now
115  return 0;
116  }
117 }
118 
119 int QgsComposerModel::columnCount( const QModelIndex &parent ) const
120 {
121  Q_UNUSED( parent );
122  return 3;
123 }
124 
125 QVariant QgsComposerModel::data( const QModelIndex &index, int role ) const
126 {
127  if ( !index.isValid() )
128  return QVariant();
129 
130  QgsComposerItem *item = itemFromIndex( index );
131  if ( !item )
132  {
133  return QVariant();
134  }
135 
136  switch ( role )
137  {
138  case Qt::DisplayRole:
139  if ( index.column() == ItemId )
140  {
141  return item->displayName();
142  }
143  else
144  {
145  return QVariant();
146  }
147 
148  case Qt::EditRole:
149  if ( index.column() == ItemId )
150  {
151  return item->id();
152  }
153  else
154  {
155  return QVariant();
156  }
157 
158  case Qt::UserRole:
159  //store item uuid in userrole so we can later get the QModelIndex for a specific item
160  return item->uuid();
161 
162  case Qt::TextAlignmentRole:
163  return Qt::AlignLeft & Qt::AlignVCenter;
164 
165  case Qt::CheckStateRole:
166  switch ( index.column() )
167  {
168  case Visibility:
169  //column 0 is visibility of item
170  return item->isVisible() ? Qt::Checked : Qt::Unchecked;
171  case LockStatus:
172  //column 1 is locked state of item
173  return item->positionLock() ? Qt::Checked : Qt::Unchecked;
174  default:
175  return QVariant();
176  }
177 
178  case Qt::FontRole:
179  if ( index.column() == ItemId && item->isSelected() )
180  {
181  //draw name of selected items in bold
182  QFont boldFont;
183  boldFont.setBold( true );
184  return boldFont;
185  }
186  else
187  {
188  return QVariant();
189  }
190  break;
191 
192  default:
193  return QVariant();
194  }
195 }
196 
197 bool QgsComposerModel::setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )
198 {
199  Q_UNUSED( role );
200 
201  if ( !index.isValid() )
202  return false;
203 
204  QgsComposerItem *item = itemFromIndex( index );
205  if ( !item )
206  {
207  return false;
208  }
209 
210  switch ( index.column() )
211  {
212  case Visibility:
213  //first column is item visibility
214  item->setVisibility( value.toBool() );
215  emit dataChanged( index, index );
216  return true;
217 
218  case LockStatus:
219  //second column is item lock state
220  item->setPositionLock( value.toBool() );
221  emit dataChanged( index, index );
222  return true;
223 
224  case ItemId:
225  //last column is item id
226  item->setId( value.toString() );
227  emit dataChanged( index, index );
228  return true;
229  }
230 
231  return false;
232 }
233 
234 QVariant QgsComposerModel::headerData( int section, Qt::Orientation orientation, int role ) const
235 {
236  static QIcon lockIcon;
237  if ( lockIcon.isNull() )
238  lockIcon = QgsApplication::getThemeIcon( "/locked.svg" );
239  static QIcon showIcon;
240  if ( showIcon.isNull() )
241  showIcon = QgsApplication::getThemeIcon( "/mActionShowAllLayers.png" );
242 
243  switch ( role )
244  {
245  case Qt::DisplayRole:
246  {
247  if ( section == ItemId )
248  {
249  return tr( "Item" );
250  }
251  else
252  {
253  return QVariant();
254  }
255  break;
256  }
257 
258  case Qt::DecorationRole:
259  {
260  if ( section == Visibility )
261  {
262  return qVariantFromValue( showIcon );
263  }
264  else if ( section == LockStatus )
265  {
266  return qVariantFromValue( lockIcon );
267  }
268  else
269  {
270  return QVariant();
271  }
272  break;
273  }
274 
275  case Qt::TextAlignmentRole:
276  return Qt::AlignLeft & Qt::AlignVCenter;
277 
278  default:
279  return QAbstractItemModel::headerData( section, orientation, role );
280  }
281 
282 }
283 
285 {
286  return Qt::MoveAction;
287 }
288 
289 QStringList QgsComposerModel::mimeTypes() const
290 {
291  QStringList types;
292  types << "application/x-vnd.qgis.qgis.composeritemid";
293  return types;
294 }
295 
296 QMimeData* QgsComposerModel::mimeData( const QModelIndexList &indexes ) const
297 {
298  QMimeData *mimeData = new QMimeData();
299  QByteArray encodedData;
300 
301  QDataStream stream( &encodedData, QIODevice::WriteOnly );
302 
303  foreach ( const QModelIndex &index, indexes )
304  {
305  if ( index.isValid() && index.column() == ItemId )
306  {
307  QgsComposerItem *item = itemFromIndex( index );
308  if ( !item )
309  {
310  continue;
311  }
312  QString text = item->uuid();
313  stream << text;
314  }
315  }
316 
317  mimeData->setData( "application/x-vnd.qgis.qgis.composeritemid", encodedData );
318  return mimeData;
319 }
320 
322 {
323  return item1->zValue() > item2->zValue();
324 }
325 
326 bool QgsComposerModel::dropMimeData( const QMimeData *data,
327  Qt::DropAction action, int row, int column, const QModelIndex &parent )
328 {
329  if ( column != ItemId )
330  {
331  return false;
332  }
333 
334  if ( action == Qt::IgnoreAction )
335  {
336  return true;
337  }
338 
339  if ( !data->hasFormat( "application/x-vnd.qgis.qgis.composeritemid" ) )
340  {
341  return false;
342  }
343 
344  if ( parent.isValid() )
345  {
346  return false;
347  }
348 
349  int beginRow = row != -1 ? row : rowCount( QModelIndex() );
350 
351  QByteArray encodedData = data->data( "application/x-vnd.qgis.qgis.composeritemid" );
352  QDataStream stream( &encodedData, QIODevice::ReadOnly );
353  QList<QgsComposerItem*> droppedItems;
354  int rows = 0;
355 
356  while ( !stream.atEnd() )
357  {
358  QString text;
359  stream >> text;
360  const QgsComposerItem* item = mComposition->getComposerItemByUuid( text );
361  if ( item )
362  {
363  droppedItems << const_cast<QgsComposerItem*>( item );
364  ++rows;
365  }
366  }
367 
368  if ( droppedItems.length() == 0 )
369  {
370  //no dropped items
371  return false;
372  }
373 
374  //move dropped items
375 
376  //first sort them by z-order
377  qSort( droppedItems.begin(), droppedItems.end(), zOrderDescending );
378 
379  //calculate position in z order list to drop items at
380  int destPos = 0;
381  if ( beginRow < rowCount() )
382  {
383  QgsComposerItem* itemBefore = mItemsInScene.at( beginRow );
384  destPos = mItemZList.indexOf( itemBefore );
385  }
386  else
387  {
388  //place items at end
389  destPos = mItemZList.size();
390  }
391 
392  //calculate position to insert moved rows to
393  int insertPos = destPos;
394  QList<QgsComposerItem*>::iterator itemIt = droppedItems.begin();
395  for ( ; itemIt != droppedItems.end(); ++itemIt )
396  {
397  int listPos = mItemZList.indexOf( *itemIt );
398  if ( listPos == -1 )
399  {
400  //should be impossible
401  continue;
402  }
403 
404  if ( listPos < destPos )
405  {
406  insertPos--;
407  }
408  }
409 
410  //remove rows from list
411  itemIt = droppedItems.begin();
412  for ( ; itemIt != droppedItems.end(); ++itemIt )
413  {
414  mItemZList.removeOne( *itemIt );
415  }
416 
417  //insert items
418  itemIt = droppedItems.begin();
419  for ( ; itemIt != droppedItems.end(); ++itemIt )
420  {
421  mItemZList.insert( insertPos, *itemIt );
422  insertPos++;
423  }
424 
426  mComposition->updateZValues( false );
427 
428  return true;
429 }
430 
431 bool QgsComposerModel::removeRows( int row, int count, const QModelIndex &parent )
432 {
433  Q_UNUSED( count );
434  if ( parent.isValid() )
435  {
436  return false;
437  }
438 
439  if ( row >= rowCount() )
440  {
441  return false;
442  }
443 
444  //do nothing - moves are handled by the dropMimeData method
445  return true;
446 }
447 
449 {
450  //totally reset model
451  beginResetModel();
452  mItemZList.clear();
454  endResetModel();
455 }
456 
458 {
459  return mItemZList.size();
460 }
461 
463 {
464  QList<QgsComposerItem*> sortedList;
465  //rebuild the item z order list based on the current zValues of items in the scene
466 
467  //get items in descending zValue order
468  QList<QGraphicsItem*> itemList = mComposition->items( Qt::DescendingOrder );
469  QList<QGraphicsItem*>::iterator itemIt = itemList.begin();
470  for ( ; itemIt != itemList.end(); ++itemIt )
471  {
472  QgsComposerItem* composerItem = dynamic_cast<QgsComposerItem*>( *itemIt );
473  if ( composerItem )
474  {
475  if ( composerItem->type() != QgsComposerItem::ComposerPaper )
476  {
477  sortedList.append( composerItem );
478  }
479  }
480  }
481 
482  mItemZList = sortedList;
484 }
485 
487 {
488  //step through the z list and rebuild the items in scene list,
489  //emitting signals as required
490  QList<QgsComposerItem*>::iterator zListIt = mItemZList.begin();
491  int row = 0;
492  for ( ; zListIt != mItemZList.end(); ++zListIt )
493  {
494  if ((( *zListIt )->type() == QgsComposerItem::ComposerPaper ) || ( *zListIt )->isRemoved() )
495  {
496  //item not in scene, skip it
497  continue;
498  }
499 
500  int sceneListPos = mItemsInScene.indexOf( *zListIt );
501  if ( sceneListPos == row )
502  {
503  //already in list in correct position, nothing to do
504 
505  }
506  else if ( sceneListPos != -1 )
507  {
508  //in list, but in wrong spot
509  beginMoveRows( QModelIndex(), sceneListPos, sceneListPos, QModelIndex(), row );
510  mItemsInScene.removeAt( sceneListPos );
511  mItemsInScene.insert( row, *zListIt );
512  endMoveRows();
513  }
514  else
515  {
516  //needs to be inserted into list
517  beginInsertRows( QModelIndex(), row, row );
518  mItemsInScene.insert( row, *zListIt );
519  endInsertRows();
520  }
521  row++;
522  }
523 }
524 
526 {
527  beginInsertRows( QModelIndex(), 0, 0 );
528  mItemZList.push_front( item );
530  item->setZValue( mItemZList.size() );
531  endInsertRows();
532 }
533 
535 {
536  if ( !item )
537  {
538  //nothing to do
539  return;
540  }
541 
542  int pos = mItemZList.indexOf( item );
543  if ( pos == -1 )
544  {
545  //item not in z list, nothing to do
546  return;
547  }
548 
549  //need to get QModelIndex of item
550  QModelIndex itemIndex = indexForItem( item );
551  if ( !itemIndex.isValid() )
552  {
553  //removing an item not in the scene (eg, deleted item)
554  //we need to remove it from the list, but don't need to call
555  //beginRemoveRows or endRemoveRows since the item was not used by the model
556  mItemZList.removeAt( pos );
558  return;
559  }
560 
561  //remove item from model
562  int row = itemIndex.row();
563  beginRemoveRows( QModelIndex() , row, row );
564  mItemZList.removeAt( pos );
566  endRemoveRows();
567 }
568 
570 {
571  if ( !item )
572  {
573  //nothing to do
574  return;
575  }
576 
577  int pos = mItemZList.indexOf( item );
578  if ( pos == -1 )
579  {
580  //item not in z list, nothing to do
581  return;
582  }
583 
584  //need to get QModelIndex of item
585  QModelIndex itemIndex = indexForItem( item );
586  if ( !itemIndex.isValid() )
587  {
588  return;
589  }
590 
591  //removing item
592  int row = itemIndex.row();
593  beginRemoveRows( QModelIndex() , row, row );
594  item->setIsRemoved( true );
596  endRemoveRows();
597 }
598 
600 {
601  if ( !item )
602  {
603  //nothing to do
604  return;
605  }
606 
607  int pos = mItemZList.indexOf( item );
608  if ( pos == -1 )
609  {
610  //item not in z list, nothing to do
611  return;
612  }
613 
614  item->setIsRemoved( false );
616 }
617 
619 {
620  if ( !item )
621  {
622  //nothing to do
623  return;
624  }
625 
626  //need to get QModelIndex of item
627  QModelIndex itemIndex = indexForItem( item, ItemId );
628  if ( !itemIndex.isValid() )
629  {
630  return;
631  }
632 
633  //emit signal for item id change
634  emit dataChanged( itemIndex, itemIndex );
635 }
636 
638 {
639  if ( !item )
640  {
641  //nothing to do
642  return;
643  }
644 
645  //need to get QModelIndex of item
646  QModelIndex itemIndex = indexForItem( item, LockStatus );
647  if ( !itemIndex.isValid() )
648  {
649  return;
650  }
651 
652  //emit signal for item lock status change
653  emit dataChanged( itemIndex, itemIndex );
654 }
655 
657 {
658  if ( !item )
659  {
660  //nothing to do
661  return;
662  }
663 
664  //need to get QModelIndex of item
665  QModelIndex itemIndex = indexForItem( item, Visibility );
666  if ( !itemIndex.isValid() )
667  {
668  return;
669  }
670 
671  //emit signal for item visibility change
672  emit dataChanged( itemIndex, itemIndex );
673 }
674 
676 {
677  if ( !item )
678  {
679  //nothing to do
680  return;
681  }
682 
683  //need to get QModelIndex of item
684  QModelIndex itemIndex = indexForItem( item, ItemId );
685  if ( !itemIndex.isValid() )
686  {
687  return;
688  }
689 
690  //emit signal for item visibility change
691  emit dataChanged( itemIndex, itemIndex );
692 }
693 
695 {
696  if ( mItemsInScene.first() == item )
697  {
698  //item is already topmost item present in scene, nothing to do
699  return false;
700  }
701 
702  //move item in z list
703  QMutableListIterator<QgsComposerItem*> it( mItemZList );
704  if ( ! it.findNext( item ) )
705  {
706  //can't find item in z list, nothing to do
707  return false;
708  }
709 
710  it.remove();
711  while ( it.hasPrevious() )
712  {
713  //search through item z list to find previous item which is present in the scene
714  //(deleted items still exist in the z list so that they can be restored to their correct stacking order,
715  //but since they are not in the scene they should be ignored here)
716  it.previous();
717  if ( it.value() && !( it.value()->isRemoved() ) )
718  {
719  break;
720  }
721  }
722  it.insert( item );
723 
724  //also move item in scene items z list and notify of model changes
725  QModelIndex itemIndex = indexForItem( item );
726  if ( !itemIndex.isValid() )
727  {
728  return true;
729  }
730 
731  //move item up in scene list
732  int row = itemIndex.row();
733  beginMoveRows( QModelIndex(), row, row, QModelIndex(), row - 1 );
735  endMoveRows();
736  return true;
737 }
738 
740 {
741  if ( mItemsInScene.last() == item )
742  {
743  //item is already lowest item present in scene, nothing to do
744  return false;
745  }
746 
747  //move item in z list
748  QMutableListIterator<QgsComposerItem*> it( mItemZList );
749  if ( ! it.findNext( item ) )
750  {
751  //can't find item in z list, nothing to do
752  return false;
753  }
754 
755  it.remove();
756  while ( it.hasNext() )
757  {
758  //search through item z list to find next item which is present in the scene
759  //(deleted items still exist in the z list so that they can be restored to their correct stacking order,
760  //but since they are not in the scene they should be ignored here)
761  it.next();
762  if ( it.value() && !( it.value()->isRemoved() ) )
763  {
764  break;
765  }
766  }
767  it.insert( item );
768 
769  //also move item in scene items z list and notify of model changes
770  QModelIndex itemIndex = indexForItem( item );
771  if ( !itemIndex.isValid() )
772  {
773  return true;
774  }
775 
776  //move item down in scene list
777  int row = itemIndex.row();
778  beginMoveRows( QModelIndex(), row, row, QModelIndex(), row + 2 );
780  endMoveRows();
781  return true;
782 }
783 
785 {
786  if ( mItemsInScene.first() == item )
787  {
788  //item is already topmost item present in scene, nothing to do
789  return false;
790  }
791 
792  //move item in z list
793  QMutableListIterator<QgsComposerItem*> it( mItemZList );
794  if ( it.findNext( item ) )
795  {
796  it.remove();
797  }
798  mItemZList.push_front( item );
799 
800  //also move item in scene items z list and notify of model changes
801  QModelIndex itemIndex = indexForItem( item );
802  if ( !itemIndex.isValid() )
803  {
804  return true;
805  }
806 
807  //move item to top
808  int row = itemIndex.row();
809  beginMoveRows( QModelIndex(), row, row, QModelIndex(), 0 );
811  endMoveRows();
812  return true;
813 }
814 
816 {
817  if ( mItemsInScene.last() == item )
818  {
819  //item is already lowest item present in scene, nothing to do
820  return false;
821  }
822 
823  //move item in z list
824  QMutableListIterator<QgsComposerItem*> it( mItemZList );
825  if ( it.findNext( item ) )
826  {
827  it.remove();
828  }
829  mItemZList.push_back( item );
830 
831  //also move item in scene items z list and notify of model changes
832  QModelIndex itemIndex = indexForItem( item );
833  if ( !itemIndex.isValid() )
834  {
835  return true;
836  }
837 
838  //move item to bottom
839  int row = itemIndex.row();
840  beginMoveRows( QModelIndex(), row, row, QModelIndex(), rowCount() );
842  endMoveRows();
843  return true;
844 }
845 
847 {
848  //search item z list for selected item
849  QListIterator<QgsComposerItem*> it( mItemZList );
850  it.toBack();
851  if ( it.findPrevious( item ) )
852  {
853  //move position to before selected item
854  while ( it.hasPrevious() )
855  {
856  //now find previous item, since list is sorted from lowest->highest items
857  if ( it.hasPrevious() && !it.peekPrevious()->isGroupMember() )
858  {
859  return it.previous();
860  }
861  it.previous();
862  }
863  }
864  return 0;
865 }
866 
868 {
869  //search item z list for selected item
870  QListIterator<QgsComposerItem*> it( mItemZList );
871  if ( it.findNext( item ) )
872  {
873  //return next item (list is sorted from lowest->highest items)
874  while ( it.hasNext() )
875  {
876  if ( !it.peekNext()->isGroupMember() )
877  {
878  return it.next();
879  }
880  it.next();
881  }
882  }
883  return 0;
884 }
885 
886 QList<QgsComposerItem *>* QgsComposerModel::zOrderList()
887 {
888  return &mItemZList;
889 }
890 
891 
892 Qt::ItemFlags QgsComposerModel::flags( const QModelIndex & index ) const
893 {
894  Qt::ItemFlags flags = QAbstractItemModel::flags( index );
895 
896  if ( ! index.isValid() )
897  {
898  return flags | Qt::ItemIsDropEnabled;;
899  }
900 
901  switch ( index.column() )
902  {
903  case Visibility:
904  case LockStatus:
905  return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
906  case ItemId:
907  return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
908  default:
909  return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
910  }
911 }
912 
913 QModelIndex QgsComposerModel::indexForItem( QgsComposerItem *item , const int column )
914 {
915  if ( !item )
916  {
917  return QModelIndex();
918  }
919 
920  int row = mItemsInScene.indexOf( item );
921  if ( row == -1 )
922  {
923  //not found
924  return QModelIndex();
925  }
926 
927  return index( row, column );
928 }
929 
930 void QgsComposerModel::setSelected( const QModelIndex &index )
931 {
932  QgsComposerItem *item = itemFromIndex( index );
933  if ( !item )
934  {
935  return;
936  }
937 
938  mComposition->setSelectedItem( item );
939 }
bool positionLock() const
Returns whether position lock for mouse drags is enabled returns true if item is locked for mouse mov...
static unsigned index
QgsComposerItem * getComposerItemAbove(QgsComposerItem *item) const
Finds the next composer item above an item.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
QgsComposerModel(QgsComposition *composition, QObject *parent=0)
Constructor.
void rebuildZList()
Rebuilds the z-order list, based on the current stacking of items in the composition.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
bool setData(const QModelIndex &index, const QVariant &value, int role)
int zOrderListSize() const
Returns the size of the z-order list, which includes items which may have been removed from the compo...
A item that forms part of a map composition.
void setSelectedItem(QgsComposerItem *item)
Clears any selected items and sets an item as the current selection.
QModelIndex indexForItem(QgsComposerItem *item, const int column=0)
Returns the QModelIndex corresponding to a QgsComposerItem, if possible.
void updateItemVisibility(QgsComposerItem *item)
Must be called when an item's visibility changes.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
void setItemRestored(QgsComposerItem *item)
Restores an item to the composition.
bool reorderItemDown(QgsComposerItem *item)
Moves an item down the z-order list.
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item's display name is modified.
bool zOrderDescending(QgsComposerItem *item1, QgsComposerItem *item2)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QList< QgsComposerItem * > * zOrderList()
Returns the item z-order list.
virtual int type() const
return correct graphics item type.
void updateItemLockStatus(QgsComposerItem *item)
Must be called when an item's lock status changes.
QString uuid() const
Get item identification name.
QList< QgsComposerItem * > mItemZList
Maintains z-Order of items.
QgsComposerItem * itemFromIndex(const QModelIndex &index) const
Returns the QgsComposerItem corresponding to a QModelIndex, if possible.
void setIsRemoved(const bool removed)
Sets whether this item has been removed from the composition.
int columnCount(const QModelIndex &parent=QModelIndex()) const
QgsComposition * mComposition
Parent composition.
void clear()
Clears all items from z-order list and resets the model.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
void rebuildSceneItemList()
Steps through the item z-order list and rebuilds the items in composition list, emitting QAbstractIte...
Qt::ItemFlags flags(const QModelIndex &index) const
const QgsComposerItem * getComposerItemByUuid(const QString theUuid) const
Returns a composer item given its unique identifier.
QList< QgsComposerItem * > mItemsInScene
Cached list of items from mItemZList which are currently in the scene.
Graphics scene for map printing.
int rowCount(const QModelIndex &parent=QModelIndex()) const
QModelIndex parent(const QModelIndex &index) const
void removeItem(QgsComposerItem *item)
Removes an item from the z-order list.
void updateZValues(const bool addUndoCommands=true)
Reset z-values of items based on position in z list.
virtual QString displayName() const
Get item display name.
void setPositionLock(const bool lock)
Locks / unlocks the item position for mouse drags.
void setSelected(const QModelIndex &index)
Sets an item as the current selection from a QModelIndex.
bool reorderItemUp(QgsComposerItem *item)
Moves an item up the z-order list.
QgsComposerItem * getComposerItemBelow(QgsComposerItem *item) const
Finds the next composer item below an item.
virtual QStringList mimeTypes() const
virtual void setId(const QString &id)
Set item's id (which is not necessarly unique)
Qt::DropActions supportedDropActions() const
void updateItemSelectStatus(QgsComposerItem *item)
Must be called when an item's selection status changes.
void setItemRemoved(QgsComposerItem *item)
Marks an item as removed from the composition.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
bool reorderItemToTop(QgsComposerItem *item)
Moves an item to the top of the z-order list.
void refreshItemsInScene()
Rebuilds the list of all composer items which are present in the composition.
void addItemAtTop(QgsComposerItem *item)
Adds an item to the top of the composition z stack.
virtual void setVisibility(const bool visible)
Sets visibility for item.
QVariant data(const QModelIndex &index, int role) const
bool reorderItemToBottom(QgsComposerItem *item)
Moves an item to the bottom of the z-order list.
#define tr(sourceText)
QString id() const
Get item's id (which is not necessarly unique)