Skip to content
Permalink
Browse files

Move method to create default 3d symbol for a geometry type to 3d sym…

…bol registry
  • Loading branch information
nyalldawson committed Jul 22, 2020
1 parent 0528fe2 commit 80e5d165119aa393f71930a91be77f7dcb2615a2
@@ -101,6 +101,13 @@ Creates a new instance of a symbol of the specified ``type``.
The caller takes ownership of the returned symbol.

Returns ``None`` if the specified type is not found in the registry.
%End

QgsAbstract3DSymbol *defaultSymbolForGeometryType( QgsWkbTypes::GeometryType type ) /Factory/;
%Docstring
Creates a new instance of the default 3D symbol for the specified geometry ``type``.

The caller takes ownership of the returned symbol.
%End

private:
@@ -548,21 +548,6 @@ void Qgs3DUtils::estimateVectorLayerZRange( QgsVectorLayer *layer, double &zMin,
}
}

std::unique_ptr<QgsAbstract3DSymbol> Qgs3DUtils::symbolForGeometryType( QgsWkbTypes::GeometryType geomType )
{
switch ( geomType )
{
case QgsWkbTypes::PointGeometry:
return std::unique_ptr<QgsAbstract3DSymbol>( new QgsPoint3DSymbol );
case QgsWkbTypes::LineGeometry:
return std::unique_ptr<QgsAbstract3DSymbol>( new QgsLine3DSymbol );
case QgsWkbTypes::PolygonGeometry:
return std::unique_ptr<QgsAbstract3DSymbol>( new QgsPolygon3DSymbol );
default:
return nullptr;
}
}

QgsExpressionContext Qgs3DUtils::globalProjectLayerExpressionContext( QgsVectorLayer *layer )
{
QgsExpressionContext exprContext;
@@ -169,9 +169,6 @@ class _3D_EXPORT Qgs3DUtils
*/
static void estimateVectorLayerZRange( QgsVectorLayer *layer, double &zMin, double &zMax );

//! Returns a new 3D symbol based on given geometry type (or NULLPTR if geometry type is not supported)
static std::unique_ptr<QgsAbstract3DSymbol> symbolForGeometryType( QgsWkbTypes::GeometryType geomType );

//! Returns expression context for use in preparation of 3D data of a layer
static QgsExpressionContext globalProjectLayerExpressionContext( QgsVectorLayer *layer );

@@ -22,6 +22,7 @@
#include "qgsvectorlayer.h"
#include "qgssymbol3dwidget.h"
#include "qgsapplication.h"
#include "qgs3dsymbolregistry.h"

#include <QAction>
#include <QClipboard>
@@ -106,7 +107,7 @@ void QgsRuleBased3DRendererWidget::setDockMode( bool dockMode )

void QgsRuleBased3DRendererWidget::addRule()
{
QgsRuleBased3DRenderer::Rule *newrule = new QgsRuleBased3DRenderer::Rule( Qgs3DUtils::symbolForGeometryType( mLayer->geometryType() ).release() );
QgsRuleBased3DRenderer::Rule *newrule = new QgsRuleBased3DRenderer::Rule( QgsApplication::symbol3DRegistry()->defaultSymbolForGeometryType( mLayer->geometryType() ) );

QgsRuleBased3DRenderer::Rule *current = currentRule();
if ( current )
@@ -568,7 +569,7 @@ Qgs3DRendererRulePropsWidget::Qgs3DRendererRulePropsWidget( QgsRuleBased3DRender
else
{
groupSymbol->setChecked( false );
mSymbol = Qgs3DUtils::symbolForGeometryType( layer->geometryType() );
mSymbol.reset( QgsApplication::symbol3DRegistry()->defaultSymbolForGeometryType( layer->geometryType() ) );
}

mSymbolWidget = new QgsSymbol3DWidget( this );
@@ -23,6 +23,7 @@
#include "qgsvectorlayer3dpropertieswidget.h"
#include "qgsvectorlayer3drenderer.h"
#include "qgsapplication.h"
#include "qgs3dsymbolregistry.h"

#include <QBoxLayout>
#include <QCheckBox>
@@ -55,7 +56,7 @@ void QgsSingleSymbol3DRendererWidget::setLayer( QgsVectorLayer *layer )
}
else
{
std::unique_ptr<QgsAbstract3DSymbol> sym( Qgs3DUtils::symbolForGeometryType( layer->geometryType() ) );
std::unique_ptr<QgsAbstract3DSymbol> sym( QgsApplication::symbol3DRegistry()->defaultSymbolForGeometryType( layer->geometryType() ) );
widgetSymbol->setSymbol( sym.get(), layer );
}
}
@@ -41,6 +41,21 @@ QgsAbstract3DSymbol *Qgs3DSymbolRegistry::createSymbol( const QString &type ) co
return mMetadata[type]->create();
}

QgsAbstract3DSymbol *Qgs3DSymbolRegistry::defaultSymbolForGeometryType( QgsWkbTypes::GeometryType type )
{
switch ( type )
{
case QgsWkbTypes::PointGeometry:
return createSymbol( QStringLiteral( "point" ) );
case QgsWkbTypes::LineGeometry:
return createSymbol( QStringLiteral( "line" ) );
case QgsWkbTypes::PolygonGeometry:
return createSymbol( QStringLiteral( "polygon" ) );
default:
return nullptr;
}
}

Qgs3DSymbolAbstractMetadata *Qgs3DSymbolRegistry::symbolMetadata( const QString &type ) const
{
return mMetadata.value( type );
@@ -18,6 +18,7 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgswkbtypes.h"

#include <QDomElement>
#include <QMap>
@@ -189,6 +190,13 @@ class CORE_EXPORT Qgs3DSymbolRegistry
*/
QgsAbstract3DSymbol *createSymbol( const QString &type ) const SIP_FACTORY;

/**
* Creates a new instance of the default 3D symbol for the specified geometry \a type.
*
* The caller takes ownership of the returned symbol.
*/
QgsAbstract3DSymbol *defaultSymbolForGeometryType( QgsWkbTypes::GeometryType type ) SIP_FACTORY;

private:
#ifdef SIP_RUN
Qgs3DSymbolRegistry( const Qgs3DSymbolRegistry &rh );
@@ -51,6 +51,7 @@ class TestQgs3DSymbolRegistry : public QObject
void addSymbol();
void fetchTypes();
void createSymbol();
void defaultSymbolForGeometryType();

private:

@@ -156,5 +157,18 @@ void TestQgs3DSymbolRegistry::createSymbol()
QVERIFY( !symbol.get() );
}

void TestQgs3DSymbolRegistry::defaultSymbolForGeometryType()
{
Qgs3DSymbolRegistry *registry = QgsApplication::symbol3DRegistry();
std::unique_ptr< QgsAbstract3DSymbol > symbol( registry->defaultSymbolForGeometryType( QgsWkbTypes::PointGeometry ) );
QCOMPARE( symbol->type(), QStringLiteral( "point" ) );
symbol.reset( registry->defaultSymbolForGeometryType( QgsWkbTypes::LineGeometry ) );
QCOMPARE( symbol->type(), QStringLiteral( "line" ) );
symbol.reset( registry->defaultSymbolForGeometryType( QgsWkbTypes::PolygonGeometry ) );
QCOMPARE( symbol->type(), QStringLiteral( "polygon" ) );
symbol.reset( registry->defaultSymbolForGeometryType( QgsWkbTypes::NullGeometry ) );
QVERIFY( !symbol );
}

QGSTEST_MAIN( TestQgs3DSymbolRegistry )
#include "testqgs3dsymbolregistry.moc"

0 comments on commit 80e5d16

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