28using namespace Qt::StringLiterals;
31QgsLayoutItemUndoCommand::QgsLayoutItemUndoCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
33 , mItemUuid( item->uuid() )
34 , mLayout( item->layout() )
35 , mItemType( item->type() )
40bool QgsLayoutItemUndoCommand::mergeWith(
const QUndoCommand *command )
42 if ( command->id() == 0 )
45 const QgsLayoutItemUndoCommand *
c =
dynamic_cast<const QgsLayoutItemUndoCommand *
>( command );
50 if (
c->itemUuid() != itemUuid() )
53 setAfterState(
c->afterState() );
57void QgsLayoutItemUndoCommand::saveState( QDomDocument &stateDoc )
const
60 QDomElement documentElement = stateDoc.createElement( u
"ItemState"_s );
66 stateDoc.appendChild( documentElement );
70 QgsDebugError( u
"QgsLayoutItemUndoCommand::saveState: could not retrieve item %1 for saving state"_s.arg( mItemUuid ) );
74void QgsLayoutItemUndoCommand::restoreState( QDomDocument &stateDoc )
81 item = recreateItem( mItemType, mLayout );
86 mLayout->project()->setDirty(
true );
87 mLayout->undoStack()->notifyUndoRedoOccurred( item );
93 mLayout->addLayoutItemPrivate( item );
97QString QgsLayoutItemUndoCommand::itemUuid()
const
102QgsLayout *QgsLayoutItemUndoCommand::layout()
const
112QgsLayoutItemDeleteUndoCommand::QgsLayoutItemDeleteUndoCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
113 : QgsLayoutItemUndoCommand( item, text, id, parent )
118bool QgsLayoutItemDeleteUndoCommand::mergeWith(
const QUndoCommand * )
123void QgsLayoutItemDeleteUndoCommand::redo()
136 layout()->removeLayoutItemPrivate( item );
140QgsLayoutItemAddItemCommand::QgsLayoutItemAddItemCommand(
QgsLayoutItem *item,
const QString &text,
int id, QUndoCommand *parent )
141 : QgsLayoutItemUndoCommand( item, text, id, parent )
146bool QgsLayoutItemAddItemCommand::containsChange()
const
151bool QgsLayoutItemAddItemCommand::mergeWith(
const QUndoCommand * )
156void QgsLayoutItemAddItemCommand::undo()
167 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)