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 QRectF itemRect = mapRectFromItem( item, item->rect() );
212 itemRect = itemRect.normalized();
213 QPointF newPos = mapToScene( itemRect.topLeft() );
215 QgsLayoutSize itemSize =
mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() );
216 item->attemptResize( itemSize, includesFrame );
219 QgsLayoutPoint itemPos =
mLayout->convertFromLayoutUnits( newPos, item->positionWithUnits().units() );
220 item->attemptMove( itemPos,
false );
224 command->saveAfterState();
225 mLayout->undoStack()->push( command.release() );
229 if ( !shouldBlockUndoCommands() )
230 mLayout->undoStack()->endMacro();
232 updateBoundingRect();
242 QDomElement childItem = document.createElement( QStringLiteral(
"ComposerItemGroupElement" ) );
243 childItem.setAttribute( QStringLiteral(
"uuid" ), item->uuid() );
244 element.appendChild( childItem );
253 QDomNodeList elementNodes = itemElement.elementsByTagName( QStringLiteral(
"ComposerItemGroupElement" ) );
254 for (
int i = 0; i < elementNodes.count(); ++i )
256 QDomNode elementNode = elementNodes.at( i );
257 if ( !elementNode.isElement() )
260 QString
uuid = elementNode.toElement().attribute( QStringLiteral(
"uuid" ) );
268 for (
const QString &
uuid : std::as_const( mItemUuids ) )
277 updateBoundingRect();
295void QgsLayoutItemGroup::updateBoundingRect()
298 if ( mItems.isEmpty() )
305 auto itemIter = mItems.constBegin();
308 double rotation = ( *itemIter )->rotation();
311 for ( ++itemIter; itemIter != mItems.constEnd(); ++itemIter )
320 setScenePos( QPointF( 0, 0 ) );
323 itemIter = mItems.constBegin();
326 QRectF groupRect = mapFromItem( ( *itemIter ), ( *itemIter )->rect() ).boundingRect();
327 QRectF groupRectWithFrame = mapFromItem( ( *itemIter ), ( *itemIter )->rectWithFrame() ).boundingRect();
330 for ( ++itemIter; itemIter != mItems.constEnd(); ++itemIter )
332 groupRect |= mapFromItem( ( *itemIter ), ( *itemIter )->rect() ).boundingRect();
333 groupRectWithFrame |= mapFromItem( ( *itemIter ), ( *itemIter )->rectWithFrame() ).boundingRect();
338 setRect( 0, 0, groupRect.width(), groupRect.height() );
339 setPos( mapToScene( groupRect.topLeft() ) );
341 QPointF bleedShift = groupRectWithFrame.topLeft() - groupRect.topLeft();
342 mRectWithFrame = QRectF( bleedShift, groupRectWithFrame.size() );
347 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)