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;
232 static QIcon lockIcon;
235 static QIcon showIcon;
241 case Qt::DisplayRole:
243 if ( section == ItemId )
250 case Qt::DecorationRole:
252 if ( section == Visibility )
254 return qVariantFromValue( showIcon );
256 else if ( section == LockStatus )
258 return qVariantFromValue( lockIcon );
264 case Qt::TextAlignmentRole:
265 return Qt::AlignLeft & Qt::AlignVCenter;
275 return Qt::MoveAction;
281 types <<
"application/x-vnd.qgis.qgis.composeritemid";
290 QDataStream stream( &encodedData, QIODevice::WriteOnly );
306 mimeData->
setData(
"application/x-vnd.qgis.qgis.composeritemid", encodedData );
318 if ( column != ItemId )
323 if ( action == Qt::IgnoreAction )
328 if ( !data->
hasFormat(
"application/x-vnd.qgis.qgis.composeritemid" ) )
340 QByteArray encodedData = data->
data(
"application/x-vnd.qgis.qgis.composeritemid" );
341 QDataStream stream( &encodedData, QIODevice::ReadOnly );
345 while ( !stream.
atEnd() )
352 droppedItems << const_cast<QgsComposerItem*>( item );
357 if ( droppedItems.
length() == 0 )
382 int insertPos = destPos;
384 for ( ; itemIt != droppedItems.
end(); ++itemIt )
393 if ( listPos < destPos )
400 itemIt = droppedItems.
begin();
401 for ( ; itemIt != droppedItems.
end(); ++itemIt )
407 itemIt = droppedItems.
begin();
408 for ( ; itemIt != droppedItems.
end(); ++itemIt )
414 rebuildSceneItemList();
415 mComposition->updateZValues(
false );
442 refreshItemsInScene();
459 for ( ; itemIt != itemList.
end(); ++itemIt )
466 sortedList.
append( composerItem );
472 rebuildSceneItemList();
475 void QgsComposerModel::rebuildSceneItemList()
489 if ( sceneListPos == row )
494 else if ( sceneListPos != -1 )
517 refreshItemsInScene();
545 refreshItemsInScene();
550 int row = itemIndex.
row();
553 refreshItemsInScene();
580 int row = itemIndex.
row();
583 refreshItemsInScene();
603 rebuildSceneItemList();
615 QModelIndex itemIndex = indexForItem( item, ItemId );
634 QModelIndex itemIndex = indexForItem( item, LockStatus );
653 QModelIndex itemIndex = indexForItem( item, Visibility );
672 QModelIndex itemIndex = indexForItem( item, ItemId );
710 if ( it.
value() && !( it.
value()->isRemoved() ) )
725 int row = itemIndex.
row();
727 refreshItemsInScene();
760 if ( it.
value() && !( it.
value()->isRemoved() ) )
775 int row = itemIndex.
row();
777 refreshItemsInScene();
811 int row = itemIndex.
row();
813 refreshItemsInScene();
847 int row = itemIndex.
row();
849 refreshItemsInScene();
884 if ( !it.
peekNext()->isGroupMember() )
906 return flags | Qt::ItemIsDropEnabled;
913 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
915 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
917 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
935 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.
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
const QgsComposerItem * getComposerItemByUuid(const QString &theUuid) const
Returns a composer item given its unique identifier.
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)
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)
virtual bool isRemoved() const
Returns whether this item has been removed from the composition.
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.
QgsComposerModel(QgsComposition *composition, QObject *parent=nullptr)
Constructor.
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)