25 , mUndoStack( new QUndoStack( layout ) )
27 connect( mUndoStack.get(), &QUndoStack::indexChanged,
this, &QgsLayoutUndoStack::indexChanged );
32 if ( mBlockedCommands == 0 )
33 mUndoStack->beginMacro( commandText );
38 if ( mBlockedCommands == 0 )
39 mUndoStack->endMacro();
49 mActiveCommands.emplace_back( std::unique_ptr< QgsAbstractLayoutUndoCommand >( object->
createCommand( commandText,
id,
nullptr ) ) );
50 mActiveCommands.back()->saveBeforeState();
55 if ( mActiveCommands.empty() )
58 mActiveCommands.back()->saveAfterState();
59 if ( mBlockedCommands == 0 && mActiveCommands.back()->containsChange() )
61 mUndoStack->push( mActiveCommands.back().release() );
65 mActiveCommands.pop_back();
70 if ( mActiveCommands.empty() )
73 mActiveCommands.pop_back();
78 return mUndoStack.get();
83 mUndoRedoOccurredItemUuids.insert( item->
uuid() );
94 if ( mBlockedCommands > 0 )
101 return mBlockedCommands > 0;
106 if ( mBlockedCommands > 0 )
110 mUndoStack->push( cmd );
115 void QgsLayoutUndoStack::indexChanged()
117 if ( mUndoRedoOccurredItemUuids.empty() )
121 mUndoRedoOccurredItemUuids.clear();
Base class for graphical items within a QgsLayout.
virtual QString uuid() const
Returns the item identification string.
Interface for layout objects which support undo/redo commands.
virtual QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr)=0
Creates a new layout undo command with the specified text and parent.
void endCommand()
Saves final state of an object and pushes the active command to the undo history.
void cancelCommand()
Cancels the active command, discarding it without pushing to the undo history.
void beginMacro(const QString &commandText)
Starts a macro command, with the given descriptive commandText.
void beginCommand(QgsLayoutUndoObjectInterface *object, const QString &commandText, int id=0)
Begins a new undo command for the specified object.
void notifyUndoRedoOccurred(QgsLayoutItem *item)
Notifies the stack that an undo or redo action occurred for a specified item.
void push(QUndoCommand *command)
Manually pushes a command to the stack, and takes ownership of the command.
void endMacro()
Ends a macro command.
bool isBlocked() const
Returns true if undo commands are currently blocked.
void undoRedoOccurredForItems(QSet< QString > itemUuids)
Emitted when an undo or redo action has occurred, which affected a set of layout itemUuids.
QUndoStack * stack()
Returns a pointer to the internal QUndoStack.
void blockCommands(bool blocked)
Sets whether undo commands for the layout should be temporarily blocked.
QgsLayoutUndoStack(QgsLayout *layout)
Constructor for QgsLayoutUndoStack, for the specified parent layout.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsProject * project() const
The project associated with the layout.
void setDirty(bool b=true)
Flag the project as dirty (modified).