24 #include <QApplication>
25 #include <QGraphicsItem>
26 #include <QDomDocument>
27 #include <QDomElement>
30 #include <QMessageBox>
35 , mComposition( composition )
75 void QgsComposerModel::refreshItemsInScene()
138 case Qt::DisplayRole:
139 if ( index.
column() == ItemId )
149 if ( index.
column() == ItemId )
162 case Qt::TextAlignmentRole:
163 return Qt::AlignLeft & Qt::AlignVCenter;
165 case Qt::CheckStateRole:
170 return item->
isVisible() ? Qt::Checked : Qt::Unchecked;
173 return item->
positionLock() ? Qt::Checked : Qt::Unchecked;
236 static QIcon lockIcon;
239 static QIcon showIcon;
245 case Qt::DisplayRole:
247 if ( section == ItemId )
258 case Qt::DecorationRole:
260 if ( section == Visibility )
262 return qVariantFromValue( showIcon );
264 else if ( section == LockStatus )
266 return qVariantFromValue( lockIcon );
275 case Qt::TextAlignmentRole:
276 return Qt::AlignLeft & Qt::AlignVCenter;
286 return Qt::MoveAction;
292 types <<
"application/x-vnd.qgis.qgis.composeritemid";
301 QDataStream stream( &encodedData, QIODevice::WriteOnly );
317 mimeData->
setData(
"application/x-vnd.qgis.qgis.composeritemid", encodedData );
327 Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
329 if ( column != ItemId )
334 if ( action == Qt::IgnoreAction )
339 if ( !data->
hasFormat(
"application/x-vnd.qgis.qgis.composeritemid" ) )
351 QByteArray encodedData = data->
data(
"application/x-vnd.qgis.qgis.composeritemid" );
352 QDataStream stream( &encodedData, QIODevice::ReadOnly );
356 while ( !stream.
atEnd() )
363 droppedItems << const_cast<QgsComposerItem*>( item );
368 if ( droppedItems.
length() == 0 )
393 int insertPos = destPos;
395 for ( ; itemIt != droppedItems.
end(); ++itemIt )
404 if ( listPos < destPos )
411 itemIt = droppedItems.
begin();
412 for ( ; itemIt != droppedItems.
end(); ++itemIt )
418 itemIt = droppedItems.
begin();
419 for ( ; itemIt != droppedItems.
end(); ++itemIt )
425 rebuildSceneItemList();
426 mComposition->updateZValues(
false );
453 refreshItemsInScene();
470 for ( ; itemIt != itemList.
end(); ++itemIt )
477 sortedList.
append( composerItem );
483 rebuildSceneItemList();
486 void QgsComposerModel::rebuildSceneItemList()
501 if ( sceneListPos == row )
506 else if ( sceneListPos != -1 )
529 refreshItemsInScene();
557 refreshItemsInScene();
562 int row = itemIndex.
row();
565 refreshItemsInScene();
592 int row = itemIndex.
row();
595 refreshItemsInScene();
615 rebuildSceneItemList();
627 QModelIndex itemIndex = indexForItem( item, ItemId );
646 QModelIndex itemIndex = indexForItem( item, LockStatus );
665 QModelIndex itemIndex = indexForItem( item, Visibility );
684 QModelIndex itemIndex = indexForItem( item, ItemId );
722 if ( it.
value() && !( it.
value()->isRemoved() ) )
737 int row = itemIndex.
row();
739 refreshItemsInScene();
772 if ( it.
value() && !( it.
value()->isRemoved() ) )
787 int row = itemIndex.
row();
789 refreshItemsInScene();
823 int row = itemIndex.
row();
825 refreshItemsInScene();
859 int row = itemIndex.
row();
861 refreshItemsInScene();
896 if ( !it.
peekNext()->isGroupMember() )
918 return flags | Qt::ItemIsDropEnabled;;
925 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
927 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
929 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
947 return index( row, column );
bool positionLock() const
Returns whether position lock for mouse drags is enabled returns true if item is locked for mouse mov...
Qt::DropActions supportedDropActions() const override
QByteArray data(const QString &mimeType) const
QgsComposerItem * getComposerItemAbove(QgsComposerItem *item) const
Finds the next composer item above an item.
QgsComposerModel(QgsComposition *composition, QObject *parent=0)
Constructor.
bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
void push_back(const T &value)
QList< QGraphicsItem * > items() 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.
int zOrderListSize() const
Returns the size of the z-order list, which includes items which may have been removed from the compo...
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 push_front(const T &value)
void updateItemVisibility(QgsComposerItem *item)
Must be called when an item'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's display name is modified.
bool zOrderDescending(QgsComposerItem *item1, QgsComposerItem *item2)
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's lock status changes.
QString uuid() const
Get item identification name.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
QList< QgsComposerItem * > mItemZList
Maintains z-Order of items.
void append(const T &value)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void setIsRemoved(const bool removed)
Sets whether this item has been removed from the composition.
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)
const QgsComposerItem * getComposerItemByUuid(const QString theUuid) const
Returns a composer item given its unique identifier.
void * internalPointer() const
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.
Graphics scene for map printing.
QVariant data(const QModelIndex &index, int role) const override
QModelIndex createIndex(int row, int column, void *ptr) const
bool findNext(const T &value)
bool contains(const T &value) const
void removeItem(QgsComposerItem *item)
Removes an item from the z-order list.
virtual QString displayName() const
Get item display name.
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 reorderItemUp(QgsComposerItem *item)
Moves an item up the z-order list.
QgsComposerItem * getComposerItemBelow(QgsComposerItem *item) const
Finds the next composer item below an item.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void insert(int i, const T &value)
virtual void setId(const QString &id)
Set item's id (which is not necessarly unique)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
const T & peekPrevious() const
void updateItemSelectStatus(QgsComposerItem *item)
Must be called when an item's selection status changes.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
void setData(const QString &mimeType, const QByteArray &data)
void setItemRemoved(QgsComposerItem *item)
Marks an item as removed from the composition.
const_iterator constEnd() const
const_iterator constBegin() const
bool reorderItemToTop(QgsComposerItem *item)
Moves an item to the top of the z-order list.
void insert(const T &value)
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.
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.
Qt::ItemFlags flags(const QModelIndex &index) const override
QString id() const
Get item's id (which is not necessarly unique)