Skip to content

Commit

Permalink
don't beak API and remove QFuture includes
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 committed Sep 6, 2019
1 parent 0e98585 commit 50f3a02
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
13 changes: 3 additions & 10 deletions python/core/auto_generated/qgspointlocator.sip.in
Expand Up @@ -11,7 +11,6 @@




class QgsPointLocator : QObject
{
%Docstring
Expand Down Expand Up @@ -98,14 +97,15 @@ Configure render context - if not ``None``, it will use to index only visible f
typedef QFlags<QgsPointLocator::Type> Types;


void init( int maxFeaturesToIndex = -1 );
bool init( int maxFeaturesToIndex = -1 );
%Docstring
Prepare the index for queries. Does nothing if the index already exists.
If the number of features is greater than the value of maxFeaturesToIndex, creation of index is stopped
to make sure we do not run out of memory. If maxFeaturesToIndex is -1, no limits are used.

This method is either blocking or non blocking according to ``asynchronous`` parameter passed
in the constructor
in the constructor.
Returns false if the creation of index is blocking and has been prematurely stopped due to the limit of features, otherwise true

.. seealso:: :py:class:`QgsPointLocator`
%End
Expand Down Expand Up @@ -259,13 +259,6 @@ Emitted whenever index has been built and initialization is finished
protected:
bool rebuildIndex( int maxFeaturesToIndex = -1 );

bool prepare();
%Docstring
prepare index if need and returns ``True`` if the index is ready to be used

.. versionadded:: 3.10
%End

protected slots:
void destroyIndex();
};
Expand Down
Binary file modified resources/data/world_map.gpkg
Binary file not shown.
17 changes: 13 additions & 4 deletions src/core/qgspointlocator.cpp
Expand Up @@ -588,9 +588,16 @@ void QgsPointLocator::setRenderContext( const QgsRenderContext *context )

}

void QgsPointLocator::onRebuildIndexFinished( bool ok )
void QgsPointLocator::onInitTaskTerminated()
{
mIsIndexing = false;
mRenderer.reset();
mSource.reset();
}

void QgsPointLocator::onRebuildIndexFinished( bool ok )
{
onInitTaskTerminated();

// treat added and deleted feature while indexing
for ( QgsFeatureId fid : mAddedFeatures )
Expand All @@ -602,13 +609,13 @@ void QgsPointLocator::onRebuildIndexFinished( bool ok )
emit initFinished( ok );
}

void QgsPointLocator::init( int maxFeaturesToIndex )
bool QgsPointLocator::init( int maxFeaturesToIndex )
{
const QgsWkbTypes::GeometryType geomType = mLayer->geometryType();
if ( geomType == QgsWkbTypes::NullGeometry // nothing to index
|| hasIndex()
|| mIsIndexing ) // already indexing, return!
return;
return true;

mRenderer.reset( mLayer->renderer() ? mLayer->renderer()->clone() : nullptr );
mSource.reset( new QgsVectorLayerFeatureSource( mLayer ) );
Expand All @@ -624,14 +631,16 @@ void QgsPointLocator::init( int maxFeaturesToIndex )
{
QgsPointLocatorInitTask *task = new QgsPointLocatorInitTask( this );
connect( task, &QgsPointLocatorInitTask::rebuildIndexFinished, this, &QgsPointLocator::onRebuildIndexFinished );
connect( task, &QgsPointLocatorInitTask::taskTerminated, this, [ = ] { mIsIndexing = false; } );
connect( task, &QgsPointLocatorInitTask::taskTerminated, this, &QgsPointLocator::onInitTaskTerminated );
QgsApplication::taskManager()->addTask( task );
return true;
}
else
{
const bool ok = rebuildIndex( maxFeaturesToIndex );
mIsIndexing = false;
emit initFinished( ok );
return ok;
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/core/qgspointlocator.h
Expand Up @@ -16,9 +16,6 @@
#ifndef QGSPOINTLOCATOR_H
#define QGSPOINTLOCATOR_H

#include <QFuture>
#include <QFutureWatcher>

class QgsPointXY;
class QgsVectorLayer;
class QgsFeatureRenderer;
Expand Down Expand Up @@ -132,10 +129,12 @@ class CORE_EXPORT QgsPointLocator : public QObject
* to make sure we do not run out of memory. If maxFeaturesToIndex is -1, no limits are used.
*
* This method is either blocking or non blocking according to \a asynchronous parameter passed
* in the constructor
* in the constructor.
* Returns false if the creation of index is blocking and has been prematurely stopped due to the limit of features, otherwise true
*
* \see QgsPointLocator()
*/
void init( int maxFeaturesToIndex = -1 );
bool init( int maxFeaturesToIndex = -1 );

//! Indicate whether the data have been already indexed
bool hasIndex() const;
Expand Down Expand Up @@ -314,22 +313,21 @@ class CORE_EXPORT QgsPointLocator : public QObject
protected:
bool rebuildIndex( int maxFeaturesToIndex = -1 );

/**
* prepare index if need and returns TRUE if the index is ready to be used
* \since 3.10
*/
bool prepare();

protected slots:
void destroyIndex();
private slots:
void onInitTaskTerminated();
void onRebuildIndexFinished( bool ok );
void onFeatureAdded( QgsFeatureId fid );
void onFeatureDeleted( QgsFeatureId fid );
void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );

private:

//! prepare index if need and returns TRUE if the index is ready to be used
bool prepare();

//! Storage manager
std::unique_ptr< SpatialIndex::IStorageManager > mStorage;

Expand Down

0 comments on commit 50f3a02

Please sign in to comment.