26 QgsLayoutItemUndoCommand::QgsLayoutItemUndoCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
28 , mItemUuid( item->uuid() )
29 , mLayout( item->layout() )
30 , mItemType( item->type() )
35 bool 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() );
52 void QgsLayoutItemUndoCommand::saveState( QDomDocument &stateDoc )
const 55 QDomElement documentElement = stateDoc.createElement( QStringLiteral(
"ItemState" ) );
58 Q_ASSERT_X( item,
"QgsLayoutItemUndoCommand::saveState",
"could not retrieve item for saving state" );
61 stateDoc.appendChild( documentElement );
64 void QgsLayoutItemUndoCommand::restoreState( QDomDocument &stateDoc )
71 item = recreateItem( mItemType,
mLayout );
76 mLayout->project()->setDirty(
true );
77 mLayout->undoStack()->notifyUndoRedoOccurred( item );
83 mLayout->addLayoutItemPrivate( item );
87 QString QgsLayoutItemUndoCommand::itemUuid()
const 92 QgsLayout *QgsLayoutItemUndoCommand::layout()
const 102 QgsLayoutItemDeleteUndoCommand::QgsLayoutItemDeleteUndoCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
103 : QgsLayoutItemUndoCommand( item, text, id, parent )
108 bool QgsLayoutItemDeleteUndoCommand::mergeWith(
const QUndoCommand * )
113 void QgsLayoutItemDeleteUndoCommand::redo()
126 layout()->removeLayoutItemPrivate( item );
130 QgsLayoutItemAddItemCommand::QgsLayoutItemAddItemCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
131 : QgsLayoutItemUndoCommand( item, text, id, parent )
136 bool QgsLayoutItemAddItemCommand::containsChange()
const 141 bool QgsLayoutItemAddItemCommand::mergeWith(
const QUndoCommand * )
146 void QgsLayoutItemAddItemCommand::undo()
157 layout()->removeLayoutItemPrivate( item );
The class is used as a container of context for various read/write operations on other objects...
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.
Base class for commands to undo/redo layout and layout object changes.
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or a nullptr if a matching item could n...
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
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores the item state in a DOM element.
static QgsLayoutItemRegistry * layoutItemRegistry()
Returns the application's layout item registry, used for layout item types.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QPointer< QgsLayout > mLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void blockCommands(bool blocked)
Sets whether undo commands for the layout should be temporarily blocked.
bool readXml(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the item state from a DOM element.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.