Skip to content

Commit

Permalink
Relucantantly accomodate insane thread unsafety of virtual layer prov…
Browse files Browse the repository at this point in the history
…ider
  • Loading branch information
nyalldawson committed Dec 16, 2022
1 parent 6872948 commit 50a157a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/core/project/qgsproject.cpp
Expand Up @@ -3969,7 +3969,8 @@ int QgsProject::validCount() const

QgsMapLayer *QgsProject::mapLayer( const QString &layerId ) const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

return mLayerStore->mapLayer( layerId );
}
Expand Down Expand Up @@ -4299,7 +4300,8 @@ void QgsProject::reloadAllLayers()

QMap<QString, QgsMapLayer *> QgsProject::mapLayers( const bool validOnly ) const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

return validOnly ? mLayerStore->validMapLayers() : mLayerStore->mapLayers();
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/providers/qgsdataprovider.cpp
Expand Up @@ -51,7 +51,8 @@ const QgsDataProviderTemporalCapabilities *QgsDataProvider::temporalCapabilities

void QgsDataProvider::reloadData()
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// Because QgsVirtualLayerTask is not thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

reloadProviderData();
emit dataChanged();
Expand Down
12 changes: 8 additions & 4 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -145,7 +145,8 @@ void QgsMapLayer::clone( QgsMapLayer *layer ) const

QgsMapLayerType QgsMapLayer::type() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

return mLayerType;
}
Expand Down Expand Up @@ -177,7 +178,8 @@ Qgis::MapLayerProperties QgsMapLayer::properties() const

QString QgsMapLayer::id() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

return mID;
}
Expand All @@ -196,7 +198,8 @@ void QgsMapLayer::setName( const QString &name )

QString QgsMapLayer::name() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

QgsDebugMsgLevel( "returning name '" + mLayerName + '\'', 4 );
return mLayerName;
Expand Down Expand Up @@ -907,7 +910,8 @@ void QgsMapLayer::setMapTipTemplate( const QString &mapTip )

bool QgsMapLayer::isValid() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

return mValid;
}
Expand Down
9 changes: 6 additions & 3 deletions src/core/qgsmaplayerstore.cpp
Expand Up @@ -53,7 +53,8 @@ int QgsMapLayerStore::validCount() const

QgsMapLayer *QgsMapLayerStore::mapLayer( const QString &layerId ) const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

return mMapLayers.value( layerId );
}
Expand Down Expand Up @@ -266,14 +267,16 @@ void QgsMapLayerStore::onMapLayerDeleted( QObject *obj )

QMap<QString, QgsMapLayer *> QgsMapLayerStore::mapLayers() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

return mMapLayers;
}

QMap<QString, QgsMapLayer *> QgsMapLayerStore::validMapLayers() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
// because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL

QMap<QString, QgsMapLayer *> validLayers;
for ( auto it = mMapLayers.constBegin(); it != mMapLayers.constEnd(); it++ )
Expand Down

0 comments on commit 50a157a

Please sign in to comment.