31#include "moc_qgsheatmaprendererwidget.cpp"
42 if (
auto *lMapCanvas =
mContext.mapCanvas() )
44 expContext = lMapCanvas->createExpressionContext();
59 const auto constAdditionalExpressionContextScopes =
mContext.additionalExpressionContextScopes();
81 QLabel *label = new QLabel(
83 "The heatmap renderer only applies to point and multipoint layers. \n"
84 "'%1' is not a point layer and cannot be rendered as a heatmap."
86 .arg( layer->name() ),
90 setLayout( new QGridLayout() );
91 layout()->addWidget( label );
97 connect( mRadiusSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsHeatmapRendererWidget::mRadiusSpinBox_valueChanged );
98 connect( mMaxSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsHeatmapRendererWidget::mMaxSpinBox_valueChanged );
99 connect( mQualitySlider, &QSlider::valueChanged,
this, &QgsHeatmapRendererWidget::mQualitySlider_valueChanged );
100 this->layout()->setContentsMargins( 0, 0, 0, 0 );
102 mRadiusUnitWidget->setUnits(
105 mWeightExpressionWidget->registerExpressionContextGenerator(
this );
106 mWeightExpressionWidget->setAllowEmptyFieldName(
true );
114 mRenderer = std::make_unique<QgsHeatmapRenderer>();
116 renderer->copyRendererData( mRenderer.get() );
119 btnColorRamp->setShowGradientOnly(
true );
122 connect( mLegendSettingsButton, &QPushButton::clicked,
this, &QgsHeatmapRendererWidget::showLegendSettings );
124 if ( mRenderer->colorRamp() )
126 btnColorRamp->blockSignals(
true );
127 btnColorRamp->setColorRamp( mRenderer->colorRamp() );
128 btnColorRamp->blockSignals(
false );
130 mRadiusSpinBox->blockSignals(
true );
131 mRadiusSpinBox->setValue( mRenderer->radius() );
132 mRadiusSpinBox->blockSignals(
false );
133 mRadiusUnitWidget->blockSignals(
true );
134 mRadiusUnitWidget->setUnit( mRenderer->radiusUnit() );
135 mRadiusUnitWidget->setMapUnitScale( mRenderer->radiusMapUnitScale() );
136 mRadiusUnitWidget->blockSignals(
false );
137 mMaxSpinBox->blockSignals(
true );
138 mMaxSpinBox->setValue( mRenderer->maximumValue() );
139 mMaxSpinBox->blockSignals(
false );
140 mQualitySlider->blockSignals(
true );
141 mQualitySlider->setValue( mRenderer->renderQuality() );
142 mQualitySlider->blockSignals(
false );
144 mWeightExpressionWidget->setLayer( layer );
145 mWeightExpressionWidget->setField( mRenderer->weightExpression() );
156 return mRenderer.get();
162 if (
auto *lMapCanvas =
context.mapCanvas() )
163 mRadiusUnitWidget->setMapCanvas( lMapCanvas );
166void QgsHeatmapRendererWidget::applyColorRamp()
173 QgsColorRamp *ramp = btnColorRamp->colorRamp();
177 mRenderer->setColorRamp( ramp );
181void QgsHeatmapRendererWidget::showLegendSettings()
189 legendPanel->
setSettings( mRenderer->legendSettings() );
191 mRenderer->setLegendSettings( legendPanel->
settings() );
199 dialog.setUseContinuousRampCheckBoxVisibility(
false );
200 dialog.setWindowTitle( tr(
"Legend Settings" ) );
203 mRenderer->setLegendSettings( dialog.settings() );
209void QgsHeatmapRendererWidget::mRadiusUnitWidget_changed()
216 mRenderer->setRadiusUnit( mRadiusUnitWidget->unit() );
217 mRenderer->setRadiusMapUnitScale( mRadiusUnitWidget->getMapUnitScale() );
221void QgsHeatmapRendererWidget::mRadiusSpinBox_valueChanged(
double d )
228 mRenderer->setRadius( d );
232void QgsHeatmapRendererWidget::mMaxSpinBox_valueChanged(
double d )
239 mRenderer->setMaximumValue( d );
243void QgsHeatmapRendererWidget::mQualitySlider_valueChanged(
int v )
250 mRenderer->setRenderQuality( v );
254void QgsHeatmapRendererWidget::weightExpressionChanged(
const QString &expression )
256 mRenderer->setWeightExpression( expression );
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
@ MetersInMapUnits
Meters value as Map units.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Abstract base class for all 2D vector feature renderers.
@ HeatmapRadius
Heatmap renderer radius.
@ HeatmapMaximum
Heatmap maximum value.
static QgsHeatmapRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Contains configuration for rendering maps.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A database of saved style entities, including symbols, color ramps, text formats and others.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.