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 : qgis::as_const( mItemUuids ) )
284 void QgsLayoutItemGroup::resetBoundingRect()
286 mBoundingRectangle = QRectF();
289 updateBoundingRect( item );
293 void QgsLayoutItemGroup::updateBoundingRect(
QgsLayoutItem *item )
296 if ( mBoundingRectangle.isEmpty() )
298 mBoundingRectangle = QRectF( 0, 0, item->rect().width(), item->rect().height() );
299 setSceneRect( QRectF( item->pos().x(), item->pos().y(), item->rect().width(), item->rect().height() ) );
311 mBoundingRectangle = mapRectToScene( mBoundingRectangle );
313 mBoundingRectangle = mBoundingRectangle.united( item->mapRectToScene( item->rect() ) );
314 setSceneRect( mBoundingRectangle );
319 mBoundingRectangle = mBoundingRectangle.united( mapRectFromItem( item, item->rect() ) );
320 QPointF newPos = mapToScene( mBoundingRectangle.topLeft().x(), mBoundingRectangle.topLeft().y() );
321 mBoundingRectangle = QRectF( 0, 0, mBoundingRectangle.width(), mBoundingRectangle.height() );
322 setSceneRect( QRectF( newPos.x(), newPos.y(), mBoundingRectangle.width(), mBoundingRectangle.height() ) );
327 void QgsLayoutItemGroup::setSceneRect(
const QRectF &rectangle )
331 setScenePos( rectangle.topLeft() );
332 setRect( 0, 0, rectangle.width(), rectangle.height() );
The class is used as a container of context for various read/write operations on other objects...
void removeItems()
Removes all items from the group (but does not delete them).
QList< QgsLayoutItem * > items() const
Returns a list of items contained by the group.
QgsLayoutItemGroup(QgsLayout *layout)
Constructor for QgsLayoutItemGroup, belonging to the specified layout.
Base class for graphical items within a QgsLayout.
bool readPropertiesFromElement(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
void cleanup() override
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
static QgsLayoutItemGroup * create(QgsLayout *layout)
Returns a new group item for the specified layout.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
void setVisibility(bool visible) override
Sets whether the item is visible.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
A container for grouping several QgsLayoutItems.
void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1) override
Attempts to move the item to a specified point.
int type() const override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
void addItem(QgsLayoutItem *item)
Adds an item to the group.
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
This class provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
bool writePropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
QString displayName() const override
Gets item display name.
virtual void cleanup()
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
QPointer< QgsLayout > mLayout
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
virtual void setItemRotation(double rotation, bool adjustPosition=true)
Sets the layout item's rotation, in degrees clockwise.
virtual QString uuid() const
Returns the item identification string.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
virtual void setVisibility(bool visible)
Sets whether the item is visible.
void setParentGroup(QgsLayoutItemGroup *group)
Sets the item's parent group.
Contains settings and helpers relating to a render of a QgsLayoutItem.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
int page() const
Returns the page the item is currently on, with the first page returning 0.
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.
static void relativeResizeRect(QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter)
Resizes a QRectF relative to a resized bounding rectangle.
void attemptResize(const QgsLayoutSize &size, bool includesFrame=false) override
Attempts to resize the item to a specified target size.
const QgsLayout * layout() const
Returns the layout the object is attached to.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.