30static void expandAll( QTreeWidgetItem *item )
32 for (
int i = 0; i < item->childCount(); i++ )
33 expandAll( item->child( i ) );
34 item->setExpanded(
true );
39 std::cout << ref.
layerId().toLocal8Bit().constData() <<
"/" << ref.
symbolLayerIdV2().toLocal8Bit().constData();
45 mTree =
new QTreeWidget(
this );
46 mTree->setHeaderHidden(
true );
48 connect( mTree, &QTreeWidget::itemChanged,
this, [&]( QTreeWidgetItem *,
int ) { emit this->
changed(); } );
51 QVBoxLayout *vbox =
new QVBoxLayout();
52 vbox->setContentsMargins( 0, 0, 0, 0 );
53 vbox->addWidget( mTree );
66 SymbolLayerFillVisitor( QTreeWidgetItem *layerItem,
const QgsVectorLayer *layer, QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &items ):
67 mLayerItem( layerItem ), mLayer( layer ), mItems( items )
81 bool visitSymbol( QTreeWidgetItem *rootItem,
const QString &identifier,
const QgsSymbol *symbol, QVector<int> rootPath )
89 QVector<int> indexPath = rootPath;
90 indexPath.append( idx );
92 std::unique_ptr< QTreeWidgetItem > slItem = std::make_unique< QTreeWidgetItem >( rootItem );
94 slItem->setIcon( 0, slIcon );
97 slItem->setText( 0, QObject::tr(
"Mask symbol layer" ) );
98 slItem->setFlags( slItem->flags() | Qt::ItemIsUserCheckable );
99 slItem->setCheckState( 0, Qt::Unchecked );
102 if ( ( sl->
layerType() ==
"MaskMarker" ) ||
103 ( subSymbol && visitSymbol( slItem.get(), identifier, subSymbol, indexPath ) ) )
106 mItems[ref] = slItem.get();
107 rootItem->addChild( slItem.release() );
120 const QgsSymbol *symbol = symbolEntity->symbol();
124 std::unique_ptr< QTreeWidgetItem > symbolItem = std::make_unique< QTreeWidgetItem >( mLayerItem, QStringList() << ( mCurrentDescription + leaf.
description ) );
126 symbolItem->setIcon( 0, icon );
128 if ( visitSymbol( symbolItem.get(), leaf.
identifier, symbol, {} ) )
129 mLayerItem->addChild( symbolItem.release() );
135 QString mCurrentDescription;
136 QString mCurrentIdentifier;
137 QTreeWidgetItem *mLayerItem;
139 QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &mItems;
145 LabelMasksVisitor( QTreeWidgetItem *layerItem,
const QgsVectorLayer *layer, QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &items ):
146 mLayerItem( layerItem ), mLayer( layer ), mItems( items )
163 if ( labelSettingsEntity->settings().format().mask().enabled() )
165 const QString maskTitle = currentRule.isEmpty()
166 ? QObject::tr(
"Label mask" )
167 : QObject::tr(
"Label mask for '%1' rule" ).arg( currentDescription );
168 QTreeWidgetItem *slItem =
new QTreeWidgetItem( mLayerItem, QStringList() << maskTitle );
169 slItem->setFlags( slItem->flags() | Qt::ItemIsUserCheckable );
170 slItem->setCheckState( 0, Qt::Unchecked );
171 mLayerItem->addChild( slItem );
178 QHash<QString, QHash<QString, QSet<QgsSymbolLayerId>>> masks;
181 QString currentDescription;
182 QTreeWidgetItem *mLayerItem;
184 QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &mItems;
198 std::unique_ptr< QTreeWidgetItem > layerItem = std::make_unique< QTreeWidgetItem >( mTree, QStringList() << layer->
name() );
199 layerItem->setData( 0, Qt::UserRole, QVariant::fromValue( vl ) );
203 LabelMasksVisitor lblVisitor( layerItem.get(), vl, mItems );
207 SymbolLayerFillVisitor slVisitor( layerItem.get(), vl, mItems );
210 if ( layerItem->childCount() > 0 )
211 mTree->addTopLevelItem( layerItem.release() );
214 expandAll( mTree->invisibleRootItem() );
220 QList<QgsMaskSourceSelectionWidget::MaskSource> sel;
221 for (
auto it = mItems.begin(); it != mItems.end(); it++ )
223 if ( it.value()->checkState( 0 ) == Qt::Checked )
230 sel.append( source );
240 for (
auto it = mItems.begin(); it != mItems.end(); it++ )
242 it.value()->setCheckState( 0, Qt::Unchecked );
247 const QString layerId = ( src.isLabeling ?
"__labels__" :
"" ) + src.layerId;
249 if ( it != mItems.end() )
251 it.value()->setCheckState( 0, Qt::Checked );
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
Layer tree node points to a map layer.
Base class for all map layer types.
Struct for storing maximum and minimum scales for measurements in map units.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
virtual QgsStyle::StyleEntity type() const =0
Returns the type of style entity.
An interface for classes which can visit style entity (e.g.
@ SymbolRule
Rule based symbology or label child rule.
A label settings entity for QgsStyle databases.
A symbol entity for QgsStyle databases.
@ LabelSettingsEntity
Label settings.
Type used to refer to a specific symbol layer in a symbol of a layer.
QString symbolLayerIdV2() const
The symbol layer's id.
QString layerId() const
The referenced vector layer / feature renderer.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
static QIcon symbolLayerPreviewIcon(const QgsSymbolLayer *layer, Qgis::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::SymbolType parentSymbolType=Qgis::SymbolType::Hybrid, QgsMapLayer *mapLayer=nullptr)
Draws a symbol layer preview to an icon.
virtual QString layerType() const =0
Returns a string that represents this layer type.
QString id() const
Returns symbol layer identifier This id is unique in the whole project.
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
Abstract base class for all rendered symbols.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Qgis::SymbolType type() const
Returns the symbol's type.
Represents a vector layer which manages a vector based data sets.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
Contains information relating to a node (i.e.
QString identifier
A string identifying the node.
QString description
A string describing the node.
QgsStyleEntityVisitorInterface::NodeType type
Node type.
Contains information relating to the style entity currently being visited.
QString description
A string describing the style entity.
const QgsStyleEntityInterface * entity
Reference to style entity being visited.
QString identifier
A string identifying the style entity.