Skip to content

Commit

Permalink
Move actions which apply to selected items only to QgsLayoutView
Browse files Browse the repository at this point in the history
Selections are a gui concept, so these actions belong to the
gui class instead of cluterring QgsLayout
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent fdba8f1 commit 822d6f7
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 254 deletions.
50 changes: 8 additions & 42 deletions python/core/layout/qgslayout.sip
Expand Up @@ -98,19 +98,6 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
not correctly emit signals to allow the layout's model to update.
%End

void lockSelectedItems();
%Docstring
Locks any selected items, preventing them from being interacted with
by mouse interactions.
.. seealso:: unlockAllItems()
%End

void unlockAllItems();
%Docstring
Unlocks all locked items in the layout.
.. seealso:: lockSelectedItems()
%End

bool raiseItem( QgsLayoutItem *item, bool deferUpdate = false );
%Docstring
Raises an ``item`` up the z-order.
Expand All @@ -122,6 +109,7 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
updating the scene for each one.

.. seealso:: lowerItem()
.. seealso:: updateZValues()
:rtype: bool
%End

Expand All @@ -136,6 +124,7 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
updating the scene for each one.

.. seealso:: raiseItem()
.. seealso:: updateZValues()
:rtype: bool
%End

Expand All @@ -150,6 +139,7 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
updating the scene for each one.

.. seealso:: moveItemToBottom()
.. seealso:: updateZValues()
:rtype: bool
%End

Expand All @@ -163,39 +153,15 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
updating the scene for each one.

.. seealso:: moveItemToTop()
.. seealso:: updateZValues()
:rtype: bool
%End

void raiseSelectedItems();
%Docstring
Raises the selected items up the z-order.
.. seealso:: lowerSelectedItems()
.. seealso:: moveSelectedItemsToTop()
.. seealso:: moveSelectedItemsToBottom()
%End

void lowerSelectedItems();
%Docstring
Lowers the selected items down the z-order.
.. seealso:: raiseSelectedItems()
.. seealso:: moveSelectedItemsToTop()
.. seealso:: moveSelectedItemsToBottom()
%End

void moveSelectedItemsToTop();
%Docstring
Raises the selected items to the top of the z-order.
.. seealso:: raiseSelectedItems()
.. seealso:: lowerSelectedItems()
.. seealso:: moveSelectedItemsToBottom()
%End

void moveSelectedItemsToBottom();
void updateZValues( const bool addUndoCommands = true );
%Docstring
Lowers the selected items to the bottom of the z-order.
.. seealso:: raiseSelectedItems()
.. seealso:: lowerSelectedItems()
.. seealso:: moveSelectedItemsToTop()
Resets the z-values of items based on their position in the internal
z order list. This should be called after any stacking changes
which deferred z-order updates.
%End

QgsLayoutItem *itemByUuid( const QString &uuid );
Expand Down
45 changes: 45 additions & 0 deletions python/gui/layout/qgslayoutview.sip
Expand Up @@ -210,6 +210,51 @@ class QgsLayoutView: QGraphicsView
.. seealso:: selectNextItemAbove()
.. seealso:: selectAll()
.. seealso:: deselectAll()
%End

void raiseSelectedItems();
%Docstring
Raises the selected items up the z-order.
.. seealso:: lowerSelectedItems()
.. seealso:: moveSelectedItemsToTop()
.. seealso:: moveSelectedItemsToBottom()
%End

void lowerSelectedItems();
%Docstring
Lowers the selected items down the z-order.
.. seealso:: raiseSelectedItems()
.. seealso:: moveSelectedItemsToTop()
.. seealso:: moveSelectedItemsToBottom()
%End

void moveSelectedItemsToTop();
%Docstring
Raises the selected items to the top of the z-order.
.. seealso:: raiseSelectedItems()
.. seealso:: lowerSelectedItems()
.. seealso:: moveSelectedItemsToBottom()
%End

void moveSelectedItemsToBottom();
%Docstring
Lowers the selected items to the bottom of the z-order.
.. seealso:: raiseSelectedItems()
.. seealso:: lowerSelectedItems()
.. seealso:: moveSelectedItemsToTop()
%End

void lockSelectedItems();
%Docstring
Locks any selected items, preventing them from being interacted with
by mouse interactions.
.. seealso:: unlockAllItems()
%End

void unlockAllItems();
%Docstring
Unlocks all locked items in the layout.
.. seealso:: lockSelectedItems()
%End

void viewChanged();
Expand Down
18 changes: 6 additions & 12 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -542,18 +542,12 @@ void QgsLayoutDesignerDialog::snapToItems( bool enabled )

