Populate 3D symbol registry, and use to create symbols

This commit is contained in:
Nyall Dawson 2020-07-15 12:49:50 +10:00
parent c7b6a115df
commit 0528fe284c
13 changed files with 82 additions and 21 deletions

View File

@ -30,6 +30,13 @@ class QgsLine3DSymbol : QgsAbstract3DSymbol
QgsLine3DSymbol();
%Docstring
Constructor for QgsLine3DSymbol
%End
static QgsAbstract3DSymbol *create() /Factory/;
%Docstring
Creates a new QgsLine3DSymbol.
Caller takes ownership of the returned symbol.
%End
virtual QString type() const;

View File

@ -35,6 +35,13 @@ Constructor for QgsPoint3DSymbol with default QgsMarkerSymbol as the billboardSy
QgsPoint3DSymbol( const QgsPoint3DSymbol &other );
%Docstring
Copy Constructor for QgsPoint3DSymbol
%End
static QgsAbstract3DSymbol *create() /Factory/;
%Docstring
Creates a new QgsPoint3DSymbol.
Caller takes ownership of the returned symbol.
%End
virtual QString type() const;

View File

@ -41,6 +41,13 @@ Constructor for QgsPolygon3DSymbol
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
static QgsAbstract3DSymbol *create() /Factory/;
%Docstring
Creates a new QgsPolygon3DSymbol.
Caller takes ownership of the returned symbol.
%End
Qgs3DTypes::AltitudeClamping altitudeClamping() const;
%Docstring
Returns method that determines altitude (whether to clamp to feature to terrain)

View File

@ -25,6 +25,10 @@
#include "qgsrulebased3drenderer.h"
#include "qgsvectorlayer3drenderer.h"
#include "qgsmeshlayer3drenderer.h"
#include "qgs3dsymbolregistry.h"
#include "qgspoint3dsymbol.h"
#include "qgsline3dsymbol.h"
#include "qgspolygon3dsymbol.h"
Qgs3D *Qgs3D::instance()
{
@ -46,6 +50,14 @@ void Qgs3D::initialize()
QgsApplication::renderer3DRegistry()->addRenderer( new QgsVectorLayer3DRendererMetadata );
QgsApplication::renderer3DRegistry()->addRenderer( new QgsRuleBased3DRendererMetadata );
QgsApplication::renderer3DRegistry()->addRenderer( new QgsMeshLayer3DRendererMetadata );
QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "point" ), QObject::tr( "Point" ),
&QgsPoint3DSymbol::create ) );
QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "line" ), QObject::tr( "Line" ),
&QgsLine3DSymbol::create ) );
QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ),
&QgsPolygon3DSymbol::create ) );
}
Qgs3D::Qgs3D()

View File

@ -28,6 +28,8 @@
#include "qgspolygon3dsymbol_p.h"
#include "qgsrulebasedchunkloader_p.h"
#include "qgsapplication.h"
#include "qgs3dsymbolregistry.h"
QgsRuleBased3DRendererMetadata::QgsRuleBased3DRendererMetadata()
: Qgs3DRendererAbstractMetadata( QStringLiteral( "rulebased" ) )
@ -185,13 +187,7 @@ QgsRuleBased3DRenderer::Rule *QgsRuleBased3DRenderer::Rule::create( const QDomEl
if ( !elemSymbol.isNull() )
{
QString symbolType = elemSymbol.attribute( QStringLiteral( "type" ) );
if ( symbolType == QLatin1String( "polygon" ) )
symbol = new QgsPolygon3DSymbol;
else if ( symbolType == QLatin1String( "point" ) )
symbol = new QgsPoint3DSymbol;
else if ( symbolType == QLatin1String( "line" ) )
symbol = new QgsLine3DSymbol;
symbol = QgsApplication::symbol3DRegistry()->createSymbol( symbolType );
if ( symbol )
symbol->readXml( elemSymbol, context );
}

View File

@ -17,13 +17,12 @@
#include "qgs3dutils.h"
#include "qgschunkedentity_p.h"
#include "qgsline3dsymbol.h"
#include "qgspoint3dsymbol.h"
#include "qgspolygon3dsymbol.h"
#include "qgsvectorlayerchunkloader_p.h"
#include "qgsvectorlayer.h"
#include "qgsxmlutils.h"
#include "qgsapplication.h"
#include "qgs3dsymbolregistry.h"
QgsVectorLayer3DRendererMetadata::QgsVectorLayer3DRendererMetadata()
@ -98,15 +97,7 @@ void QgsVectorLayer3DRenderer::readXml( const QDomElement &elem, const QgsReadWr
QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
QString symbolType = elemSymbol.attribute( QStringLiteral( "type" ) );
QgsAbstract3DSymbol *symbol = nullptr;
if ( symbolType == QLatin1String( "polygon" ) )
symbol = new QgsPolygon3DSymbol;
else if ( symbolType == QLatin1String( "point" ) )
symbol = new QgsPoint3DSymbol;
else if ( symbolType == QLatin1String( "line" ) )
symbol = new QgsLine3DSymbol;
if ( symbol )
symbol->readXml( elemSymbol, context );
mSymbol.reset( symbol );
mSymbol.reset( QgsApplication::symbol3DRegistry()->createSymbol( symbolType ) );
if ( mSymbol )
mSymbol->readXml( elemSymbol, context );
}

View File

@ -57,3 +57,8 @@ void QgsLine3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex
QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
mMaterial.readXml( elemMaterial );
}
QgsAbstract3DSymbol *QgsLine3DSymbol::create()
{
return new QgsLine3DSymbol();
}

