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();
214 cboRenderers->setCurrentIndex( -1 );
215 cboRenderers->blockSignals(
false );
220 setRendererWidget( renderer->
type() );
224 if ( brightnessFilter )
226 mSliderBrightness->setValue( brightnessFilter->brightness() );
227 mSliderContrast->setValue( brightnessFilter->contrast() );
230 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
231 btnColorizeColor->setContext( QStringLiteral(
"symbology" ) );
236 if ( hueSaturationFilter )
238 sliderSaturation->setValue( hueSaturationFilter->
saturation() );
239 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->
grayscaleMode() );
242 toggleSaturationControls( static_cast<int>( hueSaturationFilter->
grayscaleMode() ) );
245 mColorizeCheck->setChecked( hueSaturationFilter->
colorizeOn() );
246 btnColorizeColor->setColor( hueSaturationFilter->
colorizeColor() );
247 toggleColorizeControls( hueSaturationFilter->
colorizeOn() );
248 sliderColorizeStrength->setValue( hueSaturationFilter->
colorizeStrength() );
252 mBlendModeComboBox->setBlendMode( mRasterLayer->
blendMode() );
256 if ( resampleFilter )
259 if ( zoomedInResampler )
261 if ( zoomedInResampler->
type() == QLatin1String(
"bilinear" ) )
263 mZoomedInResamplingComboBox->setCurrentIndex( 1 );
265 else if ( zoomedInResampler->
type() == QLatin1String(
"cubic" ) )
267 mZoomedInResamplingComboBox->setCurrentIndex( 2 );
272 mZoomedInResamplingComboBox->setCurrentIndex( 0 );
276 if ( zoomedOutResampler )
278 if ( zoomedOutResampler->
type() == QLatin1String(
"bilinear" ) )
280 mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
285 mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
287 mMaximumOversamplingSpinBox->setValue( resampleFilter->
maxOversampling() );
291 void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
293 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
294 mSliderBrightness->setValue( 0 );
295 mSliderContrast->setValue( 0 );
296 sliderSaturation->setValue( 0 );
298 mColorizeCheck->setChecked(
false );
299 sliderColorizeStrength->setValue( 100 );
302 void QgsRendererRasterPropertiesWidget::toggleSaturationControls(
int grayscaleMode )
305 if ( grayscaleMode == 0 )
307 sliderSaturation->setEnabled(
true );
308 spinBoxSaturation->setEnabled(
true );
312 sliderSaturation->setEnabled(
false );
313 spinBoxSaturation->setEnabled(
false );
318 void QgsRendererRasterPropertiesWidget::toggleColorizeControls(
bool colorizeEnabled )
321 btnColorizeColor->setEnabled( colorizeEnabled );
322 sliderColorizeStrength->setEnabled( colorizeEnabled );
323 spinColorizeStrength->setEnabled( colorizeEnabled );
327 void QgsRendererRasterPropertiesWidget::setRendererWidget(
const QString &rendererName )
339 opacity = oldRenderer->
opacity();
347 QgsDebugMsg( QStringLiteral(
"renderer has widgetCreateFunction" ) );
352 if ( rendererName == QLatin1String(
"singlebandgray" ) )
355 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
357 else if ( rendererName == QLatin1String(
"multibandcolor" ) )
360 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
368 stackedWidget->addWidget( mRendererWidget );
369 stackedWidget->setCurrentWidget( mRendererWidget );
376 QList<int> oldBands = oldRenderer->
usesBands();
377 QList<int> newBands = newRenderer->
usesBands();
379 if ( oldBands != newBands )
381 populateTransparencyTable( newRenderer );
391 if ( mRendererWidget != oldWidget )
394 int widgetIndex = cboRenderers->findData( rendererName );
395 if ( widgetIndex != -1 )
397 whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
402 void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
404 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 null.
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)
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