49 setupBlankUi( layer->
name() );
53 connect( mLabelFieldComboBox, &QComboBox::currentTextChanged,
this, &QgsPointDisplacementRendererWidget::mLabelFieldComboBox_currentIndexChanged );
54 connect( mRendererComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsPointDisplacementRendererWidget::mRendererComboBox_currentIndexChanged );
55 connect( mPlacementComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsPointDisplacementRendererWidget::mPlacementComboBox_currentIndexChanged );
56 connect( mCircleWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsPointDisplacementRendererWidget::mCircleWidthSpinBox_valueChanged );
57 connect( mCircleColorButton, &
QgsColorButton::colorChanged,
this, &QgsPointDisplacementRendererWidget::mCircleColorButton_colorChanged );
58 connect( mDistanceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsPointDisplacementRendererWidget::mDistanceSpinBox_valueChanged );
61 connect( mCircleModificationSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsPointDisplacementRendererWidget::mCircleModificationSpinBox_valueChanged );
62 connect( mLabelDistanceFactorSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsPointDisplacementRendererWidget::mLabelDistanceFactorSpinBox_valueChanged );
63 connect( mScaleDependentLabelsCheckBox, &QCheckBox::stateChanged,
this, &QgsPointDisplacementRendererWidget::mScaleDependentLabelsCheckBox_stateChanged );
64 connect( mRendererSettingsButton, &QPushButton::clicked,
this, &QgsPointDisplacementRendererWidget::mRendererSettingsButton_clicked );
65 this->layout()->setContentsMargins( 0, 0, 0, 0 );
78 mRenderer = std::make_unique< QgsPointDisplacementRenderer >();
83 blockAllSignals(
true );
93 for (
const QgsField &f : layerFields )
95 mLabelFieldComboBox->addItem( f.name() );
97 mLabelFieldComboBox->addItem( tr(
"None" ) );
99 const QString currentLabelAttribute = mRenderer->labelAttributeName();
100 if ( !currentLabelAttribute.isEmpty() )
102 mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( currentLabelAttribute ) );
106 mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( tr(
"None" ) ) );
112 QStringList::const_iterator it = rendererList.constBegin();
113 for ( ; it != rendererList.constEnd(); ++it )
115 if ( *it != QLatin1String(
"pointDisplacement" ) && *it != QLatin1String(
"pointCluster" ) && *it != QLatin1String(
"heatmapRenderer" ) )
122 mCircleColorButton->setColorDialogTitle( tr(
"Select Color" ) );
123 mCircleColorButton->setContext( QStringLiteral(
"symbology" ) );
124 mCircleColorButton->setAllowOpacity(
true );
125 mCircleColorButton->setShowNoColor(
true );
126 mCircleColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
127 mLabelColorButton->setContext( QStringLiteral(
"symbology" ) );
128 mLabelColorButton->setColorDialogTitle( tr(
"Select Color" ) );
129 mLabelColorButton->setAllowOpacity(
true );
131 mCircleWidthSpinBox->setValue( mRenderer->circleWidth() );
132 mCircleColorButton->setColor( mRenderer->circleColor() );
133 mLabelColorButton->setColor( mRenderer->labelColor() );
134 mLabelFontButton->setCurrentFont( mRenderer->labelFont() );
135 mCircleModificationSpinBox->setClearValue( 0.0 );
136 mCircleModificationSpinBox->setValue( mRenderer->circleRadiusAddition() );
137 mLabelDistanceFactorSpinBox->setClearValue( 0.5 );
138 mLabelDistanceFactorSpinBox->setValue( mRenderer->labelDistanceFactor() );
139 mDistanceSpinBox->setValue( mRenderer->tolerance() );
140 mDistanceUnitWidget->setUnit( mRenderer->toleranceUnit() );
141 mDistanceUnitWidget->setMapUnitScale( mRenderer->toleranceMapUnitScale() );
142 mCenterSymbolToolButton->setSymbol( mRenderer->centerSymbol()->clone() );
144 mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( mRenderer->placement() ) );
147 mMinLabelScaleWidget->setScale( std::max( mRenderer->minimumLabelScale(), 0.0 ) );
148 if ( mRenderer->minimumLabelScale() > 0 )
150 mScaleDependentLabelsCheckBox->setCheckState( Qt::Checked );
154 mScaleDependentLabelsCheckBox->setCheckState( Qt::Unchecked );
155 mMinLabelScaleWidget->setEnabled(
false );
159 blockAllSignals(
false );
162 if ( mRenderer->embeddedRenderer() )
164 const QString rendererName = mRenderer->embeddedRenderer()->type();
165 const int rendererIndex = mRendererComboBox->findData( rendererName );
166 if ( rendererIndex != -1 )
168 mRendererComboBox->setCurrentIndex( rendererIndex );
169 mRendererComboBox_currentIndexChanged( rendererIndex );
174 connect( mLabelFontButton, &
QgsFontButton::changed,
this, &QgsPointDisplacementRendererWidget::labelFontChanged );
175 connect( mCenterSymbolToolButton, &
QgsSymbolButton::changed,
this, &QgsPointDisplacementRendererWidget::centerSymbolChanged );
176 mCenterSymbolToolButton->setDialogTitle( tr(
"Center symbol" ) );
177 mCenterSymbolToolButton->setLayer(
mLayer );
178 mCenterSymbolToolButton->registerExpressionContextGenerator(
this );
185 return mRenderer.get();
191 if ( mDistanceUnitWidget )
193 if ( mMinLabelScaleWidget )
196 mMinLabelScaleWidget->setShowCurrentScaleButton(
true );
198 if ( mCenterSymbolToolButton )
217 const auto constScopes = scopes;
225void QgsPointDisplacementRendererWidget::mLabelFieldComboBox_currentIndexChanged(
const QString &text )
229 if ( text == tr(
"None" ) )
231 mRenderer->setLabelAttributeName( QString() );
235 mRenderer->setLabelAttributeName( text );
241void QgsPointDisplacementRendererWidget::mRendererComboBox_currentIndexChanged(
int index )
243 const QString rendererId = mRendererComboBox->itemData( index ).toString();
248 const std::unique_ptr< QgsFeatureRenderer> oldRenderer( mRenderer->embeddedRenderer()->clone() );
250 mRenderer->setEmbeddedRenderer( tempRenderWidget->
renderer()->
clone() );
251 delete tempRenderWidget;
256void QgsPointDisplacementRendererWidget::mPlacementComboBox_currentIndexChanged(
int index )
265void QgsPointDisplacementRendererWidget::mRendererSettingsButton_clicked()
292void QgsPointDisplacementRendererWidget::labelFontChanged()
299 mRenderer->setLabelFont( mLabelFontButton->currentFont() );
303void QgsPointDisplacementRendererWidget::mCircleWidthSpinBox_valueChanged(
double d )
307 mRenderer->setCircleWidth( d );
312void QgsPointDisplacementRendererWidget::mCircleColorButton_colorChanged(
const QColor &newColor )
319 mRenderer->setCircleColor( newColor );
323void QgsPointDisplacementRendererWidget::mLabelColorButton_colorChanged(
const QColor &newColor )
330 mRenderer->setLabelColor( newColor );
334void QgsPointDisplacementRendererWidget::mCircleModificationSpinBox_valueChanged(
double d )
341 mRenderer->setCircleRadiusAddition( d );
345void QgsPointDisplacementRendererWidget::mLabelDistanceFactorSpinBox_valueChanged(
double d )
352 mRenderer->setLabelDistanceFactor( d );
356void QgsPointDisplacementRendererWidget::mDistanceSpinBox_valueChanged(
double d )
360 mRenderer->setTolerance( d );
365void QgsPointDisplacementRendererWidget::mDistanceUnitWidget_changed()
369 mRenderer->setToleranceUnit( mDistanceUnitWidget->unit() );
370 mRenderer->setToleranceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
375void QgsPointDisplacementRendererWidget::mScaleDependentLabelsCheckBox_stateChanged(
int state )
377 if ( state == Qt::Unchecked )
379 mMinLabelScaleWidget->setScale( 0 );
380 mMinLabelScaleWidget->setEnabled(
false );
384 mMinLabelScaleWidget->setEnabled(
true );
388void QgsPointDisplacementRendererWidget::minLabelScaleChanged(
double scale )
395 mRenderer->setMinimumLabelScale( scale );
399void QgsPointDisplacementRendererWidget::blockAllSignals(
bool block )
401 mLabelFieldComboBox->blockSignals( block );
402 mLabelFontButton->blockSignals( block );
403 mCircleWidthSpinBox->blockSignals( block );
404 mCircleColorButton->blockSignals( block );
405 mRendererComboBox->blockSignals( block );
406 mLabelColorButton->blockSignals( block );
407 mCircleModificationSpinBox->blockSignals( block );
408 mLabelDistanceFactorSpinBox->blockSignals( block );
409 mScaleDependentLabelsCheckBox->blockSignals( block );
410 mMinLabelScaleWidget->blockSignals( block );
411 mCenterSymbolToolButton->blockSignals( block );
412 mDistanceSpinBox->blockSignals( block );
413 mDistanceUnitWidget->blockSignals( block );
414 mPlacementComboBox->blockSignals( block );
417void QgsPointDisplacementRendererWidget::centerSymbolChanged()
419 mRenderer->setCenterSymbol( mCenterSymbolToolButton->clonedSymbol<
QgsMarkerSymbol >() );
423void QgsPointDisplacementRendererWidget::updateRendererFromWidget()
433void QgsPointDisplacementRendererWidget::setupBlankUi(
const QString &layerName )
435 QLabel *label =
new QLabel( tr(
"The point displacement renderer only applies to (single) point layers. \n'%1' is not a (single) point layer and cannot be displayed by the point displacement renderer." ).arg( layerName ),
this );
436 QVBoxLayout *layout =
new QVBoxLayout(
this );
437 layout->setContentsMargins( 0, 0, 0, 0 );
438 layout->addWidget( label );
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
A marker symbol type, for rendering Point and MultiPoint geometries.
Placement
Placement methods for dispersing points.
@ ConcentricRings
Place points in concentric rings around group.
@ Ring
Place points in a single ring around group.
@ Grid
Place points in a grid around group.
static QgsPointDisplacementRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsPointDisplacementRenderer from an existing renderer.
QStringList renderersList(QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All) const
Returns a list of available renderers.
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
void setAdditionalExpressionContextScopes(const QList< QgsExpressionContextScope > &scopes)
Sets a list of additional expression context scopes to show as available within the layer.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
@ RenderMetersInMapUnits
Meters value as Map units.
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
@ RenderMapUnits
Map units.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Single variable definition for use within a QgsExpressionContextScope.