19#include "moc_qgspointdisplacementrendererwidget.cpp"
48 setupBlankUi( layer->
name() );
52 connect( mLabelFieldComboBox, &QComboBox::currentTextChanged,
this, &QgsPointDisplacementRendererWidget::mLabelFieldComboBox_currentIndexChanged );
53 connect( mRendererComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsPointDisplacementRendererWidget::mRendererComboBox_currentIndexChanged );
54 connect( mPlacementComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsPointDisplacementRendererWidget::mPlacementComboBox_currentIndexChanged );
55 connect( mCircleWidthSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointDisplacementRendererWidget::mCircleWidthSpinBox_valueChanged );
56 connect( mCircleColorButton, &
QgsColorButton::colorChanged,
this, &QgsPointDisplacementRendererWidget::mCircleColorButton_colorChanged );
57 connect( mDistanceSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointDisplacementRendererWidget::mDistanceSpinBox_valueChanged );
60 connect( mCircleModificationSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointDisplacementRendererWidget::mCircleModificationSpinBox_valueChanged );
61 connect( mLabelDistanceFactorSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsPointDisplacementRendererWidget::mLabelDistanceFactorSpinBox_valueChanged );
62 connect( mScaleDependentLabelsCheckBox, &QCheckBox::stateChanged,
this, &QgsPointDisplacementRendererWidget::mScaleDependentLabelsCheckBox_stateChanged );
63 connect( mRendererSettingsButton, &QPushButton::clicked,
this, &QgsPointDisplacementRendererWidget::mRendererSettingsButton_clicked );
64 this->layout()->setContentsMargins( 0, 0, 0, 0 );
76 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 const 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 const QString rendererName = mRenderer->embeddedRenderer()->type();
163 const 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 )
222void QgsPointDisplacementRendererWidget::mLabelFieldComboBox_currentIndexChanged(
const QString &text )
226 if ( text == tr(
"None" ) )
228 mRenderer->setLabelAttributeName( QString() );
232 mRenderer->setLabelAttributeName( text );
238void QgsPointDisplacementRendererWidget::mRendererComboBox_currentIndexChanged(
int index )
240 const QString rendererId = mRendererComboBox->itemData( index ).toString();
245 const std::unique_ptr<QgsFeatureRenderer> oldRenderer( mRenderer->embeddedRenderer()->clone() );
247 mRenderer->setEmbeddedRenderer( tempRenderWidget->
renderer()->
clone() );
248 delete tempRenderWidget;
253void QgsPointDisplacementRendererWidget::mPlacementComboBox_currentIndexChanged(
int index )
262void QgsPointDisplacementRendererWidget::mRendererSettingsButton_clicked()
289void QgsPointDisplacementRendererWidget::labelFontChanged()
296 mRenderer->setLabelFont( mLabelFontButton->currentFont() );
300void QgsPointDisplacementRendererWidget::mCircleWidthSpinBox_valueChanged(
double d )
304 mRenderer->setCircleWidth( d );
309void QgsPointDisplacementRendererWidget::mCircleColorButton_colorChanged(
const QColor &newColor )
316 mRenderer->setCircleColor( newColor );
320void QgsPointDisplacementRendererWidget::mLabelColorButton_colorChanged(
const QColor &newColor )
327 mRenderer->setLabelColor( newColor );
331void QgsPointDisplacementRendererWidget::mCircleModificationSpinBox_valueChanged(
double d )
338 mRenderer->setCircleRadiusAddition( d );
342void QgsPointDisplacementRendererWidget::mLabelDistanceFactorSpinBox_valueChanged(
double d )
349 mRenderer->setLabelDistanceFactor( d );
353void QgsPointDisplacementRendererWidget::mDistanceSpinBox_valueChanged(
double d )
357 mRenderer->setTolerance( d );
362void QgsPointDisplacementRendererWidget::mDistanceUnitWidget_changed()
366 mRenderer->setToleranceUnit( mDistanceUnitWidget->unit() );
367 mRenderer->setToleranceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
372void QgsPointDisplacementRendererWidget::mScaleDependentLabelsCheckBox_stateChanged(
int state )
374 if ( state == Qt::Unchecked )
376 mMinLabelScaleWidget->setScale( 0 );
377 mMinLabelScaleWidget->setEnabled(
false );
381 mMinLabelScaleWidget->setEnabled(
true );
385void QgsPointDisplacementRendererWidget::minLabelScaleChanged(
double scale )
392 mRenderer->setMinimumLabelScale( scale );
396void QgsPointDisplacementRendererWidget::blockAllSignals(
bool block )
398 mLabelFieldComboBox->blockSignals( block );
399 mLabelFontButton->blockSignals( block );
400 mCircleWidthSpinBox->blockSignals( block );
401 mCircleColorButton->blockSignals( block );
402 mRendererComboBox->blockSignals( block );
403 mLabelColorButton->blockSignals( block );
404 mCircleModificationSpinBox->blockSignals( block );
405 mLabelDistanceFactorSpinBox->blockSignals( block );
406 mScaleDependentLabelsCheckBox->blockSignals( block );
407 mMinLabelScaleWidget->blockSignals( block );
408 mCenterSymbolToolButton->blockSignals( block );
409 mDistanceSpinBox->blockSignals( block );
410 mDistanceUnitWidget->blockSignals( block );
411 mPlacementComboBox->blockSignals( block );
414void QgsPointDisplacementRendererWidget::centerSymbolChanged()
416 mRenderer->setCenterSymbol( mCenterSymbolToolButton->clonedSymbol<
QgsMarkerSymbol>() );
420void QgsPointDisplacementRendererWidget::updateRendererFromWidget()
430void QgsPointDisplacementRendererWidget::setupBlankUi(
const QString &layerName )
432 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 );
433 QVBoxLayout *layout =
new QVBoxLayout(
this );
434 layout->setContentsMargins( 0, 0, 0, 0 );
435 layout->addWidget( label );
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MetersInMapUnits
Meters value as Map units.
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.
Abstract base class for all 2D vector feature renderers.
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.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
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.