Skip to content
Permalink
Browse files

Add method to retrieve compatible layer types from 3d symbol in style…

… library
  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent 93022ea commit 6245b552a4357626cc9a590d0b2aa35374d9ef88
@@ -343,11 +343,10 @@ Returns count of 3D symbols in the style.
.. versionadded:: 3.16
%End

QString symbol3DType( const QString &name ) const;
QList< QgsWkbTypes::GeometryType > symbol3DCompatibleGeometryTypes( const QString &name ) const;
%Docstring
Returns the symbol type corresponding to the 3d symbol
with the specified ``name``, or an empty string
if a matching 3d symbol is not present.
Returns the list of the vector layer geometry types which are compatible with the 3D symbol
with the specified ``name``, or an empty list if a matching 3d symbol is not present.

.. versionadded:: 3.16
%End
@@ -2151,12 +2151,12 @@ int QgsStyle::symbol3DCount() const
return m3dSymbols.count();
}

QString QgsStyle::symbol3DType( const QString &name ) const
QList<QgsWkbTypes::GeometryType> QgsStyle::symbol3DCompatibleGeometryTypes( const QString &name ) const
{
if ( !m3dSymbols.contains( name ) )
return QString();
return QList<QgsWkbTypes::GeometryType>();

return m3dSymbols.value( name )->type();
return m3dSymbols.value( name )->compatibleGeometryTypes();
}

QgsWkbTypes::GeometryType QgsStyle::labelSettingsLayerType( const QString &name ) const
@@ -405,13 +405,12 @@ class CORE_EXPORT QgsStyle : public QObject
int symbol3DCount() const;

/**
* Returns the symbol type corresponding to the 3d symbol
* with the specified \a name, or an empty string
* if a matching 3d symbol is not present.
* Returns the list of the vector layer geometry types which are compatible with the 3D symbol
* with the specified \a name, or an empty list if a matching 3d symbol is not present.
*
* \since QGIS 3.16
*/
QString symbol3DType( const QString &name ) const;
QList< QgsWkbTypes::GeometryType > symbol3DCompatibleGeometryTypes( const QString &name ) const;

/**
* Returns the layer geometry type corresponding to the label settings
@@ -108,6 +108,7 @@ class Dummy3DSymbol : public QgsAbstract3DSymbol
QgsAbstract3DSymbol *clone() const override { Dummy3DSymbol *res = new Dummy3DSymbol(); res->id = id; return res; }
void readXml( const QDomElement &elem, const QgsReadWriteContext & ) override { id = elem.attribute( QStringLiteral( "id" ) ); }
void writeXml( QDomElement &elem, const QgsReadWriteContext & ) const override { elem.setAttribute( QStringLiteral( "id" ), id ); }
QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return QList< QgsWkbTypes::GeometryType >() << QgsWkbTypes::PointGeometry << QgsWkbTypes::LineGeometry; }

QString id;

@@ -444,6 +445,7 @@ void TestStyle::testCreate3dSymbol()
QCOMPARE( mStyle->symbol3DCount(), 0 );
// non existent settings, should be default
QVERIFY( !mStyle->symbol3D( QString( "blah" ) ) );
QVERIFY( mStyle->symbol3DCompatibleGeometryTypes( QStringLiteral( "blah" ) ).isEmpty() );

QSignalSpy spy( mStyle, &QgsStyle::entityAdded );
QSignalSpy spyChanged( mStyle, &QgsStyle::entityChanged );
@@ -456,6 +458,8 @@ void TestStyle::testCreate3dSymbol()

QVERIFY( mStyle->symbol3DNames().contains( QStringLiteral( "test_settings" ) ) );
QCOMPARE( mStyle->symbol3DCount(), 1 );
QVERIFY( mStyle->symbol3DCompatibleGeometryTypes( QStringLiteral( "blah" ) ).isEmpty() );
QCOMPARE( mStyle->symbol3DCompatibleGeometryTypes( QStringLiteral( "test_settings" ) ), QList< QgsWkbTypes::GeometryType >() << QgsWkbTypes::PointGeometry << QgsWkbTypes::LineGeometry );
std::unique_ptr< Dummy3DSymbol > retrieved( dynamic_cast< Dummy3DSymbol * >( mStyle->symbol3D( QStringLiteral( "test_settings" ) ) ) );
QCOMPARE( retrieved->id, QStringLiteral( "xxx" ) );
symbol.id = QStringLiteral( "yyy" );

0 comments on commit 6245b55

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