Merge pull request #31863 from m-kuhn/gapCheckIgnoreMissingLayer

Gap check ignore missing layer
This commit is contained in:
Matthias Kuhn 2019-09-20 18:49:38 +02:00 committed by GitHub
commit ff4f32db0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 7 deletions

View File

@ -1398,6 +1398,14 @@ Sets the coordinate transform context to ``transformContext``
signals:
void beforeResolveReferences( QgsProject *project );
%Docstring
Emitted when all layers are loaded and references can be resolved,
just before the references of this layer are resolved.
.. versionadded:: 3.10
%End
void statusChanged( const QString &status );
%Docstring
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)

View File

@ -37,10 +37,13 @@ void QgsGeometryGapCheck::prepare( const QgsGeometryCheckContext *context, const
if ( configuration.value( QStringLiteral( "allowedGapsEnabled" ) ).toBool() )
{
QgsVectorLayer *layer = context->project()->mapLayer<QgsVectorLayer *>( configuration.value( "allowedGapsLayer" ).toString() );
mAllowedGapsLayer = layer;
mAllowedGapsSource = qgis::make_unique<QgsVectorLayerFeatureSource>( layer );
if ( layer )
{
mAllowedGapsLayer = layer;
mAllowedGapsSource = qgis::make_unique<QgsVectorLayerFeatureSource>( layer );
mAllowedGapsBuffer = configuration.value( QStringLiteral( "allowedGapsBuffer" ) ).toDouble();
mAllowedGapsBuffer = configuration.value( QStringLiteral( "allowedGapsBuffer" ) ).toDouble();
}
}
else
{

View File

@ -27,6 +27,7 @@ email : matthias@opengis.ch
#include "qgsreadwritelocker.h"
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"
#include "qgsmessagelog.h"
#include <QtConcurrent>
#include <QFutureWatcher>
@ -99,7 +100,10 @@ void QgsGeometryValidationService::onLayersAdded( const QList<QgsMapLayer *> &la
mLayerChecks.remove( vectorLayer );
} );
enableLayerChecks( vectorLayer );
connect( vectorLayer, &QgsMapLayer::beforeResolveReferences, this, [this, vectorLayer]()
{
enableLayerChecks( vectorLayer );
} );
}
}
}
@ -273,9 +277,16 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
if ( checkConfiguration.value( QStringLiteral( "allowedGapsEnabled" ) ).toBool() )
{
QgsVectorLayer *gapsLayer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( checkConfiguration.value( "allowedGapsLayer" ).toString() );
connect( layer, &QgsVectorLayer::editingStarted, gapsLayer, [gapsLayer] { gapsLayer->startEditing(); } );
connect( layer, &QgsVectorLayer::beforeRollBack, gapsLayer, [gapsLayer] { gapsLayer->rollBack(); } );
connect( layer, &QgsVectorLayer::editingStopped, gapsLayer, [gapsLayer] { gapsLayer->commitChanges(); } );
if ( gapsLayer )
{
connect( layer, &QgsVectorLayer::editingStarted, gapsLayer, [gapsLayer] { gapsLayer->startEditing(); } );
connect( layer, &QgsVectorLayer::beforeRollBack, gapsLayer, [gapsLayer] { gapsLayer->rollBack(); } );
connect( layer, &QgsVectorLayer::editingStopped, gapsLayer, [gapsLayer] { gapsLayer->commitChanges(); } );
}
else
{
QgsMessageLog::logMessage( tr( "Allowed gaps layer %1 configured but not loaded. Allowed gaps not working." ).arg( checkConfiguration.value( "allowedGapsLayer" ).toString() ), tr( "Geometry validation" ) );
}
}
}
}

View File

@ -612,6 +612,7 @@ QString QgsMapLayer::decodedSource( const QString &source, const QString &dataPr
void QgsMapLayer::resolveReferences( QgsProject *project )
{
emit beforeResolveReferences( project );
if ( m3DRenderer )
m3DRenderer->resolveReferences( *project );
}

View File

@ -1254,6 +1254,14 @@ class CORE_EXPORT QgsMapLayer : public QObject
signals:
/**
* Emitted when all layers are loaded and references can be resolved,
* just before the references of this layer are resolved.
*
* \since QGIS 3.10
*/
void beforeResolveReferences( QgsProject *project );
//! Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
void statusChanged( const QString &status );