58 QList<QgsLayoutItem3DMap *> mapsList;
59 mLayout->layoutItems( mapsList );
68 if ( map->mMapId == mMapId )
71 maxId = std::max( maxId, map->mMapId );
76 mLayout->itemsModel()->updateItemDisplayName(
this );
88 return tr(
"3D Map %1" ).arg( mMapId );
91 void QgsLayoutItem3DMap::updateToolTip()
99 QPainter *painter = ctx.
painter();
101 int w =
static_cast<int>( std::ceil( rect().width() * ctx.
scaleFactor() ) );
102 int h =
static_cast<int>( std::ceil( rect().height() * ctx.
scaleFactor() ) );
103 QRect r( 0, 0, w, h );
109 painter->drawText( r, Qt::AlignCenter, tr(
"Scene not set" ) );
117 mCapturedImage = QImage();
120 if ( !mCapturedImage.isNull() )
122 painter->drawImage( r, mCapturedImage );
129 if (
mLayout->renderContext().isPreviewRender() )
131 painter->drawText( r, Qt::AlignCenter, tr(
"Loading" ) );
136 QSize sizePixelsInt = QSize( static_cast<int>( std::ceil( sizePixels.width() ) ),
137 static_cast<int>( std::ceil( sizePixels.height() ) ) );
144 mEngine->setSize( sizePixelsInt );
149 mEngine->setRootEntity( mScene );
152 if ( mEngine->size() != sizePixelsInt )
153 mEngine->setSize( sizePixelsInt );
157 if (
mLayout->renderContext().isPreviewRender() )
159 onSceneStateChanged();
170 painter->drawImage( r, img );
176 void QgsLayoutItem3DMap::onImageCaptured(
const QImage &img )
178 mCapturedImage = img;
182 void QgsLayoutItem3DMap::onSceneStateChanged()
186 mEngine->requestCaptureImage();
190 void QgsLayoutItem3DMap::onSizePositionChanged()
192 mCapturedImage = QImage();
201 QDomElement elemSettings = mSettings->writeXml( document, context );
202 element.appendChild( elemSettings );
205 QDomElement elemCameraPose = mCameraPose.
writeXml( document );
206 element.appendChild( elemCameraPose );
213 Q_UNUSED( document );
214 QDomElement elemSettings = element.firstChildElement( QStringLiteral(
"qgis3d" ) );
215 if ( !elemSettings.isNull() )
218 mSettings->readXml( elemSettings, context );
220 mSettings->resolveReferences( *
mLayout->project() );
223 QDomElement elemCameraPose = element.firstChildElement( QStringLiteral(
"camera-pose" ) );
224 if ( !elemCameraPose.isNull() )
225 mCameraPose.
readXml( elemCameraPose );
237 mSettings.reset( settings );
242 mCapturedImage = QImage();
250 mCapturedImage = QImage();
255 if ( mCameraPose == pose )
259 mCapturedImage = QImage();
The class is used as a container of context for various read/write operations on other objects...
Base class for graphical items within a QgsLayout.
void setCameraPose(const QgsCameraPose &pose)
Configures camera view.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written using writeXml()
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
3 Definition of the world
virtual int type() const override
3 Class that encapsulates camera pose in a 3D scene.
void setMapSettings(Qgs3DMapSettings *settings)
Configures map scene.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
void sizePositionChanged()
Emitted when the item's size or position changes.
void assignFreeId()
Sets the map id() to a number not yet used in the layout.
SceneState sceneState() const
Returns the current state of the scene.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
3 Off-screen 3D engine implementation.
QPointer< QgsLayout > mLayout
The scene is fully loaded/updated.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Contains settings and helpers relating to a render of a QgsLayoutItem.
static QImage captureSceneImage(QgsAbstract3DEngine &engine, Qgs3DMapScene *scene)
Captures image of the current 3D scene of a 3D engine.
QIcon icon() const override
Returns the item's icon.
Contains information about the context of a rendering operation.
QgsLayoutItem3DMap(QgsLayout *layout)
Constructor for QgsLayoutItem3DMap, with the specified parent layout.
QPainter * painter()
Returns the destination QPainter for the render operation.
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children...
void imageCaptured(const QImage &image)
Emitted after a call to requestCaptureImage() to return the captured image.
QColor backgroundColor() const
Returns the background color for this item.
3Implements support of 3D map views in print layouts
void sceneStateChanged()
Emitted when the scene's state has changed.
QString displayName() const override
overridden to show "3D Map 1" type names
QString id() const
Returns the item's ID name.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element and returns it.
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
void setCameraPose(const QgsCameraPose &camPose)
Sets camera pose.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
QgsCameraController * cameraController()
Returns camera controller.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
static QgsLayoutItem3DMap * create(QgsLayout *layout)
Returns a new 3D map item for the specified layout.