38 mLayout->removeLayoutItem( item );
57 if ( !
id().isEmpty() )
61 return tr(
"<Group>" );
76 if ( mItems.contains( item ) )
81 mItems << QPointer< QgsLayoutItem >( item );
84 updateBoundingRect( item );
94 item->setParentGroup(
nullptr );
101 QList<QgsLayoutItem *> val;
113 if ( !shouldBlockUndoCommands() )
114 mLayout->undoStack()->beginMacro( tr(
"Set Group Visibility" ) );
120 bool prev = item->mBlockUndoCommands;
121 item->mBlockUndoCommands = mBlockUndoCommands;
122 item->setVisibility( visible );
123 item->mBlockUndoCommands = prev;
128 if ( !shouldBlockUndoCommands() )
129 mLayout->undoStack()->endMacro();
134 Q_UNUSED( useReferencePoint )
138 if ( !shouldBlockUndoCommands() )
139 mLayout->undoStack()->beginMacro( tr(
"Move group" ) );
143 scenePoint =
mLayout->convertToLayoutUnits( point );
145 scenePoint =
mLayout->pageCollection()->pagePositionToLayoutPosition(
page, point );
147 double deltaX = scenePoint.x() - pos().x();
148 double deltaY = scenePoint.y() - pos().y();
156 std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
157 if ( !shouldBlockUndoCommands() )
160 command->saveBeforeState();
163 item->attemptMoveBy( deltaX, deltaY );
167 command->saveAfterState();
168 mLayout->undoStack()->push( command.release() );
173 if ( !shouldBlockUndoCommands() )
174 mLayout->undoStack()->endMacro();
183 if ( !shouldBlockUndoCommands() )
184 mLayout->undoStack()->beginMacro( tr(
"Resize Group" ) );
186 QRectF oldRect = rect();
187 QSizeF newSizeLayoutUnits =
mLayout->convertToLayoutUnits( size );
189 newRect.setSize( newSizeLayoutUnits );
197 std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
198 if ( !shouldBlockUndoCommands() )
201 command->saveBeforeState();
204 QRectF itemRect = mapRectFromItem( item, item->rect() );
207 itemRect = itemRect.normalized();
208 QPointF newPos = mapToScene( itemRect.topLeft() );
210 QgsLayoutSize itemSize =
mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() );
211 item->attemptResize( itemSize, includesFrame );
214 QgsLayoutPoint itemPos =
mLayout->convertFromLayoutUnits( newPos, item->positionWithUnits().units() );
215 item->attemptMove( itemPos,
false );
219 command->saveAfterState();
220 mLayout->undoStack()->push( command.release() );
224 if ( !shouldBlockUndoCommands() )
225 mLayout->undoStack()->endMacro();
237 QDomElement childItem = document.createElement( QStringLiteral(
"ComposerItemGroupElement" ) );
238 childItem.setAttribute( QStringLiteral(
"uuid" ), item->uuid() );
239 element.appendChild( childItem );
248 QDomNodeList elementNodes = itemElement.elementsByTagName( QStringLiteral(
"ComposerItemGroupElement" ) );
249 for (
int i = 0; i < elementNodes.count(); ++i )
251 QDomNode elementNode = elementNodes.at( i );
252 if ( !elementNode.isElement() )
255 QString
uuid = elementNode.toElement().attribute( QStringLiteral(
"uuid" ) );
263 for (
const QString &
uuid : std::as_const( mItemUuids ) )
289 void QgsLayoutItemGroup::resetBoundingRect()
291 mBoundingRectangle = QRectF();
294 updateBoundingRect( item );
298 void QgsLayoutItemGroup::updateBoundingRect(
QgsLayoutItem *item )
301 if ( mBoundingRectangle.isEmpty() )
303 mBoundingRectangle = QRectF( 0, 0, item->rect().width(), item->rect().height() );
304 setSceneRect( QRectF( item->pos().x(), item->pos().y(), item->rect().width(), item->rect().height() ) );
316 mBoundingRectangle = mapRectToScene( mBoundingRectangle );
318 mBoundingRectangle = mBoundingRectangle.united( item->mapRectToScene( item->rect() ) );
319 setSceneRect( mBoundingRectangle );
324 mBoundingRectangle = mBoundingRectangle.united( mapRectFromItem( item, item->rect() ) );
325 QPointF newPos = mapToScene( mBoundingRectangle.topLeft().x(), mBoundingRectangle.topLeft().y() );
326 mBoundingRectangle = QRectF( 0, 0, mBoundingRectangle.width(), mBoundingRectangle.height() );
327 setSceneRect( QRectF( newPos.x(), newPos.y(), mBoundingRectangle.width(), mBoundingRectangle.height() ) );
332 void QgsLayoutItemGroup::setSceneRect(
const QRectF &rectangle )
336 setScenePos( rectangle.topLeft() );
337 setRect( 0, 0, rectangle.width(), rectangle.height() );