Skip to content

Commit

Permalink
check if Qgs3DMapScene has been created before accessing
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros authored and nyalldawson committed Oct 19, 2023
1 parent 689a935 commit ca5041b
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions src/app/3d/qgs3dmapcanvas.cpp
Expand Up @@ -149,38 +149,47 @@ QgsCameraController *Qgs3DMapCanvas::cameraController()

void Qgs3DMapCanvas::resetView()
{
if ( !mScene )
return;

mScene->viewZoomFull();
}

void Qgs3DMapCanvas::setViewFromTop( const QgsPointXY &center, float distance, float rotation )
{
if ( !mScene )
return;

const float worldX = center.x() - mMap->origin().x();
const float worldY = center.y() - mMap->origin().y();
mScene->cameraController()->setViewFromTop( worldX, -worldY, distance, rotation );
}

void Qgs3DMapCanvas::saveAsImage( const QString &fileName, const QString &fileFormat )
{
if ( !fileName.isEmpty() )
if ( !mScene || fileName.isEmpty() )
return;

mCaptureFileName = fileName;
mCaptureFileFormat = fileFormat;
mEngine->setRenderCaptureEnabled( true );
// Setup a frame action that is used to wait until next frame
Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
mScene->addComponent( screenCaptureFrameAction );
// Wait to have the render capture enabled in the next frame
connect( screenCaptureFrameAction, &Qt3DLogic::QFrameAction::triggered, this, [ = ]( float )
{
mCaptureFileName = fileName;
mCaptureFileFormat = fileFormat;
mEngine->setRenderCaptureEnabled( true );
// Setup a frame action that is used to wait until next frame
Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
mScene->addComponent( screenCaptureFrameAction );
// Wait to have the render capture enabled in the next frame
connect( screenCaptureFrameAction, &Qt3DLogic::QFrameAction::triggered, this, [ = ]( float )
{
mEngine->requestCaptureImage();
mScene->removeComponent( screenCaptureFrameAction );
screenCaptureFrameAction->deleteLater();
} );
}
mEngine->requestCaptureImage();
mScene->removeComponent( screenCaptureFrameAction );
screenCaptureFrameAction->deleteLater();
} );
}

void Qgs3DMapCanvas::captureDepthBuffer()
{
if ( !mScene )
return;

// Setup a frame action that is used to wait until next frame
Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
mScene->addComponent( screenCaptureFrameAction );
Expand All @@ -195,6 +204,9 @@ void Qgs3DMapCanvas::captureDepthBuffer()

void Qgs3DMapCanvas::setMapTool( Qgs3DMapTool *tool )
{
if ( !mScene )
return;

if ( tool == mMapTool )
return;

Expand Down Expand Up @@ -281,6 +293,9 @@ void Qgs3DMapCanvas::setTemporalController( QgsTemporalController *temporalContr

void Qgs3DMapCanvas::updateTemporalRange( const QgsDateTimeRange &temporalrange )
{
if ( !mScene )
return;

mMap->setTemporalRange( temporalrange );
mScene->updateTemporal();
}
Expand All @@ -297,10 +312,13 @@ void Qgs3DMapCanvas::onNavigationModeChanged( Qgis::NavigationMode mode )

void Qgs3DMapCanvas::setViewFrom2DExtent( const QgsRectangle &extent )
{
if ( !mScene )
return;

mScene->setViewFrom2DExtent( extent );
}

QVector<QgsPointXY> Qgs3DMapCanvas::viewFrustum2DExtent()
{
return mScene->viewFrustum2DExtent();
return mScene ? mScene->viewFrustum2DExtent() : QVector<QgsPointXY>();
}

0 comments on commit ca5041b

Please sign in to comment.