mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-30 00:04:26 -04:00
Don't call processEvents and clear added/deleted list
This commit is contained in:
parent
f03da03d33
commit
d246d9f593
python/core/auto_generated
src/core
qgspointlocator.cppqgspointlocator.hqgspointlocatorinittask.cppqgspointlocatorinittask.hqgssnappingutils.cpp
tests/src/core
@ -257,7 +257,7 @@ This method is useful if constructor parameter ``relaxed`` is ``True``
|
|||||||
.. seealso:: :py:class:`QgsPointLocator`
|
.. seealso:: :py:class:`QgsPointLocator`
|
||||||
%End
|
%End
|
||||||
|
|
||||||
void waitForFinished() const;
|
void waitForIndexingFinished();
|
||||||
%Docstring
|
%Docstring
|
||||||
If the point locator has been initialized relaxedly and is currently indexing,
|
If the point locator has been initialized relaxedly and is currently indexing,
|
||||||
this methods waits for the indexing to be finished
|
this methods waits for the indexing to be finished
|
||||||
|
@ -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;
|
mIsIndexing = false;
|
||||||
mRenderer.reset();
|
mRenderer.reset();
|
||||||
mSource.reset();
|
mSource.reset();
|
||||||
}
|
|
||||||
|
|
||||||
void QgsPointLocator::onRebuildIndexFinished( bool ok )
|
|
||||||
{
|
|
||||||
onInitTaskTerminated();
|
|
||||||
|
|
||||||
// treat added and deleted feature while indexing
|
// treat added and deleted feature while indexing
|
||||||
for ( QgsFeatureId fid : mAddedFeatures )
|
for ( QgsFeatureId fid : mAddedFeatures )
|
||||||
onFeatureAdded( fid );
|
onFeatureAdded( fid );
|
||||||
|
mAddedFeatures.clear();
|
||||||
|
|
||||||
for ( QgsFeatureId fid : mDeletedFeatures )
|
for ( QgsFeatureId fid : mDeletedFeatures )
|
||||||
onFeatureDeleted( fid );
|
onFeatureDeleted( fid );
|
||||||
|
mDeletedFeatures.clear();
|
||||||
|
|
||||||
emit initFinished( ok );
|
emit initFinished( mInitTask->isBuildOK() );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsPointLocator::init( int maxFeaturesToIndex, bool relaxed )
|
bool QgsPointLocator::init( int maxFeaturesToIndex, bool relaxed )
|
||||||
@ -628,8 +630,8 @@ bool QgsPointLocator::init( int maxFeaturesToIndex, bool relaxed )
|
|||||||
if ( relaxed )
|
if ( relaxed )
|
||||||
{
|
{
|
||||||
mInitTask = new QgsPointLocatorInitTask( this );
|
mInitTask = new QgsPointLocatorInitTask( this );
|
||||||
connect( mInitTask, &QgsPointLocatorInitTask::rebuildIndexFinished, this, &QgsPointLocator::onRebuildIndexFinished );
|
connect( mInitTask, &QgsPointLocatorInitTask::taskTerminated, this, &QgsPointLocator::onInitTaskFinished );
|
||||||
connect( mInitTask, &QgsPointLocatorInitTask::taskTerminated, this, &QgsPointLocator::onInitTaskTerminated );
|
connect( mInitTask, &QgsPointLocatorInitTask::taskCompleted, this, &QgsPointLocator::onInitTaskFinished );
|
||||||
QgsApplication::taskManager()->addTask( mInitTask );
|
QgsApplication::taskManager()->addTask( mInitTask );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -642,13 +644,11 @@ bool QgsPointLocator::init( int maxFeaturesToIndex, bool relaxed )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsPointLocator::waitForFinished() const
|
void QgsPointLocator::waitForIndexingFinished()
|
||||||
{
|
{
|
||||||
mInitTask->waitForFinished();
|
mInitTask->waitForFinished();
|
||||||
|
|
||||||
// force process of signal emitted from task thread
|
onInitTaskFinished();
|
||||||
// so rebuildIndexFinished and taskTerminated are called
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsPointLocator::hasIndex() const
|
bool QgsPointLocator::hasIndex() const
|
||||||
@ -663,7 +663,7 @@ bool QgsPointLocator::prepare( bool relaxed )
|
|||||||
if ( relaxed )
|
if ( relaxed )
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
waitForFinished();
|
waitForIndexingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !mRTree )
|
if ( !mRTree )
|
||||||
|
@ -338,7 +338,7 @@ class CORE_EXPORT QgsPointLocator : public QObject
|
|||||||
* If the point locator has been initialized relaxedly and is currently indexing,
|
* If the point locator has been initialized relaxedly and is currently indexing,
|
||||||
* this methods waits for the indexing to be finished
|
* this methods waits for the indexing to be finished
|
||||||
*/
|
*/
|
||||||
void waitForFinished() const;
|
void waitForIndexingFinished();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@ -355,8 +355,7 @@ class CORE_EXPORT QgsPointLocator : public QObject
|
|||||||
protected slots:
|
protected slots:
|
||||||
void destroyIndex();
|
void destroyIndex();
|
||||||
private slots:
|
private slots:
|
||||||
void onInitTaskTerminated();
|
void onInitTaskFinished();
|
||||||
void onRebuildIndexFinished( bool ok );
|
|
||||||
void onFeatureAdded( QgsFeatureId fid );
|
void onFeatureAdded( QgsFeatureId fid );
|
||||||
void onFeatureDeleted( QgsFeatureId fid );
|
void onFeatureDeleted( QgsFeatureId fid );
|
||||||
void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
|
void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
|
||||||
|
@ -24,10 +24,14 @@ QgsPointLocatorInitTask::QgsPointLocatorInitTask( QgsPointLocator *loc )
|
|||||||
, mLoc( loc )
|
, mLoc( loc )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
bool QgsPointLocatorInitTask::isBuildOK() const
|
||||||
|
{
|
||||||
|
return mBuildOK;
|
||||||
|
}
|
||||||
|
|
||||||
bool QgsPointLocatorInitTask::run()
|
bool QgsPointLocatorInitTask::run()
|
||||||
{
|
{
|
||||||
const bool ok = mLoc->rebuildIndex();
|
mBuildOK = mLoc->rebuildIndex();
|
||||||
emit rebuildIndexFinished( ok );
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,11 @@ class QgsPointLocatorInitTask : public QgsTask
|
|||||||
|
|
||||||
QgsPointLocatorInitTask( QgsPointLocator *loc );
|
QgsPointLocatorInitTask( QgsPointLocator *loc );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE when the task has finished and the index build was ok
|
||||||
|
*/
|
||||||
|
bool isBuildOK() const;
|
||||||
|
|
||||||
bool run();
|
bool run();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -50,6 +55,7 @@ class QgsPointLocatorInitTask : public QgsTask
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
QgsPointLocator *mLoc = nullptr;
|
QgsPointLocator *mLoc = nullptr;
|
||||||
|
bool mBuildOK = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
@ -396,7 +396,7 @@ void QgsSnappingUtils::prepareIndex( const QList<LayerAndAreaOfInterest> &layers
|
|||||||
|
|
||||||
if ( loc->isIndexing() && !relaxed )
|
if ( loc->isIndexing() && !relaxed )
|
||||||
{
|
{
|
||||||
loc->waitForFinished();
|
loc->waitForIndexingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ class TestQgsPointLocator : public QObject
|
|||||||
mVL->rollBack();
|
mVL->rollBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
void testWaitForFinished()
|
void testWaitForIndexingFinished()
|
||||||
{
|
{
|
||||||
QgsPointLocator loc( mVL, QgsCoordinateReferenceSystem(), QgsCoordinateTransformContext(), nullptr );
|
QgsPointLocator loc( mVL, QgsCoordinateReferenceSystem(), QgsCoordinateTransformContext(), nullptr );
|
||||||
QgsPointXY pt( 2, 2 );
|
QgsPointXY pt( 2, 2 );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user