Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow remove symbol layer from registry
  • Loading branch information
3nids committed Nov 26, 2021
1 parent 68ebf22 commit 99194ce
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Expand Up @@ -132,7 +132,14 @@ Returns metadata for specified symbol layer. Returns ``None`` if not found

bool addSymbolLayerType( QgsSymbolLayerAbstractMetadata *metadata /Transfer/ );
%Docstring
register a new symbol layer type. Takes ownership of the metadata instance.
Registers a new symbol layer type. Takes ownership of the metadata instance.
%End

bool removeSymbolLayerType( QgsSymbolLayerAbstractMetadata *metadata );
%Docstring
Removes a symbol layer type

.. versionadded:: 3.22.2
%End

QgsSymbolLayer *createSymbolLayer( const QString &name, const QVariantMap &properties = QVariantMap() ) const /Factory/;
Expand Down
10 changes: 10 additions & 0 deletions src/core/symbology/qgssymbollayerregistry.cpp
Expand Up @@ -97,6 +97,16 @@ bool QgsSymbolLayerRegistry::addSymbolLayerType( QgsSymbolLayerAbstractMetadata
return true;
}

bool QgsSymbolLayerRegistry::removeSymbolLayerType( QgsSymbolLayerAbstractMetadata *metadata )
{
if ( !metadata || !mMetadata.contains( metadata->name() ) )
return false;

metadata = mMetadata.take( metadata->name() );
delete metadata;
return true;
}


QgsSymbolLayerAbstractMetadata *QgsSymbolLayerRegistry::symbolLayerMetadata( const QString &name ) const
{
Expand Down
8 changes: 7 additions & 1 deletion src/core/symbology/qgssymbollayerregistry.h
Expand Up @@ -195,9 +195,15 @@ class CORE_EXPORT QgsSymbolLayerRegistry
//! Returns metadata for specified symbol layer. Returns NULLPTR if not found
QgsSymbolLayerAbstractMetadata *symbolLayerMetadata( const QString &name ) const;

//! register a new symbol layer type. Takes ownership of the metadata instance.
//! Registers a new symbol layer type. Takes ownership of the metadata instance.
bool addSymbolLayerType( QgsSymbolLayerAbstractMetadata *metadata SIP_TRANSFER );

/**
* Removes a symbol layer type
* \since QGIS 3.22.2
*/
bool removeSymbolLayerType( QgsSymbolLayerAbstractMetadata *metadata );

//! create a new instance of symbol layer given symbol layer name and properties
QgsSymbolLayer *createSymbolLayer( const QString &name, const QVariantMap &properties = QVariantMap() ) const SIP_FACTORY;

Expand Down
8 changes: 7 additions & 1 deletion src/gui/symbology/qgssymbolselectordialog.cpp
Expand Up @@ -189,7 +189,13 @@ class SymbolLayerItem : public QStandardItem
if ( role == Qt::DisplayRole || role == Qt::EditRole )
{
if ( mIsLayer )
return QgsApplication::symbolLayerRegistry()->symbolLayerMetadata( mLayer->layerType() )->visibleName();
{
QgsSymbolLayerAbstractMetadata *m = QgsApplication::symbolLayerRegistry()->symbolLayerMetadata( mLayer->layerType() );
if ( m )
return m->visibleName();
else
return QString();
}
else
{
switch ( mSymbol->type() )
Expand Down

0 comments on commit 99194ce

Please sign in to comment.