Skip to content
Permalink
Browse files

Make setting point cloud layer data source follow expected behavior

for map layers

Will make it possible to repair point cloud layer sources
  • Loading branch information
nyalldawson committed Oct 26, 2020
1 parent 8fd7cc8 commit 23dfbf8e095a3443752ad46bf6871da989c977be
@@ -39,6 +39,8 @@ Constructor for LayerOptions with optional ``transformContext``.

QgsCoordinateTransformContext transformContext;

bool loadDefaultStyle;

bool skipCrsValidation;
};

@@ -83,6 +85,8 @@ QgsPointCloudLayer cannot be copied.

virtual QString loadDefaultStyle( bool &resultFlag /Out/ );

virtual void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );


private:
QgsPointCloudLayer( const QgsPointCloudLayer &rhs );
@@ -29,19 +29,11 @@ QgsPointCloudLayer::QgsPointCloudLayer( const QString &path,
const QgsPointCloudLayer::LayerOptions &options )
: QgsMapLayer( QgsMapLayerType::PointCloudLayer, baseName, path )
{
Q_UNUSED( options )
bool ok = false;
if ( !path.isEmpty() && !providerLib.isEmpty() )
{
QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
if ( mReadFlags & QgsMapLayer::FlagTrustLayerMetadata )
{
flags |= QgsDataProvider::FlagTrustDataSource;
}
ok = loadDataSource( providerLib, providerOptions, flags );
setDataSource( path, baseName, providerLib, providerOptions, options.loadDefaultStyle );
}
setValid( ok );
}

QgsPointCloudLayer::~QgsPointCloudLayer() = default;
@@ -80,17 +72,15 @@ bool QgsPointCloudLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext
{
// create provider
QDomNode pkeyNode = layerNode.namedItem( QStringLiteral( "provider" ) );
QString providerKey = pkeyNode.toElement().text();
QgsDataProvider::ProviderOptions providerOptions { context.transformContext() };
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
if ( mReadFlags & QgsMapLayer::FlagTrustLayerMetadata )
mProviderKey = pkeyNode.toElement().text();

if ( !( mReadFlags & QgsMapLayer::FlagDontResolveLayers ) )
{
flags |= QgsDataProvider::FlagTrustDataSource;
QgsDataProvider::ProviderOptions providerOptions { context.transformContext() };
setDataSource( mDataSource, mLayerName, mProviderKey, providerOptions, false );
}
// TODO: support QgsMapLayer::FlagDontResolveLayers ?
bool ok = loadDataSource( providerKey, providerOptions, flags );
setValid( ok );
if ( !ok )

if ( !isValid() )
{
return false;
}
@@ -156,17 +146,30 @@ QString QgsPointCloudLayer::loadDefaultStyle( bool &resultFlag )
return QString();
}


bool QgsPointCloudLayer::loadDataSource( const QString &providerLib, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
void QgsPointCloudLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag )
{
QString dataSource = mDataSource;
mProviderKey = providerLib;
Q_UNUSED( loadDefaultStyleFlag )

if ( mDataProvider )
disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );

setName( baseName );
mProviderKey = provider;
mDataSource = dataSource;

mDataProvider.reset( qobject_cast<QgsPointCloudDataProvider *>( QgsProviderRegistry::instance()->createProvider( providerLib, dataSource, options, flags ) ) );
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
if ( mReadFlags & QgsMapLayer::FlagTrustLayerMetadata )
{
flags |= QgsDataProvider::FlagTrustDataSource;
}

mDataProvider.reset( qobject_cast<QgsPointCloudDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource, options, flags ) ) );
if ( !mDataProvider )
{
QgsDebugMsgLevel( QStringLiteral( "Unable to get point cloud data provider" ), 2 );
return false;
QgsDebugMsg( QStringLiteral( "Unable to get point cloud data provider" ) );
setValid( false );
emit dataSourceChanged();
return;
}

mDataProvider->setParent( this );
@@ -175,13 +178,15 @@ bool QgsPointCloudLayer::loadDataSource( const QString &providerLib, const QgsDa
setValid( mDataProvider->isValid() );
if ( !isValid() )
{
QgsDebugMsgLevel( QStringLiteral( "Invalid point cloud provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ), 2 );
return false;
QgsDebugMsg( QStringLiteral( "Invalid point cloud provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ) );
emit dataSourceChanged();
return;
}

setCrs( mDataProvider->crs() );

connect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );

return true;
emit dataSourceChanged();
triggerRepaint();
}
@@ -54,8 +54,14 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer
: transformContext( transformContext )
{}

/**
* Coordinate transform context
*/
QgsCoordinateTransformContext transformContext;

//! Set to TRUE if the default layer style should be loaded
bool loadDefaultStyle = true;

/**
* Controls whether the layer is allowed to have an invalid/unknown CRS.
*
@@ -105,13 +111,10 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer

void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
QString loadDefaultStyle( bool &resultFlag SIP_OUT ) override;
void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false ) override;

private:
bool loadDataSource( const QString &providerLib, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );

/**
* Returns TRUE if the provider is in read-only mode
*/
bool isReadOnly() const override {return true;}

#ifdef SIP_RUN

0 comments on commit 23dfbf8

Please sign in to comment.
You can’t perform that action at this time.