QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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
QgsLayoutItem::UndoCommand
UndoCommand
Layout item undo commands, used for collapsing undo commands.
Definition: qgslayoutitem.h:216
QgsLayoutItemPage
Item representing the paper in a layout.
Definition: qgslayoutitempage.h:55
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsLayoutItemPage::~QgsLayoutItemPage
~QgsLayoutItemPage() override
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:45
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLayoutItem::type
int type() const override
Returns a unique graphics item type identifier.
Definition: qgslayoutitem.cpp:124
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
qgslayoutitem.h
QgsLayoutItemPage::pageStyleSymbol
const QgsFillSymbol * pageStyleSymbol() const
Returns the symbol to use for drawing the page background.
Definition: qgslayoutitempage.h:137
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
QgsAbstractLayoutUndoCommand
Base class for commands to undo/redo layout and layout object changes.
Definition: qgslayoutundocommand.h:35
QgsLayoutItemPage::Orientation
Orientation
Page orientation.
Definition: qgslayoutitempage.h:63
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsLayoutItem::displayName
virtual QString displayName() const
Gets item display name.
Definition: qgslayoutitem.cpp:107
QgsLayoutItemPage::Portrait
@ Portrait
Portrait orientation.
Definition: qgslayoutitempage.h:64
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1234
QgsLayoutItem::attemptResize
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Definition: qgslayoutitem.cpp:428
QgsLayoutSize
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:41
QgsLayoutItem::createCommand
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.
Definition: qgslayoutitem.cpp:828
qgslayoutitemregistry.h