Skip to content
Permalink
Browse files

Move feature handler creation responsibility to 3d symbol registry

  • Loading branch information
nyalldawson committed Jul 22, 2020
1 parent 80e5d16 commit c3837359d6dcc85472996c7f808d0c372170f1ca
@@ -59,6 +59,7 @@ Caller takes ownership of the returned symbol.




class Qgs3DSymbolRegistry
{
%Docstring
@@ -110,6 +111,7 @@ Creates a new instance of the default 3D symbol for the specified geometry ``typ
The caller takes ownership of the returned symbol.
%End


private:
Qgs3DSymbolRegistry( const Qgs3DSymbolRegistry &rh );
};
@@ -30,6 +30,10 @@
#include "qgsline3dsymbol.h"
#include "qgspolygon3dsymbol.h"

#include "qgspolygon3dsymbol_p.h"
#include "qgspoint3dsymbol_p.h"
#include "qgsline3dsymbol_p.h"

Qgs3D *Qgs3D::instance()
{
static Qgs3D *sInstance( new Qgs3D() );
@@ -52,12 +56,11 @@ void Qgs3D::initialize()
QgsApplication::renderer3DRegistry()->addRenderer( new QgsMeshLayer3DRendererMetadata );

QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "point" ), QObject::tr( "Point" ),
&QgsPoint3DSymbol::create ) );
&QgsPoint3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForPoint3DSymbol ) );
QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "line" ), QObject::tr( "Line" ),
&QgsLine3DSymbol::create ) );
&QgsLine3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForLine3DSymbol ) );
QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ),
&QgsPolygon3DSymbol::create ) );

&QgsPolygon3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForPolygon3DSymbol ) );
}

Qgs3D::Qgs3D()
@@ -23,9 +23,6 @@
#include "qgsline3dsymbol.h"
#include "qgspoint3dsymbol.h"
#include "qgspolygon3dsymbol.h"
#include "qgsline3dsymbol_p.h"
#include "qgspoint3dsymbol_p.h"
#include "qgspolygon3dsymbol_p.h"

