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();
void setDirty(bool b=true)
Flag the project as dirty (modified).
Base class for graphical items within a QgsLayout.
bool isBlocked() const
Returns true if undo commands are currently blocked.
void push(QUndoCommand *command)
Manually pushes a command to the stack, and takes ownership of the command.
void endCommand()
Saves final state of an object and pushes the active command to the undo history. ...
QgsLayoutUndoStack(QgsLayout *layout)
Constructor for QgsLayoutUndoStack, for the specified parent layout.
void notifyUndoRedoOccurred(QgsLayoutItem *item)
Notifies the stack that an undo or redo action occurred for a specified item.
void cancelCommand()
Cancels the active command, discarding it without pushing to the undo history.
virtual QString uuid() const
Returns the item identification string.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void beginMacro(const QString &commandText)
Starts a macro command, with the given descriptive commandText.
void blockCommands(bool blocked)
Sets whether undo commands for the layout should be temporarily blocked.
void beginCommand(QgsLayoutUndoObjectInterface *object, const QString &commandText, int id=0)
Begins a new undo command for the specified object.
QUndoStack * stack()
Returns a pointer to the internal QUndoStack.
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.
Interface for layout objects which support undo/redo commands.
void endMacro()
Ends a macro command.
void undoRedoOccurredForItems(QSet< QString > itemUuids)
Emitted when an undo or redo action has occurred, which affected a set of layout itemUuids.
QgsProject * project() const
The project associated with the layout.