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