Skip to content

Commit

Permalink
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -206,7 +206,7 @@ Returns the status of point cloud statistics calculation
.. versionadded:: 3.26
%End

void waitForStatisticsCalculationToFinish();
void waitForStatisticsCalculationToFinish( bool cancelTask );
%Docstring
If a statistics calculation task is running wait for it to finish

10 changes: 6 additions & 4 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Original file line number Diff line number Diff line change
@@ -67,7 +67,8 @@ QgsPointCloudLayer::QgsPointCloudLayer( const QString &uri,

QgsPointCloudLayer::~QgsPointCloudLayer()
{
waitForStatisticsCalculationToFinish();
// TODO: switch to using private resources for the inner workings of the stats calculation task
waitForStatisticsCalculationToFinish( true );
}

QgsPointCloudLayer *QgsPointCloudLayer::clone() const
@@ -814,17 +815,18 @@ void QgsPointCloudLayer::calculateStatistics()
emit statisticsCalculationStateChanged( mStatisticsCalculationState );
}

void QgsPointCloudLayer::waitForStatisticsCalculationToFinish()
void QgsPointCloudLayer::waitForStatisticsCalculationToFinish( bool cancelTask )
{
// If the statistics calculation task is still running we need to cancel it and wait for the task to get actually terminated or completed properly
// If the statistics calculation task is still running we need to wait for the task to get actually terminated or completed properly
if ( QgsTask *task = QgsApplication::taskManager()->task( mStatsCalculationTask ) )
{
if ( task->isActive() )
{
QEventLoop loop;
connect( task, &QgsTask::taskCompleted, &loop, &QEventLoop::quit );
connect( task, &QgsTask::taskTerminated, &loop, &QEventLoop::quit );
task->cancel();
if ( cancelTask )
task->cancel();
loop.exec();
}
}
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudlayer.h
Original file line number Diff line number Diff line change
@@ -249,7 +249,7 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer, public QgsAbstractPro
* If a statistics calculation task is running wait for it to finish
* \since QGIS 3.26
*/
void waitForStatisticsCalculationToFinish();
void waitForStatisticsCalculationToFinish( bool cancelTask );
signals:

/**
1 change: 1 addition & 0 deletions tests/src/providers/testqgscopcprovider.cpp
Original file line number Diff line number Diff line change
@@ -325,6 +325,7 @@ void TestQgsCopcProvider::calculateZRange()
{
std::unique_ptr< QgsPointCloudLayer > layer = std::make_unique< QgsPointCloudLayer >( mTestDataDir + QStringLiteral( "point_clouds/copc/sunshine-coast.copc.laz" ), QStringLiteral( "layer" ), QStringLiteral( "copc" ) );
QVERIFY( layer->isValid() );
layer->waitForStatisticsCalculationToFinish( false );

QgsDoubleRange range = layer->elevationProperties()->calculateZRange( layer.get() );
QGSCOMPARENEAR( range.lower(), 74.34, 0.01 );

0 comments on commit b5e2887

Please sign in to comment.