39 static void _initRendererWidgetFunctions()
41 static bool sInitialized =
false;
66 connect( mResetColorRenderingBtn, &QToolButton::clicked,
this, &QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked );
68 _initRendererWidgetFunctions();
70 mZoomedInResamplingComboBox->insertItem( 0, tr(
"Nearest neighbour" ) );
71 mZoomedInResamplingComboBox->insertItem( 1, tr(
"Bilinear" ) );
72 mZoomedInResamplingComboBox->insertItem( 2, tr(
"Cubic" ) );
73 mZoomedOutResamplingComboBox->insertItem( 0, tr(
"Nearest neighbour" ) );
74 mZoomedOutResamplingComboBox->insertItem( 1, tr(
"Average" ) );
78 connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
79 connect( mBrightnessSpinBox, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
81 connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
82 connect( mContrastSpinBox, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );
85 connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
86 connect( spinBoxSaturation, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
89 connect( sliderColorizeStrength, &QAbstractSlider::valueChanged, spinColorizeStrength, &QSpinBox::setValue );
90 connect( spinColorizeStrength, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ), sliderColorizeStrength, &QAbstractSlider::setValue );
93 connect( comboGrayscale,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRendererRasterPropertiesWidget::toggleSaturationControls );
96 connect( mColorizeCheck, &QAbstractButton::toggled,
this, &QgsRendererRasterPropertiesWidget::toggleColorizeControls );
102 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 );
124 QString rendererName = cboRenderers->currentData().toString();
125 setRendererWidget( rendererName );
133 brightnessFilter->setBrightness( mSliderBrightness->value() );
134 brightnessFilter->setContrast( mSliderContrast->value() );
137 if (
QgsRasterRendererWidget *rendererWidget = dynamic_cast<QgsRasterRendererWidget *>( stackedWidget->currentWidget() ) )
139 rendererWidget->doComputations();
146 newRenderer->copyCommonProperties( oldRenderer,
false );
154 hueSaturationFilter->setSaturation( sliderSaturation->value() );
156 hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
157 hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
158 hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
164 QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
165 if ( zoomedInResamplingMethod == tr(
"Bilinear" ) )
169 else if ( zoomedInResamplingMethod == tr(
"Cubic" ) )
174 resampleFilter->setZoomedInResampler( zoomedInResampler );
178 QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
179 if ( zoomedOutResamplingMethod == tr(
"Average" ) )
184 resampleFilter->setZoomedOutResampler( zoomedOutResampler );
186 resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
189 mRasterLayer->
setBlendMode( mBlendModeComboBox->blendMode() );
194 mRasterLayer = layer;
196 cboRenderers->blockSignals(
true );
197 cboRenderers->clear();
200 for (
const QString &name : constRenderersList )
211 cboRenderers->setCurrentIndex( -1 );
212 cboRenderers->blockSignals(
false );
216 setRendererWidget( renderer->type() );
221 mSliderBrightness->setValue( brightnessFilter->brightness() );
222 mSliderContrast->setValue( brightnessFilter->contrast() );
225 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
226 btnColorizeColor->setContext( QStringLiteral(
"symbology" ) );
232 sliderSaturation->setValue( hueSaturationFilter->saturation() );
233 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->grayscaleMode() );
236 toggleSaturationControls( static_cast<int>( hueSaturationFilter->grayscaleMode() ) );
239 mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
240 btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
241 toggleColorizeControls( hueSaturationFilter->colorizeOn() );
242 sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
246 mBlendModeComboBox->setBlendMode( mRasterLayer->
blendMode() );
252 if ( zoomedInResampler )
254 if ( zoomedInResampler->
type() == QLatin1String(
"bilinear" ) )
256 mZoomedInResamplingComboBox->setCurrentIndex( 1 );
258 else if ( zoomedInResampler->
type() == QLatin1String(
"cubic" ) )
260 mZoomedInResamplingComboBox->setCurrentIndex( 2 );
265 mZoomedInResamplingComboBox->setCurrentIndex( 0 );
269 if ( zoomedOutResampler )
271 if ( zoomedOutResampler->
type() == QLatin1String(
"bilinear" ) )
273 mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
278 mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
280 mMaximumOversamplingSpinBox->setValue( resampleFilter->maxOversampling() );
284 void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
286 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
287 mSliderBrightness->setValue( 0 );
288 mSliderContrast->setValue( 0 );
289 sliderSaturation->setValue( 0 );
291 mColorizeCheck->setChecked(
false );
292 sliderColorizeStrength->setValue( 100 );
295 void QgsRendererRasterPropertiesWidget::toggleSaturationControls(
int grayscaleMode )
298 if ( grayscaleMode == 0 )
300 sliderSaturation->setEnabled(
true );
301 spinBoxSaturation->setEnabled(
true );
305 sliderSaturation->setEnabled(
false );
306 spinBoxSaturation->setEnabled(
false );
311 void QgsRendererRasterPropertiesWidget::toggleColorizeControls(
bool colorizeEnabled )
314 btnColorizeColor->setEnabled( colorizeEnabled );
315 sliderColorizeStrength->setEnabled( colorizeEnabled );
316 spinColorizeStrength->setEnabled( colorizeEnabled );
320 void QgsRendererRasterPropertiesWidget::setRendererWidget(
const QString &rendererName )
330 alphaBand = oldRenderer->alphaBand();
331 opacity = oldRenderer->opacity();
339 QgsDebugMsg( QStringLiteral(
"renderer has widgetCreateFunction" ) );
344 if ( rendererName == QLatin1String(
"singlebandgray" ) )
347 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
349 else if ( rendererName == QLatin1String(
"multibandcolor" ) )
352 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
360 stackedWidget->addWidget( mRendererWidget );
361 stackedWidget->setCurrentWidget( mRendererWidget );
368 QList<int> oldBands = oldRenderer->
usesBands();
369 QList<int> newBands = newRenderer->
usesBands();
371 if ( oldBands != newBands )
373 populateTransparencyTable( newRenderer );
383 if ( mRendererWidget != oldWidget )
386 int widgetIndex = cboRenderers->findData( rendererName );
387 if ( widgetIndex != -1 )
389 whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
394 void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
396 if ( mRendererWidget )
double maximumValue() const
Returns the maximum value for the contrast enhancement range.
A rectangle specified with double values.
Base class for all map layer types.
Interface for resampling rasters (e.g.
QgsHueSaturationFilter * hueSaturationFilter() const
Returns the raster's hue/saturation filter.
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
QgsRasterRendererWidgetCreateFunc widgetCreateFunction
void setRenderer(QgsRasterRenderer *renderer)
Sets the raster's renderer.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
double minimumValue() const
Returns the minimum value for the contrast enhancement range.
Resample filter pipe for rasters.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
Map canvas is a class for displaying all GIS data types on a canvas.
void styleChanged()
Signal emitted whenever a change affects the layer's style.
QgsBrightnessContrastFilter * brightnessFilter() const
Returns the raster's brightness/contrast filter.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
virtual QString type() const =0
Gets a descriptive type identifier for this raster resampler.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
Raster renderer pipe for single band gray.
LayerType rasterType()
Returns the raster layer type (which is a read only property).
void setAlphaBand(int band)
QStringList renderersList() const
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Registry for raster renderer entries.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
QgsRasterResampleFilter * resampleFilter() const
Returns the raster's resample filter.
Brightness/contrast filter pipe for rasters.
Bilinear Raster Resampler.
Color and saturation filter pipe for rasters.
Renderer for multiband images with the color components.
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1...
void insertWidgetFunction(const QString &rendererName, QgsRasterRendererWidgetCreateFunc func)
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers...
Raster renderer pipe that applies colors to a raster.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.