QGIS API Documentation  3.6.0-Noosa (5873452)
qgslayoutitemgroup.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemgroup.h
3  ---------------------
4  begin : October 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSLAYOUTITEMGROUP_H
18 #define QGSLAYOUTITEMGROUP_H
19 
20 #include "qgis_core.h"
21 #include "qgslayoutitem.h"
22 
28 class CORE_EXPORT QgsLayoutItemGroup: public QgsLayoutItem
29 {
30  Q_OBJECT
31 
32  public:
33 
37  explicit QgsLayoutItemGroup( QgsLayout *layout );
38 
39  void cleanup() override;
40 
41  int type() const override;
42  QString displayName() const override;
43 
49  static QgsLayoutItemGroup *create( QgsLayout *layout ) SIP_FACTORY;
50 
55  void addItem( QgsLayoutItem *item SIP_TRANSFER );
56 
61  void removeItems();
62 
66  QList<QgsLayoutItem *> items() const;
67 
68  //overridden to also hide grouped items
69  void setVisibility( bool visible ) override;
70 
71  //overridden to move child items
72  void attemptMove( const QgsLayoutPoint &point, bool useReferencePoint = true, bool includesFrame = false, int page = -1 ) override;
73  void attemptResize( const QgsLayoutSize &size, bool includesFrame = false ) override;
74 
75  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
76 
77  void finalizeRestoreFromXml() override;
78 
79  protected:
80  void draw( QgsLayoutItemRenderContext &context ) override;
81  bool writePropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
82  bool readPropertiesFromElement( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
83 
84  private:
85 
86  void resetBoundingRect();
87  void updateBoundingRect( QgsLayoutItem *item );
88  void setSceneRect( const QRectF &rectangle );
89 
90  QList< QString > mItemUuids;
91  QList< QPointer< QgsLayoutItem >> mItems;
92  QRectF mBoundingRectangle;
93 };
94 
95 #endif //QGSLAYOUTITEMGROUP_H
96 
97 
98 
The class is used as a container of context for various read/write operations on other objects...
Base class for graphical items within a QgsLayout.
int type() const override
Returns a unique graphics item type identifier.
A container for grouping several QgsLayoutItems.
This class provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Handles preparing a paint surface for the layout item and painting the item&#39;s content.
virtual void cleanup()
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:69
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
virtual void setVisibility(bool visible)
Sets whether the item is visible.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:44
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
virtual QString displayName() const
Gets item display name.
virtual void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1)
Attempts to move the item to a specified point.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
friend class QgsLayoutItemGroup
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item&#39;s contents using the specified item render context.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40