Skip to content

Commit

Permalink
Add undo/redo commands when toggling lock through items panel
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent afd9d23 commit 3e933dc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/core/layout/qgslayoutitem.cpp
Expand Up @@ -114,8 +114,14 @@ void QgsLayoutItem::setLocked( const bool locked )
return;
}

if ( mLayout && !mBlockUndoCommands )
mLayout->undoStack()->beginCommand( this, locked ? tr( "Item locked" ) : tr( "Item unlocked" ) );

mIsLocked = locked;

if ( mLayout && !mBlockUndoCommands )
mLayout->undoStack()->endCommand();

//inform model that id data has changed
if ( mLayout )
{
Expand Down Expand Up @@ -719,6 +725,7 @@ bool QgsLayoutItem::readPropertiesFromElement( const QDomElement &element, const
{
readObjectPropertiesFromElement( element, document, context );

mBlockUndoCommands = true;
mUuid = element.attribute( QStringLiteral( "uuid" ), QUuid::createUuid().toString() );
setId( element.attribute( QStringLiteral( "id" ) ) );
mReferencePoint = static_cast< ReferencePoint >( element.attribute( QStringLiteral( "referencePoint" ) ).toInt() );
Expand Down Expand Up @@ -826,6 +833,7 @@ bool QgsLayoutItem::readPropertiesFromElement( const QDomElement &element, const
mEvaluatedExcludeFromExports = mExcludeFromExports;
#endif

mBlockUndoCommands = false;
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/layout/qgslayoutitem.h
Expand Up @@ -590,6 +590,8 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
//! Background color
QColor mBackgroundColor = QColor( 255, 255, 255 );

bool mBlockUndoCommands = false;

void initConnectionsToLayout();

//! Prepares a painter by setting rendering flags
Expand Down
4 changes: 0 additions & 4 deletions src/gui/layout/qgslayoutview.cpp
Expand Up @@ -504,9 +504,7 @@ void QgsLayoutView::lockSelectedItems()
const QList<QgsLayoutItem *> selectionList = currentLayout()->selectedLayoutItems();
for ( QgsLayoutItem *item : selectionList )
{
currentLayout()->undoStack()->beginCommand( item, QString() );
item->setLocked( true );
currentLayout()->undoStack()->endCommand();
}

currentLayout()->deselectAll();
Expand All @@ -530,11 +528,9 @@ void QgsLayoutView::unlockAllItems()
if ( item && item->isLocked() )
{
focusItem = item;
currentLayout()->undoStack()->beginCommand( item, QString() );
item->setLocked( false );
//select unlocked items, same behavior as illustrator
item->setSelected( true );
currentLayout()->undoStack()->endCommand();
}
}
currentLayout()->undoStack()->endMacro();
Expand Down

0 comments on commit 3e933dc

Please sign in to comment.