Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
vcloarec committed Apr 4, 2020
1 parent 3c643d9 commit 0eaba81
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/3d/qgs3dmaptoolidentify.cpp
Expand Up @@ -87,6 +87,7 @@ void Qgs3DMapToolIdentify::activate()
}

mCanvas->scene()->registerPickHandler( mPickHandler.get() );
mIsActive = true;
}

void Qgs3DMapToolIdentify::deactivate()
Expand All @@ -97,6 +98,7 @@ void Qgs3DMapToolIdentify::deactivate()
}

mCanvas->scene()->unregisterPickHandler( mPickHandler.get() );
mIsActive = false;
}

QCursor Qgs3DMapToolIdentify::cursor() const
Expand All @@ -106,6 +108,8 @@ QCursor Qgs3DMapToolIdentify::cursor() const

void Qgs3DMapToolIdentify::onMapSettingsChanged()
{
if ( !mIsActive )
return;
connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolIdentify::onTerrainEntityChanged );
}

Expand Down Expand Up @@ -153,6 +157,8 @@ void Qgs3DMapToolIdentify::onTerrainPicked( Qt3DRender::QPickEvent *event )

void Qgs3DMapToolIdentify::onTerrainEntityChanged()
{
if ( !mIsActive )
return;
// no need to disconnect from the previous entity: it has been destroyed
// start listening to the new terrain entity
if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() )
Expand Down
2 changes: 2 additions & 0 deletions src/app/3d/qgs3dmaptoolidentify.h
Expand Up @@ -53,6 +53,8 @@ class Qgs3DMapToolIdentify : public Qgs3DMapTool
private:
std::unique_ptr<Qgs3DMapToolIdentifyPickHandler> mPickHandler;

bool mIsActive = false;

friend class Qgs3DMapToolIdentifyPickHandler;
};

Expand Down
8 changes: 8 additions & 0 deletions src/app/3d/qgs3dmaptoolmeasureline.cpp
Expand Up @@ -124,6 +124,8 @@ QCursor Qgs3DMapToolMeasureLine::cursor() const

void Qgs3DMapToolMeasureLine::onMapSettingsChanged()
{
if ( !mIsAlreadyActivated )
return;
connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolMeasureLine::onTerrainEntityChanged );

// Update scale if the terrain vertical scale changed
Expand All @@ -137,6 +139,8 @@ void Qgs3DMapToolMeasureLine::onTerrainPicked( Qt3DRender::QPickEvent *event )

void Qgs3DMapToolMeasureLine::onTerrainEntityChanged()
{
if ( !mIsAlreadyActivated )
return;
// no need to disconnect from the previous entity: it has been destroyed
// start listening to the new terrain entity
if ( QgsTerrainEntity *terrainEntity = mCanvas->scene()->terrainEntity() )
Expand Down Expand Up @@ -175,6 +179,8 @@ void Qgs3DMapToolMeasureLine::handleClick( Qt3DRender::QPickEvent *event, const

void Qgs3DMapToolMeasureLine::updateMeasurementLayer()
{
if ( !mMeasurementLayer )
return;
double verticalScale = canvas()->map()->terrainVerticalScale();
QgsLineString *line;
if ( verticalScale != 1.0 )
Expand Down Expand Up @@ -205,6 +211,8 @@ void Qgs3DMapToolMeasureLine::updateMeasurementLayer()

void Qgs3DMapToolMeasureLine::updateSettings()
{
if ( !mMeasurementLayer )
return;
// Line style
QgsLine3DSymbol *lineSymbol = new QgsLine3DSymbol;
lineSymbol->setRenderAsSimpleLines( true );
Expand Down

0 comments on commit 0eaba81

Please sign in to comment.