18#include "moc_qgslayoutitemgroup.cpp" 
   44      mLayout->removeLayoutItem( item );
 
 
   63  if ( !
id().isEmpty() )
 
   67  return tr( 
"<Group>" );
 
 
   82  if ( mItems.contains( item ) )
 
   87  mItems << QPointer< QgsLayoutItem >( item );
 
 
  100    item->setParentGroup( 
nullptr );
 
 
  107  QList<QgsLayoutItem *> val;
 
 
  119  if ( !shouldBlockUndoCommands() )
 
  120    mLayout->undoStack()->beginMacro( tr( 
"Set Group Visibility" ) );
 
  126    bool prev = item->mBlockUndoCommands;
 
  127    item->mBlockUndoCommands = mBlockUndoCommands;
 
  128    item->setVisibility( visible );
 
  129    item->mBlockUndoCommands = prev;
 
  134  if ( !shouldBlockUndoCommands() )
 
  135    mLayout->undoStack()->endMacro();
 
 
  140  Q_UNUSED( useReferencePoint ) 
 
  144  if ( !shouldBlockUndoCommands() )
 
  145    mLayout->undoStack()->beginMacro( tr( 
"Move group" ) );
 
  149    scenePoint = 
mLayout->convertToLayoutUnits( point );
 
  151    scenePoint = 
mLayout->pageCollection()->pagePositionToLayoutPosition( 
page, point );
 
  153  double deltaX = scenePoint.x() - pos().x();
 
  154  double deltaY = scenePoint.y() - pos().y();
 
  162    std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
 
  163    if ( !shouldBlockUndoCommands() )
 
  166      command->saveBeforeState();
 
  169    item->attemptMoveBy( deltaX, deltaY );
 
  173      command->saveAfterState();
 
  174      mLayout->undoStack()->push( command.release() );
 
  179  if ( !shouldBlockUndoCommands() )
 
  180    mLayout->undoStack()->endMacro();
 
  181  updateBoundingRect();
 
 
  189  if ( !shouldBlockUndoCommands() )
 
  190    mLayout->undoStack()->beginMacro( tr( 
"Resize Group" ) );
 
  192  QRectF oldRect = rect();
 
  193  QSizeF newSizeLayoutUnits = 
mLayout->convertToLayoutUnits( size );
 
  195  newRect.setSize( newSizeLayoutUnits );
 
  203    std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
 
  204    if ( !shouldBlockUndoCommands() )
 
  207      command->saveBeforeState();
 
  210    const QRectF originalItemRect = item->rect();
 
  211    QRectF itemRect = mapRectFromItem( item, originalItemRect );
 
  214    itemRect = itemRect.normalized();
 
  215    QPointF newPos = mapToScene( itemRect.topLeft() );
 
  217    QgsLayoutSize itemSize = 
mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() );
 
  218    item->attemptResize( itemSize, includesFrame );
 
  221    QgsLayoutPoint itemPos = 
mLayout->convertFromLayoutUnits( newPos, item->positionWithUnits().units() );
 
  222    item->attemptMove( itemPos, 
false );
 
  226      command->saveAfterState();
 
  227      mLayout->undoStack()->push( command.release() );
 
  231  if ( !shouldBlockUndoCommands() )
 
  232    mLayout->undoStack()->endMacro();
 
  234  updateBoundingRect();
 
 
  244    QDomElement childItem = document.createElement( QStringLiteral( 
"ComposerItemGroupElement" ) );
 
  245    childItem.setAttribute( QStringLiteral( 
"uuid" ), item->uuid() );
 
  246    element.appendChild( childItem );
 
 
  255  QDomNodeList elementNodes = itemElement.elementsByTagName( QStringLiteral( 
"ComposerItemGroupElement" ) );
 
  256  for ( 
int i = 0; i < elementNodes.count(); ++i )
 
  258    QDomNode elementNode = elementNodes.at( i );
 
  259    if ( !elementNode.isElement() )
 
  262    QString 
uuid = elementNode.toElement().attribute( QStringLiteral( 
"uuid" ) );
 
 
  270  for ( 
const QString &
uuid : std::as_const( mItemUuids ) )
 
  279  updateBoundingRect();
 
 
  297void QgsLayoutItemGroup::updateBoundingRect()
 
  300  if ( mItems.isEmpty() )
 
  307  auto itemIter = mItems.constBegin();
 
  310  double rotation = ( *itemIter )->rotation();
 
  313  for ( ++itemIter; itemIter != mItems.constEnd(); ++itemIter )
 
  322  setScenePos( QPointF( 0, 0 ) );
 
  325  itemIter = mItems.constBegin();
 
  328  QRectF groupRect = mapFromItem( ( *itemIter ), ( *itemIter )->rect() ).boundingRect();
 
  329  QRectF groupRectWithFrame = mapFromItem( ( *itemIter ), ( *itemIter )->rectWithFrame() ).boundingRect();
 
  332  for ( ++itemIter; itemIter != mItems.constEnd(); ++itemIter )
 
  334    groupRect |= mapFromItem( ( *itemIter ), ( *itemIter )->rect() ).boundingRect();
 
  335    groupRectWithFrame |= mapFromItem( ( *itemIter ), ( *itemIter )->rectWithFrame() ).boundingRect();
 
  340  setRect( 0, 0, groupRect.width(), groupRect.height() );
 
  341  setPos( mapToScene( groupRect.topLeft() ) );
 
  343  QPointF bleedShift = groupRectWithFrame.topLeft() - groupRect.topLeft();
 
  344  mRectWithFrame = QRectF( bleedShift, groupRectWithFrame.size() );
 
  349  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
 
Provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
 
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
 
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.
 
A container for the context for various read/write operations on objects.
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)