36void QgsRendererRasterPropertiesWidget::initRendererWidgetFunctions()
38 static bool sInitialized =
false;
60 connect( mResetColorRenderingBtn, &QToolButton::clicked,
this, &QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked );
62 initRendererWidgetFunctions();
64 mResamplingUtils.initWidgets( mRasterLayer, mZoomedInResamplingComboBox, mZoomedOutResamplingComboBox, mMaximumOversamplingSpinBox, mCbEarlyResampling );
68 connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
69 connect( mBrightnessSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
70 mBrightnessSpinBox->setClearValue( 0 );
72 connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
73 connect( mContrastSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );
74 mContrastSpinBox->setClearValue( 0 );
76 connect( mSliderGamma, &QAbstractSlider::valueChanged,
this, &QgsRendererRasterPropertiesWidget::updateGammaSpinBox );
77 connect( mGammaSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsRendererRasterPropertiesWidget::updateGammaSlider );
78 mGammaSpinBox->setClearValue( 1.0 );
81 connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
82 connect( spinBoxSaturation,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
83 spinBoxSaturation->setClearValue( 0 );
86 connect( sliderColorizeStrength, &QAbstractSlider::valueChanged, spinColorizeStrength, &QSpinBox::setValue );
87 connect( spinColorizeStrength,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), sliderColorizeStrength, &QAbstractSlider::setValue );
88 spinColorizeStrength->setClearValue( 100 );
91 connect( comboGrayscale,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRendererRasterPropertiesWidget::toggleSaturationControls );
94 connect( mColorizeCheck, &QAbstractButton::toggled,
this, &QgsRendererRasterPropertiesWidget::toggleColorizeControls );
99 connect( mGammaSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
101 connect( spinColorizeStrength,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
105 connect( mBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
106 connect( mZoomedInResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
107 connect( mZoomedOutResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
108 connect( mMaximumOversamplingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
125 const QString rendererName = cboRenderers->currentData().toString();
126 setRendererWidget( rendererName );
134 brightnessFilter->setBrightness( mSliderBrightness->value() );
135 brightnessFilter->setContrast( mSliderContrast->value() );
136 brightnessFilter->setGamma( mGammaSpinBox->value() );
141 rendererWidget->doComputations();
148 newRenderer->copyCommonProperties( oldRenderer,
false );
156 hueSaturationFilter->setSaturation( sliderSaturation->value() );
158 hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
159 hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
160 hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
161 hueSaturationFilter->setInvertColors( mInvertColorsCheck->isChecked() );
164 mResamplingUtils.refreshLayerFromWidgets();
166 mRasterLayer->
setBlendMode( mBlendModeComboBox->blendMode() );
171 mRasterLayer = layer;
173 cboRenderers->blockSignals(
true );
174 cboRenderers->clear();
177 for (
const QString &name : constRenderersList )
188 cboRenderers->setCurrentIndex( -1 );
189 cboRenderers->blockSignals(
false );
193 setRendererWidget( renderer->type() );
198 mSliderBrightness->setValue( brightnessFilter->brightness() );
199 mSliderContrast->setValue( brightnessFilter->contrast() );
200 mGammaSpinBox->setValue( brightnessFilter->gamma() );
203 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
204 btnColorizeColor->setContext( QStringLiteral(
"symbology" ) );
210 sliderSaturation->setValue( hueSaturationFilter->saturation() );
211 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->grayscaleMode() );
214 toggleSaturationControls(
static_cast<int>( hueSaturationFilter->grayscaleMode() ) );
217 mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
218 btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
219 toggleColorizeControls( hueSaturationFilter->colorizeOn() );
220 sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
222 mInvertColorsCheck->setChecked( hueSaturationFilter->invertColors() );
227 mBlendModeComboBox->setBlendMode( mRasterLayer->
blendMode() );
230 mResamplingUtils.refreshWidgetsFromLayer();
233void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
235 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
236 mSliderBrightness->setValue( 0 );
237 mSliderContrast->setValue( 0 );
238 mGammaSpinBox->setValue( 1.0 );
239 sliderSaturation->setValue( 0 );
241 mColorizeCheck->setChecked(
false );
242 sliderColorizeStrength->setValue( 100 );
243 mInvertColorsCheck->setChecked(
false );
246void QgsRendererRasterPropertiesWidget::toggleSaturationControls(
int grayscaleMode )
249 if ( grayscaleMode == 0 )
251 sliderSaturation->setEnabled(
true );
252 spinBoxSaturation->setEnabled(
true );
256 sliderSaturation->setEnabled(
false );
257 spinBoxSaturation->setEnabled(
false );
262void QgsRendererRasterPropertiesWidget::toggleColorizeControls(
bool colorizeEnabled )
265 btnColorizeColor->setEnabled( colorizeEnabled );
266 sliderColorizeStrength->setEnabled( colorizeEnabled );
267 spinColorizeStrength->setEnabled( colorizeEnabled );
271void QgsRendererRasterPropertiesWidget::setRendererWidget(
const QString &rendererName )
282 alphaBand = oldRenderer->alphaBand();
283 opacity = oldRenderer->opacity();
284 nodataColor = oldRenderer->nodataColor();
292 QgsDebugMsgLevel( QStringLiteral(
"renderer has widgetCreateFunction" ), 3 );
299 std::unique_ptr< QgsRasterRenderer > oldRenderer( oldWidget->
renderer() );
300 if ( !oldRenderer || oldRenderer->type() != rendererName )
302 if ( rendererName == QLatin1String(
"singlebandgray" ) )
305 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
307 else if ( rendererName == QLatin1String(
"multibandcolor" ) )
310 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
320 stackedWidget->addWidget( mRendererWidget );
321 stackedWidget->setCurrentWidget( mRendererWidget );
328 QList<int> oldBands = oldRenderer->
usesBands();
329 QList<int> newBands = newRenderer->
usesBands();
331 if ( oldBands != newBands )
333 populateTransparencyTable( newRenderer );
343 if ( mRendererWidget != oldWidget )
346 const int widgetIndex = cboRenderers->findData( rendererName );
347 if ( widgetIndex != -1 )
349 whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
354void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
356 if ( mRendererWidget )
392void QgsRendererRasterPropertiesWidget::updateGammaSpinBox(
int value )
394 mGammaSpinBox->setValue( value / 100.0 );
397void QgsRendererRasterPropertiesWidget::updateGammaSlider(
double value )
399 mSliderGamma->setValue( value * 100 );
@ SingleBandColorData
Single band containing color data.
@ SingleBandGray
A single band image drawn as a range of gray colors.
@ MultiBandColor
A layer containing 2 or more bands, mapped to RGB color space. In the case of a multiband with only t...
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers.
Brightness/contrast and gamma correction filter pipe for rasters.
Manipulates raster or point cloud pixel values so that they enhanceContrast or clip into a specified ...
double minimumValue() const
Returns the minimum value for the contrast enhancement range.
double maximumValue() const
Returns the maximum value for the contrast enhancement range.
Color and saturation filter pipe for rasters.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
Base class for all map layer types.
virtual QgsRectangle extent() const
Returns the extent of the layer.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
QgsCoordinateReferenceSystem crs
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
void styleChanged()
Signal emitted whenever a change affects the layer's style.
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
Renderer for multiband images with the color components.
static bool layerIsContainedInGroupLayer(QgsProject *project, QgsMapLayer *layer)
Returns true if the specified layer is a child layer from any QgsGroupLayer in the given project.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Represents a raster layer.
Qgis::RasterLayerType rasterType() const
Returns the raster layer type (which is a read only property).
QgsBrightnessContrastFilter * brightnessFilter() const
Returns the raster's brightness/contrast filter.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
void setRenderer(QgsRasterRenderer *renderer)
Sets the raster's renderer.
QgsHueSaturationFilter * hueSaturationFilter() const
Returns the raster's hue/saturation filter.
void insertWidgetFunction(const QString &rendererName, QgsRasterRendererWidgetCreateFunc func)
bool rendererData(const QString &rendererName, QgsRasterRendererRegistryEntry &data) const
QStringList renderersList() const
Raster renderer pipe that applies colors to a raster.
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
void setAlphaBand(int band)
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
void setNodataColor(const QColor &color)
Sets the color to use for shading nodata pixels.
A rectangle specified with double values.
Raster renderer pipe for single band gray.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
#define QgsDebugMsgLevel(str, level)
Registry for raster renderer entries.
QgsRasterRendererWidgetCreateFunc widgetCreateFunction