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;
225 void QgsPointDisplacementRendererWidget::mLabelFieldComboBox_currentIndexChanged(
const QString &text )
229 if ( text == tr(
"None" ) )
231 mRenderer->setLabelAttributeName( QString() );
235 mRenderer->setLabelAttributeName( text );
241 void 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;
256 void QgsPointDisplacementRendererWidget::mPlacementComboBox_currentIndexChanged(
int index )
265 void QgsPointDisplacementRendererWidget::mRendererSettingsButton_clicked()
292 void QgsPointDisplacementRendererWidget::labelFontChanged()
299 mRenderer->setLabelFont( mLabelFontButton->currentFont() );
303 void QgsPointDisplacementRendererWidget::mCircleWidthSpinBox_valueChanged(
double d )
307 mRenderer->setCircleWidth( d );
312 void QgsPointDisplacementRendererWidget::mCircleColorButton_colorChanged(
const QColor &newColor )
319 mRenderer->setCircleColor( newColor );
323 void QgsPointDisplacementRendererWidget::mLabelColorButton_colorChanged(
const QColor &newColor )
330 mRenderer->setLabelColor( newColor );
334 void QgsPointDisplacementRendererWidget::mCircleModificationSpinBox_valueChanged(
double d )
341 mRenderer->setCircleRadiusAddition( d );
345 void QgsPointDisplacementRendererWidget::mLabelDistanceFactorSpinBox_valueChanged(
double d )
352 mRenderer->setLabelDistanceFactor( d );
356 void QgsPointDisplacementRendererWidget::mDistanceSpinBox_valueChanged(
double d )
360 mRenderer->setTolerance( d );
365 void QgsPointDisplacementRendererWidget::mDistanceUnitWidget_changed()
369 mRenderer->setToleranceUnit( mDistanceUnitWidget->unit() );
370 mRenderer->setToleranceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
375 void QgsPointDisplacementRendererWidget::mScaleDependentLabelsCheckBox_stateChanged(
int state )
377 if ( state == Qt::Unchecked )
379 mMinLabelScaleWidget->setScale( 0 );
380 mMinLabelScaleWidget->setEnabled(
false );
384 mMinLabelScaleWidget->setEnabled(
true );
388 void QgsPointDisplacementRendererWidget::minLabelScaleChanged(
double scale )
395 mRenderer->setMinimumLabelScale( scale );
399 void 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 );
417 void QgsPointDisplacementRendererWidget::centerSymbolChanged()
419 mRenderer->setCenterSymbol( mCenterSymbolToolButton->clonedSymbol<
QgsMarkerSymbol >() );
423 void QgsPointDisplacementRendererWidget::updateRendererFromWidget()
433 void 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 );