Don't call processEvents and clear added/deleted list

This commit is contained in:
Julien Cabieces 2019-10-30 10:46:26 +01:00
parent f03da03d33
commit d246d9f593
7 changed files with 31 additions and 22 deletions

View File

@ -257,7 +257,7 @@ This method is useful if constructor parameter ``relaxed`` is ``True``
.. seealso:: :py:class:`QgsPointLocator`
%End
void waitForFinished() const;
void waitForIndexingFinished();
%Docstring
If the point locator has been initialized relaxedly and is currently indexing,
this methods waits for the indexing to be finished

View File

@ -586,25 +586,27 @@ void QgsPointLocator::setRenderContext( const QgsRenderContext *context )
}
void QgsPointLocator::onInitTaskTerminated()
void QgsPointLocator::onInitTaskFinished()
{
// Check that we don't call this method twice, when calling waitForFinished
// for instance (because of taskCompleted signal)
if ( !mIsIndexing )
return;
mIsIndexing = false;
mRenderer.reset();
mSource.reset();
}
void QgsPointLocator::onRebuildIndexFinished( bool ok )
{
onInitTaskTerminated();
// treat added and deleted feature while indexing
for ( QgsFeatureId fid : mAddedFeatures )
onFeatureAdded( fid );
mAddedFeatures.clear();
for ( QgsFeatureId fid : mDeletedFeatures )
onFeatureDeleted( fid );
mDeletedFeatures.clear();
emit initFinished( ok );
emit initFinished( mInitTask->isBuildOK() );
}
bool QgsPointLocator::init( int maxFeaturesToIndex, bool relaxed )
@ -628,8 +630,8 @@ bool QgsPointLocator::init( int maxFeaturesToIndex, bool relaxed )
if ( relaxed )
{
mInitTask = new QgsPointLocatorInitTask( this );
connect( mInitTask, &QgsPointLocatorInitTask::rebuildIndexFinished, this, &QgsPointLocator::onRebuildIndexFinished );
connect( mInitTask, &QgsPointLocatorInitTask::taskTerminated, this, &QgsPointLocator::onInitTaskTerminated );
connect( mInitTask, &QgsPointLocatorInitTask::taskTerminated, this, &QgsPointLocator::onInitTaskFinished );
connect( mInitTask, &QgsPointLocatorInitTask::taskCompleted, this, &QgsPointLocator::onInitTaskFinished );
QgsApplication::taskManager()->addTask( mInitTask );
return true;
}
@ -642,13 +644,11 @@ bool QgsPointLocator::init( int maxFeaturesToIndex, bool relaxed )
}
}
void QgsPointLocator::waitForFinished() const
void QgsPointLocator::waitForIndexingFinished()
{
mInitTask->waitForFinished();
// force process of signal emitted from task thread
// so rebuildIndexFinished and taskTerminated are called
QCoreApplication::processEvents();
onInitTaskFinished();
}
bool QgsPointLocator::hasIndex() const
@ -663,7 +663,7 @@ bool QgsPointLocator::prepare( bool relaxed )
if ( relaxed )
return false;
else
waitForFinished();
waitForIndexingFinished();
}
if ( !mRTree )

View File

@ -338,7 +338,7 @@ class CORE_EXPORT QgsPointLocator : public QObject
* If the point locator has been initialized relaxedly and is currently indexing,
* this methods waits for the indexing to be finished
*/
void waitForFinished() const;
void waitForIndexingFinished();
signals:
@ -355,8 +355,7 @@ class CORE_EXPORT QgsPointLocator : public QObject
protected slots:
void destroyIndex();
private slots:
void onInitTaskTerminated();
void onRebuildIndexFinished( bool ok );
void onInitTaskFinished();
void onFeatureAdded( QgsFeatureId fid );
void onFeatureDeleted( QgsFeatureId fid );
void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );

View File

@ -24,10 +24,14 @@ QgsPointLocatorInitTask::QgsPointLocatorInitTask( QgsPointLocator *loc )
, mLoc( loc )
{}
bool QgsPointLocatorInitTask::isBuildOK() const
{
return mBuildOK;
}
bool QgsPointLocatorInitTask::run()
{
const bool ok = mLoc->rebuildIndex();
emit rebuildIndexFinished( ok );
mBuildOK = mLoc->rebuildIndex();
return true;
}

View File

@ -41,6 +41,11 @@ class QgsPointLocatorInitTask : public QgsTask
QgsPointLocatorInitTask( QgsPointLocator *loc );
/**
* Returns TRUE when the task has finished and the index build was ok
*/
bool isBuildOK() const;
bool run();
signals:
@ -50,6 +55,7 @@ class QgsPointLocatorInitTask : public QgsTask
private:
QgsPointLocator *mLoc = nullptr;
bool mBuildOK = false;
};
/// @endcond

View File

@ -396,7 +396,7 @@ void QgsSnappingUtils::prepareIndex( const QList<LayerAndAreaOfInterest> &layers
if ( loc->isIndexing() && !relaxed )
{
loc->waitForFinished();
loc->waitForIndexingFinished();
}

View File

@ -437,7 +437,7 @@ class TestQgsPointLocator : public QObject
mVL->rollBack();
}
void testWaitForFinished()
void testWaitForIndexingFinished()
{
QgsPointLocator loc( mVL, QgsCoordinateReferenceSystem(), QgsCoordinateTransformContext(), nullptr );
QgsPointXY pt( 2, 2 );