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 >();
81 blockAllSignals(
true );
91 for (
const QgsField &f : layerFields )
93 mLabelFieldComboBox->addItem( f.name() );
95 mLabelFieldComboBox->addItem( tr(
"None" ) );
97 QString currentLabelAttribute = mRenderer->labelAttributeName();
98 if ( !currentLabelAttribute.isEmpty() )
100 mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( currentLabelAttribute ) );
104 mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( tr(
"None" ) ) );
110 QStringList::const_iterator it = rendererList.constBegin();
111 for ( ; it != rendererList.constEnd(); ++it )
113 if ( *it != QLatin1String(
"pointDisplacement" ) && *it != QLatin1String(
"pointCluster" ) && *it != QLatin1String(
"heatmapRenderer" ) )
120 mCircleColorButton->setColorDialogTitle( tr(
"Select Color" ) );
121 mCircleColorButton->setContext( QStringLiteral(
"symbology" ) );
122 mCircleColorButton->setAllowOpacity(
true );
123 mCircleColorButton->setShowNoColor(
true );
124 mCircleColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
125 mLabelColorButton->setContext( QStringLiteral(
"symbology" ) );
126 mLabelColorButton->setColorDialogTitle( tr(
"Select Color" ) );
127 mLabelColorButton->setAllowOpacity(
true );
129 mCircleWidthSpinBox->setValue( mRenderer->circleWidth() );
130 mCircleColorButton->setColor( mRenderer->circleColor() );
131 mLabelColorButton->setColor( mRenderer->labelColor() );
132 mLabelFontButton->setCurrentFont( mRenderer->labelFont() );
133 mCircleModificationSpinBox->setClearValue( 0.0 );
134 mCircleModificationSpinBox->setValue( mRenderer->circleRadiusAddition() );
135 mLabelDistanceFactorSpinBox->setClearValue( 0.5 );
136 mLabelDistanceFactorSpinBox->setValue( mRenderer->labelDistanceFactor() );
137 mDistanceSpinBox->setValue( mRenderer->tolerance() );
138 mDistanceUnitWidget->setUnit( mRenderer->toleranceUnit() );
139 mDistanceUnitWidget->setMapUnitScale( mRenderer->toleranceMapUnitScale() );
140 mCenterSymbolToolButton->setSymbol( mRenderer->centerSymbol()->clone() );
142 mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( mRenderer->placement() ) );
145 mMinLabelScaleWidget->setScale( std::max( mRenderer->minimumLabelScale(), 0.0 ) );
146 if ( mRenderer->minimumLabelScale() > 0 )
148 mScaleDependentLabelsCheckBox->setCheckState( Qt::Checked );
152 mScaleDependentLabelsCheckBox->setCheckState( Qt::Unchecked );
153 mMinLabelScaleWidget->setEnabled(
false );
157 blockAllSignals(
false );
160 if ( mRenderer->embeddedRenderer() )
162 QString rendererName = mRenderer->embeddedRenderer()->type();
163 int rendererIndex = mRendererComboBox->findData( rendererName );
164 if ( rendererIndex != -1 )
166 mRendererComboBox->setCurrentIndex( rendererIndex );
167 mRendererComboBox_currentIndexChanged( rendererIndex );
172 connect( mLabelFontButton, &
QgsFontButton::changed,
this, &QgsPointDisplacementRendererWidget::labelFontChanged );
173 connect( mCenterSymbolToolButton, &
QgsSymbolButton::changed,
this, &QgsPointDisplacementRendererWidget::centerSymbolChanged );
174 mCenterSymbolToolButton->setDialogTitle( tr(
"Center symbol" ) );
175 mCenterSymbolToolButton->setLayer(
mLayer );
176 mCenterSymbolToolButton->registerExpressionContextGenerator(
this );
183 return mRenderer.get();
189 if ( mDistanceUnitWidget )
191 if ( mMinLabelScaleWidget )
194 mMinLabelScaleWidget->setShowCurrentScaleButton(
true );
196 if ( mCenterSymbolToolButton )
215 const auto constScopes = scopes;
223 void QgsPointDisplacementRendererWidget::mLabelFieldComboBox_currentIndexChanged(
const QString &text )
227 if ( text == tr(
"None" ) )
229 mRenderer->setLabelAttributeName( QString() );
233 mRenderer->setLabelAttributeName( text );
239 void QgsPointDisplacementRendererWidget::mRendererComboBox_currentIndexChanged(
int index )
241 QString rendererId = mRendererComboBox->itemData( index ).toString();
246 std::unique_ptr< QgsFeatureRenderer> oldRenderer( mRenderer->embeddedRenderer()->clone() );
248 mRenderer->setEmbeddedRenderer( tempRenderWidget->
renderer()->
clone() );
249 delete tempRenderWidget;
254 void QgsPointDisplacementRendererWidget::mPlacementComboBox_currentIndexChanged(
int index )
263 void QgsPointDisplacementRendererWidget::mRendererSettingsButton_clicked()
290 void QgsPointDisplacementRendererWidget::labelFontChanged()
297 mRenderer->setLabelFont( mLabelFontButton->currentFont() );
301 void QgsPointDisplacementRendererWidget::mCircleWidthSpinBox_valueChanged(
double d )
305 mRenderer->setCircleWidth( d );
310 void QgsPointDisplacementRendererWidget::mCircleColorButton_colorChanged(
const QColor &newColor )
317 mRenderer->setCircleColor( newColor );
321 void QgsPointDisplacementRendererWidget::mLabelColorButton_colorChanged(
const QColor &newColor )
328 mRenderer->setLabelColor( newColor );
332 void QgsPointDisplacementRendererWidget::mCircleModificationSpinBox_valueChanged(
double d )
339 mRenderer->setCircleRadiusAddition( d );
343 void QgsPointDisplacementRendererWidget::mLabelDistanceFactorSpinBox_valueChanged(
double d )
350 mRenderer->setLabelDistanceFactor( d );
354 void QgsPointDisplacementRendererWidget::mDistanceSpinBox_valueChanged(
double d )
358 mRenderer->setTolerance( d );
363 void QgsPointDisplacementRendererWidget::mDistanceUnitWidget_changed()
367 mRenderer->setToleranceUnit( mDistanceUnitWidget->unit() );
368 mRenderer->setToleranceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
373 void QgsPointDisplacementRendererWidget::mScaleDependentLabelsCheckBox_stateChanged(
int state )
375 if ( state == Qt::Unchecked )
377 mMinLabelScaleWidget->setScale( 0 );
378 mMinLabelScaleWidget->setEnabled(
false );
382 mMinLabelScaleWidget->setEnabled(
true );
386 void QgsPointDisplacementRendererWidget::minLabelScaleChanged(
double scale )
393 mRenderer->setMinimumLabelScale( scale );
397 void QgsPointDisplacementRendererWidget::blockAllSignals(
bool block )
399 mLabelFieldComboBox->blockSignals( block );
400 mLabelFontButton->blockSignals( block );
401 mCircleWidthSpinBox->blockSignals( block );
402 mCircleColorButton->blockSignals( block );
403 mRendererComboBox->blockSignals( block );
404 mLabelColorButton->blockSignals( block );
405 mCircleModificationSpinBox->blockSignals( block );
406 mLabelDistanceFactorSpinBox->blockSignals( block );
407 mScaleDependentLabelsCheckBox->blockSignals( block );
408 mMinLabelScaleWidget->blockSignals( block );
409 mCenterSymbolToolButton->blockSignals( block );
410 mDistanceSpinBox->blockSignals( block );
411 mDistanceUnitWidget->blockSignals( block );
412 mPlacementComboBox->blockSignals( block );
415 void QgsPointDisplacementRendererWidget::centerSymbolChanged()
417 mRenderer->setCenterSymbol( mCenterSymbolToolButton->clonedSymbol<
QgsMarkerSymbol >() );
421 void QgsPointDisplacementRendererWidget::updateRendererFromWidget()
431 void QgsPointDisplacementRendererWidget::setupBlankUi(
const QString &layerName )
433 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 );
434 QVBoxLayout *layout =
new QVBoxLayout(
this );
435 layout->setContentsMargins( 0, 0, 0, 0 );
436 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.
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...
static bool isMultiType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a multi type.
Single variable definition for use within a QgsExpressionContextScope.