40 static void _initRendererWidgetFunctions()
42 static bool sInitialized =
false;
62 mRasterLayer = qobject_cast<QgsRasterLayer *>( layer );
68 connect( mResetColorRenderingBtn, &QToolButton::clicked,
this, &QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked );
70 _initRendererWidgetFunctions();
72 mZoomedInResamplingComboBox->insertItem( 0, tr(
"Nearest neighbour" ) );
73 mZoomedInResamplingComboBox->insertItem( 1, tr(
"Bilinear" ) );
74 mZoomedInResamplingComboBox->insertItem( 2, tr(
"Cubic" ) );
75 mZoomedOutResamplingComboBox->insertItem( 0, tr(
"Nearest neighbour" ) );
76 mZoomedOutResamplingComboBox->insertItem( 1, tr(
"Average" ) );
80 connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
81 connect( mBrightnessSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
83 connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
84 connect( mContrastSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );
87 connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
88 connect( spinBoxSaturation,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
91 connect( sliderColorizeStrength, &QAbstractSlider::valueChanged, spinColorizeStrength, &QSpinBox::setValue );
92 connect( spinColorizeStrength,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ), sliderColorizeStrength, &QAbstractSlider::setValue );
95 connect( comboGrayscale,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRendererRasterPropertiesWidget::toggleSaturationControls );
98 connect( mColorizeCheck, &QAbstractButton::toggled,
this, &QgsRendererRasterPropertiesWidget::toggleColorizeControls );
101 connect( mBrightnessSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
104 connect( spinColorizeStrength,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
107 connect( mBlendModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
108 connect( mZoomedInResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
109 connect( mZoomedOutResamplingComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &
QgsPanelWidget::widgetChanged );
110 connect( mMaximumOversamplingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsPanelWidget::widgetChanged );
126 QString rendererName = cboRenderers->currentData().toString();
127 setRendererWidget( rendererName );
135 brightnessFilter->setBrightness( mSliderBrightness->value() );
136 brightnessFilter->setContrast( mSliderContrast->value() );
141 rendererWidget->doComputations();
148 newRenderer->copyCommonProperties( oldRenderer,
false );
156 hueSaturationFilter->setSaturation( sliderSaturation->value() );
158 hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
159 hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
160 hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
166 QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
167 if ( zoomedInResamplingMethod == tr(
"Bilinear" ) )
171 else if ( zoomedInResamplingMethod == tr(
"Cubic" ) )
176 resampleFilter->setZoomedInResampler( zoomedInResampler );
180 QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
181 if ( zoomedOutResamplingMethod == tr(
"Average" ) )
186 resampleFilter->setZoomedOutResampler( zoomedOutResampler );
188 resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
191 mRasterLayer->
setBlendMode( mBlendModeComboBox->blendMode() );
196 mRasterLayer = layer;
198 cboRenderers->blockSignals(
true );
199 cboRenderers->clear();
202 for (
const QString &name : constRenderersList )
213 cboRenderers->setCurrentIndex( -1 );
214 cboRenderers->blockSignals(
false );
218 setRendererWidget( renderer->type() );
223 mSliderBrightness->setValue( brightnessFilter->brightness() );
224 mSliderContrast->setValue( brightnessFilter->contrast() );
227 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
228 btnColorizeColor->setContext( QStringLiteral(
"symbology" ) );
234 sliderSaturation->setValue( hueSaturationFilter->saturation() );
235 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->grayscaleMode() );
238 toggleSaturationControls(
static_cast<int>( hueSaturationFilter->grayscaleMode() ) );
241 mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
242 btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
243 toggleColorizeControls( hueSaturationFilter->colorizeOn() );
244 sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
248 mBlendModeComboBox->setBlendMode( mRasterLayer->
blendMode() );
254 if ( zoomedInResampler )
256 if ( zoomedInResampler->
type() == QLatin1String(
"bilinear" ) )
258 mZoomedInResamplingComboBox->setCurrentIndex( 1 );
260 else if ( zoomedInResampler->
type() == QLatin1String(
"cubic" ) )
262 mZoomedInResamplingComboBox->setCurrentIndex( 2 );
267 mZoomedInResamplingComboBox->setCurrentIndex( 0 );
271 if ( zoomedOutResampler )
273 if ( zoomedOutResampler->
type() == QLatin1String(
"bilinear" ) )
275 mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
280 mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
282 mMaximumOversamplingSpinBox->setValue( resampleFilter->maxOversampling() );
286 void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
288 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
289 mSliderBrightness->setValue( 0 );
290 mSliderContrast->setValue( 0 );
291 sliderSaturation->setValue( 0 );
293 mColorizeCheck->setChecked(
false );
294 sliderColorizeStrength->setValue( 100 );
297 void QgsRendererRasterPropertiesWidget::toggleSaturationControls(
int grayscaleMode )
300 if ( grayscaleMode == 0 )
302 sliderSaturation->setEnabled(
true );
303 spinBoxSaturation->setEnabled(
true );
307 sliderSaturation->setEnabled(
false );
308 spinBoxSaturation->setEnabled(
false );
313 void QgsRendererRasterPropertiesWidget::toggleColorizeControls(
bool colorizeEnabled )
316 btnColorizeColor->setEnabled( colorizeEnabled );
317 sliderColorizeStrength->setEnabled( colorizeEnabled );
318 spinColorizeStrength->setEnabled( colorizeEnabled );
322 void QgsRendererRasterPropertiesWidget::setRendererWidget(
const QString &rendererName )
333 alphaBand = oldRenderer->alphaBand();
334 opacity = oldRenderer->opacity();
335 nodataColor = oldRenderer->nodataColor();
343 QgsDebugMsgLevel( QStringLiteral(
"renderer has widgetCreateFunction" ), 3 );
348 if ( rendererName == QLatin1String(
"singlebandgray" ) )
351 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
353 else if ( rendererName == QLatin1String(
"multibandcolor" ) )
356 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
365 stackedWidget->addWidget( mRendererWidget );
366 stackedWidget->setCurrentWidget( mRendererWidget );
373 QList<int> oldBands = oldRenderer->
usesBands();
374 QList<int> newBands = newRenderer->
usesBands();
376 if ( oldBands != newBands )
378 populateTransparencyTable( newRenderer );
388 if ( mRendererWidget != oldWidget )
391 int widgetIndex = cboRenderers->findData( rendererName );
392 if ( widgetIndex != -1 )
394 whileBlocking( cboRenderers )->setCurrentIndex( widgetIndex );
399 void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
401 if ( mRendererWidget )