View File

@ -38,6 +38,13 @@ class _3D_EXPORT QgsLine3DSymbol : public QgsAbstract3DSymbol
//! Constructor for QgsLine3DSymbol
QgsLine3DSymbol() = default;
/**
* Creates a new QgsLine3DSymbol.
*
* Caller takes ownership of the returned symbol.
*/
static QgsAbstract3DSymbol *create() SIP_FACTORY;
QString type() const override { return "line"; }
QgsAbstract3DSymbol *clone() const override SIP_FACTORY;

View File

@ -26,6 +26,11 @@ QgsAbstract3DSymbol *QgsPoint3DSymbol::clone() const
return new QgsPoint3DSymbol( *this );
}
QgsAbstract3DSymbol *QgsPoint3DSymbol::create()
{
return new QgsPoint3DSymbol();
}
QgsPoint3DSymbol::QgsPoint3DSymbol()
{
setBillboardSymbol( static_cast<QgsMarkerSymbol *>( QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ) ) );

View File

@ -43,6 +43,13 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol
//! Copy Constructor for QgsPoint3DSymbol
QgsPoint3DSymbol( const QgsPoint3DSymbol &other );
/**
* Creates a new QgsPoint3DSymbol.
*
* Caller takes ownership of the returned symbol.
*/
static QgsAbstract3DSymbol *create() SIP_FACTORY;
QString type() const override { return "point"; }
QgsAbstract3DSymbol *clone() const override SIP_FACTORY;

View File

@ -84,3 +84,8 @@ void QgsPolygon3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteCon
mEdgeColor = QgsSymbolLayerUtils::decodeColor( elemEdges.attribute( QStringLiteral( "color" ) ) );
}
}
QgsAbstract3DSymbol *QgsPolygon3DSymbol::create()
{
return new QgsPolygon3DSymbol();
}

View File

@ -45,6 +45,13 @@ class _3D_EXPORT QgsPolygon3DSymbol : public QgsAbstract3DSymbol
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
/**
* Creates a new QgsPolygon3DSymbol.
*
* Caller takes ownership of the returned symbol.
*/
static QgsAbstract3DSymbol *create() SIP_FACTORY;
//! Returns method that determines altitude (whether to clamp to feature to terrain)
Qgs3DTypes::AltitudeClamping altitudeClamping() const { return mAltClamping; }
//! Sets method that determines altitude (whether to clamp to feature to terrain)

View File

@ -20,6 +20,7 @@
#include <QObject>
#include "qgstest.h"
#include "qgs3d.h"
//dummy symbol for testing
class Dummy3DSymbol : public QgsAbstract3DSymbol
@ -101,6 +102,10 @@ void TestQgs3DSymbolRegistry::instanceHasDefaultSymbols()
//check that symbol registry is initially populated with some symbols
//(assumes that there is some default symbols)
Qgs3DSymbolRegistry *registry = QgsApplication::symbol3DRegistry();
// should be empty until initialized
QVERIFY( registry->symbolTypes().empty() );
Qgs3D::initialize();
QVERIFY( registry->symbolTypes().length() > 0 );
}