@@ -149,38 +149,47 @@ QgsCameraController *Qgs3DMapCanvas::cameraController()
149
149
150
150
void Qgs3DMapCanvas::resetView ()
151
151
{
152
+ if ( !mScene )
153
+ return ;
154
+
152
155
mScene ->viewZoomFull ();
153
156
}
154
157
155
158
void Qgs3DMapCanvas::setViewFromTop ( const QgsPointXY ¢er, float distance, float rotation )
156
159
{
160
+ if ( !mScene )
161
+ return ;
162
+
157
163
const float worldX = center.x () - mMap ->origin ().x ();
158
164
const float worldY = center.y () - mMap ->origin ().y ();
159
165
mScene ->cameraController ()->setViewFromTop ( worldX, -worldY, distance, rotation );
160
166
}
161
167
162
168
void Qgs3DMapCanvas::saveAsImage ( const QString &fileName, const QString &fileFormat )
163
169
{
164
- if ( !fileName.isEmpty () )
170
+ if ( !mScene || fileName.isEmpty () )
171
+ return ;
172
+
173
+ mCaptureFileName = fileName;
174
+ mCaptureFileFormat = fileFormat;
175
+ mEngine ->setRenderCaptureEnabled ( true );
176
+ // Setup a frame action that is used to wait until next frame
177
+ Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
178
+ mScene ->addComponent ( screenCaptureFrameAction );
179
+ // Wait to have the render capture enabled in the next frame
180
+ connect ( screenCaptureFrameAction, &Qt3DLogic::QFrameAction::triggered, this , [ = ]( float )
165
181
{
166
- mCaptureFileName = fileName;
167
- mCaptureFileFormat = fileFormat;
168
- mEngine ->setRenderCaptureEnabled ( true );
169
- // Setup a frame action that is used to wait until next frame
170
- Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
171
- mScene ->addComponent ( screenCaptureFrameAction );
172
- // Wait to have the render capture enabled in the next frame
173
- connect ( screenCaptureFrameAction, &Qt3DLogic::QFrameAction::triggered, this , [ = ]( float )
174
- {
175
- mEngine ->requestCaptureImage ();
176
- mScene ->removeComponent ( screenCaptureFrameAction );
177
- screenCaptureFrameAction->deleteLater ();
178
- } );
179
- }
182
+ mEngine ->requestCaptureImage ();
183
+ mScene ->removeComponent ( screenCaptureFrameAction );
184
+ screenCaptureFrameAction->deleteLater ();
185
+ } );
180
186
}
181
187
182
188
void Qgs3DMapCanvas::captureDepthBuffer ()
183
189
{
190
+ if ( !mScene )
191
+ return ;
192
+
184
193
// Setup a frame action that is used to wait until next frame
185
194
Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
186
195
mScene ->addComponent ( screenCaptureFrameAction );
@@ -195,6 +204,9 @@ void Qgs3DMapCanvas::captureDepthBuffer()
195
204
196
205
void Qgs3DMapCanvas::setMapTool ( Qgs3DMapTool *tool )
197
206
{
207
+ if ( !mScene )
208
+ return ;
209
+
198
210
if ( tool == mMapTool )
199
211
return ;
200
212
@@ -281,6 +293,9 @@ void Qgs3DMapCanvas::setTemporalController( QgsTemporalController *temporalContr
281
293
282
294
void Qgs3DMapCanvas::updateTemporalRange ( const QgsDateTimeRange &temporalrange )
283
295
{
296
+ if ( !mScene )
297
+ return ;
298
+
284
299
mMap ->setTemporalRange ( temporalrange );
285
300
mScene ->updateTemporal ();
286
301
}
@@ -297,10 +312,13 @@ void Qgs3DMapCanvas::onNavigationModeChanged( Qgis::NavigationMode mode )
297
312
298
313
void Qgs3DMapCanvas::setViewFrom2DExtent ( const QgsRectangle &extent )
299
314
{
315
+ if ( !mScene )
316
+ return ;
317
+
300
318
mScene ->setViewFrom2DExtent ( extent );
301
319
}
302
320
303
321
QVector<QgsPointXY> Qgs3DMapCanvas::viewFrustum2DExtent ()
304
322
{
305
- return mScene ->viewFrustum2DExtent ();
323
+ return mScene ? mScene ->viewFrustum2DExtent () : QVector<QgsPointXY> ();
306
324
}
0 commit comments