31#include "moc_qgsheatmaprendererwidget.cpp"
42 if (
auto *lMapCanvas =
mContext.mapCanvas() )
44 expContext = lMapCanvas->createExpressionContext();
58 const auto constAdditionalExpressionContextScopes =
mContext.additionalExpressionContextScopes();
80 QLabel *label = new QLabel( tr(
"The heatmap renderer only applies to point and multipoint layers. \n"
81 "'%1' is not a point layer and cannot be rendered as a heatmap." )
82 .arg( layer->name() ),
85 setLayout( new QGridLayout() );
86 layout()->addWidget( label );
92 connect( mRadiusSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsHeatmapRendererWidget::mRadiusSpinBox_valueChanged );
93 connect( mMaxSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsHeatmapRendererWidget::mMaxSpinBox_valueChanged );
94 connect( mQualitySlider, &QSlider::valueChanged,
this, &QgsHeatmapRendererWidget::mQualitySlider_valueChanged );
95 this->layout()->setContentsMargins( 0, 0, 0, 0 );
98 mWeightExpressionWidget->registerExpressionContextGenerator(
this );
99 mWeightExpressionWidget->setAllowEmptyFieldName(
true );
107 mRenderer = std::make_unique<QgsHeatmapRenderer>();
109 renderer->copyRendererData( mRenderer.get() );
112 btnColorRamp->setShowGradientOnly(
true );
115 connect( mLegendSettingsButton, &QPushButton::clicked,
this, &QgsHeatmapRendererWidget::showLegendSettings );
117 if ( mRenderer->colorRamp() )
119 btnColorRamp->blockSignals(
true );
120 btnColorRamp->setColorRamp( mRenderer->colorRamp() );
121 btnColorRamp->blockSignals(
false );
123 mRadiusSpinBox->blockSignals(
true );
124 mRadiusSpinBox->setValue( mRenderer->radius() );
125 mRadiusSpinBox->blockSignals(
false );
126 mRadiusUnitWidget->blockSignals(
true );
127 mRadiusUnitWidget->setUnit( mRenderer->radiusUnit() );
128 mRadiusUnitWidget->setMapUnitScale( mRenderer->radiusMapUnitScale() );
129 mRadiusUnitWidget->blockSignals(
false );
130 mMaxSpinBox->blockSignals(
true );
131 mMaxSpinBox->setValue( mRenderer->maximumValue() );
132 mMaxSpinBox->blockSignals(
false );
133 mQualitySlider->blockSignals(
true );
134 mQualitySlider->setValue( mRenderer->renderQuality() );
135 mQualitySlider->blockSignals(
false );
137 mWeightExpressionWidget->setLayer( layer );
138 mWeightExpressionWidget->setField( mRenderer->weightExpression() );
149 return mRenderer.get();
155 if (
auto *lMapCanvas =
context.mapCanvas() )
156 mRadiusUnitWidget->setMapCanvas( lMapCanvas );
159void QgsHeatmapRendererWidget::applyColorRamp()
166 QgsColorRamp *ramp = btnColorRamp->colorRamp();
170 mRenderer->setColorRamp( ramp );
174void QgsHeatmapRendererWidget::showLegendSettings()
182 legendPanel->
setSettings( mRenderer->legendSettings() );
184 mRenderer->setLegendSettings( legendPanel->
settings() );
192 dialog.setUseContinuousRampCheckBoxVisibility(
false );
193 dialog.setWindowTitle( tr(
"Legend Settings" ) );
196 mRenderer->setLegendSettings( dialog.settings() );
202void QgsHeatmapRendererWidget::mRadiusUnitWidget_changed()
209 mRenderer->setRadiusUnit( mRadiusUnitWidget->unit() );
210 mRenderer->setRadiusMapUnitScale( mRadiusUnitWidget->getMapUnitScale() );
214void QgsHeatmapRendererWidget::mRadiusSpinBox_valueChanged(
double d )
221 mRenderer->setRadius( d );
225void QgsHeatmapRendererWidget::mMaxSpinBox_valueChanged(
double d )
232 mRenderer->setMaximumValue( d );
236void QgsHeatmapRendererWidget::mQualitySlider_valueChanged(
int v )
243 mRenderer->setRenderQuality( v );
247void QgsHeatmapRendererWidget::weightExpressionChanged(
const QString &expression )
249 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.