#include "qgsrulebasedchunkloader_p.h"
#include "qgsapplication.h"
@@ -255,20 +252,7 @@ void QgsRuleBased3DRenderer::Rule::createHandlers( QgsVectorLayer *layer, QgsRul
{
// add handler!
Q_ASSERT( !handlers.value( this ) );
QgsFeature3DHandler *handler = nullptr;
if ( mSymbol->type() == QLatin1String( "polygon" ) )
{
handler = Qgs3DSymbolImpl::handlerForPolygon3DSymbol( layer, *static_cast<QgsPolygon3DSymbol *>( mSymbol.get() ) );
}
else if ( mSymbol->type() == QLatin1String( "point" ) )
{
handler = Qgs3DSymbolImpl::handlerForPoint3DSymbol( layer, *static_cast<QgsPoint3DSymbol *>( mSymbol.get() ) );
}
else if ( mSymbol->type() == QLatin1String( "line" ) )
{
handler = Qgs3DSymbolImpl::handlerForLine3DSymbol( layer, *static_cast<QgsLine3DSymbol *>( mSymbol.get() ) );
}

QgsFeature3DHandler *handler = QgsApplication::symbol3DRegistry()->createHandlerForSymbol( layer, mSymbol.get() );
if ( handler )
handlers[this] = handler;
}
@@ -28,9 +28,8 @@
#include "qgspoint3dsymbol.h"
#include "qgspolygon3dsymbol.h"

#include "qgsline3dsymbol_p.h"
#include "qgspoint3dsymbol_p.h"
#include "qgspolygon3dsymbol_p.h"
#include "qgsapplication.h"
#include "qgs3dsymbolregistry.h"

#include <QtConcurrent>

@@ -52,17 +51,10 @@ QgsVectorLayerChunkLoader::QgsVectorLayerChunkLoader( const QgsVectorLayerChunkL
QgsVectorLayer *layer = mFactory->mLayer;
const Qgs3DMapSettings &map = mFactory->mMap;

QgsFeature3DHandler *handler = nullptr;
QString symbolType = mFactory->mSymbol->type();
if ( symbolType == QLatin1String( "polygon" ) )
handler = Qgs3DSymbolImpl::handlerForPolygon3DSymbol( layer, *static_cast<QgsPolygon3DSymbol *>( mFactory->mSymbol.get() ) );
else if ( symbolType == QLatin1String( "point" ) )
handler = Qgs3DSymbolImpl::handlerForPoint3DSymbol( layer, *static_cast<QgsPoint3DSymbol *>( mFactory->mSymbol.get() ) );
else if ( symbolType == QLatin1String( "line" ) )
handler = Qgs3DSymbolImpl::handlerForLine3DSymbol( layer, *static_cast<QgsLine3DSymbol *>( mFactory->mSymbol.get() ) );
else
QgsFeature3DHandler *handler = QgsApplication::symbol3DRegistry()->createHandlerForSymbol( layer, mFactory->mSymbol.get() );
if ( !handler )
{
QgsDebugMsg( QStringLiteral( "Unknown 3D symbol type for vector layer: " ) + symbolType );
QgsDebugMsg( QStringLiteral( "Unknown 3D symbol type for vector layer: " ) + mFactory->mSymbol->type() );
return;
}
mHandler.reset( handler );
@@ -433,18 +433,22 @@ void QgsThickLine3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const Q
namespace Qgs3DSymbolImpl
{

QgsFeature3DHandler *handlerForLine3DSymbol( QgsVectorLayer *layer, const QgsLine3DSymbol &symbol )
QgsFeature3DHandler *handlerForLine3DSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol )
{
if ( symbol.renderAsSimpleLines() )
return new QgsThickLine3DSymbolHandler( symbol, layer->selectedFeatureIds() );
const QgsLine3DSymbol *lineSymbol = dynamic_cast< const QgsLine3DSymbol * >( symbol );
if ( !lineSymbol )
return nullptr;

if ( lineSymbol->renderAsSimpleLines() )
return new QgsThickLine3DSymbolHandler( *lineSymbol, layer->selectedFeatureIds() );
//return new QgsSimpleLine3DSymbolHandler( symbol, layer->selectedFeatureIds() );
else
return new QgsBufferedLine3DSymbolHandler( symbol, layer->selectedFeatureIds() );
return new QgsBufferedLine3DSymbolHandler( *lineSymbol, layer->selectedFeatureIds() );
}

Qt3DCore::QEntity *entityForLine3DSymbol( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsLine3DSymbol &symbol )
{
QgsFeature3DHandler *handler = handlerForLine3DSymbol( layer, symbol );
QgsFeature3DHandler *handler = handlerForLine3DSymbol( layer, &symbol );
Qt3DCore::QEntity *e = entityFromHandler( handler, map, layer );
delete handler;
return e;
@@ -32,11 +32,12 @@
#include "qgsfeature3dhandler_p.h"

class QgsLine3DSymbol;
class QgsAbstract3DSymbol;

namespace Qgs3DSymbolImpl
{
//! factory method for QgsLine3DSymbol
QgsFeature3DHandler *handlerForLine3DSymbol( QgsVectorLayer *layer, const QgsLine3DSymbol &symbol );
QgsFeature3DHandler *handlerForLine3DSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol );

//! convenience function to create a complete entity from QgsPolygon3DSymbol (will run getFeatures() on the layer)
Qt3DCore::QEntity *entityForLine3DSymbol( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsLine3DSymbol &symbol );
@@ -615,20 +615,24 @@ void QgsPoint3DBillboardSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, co
namespace Qgs3DSymbolImpl
{

QgsFeature3DHandler *handlerForPoint3DSymbol( QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol )
QgsFeature3DHandler *handlerForPoint3DSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol )
{
if ( symbol.shape() == QgsPoint3DSymbol::Model )
return new QgsModelPoint3DSymbolHandler( symbol, layer->selectedFeatureIds() );
const QgsPoint3DSymbol *pointSymbol = dynamic_cast< const QgsPoint3DSymbol * >( symbol );
if ( !pointSymbol )
return nullptr;

if ( pointSymbol->shape() == QgsPoint3DSymbol::Model )
return new QgsModelPoint3DSymbolHandler( *pointSymbol, layer->selectedFeatureIds() );
// Add proper handler for billboard
else if ( symbol.shape() == QgsPoint3DSymbol::Billboard )
return new QgsPoint3DBillboardSymbolHandler( symbol, layer->selectedFeatureIds() );
else if ( pointSymbol->shape() == QgsPoint3DSymbol::Billboard )
return new QgsPoint3DBillboardSymbolHandler( *pointSymbol, layer->selectedFeatureIds() );
else
return new QgsInstancedPoint3DSymbolHandler( symbol, layer->selectedFeatureIds() );
return new QgsInstancedPoint3DSymbolHandler( *pointSymbol, layer->selectedFeatureIds() );
}

Qt3DCore::QEntity *entityForPoint3DSymbol( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol )
{
QgsFeature3DHandler *handler = handlerForPoint3DSymbol( layer, symbol );
QgsFeature3DHandler *handler = handlerForPoint3DSymbol( layer, &symbol );
Qt3DCore::QEntity *e = entityFromHandler( handler, map, layer );
delete handler;
return e;
@@ -32,11 +32,12 @@
#include "qgsfeature3dhandler_p.h"

class QgsPoint3DSymbol;
class QgsAbstract3DSymbol;

namespace Qgs3DSymbolImpl
{
//! factory method for QgsLine3DSymbol
QgsFeature3DHandler *handlerForPoint3DSymbol( QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol );
QgsFeature3DHandler *handlerForPoint3DSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol );

//! convenience function to create a complete entity from QgsPolygon3DSymbol (will run getFeatures() on the layer)
Qt3DCore::QEntity *entityForPoint3DSymbol( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol );
@@ -371,14 +371,18 @@ namespace Qgs3DSymbolImpl
{


QgsFeature3DHandler *handlerForPolygon3DSymbol( QgsVectorLayer *layer, const QgsPolygon3DSymbol &symbol )
QgsFeature3DHandler *handlerForPolygon3DSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol )
{
return new QgsPolygon3DSymbolHandler( symbol, layer->selectedFeatureIds() );
const QgsPolygon3DSymbol *polygonSymbol = dynamic_cast< const QgsPolygon3DSymbol * >( symbol );
if ( !polygonSymbol )
return nullptr;

return new QgsPolygon3DSymbolHandler( *polygonSymbol, layer->selectedFeatureIds() );
}

Qt3DCore::QEntity *entityForPolygon3DSymbol( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsPolygon3DSymbol &symbol )
{
QgsFeature3DHandler *handler = handlerForPolygon3DSymbol( layer, symbol );
QgsFeature3DHandler *handler = handlerForPolygon3DSymbol( layer, &symbol );
Qt3DCore::QEntity *e = entityFromHandler( handler, map, layer );
delete handler;
return e;
@@ -32,11 +32,12 @@
#include "qgsfeature3dhandler_p.h"

class QgsPolygon3DSymbol;
class QgsAbstract3DSymbol;

namespace Qgs3DSymbolImpl
{
//! factory method for QgsPolygon3DSymbol
QgsFeature3DHandler *handlerForPolygon3DSymbol( QgsVectorLayer *layer, const QgsPolygon3DSymbol &symbol );
QgsFeature3DHandler *handlerForPolygon3DSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol );

//! convenience function to create a complete entity from QgsPolygon3DSymbol (will run getFeatures() on the layer)
Qt3DCore::QEntity *entityForPolygon3DSymbol( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsPolygon3DSymbol &symbol );
@@ -14,6 +14,7 @@
***************************************************************************/

#include "qgs3dsymbolregistry.h"
#include "qgsabstract3dsymbol.h"

Qgs3DSymbolRegistry::Qgs3DSymbolRegistry()
{
@@ -56,6 +57,17 @@ QgsAbstract3DSymbol *Qgs3DSymbolRegistry::defaultSymbolForGeometryType( QgsWkbTy
}
}

QgsFeature3DHandler *Qgs3DSymbolRegistry::createHandlerForSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol )
{
if ( !symbol )
return nullptr;

if ( !mMetadata.contains( symbol->type() ) )
return nullptr;

return mMetadata.value( symbol->type() )->createFeatureHandler( layer, symbol );
}

Qgs3DSymbolAbstractMetadata *Qgs3DSymbolRegistry::symbolMetadata( const QString &type ) const
{
return mMetadata.value( type );
@@ -27,6 +27,7 @@ class QgsAbstract3DSymbol;
class QgsReadWriteContext;
class Qgs3DSymbolWidget;
class QgsVectorLayer;
class QgsFeature3DHandler;

/**
* \ingroup core
@@ -78,6 +79,15 @@ class CORE_EXPORT Qgs3DSymbolAbstractMetadata
* \note Not available in Python bindings
*/
virtual Qgs3DSymbolWidget *createSymbolWidget( QgsVectorLayer * ) SIP_FACTORY { return nullptr; }

/**
* Creates a feature handler for a \a symbol of matching type, for the specified vector \a layer.
*
* Caller takes ownership of the returned handler.
*
* \note Not available in Python bindings
*/
virtual QgsFeature3DHandler *createFeatureHandler( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol ) SIP_FACTORY { Q_UNUSED( layer ); Q_UNUSED( symbol ); return nullptr; }
#endif

private:
@@ -88,6 +98,9 @@ class CORE_EXPORT Qgs3DSymbolAbstractMetadata
//! 3D symbol creation function
typedef QgsAbstract3DSymbol *( *Qgs3DSymbolCreateFunc )() SIP_SKIP;

//! 3D symbol widget creation function
typedef QgsFeature3DHandler *( *Qgs3DSymbolFeatureHandlerFunc )( QgsVectorLayer *, const QgsAbstract3DSymbol * ) SIP_SKIP;

//! 3D symbol widget creation function
typedef Qgs3DSymbolWidget *( *Qgs3DSymbolWidgetFunc )( QgsVectorLayer * ) SIP_SKIP;

@@ -108,15 +121,17 @@ class CORE_EXPORT Qgs3DSymbolMetadata : public Qgs3DSymbolAbstractMetadata
/**
* Constructor for Qgs3DSymbolMetadata, with the specified \a type and \a visibleName.
*
* The \a pfCreate and \a pfWidget arguments are used to specify
* The \a pfCreate, \a pfWidget and \a pfHandler arguments are used to specify
* static functions for creating the symbol type and configuration widget.
*/
Qgs3DSymbolMetadata( const QString &type, const QString &visibleName,
Qgs3DSymbolCreateFunc pfCreate,
Qgs3DSymbolWidgetFunc pfWidget = nullptr ) SIP_SKIP
Qgs3DSymbolWidgetFunc pfWidget = nullptr,
Qgs3DSymbolFeatureHandlerFunc pfHandler = nullptr ) SIP_SKIP
: Qgs3DSymbolAbstractMetadata( type, visibleName )
, mCreateFunc( pfCreate )
, mWidgetFunc( pfWidget )
, mFeatureHandlerFunc( pfHandler )
{}

/**
@@ -138,12 +153,19 @@ class CORE_EXPORT Qgs3DSymbolMetadata : public Qgs3DSymbolAbstractMetadata
*/
void setWidgetFunction( Qgs3DSymbolWidgetFunc function ) { mWidgetFunc = function; }

/**
* Sets the symbol type's feature handler creation \a function.
*/
void setFeatureHandlerFunction( Qgs3DSymbolFeatureHandlerFunc function ) { mFeatureHandlerFunc = function; }

QgsAbstract3DSymbol *create() override SIP_FACTORY { return mCreateFunc ? mCreateFunc() : nullptr; }
Qgs3DSymbolWidget *createSymbolWidget( QgsVectorLayer *vl ) override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc( vl ) : nullptr; }
QgsFeature3DHandler *createFeatureHandler( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol ) override SIP_FACTORY { return mFeatureHandlerFunc ? mFeatureHandlerFunc( layer, symbol ) : nullptr; }

private:
Qgs3DSymbolCreateFunc mCreateFunc;
Qgs3DSymbolWidgetFunc mWidgetFunc;
Qgs3DSymbolFeatureHandlerFunc mFeatureHandlerFunc;

};
#endif
@@ -197,6 +219,18 @@ class CORE_EXPORT Qgs3DSymbolRegistry
*/
QgsAbstract3DSymbol *defaultSymbolForGeometryType( QgsWkbTypes::GeometryType type ) SIP_FACTORY;

#ifndef SIP_RUN

/**
* Creates a feature handler for a \a symbol, for the specified vector \a layer.
*
* Caller takes ownership of the returned handler.
*
* \note Not available in Python bindings
*/
QgsFeature3DHandler *createHandlerForSymbol( QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol ) SIP_FACTORY;
#endif

private:
#ifdef SIP_RUN
Qgs3DSymbolRegistry( const Qgs3DSymbolRegistry &rh );

0 comments on commit c383735

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