[BUG][3D] fix 3D crash with measure line (#35412)

* fix 3D crash with measure line

* avoid non wanted windows opening of identify tool and measurment tool

* adds guard avoid crashing when closing settings

* spelling
This commit is contained in:
Vincent Cloarec 2020-04-04 06:56:38 -04:00 committed by GitHub
parent 3c643d9cbd
commit 0eaba81c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -87,6 +87,7 @@ void Qgs3DMapToolIdentify::activate()
} }
mCanvas->scene()->registerPickHandler( mPickHandler.get() ); mCanvas->scene()->registerPickHandler( mPickHandler.get() );
mIsActive = true;
} }
void Qgs3DMapToolIdentify::deactivate() void Qgs3DMapToolIdentify::deactivate()
@ -97,6 +98,7 @@ void Qgs3DMapToolIdentify::deactivate()
} }
mCanvas->scene()->unregisterPickHandler( mPickHandler.get() ); mCanvas->scene()->unregisterPickHandler( mPickHandler.get() );
mIsActive = false;
} }
QCursor Qgs3DMapToolIdentify::cursor() const QCursor Qgs3DMapToolIdentify::cursor() const
@ -106,6 +108,8 @@ QCursor Qgs3DMapToolIdentify::cursor() const
void Qgs3DMapToolIdentify::onMapSettingsChanged() void Qgs3DMapToolIdentify::onMapSettingsChanged()
{ {
if ( !mIsActive )
return;
connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolIdentify::onTerrainEntityChanged ); connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolIdentify::onTerrainEntityChanged );
} }
@ -153,6 +157,8 @@ void Qgs3DMapToolIdentify::onTerrainPicked( Qt3DRender::QPickEvent *event )
void Qgs3DMapToolIdentify::onTerrainEntityChanged() void Qgs3DMapToolIdentify::onTerrainEntityChanged()
{ {
if ( !mIsActive )
return;
// no need to disconnect from the previous entity: it has been destroyed // no need to disconnect from the previous entity: it has been destroyed
// start listening to the new terrain entity // start listening to the new terrain entity
if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() ) if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() )

View File

@ -53,6 +53,8 @@ class Qgs3DMapToolIdentify : public Qgs3DMapTool
private: private:
std::unique_ptr<Qgs3DMapToolIdentifyPickHandler> mPickHandler; std::unique_ptr<Qgs3DMapToolIdentifyPickHandler> mPickHandler;
bool mIsActive = false;
friend class Qgs3DMapToolIdentifyPickHandler; friend class Qgs3DMapToolIdentifyPickHandler;
}; };

View File

@ -124,6 +124,8 @@ QCursor Qgs3DMapToolMeasureLine::cursor() const
void Qgs3DMapToolMeasureLine::onMapSettingsChanged() void Qgs3DMapToolMeasureLine::onMapSettingsChanged()
{ {
if ( !mIsAlreadyActivated )
return;
connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolMeasureLine::onTerrainEntityChanged ); connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolMeasureLine::onTerrainEntityChanged );
// Update scale if the terrain vertical scale changed // Update scale if the terrain vertical scale changed
@ -137,6 +139,8 @@ void Qgs3DMapToolMeasureLine::onTerrainPicked( Qt3DRender::QPickEvent *event )
void Qgs3DMapToolMeasureLine::onTerrainEntityChanged() void Qgs3DMapToolMeasureLine::onTerrainEntityChanged()
{ {
if ( !mIsAlreadyActivated )
return;
// no need to disconnect from the previous entity: it has been destroyed // no need to disconnect from the previous entity: it has been destroyed
// start listening to the new terrain entity // start listening to the new terrain entity
if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() ) if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() )
@ -175,6 +179,8 @@ void Qgs3DMapToolMeasureLine::handleClick( Qt3DRender::QPickEvent *event, const
void Qgs3DMapToolMeasureLine::updateMeasurementLayer() void Qgs3DMapToolMeasureLine::updateMeasurementLayer()
{ {
if ( !mMeasurementLayer )
return;
double verticalScale = canvas()->map()->terrainVerticalScale(); double verticalScale = canvas()->map()->terrainVerticalScale();
QgsLineString *line; QgsLineString *line;
if ( verticalScale != 1.0 ) if ( verticalScale != 1.0 )
@ -205,6 +211,8 @@ void Qgs3DMapToolMeasureLine::updateMeasurementLayer()
void Qgs3DMapToolMeasureLine::updateSettings() void Qgs3DMapToolMeasureLine::updateSettings()
{ {
if ( !mMeasurementLayer )
return;
// Line style // Line style
QgsLine3DSymbol *lineSymbol = new QgsLine3DSymbol; QgsLine3DSymbol *lineSymbol = new QgsLine3DSymbol;
lineSymbol->setRenderAsSimpleLines( true ); lineSymbol->setRenderAsSimpleLines( true );