43 mLayout->removeLayoutItem( item );
62 if ( !
id().isEmpty() )
66 return tr(
"<Group>" );
81 if ( mItems.contains( item ) )
86 mItems << QPointer< QgsLayoutItem >( item );
99 item->setParentGroup(
nullptr );
106 QList<QgsLayoutItem *> val;
118 if ( !shouldBlockUndoCommands() )
119 mLayout->undoStack()->beginMacro( tr(
"Set Group Visibility" ) );
125 bool prev = item->mBlockUndoCommands;
126 item->mBlockUndoCommands = mBlockUndoCommands;
127 item->setVisibility( visible );
128 item->mBlockUndoCommands = prev;
133 if ( !shouldBlockUndoCommands() )
134 mLayout->undoStack()->endMacro();
139 Q_UNUSED( useReferencePoint )
143 if ( !shouldBlockUndoCommands() )
144 mLayout->undoStack()->beginMacro( tr(
"Move group" ) );
148 scenePoint =
mLayout->convertToLayoutUnits( point );
150 scenePoint =
mLayout->pageCollection()->pagePositionToLayoutPosition(
page, point );
152 double deltaX = scenePoint.x() - pos().x();
153 double deltaY = scenePoint.y() - pos().y();
161 std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
162 if ( !shouldBlockUndoCommands() )
165 command->saveBeforeState();
168 item->attemptMoveBy( deltaX, deltaY );
172 command->saveAfterState();
173 mLayout->undoStack()->push( command.release() );
178 if ( !shouldBlockUndoCommands() )
179 mLayout->undoStack()->endMacro();
180 updateBoundingRect();
188 if ( !shouldBlockUndoCommands() )
189 mLayout->undoStack()->beginMacro( tr(
"Resize Group" ) );
191 QRectF oldRect = rect();
192 QSizeF newSizeLayoutUnits =
mLayout->convertToLayoutUnits( size );
194 newRect.setSize( newSizeLayoutUnits );
202 std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
203 if ( !shouldBlockUndoCommands() )
206 command->saveBeforeState();
209 const QRectF originalItemRect = item->rect();
210 QRectF itemRect = mapRectFromItem( item, originalItemRect );
213 itemRect = itemRect.normalized();
214 QPointF newPos = mapToScene( itemRect.topLeft() );
216 QgsLayoutSize itemSize =
mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() );
217 item->attemptResize( itemSize, includesFrame );
220 QgsLayoutPoint itemPos =
mLayout->convertFromLayoutUnits( newPos, item->positionWithUnits().units() );
221 item->attemptMove( itemPos,
false );
225 command->saveAfterState();
226 mLayout->undoStack()->push( command.release() );
230 if ( !shouldBlockUndoCommands() )
231 mLayout->undoStack()->endMacro();
233 updateBoundingRect();
243 QDomElement childItem = document.createElement( QStringLiteral(
"ComposerItemGroupElement" ) );
244 childItem.setAttribute( QStringLiteral(
"uuid" ), item->uuid() );
245 element.appendChild( childItem );
254 QDomNodeList elementNodes = itemElement.elementsByTagName( QStringLiteral(
"ComposerItemGroupElement" ) );
255 for (
int i = 0; i < elementNodes.count(); ++i )
257 QDomNode elementNode = elementNodes.at( i );
258 if ( !elementNode.isElement() )
261 QString
uuid = elementNode.toElement().attribute( QStringLiteral(
"uuid" ) );
269 for (
const QString &
uuid : std::as_const( mItemUuids ) )
278 updateBoundingRect();
296void QgsLayoutItemGroup::updateBoundingRect()
299 if ( mItems.isEmpty() )
306 auto itemIter = mItems.constBegin();
309 double rotation = ( *itemIter )->rotation();
312 for ( ++itemIter; itemIter != mItems.constEnd(); ++itemIter )
321 setScenePos( QPointF( 0, 0 ) );
324 itemIter = mItems.constBegin();
327 QRectF groupRect = mapFromItem( ( *itemIter ), ( *itemIter )->rect() ).boundingRect();
328 QRectF groupRectWithFrame = mapFromItem( ( *itemIter ), ( *itemIter )->rectWithFrame() ).boundingRect();
331 for ( ++itemIter; itemIter != mItems.constEnd(); ++itemIter )
333 groupRect |= mapFromItem( ( *itemIter ), ( *itemIter )->rect() ).boundingRect();
334 groupRectWithFrame |= mapFromItem( ( *itemIter ), ( *itemIter )->rectWithFrame() ).boundingRect();
339 setRect( 0, 0, groupRect.width(), groupRect.height() );
340 setPos( mapToScene( groupRect.topLeft() ) );
342 QPointF bleedShift = groupRectWithFrame.topLeft() - groupRect.topLeft();
343 mRectWithFrame = QRectF( bleedShift, groupRectWithFrame.size() );
348 return mRectWithFrame;
A container for grouping several QgsLayoutItems.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
QRectF rectWithFrame() const override
Returns the item's rectangular bounds, including any bleed caused by the item's frame.
void removeItems()
Removes all items from the group (but does not delete them).
void addItem(QgsLayoutItem *item)
Adds an item to the group.
QList< QgsLayoutItem * > items() const
Returns a list of items contained by the group.
~QgsLayoutItemGroup() override
void setVisibility(bool visible) override
Sets whether the item is visible.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
bool writePropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
int type() const override
ExportLayerBehavior exportLayerBehavior() const override
Returns the behavior of this item during exporting to layered exports (e.g.
void cleanup() override
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
void attemptResize(const QgsLayoutSize &size, bool includesFrame=false) override
Attempts to resize the item to a specified target size.
static QgsLayoutItemGroup * create(QgsLayout *layout)
Returns a new group item for the specified layout.
void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1) override
Attempts to move the item to a specified point.
bool readPropertiesFromElement(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
QString displayName() const override
Gets item display name.
@ LayoutGroup
Grouped item.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Base class for graphical items within a QgsLayout.
friend class QgsLayoutItemGroup
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.
virtual void cleanup()
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
virtual void setItemRotation(double rotation, bool adjustPosition=true)
Sets the layout item's rotation, in degrees clockwise.
virtual void setVisibility(bool visible)
Sets whether the item is visible.
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
int page() const
Returns the page the item is currently on, with the first page returning 0.
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
virtual QString uuid() const
Returns the item identification string.
virtual void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1)
Attempts to move the item to a specified point.
QString id() const
Returns the item's ID name.
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
@ MustPlaceInOwnLayer
Item must be placed in its own individual layer.
void setParentGroup(QgsLayoutItemGroup *group)
Sets the item's parent group.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QPointer< QgsLayout > mLayout
This class provides a method of storing points, consisting of an x and y coordinate,...
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
static void relativeResizeRect(QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter)
Resizes a QRectF relative to a resized bounding rectangle.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
The class is used as a container of context for various read/write operations on other objects.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)