QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslayoutitem3dmap.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitem3dmap.h
3  --------------------------------------
4  Date : August 2018
5  Copyright : (C) 2018 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSLAYOUTITEM3DMAP_H
17 #define QGSLAYOUTITEM3DMAP_H
18 
19 #include "qgis_3d.h"
20 
21 #include "qgslayoutitem.h"
22 #include "qgstemporalrangeobject.h"
23 #include "qgscamerapose.h"
24 
25 #ifdef SIP_RUN
26 // this is needed for the "convert to subclass" code below to compile
27 % ModuleHeaderCode
28 #include "qgslayoutitem3dmap.h"
29 % End
30 #endif
31 
32 
33 class Qgs3DMapScene;
34 class Qgs3DMapSettings;
36 
44 class _3D_EXPORT QgsLayoutItem3DMap : public QgsLayoutItem, public QgsTemporalRangeObject
45 {
46  Q_OBJECT
47 
48 #ifdef SIP_RUN
50  // the conversions have to be static, because they're using multiple inheritance
51  // (seen in PyQt4 .sip files for some QGraphicsItem classes)
52  switch ( sipCpp->type() )
53  {
54  // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
55  case QGraphicsItem::UserType + 115:
56  sipType = sipType_QgsLayoutItem3DMap;
57  *sipCppRet = static_cast<QgsLayoutItem3DMap *>( sipCpp );
58  break;
59  default:
60  sipType = 0;
61  }
62  SIP_END
63 #endif
64 
65  public:
66 
73 
75 
81  static QgsLayoutItem3DMap *create( QgsLayout *layout ) SIP_FACTORY;
82 
83  virtual int type() const override;
84  QIcon icon() const override;
85 
87  void setCameraPose( const QgsCameraPose &pose );
89  QgsCameraPose cameraPose() const { return mCameraPose; }
90 
96  void setMapSettings( Qgs3DMapSettings *settings SIP_TRANSFER );
98  Qgs3DMapSettings *mapSettings() const { return mSettings.get(); }
99 
103  void assignFreeId();
104 
106  QString displayName() const override;
107 
108  void finalizeRestoreFromXml() override;
109 
110  public slots:
111  void refresh() override;
112 
113  protected:
114  void draw( QgsLayoutItemRenderContext &context ) override;
115  bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
116  bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
117 
118  private slots:
119  void onImageCaptured( const QImage &img );
120  void onSceneStateChanged();
121  void onSizePositionChanged();
122 
123  private:
125  void updateToolTip();
126 
127  private:
128  std::unique_ptr<Qgs3DMapSettings> mSettings;
129  std::unique_ptr<QgsOffscreen3DEngine> mEngine;
130  Qgs3DMapScene *mScene = nullptr;
131  QImage mCapturedImage;
132  QgsCameraPose mCameraPose;
133  bool mDrawing = false;
134 
136  int mMapId = 1;
137 };
138 
139 #endif // QGSLAYOUTITEM3DMAP_H
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
qgstemporalrangeobject.h
QgsLayoutItem::icon
virtual QIcon icon() const
Returns the item's icon.
Definition: qgslayoutitem.h:334
QgsLayoutItem::finalizeRestoreFromXml
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
Definition: qgslayoutitem.cpp:824
QgsLayoutItem3DMap::cameraPose
QgsCameraPose cameraPose() const
Returns camera view.
Definition: qgslayoutitem3dmap.h:89
QgsLayoutItemRenderContext
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:45
QgsLayoutItem3DMap
3
Definition: qgslayoutitem3dmap.h:45
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
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
qgslayoutitem.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Qgs3DMapSettings
3 Definition of the world
Definition: qgs3dmapsettings.h:54
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
QgsCameraPose
3 Class that encapsulates camera pose in a 3D scene.
Definition: qgscamerapose.h:45
QgsLayoutItem::refresh
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
Definition: qgslayoutitem.cpp:1176
Qgs3DMapScene
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
Definition: qgs3dmapscene.h:69
qgscamerapose.h
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
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
QgsOffscreen3DEngine
3 Off-screen 3D engine implementation.
Definition: qgsoffscreen3dengine.h:65
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsLayoutItem3DMap::~QgsLayoutItem3DMap
~QgsLayoutItem3DMap()
QgsTemporalRangeObject
Base class for objects with an associated (optional) temporal range.
Definition: qgstemporalrangeobject.h:34
qgslayoutitem3dmap.h
QgsLayoutItem3DMap::mapSettings
Qgs3DMapSettings * mapSettings() const
Returns map scene. May be nullptr if not yet configured.
Definition: qgslayoutitem3dmap.h:98