Skip to content

Commit 93ade1f

Browse files
committed
Merge pull request #480 from nyalldawson/hue_saturation
Add hue and saturation controls for raster layers
2 parents 1b663bb + 0f7e90b commit 93ade1f

10 files changed

+663
-4
lines changed

src/app/qgsrasterlayerproperties.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "qgsrastertransparency.h"
4646
#include "qgssinglebandgrayrendererwidget.h"
4747
#include "qgssinglebandpseudocolorrendererwidget.h"
48+
#include "qgshuesaturationfilter.h"
4849

4950
#include <QTableWidgetItem>
5051
#include <QHeaderView>
@@ -89,6 +90,20 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
8990
connect( mSliderContrast, SIGNAL( valueChanged( int ) ), mContrastSpinBox, SLOT( setValue( int ) ) );
9091
connect( mContrastSpinBox, SIGNAL( valueChanged( int ) ), mSliderContrast, SLOT( setValue( int ) ) );
9192

93+
// Connect saturation slider and spin box
94+
connect( sliderSaturation, SIGNAL( valueChanged( int ) ), spinBoxSaturation, SLOT( setValue( int ) ) );
95+
connect( spinBoxSaturation, SIGNAL( valueChanged( int ) ), sliderSaturation, SLOT( setValue( int ) ) );
96+
97+
// Connect colorize strength slider and spin box
98+
connect( sliderColorizeStrength, SIGNAL( valueChanged( int ) ), spinColorizeStrength, SLOT( setValue( int ) ) );
99+
connect( spinColorizeStrength, SIGNAL( valueChanged( int ) ), sliderColorizeStrength, SLOT( setValue( int ) ) );
100+
101+
// enable or disable saturation slider and spin box depending on grayscale combo choice
102+
connect( comboGrayscale, SIGNAL( currentIndexChanged( int ) ), this, SLOT( toggleSaturationControls( int ) ) );
103+
104+
// enable or disable colorize colorbutton with colorize checkbox
105+
connect( mColorizeCheck, SIGNAL( toggled( bool ) ), this, SLOT( toggleColorizeControls( bool ) ) );
106+
92107
// enable or disable Build Pyramids button depending on selection in pyramid list
93108
connect( lbxPyramidResolutions, SIGNAL( itemSelectionChanged() ), this, SLOT( toggleBuildPyramidsButton() ) );
94109

@@ -250,6 +265,25 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
250265
mMaximumOversamplingSpinBox->setValue( resampleFilter->maxOversampling() );
251266
}
252267

268+
// Hue and saturation color control
269+
mHueSaturationGroupBox->setSaveCheckedState( true );
270+
const QgsHueSaturationFilter* hueSaturationFilter = mRasterLayer->hueSaturationFilter();
271+
//set hue and saturation controls to current values
272+
if ( hueSaturationFilter )
273+
{
274+
sliderSaturation->setValue( hueSaturationFilter->saturation() );
275+
comboGrayscale->setCurrentIndex(( int ) hueSaturationFilter->grayscaleMode() );
276+
277+
// Set initial state of saturation controls based on grayscale mode choice
278+
toggleSaturationControls(( int )hueSaturationFilter->grayscaleMode() );
279+
280+
// Set initial state of colorize controls
281+
mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
282+
btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
283+
toggleColorizeControls( hueSaturationFilter->colorizeOn() );
284+
sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
285+
}
286+
253287
//blend mode
254288
mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );
255289

@@ -824,6 +858,17 @@ void QgsRasterLayerProperties::apply()
824858
resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
825859
}
826860

861+
// Hue and saturation controls
862+
QgsHueSaturationFilter* hueSaturationFilter = mRasterLayer->hueSaturationFilter();
863+
if ( hueSaturationFilter )
864+
{
865+
hueSaturationFilter->setSaturation( sliderSaturation->value() );
866+
hueSaturationFilter->setGrayscaleMode(( QgsHueSaturationFilter::GrayscaleMode ) comboGrayscale->currentIndex() );
867+
hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
868+
hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
869+
hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
870+
}
871+
827872
//set the blend mode for the layer
828873
mRasterLayer->setBlendMode(( QgsMapRenderer::BlendMode ) mBlendModeComboBox->blendMode() );
829874

@@ -1457,6 +1502,29 @@ void QgsRasterLayerProperties::sliderTransparency_valueChanged( int theValue )
14571502
lblTransparencyPercent->setText( QString::number( myInt ) + "%" );
14581503
}//sliderTransparency_valueChanged
14591504

1505+
void QgsRasterLayerProperties::toggleSaturationControls( int grayscaleMode )
1506+
{
1507+
// Enable or disable saturation controls based on choice of grayscale mode
1508+
if ( grayscaleMode == 0 )
1509+
{
1510+
sliderSaturation->setEnabled( true );
1511+
spinBoxSaturation->setEnabled( true );
1512+
}
1513+
else
1514+
{
1515+
sliderSaturation->setEnabled( false );
1516+
spinBoxSaturation->setEnabled( false );
1517+
}
1518+
}
1519+
1520+
void QgsRasterLayerProperties::toggleColorizeControls( bool colorizeEnabled )
1521+
{
1522+
// Enable or disable colorize controls based on checkbox
1523+
btnColorizeColor->setEnabled( colorizeEnabled );
1524+
sliderColorizeStrength->setEnabled( colorizeEnabled );
1525+
spinColorizeStrength->setEnabled( colorizeEnabled );
1526+
}
1527+
14601528

14611529
QLinearGradient QgsRasterLayerProperties::redGradient()
14621530
{

src/app/qgsrasterlayerproperties.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
103103
/**Enable or disable Build pyramids button depending on selection in pyramids list*/
104104
void toggleBuildPyramidsButton();
105105

106+
/**Enable or disable saturation controls depending on choice of grayscale mode */
107+
void toggleSaturationControls( int grayscaleMode );
108+
109+
/**Enable or disable colorize controls depending on checkbox */
110+
void toggleColorizeControls( bool colorizeEnabled );
111+
106112
/** Update items in pipe list */
107113
void pipeItemClicked( QTreeWidgetItem * item, int column );
108114

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ SET(QGIS_CORE_SRCS
211211
raster/qgssinglebandgrayrenderer.cpp
212212
raster/qgssinglebandpseudocolorrenderer.cpp
213213
raster/qgsbrightnesscontrastfilter.cpp
214+
raster/qgshuesaturationfilter.cpp
214215

215216
renderer/qgscontinuouscolorrenderer.cpp
216217
renderer/qgsgraduatedsymbolrenderer.cpp

0 commit comments

Comments
 (0)