60 QList<QgsLayoutItem3DMap *> mapsList;
61 mLayout->layoutItems( mapsList );
70 if ( map->mMapId == mMapId )
73 maxId = std::max( maxId, map->mMapId );
78 mLayout->itemsModel()->updateItemDisplayName(
this );
90 return tr(
"3D Map %1" ).arg( mMapId );
93 void QgsLayoutItem3DMap::updateToolTip()
101 QPainter *painter = ctx.
painter();
103 int w =
static_cast<int>( std::ceil( rect().width() * ctx.
scaleFactor() ) );
104 int h =
static_cast<int>( std::ceil( rect().height() * ctx.
scaleFactor() ) );
105 QRect r( 0, 0, w, h );
111 painter->drawText( r, Qt::AlignCenter, tr(
"Scene not set" ) );
119 mCapturedImage = QImage();
122 if ( !mCapturedImage.isNull() )
124 painter->drawImage( r, mCapturedImage );
131 if (
mLayout->renderContext().isPreviewRender() )
133 painter->drawText( r, Qt::AlignCenter, tr(
"Loading" ) );
151 QSize sizePixelsInt = QSize(
static_cast<int>( std::ceil( sizePixels.width() ) ),
152 static_cast<int>( std::ceil( sizePixels.height() ) ) );
162 mEngine->setSize( sizePixelsInt );
166 mEngine->setRootEntity( mScene );
170 if ( mEngine->size() != sizePixelsInt )
171 mEngine->setSize( sizePixelsInt );
175 if (
mLayout->renderContext().isPreviewRender() )
177 onSceneStateChanged();
188 painter->drawImage( r, img );
194 void QgsLayoutItem3DMap::onImageCaptured(
const QImage &img )
196 mCapturedImage = img;
200 void QgsLayoutItem3DMap::onSceneStateChanged()
204 mEngine->requestCaptureImage();
208 void QgsLayoutItem3DMap::onSizePositionChanged()
210 mCapturedImage = QImage();
219 QDomElement elemSettings = mSettings->writeXml( document, context );
220 element.appendChild( elemSettings );
223 QDomElement elemCameraPose = mCameraPose.
writeXml( document );
224 element.appendChild( elemCameraPose );
227 QDomElement elemTemporal = document.createElement( QStringLiteral(
"temporal-settings" ) );
228 elemTemporal.setAttribute( QStringLiteral(
"isTemporal" ),
isTemporal() ? 1 : 0 );
231 elemTemporal.setAttribute( QStringLiteral(
"temporalRangeBegin" ),
temporalRange().begin().toString( Qt::ISODate ) );
232 elemTemporal.setAttribute( QStringLiteral(
"temporalRangeEnd" ),
temporalRange().end().toString( Qt::ISODate ) );
234 element.appendChild( elemTemporal );
242 QDomElement elemSettings = element.firstChildElement( QStringLiteral(
"qgis3d" ) );
243 if ( !elemSettings.isNull() )
246 mSettings->readXml( elemSettings, context );
249 mSettings->resolveReferences( *
mLayout->project() );
251 mSettings->setTransformContext(
mLayout->project()->transformContext() );
252 mSettings->setPathResolver(
mLayout->project()->pathResolver() );
253 mSettings->setMapThemeCollection(
mLayout->project()->mapThemeCollection() );
257 QDomElement elemCameraPose = element.firstChildElement( QStringLiteral(
"camera-pose" ) );
258 if ( !elemCameraPose.isNull() )
259 mCameraPose.
readXml( elemCameraPose );
262 QDomElement elemTemporal = element.firstChildElement( QStringLiteral(
"temporal-settings" ) );
263 setIsTemporal( elemTemporal.attribute( QStringLiteral(
"isTemporal" ) ).toInt() );
266 QDateTime begin = QDateTime::fromString( elemTemporal.attribute( QStringLiteral(
"temporalRangeBegin" ) ), Qt::ISODate );
267 QDateTime end = QDateTime::fromString( elemTemporal.attribute( QStringLiteral(
"temporalRangeBegin" ) ), Qt::ISODate );
281 mSettings.reset( settings );
286 mCapturedImage = QImage();
294 mCapturedImage = QImage();
299 if ( mCameraPose == pose )
303 mCapturedImage = QImage();
@ Export
Renderer used for printing or exporting to a file.
@ View
Renderer used for displaying on screen.
@ Ready
The scene is fully loaded/updated.
QgsCameraController * cameraController()
Returns camera controller.
void sceneStateChanged()
Emitted when the scene's state has changed.
SceneState sceneState() const
Returns the current state of the scene.
static QImage captureSceneImage(QgsAbstract3DEngine &engine, Qgs3DMapScene *scene)
Captures image of the current 3D scene of a 3D engine.
void imageCaptured(const QImage &image)
Emitted after a call to requestCaptureImage() to return the captured image.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
void setCameraPose(const QgsCameraPose &camPose)
Sets camera pose.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element and returns it.
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written using writeXml()
void setCameraPose(const QgsCameraPose &pose)
Configures camera view.
QString displayName() const override
overridden to show "3D Map 1" type names
QgsLayoutItem3DMap(QgsLayout *layout)
Constructor for QgsLayoutItem3DMap, with the specified parent layout.
virtual int type() const override
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
QIcon icon() const override
Returns the item's icon.
static QgsLayoutItem3DMap * create(QgsLayout *layout)
Returns a new 3D map item for the specified layout.
void setMapSettings(Qgs3DMapSettings *settings)
Configures map scene.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
void assignFreeId()
Sets the map id() to a number not yet used in the layout.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Base class for graphical items within a QgsLayout.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QColor backgroundColor() const
Returns the background color for this item.
void sizePositionChanged()
Emitted when the item's size or position changes.
QString id() const
Returns the item's ID name.
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
const QgsLayout * layout() const
Returns the layout the object is attached to.
QPointer< QgsLayout > mLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
void setIsTemporal(bool enabled)
Sets whether the temporal range is enabled (i.e.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.