40#include "moc_qgsmaskingwidget.cpp"
42QgsMaskingWidget::QgsMaskingWidget( QWidget *parent )
51void QgsMaskingWidget::onSelectionChanged()
54 const bool printMessage = mMaskTargetsWidget->selection().empty() != mMaskSourcesWidget->sourceSet().isEmpty();
56 if ( mMessageBarItem && !printMessage )
58 mMessageBar->popWidget( mMessageBarItem );
59 delete mMessageBarItem;
61 else if ( !mMessageBarItem && printMessage )
64 mMessageBar->pushItem( mMessageBarItem );
79QList<QPair<QString, QList<QgsSymbolLayerReference>>> symbolLayerMasks(
const QgsVectorLayer *layer )
84 QList<QPair<QString, QList<QgsSymbolLayerReference>>> mMasks;
86 if ( !sl->
masks().isEmpty() )
87 mMasks.push_back( qMakePair( sl->
id(), sl->
masks() ) );
93QString symbolLayerSelectiveMaskingSourceId(
const QgsVectorLayer *layer, QSet<QString> &maskedSymbolLayers )
98 QString maskingSourceSetId;
103 maskedSymbolLayers.insert( sl->
id() );
107 return maskingSourceSetId;
116void QgsMaskingWidget::populate()
118 const QSignalBlocker blockerSourceWidget( mMaskSourcesWidget );
119 const QSignalBlocker blockerTargetWidget( mMaskTargetsWidget );
121 mMaskSourcesWidget->update();
122 mMaskTargetsWidget->setLayer( mLayer );
125 QSet<QString> maskedSymbolLayers;
130 const QString selectiveMaskingSourceSetId = symbolLayerSelectiveMaskingSourceId( mLayer, maskedSymbolLayers );
131 if ( !selectiveMaskingSourceSetId.isEmpty() )
140 for (
auto layerIt = layers.begin(); layerIt != layers.end(); layerIt++ )
142 const QString layerId = layerIt.key();
143 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layerIt.value() );
148 const QList<QPair<QString, QList<QgsSymbolLayerReference>>> slMasks = symbolLayerMasks( vl );
149 for (
const QPair<QString, QList<QgsSymbolLayerReference>> &p : slMasks )
151 const QString &sourceSymbolLayerId = p.first;
154 if ( ref.
layerId() == mLayer->id() )
166 for (
auto it = labelMasks.begin(); it != labelMasks.end(); it++ )
168 const QString &ruleKey = it.key();
169 for (
auto it2 = it.value().begin(); it2 != it.value().end(); it2++ )
171 if ( it2.key() == mLayer->id() )
174 maskedSymbolLayers.unite( it2.value().symbolLayerIdsToMask );
183 mMaskSourcesWidget->setSourceSet( maskSources );
184 mMaskTargetsWidget->setSelection( maskedSymbolLayers );
187void QgsMaskingWidget::apply()
192 QSet<QString> layersToRefresh;
193 const QSet<QString> maskedSymbolLayerIds = mMaskTargetsWidget->selection();
197 SymbolLayerVisitor selectiveMaskingSourceSetter( [&](
const QgsSymbolLayer *sl ) {
199 if ( !maskSourceSet.
isValid() )
205 const bool isMasked = maskedSymbolLayerIds.contains( sl->
id() );
209 if ( mLayer && mLayer->renderer() )
211 mLayer->renderer()->accept( &selectiveMaskingSourceSetter );
215 layersToRefresh.insert( source.layerId() );
219 for (
auto layerIt = layers.begin(); layerIt != layers.end(); layerIt++ )
221 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layerIt.value() );
237 if ( ref.
layerId() != mLayer->id() )
238 newMasks.append( ref );
240 if ( !maskSourceSet.
isValid() )
244 switch ( source.sourceType() )
247 if ( source.layerId() == layerIt.key() && source.sourceId() == sl->
id() )
250 for (
const QString &maskedId : maskedSymbolLayerIds )
255 layersToRefresh.insert( source.layerId() );
285 if ( ref.
layerId() != mLayer->id() )
286 newMasks.append( ref );
288 if ( !maskSourceSet.
isValid() )
293 switch ( source.sourceType() )
296 if ( source.layerId() == layerIt.key() && source.sourceId() == labelProvider )
298 for (
const QString &maskedId : maskedSymbolLayerIds )
303 layersToRefresh.insert( source.layerId() );
320 mLayer->triggerRepaint();
322 for (
const QString &layerId : layersToRefresh )
329SymbolLayerVisitor::SymbolLayerVisitor( SymbolLayerVisitor::SymbolLayerCallback callback )
330 : mCallback( std::move( callback ) )
341void SymbolLayerVisitor::visitSymbol(
const QgsSymbol *symbol,
const QString &leafIdentifier )
352 visitSymbol( subSymbol, leafIdentifier );
361 if ( symbolEntity->symbol() )
362 visitSymbol( symbolEntity->symbol(), leaf.
identifier );
@ Label
A mask generated from a labeling provider.
@ SymbolLayer
A mask generated from a symbol layer.
@ Warning
Warning message.
virtual QStringList subProviders() const
Gets list of sub-providers within the layer's labeling.
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.
Special symbol layer that uses its sub symbol as a selective mask.
void setMasks(const QList< QgsSymbolLayerReference > &maskedLayers)
Sets the symbol layers that will be masked by the sub symbol's shape.
QList< QgsSymbolLayerReference > masks() const override
Returns a list of references to symbol layers that are masked by the sub symbol's shape.
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).
const QgsSelectiveMaskingSourceSetManager * selectiveMaskingSourceSetManager() const
Returns the project's selective masking set manager, which manages storage of a set of selective mask...
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Encapsulates a single source for selective masking (e.g.
QgsSelectiveMaskingSourceSet setById(const QString &id) const
Returns the set with a matching id, or an invalid set if no matching sets were found.
Represents a named set of selective masking sources (QgsSelectiveMaskSource).
QString id() const
Returns a unique identifier for the set.
QVector< QgsSelectiveMaskSource > sources() const
Returns the list of selective mask sources configured in this set.
void append(const QgsSelectiveMaskSource &source)
Appends a source to the set.
bool isValid() const
Returns true if the source set is valid, or false if it is invalid (default constructed).
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.
QString symbolLayerIdV2() const
The symbol layer's id.
QString layerId() const
The referenced vector layer / feature renderer.
Abstract base class for symbol layers.
QString selectiveMaskingSourceSetId() const
Returns the selective masking source set ID for this symbol layer.
void setSelectiveMaskingSourceSetId(const QString &id)
Sets the selective masking source set id for this symbol 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 > collectObjectsMaskedByLabelsFromLayer(const QgsVectorLayer *layer, const QHash< QString, QgsSelectiveMaskingSourceSet > &selectiveMaskingSourceSets, const QVector< QgsVectorLayer * > &allRenderedVectorLayers)
Returns all objects that will be masked by the labels for a given vector layer.
Represents a vector layer which manages a vector based dataset.
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.
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.