38 static void _initRendererWidgetFunctions()
40 static bool sInitialized =
false;
64 connect( mResetColorRenderingBtn, &QToolButton::clicked,
this, &QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked );
66 _initRendererWidgetFunctions();
68 mZoomedInResamplingComboBox->insertItem( 0, tr(
"Nearest neighbour" ) );
69 mZoomedInResamplingComboBox->insertItem( 1, tr(
"Bilinear" ) );
70 mZoomedInResamplingComboBox->insertItem( 2, tr(
"Cubic" ) );
71 mZoomedOutResamplingComboBox->insertItem( 0, tr(
"Nearest neighbour" ) );
72 mZoomedOutResamplingComboBox->insertItem( 1, tr(
"Average" ) );
76 connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
77 connect( mBrightnessSpinBox, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
79 connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
80 connect( mContrastSpinBox, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );
83 connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
84 connect( spinBoxSaturation, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
87 connect( sliderColorizeStrength, &QAbstractSlider::valueChanged, spinColorizeStrength, &QSpinBox::setValue );
88 connect( spinColorizeStrength, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ), sliderColorizeStrength, &QAbstractSlider::setValue );
91 connect( comboGrayscale,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRendererRasterPropertiesWidget::toggleSaturationControls );
94 connect( mColorizeCheck, &QAbstractButton::toggled,
this, &QgsRendererRasterPropertiesWidget::toggleColorizeControls );
100 connect( spinColorizeStrength, static_cast <
void ( QSpinBox::* )(
int ) > ( &QSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
103 connect( mBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
104 connect( mZoomedInResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
105 connect( mZoomedOutResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
106 connect( mMaximumOversamplingSpinBox, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
122 QString rendererName = cboRenderers->currentData().toString();
123 setRendererWidget( rendererName );
133 if ( rendererWidget )
149 if ( hueSaturationFilter )
151 hueSaturationFilter->
setSaturation( sliderSaturation->value() );
153 hueSaturationFilter->
setColorizeOn( mColorizeCheck->checkState() );
159 if ( resampleFilter )
162 QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
163 if ( zoomedInResamplingMethod == tr(
"Bilinear" ) )
167 else if ( zoomedInResamplingMethod == tr(
"Cubic" ) )
176 QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
177 if ( zoomedOutResamplingMethod == tr(
"Average" ) )
187 mRasterLayer->
setBlendMode( mBlendModeComboBox->blendMode() );
192 mRasterLayer = layer;
194 cboRenderers->blockSignals(
true );
195 cboRenderers->clear();
208 cboRenderers->setCurrentIndex( -1 );
209 cboRenderers->blockSignals(
false );
214 setRendererWidget( renderer->
type() );
218 if ( brightnessFilter )
220 mSliderBrightness->setValue( brightnessFilter->brightness() );
221 mSliderContrast->setValue( brightnessFilter->contrast() );
224 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
225 btnColorizeColor->setContext( QStringLiteral(
"symbology" ) );
230 if ( hueSaturationFilter )
232 sliderSaturation->setValue( hueSaturationFilter->
saturation() );
233 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->
grayscaleMode() );
236 toggleSaturationControls( (
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() );
250 if ( resampleFilter )
253 if ( zoomedInResampler )
255 if ( zoomedInResampler->
type() == QLatin1String(
"bilinear" ) )
257 mZoomedInResamplingComboBox->setCurrentIndex( 1 );
259 else if ( zoomedInResampler->
type() == QLatin1String(
"cubic" ) )
261 mZoomedInResamplingComboBox->setCurrentIndex( 2 );
266 mZoomedInResamplingComboBox->setCurrentIndex( 0 );
270 if ( zoomedOutResampler )
272 if ( zoomedOutResampler->
type() == QLatin1String(
"bilinear" ) )
274 mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
279 mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
281 mMaximumOversamplingSpinBox->setValue( resampleFilter->
maxOversampling() );
285 void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
287 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
288 mSliderBrightness->setValue( 0 );
289 mSliderContrast->setValue( 0 );
290 sliderSaturation->setValue( 0 );
292 mColorizeCheck->setChecked(
false );
293 sliderColorizeStrength->setValue( 100 );
296 void QgsRendererRasterPropertiesWidget::toggleSaturationControls(
int grayscaleMode )
299 if ( grayscaleMode == 0 )
301 sliderSaturation->setEnabled(
true );
302 spinBoxSaturation->setEnabled(
true );
306 sliderSaturation->setEnabled(
false );
307 spinBoxSaturation->setEnabled(
false );
312 void QgsRendererRasterPropertiesWidget::toggleColorizeControls(
bool colorizeEnabled )
315 btnColorizeColor->setEnabled( colorizeEnabled );
316 sliderColorizeStrength->setEnabled( colorizeEnabled );
317 spinColorizeStrength->setEnabled( colorizeEnabled );
321 void QgsRendererRasterPropertiesWidget::setRendererWidget(
const QString &rendererName )
333 opacity = oldRenderer->
opacity();
341 QgsDebugMsg(
"renderer has widgetCreateFunction" );
346 if ( rendererName == QLatin1String(
"singlebandgray" ) )
349 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
351 else if ( rendererName == QLatin1String(
"multibandcolor" ) )
354 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
362 stackedWidget->addWidget( mRendererWidget );
363 stackedWidget->setCurrentWidget( mRendererWidget );
370 QList<int> oldBands = oldRenderer->
usesBands();
371 QList<int> newBands = newRenderer->
usesBands();
373 if ( oldBands != newBands )
375 populateTransparencyTable( newRenderer );
385 if ( mRendererWidget != oldWidget )
388 int widgetIndex = cboRenderers->findData( rendererName );
389 if ( widgetIndex != -1 )
391 whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
396 void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
398 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
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.
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