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() );
A container for grouping several QgsLayoutItems.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
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.
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)