26QgsLayoutItemUndoCommand::QgsLayoutItemUndoCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
28 , mItemUuid( item->uuid() )
29 , mLayout( item->layout() )
30 , mItemType( item->type() )
35bool QgsLayoutItemUndoCommand::mergeWith(
const QUndoCommand *command )
37 if ( command->id() == 0 )
40 const QgsLayoutItemUndoCommand *
c =
dynamic_cast<const QgsLayoutItemUndoCommand *
>( command );
45 if (
c->itemUuid() != itemUuid() )
48 setAfterState(
c->afterState() );
52void QgsLayoutItemUndoCommand::saveState( QDomDocument &stateDoc )
const
55 QDomElement documentElement = stateDoc.createElement( QStringLiteral(
"ItemState" ) );
61 stateDoc.appendChild( documentElement );
65 QgsDebugError( QStringLiteral(
"QgsLayoutItemUndoCommand::saveState: could not retrieve item %1 for saving state" ).arg( mItemUuid ) );
69void QgsLayoutItemUndoCommand::restoreState( QDomDocument &stateDoc )
76 item = recreateItem( mItemType, mLayout );
81 mLayout->project()->setDirty(
true );
82 mLayout->undoStack()->notifyUndoRedoOccurred( item );
88 mLayout->addLayoutItemPrivate( item );
92QString QgsLayoutItemUndoCommand::itemUuid()
const
97QgsLayout *QgsLayoutItemUndoCommand::layout()
const
107QgsLayoutItemDeleteUndoCommand::QgsLayoutItemDeleteUndoCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
108 : QgsLayoutItemUndoCommand( item, text, id, parent )
113bool QgsLayoutItemDeleteUndoCommand::mergeWith(
const QUndoCommand * )
118void QgsLayoutItemDeleteUndoCommand::redo()
131 layout()->removeLayoutItemPrivate( item );
135QgsLayoutItemAddItemCommand::QgsLayoutItemAddItemCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
136 : QgsLayoutItemUndoCommand( item, text, id, parent )
141bool QgsLayoutItemAddItemCommand::containsChange()
const
146bool QgsLayoutItemAddItemCommand::mergeWith(
const QUndoCommand * )
151void QgsLayoutItemAddItemCommand::undo()
162 layout()->removeLayoutItemPrivate( item );
Base class for commands to undo/redo layout and layout object changes.
static QgsLayoutItemRegistry * layoutItemRegistry()
Returns the application's layout item registry, used for layout item types.
QgsLayoutItem * createItem(int type, QgsLayout *layout) const
Creates a new instance of a layout item given the item type, and target layout.
Base class for graphical items within a QgsLayout.
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores the item state in a DOM element.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
bool readXml(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the item state from a DOM element.
void blockCommands(bool blocked)
Sets whether undo commands for the layout should be temporarily blocked.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...
The class is used as a container of context for various read/write operations on other objects.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define QgsDebugError(str)