mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
When moving/resizing grouped items, don't snap to selected
groups members
This commit is contained in:
parent
f58947d9b6
commit
46a0a48fc9
@ -116,8 +116,9 @@ 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!" );
|
||||
|
||||
if ( item )
|
||||
layout()->removeLayoutItemPrivate( item );
|
||||
}
|
||||
|
||||
|
@ -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 ) )
|
||||
{
|
||||
@ -736,6 +717,8 @@ 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;
|
||||
@ -743,11 +726,11 @@ QPointF QgsLayoutMouseHandles::snapPoint( QPointF originalPoint, QgsLayoutMouseH
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
@ -29,6 +29,7 @@
|
||||
class QgsLayout;
|
||||
class QGraphicsView;
|
||||
class QgsLayoutView;
|
||||
class QgsLayoutItem;
|
||||
class QInputEvent;
|
||||
|
||||
///@cond PRIVATE
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user