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 );
77 mRenderer = std::make_unique< QgsPointDisplacementRenderer >();
82 blockAllSignals(
true );
92 for (
const QgsField &f : layerFields )
94 mLabelFieldComboBox->addItem( f.name() );
96 mLabelFieldComboBox->addItem( tr(
"None" ) );
98 const QString currentLabelAttribute = mRenderer->labelAttributeName();
99 if ( !currentLabelAttribute.isEmpty() )
101 mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( currentLabelAttribute ) );
105 mLabelFieldComboBox->setCurrentIndex( mLabelFieldComboBox->findText( tr(
"None" ) ) );
111 QStringList::const_iterator it = rendererList.constBegin();
112 for ( ; it != rendererList.constEnd(); ++it )
114 if ( *it != QLatin1String(
"pointDisplacement" ) && *it != QLatin1String(
"pointCluster" ) && *it != QLatin1String(
"heatmapRenderer" ) )
121 mCircleColorButton->setColorDialogTitle( tr(
"Select Color" ) );
122 mCircleColorButton->setContext( QStringLiteral(
"symbology" ) );
123 mCircleColorButton->setAllowOpacity(
true );
124 mCircleColorButton->setShowNoColor(
true );
125 mCircleColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
126 mLabelColorButton->setContext( QStringLiteral(
"symbology" ) );
127 mLabelColorButton->setColorDialogTitle( tr(
"Select Color" ) );
128 mLabelColorButton->setAllowOpacity(
true );
130 mCircleWidthSpinBox->setValue( mRenderer->circleWidth() );
131 mCircleColorButton->setColor( mRenderer->circleColor() );
132 mLabelColorButton->setColor( mRenderer->labelColor() );
133 mLabelFontButton->setCurrentFont( mRenderer->labelFont() );
134 mCircleModificationSpinBox->setClearValue( 0.0 );
135 mCircleModificationSpinBox->setValue( mRenderer->circleRadiusAddition() );
136 mLabelDistanceFactorSpinBox->setClearValue( 0.5 );
137 mLabelDistanceFactorSpinBox->setValue( mRenderer->labelDistanceFactor() );
138 mDistanceSpinBox->setValue( mRenderer->tolerance() );
139 mDistanceUnitWidget->setUnit( mRenderer->toleranceUnit() );
140 mDistanceUnitWidget->setMapUnitScale( mRenderer->toleranceMapUnitScale() );
141 mCenterSymbolToolButton->setSymbol( mRenderer->centerSymbol()->clone() );
143 mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( mRenderer->placement() ) );
146 mMinLabelScaleWidget->setScale( std::max( mRenderer->minimumLabelScale(), 0.0 ) );
147 if ( mRenderer->minimumLabelScale() > 0 )
149 mScaleDependentLabelsCheckBox->setCheckState( Qt::Checked );
153 mScaleDependentLabelsCheckBox->setCheckState( Qt::Unchecked );
154 mMinLabelScaleWidget->setEnabled(
false );
158 blockAllSignals(
false );
161 if ( mRenderer->embeddedRenderer() )
163 const QString rendererName = mRenderer->embeddedRenderer()->type();
164 const int rendererIndex = mRendererComboBox->findData( rendererName );
165 if ( rendererIndex != -1 )
167 mRendererComboBox->setCurrentIndex( rendererIndex );
168 mRendererComboBox_currentIndexChanged( rendererIndex );
173 connect( mLabelFontButton, &
QgsFontButton::changed,
this, &QgsPointDisplacementRendererWidget::labelFontChanged );
174 connect( mCenterSymbolToolButton, &
QgsSymbolButton::changed,
this, &QgsPointDisplacementRendererWidget::centerSymbolChanged );
175 mCenterSymbolToolButton->setDialogTitle( tr(
"Center symbol" ) );
176 mCenterSymbolToolButton->setLayer(
mLayer );
177 mCenterSymbolToolButton->registerExpressionContextGenerator(
this );
184 return mRenderer.get();
190 if ( mDistanceUnitWidget )
192 if ( mMinLabelScaleWidget )
195 mMinLabelScaleWidget->setShowCurrentScaleButton(
true );
197 if ( mCenterSymbolToolButton )
216 const auto constScopes = scopes;
224void QgsPointDisplacementRendererWidget::mLabelFieldComboBox_currentIndexChanged(
const QString &text )
228 if ( text == tr(
"None" ) )
230 mRenderer->setLabelAttributeName( QString() );
234 mRenderer->setLabelAttributeName( text );
240void QgsPointDisplacementRendererWidget::mRendererComboBox_currentIndexChanged(
int index )
242 const QString rendererId = mRendererComboBox->itemData( index ).toString();
247 const std::unique_ptr< QgsFeatureRenderer> oldRenderer( mRenderer->embeddedRenderer()->clone() );
249 mRenderer->setEmbeddedRenderer( tempRenderWidget->
renderer()->
clone() );
250 delete tempRenderWidget;
255void QgsPointDisplacementRendererWidget::mPlacementComboBox_currentIndexChanged(
int index )
264void QgsPointDisplacementRendererWidget::mRendererSettingsButton_clicked()
291void QgsPointDisplacementRendererWidget::labelFontChanged()
298 mRenderer->setLabelFont( mLabelFontButton->currentFont() );
302void QgsPointDisplacementRendererWidget::mCircleWidthSpinBox_valueChanged(
double d )
306 mRenderer->setCircleWidth( d );
311void QgsPointDisplacementRendererWidget::mCircleColorButton_colorChanged(
const QColor &newColor )
318 mRenderer->setCircleColor( newColor );
322void QgsPointDisplacementRendererWidget::mLabelColorButton_colorChanged(
const QColor &newColor )
329 mRenderer->setLabelColor( newColor );
333void QgsPointDisplacementRendererWidget::mCircleModificationSpinBox_valueChanged(
double d )
340 mRenderer->setCircleRadiusAddition( d );
344void QgsPointDisplacementRendererWidget::mLabelDistanceFactorSpinBox_valueChanged(
double d )
351 mRenderer->setLabelDistanceFactor( d );
355void QgsPointDisplacementRendererWidget::mDistanceSpinBox_valueChanged(
double d )
359 mRenderer->setTolerance( d );
364void QgsPointDisplacementRendererWidget::mDistanceUnitWidget_changed()
368 mRenderer->setToleranceUnit( mDistanceUnitWidget->unit() );
369 mRenderer->setToleranceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
374void QgsPointDisplacementRendererWidget::mScaleDependentLabelsCheckBox_stateChanged(
int state )
376 if ( state == Qt::Unchecked )
378 mMinLabelScaleWidget->setScale( 0 );
379 mMinLabelScaleWidget->setEnabled(
false );
383 mMinLabelScaleWidget->setEnabled(
true );
387void QgsPointDisplacementRendererWidget::minLabelScaleChanged(
double scale )
394 mRenderer->setMinimumLabelScale( scale );
398void QgsPointDisplacementRendererWidget::blockAllSignals(
bool block )
400 mLabelFieldComboBox->blockSignals( block );
401 mLabelFontButton->blockSignals( block );
402 mCircleWidthSpinBox->blockSignals( block );
403 mCircleColorButton->blockSignals( block );
404 mRendererComboBox->blockSignals( block );
405 mLabelColorButton->blockSignals( block );
406 mCircleModificationSpinBox->blockSignals( block );
407 mLabelDistanceFactorSpinBox->blockSignals( block );
408 mScaleDependentLabelsCheckBox->blockSignals( block );
409 mMinLabelScaleWidget->blockSignals( block );
410 mCenterSymbolToolButton->blockSignals( block );
411 mDistanceSpinBox->blockSignals( block );
412 mDistanceUnitWidget->blockSignals( block );
413 mPlacementComboBox->blockSignals( block );
416void QgsPointDisplacementRendererWidget::centerSymbolChanged()
418 mRenderer->setCenterSymbol( mCenterSymbolToolButton->clonedSymbol<
QgsMarkerSymbol >() );
422void QgsPointDisplacementRendererWidget::updateRendererFromWidget()
432void QgsPointDisplacementRendererWidget::setupBlankUi(
const QString &layerName )
434 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 );
435 QVBoxLayout *layout =
new QVBoxLayout(
this );
436 layout->setContentsMargins( 0, 0, 0, 0 );
437 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.