QGIS API Documentation  3.17.0-Master (a84647cf30)
qgslayoutitempage.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitempage.h
3  --------------------
4  begin : July 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 QGSLAYOUTITEMPAGE_H
18 #define QGSLAYOUTITEMPAGE_H
19 
20 #include "qgis_core.h"
21 #include "qgslayoutitem.h"
22 #include "qgslayoutitemregistry.h"
23 #include "qgis_sip.h"
24 
25 
27 #ifndef SIP_RUN
28 
35 class CORE_EXPORT QgsLayoutItemPageGrid: public QGraphicsRectItem
36 {
37  public:
38  QgsLayoutItemPageGrid( double x, double y, double width, double height, QgsLayout *layout );
39 
40  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
41 
42  private:
43  QgsLayout *mLayout = nullptr;
44 };
45 #endif
46 
54 class CORE_EXPORT QgsLayoutItemPage : public QgsLayoutItem
55 {
56 
57  Q_OBJECT
58 
59  public:
60 
63  {
65  Landscape
66  };
67 
70  {
71  UndoPageSymbol = 3000,
72  };
73 
77  explicit QgsLayoutItemPage( QgsLayout *layout );
78  ~QgsLayoutItemPage() override;
79 
85  static QgsLayoutItemPage *create( QgsLayout *layout ) SIP_FACTORY;
86 
87  int type() const override;
88  QString displayName() const override;
89 
94  void setPageSize( const QgsLayoutSize &size );
95 
105  bool setPageSize( const QString &size, Orientation orientation = Portrait );
106 
111  QgsLayoutSize pageSize() const;
112 
117  Orientation orientation() const;
118 
128  void setPageStyleSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
129 
137  const QgsFillSymbol *pageStyleSymbol() const { return mPageStyleSymbol.get(); }
138 
144  static QgsLayoutItemPage::Orientation decodePageOrientation( const QString &string, bool *ok SIP_OUT = nullptr );
145 
146  QRectF boundingRect() const override;
147  void attemptResize( const QgsLayoutSize &size, bool includesFrame = false ) override;
148  QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
149  ExportLayerBehavior exportLayerBehavior() const override;
150  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
151 
152  public slots:
153 
154  void redraw() override;
155 
156  protected:
157 
158  void draw( QgsLayoutItemRenderContext &context ) override;
159  void drawFrame( QgsRenderContext &context ) override;
160  void drawBackground( QgsRenderContext &context ) override;
161  bool writePropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
162  bool readPropertiesFromElement( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
163 
164  private:
165 
166  double mMaximumShadowWidth = -1;
167 
168  std::unique_ptr< QgsLayoutItemPageGrid > mGrid;
169  mutable QRectF mBoundingRect;
170 
172  std::unique_ptr< QgsFillSymbol > mPageStyleSymbol;
173 
174  void createDefaultPageStyleSymbol();
175 
176  friend class TestQgsLayoutPage;
177 };
178 
179 #endif //QGSLAYOUTITEMPAGE_H
The class is used as a container of context for various read/write operations on other objects...
Portrait orientation.
Base class for graphical items within a QgsLayout.
int type() const override
Returns a unique graphics item type identifier.
Base class for commands to undo/redo layout and layout object changes.
UndoCommand
Layout item undo commands, used for collapsing undo commands.
An interface for classes which can visit style entity (e.g.
virtual void drawFrame(QgsRenderContext &context)
Draws the frame around the item.
const QgsFillSymbol * pageStyleSymbol() const
Returns the symbol to use for drawing the page background.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
virtual void drawBackground(QgsRenderContext &context)
Draws the background for the item.
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:76
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
virtual void redraw()
Triggers a redraw (update) of the item.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:44
virtual QString displayName() const
Gets item display name.
Contains information about the context of a rendering operation.
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
#define SIP_OUT
Definition: qgis_sip.h:58
Orientation
Page orientation.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item&#39;s contents using the specified item render context.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1295
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40
virtual ExportLayerBehavior exportLayerBehavior() const
Returns the behavior of this item during exporting to layered exports (e.g.
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.
Item representing the paper in a layout.