Skip to content

Commit a34eabd

Browse files
committedJul 22, 2020
[api] Add a proper registry for 3D symbol types
1 parent f60b79f commit a34eabd

File tree

10 files changed

+556
-0
lines changed

10 files changed

+556
-0
lines changed
 
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/./3d/qgs3dsymbolregistry.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class Qgs3DSymbolAbstractMetadata
14+
{
15+
%Docstring
16+
Stores metadata about one 3D symbol class.
17+
18+
.. note::
19+
20+
It's necessary to implement :py:func:`~createSymbol` function.
21+
In C++ you can use Qgs3DSymbolMetadata convenience class.
22+
23+
.. versionadded:: 3.16
24+
%End
25+
26+
%TypeHeaderCode
27+
#include "qgs3dsymbolregistry.h"
28+
%End
29+
public:
30+
31+
Qgs3DSymbolAbstractMetadata( const QString &type, const QString &visibleName );
32+
%Docstring
33+
Constructor for Qgs3DSymbolAbstractMetadata, with the specified ``type`` and ``visibleName``.
34+
%End
35+
36+
virtual ~Qgs3DSymbolAbstractMetadata();
37+
38+
QString type() const;
39+
%Docstring
40+
Returns the unique symbol type string.
41+
%End
42+
43+
QString visibleName() const;
44+
%Docstring
45+
Returns the symbol's visible (translated) name.
46+
%End
47+
48+
virtual QgsAbstract3DSymbol *create() = 0 /Factory/;
49+
%Docstring
50+
Creates a new instance of this symbol type.
51+
52+
Caller takes ownership of the returned symbol.
53+
%End
54+
55+
56+
};
57+
58+
59+
60+
61+
62+
class Qgs3DSymbolRegistry
63+
{
64+
%Docstring
65+
Registry of available 3D symbol classes.
66+
67+
Qgs3DSymbolRegistry is not usually directly created, but rather accessed through
68+
:py:func:`QgsApplication.symbol3DRegistry()`.
69+
70+
.. versionadded:: 3.16
71+
%End
72+
73+
%TypeHeaderCode
74+
#include "qgs3dsymbolregistry.h"
75+
%End
76+
public:
77+
78+
Qgs3DSymbolRegistry();
79+
~Qgs3DSymbolRegistry();
80+
81+
82+
Qgs3DSymbolAbstractMetadata *symbolMetadata( const QString &type ) const;
83+
%Docstring
84+
Returns metadata for specified symbol ``type``. Returns ``None`` if not found
85+
%End
86+
87+
QStringList symbolTypes() const;
88+
%Docstring
89+
Returns a list of all available symbol types.
90+
%End
91+
92+
bool addSymbolType( Qgs3DSymbolAbstractMetadata *metadata /Transfer/ );
93+
%Docstring
94+
Registers a new symbol type. Takes ownership of the ``metadata`` instance.
95+
%End
96+
97+
QgsAbstract3DSymbol *createSymbol( const QString &type ) const /Factory/;
98+
%Docstring
99+
Creates a new instance of a symbol of the specified ``type``.
100+
101+
The caller takes ownership of the returned symbol.
102+
103+
Returns ``None`` if the specified type is not found in the registry.
104+
%End
105+
106+
private:
107+
Qgs3DSymbolRegistry( const Qgs3DSymbolRegistry &rh );
108+
};
109+
110+
111+
/************************************************************************
112+
* This file has been generated automatically from *
113+
* *
114+
* src/core/./3d/qgs3dsymbolregistry.h *
115+
* *
116+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
117+
************************************************************************/

‎python/core/auto_generated/qgsapplication.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,13 @@ Gets the registry of available field formatters.
850850
Returns registry of available 3D renderers.
851851

852852
.. versionadded:: 3.0
853+
%End
854+
855+
static Qgs3DSymbolRegistry *symbol3DRegistry() /KeepReference/;
856+
%Docstring
857+
Returns registry of available 3D symbols.
858+
859+
.. versionadded:: 3.16
853860
%End
854861

