31#include "moc_qgslayoutitem3dmap.cpp"
33using namespace Qt::StringLiterals;
66 QList<QgsLayoutItem3DMap *> mapsList;
67 mLayout->layoutItems( mapsList );
76 if ( map->mMapId == mMapId )
79 maxId = std::max( maxId, map->mMapId );
84 mLayout->itemsModel()->updateItemDisplayName(
this );
96 return tr(
"3D Map %1" ).arg( mMapId );
99void QgsLayoutItem3DMap::updateToolTip()
107 QPainter *painter = ctx.
painter();
109 int w =
static_cast<int>( std::ceil( rect().width() * ctx.
scaleFactor() ) );
110 int h =
static_cast<int>( std::ceil( rect().height() * ctx.
scaleFactor() ) );
111 QRect r( 0, 0, w, h );
115 painter->drawText( r, Qt::AlignCenter, tr(
"Scene not set" ) );
122 mCapturedImage = QImage();
125 if ( !mCapturedImage.isNull() )
127 painter->drawImage( r, mCapturedImage );
133 if (
mLayout->renderContext().isPreviewRender() )
135 painter->drawText( r, Qt::AlignCenter, tr(
"Loading" ) );
152 QSize sizePixelsInt = QSize(
static_cast<int>( std::ceil( sizePixels.width() ) ),
static_cast<int>( std::ceil( sizePixels.height() ) ) );
159 mEngine = std::make_unique<QgsOffscreen3DEngine>();
162 mEngine->setSize( sizePixelsInt );
166 mEngine->setRootEntity( mScene );
169 if ( mEngine->size() != sizePixelsInt )
170 mEngine->setSize( sizePixelsInt );
172 mScene->cameraController()->setCameraPose( mCameraPose );
174 if (
mLayout->renderContext().isPreviewRender() )
176 onSceneStateChanged();
190 painter->drawImage( r, img );
198void QgsLayoutItem3DMap::onImageCaptured(
const QImage &img )
200 mCapturedImage = img;
204void QgsLayoutItem3DMap::onSceneStateChanged()
208 mEngine->requestCaptureImage();
212void QgsLayoutItem3DMap::onSizePositionChanged()
214 mCapturedImage = QImage();
223 QDomElement elemSettings = mSettings->writeXml( document, context );
224 element.appendChild( elemSettings );
227 QDomElement elemCameraPose = mCameraPose.writeXml( document );
228 element.appendChild( elemCameraPose );
231 QDomElement elemTemporal = document.createElement( u
"temporal-settings"_s );
232 elemTemporal.setAttribute( u
"isTemporal"_s,
isTemporal() ? 1 : 0 );
235 elemTemporal.setAttribute( u
"temporalRangeBegin"_s,
temporalRange().begin().toString( Qt::ISODate ) );
236 elemTemporal.setAttribute( u
"temporalRangeEnd"_s,
temporalRange().end().toString( Qt::ISODate ) );
238 element.appendChild( elemTemporal );
246 QDomElement elemSettings = element.firstChildElement( u
"qgis3d"_s );
247 if ( !elemSettings.isNull() )
249 mSettings = std::make_unique<Qgs3DMapSettings>();
250 mSettings->readXml( elemSettings, context );
253 mSettings->resolveReferences( *
mLayout->project() );
255 mSettings->setTransformContext(
mLayout->project()->transformContext() );
256 mSettings->setPathResolver(
mLayout->project()->pathResolver() );
257 mSettings->setMapThemeCollection(
mLayout->project()->mapThemeCollection() );
261 QDomElement elemCameraPose = element.firstChildElement( u
"camera-pose"_s );
262 if ( !elemCameraPose.isNull() )
263 mCameraPose.readXml( elemCameraPose );
266 QDomElement elemTemporal = element.firstChildElement( u
"temporal-settings"_s );
267 setIsTemporal( elemTemporal.attribute( u
"isTemporal"_s ).toInt() );
270 QDateTime begin = QDateTime::fromString( elemTemporal.attribute( u
"temporalRangeBegin"_s ), Qt::ISODate );
271 QDateTime end = QDateTime::fromString( elemTemporal.attribute( u
"temporalRangeBegin"_s ), Qt::ISODate );
285 mSettings.reset( settings );
290 mCapturedImage = QImage();
298 mCapturedImage = QImage();
303 if ( mCameraPose == pose )
307 mCapturedImage = QImage();
@ Export
Renderer used for printing or exporting to a file.
@ View
Renderer used for displaying on screen.
Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
@ Ready
The scene is fully loaded/updated.
void sceneStateChanged()
Emitted when the scene's state has changed.
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.
Encapsulates camera pose in a 3D scene.
void setCameraPose(const QgsCameraPose &pose)
Configures camera view.
~QgsLayoutItem3DMap() override
QString displayName() const override
overridden to show "3D Map 1" type names
QgsLayoutItem3DMap(QgsLayout *layout)
Constructor for QgsLayoutItem3DMap, with the specified parent layout.
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.
QColor backgroundColor(bool useDataDefined=true) const
Returns the background color for this item.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
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
A container for the context for various read/write operations on 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.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.