Skip to content

Commit

Permalink
Create undo/redo commands when changing item visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent 3e933dc commit bb2e1ef
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
10 changes: 10 additions & 0 deletions python/core/layout/qgslayoutitem.sip
Expand Up @@ -113,6 +113,16 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
Sets whether the item should be selected.
%End

virtual void setVisibility( const bool visible );
%Docstring
Sets whether the item is ``visible``.
.. note::

QGraphicsItem.setVisible should not be called directly
on a QgsLayoutItem, as some item types (e.g., groups) need to override
the visibility toggle.
%End

void setLocked( const bool locked );
%Docstring
Sets whether the item is ``locked``, preventing mouse interactions with the item.
Expand Down
32 changes: 27 additions & 5 deletions src/core/layout/qgslayoutitem.cpp
Expand Up @@ -85,14 +85,13 @@ void QgsLayoutItem::setId( const QString &id )
mId = id;
setToolTip( id );

//TODO
#if 0
//inform model that id data has changed
if ( mComposition )
if ( mLayout )
{
mComposition->itemsModel()->updateItemDisplayName( this );
mLayout->itemsModel()->updateItemDisplayName( this );
}

#if 0 //TODO
emit itemChanged();
#endif
}
Expand All @@ -107,6 +106,29 @@ void QgsLayoutItem::setSelected( bool selected )
}
}

void QgsLayoutItem::setVisibility( const bool visible )
{
if ( visible == isVisible() )
{
//nothing to do
return;
}

if ( mLayout && !mBlockUndoCommands )
mLayout->undoStack()->beginCommand( this, visible ? tr( "Item shown" ) : tr( "Item hidden" ) );

QGraphicsItem::setVisible( visible );

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

//inform model that visibility has changed
if ( mLayout )
{
mLayout->itemsModel()->updateItemVisibility( this );
}
}

void QgsLayoutItem::setLocked( const bool locked )
{
if ( locked == mIsLocked )
Expand Down Expand Up @@ -750,7 +772,7 @@ bool QgsLayoutItem::readPropertiesFromElement( const QDomElement &element, const
setLocked( false );
}
//visibility
setVisible( element.attribute( "visibility", "1" ) != "0" );
setVisibility( element.attribute( "visibility", "1" ) != "0" );
setZValue( element.attribute( "zValue" ).toDouble() );

//frame
Expand Down
8 changes: 8 additions & 0 deletions src/core/layout/qgslayoutitem.h
Expand Up @@ -133,6 +133,14 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
*/
virtual void setSelected( bool selected );

/**
* Sets whether the item is \a visible.
* \note QGraphicsItem::setVisible should not be called directly
* on a QgsLayoutItem, as some item types (e.g., groups) need to override
* the visibility toggle.
*/
virtual void setVisibility( const bool visible );

/**
* Sets whether the item is \a locked, preventing mouse interactions with the item.
* \see isLocked()
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutmodel.cpp
Expand Up @@ -207,7 +207,7 @@ bool QgsLayoutModel::setData( const QModelIndex &index, const QVariant &value, i
{
case Visibility:
//first column is item visibility
item->setVisible( value.toBool() );
item->setVisibility( value.toBool() );
return true;

case LockStatus:
Expand Down

0 comments on commit bb2e1ef

Please sign in to comment.