37 static void _initRendererWidgetFunctions()
39 static bool sInitialized =
false;
63 connect( mResetColorRenderingBtn, &QToolButton::clicked,
this, &QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked );
65 _initRendererWidgetFunctions();
67 mResamplingUtils.initWidgets( mRasterLayer, mZoomedInResamplingComboBox, mZoomedOutResamplingComboBox, mMaximumOversamplingSpinBox, mCbEarlyResampling );
71 connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
72 connect( mBrightnessSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
73 mBrightnessSpinBox->setClearValue( 0 );
75 connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
76 connect( mContrastSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );
77 mContrastSpinBox->setClearValue( 0 );
79 connect( mSliderGamma, &QAbstractSlider::valueChanged,
this, &QgsRendererRasterPropertiesWidget::updateGammaSpinBox );
80 connect( mGammaSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsRendererRasterPropertiesWidget::updateGammaSlider );
81 mGammaSpinBox->setClearValue( 1.0 );
84 connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
85 connect( spinBoxSaturation,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
86 spinBoxSaturation->setClearValue( 0 );
89 connect( sliderColorizeStrength, &QAbstractSlider::valueChanged, spinColorizeStrength, &QSpinBox::setValue );
90 connect( spinColorizeStrength,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), sliderColorizeStrength, &QAbstractSlider::setValue );
91 spinColorizeStrength->setClearValue( 100 );
94 connect( comboGrayscale,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRendererRasterPropertiesWidget::toggleSaturationControls );
97 connect( mColorizeCheck, &QAbstractButton::toggled,
this, &QgsRendererRasterPropertiesWidget::toggleColorizeControls );
100 connect( mBrightnessSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
102 connect( mGammaSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
104 connect( spinColorizeStrength,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
108 connect( mBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
109 connect( mZoomedInResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
110 connect( mZoomedOutResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
111 connect( mMaximumOversamplingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
128 const QString rendererName = cboRenderers->currentData().toString();
129 setRendererWidget( rendererName );
137 brightnessFilter->setBrightness( mSliderBrightness->value() );
138 brightnessFilter->setContrast( mSliderContrast->value() );
139 brightnessFilter->setGamma( mGammaSpinBox->value() );
144 rendererWidget->doComputations();
151 newRenderer->copyCommonProperties( oldRenderer,
false );
159 hueSaturationFilter->setSaturation( sliderSaturation->value() );
161 hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
162 hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
163 hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
164 hueSaturationFilter->setInvertColors( mInvertColorsCheck->isChecked() );
167 mResamplingUtils.refreshLayerFromWidgets();
169 mRasterLayer->
setBlendMode( mBlendModeComboBox->blendMode() );
174 mRasterLayer = layer;
176 cboRenderers->blockSignals(
true );
177 cboRenderers->clear();
180 for (
const QString &name : constRenderersList )
191 cboRenderers->setCurrentIndex( -1 );
192 cboRenderers->blockSignals(
false );
196 setRendererWidget( renderer->type() );
201 mSliderBrightness->setValue( brightnessFilter->brightness() );
202 mSliderContrast->setValue( brightnessFilter->contrast() );
203 mGammaSpinBox->setValue( brightnessFilter->gamma() );
206 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
207 btnColorizeColor->setContext( QStringLiteral(
"symbology" ) );
213 sliderSaturation->setValue( hueSaturationFilter->saturation() );
214 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->grayscaleMode() );
217 toggleSaturationControls(
static_cast<int>( hueSaturationFilter->grayscaleMode() ) );
220 mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
221 btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
222 toggleColorizeControls( hueSaturationFilter->colorizeOn() );
223 sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
225 mInvertColorsCheck->setChecked( hueSaturationFilter->invertColors() );
229 mBlendModeComboBox->setBlendMode( mRasterLayer->
blendMode() );
232 mResamplingUtils.refreshWidgetsFromLayer();
235 void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
237 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
238 mSliderBrightness->setValue( 0 );
239 mSliderContrast->setValue( 0 );
240 mGammaSpinBox->setValue( 1.0 );
241 sliderSaturation->setValue( 0 );
243 mColorizeCheck->setChecked(
false );
244 sliderColorizeStrength->setValue( 100 );
245 mInvertColorsCheck->setChecked(
false );
248 void QgsRendererRasterPropertiesWidget::toggleSaturationControls(
int grayscaleMode )
251 if ( grayscaleMode == 0 )
253 sliderSaturation->setEnabled(
true );
254 spinBoxSaturation->setEnabled(
true );
258 sliderSaturation->setEnabled(
false );
259 spinBoxSaturation->setEnabled(
false );
264 void QgsRendererRasterPropertiesWidget::toggleColorizeControls(
bool colorizeEnabled )
267 btnColorizeColor->setEnabled( colorizeEnabled );
268 sliderColorizeStrength->setEnabled( colorizeEnabled );
269 spinColorizeStrength->setEnabled( colorizeEnabled );
273 void QgsRendererRasterPropertiesWidget::setRendererWidget(
const QString &rendererName )
284 alphaBand = oldRenderer->alphaBand();
285 opacity = oldRenderer->opacity();
286 nodataColor = oldRenderer->nodataColor();
294 QgsDebugMsgLevel( QStringLiteral(
"renderer has widgetCreateFunction" ), 3 );
299 std::unique_ptr< QgsRasterRenderer > oldRenderer( oldWidget->
renderer() );
300 if ( !oldRenderer || oldRenderer->type() != rendererName )
302 if ( rendererName == QLatin1String(
"singlebandgray" ) )
305 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
307 else if ( rendererName == QLatin1String(
"multibandcolor" ) )
310 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
320 stackedWidget->addWidget( mRendererWidget );
321 stackedWidget->setCurrentWidget( mRendererWidget );
328 QList<int> oldBands = oldRenderer->
usesBands();
329 QList<int> newBands = newRenderer->
usesBands();
331 if ( oldBands != newBands )
333 populateTransparencyTable( newRenderer );
343 if ( mRendererWidget != oldWidget )
346 const int widgetIndex = cboRenderers->findData( rendererName );
347 if ( widgetIndex != -1 )
349 whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
354 void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
356 if ( mRendererWidget )
392 void QgsRendererRasterPropertiesWidget::updateGammaSpinBox(
int value )
394 mGammaSpinBox->setValue( value / 100.0 );
397 void QgsRendererRasterPropertiesWidget::updateGammaSlider(
double value )
399 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.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
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
Renderer for multiband images with the color components.
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.
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....
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
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