16 #include <QTreeWidget>
17 #include <QVBoxLayout>
33 static void expandAll( QTreeWidgetItem *item )
35 for (
int i = 0; i < item->childCount(); i++ )
36 expandAll( item->child( i ) );
37 item->setExpanded(
true );
42 std::cout << lid.
symbolKey().toLocal8Bit().constData() <<
"/";
44 for (
int i = 0; i < path.size(); i++ )
46 std::cout << path[i] <<
"/";
52 std::cout << ref.
layerId().toLocal8Bit().constData() <<
"/";
59 mTree =
new QTreeWidget(
this );
60 mTree->setHeaderHidden(
true );
62 connect( mTree, &QTreeWidget::itemChanged,
this, [&]( QTreeWidgetItem *,
int ) { emit this->
changed(); } );
65 QVBoxLayout *vbox =
new QVBoxLayout();
66 vbox->setContentsMargins( 0, 0, 0, 0 );
67 vbox->addWidget( mTree );
80 SymbolLayerFillVisitor( QTreeWidgetItem *layerItem,
const QgsVectorLayer *layer, QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &items ):
81 mLayerItem( layerItem ), mLayer( layer ), mItems( items )
95 bool visitSymbol( QTreeWidgetItem *rootItem,
const QString &identifier,
const QgsSymbol *symbol, QVector<int> rootPath )
103 QVector<int> indexPath = rootPath;
104 indexPath.append( idx );
106 std::unique_ptr< QTreeWidgetItem > slItem = std::make_unique< QTreeWidgetItem >( rootItem );
108 slItem->setIcon( 0, slIcon );
111 slItem->setText( 0, QObject::tr(
"Mask symbol layer" ) );
112 slItem->setFlags( slItem->flags() | Qt::ItemIsUserCheckable );
113 slItem->setCheckState( 0, Qt::Unchecked );
116 if ( ( sl->
layerType() ==
"MaskMarker" ) ||
117 ( subSymbol && visitSymbol( slItem.get(), identifier, subSymbol, indexPath ) ) )
120 mItems[ref] = slItem.get();
121 rootItem->addChild( slItem.release() );
134 const QgsSymbol *symbol = symbolEntity->symbol();
138 std::unique_ptr< QTreeWidgetItem > symbolItem = std::make_unique< QTreeWidgetItem >( mLayerItem, QStringList() << ( mCurrentDescription + leaf.
description ) );
140 symbolItem->setIcon( 0, icon );
142 if ( visitSymbol( symbolItem.get(), leaf.
identifier, symbol, {} ) )
143 mLayerItem->addChild( symbolItem.release() );
149 QString mCurrentDescription;
150 QString mCurrentIdentifier;
151 QTreeWidgetItem *mLayerItem;
153 QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &mItems;
159 LabelMasksVisitor( QTreeWidgetItem *layerItem,
const QgsVectorLayer *layer, QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &items ):
160 mLayerItem( layerItem ), mLayer( layer ), mItems( items )
177 if ( labelSettingsEntity->settings().format().mask().enabled() )
179 QString maskTitle = currentRule.isEmpty()
180 ? QObject::tr(
"Label mask" )
181 : QObject::tr(
"Label mask for '%1' rule" ).arg( currentDescription );
182 QTreeWidgetItem *slItem =
new QTreeWidgetItem( mLayerItem, QStringList() << maskTitle );
183 slItem->setFlags( slItem->flags() | Qt::ItemIsUserCheckable );
184 slItem->setCheckState( 0, Qt::Unchecked );
185 mLayerItem->addChild( slItem );
192 QHash<QString, QHash<QString, QSet<QgsSymbolLayerId>>> masks;
195 QString currentDescription;
196 QTreeWidgetItem *mLayerItem;
198 QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &mItems;
205 const QgsMapLayer *layer = layerTreeLayer->layer();
206 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
212 std::unique_ptr< QTreeWidgetItem > layerItem = std::make_unique< QTreeWidgetItem >( mTree, QStringList() << layer->
name() );
213 layerItem->setData( 0, Qt::UserRole, vl );
217 LabelMasksVisitor lblVisitor( layerItem.get(), vl, mItems );
221 SymbolLayerFillVisitor slVisitor( layerItem.get(), vl, mItems );
224 if ( layerItem->childCount() > 0 )
225 mTree->addTopLevelItem( layerItem.release() );
228 expandAll( mTree->invisibleRootItem() );
234 QList<QgsMaskSourceSelectionWidget::MaskSource> sel;
235 for (
auto it = mItems.begin(); it != mItems.end(); it++ )
237 if ( it.value()->checkState( 0 ) == Qt::Checked )
244 sel.append( source );
254 for (
auto it = mItems.begin(); it != mItems.end(); it++ )
256 it.value()->setCheckState( 0, Qt::Unchecked );
261 QString layerId = ( src.isLabeling ?
"__labels__" :
"" ) + src.layerId;
263 if ( it != mItems.end() )
265 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.
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.
We may need stable references to symbol layers, when pointers to symbol layers is not usable (when a ...
QVector< int > symbolLayerIndexPath() const
Returns the symbol layer index path inside the symbol.
QString symbolKey() const
Returns the key associated to the symbol.
Type used to refer to a specific symbol layer in a symbol of a layer.
QgsSymbolLayerId symbolLayerId() 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, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
Draws a symbol layer preview to an icon.
virtual QString layerType() const =0
Returns a string that represents this layer type.
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.
@ RenderMillimeters
Millimeters.
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.