QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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:215
QgsLayoutItemPage
Item representing the paper in a layout.
Definition: qgslayoutitempage.h:54
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsLayoutItemRenderContext
Definition: qgslayoutitem.h:44
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsStyleEntityVisitorInterface
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: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:112
QgsAbstractLayoutUndoCommand
Definition: qgslayoutundocommand.h:34
QgsLayoutItemPage::Orientation
Orientation
Page orientation.
Definition: qgslayoutitempage.h:62
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsLayoutItem::displayName
virtual QString displayName() const
Gets item display name.
Definition: qgslayoutitem.cpp:107
QgsLayoutItemPage::Portrait
@ Portrait
Portrait orientation.
Definition: qgslayoutitempage.h:64
QgsFillSymbol
Definition: qgssymbol.h:1212
QgsLayoutItem::attemptResize
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Definition: qgslayoutitem.cpp:432
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