void QgsLayoutDesignerDialog::unlockAllItems()
{
if ( mLayout )
{
mLayout->unlockAllItems();
}
mView->unlockAllItems();
}

void QgsLayoutDesignerDialog::lockSelectedItems()
{
if ( mLayout )
{
mLayout->lockSelectedItems();
}
mView->lockSelectedItems();
}

void QgsLayoutDesignerDialog::setPanelVisibility( bool hidden )
Expand Down Expand Up @@ -616,22 +610,22 @@ void QgsLayoutDesignerDialog::setPanelVisibility( bool hidden )

void QgsLayoutDesignerDialog::raiseSelectedItems()
{
mLayout->raiseSelectedItems();
mView->raiseSelectedItems();
}

void QgsLayoutDesignerDialog::lowerSelectedItems()
{
mLayout->lowerSelectedItems();
mView->lowerSelectedItems();
}

void QgsLayoutDesignerDialog::moveSelectedItemsToTop()
{
mLayout->moveSelectedItemsToTop();
mView->moveSelectedItemsToTop();
}

void QgsLayoutDesignerDialog::moveSelectedItemsToBottom()
{
mLayout->moveSelectedItemsToBottom();
mView->moveSelectedItemsToBottom();
}

void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
Expand Down
121 changes: 0 additions & 121 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -113,47 +113,6 @@ void QgsLayout::deselectAll()
emit selectedItemChanged( nullptr );
}

void QgsLayout::lockSelectedItems()
{
mUndoStack->beginMacro( tr( "Items locked" ) );
const QList<QgsLayoutItem *> selectionList = selectedLayoutItems();
for ( QgsLayoutItem *item : selectionList )
{
mUndoStack->beginCommand( item, QString() );
item->setLocked( true );
mUndoStack->endCommand();
}

deselectAll();
mUndoStack->endMacro();
}

void QgsLayout::unlockAllItems()
{
//unlock all items in composer

mUndoStack->beginMacro( tr( "Items unlocked" ) );

//first, clear the selection
deselectAll();

const QList<QGraphicsItem *> itemList = items();
for ( QGraphicsItem *graphicItem : itemList )
{
QgsLayoutItem *item = dynamic_cast<QgsLayoutItem *>( graphicItem );
if ( item && item->isLocked() )
{
mUndoStack->beginCommand( item, QString() );
item->setLocked( false );
//select unlocked items, same behavior as illustrator
item->setSelected( true );
emit selectedItemChanged( item );
mUndoStack->endCommand();
}
}
mUndoStack->endMacro();
}

bool QgsLayout::raiseItem( QgsLayoutItem *item, bool deferUpdate )
{
//model handles reordering items
Expand Down Expand Up @@ -206,86 +165,6 @@ bool QgsLayout::moveItemToBottom( QgsLayoutItem *item, bool deferUpdate )
return result;
}

void QgsLayout::raiseSelectedItems()
{
const QList<QgsLayoutItem *> selectedItems = selectedLayoutItems();
bool itemsRaised = false;
for ( QgsLayoutItem *item : selectedItems )
{
itemsRaised = itemsRaised | raiseItem( item, true );
}

if ( !itemsRaised )
{
//no change
return;
}

//update all positions
updateZValues();
update();
}

void QgsLayout::lowerSelectedItems()
{
const QList<QgsLayoutItem *> selectedItems = selectedLayoutItems();
bool itemsLowered = false;
for ( QgsLayoutItem *item : selectedItems )
{
itemsLowered = itemsLowered | lowerItem( item, true );
}

if ( !itemsLowered )
{
//no change
return;
}

//update all positions
updateZValues();
update();
}

void QgsLayout::moveSelectedItemsToTop()
{
const QList<QgsLayoutItem *> selectedItems = selectedLayoutItems();
bool itemsRaised = false;
for ( QgsLayoutItem *item : selectedItems )
{
itemsRaised = itemsRaised | moveItemToTop( item, true );
}

if ( !itemsRaised )
{
//no change
return;
}

//update all positions
updateZValues();
update();
}

void QgsLayout::moveSelectedItemsToBottom()
{
const QList<QgsLayoutItem *> selectedItems = selectedLayoutItems();
bool itemsLowered = false;
for ( QgsLayoutItem *item : selectedItems )
{
itemsLowered = itemsLowered | moveItemToBottom( item, true );
}

if ( !itemsLowered )
{
//no change
return;
}

//update all positions
updateZValues();
update();
}

QgsLayoutItem *QgsLayout::itemByUuid( const QString &uuid )
{
QList<QgsLayoutItem *> itemList;
Expand Down

0 comments on commit 822d6f7

Please sign in to comment.