855862
static QgsScaleBarRendererRegistry *scaleBarRendererRegistry() /KeepReference/;

‎python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
%Include auto_generated/qgsxmlutils.sip
252252
%Include auto_generated/qgsziputils.sip
253253
%Include auto_generated/./3d/qgs3drendererregistry.sip
254+
%Include auto_generated/./3d/qgs3dsymbolregistry.sip
254255
%Include auto_generated/./3d/qgsabstract3dsymbol.sip
255256
%Include auto_generated/./3d/qgsabstract3drenderer.sip
256257
%Include auto_generated/annotations/qgsannotation.sip

‎src/core/3d/qgs3dsymbolregistry.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/***************************************************************************
2+
qgs3dsymbolregistry.cpp
3+
--------------------------------------
4+
Date : July 2020
5+
Copyright : (C) 2020 by Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgs3dsymbolregistry.h"
17+
18+
Qgs3DSymbolRegistry::Qgs3DSymbolRegistry()
19+
{
20+
}
21+
22+
Qgs3DSymbolRegistry::~Qgs3DSymbolRegistry()
23+
{
24+
qDeleteAll( mMetadata );
25+
}
26+
27+
bool Qgs3DSymbolRegistry::addSymbolType( Qgs3DSymbolAbstractMetadata *metadata )
28+
{
29+
if ( !metadata || mMetadata.contains( metadata->type() ) )
30+
return false;
31+
32+
mMetadata[metadata->type()] = metadata;
33+
return true;
34+
}
35+
36+
QgsAbstract3DSymbol *Qgs3DSymbolRegistry::createSymbol( const QString &type ) const
37+
{
38+
if ( !mMetadata.contains( type ) )
39+
return nullptr;
40+
41+
return mMetadata[type]->create();
42+
}
43+
44+
Qgs3DSymbolAbstractMetadata *Qgs3DSymbolRegistry::symbolMetadata( const QString &type ) const
45+
{
46+
return mMetadata.value( type );
47+
}
48+
49+
QStringList Qgs3DSymbolRegistry::symbolTypes() const
50+
{
51+
return mMetadata.keys();
52+
}

‎src/core/3d/qgs3dsymbolregistry.h

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
/***************************************************************************
2+
qgs3dsymbolregistry.h
3+
--------------------------------------
4+
Date : July 2020
5+
Copyright : (C) 2020 by Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGS3DSYMBOLREGISTRY_H
17+
#define QGS3DSYMBOLREGISTRY_H
18+
19+
#include "qgis_core.h"
20+
#include "qgis_sip.h"
21+
22+
#include <QDomElement>
23+
#include <QMap>
24+
25+
class QgsAbstract3DSymbol;
26+
class QgsReadWriteContext;
27+
class Qgs3DSymbolWidget;
28+
class QgsVectorLayer;
29+
30+
/**
31+
* \ingroup core
32+
* Stores metadata about one 3D symbol class.
33+
*
34+
* \note It's necessary to implement createSymbol() function.
35+
* In C++ you can use Qgs3DSymbolMetadata convenience class.
36+
*
37+
* \since QGIS 3.16
38+
*/
39+
class CORE_EXPORT Qgs3DSymbolAbstractMetadata
40+
{
41+
public:
42+
43+
/**
44+
* Constructor for Qgs3DSymbolAbstractMetadata, with the specified \a type and \a visibleName.
45+
*/
46+
Qgs3DSymbolAbstractMetadata( const QString &type, const QString &visibleName )
47+
: mType( type )
48+
, mVisibleName( visibleName )
49+
{}
50+
51+
virtual ~Qgs3DSymbolAbstractMetadata() = default;
52+
53+
/**
54+
* Returns the unique symbol type string.
55+
*/
56+
QString type() const { return mType; }
57+
58+
/**
59+
* Returns the symbol's visible (translated) name.
60+
*/
61+
QString visibleName() const { return mVisibleName; }
62+
63+
/**
64+
* Creates a new instance of this symbol type.
65+
*
66+
* Caller takes ownership of the returned symbol.
67+
*/
68+
virtual QgsAbstract3DSymbol *create() = 0 SIP_FACTORY;
69+
70+
#ifndef SIP_RUN
71+
72+
/**
73+
* Create a widget for configuring a symbol of this type.
74+
*
75+
* Can return NULLPTR if there's no GUI.
76+
*
77+
* \note Not available in Python bindings
78+
*/
79+
virtual Qgs3DSymbolWidget *createSymbolWidget( QgsVectorLayer * ) SIP_FACTORY { return nullptr; }
80+
#endif
81+
82+
private:
83+
QString mType;
84+
QString mVisibleName;
85+
};
86+
87+
//! 3D symbol creation function
88+
typedef QgsAbstract3DSymbol *( *Qgs3DSymbolCreateFunc )() SIP_SKIP;
89+
90+
//! 3D symbol widget creation function
91+
typedef Qgs3DSymbolWidget *( *Qgs3DSymbolWidgetFunc )( QgsVectorLayer * ) SIP_SKIP;
92+
93+
#ifndef SIP_RUN
94+
95+
/**
96+
* \ingroup core
97+
* Convenience metadata class that uses static functions to create a 3D symbol and its widget.
98+
*
99+
* \note Not available in Python bindings.
100+
*
101+
* \since QGIS 3.16
102+
*/
103+
class CORE_EXPORT Qgs3DSymbolMetadata : public Qgs3DSymbolAbstractMetadata
104+
{
105+
public:
106+
107+
/**
108+
* Constructor for Qgs3DSymbolMetadata, with the specified \a type and \a visibleName.
109+
*
110+
* The \a pfCreate and \a pfWidget arguments are used to specify
111+
* static functions for creating the symbol type and configuration widget.
112+
*/
113+
Qgs3DSymbolMetadata( const QString &type, const QString &visibleName,
114+
Qgs3DSymbolCreateFunc pfCreate,
115+
Qgs3DSymbolWidgetFunc pfWidget = nullptr ) SIP_SKIP
116+
: Qgs3DSymbolAbstractMetadata( type, visibleName )
117+
, mCreateFunc( pfCreate )
118+
, mWidgetFunc( pfWidget )
119+
{}
120+
121+
/**
122+
* Returns the symbol type's creation function.
123+
*/
124+
Qgs3DSymbolCreateFunc createFunction() const { return mCreateFunc; }
125+
126+
/**
127+
* Returns the symbol type's widget creation function.
128+
*
129+
* \see setWidgetFunction()
130+
*/
131+
Qgs3DSymbolWidgetFunc widgetFunction() const { return mWidgetFunc; }
132+
133+
/**
134+
* Sets the symbol type's widget creation \a function.
135+
*
136+
* \see widgetFunction()
137+
*/
138+
void setWidgetFunction( Qgs3DSymbolWidgetFunc function ) { mWidgetFunc = function; }
139+
140+
QgsAbstract3DSymbol *create() override SIP_FACTORY { return mCreateFunc ? mCreateFunc() : nullptr; }
141+
Qgs3DSymbolWidget *createSymbolWidget( QgsVectorLayer *vl ) override SIP_FACTORY { return mWidgetFunc ? mWidgetFunc( vl ) : nullptr; }
142+
143+
private:
144+
Qgs3DSymbolCreateFunc mCreateFunc;
145+
Qgs3DSymbolWidgetFunc mWidgetFunc;
146+
147+
};
148+
#endif
149+
150+
151+
/**
152+
* \ingroup core
153+
* Registry of available 3D symbol classes.
154+
*
155+
* Qgs3DSymbolRegistry is not usually directly created, but rather accessed through
156+
* QgsApplication::symbol3DRegistry().
157+
*
158+
* \since QGIS 3.16
159+
*/
160+
class CORE_EXPORT Qgs3DSymbolRegistry
161+
{
162+
public:
163+
164+
Qgs3DSymbolRegistry();
165+
~Qgs3DSymbolRegistry();
166+
167+
//! Qgs3DSymbolRegistry cannot be copied.
168+
Qgs3DSymbolRegistry( const Qgs3DSymbolRegistry &rh ) = delete;
169+
//! Qgs3DSymbolRegistry cannot be copied.
170+
Qgs3DSymbolRegistry &operator=( const Qgs3DSymbolRegistry &rh ) = delete;
171+
172+
//! Returns metadata for specified symbol \a type. Returns NULLPTR if not found
173+
Qgs3DSymbolAbstractMetadata *symbolMetadata( const QString &type ) const;
174+
175+
/**
176+
* Returns a list of all available symbol types.
177+
*/
178+
QStringList symbolTypes() const;
179+
180+
//! Registers a new symbol type. Takes ownership of the \a metadata instance.
181+
bool addSymbolType( Qgs3DSymbolAbstractMetadata *metadata SIP_TRANSFER );
182+
183+
/**
184+
* Creates a new instance of a symbol of the specified \a type.
185+
*
186+
* The caller takes ownership of the returned symbol.
187+
*
188+
* Returns NULLPTR if the specified type is not found in the registry.
189+
*/
190+
QgsAbstract3DSymbol *createSymbol( const QString &type ) const SIP_FACTORY;
191+
192+
private:
193+
#ifdef SIP_RUN
194+
Qgs3DSymbolRegistry( const Qgs3DSymbolRegistry &rh );
195+
#endif
196+
197+
QMap<QString, Qgs3DSymbolAbstractMetadata *> mMetadata;
198+
};
199+
200+
201+
#endif // QGS3DSYMBOLREGISTRY_H

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ SET(QGIS_CORE_SRCS
654654
geometry/qgswkbtypes.cpp
655655

656656
3d/qgs3drendererregistry.cpp
657+
3d/qgs3dsymbolregistry.cpp
657658
3d/qgsabstract3dsymbol.cpp
658659
3d/qgsabstract3drenderer.cpp
659660

@@ -1033,6 +1034,7 @@ SET(QGIS_CORE_HDRS
10331034
qobjectuniqueptr.h
10341035

10351036
3d/qgs3drendererregistry.h
1037+
3d/qgs3dsymbolregistry.h
10361038
3d/qgsabstract3dsymbol.h
10371039
3d/qgsabstract3drenderer.h
10381040

‎src/core/qgsapplication.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "qgsuserprofilemanager.h"
5555
#include "qgsreferencedgeometry.h"
5656
#include "qgs3drendererregistry.h"
57+
#include "qgs3dsymbolregistry.h"
5758
#include "qgslayoutrendercontext.h"
5859
#include "qgssqliteutils.h"
5960
#include "qgsstyle.h"
@@ -2235,6 +2236,11 @@ Qgs3DRendererRegistry *QgsApplication::renderer3DRegistry()
22352236
return members()->m3DRendererRegistry;
22362237
}
22372238

2239+
Qgs3DSymbolRegistry *QgsApplication::symbol3DRegistry()
2240+
{
2241+
return members()->m3DSymbolRegistry;
2242+
}
2243+
22382244
QgsScaleBarRendererRegistry *QgsApplication::scaleBarRendererRegistry()
22392245
{
22402246
return members()->mScaleBarRendererRegistry;
@@ -2355,6 +2361,11 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
23552361
mAnnotationRegistry = new QgsAnnotationRegistry();
23562362
profiler->end();
23572363
}
2364+
{
2365+
profiler->start( tr( "Setup 3D symbol registry" ) );
2366+
m3DSymbolRegistry = new Qgs3DSymbolRegistry();
2367+
profiler->end();
2368+
}
23582369
{
23592370
profiler->start( tr( "Setup 3D renderer registry" ) );
23602371
m3DRendererRegistry = new Qgs3DRendererRegistry();
@@ -2399,6 +2410,7 @@ QgsApplication::ApplicationMembers::~ApplicationMembers()
23992410
delete mValidityCheckRegistry;
24002411
delete mActionScopeRegistry;
24012412
delete m3DRendererRegistry;
2413+
delete m3DSymbolRegistry;
24022414
delete mAnnotationRegistry;
24032415
delete mColorSchemeRegistry;
24042416
delete mFieldFormatterRegistry;

‎src/core/qgsapplication.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class QgsStyleModel;
6060
class QgsNumericFormatRegistry;
6161
class QgsConnectionRegistry;
6262
class QgsScaleBarRendererRegistry;
63+
class Qgs3DSymbolRegistry;
6364

6465
/**
6566
* \ingroup core
@@ -785,6 +786,12 @@ class CORE_EXPORT QgsApplication : public QApplication
785786
*/
786787
static Qgs3DRendererRegistry *renderer3DRegistry() SIP_KEEPREFERENCE;
787788

789+
/**
790+
* Returns registry of available 3D symbols.
791+
* \since QGIS 3.16
792+
*/
793+
static Qgs3DSymbolRegistry *symbol3DRegistry() SIP_KEEPREFERENCE;
794+
788795
/**
789796
* Gets the registry of available scalebar renderers.
790797
*
@@ -928,6 +935,7 @@ class CORE_EXPORT QgsApplication : public QApplication
928935
struct ApplicationMembers
929936
{
930937
Qgs3DRendererRegistry *m3DRendererRegistry = nullptr;
938+
Qgs3DSymbolRegistry *m3DSymbolRegistry = nullptr;
931939
QgsActionScopeRegistry *mActionScopeRegistry = nullptr;
932940
QgsAnnotationRegistry *mAnnotationRegistry = nullptr;
933941
QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;

‎tests/src/3d/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ ADD_QGIS_TEST(3dutilstest testqgs3dutils.cpp)
7979
ADD_QGIS_TEST(3drenderingtest testqgs3drendering.cpp)
8080
ADD_QGIS_TEST(layout3dmaptest testqgslayout3dmap.cpp)
8181
ADD_QGIS_TEST(tessellatortest testqgstessellator.cpp)
82+
ADD_QGIS_TEST(3dsymbolregistrytest testqgs3dsymbolregistry.cpp)
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/***************************************************************************
2+
TestQgs3DSymbolRegistry.cpp
3+
-----------------------
4+
begin : July 2019
5+
copyright : (C) 2019 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgs3dsymbolregistry.h"
19+
#include "qgsabstract3dsymbol.h"
20+
21+
#include <QObject>
22+
#include "qgstest.h"
23+
24+
//dummy symbol for testing
25+
class Dummy3DSymbol : public QgsAbstract3DSymbol
26+
{
27+
public:
28+
Dummy3DSymbol() = default;
29+
QString type() const override { return QStringLiteral( "Dummy" ); }
30+
QgsAbstract3DSymbol *clone() const override { return new Dummy3DSymbol(); }
31+
void writeXml( QDomElement &, const QgsReadWriteContext & ) const override {}
32+
void readXml( const QDomElement &, const QgsReadWriteContext & ) override {}
33+
34+
static QgsAbstract3DSymbol *create() { return new Dummy3DSymbol(); }
35+
36+
};
37+
38+
class TestQgs3DSymbolRegistry : public QObject
39+
{
40+
Q_OBJECT
41+
42+
private slots:
43+
void initTestCase();
44+
void cleanupTestCase();
45+
void init();
46+
void cleanup();
47+
void metadata();
48+
void createInstance();
49+
void instanceHasDefaultSymbols();
50+
void addSymbol();
51+
void fetchTypes();
52+
void createSymbol();
53+
54+
private:
55+
56+
};
57+
58+
void TestQgs3DSymbolRegistry::initTestCase()
59+
{
60+
QgsApplication::init(); // init paths for CRS lookup
61+
QgsApplication::initQgis();
62+
}
63+
64+
void TestQgs3DSymbolRegistry::cleanupTestCase()
65+
{
66+
QgsApplication::exitQgis();
67+
}
68+
69+
void TestQgs3DSymbolRegistry::init()
70+
{
71+
72+
}
73+
74+
void TestQgs3DSymbolRegistry::cleanup()
75+
{
76+
77+
}
78+
79+
void TestQgs3DSymbolRegistry::metadata()
80+
{
81+
Qgs3DSymbolMetadata metadata = Qgs3DSymbolMetadata( QStringLiteral( "name" ), QStringLiteral( "display name" ), Dummy3DSymbol::create );
82+
QCOMPARE( metadata.type(), QString( "name" ) );
83+
QCOMPARE( metadata.visibleName(), QString( "display name" ) );
84+
85+
//test creating symbol from metadata
86+
QVariantMap map;
87+
std::unique_ptr< QgsAbstract3DSymbol > symbol( metadata.create() );
88+
QVERIFY( symbol );
89+
Dummy3DSymbol *dummySymbol = dynamic_cast<Dummy3DSymbol *>( symbol.get() );
90+
QVERIFY( dummySymbol );
91+
}
92+
93+
void TestQgs3DSymbolRegistry::createInstance()
94+
{
95+
Qgs3DSymbolRegistry *registry = QgsApplication::symbol3DRegistry();
96+
QVERIFY( registry );
97+
}
98+
99+
void TestQgs3DSymbolRegistry::instanceHasDefaultSymbols()
100+
{
101+
//check that symbol registry is initially populated with some symbols
102+
//(assumes that there is some default symbols)
103+
Qgs3DSymbolRegistry *registry = QgsApplication::symbol3DRegistry();
104+
QVERIFY( registry->symbolTypes().length() > 0 );
105+
}
106+
107+
void TestQgs3DSymbolRegistry::addSymbol()
108+
{
109+
Qgs3DSymbolRegistry *registry = QgsApplication::symbol3DRegistry();
110+
int previousCount = registry->symbolTypes().length();
111+
112+
registry->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "Dummy" ), QStringLiteral( "Dummy symbol" ), Dummy3DSymbol::create ) );
113+
QCOMPARE( registry->symbolTypes().length(), previousCount + 1 );
114+
//try adding again, should have no effect
115+
Qgs3DSymbolMetadata *dupe = new Qgs3DSymbolMetadata( QStringLiteral( "Dummy" ), QStringLiteral( "Dummy symbol" ), Dummy3DSymbol::create );
116+
QVERIFY( ! registry->addSymbolType( dupe ) );
117+
QCOMPARE( registry->symbolTypes().length(), previousCount + 1 );
118+
delete dupe;
119+
120+
//try adding empty metadata
121+
registry->addSymbolType( nullptr );
122+
QCOMPARE( registry->symbolTypes().length(), previousCount + 1 );
123+
}
124+
125+
void TestQgs3DSymbolRegistry::fetchTypes()
126+
{
127+
Qgs3DSymbolRegistry *registry = QgsApplication::symbol3DRegistry();
128+
QStringList types = registry->symbolTypes();
129+
130+
QVERIFY( types.contains( "Dummy" ) );
131+
132+
Qgs3DSymbolAbstractMetadata *metadata = registry->symbolMetadata( QStringLiteral( "Dummy" ) );
133+
QCOMPARE( metadata->type(), QString( "Dummy" ) );
134+
135+
//metadata for bad symbol
136+
metadata = registry->symbolMetadata( QStringLiteral( "bad symbol" ) );
137+
QVERIFY( !metadata );
138+
}
139+
140+
void TestQgs3DSymbolRegistry::createSymbol()
141+
{
142+
Qgs3DSymbolRegistry *registry = QgsApplication::symbol3DRegistry();
143+
std::unique_ptr< QgsAbstract3DSymbol > symbol( registry->createSymbol( QStringLiteral( "Dummy" ) ) );
144+
145+
QVERIFY( symbol.get() );
146+
Dummy3DSymbol *dummySymbol = dynamic_cast<Dummy3DSymbol *>( symbol.get() );
147+
QVERIFY( dummySymbol );
148+
149+
//try creating a bad symbol
150+
symbol.reset( registry->createSymbol( QStringLiteral( "bad symbol" ) ) );
151+
QVERIFY( !symbol.get() );
152+
}
153+
154+
QGSTEST_MAIN( TestQgs3DSymbolRegistry )
155+
#include "testqgs3dsymbolregistry.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.