QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
37 class CORE_EXPORT QgsLayoutItemPageGrid: public QGraphicsRectItem
38 {
39  public:
40  QgsLayoutItemPageGrid( double x, double y, double width, double height, QgsLayout *layout );
41 
42  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
43 
44  private:
45  QgsLayout *mLayout = nullptr;
46 };
47 #endif
49 
56 class CORE_EXPORT QgsLayoutItemPage : public QgsLayoutItem
57 {
58 
59  Q_OBJECT
60 
61  public:
62 
65  {
67  Landscape
68  };
69 
72  {
73  UndoPageSymbol = 3000,
74  };
75 
79  explicit QgsLayoutItemPage( QgsLayout *layout );
80  ~QgsLayoutItemPage() override;
81 
87  static QgsLayoutItemPage *create( QgsLayout *layout ) SIP_FACTORY;
88 
89  int type() const override;
90  QString displayName() const override;
91 
96  void setPageSize( const QgsLayoutSize &size );
97 
107  bool setPageSize( const QString &size, Orientation orientation = Portrait );
108 
113  QgsLayoutSize pageSize() const;
114 
119  Orientation orientation() const;
120 
130  void setPageStyleSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
131 
139  const QgsFillSymbol *pageStyleSymbol() const { return mPageStyleSymbol.get(); }
140 
146  static QgsLayoutItemPage::Orientation decodePageOrientation( const QString &string, bool *ok SIP_OUT = nullptr );
147 
148  QRectF boundingRect() const override;
149  void attemptResize( const QgsLayoutSize &size, bool includesFrame = false ) override;
150  QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
151  ExportLayerBehavior exportLayerBehavior() const override;
152  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
153 
154  public slots:
155 
156  void redraw() override;
157 
158  protected:
159 
160  void draw( QgsLayoutItemRenderContext &context ) override;
161  void drawFrame( QgsRenderContext &context ) override;
162  void drawBackground( QgsRenderContext &context ) override;
163  bool writePropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
164  bool readPropertiesFromElement( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
165 
166  private:
167 
168  double mMaximumShadowWidth = -1;
169 
170  std::unique_ptr< QgsLayoutItemPageGrid > mGrid;
171  mutable QRectF mBoundingRect;
172 
174  std::unique_ptr< QgsFillSymbol > mPageStyleSymbol;
175 
176  void createDefaultPageStyleSymbol();
177 
178  friend class TestQgsLayoutPage;
179 };
180 
181 #endif //QGSLAYOUTITEMPAGE_H
Base class for commands to undo/redo layout and layout object changes.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1307
Item representing the paper in a layout.
~QgsLayoutItemPage() override
const QgsFillSymbol * pageStyleSymbol() const
Returns the symbol to use for drawing the page background.
Orientation
Page orientation.
@ Portrait
Portrait orientation.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:45
Base class for graphical items within a QgsLayout.
UndoCommand
Layout item undo commands, used for collapsing undo commands.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:41
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76