27QgsLayoutItemUndoCommand::QgsLayoutItemUndoCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
29 , mItemUuid( item->uuid() )
30 , mLayout( item->layout() )
31 , mItemType( item->type() )
36bool QgsLayoutItemUndoCommand::mergeWith(
const QUndoCommand *command )
38 if ( command->id() == 0 )
41 const QgsLayoutItemUndoCommand *
c =
dynamic_cast<const QgsLayoutItemUndoCommand *
>( command );
46 if (
c->itemUuid() != itemUuid() )
49 setAfterState(
c->afterState() );
53void QgsLayoutItemUndoCommand::saveState( QDomDocument &stateDoc )
const
56 QDomElement documentElement = stateDoc.createElement( QStringLiteral(
"ItemState" ) );
62 stateDoc.appendChild( documentElement );
66 QgsDebugError( QStringLiteral(
"QgsLayoutItemUndoCommand::saveState: could not retrieve item %1 for saving state" ).arg( mItemUuid ) );
70void QgsLayoutItemUndoCommand::restoreState( QDomDocument &stateDoc )
77 item = recreateItem( mItemType, mLayout );
82 mLayout->project()->setDirty(
true );
83 mLayout->undoStack()->notifyUndoRedoOccurred( item );
89 mLayout->addLayoutItemPrivate( item );
93QString QgsLayoutItemUndoCommand::itemUuid()
const
98QgsLayout *QgsLayoutItemUndoCommand::layout()
const
108QgsLayoutItemDeleteUndoCommand::QgsLayoutItemDeleteUndoCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
109 : QgsLayoutItemUndoCommand( item, text, id, parent )
114bool QgsLayoutItemDeleteUndoCommand::mergeWith(
const QUndoCommand * )
119void QgsLayoutItemDeleteUndoCommand::redo()
132 layout()->removeLayoutItemPrivate( item );
136QgsLayoutItemAddItemCommand::QgsLayoutItemAddItemCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
137 : QgsLayoutItemUndoCommand( item, text, id, parent )
142bool QgsLayoutItemAddItemCommand::containsChange()
const
147bool QgsLayoutItemAddItemCommand::mergeWith(
const QUndoCommand * )
152void QgsLayoutItemAddItemCommand::undo()
163 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 ...
A container for the context for various read/write operations on 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)