QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslayoutitemmarker.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemmarker.h
3  ---------------------
4  begin : April 2020
5  copyright : (C) 2020 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 QGSLAYOUTITEMMARKER_H
18 #define QGSLAYOUTITEMMARKER_H
19 
20 #include "qgis_core.h"
21 #include "qgslayoutitem.h"
22 #include "qgslayoutitemregistry.h"
24 
25 class QgsMarkerSymbol;
26 
33 class CORE_EXPORT QgsLayoutItemMarker : public QgsLayoutItem
34 {
35  Q_OBJECT
36 
37  public:
38 
42  explicit QgsLayoutItemMarker( QgsLayout *layout );
44 
50  static QgsLayoutItemMarker *create( QgsLayout *layout ) SIP_FACTORY;
51 
52 
53  int type() const override;
54  QIcon icon() const override;
55 
60  void setSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
61 
66  QgsMarkerSymbol *symbol();
67 
77  void setLinkedMap( QgsLayoutItemMap *map );
78 
85  QgsLayoutItemMap *linkedMap() const;
86 
93  double northArrowRotation() const { return mNorthArrowRotation; }
94 
100  QgsLayoutNorthArrowHandler::NorthMode northMode() const;
101 
107  void setNorthMode( QgsLayoutNorthArrowHandler::NorthMode mode );
108 
114  double northOffset() const;
115 
121  void setNorthOffset( double offset );
122 
123  // Depending on the symbol style, the bounding rectangle can be larger than the shape
124  QRectF boundingRect() const override;
125 
126  QgsLayoutSize fixedSize() const override;
127 
128  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
129 
130  protected:
131 
132  void draw( QgsLayoutItemRenderContext &context ) override;
133 
134  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
135  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
136 
137  void finalizeRestoreFromXml() override;
138  private slots:
139 
144  void refreshSymbol();
145 
147  void updateBoundingRect();
148 
149  void northArrowRotationChanged( double rotation );
150 
151  private:
152 
153  std::unique_ptr< QgsMarkerSymbol > mShapeStyleSymbol;
154 
155  QPointF mPoint;
156  QRectF mCurrentRectangle;
157  QgsLayoutSize mFixedSize;
158 
159  QString mRotationMapUuid;
160  QgsLayoutNorthArrowHandler *mNorthArrowHandler = nullptr;
161  double mNorthArrowRotation = 0;
162 
163  QgsLayoutItemMarker( const QgsLayoutItemMarker & ) = delete;
164  QgsLayoutItemMarker &operator=( const QgsLayoutItemMarker & ) = delete;
165 };
166 
167 
168 #endif //QGSLAYOUTITEMMARKER_H
QgsLayoutItemMarker
A layout item for showing marker symbols.
Definition: qgslayoutitemmarker.h:34
QgsLayoutItem::writePropertiesToElement
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
Definition: qgslayoutitem.cpp:1325
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsLayoutItemMarker::northArrowRotation
double northArrowRotation() const
When the marker is linked to a map in north arrow rotation mode, returns the current north arrow rota...
Definition: qgslayoutitemmarker.h:93
QgsLayoutItem::icon
virtual QIcon icon() const
Returns the item's icon.
Definition: qgslayoutitem.h:334
qgslayoutnortharrowhandler.h
QgsLayoutItem::finalizeRestoreFromXml
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
Definition: qgslayoutitem.cpp:824
QgsLayoutItemMarker::~QgsLayoutItemMarker
~QgsLayoutItemMarker() override
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:45
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsLayoutItem::readPropertiesFromElement
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
Definition: qgslayoutitem.cpp:1330
QgsLayoutItem::draw
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
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
qgslayoutitem.h
QgsLayoutItem::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Definition: qgslayoutitem.cpp:1165
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:931
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
QgsLayoutNorthArrowHandler
An object which handles north-arrow type behavior for layout items.
Definition: qgslayoutnortharrowhandler.h:33
QgsLayoutNorthArrowHandler::NorthMode
NorthMode
Method for syncing rotation to a map's North direction.
Definition: qgslayoutnortharrowhandler.h:39
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:318
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsLayoutSize
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:41
qgslayoutitemregistry.h
QgsLayoutItem::fixedSize
virtual QgsLayoutSize fixedSize() const
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized.
Definition: qgslayoutitem.h:552