23#include "moc_qgsmaskingwidget.cpp"
37QgsMaskingWidget::QgsMaskingWidget( QWidget *parent )
46void QgsMaskingWidget::onSelectionChanged()
49 const bool printMessage = mMaskTargetsWidget->selection().empty() != mMaskSourcesWidget->selection().empty();
51 if ( mMessageBarItem && !printMessage )
53 mMessageBar->popWidget( mMessageBarItem );
54 delete mMessageBarItem;
56 else if ( !mMessageBarItem && printMessage )
59 mMessageBar->pushItem( mMessageBarItem );
74QList<QPair<QString, QList<QgsSymbolLayerReference>>> symbolLayerMasks(
const QgsVectorLayer *layer )
79 QList<QPair<QString, QList<QgsSymbolLayerReference>>> mMasks;
80 SymbolLayerVisitor collector( [&](
const QgsSymbolLayer *sl,
const QString &lid ) {
81 if ( !sl->
masks().isEmpty() )
82 mMasks.push_back( qMakePair( lid, sl->
masks() ) );
94void QgsMaskingWidget::populate()
96 const QSignalBlocker blockerSourceWidget( mMaskSourcesWidget );
97 const QSignalBlocker blockerTargetWidget( mMaskTargetsWidget );
99 mMaskSourcesWidget->update();
100 mMaskTargetsWidget->setLayer( mLayer );
103 QSet<QString> maskedSymbolLayers;
104 QList<QgsMaskSourceSelectionWidget::MaskSource> maskSources;
108 for (
auto layerIt = layers.begin(); layerIt != layers.end(); layerIt++ )
110 const QString layerId = layerIt.key();
111 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layerIt.value() );
116 const QList<QPair<QString, QList<QgsSymbolLayerReference>>> slMasks = symbolLayerMasks( vl );
117 for (
const QPair<QString, QList<QgsSymbolLayerReference>> &p : slMasks )
119 const QString &sourceSymbolLayerId = p.first;
122 if ( ref.layerId() == mLayer->id() )
125 maskedSymbolLayers.insert( ref.symbolLayerIdV2() );
130 maskSources.append( source );
137 for (
auto it = labelMasks.begin(); it != labelMasks.end(); it++ )
139 const QString &ruleKey = it.key();
140 for (
auto it2 = it.value().begin(); it2 != it.value().end(); it2++ )
142 if ( it2.key() == mLayer->id() )
145 maskedSymbolLayers.unite( it2.value().symbolLayerIds );
150 maskSources.append( source );
156 mMaskSourcesWidget->setSelection( maskSources );
157 mMaskTargetsWidget->setSelection( maskedSymbolLayers );
160void QgsMaskingWidget::apply()
162 QList<QgsMaskSourceSelectionWidget::MaskSource> maskSources = mMaskSourcesWidget->selection();
163 QSet<QString> maskedSymbolLayers = mMaskTargetsWidget->selection();
165 QSet<QString> layersToRefresh;
168 for (
auto layerIt = layers.begin(); layerIt != layers.end(); layerIt++ )
170 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layerIt.value() );
176 SymbolLayerVisitor maskSetter( [&](
const QgsSymbolLayer *sl,
const QString &slId ) {
179 QgsMaskMarkerSymbolLayer *maskSl = const_cast<QgsMaskMarkerSymbolLayer *>( static_cast<const QgsMaskMarkerSymbolLayer *>( sl ) );
181 const QgsSymbolLayerReferenceList masks = maskSl->masks();
182 QgsSymbolLayerReferenceList newMasks;
183 for ( const QgsSymbolLayerReference &ref : masks )
186 if ( ref.layerId() != mLayer->id() )
187 newMasks.append( ref );
194 for (
const QString &maskedId : maskedSymbolLayers )
199 layersToRefresh.insert( source.
layerId );
202 maskSl->setMasks( newMasks );
212 for (
const QString &labelProvider : vl->labeling()->subProviders() )
224 if ( ref.layerId() != mLayer->id() )
225 newMasks.append( ref );
233 for (
const QString &maskedId : maskedSymbolLayers )
238 layersToRefresh.insert( source.
layerId );
249 mLayer->triggerRepaint();
251 for (
const QString &layerId : layersToRefresh )
258SymbolLayerVisitor::SymbolLayerVisitor( SymbolLayerVisitor::SymbolLayerCallback callback )
259 : mCallback( callback )
271void SymbolLayerVisitor::visitSymbol(
const QgsSymbol *symbol,
const QString &leafIdentifier, QVector<int> rootPath )
275 QVector<int> indexPath = rootPath;
276 indexPath.push_back( idx );
280 mCallback( sl, sl->
id() );
285 visitSymbol( subSymbol, leafIdentifier, indexPath );
294 if ( symbolEntity->symbol() )
295 visitSymbol( symbolEntity->symbol(), leaf.
identifier, {} );
@ Warning
Warning message.
virtual void setSettings(QgsPalLayerSettings *settings, const QString &providerId=QString())=0
Set pal settings for a specific provider (takes ownership).
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Base class for all map layer types.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
Represents an item shown within a QgsMessageBar widget.
Contains settings for how a map layer will be labeled.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
void setDirty(bool b=true)
Flag the project as dirty (modified).
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
virtual QgsStyle::StyleEntity type() const =0
Returns the type of style entity.
@ SymbolRule
Rule based symbology or label child rule.
A symbol entity for QgsStyle databases.
Type used to refer to a specific symbol layer in a symbol of a layer.
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 QList< QgsSymbolLayerReference > masks() const
Returns masks defined by this symbol layer.
Abstract base class for all rendered symbols.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Container for all settings relating to text rendering.
QgsTextMaskSettings & mask()
Returns a reference to the masking settings.
void setMaskedSymbolLayers(const QList< QgsSymbolLayerReference > &maskedLayers)
Sets the symbol layers that will be masked by this buffer.
QList< QgsSymbolLayerReference > maskedSymbolLayers() const
Returns a list of references to symbol layers that are masked by this buffer.
bool enabled() const
Returns whether the mask is enabled.
static QHash< QString, QgsMaskedLayers > labelMasks(const QgsVectorLayer *)
Returns masks defined in labeling options of a layer.
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.
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
Contains information relating to a node (i.e.
QString identifier
A string identifying the node.
QgsStyleEntityVisitorInterface::NodeType type
Node type.
Contains information relating to the style entity currently being visited.
const QgsStyleEntityInterface * entity
Reference to style entity being visited.
QString identifier
A string identifying the style entity.