QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgstestutils.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstestutils.cpp
3 --------------------
4 begin : January 2018
5 copyright : (C) 2018 by Nyall Dawson
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgstestutils.h"
18#include "qgsconnectionpool.h"
19#include <QtConcurrentMap>
22
23static void getFeaturesForProvider( const QPair< std::shared_ptr< QgsAbstractFeatureSource >, QgsFeatureRequest > &pair )
24{
25 QgsFeatureIterator it = pair.first->getFeatures( pair.second );
26 QgsFeature f;
27 while ( it.nextFeature( f ) )
28 {
29
30 }
31}
32
33bool QgsTestUtils::testProviderIteratorThreadSafety( QgsVectorDataProvider *provider, const QgsFeatureRequest &request )
34{
35 constexpr int JOBS_TO_RUN = 100;
36 QList< QPair< std::shared_ptr< QgsAbstractFeatureSource >, QgsFeatureRequest > > jobs;
37 jobs.reserve( JOBS_TO_RUN );
38 for ( int i = 0; i < JOBS_TO_RUN; ++i )
39 {
40 jobs.append( qMakePair( std::shared_ptr< QgsAbstractFeatureSource >( provider->featureSource() ), request ) );
41 }
42
43 //freaking hammer the provider with a ton of concurrent requests.
44 //thread unsafe providers... you better be ready!!!!
45 QtConcurrent::blockingMap( jobs, getFeaturesForProvider );
46
47 return true;
48}
49
50
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
This is the base class for vector data providers.
virtual QgsAbstractFeatureSource * featureSource() const =0
Returns feature source object that can be used for querying provider's data.