Skip to content
Permalink
Browse files

Hookup API for point cloud data providers to create default renderers…

… for associated layers
  • Loading branch information
nyalldawson committed Nov 12, 2020
1 parent c2fe0d3 commit 0169347f5be406431d65f65ce17de6abb7ffadba
@@ -28,6 +28,18 @@ Responsible for reading native point cloud data and returning the indexed data.
#include "qgspointclouddataprovider.h"
%End
public:

enum Capability
{
NoCapabilities,
ReadLayerMetadata,
WriteLayerMetadata,
CreateRenderer,
};

typedef QFlags<QgsPointCloudDataProvider::Capability> Capabilities;


QgsPointCloudDataProvider( const QString &uri,
const QgsDataProvider::ProviderOptions &providerOptions,
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
@@ -37,11 +49,32 @@ Ctor

~QgsPointCloudDataProvider();

virtual QgsPointCloudDataProvider::Capabilities capabilities() const;
%Docstring
Returns flags containing the supported capabilities for the data provider.
%End

virtual QgsPointCloudAttributeCollection attributes() const = 0;
%Docstring
Returns the attributes available from this data provider.
%End


virtual QgsPointCloudRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const /Factory/;
%Docstring
Creates a new 2D point cloud renderer, using provider backend specific information.

The ``configuration`` map can be used to pass provider-specific configuration maps to the provider to
allow customization of the returned renderer. Support and format of ``configuration`` varies by provider.

When called with an empty ``configuration`` map the provider's default renderer will be returned.

This method returns a new renderer and the caller takes ownership of the returned object.

Only providers which report the CreateRenderer capability will return a 2D renderer. Other
providers will return ``None``.
%End

};

/************************************************************************
@@ -11,6 +11,7 @@




class QgsPointCloudLayer : QgsMapLayer
{
%Docstring
@@ -91,6 +92,8 @@ QgsPointCloudLayer cannot be copied.

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

virtual QString loadDefaultStyle( bool &resultFlag /Out/ ) ${SIP_FINAL};

virtual QString htmlMetadata() const;


@@ -29,3 +29,12 @@ QgsPointCloudDataProvider::QgsPointCloudDataProvider(

QgsPointCloudDataProvider::~QgsPointCloudDataProvider() = default;

QgsPointCloudDataProvider::Capabilities QgsPointCloudDataProvider::capabilities() const
{
return QgsPointCloudDataProvider::NoCapabilities;
}

QgsPointCloudRenderer *QgsPointCloudDataProvider::createRenderer( const QVariantMap & ) const
{
return nullptr;
}
@@ -24,6 +24,7 @@
#include <memory>

class QgsPointCloudIndex;
class QgsPointCloudRenderer;

/**
* \ingroup core
@@ -39,13 +40,32 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
{
Q_OBJECT
public:

/**
* Capabilities that providers may implement.
*/
enum Capability
{
NoCapabilities = 0, //!< Provider has no capabilities
ReadLayerMetadata = 1 << 0, //!< Provider can read layer metadata from data store.
WriteLayerMetadata = 1 << 1, //!< Provider can write layer metadata to the data store. See QgsDataProvider::writeLayerMetadata()
CreateRenderer = 1 << 2, //!< Provider can create 2D renderers using backend-specific formatting information. See QgsPointCloudDataProvider::createRenderer().
};

Q_DECLARE_FLAGS( Capabilities, Capability )

//! Ctor
QgsPointCloudDataProvider( const QString &uri,
const QgsDataProvider::ProviderOptions &providerOptions,
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );

~QgsPointCloudDataProvider() override;

/**
* Returns flags containing the supported capabilities for the data provider.
*/
virtual QgsPointCloudDataProvider::Capabilities capabilities() const;

/**
* Returns the attributes available from this data provider.
*/
@@ -59,6 +79,22 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
* \note Not available in Python bindings
*/
virtual QgsPointCloudIndex *index() const SIP_SKIP {return nullptr;}

/**
* Creates a new 2D point cloud renderer, using provider backend specific information.
*
* The \a configuration map can be used to pass provider-specific configuration maps to the provider to
* allow customization of the returned renderer. Support and format of \a configuration varies by provider.
*
* When called with an empty \a configuration map the provider's default renderer will be returned.
*
* This method returns a new renderer and the caller takes ownership of the returned object.
*
* Only providers which report the CreateRenderer capability will return a 2D renderer. Other
* providers will return NULLPTR.
*/
virtual QgsPointCloudRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;

};

#endif // QGSMESHDATAPROVIDER_H
@@ -24,6 +24,8 @@
#include "qgslogger.h"
#include "qgslayermetadataformatter.h"
#include "qgspointcloudrenderer.h"
#include "qgsruntimeprofiler.h"
#include "qgsapplication.h"

QgsPointCloudLayer::QgsPointCloudLayer( const QString &path,
const QString &baseName,
@@ -220,6 +222,17 @@ void QgsPointCloudLayer::setDataSource( const QString &dataSource, const QString

bool defaultLoadedFlag = false;

if ( loadDefaultStyleFlag && isSpatial() && mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
{
// first try to create a renderer directly from the data provider
std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
if ( defaultRenderer )
{
defaultLoadedFlag = true;
setRenderer( defaultRenderer.release() );
}
}

if ( !defaultLoadedFlag && loadDefaultStyleFlag )
{
loadDefaultStyle( defaultLoadedFlag );
@@ -238,6 +251,23 @@ void QgsPointCloudLayer::setDataSource( const QString &dataSource, const QString
triggerRepaint();
}

QString QgsPointCloudLayer::loadDefaultStyle( bool &resultFlag )
{
if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
{
// first try to create a renderer directly from the data provider
std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
if ( defaultRenderer )
{
resultFlag = true;
setRenderer( defaultRenderer.release() );
return QString();
}
}

return QgsMapLayer::loadDefaultStyle( resultFlag );
}

QString QgsPointCloudLayer::htmlMetadata() const
{
QgsLayerMetadataFormatter htmlFormatter( metadata() );
@@ -121,6 +121,7 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer

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

/**

0 comments on commit 0169347

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