Skip to content

Commit

Permalink
Add method to retrieve compatible layer types from 3d symbol in style…
Browse files Browse the repository at this point in the history
… library
  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent 93022ea commit 6245b55
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
7 changes: 3 additions & 4 deletions python/core/auto_generated/symbology/qgsstyle.sip.in
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology/qgsstyle.cpp
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/core/symbology/qgsstyle.h
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqgsstyle.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand All @@ -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" );
Expand Down

0 comments on commit 6245b55

Please sign in to comment.