Create undo/redo commands when changing item visibility

This commit is contained in:
Nyall Dawson 2017-10-04 21:29:41 +10:00
parent 3e933dcda8
commit bb2e1efdb8
4 changed files with 46 additions and 6 deletions

View File

@ -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.

View File

@ -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
}
@ -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 )
@ -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

View File

@ -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()

View File

@ -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: