39static void _initRendererWidgetFunctions()
41 static bool sInitialized =
false;
65 connect( mResetColorRenderingBtn, &QToolButton::clicked,
this, &QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked );
67 _initRendererWidgetFunctions();
69 mResamplingUtils.initWidgets( mRasterLayer, mZoomedInResamplingComboBox, mZoomedOutResamplingComboBox, mMaximumOversamplingSpinBox, mCbEarlyResampling );
73 connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
74 connect( mBrightnessSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
75 mBrightnessSpinBox->setClearValue( 0 );
77 connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
78 connect( mContrastSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );
79 mContrastSpinBox->setClearValue( 0 );
81 connect( mSliderGamma, &QAbstractSlider::valueChanged,
this, &QgsRendererRasterPropertiesWidget::updateGammaSpinBox );
82 connect( mGammaSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsRendererRasterPropertiesWidget::updateGammaSlider );
83 mGammaSpinBox->setClearValue( 1.0 );
86 connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
87 connect( spinBoxSaturation,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
88 spinBoxSaturation->setClearValue( 0 );
91 connect( sliderColorizeStrength, &QAbstractSlider::valueChanged, spinColorizeStrength, &QSpinBox::setValue );
92 connect( spinColorizeStrength,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), sliderColorizeStrength, &QAbstractSlider::setValue );
93 spinColorizeStrength->setClearValue( 100 );
96 connect( comboGrayscale,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRendererRasterPropertiesWidget::toggleSaturationControls );
99 connect( mColorizeCheck, &QAbstractButton::toggled,
this, &QgsRendererRasterPropertiesWidget::toggleColorizeControls );
102 connect( mBrightnessSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
104 connect( mGammaSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
106 connect( spinColorizeStrength,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
110 connect( mBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
111 connect( mZoomedInResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
112 connect( mZoomedOutResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
113 connect( mMaximumOversamplingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
130 const QString rendererName = cboRenderers->currentData().toString();
131 setRendererWidget( rendererName );
139 brightnessFilter->setBrightness( mSliderBrightness->value() );
140 brightnessFilter->setContrast( mSliderContrast->value() );
141 brightnessFilter->setGamma( mGammaSpinBox->value() );
146 rendererWidget->doComputations();
153 newRenderer->copyCommonProperties( oldRenderer,
false );
161 hueSaturationFilter->setSaturation( sliderSaturation->value() );
163 hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
164 hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
165 hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
166 hueSaturationFilter->setInvertColors( mInvertColorsCheck->isChecked() );
169 mResamplingUtils.refreshLayerFromWidgets();
171 mRasterLayer->
setBlendMode( mBlendModeComboBox->blendMode() );
176 mRasterLayer = layer;
178 cboRenderers->blockSignals(
true );
179 cboRenderers->clear();
182 for (
const QString &name : constRenderersList )
193 cboRenderers->setCurrentIndex( -1 );
194 cboRenderers->blockSignals(
false );
198 setRendererWidget( renderer->type() );
203 mSliderBrightness->setValue( brightnessFilter->brightness() );
204 mSliderContrast->setValue( brightnessFilter->contrast() );
205 mGammaSpinBox->setValue( brightnessFilter->gamma() );
208 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
209 btnColorizeColor->setContext( QStringLiteral(
"symbology" ) );
215 sliderSaturation->setValue( hueSaturationFilter->saturation() );
216 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->grayscaleMode() );
219 toggleSaturationControls(
static_cast<int>( hueSaturationFilter->grayscaleMode() ) );
222 mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
223 btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
224 toggleColorizeControls( hueSaturationFilter->colorizeOn() );
225 sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
227 mInvertColorsCheck->setChecked( hueSaturationFilter->invertColors() );
232 mBlendModeComboBox->setBlendMode( mRasterLayer->
blendMode() );
235 mResamplingUtils.refreshWidgetsFromLayer();
238void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
240 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
241 mSliderBrightness->setValue( 0 );
242 mSliderContrast->setValue( 0 );
243 mGammaSpinBox->setValue( 1.0 );
244 sliderSaturation->setValue( 0 );
246 mColorizeCheck->setChecked(
false );
247 sliderColorizeStrength->setValue( 100 );
248 mInvertColorsCheck->setChecked(
false );
251void QgsRendererRasterPropertiesWidget::toggleSaturationControls(
int grayscaleMode )
254 if ( grayscaleMode == 0 )
256 sliderSaturation->setEnabled(
true );
257 spinBoxSaturation->setEnabled(
true );
261 sliderSaturation->setEnabled(
false );
262 spinBoxSaturation->setEnabled(
false );
267void QgsRendererRasterPropertiesWidget::toggleColorizeControls(
bool colorizeEnabled )
270 btnColorizeColor->setEnabled( colorizeEnabled );
271 sliderColorizeStrength->setEnabled( colorizeEnabled );
272 spinColorizeStrength->setEnabled( colorizeEnabled );
276void QgsRendererRasterPropertiesWidget::setRendererWidget(
const QString &rendererName )
287 alphaBand = oldRenderer->alphaBand();
288 opacity = oldRenderer->opacity();
289 nodataColor = oldRenderer->nodataColor();
297 QgsDebugMsgLevel( QStringLiteral(
"renderer has widgetCreateFunction" ), 3 );
304 std::unique_ptr< QgsRasterRenderer > oldRenderer( oldWidget->
renderer() );
305 if ( !oldRenderer || oldRenderer->type() != rendererName )
307 if ( rendererName == QLatin1String(
"singlebandgray" ) )
310 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
312 else if ( rendererName == QLatin1String(
"multibandcolor" ) )
315 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
325 stackedWidget->addWidget( mRendererWidget );
326 stackedWidget->setCurrentWidget( mRendererWidget );
333 QList<int> oldBands = oldRenderer->
usesBands();
334 QList<int> newBands = newRenderer->
usesBands();
336 if ( oldBands != newBands )
338 populateTransparencyTable( newRenderer );
348 if ( mRendererWidget != oldWidget )
351 const int widgetIndex = cboRenderers->findData( rendererName );
352 if ( widgetIndex != -1 )
354 whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
359void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
361 if ( mRendererWidget )
397void QgsRendererRasterPropertiesWidget::updateGammaSpinBox(
int value )
399 mGammaSpinBox->setValue( value / 100.0 );
402void QgsRendererRasterPropertiesWidget::updateGammaSlider(
double value )
404 mSliderGamma->setValue( value * 100 );
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.
QgsBrightnessContrastFilter * brightnessFilter() const
Returns the raster's brightness/contrast filter.
LayerType rasterType()
Returns the raster layer type (which is a read only property).
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)
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