QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 <QPageLayout>
21 
22 #include "qgis_core.h"
23 #include "qgslayoutitem.h"
24 #include "qgslayoutitemregistry.h"
25 #include "qgis_sip.h"
26 
27 
29 #ifndef SIP_RUN
30 
39 class CORE_EXPORT QgsLayoutItemPageGrid: public QGraphicsRectItem
40 {
41  public:
42  QgsLayoutItemPageGrid( double x, double y, double width, double height, QgsLayout *layout );
43 
44  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
45 
46  private:
47  QgsLayout *mLayout = nullptr;
48 };
49 #endif
50 
58 class CORE_EXPORT QgsLayoutItemPage : public QgsLayoutItem
59 {
60 
61  Q_OBJECT
62 
63  public:
64 
67  {
69  Landscape
70  };
71 
74  {
75  UndoPageSymbol = 3000,
76  };
77 
81  explicit QgsLayoutItemPage( QgsLayout *layout );
82  ~QgsLayoutItemPage() override;
83 
89  static QgsLayoutItemPage *create( QgsLayout *layout ) SIP_FACTORY;
90 
91  int type() const override;
92  QString displayName() const override;
93 
98  void setPageSize( const QgsLayoutSize &size );
99 
109  bool setPageSize( const QString &size, Orientation orientation = Portrait );
110 
115  QPageLayout pageLayout() const;
116 
121  QgsLayoutSize pageSize() const;
122 
127  Orientation orientation() const;
128 
138  void setPageStyleSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
139 
147  const QgsFillSymbol *pageStyleSymbol() const { return mPageStyleSymbol.get(); }
148 
154  static QgsLayoutItemPage::Orientation decodePageOrientation( const QString &string, bool *ok SIP_OUT = nullptr );
155 
156  QRectF boundingRect() const override;
157  void attemptResize( const QgsLayoutSize &size, bool includesFrame = false ) override;
158  QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id, QUndoCommand *parent = nullptr ) override SIP_FACTORY;
159  ExportLayerBehavior exportLayerBehavior() const override;
160  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
161 
162  public slots:
163 
164  void redraw() override;
165 
166  protected:
167 
168  void draw( QgsLayoutItemRenderContext &context ) override;
169  void drawFrame( QgsRenderContext &context ) override;
170  void drawBackground( QgsRenderContext &context ) override;
171  bool writePropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
172  bool readPropertiesFromElement( const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context ) override;
173 
174  private:
175 
176  double mMaximumShadowWidth = -1;
177 
178  std::unique_ptr< QgsLayoutItemPageGrid > mGrid;
179  mutable QRectF mBoundingRect;
180 
182  std::unique_ptr< QgsFillSymbol > mPageStyleSymbol;
183 
184  void createDefaultPageStyleSymbol();
185 
186  friend class TestQgsLayoutPage;
187 };
188 
189 #endif //QGSLAYOUTITEMPAGE_H
QgsLayoutItem::UndoCommand
UndoCommand
Layout item undo commands, used for collapsing undo commands.
Definition: qgslayoutitem.h:215
QgsLayoutItemPage
Item representing the paper in a layout.
Definition: qgslayoutitempage.h:58
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
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:44
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
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:147
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:112
QgsAbstractLayoutUndoCommand
Base class for commands to undo/redo layout and layout object changes.
Definition: qgslayoutundocommand.h:34
QgsLayoutItemPage::Orientation
Orientation
Page orientation.
Definition: qgslayoutitempage.h:66
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:68
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsLayoutItem::attemptResize
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Definition: qgslayoutitem.cpp:429
QgsLayoutSize
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40
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:829
qgslayoutitemregistry.h