23 #include <QApplication> 24 #include <QGraphicsItem> 25 #include <QDomDocument> 26 #include <QDomElement> 29 #include <QMessageBox> 34 , mComposition( composition )
74 void QgsComposerModel::refreshItemsInScene()
137 case Qt::DisplayRole:
162 return qVariantFromValue( qobject_cast<QObject *>( item ) );
164 case Qt::TextAlignmentRole:
165 return Qt::AlignLeft & Qt::AlignVCenter;
167 case Qt::CheckStateRole:
172 return item->
isVisible() ? Qt::Checked : Qt::Unchecked;
175 return item->
positionLock() ? Qt::Checked : Qt::Unchecked;
231 static QIcon lockIcon;
234 static QIcon showIcon;
240 case Qt::DisplayRole:
249 case Qt::DecorationRole:
253 return qVariantFromValue( showIcon );
257 return qVariantFromValue( lockIcon );
263 case Qt::TextAlignmentRole:
264 return Qt::AlignLeft & Qt::AlignVCenter;
274 return Qt::MoveAction;
280 types <<
"application/x-vnd.qgis.qgis.composeritemid";
289 QDataStream stream( &encodedData, QIODevice::WriteOnly );
305 mimeData->
setData(
"application/x-vnd.qgis.qgis.composeritemid", encodedData );
322 if ( action == Qt::IgnoreAction )
327 if ( !data->
hasFormat(
"application/x-vnd.qgis.qgis.composeritemid" ) )
339 QByteArray encodedData = data->
data(
"application/x-vnd.qgis.qgis.composeritemid" );
340 QDataStream stream( &encodedData, QIODevice::ReadOnly );
344 while ( !stream.
atEnd() )
351 droppedItems << const_cast<QgsComposerItem*>( item );
356 if ( droppedItems.
length() == 0 )
381 int insertPos = destPos;
383 for ( ; itemIt != droppedItems.
end(); ++itemIt )
392 if ( listPos < destPos )
399 itemIt = droppedItems.
begin();
400 for ( ; itemIt != droppedItems.
end(); ++itemIt )
406 itemIt = droppedItems.
begin();
407 for ( ; itemIt != droppedItems.
end(); ++itemIt )
413 rebuildSceneItemList();
414 mComposition->updateZValues(
false );
441 refreshItemsInScene();
458 for ( ; itemIt != itemList.
end(); ++itemIt )
465 sortedList.
append( composerItem );
471 rebuildSceneItemList();
474 void QgsComposerModel::rebuildSceneItemList()
488 if ( sceneListPos == row )
493 else if ( sceneListPos != -1 )
516 refreshItemsInScene();
544 refreshItemsInScene();
549 int row = itemIndex.
row();
552 refreshItemsInScene();
579 int row = itemIndex.
row();
582 refreshItemsInScene();
602 rebuildSceneItemList();
709 if ( it.
value() && !( it.
value()->isRemoved() ) )
724 int row = itemIndex.
row();
726 refreshItemsInScene();
759 if ( it.
value() && !( it.
value()->isRemoved() ) )
774 int row = itemIndex.
row();
776 refreshItemsInScene();
810 int row = itemIndex.
row();
812 refreshItemsInScene();
846 int row = itemIndex.
row();
848 refreshItemsInScene();
883 if ( !it.
peekNext()->isGroupMember() )
905 return flags | Qt::ItemIsDropEnabled;
912 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
914 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
916 return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
934 return index( row, column );
955 , mComposition( composition )
985 mItemTypeFilter = itemType;
991 if ( mExceptedList == exceptList )
994 mExceptedList = exceptList;
1008 if ( mExceptedList.
contains( item ) )
Qt::DropActions supportedDropActions() const override
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
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)
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QgsComposerModel * itemsModel()
Returns the items model attached to the composition.
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.
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)
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.
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)
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's lock status changes.
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.
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 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.
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.
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.
QAbstractItemModel * sourceModel() const
bool reorderItemUp(QgsComposerItem *item)
Moves an item up the z-order list.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void insert(int i, const T &value)
void setSortLocaleAware(bool on)
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
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.
void insert(const T &value)
void setFilterType(QgsComposerItem::ItemType itemType)
Sets the item type filter.
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's id (which is not necessarly unique)
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