Skip to content

Commit

Permalink
When moving/resizing grouped items, don't snap to selected
Browse files Browse the repository at this point in the history
groups members
  • Loading branch information
nyalldawson committed Oct 9, 2017
1 parent f58947d commit 46a0a48
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/core/layout/qgslayoutitemundocommand.cpp
Expand Up @@ -116,9 +116,10 @@ void QgsLayoutItemDeleteUndoCommand::redo()
}

QgsLayoutItem *item = layout()->itemByUuid( itemUuid() );
Q_ASSERT_X( item, "QgsLayoutItemDeleteUndoCommand::redo", "could not find item to re-delete!" );
//Q_ASSERT_X( item, "QgsLayoutItemDeleteUndoCommand::redo", "could not find item to re-delete!" );

layout()->removeLayoutItemPrivate( item );
if ( item )
layout()->removeLayoutItemPrivate( item );
}

QgsLayoutItemAddItemCommand::QgsLayoutItemAddItemCommand( QgsLayoutItem *item, const QString &text, int id, QUndoCommand *parent )
Expand Down
43 changes: 21 additions & 22 deletions src/gui/layout/qgslayoutmousehandles.cpp
Expand Up @@ -132,26 +132,7 @@ void QgsLayoutMouseHandles::drawSelectedItemBounds( QPainter *painter )
painter->setBrush( Qt::NoBrush );

QList< QgsLayoutItem * > itemsToDraw;

std::function< void( const QList< QgsLayoutItem * > items ) > collectItems;

collectItems = [&itemsToDraw, &collectItems]( const QList< QgsLayoutItem * > items )
{
for ( QgsLayoutItem *item : items )
{
if ( item->type() == QgsLayoutItemRegistry::LayoutGroup )
{
// if a group is selected, we don't draw the bounds of the group - instead we draw the bounds of the grouped items
collectItems( static_cast< QgsLayoutItemGroup * >( item )->items() );
}
else
{
itemsToDraw << item;
}
}
};
collectItems( selectedItems );

collectItems( selectedItems, itemsToDraw );

for ( QgsLayoutItem *item : qgsAsConst( itemsToDraw ) )
{
Expand Down Expand Up @@ -736,18 +717,20 @@ QPointF QgsLayoutMouseHandles::snapPoint( QPointF originalPoint, QgsLayoutMouseH
bool snapped = false;

const QList< QgsLayoutItem * > selectedItems = mLayout->selectedLayoutItems();
QList< QgsLayoutItem * > itemsToExclude;
collectItems( selectedItems, itemsToExclude );

//depending on the mode, we either snap just the single point, or all the bounds of the selection
QPointF snappedPoint;
switch ( mode )
{
case Item:
snappedPoint = mLayout->snapper().snapRect( rect().translated( originalPoint ), mView->transform().m11(), snapped, snapHorizontal ? mHorizontalSnapLine.get() : nullptr,
snapVertical ? mVerticalSnapLine.get() : nullptr, &selectedItems ).topLeft();
snapVertical ? mVerticalSnapLine.get() : nullptr, &itemsToExclude ).topLeft();
break;
case Point:
snappedPoint = mLayout->snapper().snapPoint( originalPoint, mView->transform().m11(), snapped, snapHorizontal ? mHorizontalSnapLine.get() : nullptr,
snapVertical ? mVerticalSnapLine.get() : nullptr, &selectedItems );
snapVertical ? mVerticalSnapLine.get() : nullptr, &itemsToExclude );
break;
}

Expand All @@ -760,6 +743,22 @@ void QgsLayoutMouseHandles::hideAlignItems()
mVerticalSnapLine->hide();
}

void QgsLayoutMouseHandles::collectItems( const QList<QgsLayoutItem *> items, QList<QgsLayoutItem *> &collected )
{
for ( QgsLayoutItem *item : items )
{
if ( item->type() == QgsLayoutItemRegistry::LayoutGroup )
{
// if a group is selected, we don't draw the bounds of the group - instead we draw the bounds of the grouped items
collectItems( static_cast< QgsLayoutItemGroup * >( item )->items(), collected );
}
else
{
collected << item;
}
}
}

void QgsLayoutMouseHandles::mousePressEvent( QGraphicsSceneMouseEvent *event )
{
//save current cursor position
Expand Down
4 changes: 4 additions & 0 deletions src/gui/layout/qgslayoutmousehandles.h
Expand Up @@ -29,6 +29,7 @@
class QgsLayout;
class QGraphicsView;
class QgsLayoutView;
class QgsLayoutItem;
class QInputEvent;

///@cond PRIVATE
Expand Down Expand Up @@ -207,6 +208,9 @@ class GUI_EXPORT QgsLayoutMouseHandles: public QObject, public QGraphicsRectItem

void hideAlignItems();

//! Collects all items from a list of \a items, exploring for any group members and adding them too
void collectItems( const QList< QgsLayoutItem * > items, QList< QgsLayoutItem * > &collected );

};

///@endcond PRIVATE
Expand Down

0 comments on commit 46a0a48

Please sign in to comment.