Check that QgsGeometryCheckContext::project is only used from main thread

This commit is contained in:
Matthias Kuhn 2019-08-12 07:25:42 +02:00
parent 43bbaf0c5d
commit f5638fe63d
7 changed files with 43 additions and 11 deletions

View File

@ -8,12 +8,26 @@
struct QgsGeometryCheckContext
class QgsGeometryCheckContext
{
%Docstring
Base configuration for geometry checks.
.. note::
This class is a technology preview and unstable API.
.. versionadded:: 3.4
%End
%TypeHeaderCode
#include "qgsgeometrycheckcontext.h"
%End
public:
QgsGeometryCheckContext( int precision,
const QgsCoordinateReferenceSystem &mapCrs,
const QgsCoordinateTransformContext &transformContext,
const QgsProject *project );
const QgsProject *mProject );
const double tolerance;
@ -23,7 +37,14 @@ struct QgsGeometryCheckContext
const QgsCoordinateTransformContext transformContext;
const QgsProject *project;
const QgsProject *project() const;
%Docstring
The project can be used to resolve additional layers.
This must only be accessed from the main thread (i.e. do not access from the collectError method)
.. versionadded:: 3.10
%End
private:
QgsGeometryCheckContext( const QgsGeometryCheckContext &rh );

View File

@ -14,12 +14,19 @@
***************************************************************************/
#include "qgsgeometrycheckcontext.h"
#include <QThread>
QgsGeometryCheckContext::QgsGeometryCheckContext( int precision, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &transformContext, const QgsProject *project )
: tolerance( std::pow( 10, -precision ) )
, reducedTolerance( std::pow( 10, -precision / 2 ) )
, mapCrs( mapCrs )
, transformContext( transformContext )
, project( project )
, mProject( project )
{
}
const QgsProject *QgsGeometryCheckContext::project() const
{
Q_ASSERT( qApp->thread() == QThread::currentThread() );
return mProject;
}

View File

@ -27,12 +27,13 @@
* \note This class is a technology preview and unstable API.
* \since QGIS 3.4
*/
struct ANALYSIS_EXPORT QgsGeometryCheckContext
class ANALYSIS_EXPORT QgsGeometryCheckContext
{
public:
QgsGeometryCheckContext( int precision,
const QgsCoordinateReferenceSystem &mapCrs,
const QgsCoordinateTransformContext &transformContext,
const QgsProject *project );
const QgsProject *mProject );
/**
* The tolerance to allow for in geometry checks.
@ -66,7 +67,10 @@ struct ANALYSIS_EXPORT QgsGeometryCheckContext
*
* \since QGIS 3.10
*/
const QgsProject *project;
const QgsProject *project() const;
private:
const QgsProject *mProject;
private:
#ifdef SIP_RUN

View File

@ -29,7 +29,7 @@
#include "qgsfeatureid.h"
typedef qint64 QgsFeatureId;
struct QgsGeometryCheckContext;
class QgsGeometryCheckContext;
class QgsGeometryCheck;
class QgsGeometryCheckError;
class QgsMapLayer;

View File

@ -30,7 +30,7 @@
class QgsGeometryCheck;
class QgsSingleGeometryCheck;
struct QgsGeometryCheckContext;
class QgsGeometryCheckContext;
/**
* \ingroup analysis

View File

@ -25,7 +25,7 @@
#include "qgsgeometrycheck.h"
class QgsGeometryCheckFactory;
struct QgsGeometryCheckContext;
class QgsGeometryCheckContext;
/**

View File

@ -36,7 +36,7 @@ void QgsGeometryGapCheck::prepare( const QgsGeometryCheckContext *context, const
{
if ( configuration.value( QStringLiteral( "allowedGapsEnabled" ) ).toBool() )
{
QgsVectorLayer *layer = context->project->mapLayer<QgsVectorLayer *>( configuration.value( "allowedGapsLayer" ).toString() );
QgsVectorLayer *layer = context->project()->mapLayer<QgsVectorLayer *>( configuration.value( "allowedGapsLayer" ).toString() );
mAllowedGapsLayer = layer;
mAllowedGapsSource = qgis::make_unique<QgsVectorLayerFeatureSource>( layer );