|
| 1 | +/** |
| 2 | + * \class QgsComposerModel |
| 3 | + * \ingroup MapComposer |
| 4 | + * |
| 5 | + * A model for items attached to a composition. The model also maintains the z-order for the |
| 6 | + * composition, and must be notified whenever item stacking changes. |
| 7 | + * |
| 8 | + * Internally, QgsComposerModel maintains two lists. One contains a complete list of all items for |
| 9 | + * the composition, ordered by their position within the z-order stack. This list also contains |
| 10 | + * items which have been removed from the composition, so that undo/redo commands can restore |
| 11 | + * them to their correct position in the stacking order. |
| 12 | + * |
| 13 | + * The second list contains only items which are currently displayed in the composition's scene. |
| 14 | + * It is used as a cache of the last known stacking order, so that the model can compare the current |
| 15 | + * stacking of items in the composition to the last known state, and emit the corresponding signals |
| 16 | + * as required. |
| 17 | + */ |
| 18 | + |
| 19 | +class QgsComposerModel : QAbstractItemModel |
| 20 | +{ |
| 21 | +%TypeHeaderCode |
| 22 | +#include "qgscomposermodel.h" |
| 23 | +%End |
| 24 | + public: |
| 25 | + |
| 26 | + /**Constructor |
| 27 | + * @param composition parent composition |
| 28 | + */ |
| 29 | + explicit QgsComposerModel( QgsComposition* composition, QObject* parent = 0 ); |
| 30 | + |
| 31 | + ~QgsComposerModel(); |
| 32 | + |
| 33 | + //reimplemented QAbstractItemModel methods |
| 34 | + QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; |
| 35 | + QModelIndex parent( const QModelIndex &index ) const; |
| 36 | + int rowCount( const QModelIndex &parent = QModelIndex() ) const; |
| 37 | + int columnCount( const QModelIndex &parent = QModelIndex() ) const; |
| 38 | + QVariant data( const QModelIndex &index, int role ) const; |
| 39 | + Qt::ItemFlags flags( const QModelIndex & index ) const; |
| 40 | + bool setData( const QModelIndex & index, const QVariant & value, int role ); |
| 41 | + QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
| 42 | + |
| 43 | + /**Clears all items from z-order list and resets the model |
| 44 | + * @note added in QGIS 2.5 |
| 45 | + */ |
| 46 | + void clear(); |
| 47 | + |
| 48 | + /**Returns the size of the z-order list, which includes items which may |
| 49 | + * have been removed from the composition. |
| 50 | + * @returns size of z-order list |
| 51 | + * @note added in QGIS 2.5 |
| 52 | + */ |
| 53 | + int zOrderListSize() const; |
| 54 | + |
| 55 | + /**Rebuilds the z-order list, based on the current stacking of items in the composition. |
| 56 | + * This method should be called after adding multiple items to the composition. |
| 57 | + * @note added in QGIS 2.5 |
| 58 | + */ |
| 59 | + void rebuildZList(); |
| 60 | + |
| 61 | + /**Adds an item to the top of the composition z stack. |
| 62 | + * @param item item to add. The item must not already exist in the z-order list. |
| 63 | + * @note added in QGIS 2.5 |
| 64 | + * @see reorderItemToTop |
| 65 | + */ |
| 66 | + void addItemAtTop( QgsComposerItem *item ); |
| 67 | + |
| 68 | + /**Removes an item from the z-order list. |
| 69 | + * @param item item to remove |
| 70 | + * @note added in QGIS 2.5 |
| 71 | + */ |
| 72 | + void removeItem( QgsComposerItem *item ); |
| 73 | + |
| 74 | + /**Moves an item up the z-order list. |
| 75 | + * @param item item to move |
| 76 | + * @returns true if item was moved. Returns false if item was not found |
| 77 | + * in z-order list or was already at the top of the z-order list. |
| 78 | + * @see reorderItemDown |
| 79 | + * @see reorderItemToTop |
| 80 | + * @see reorderItemToBottom |
| 81 | + * @note added in QGIS 2.5 |
| 82 | + */ |
| 83 | + bool reorderItemUp( QgsComposerItem *item ); |
| 84 | + |
| 85 | + /**Moves an item down the z-order list. |
| 86 | + * @param item item to move |
| 87 | + * @returns true if item was moved. Returns false if item was not found |
| 88 | + * in z-order list or was already at the bottom of the z-order list. |
| 89 | + * @see reorderItemUp |
| 90 | + * @see reorderItemToTop |
| 91 | + * @see reorderItemToBottom |
| 92 | + * @note added in QGIS 2.5 |
| 93 | + */ |
| 94 | + bool reorderItemDown( QgsComposerItem *item ); |
| 95 | + |
| 96 | + /**Moves an item to the top of the z-order list. |
| 97 | + * @param item item to move |
| 98 | + * @returns true if item was moved. Returns false if item was not found |
| 99 | + * in z-order list or was already at the top of the z-order list. |
| 100 | + * @see reorderItemUp |
| 101 | + * @see reorderItemDown |
| 102 | + * @see reorderItemToBottom |
| 103 | + * @note added in QGIS 2.5 |
| 104 | + */ |
| 105 | + bool reorderItemToTop( QgsComposerItem *item ); |
| 106 | + |
| 107 | + /**Moves an item to the bottom of the z-order list. |
| 108 | + * @param item item to move |
| 109 | + * @returns true if item was moved. Returns false if item was not found |
| 110 | + * in z-order list or was already at the bottom of the z-order list. |
| 111 | + * @see reorderItemUp |
| 112 | + * @see reorderItemDown |
| 113 | + * @see reorderItemToTop |
| 114 | + * @note added in QGIS 2.5 |
| 115 | + */ |
| 116 | + bool reorderItemToBottom( QgsComposerItem *item ); |
| 117 | + |
| 118 | + /**Finds the next composer item above an item. This method only considers |
| 119 | + * items which are currently in the composition, and ignores items which have been |
| 120 | + * removed from the composition. |
| 121 | + * @param item item to search above |
| 122 | + * @returns item above specified item. If no items were found, no item |
| 123 | + * will be returned. |
| 124 | + * @see getComposerItemBelow |
| 125 | + * @note added in QGIS 2.5 |
| 126 | + */ |
| 127 | + QgsComposerItem* getComposerItemAbove( QgsComposerItem *item ) const; |
| 128 | + |
| 129 | + /**Finds the next composer item below an item. This method only considers |
| 130 | + * items which are currently in the composition, and ignores items which have been |
| 131 | + * removed from the composition. |
| 132 | + * @param item item to search above |
| 133 | + * @returns item below specified item. If no items were found, no item |
| 134 | + * will be returned. |
| 135 | + * @see getComposerItemAbove |
| 136 | + * @note added in QGIS 2.5 |
| 137 | + */ |
| 138 | + QgsComposerItem* getComposerItemBelow( QgsComposerItem *item ) const; |
| 139 | + |
| 140 | + /**Returns the item z-order list. This list includes both items currently in the |
| 141 | + * composition and items which have been removed from the composition. |
| 142 | + * @returns item z-order list |
| 143 | + * @note added in QGIS 2.5 |
| 144 | + */ |
| 145 | + QList<QgsComposerItem *>* zOrderList(); |
| 146 | + |
| 147 | + /**Marks an item as removed from the composition. This must be called whenever an item |
| 148 | + * has been removed from the composition. |
| 149 | + * @param item to mark as removed from the composition |
| 150 | + * @see setItemRestored |
| 151 | + * @note added in QGIS 2.5 |
| 152 | + */ |
| 153 | + void setItemRemoved( QgsComposerItem *item ); |
| 154 | + |
| 155 | + /**Restores an item to the composition. This must be called whenever an item removed |
| 156 | + * from the composition is restored to the composition. |
| 157 | + * @param item to mark as restored to the composition |
| 158 | + * @see setItemRemoved |
| 159 | + * @note added in QGIS 2.5 |
| 160 | + */ |
| 161 | + void setItemRestored( QgsComposerItem *item ); |
| 162 | + |
| 163 | + /**Must be called when an item's display name is modified |
| 164 | + * @param item item to update |
| 165 | + * @see updateItemLockStatus |
| 166 | + * @see updateItemVisibility |
| 167 | + * @note added in QGIS 2.5 |
| 168 | + */ |
| 169 | + void updateItemDisplayName( QgsComposerItem *item ); |
| 170 | + |
| 171 | + /**Must be called when an item's lock status changes |
| 172 | + * @param item item to update |
| 173 | + * @see updateItemDisplayName |
| 174 | + * @see updateItemVisibility |
| 175 | + * @note added in QGIS 2.5 |
| 176 | + */ |
| 177 | + void updateItemLockStatus( QgsComposerItem *item ); |
| 178 | + |
| 179 | + /**Must be called when an item's visibility changes |
| 180 | + * @param item item to update |
| 181 | + * @see updateItemDisplayName |
| 182 | + * @see updateItemLockStatus |
| 183 | + * @note added in QGIS 2.5 |
| 184 | + */ |
| 185 | + void updateItemVisibility( QgsComposerItem *item ); |
| 186 | + |
| 187 | + public slots: |
| 188 | + |
| 189 | + /**Sets an item as the current selection from a QModelIndex |
| 190 | + * @param index QModelIndex of item to set as selected |
| 191 | + * @note added in QGIS 2.5 |
| 192 | + */ |
| 193 | + void setSelected( const QModelIndex &index ); |
| 194 | +}; |
0 commit comments