Skip to content
Permalink
Browse files

add gamma controls to the raster layer properties

  • Loading branch information
alexbruy committed Jun 30, 2020
1 parent ccae627 commit f37ac2ef2cd57677efe7e62d028fdfafd5bddb4e
@@ -21,6 +21,7 @@
#include "qgsgui.h"
#include "qgsapplication.h"
#include "qgsbrightnesscontrastfilter.h"
#include "qgsgammacorrectionfilter.h"
#include "qgscontrastenhancement.h"
#include "qgscoordinatetransform.h"
#include "qgsprojectionselectiondialog.h"
@@ -163,6 +164,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
connect( mContrastSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );

// gamma correction controls
connect( mSliderGamma, &QAbstractSlider::valueChanged, this, &QgsRasterLayerProperties::updateGammaSpinBox );
connect( mGammaSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterLayerProperties::updateGammaSlider );

// Connect saturation slider and spin box
connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
connect( spinBoxSaturation, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
@@ -753,17 +758,23 @@ void QgsRasterLayerProperties::sync()
QgsDebugMsg( QStringLiteral( "populate transparency tab" ) );

/*
* Style tab (brightness and contrast)
* Style tab
*/

//set brightness and contrast
QgsBrightnessContrastFilter *brightnessFilter = mRasterLayer->brightnessFilter();
if ( brightnessFilter )
{
mSliderBrightness->setValue( brightnessFilter->brightness() );
mSliderContrast->setValue( brightnessFilter->contrast() );
}

//set the transparency slider
//set gamma
QgsGammaCorrectionFilter *gammaFilter = mRasterLayer->gammaCorrectionFilter();
if ( gammaFilter )
{
mGammaSpinBox->setValue( gammaFilter->gamma() );
}

/*
* Transparent Pixel Tab
@@ -927,6 +938,7 @@ void QgsRasterLayerProperties::apply()

mRasterLayer->brightnessFilter()->setBrightness( mSliderBrightness->value() );
mRasterLayer->brightnessFilter()->setContrast( mSliderContrast->value() );
mRasterLayer->gammaCorrectionFilter()->setGamma( mGammaSpinBox->value() );

QgsDebugMsg( QStringLiteral( "processing transparency tab" ) );
/*
@@ -2312,6 +2324,7 @@ void QgsRasterLayerProperties::mResetColorRenderingBtn_clicked()
mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
mSliderBrightness->setValue( 0 );
mSliderContrast->setValue( 0 );
mGammaSpinBox->setValue( 1 );
sliderSaturation->setValue( 0 );
comboGrayscale->setCurrentIndex( ( int ) QgsHueSaturationFilter::GrayscaleOff );
mColorizeCheck->setChecked( false );
@@ -2359,3 +2372,13 @@ void QgsRasterLayerProperties::showHelp()
QgsHelp::openHelp( QStringLiteral( "working_with_raster/raster_properties.html" ) );
}
}

void QgsRasterLayerProperties::updateGammaSpinBox( int value )
{
whileBlocking( mGammaSpinBox )->setValue( value / 100.0 );
}

void QgsRasterLayerProperties::updateGammaSlider( double value )
{
whileBlocking( mSliderGamma )->setValue( value * 100 );
}
@@ -125,7 +125,17 @@ class GUI_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private

void pixelSelected( const QgsPointXY &, const Qt::MouseButton & );

/**
* updates gamma spinbox on slider changes
* \since QGIS 3.16
*/
void updateGammaSpinBox( int value );

/**
* updates gamma slider on spinbox changes
* \since QGIS 3.16
*/
void updateGammaSlider( double value );

void mRenderTypeComboBox_currentIndexChanged( int index );
//! Load the default style when appropriate button is pressed.

0 comments on commit f37ac2e

Please sign in to comment.
You can’t perform that action at this time.