39 static void _initRendererWidgetFunctions()
41 static bool sInitialized =
false;
62 if ( !( mRasterLayer && mRasterLayer->
isValid() ) )
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 );
132 if ( ! mRasterLayer->
isValid() )
139 if ( rendererWidget )
155 if ( hueSaturationFilter )
157 hueSaturationFilter->
setSaturation( sliderSaturation->value() );
159 hueSaturationFilter->
setColorizeOn( mColorizeCheck->checkState() );
165 if ( resampleFilter )
168 QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
169 if ( zoomedInResamplingMethod == tr(
"Bilinear" ) )
173 else if ( zoomedInResamplingMethod == tr(
"Cubic" ) )
182 QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
183 if ( zoomedOutResamplingMethod == tr(
"Average" ) )
193 mRasterLayer->
setBlendMode( mBlendModeComboBox->blendMode() );
198 mRasterLayer = layer;
200 cboRenderers->blockSignals(
true );
201 cboRenderers->clear();
204 for (
const QString &name : constRenderersList )
215 cboRenderers->setCurrentIndex( -1 );
216 cboRenderers->blockSignals(
false );
221 setRendererWidget( renderer->
type() );
225 if ( brightnessFilter )
227 mSliderBrightness->setValue( brightnessFilter->brightness() );
228 mSliderContrast->setValue( brightnessFilter->contrast() );
231 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
232 btnColorizeColor->setContext( QStringLiteral(
"symbology" ) );
237 if ( hueSaturationFilter )
239 sliderSaturation->setValue( hueSaturationFilter->
saturation() );
240 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->
grayscaleMode() );
243 toggleSaturationControls( static_cast<int>( hueSaturationFilter->
grayscaleMode() ) );
246 mColorizeCheck->setChecked( hueSaturationFilter->
colorizeOn() );
247 btnColorizeColor->setColor( hueSaturationFilter->
colorizeColor() );
248 toggleColorizeControls( hueSaturationFilter->
colorizeOn() );
249 sliderColorizeStrength->setValue( hueSaturationFilter->
colorizeStrength() );
253 mBlendModeComboBox->setBlendMode( mRasterLayer->
blendMode() );
257 if ( resampleFilter )
260 if ( zoomedInResampler )
262 if ( zoomedInResampler->
type() == QLatin1String(
"bilinear" ) )
264 mZoomedInResamplingComboBox->setCurrentIndex( 1 );
266 else if ( zoomedInResampler->
type() == QLatin1String(
"cubic" ) )
268 mZoomedInResamplingComboBox->setCurrentIndex( 2 );
273 mZoomedInResamplingComboBox->setCurrentIndex( 0 );
277 if ( zoomedOutResampler )
279 if ( zoomedOutResampler->
type() == QLatin1String(
"bilinear" ) )
281 mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
286 mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
288 mMaximumOversamplingSpinBox->setValue( resampleFilter->
maxOversampling() );
292 void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
294 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
295 mSliderBrightness->setValue( 0 );
296 mSliderContrast->setValue( 0 );
297 sliderSaturation->setValue( 0 );
299 mColorizeCheck->setChecked(
false );
300 sliderColorizeStrength->setValue( 100 );
303 void QgsRendererRasterPropertiesWidget::toggleSaturationControls(
int grayscaleMode )
306 if ( grayscaleMode == 0 )
308 sliderSaturation->setEnabled(
true );
309 spinBoxSaturation->setEnabled(
true );
313 sliderSaturation->setEnabled(
false );
314 spinBoxSaturation->setEnabled(
false );
319 void QgsRendererRasterPropertiesWidget::toggleColorizeControls(
bool colorizeEnabled )
322 btnColorizeColor->setEnabled( colorizeEnabled );
323 sliderColorizeStrength->setEnabled( colorizeEnabled );
324 spinColorizeStrength->setEnabled( colorizeEnabled );
328 void QgsRendererRasterPropertiesWidget::setRendererWidget(
const QString &rendererName )
340 opacity = oldRenderer->
opacity();
348 QgsDebugMsg( QStringLiteral(
"renderer has widgetCreateFunction" ) );
353 if ( rendererName == QLatin1String(
"singlebandgray" ) )
356 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
358 else if ( rendererName == QLatin1String(
"multibandcolor" ) )
361 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
369 stackedWidget->addWidget( mRendererWidget );
370 stackedWidget->setCurrentWidget( mRendererWidget );
377 QList<int> oldBands = oldRenderer->
usesBands();
378 QList<int> newBands = newRenderer->
usesBands();
380 if ( oldBands != newBands )
382 populateTransparencyTable( newRenderer );
392 if ( mRendererWidget != oldWidget )
395 int widgetIndex = cboRenderers->findData( rendererName );
396 if ( widgetIndex != -1 )
398 whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
403 void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
405 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.
void setMaxOversampling(double os)
Interface for resampling rasters (e.g.
QgsHueSaturationFilter * hueSaturationFilter() const
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
double opacity() const
Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1...
QgsRasterRendererWidgetCreateFunc widgetCreateFunction
void setColorizeColor(const QColor &colorizeColor)
void setRenderer(QgsRasterRenderer *renderer)
Sets raster renderer. Takes ownership of the renderer object.
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
virtual QString type() const
int colorizeStrength() const
double minimumValue() const
Returns the minimum value for the contrast enhancement range.
Resample filter pipe for rasters.
QgsRasterRenderer * renderer() const
bool isValid() const
Returns the status of the layer.
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
QgsRasterDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
void setBrightness(int brightness)
void setContrast(int contrast)
virtual QString type() const =0
Gets a descriptive type identifier for this raster resampler.
void copyCommonProperties(const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
Copies common properties like opacity / transparency data from other renderer.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
double maxOversampling() const
Raster renderer pipe for single band gray.
LayerType rasterType()
Returns the raster layer type (which is a read only property).
void setAlphaBand(int band)
void setColorizeOn(bool colorizeOn)
QStringList renderersList() const
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Registry for raster renderer entries.
QgsHueSaturationFilter::GrayscaleMode grayscaleMode() const
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
void setZoomedInResampler(QgsRasterResampler *r)
Sets resampler for zoomed in scales. Takes ownership of the object.
QgsRasterResampleFilter * resampleFilter() const
Sets raster resample filter. Takes ownership of the resample filter object.
Brightness/contrast filter pipe for rasters.
Bilinear Raster Resampler.
const QgsRasterResampler * zoomedOutResampler() const
Color and saturation filter pipe for rasters.
void setZoomedOutResampler(QgsRasterResampler *r)
Sets resampler for zoomed out scales. Takes ownership of the object.
QColor colorizeColor() const
Renderer for multiband images with the color components.
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
void setColorizeStrength(int colorizeStrength)
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.
void setGrayscaleMode(QgsHueSaturationFilter::GrayscaleMode grayscaleMode)
void setSaturation(int saturation)
const QgsRasterResampler * zoomedInResampler() const