75 changes: 75 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

connect( spinFontSize, SIGNAL( valueChanged( const QString& ) ), this, SLOT( fontSizeChanged( const QString& ) ) );

connect( chkUseStandardDeviation, SIGNAL( stateChanged( int ) ), this, SLOT( toggleStandardDeviation( int ) ) );

connect( this, SIGNAL( accepted() ), this, SLOT( saveOptions() ) );

QStringList styles = QStyleFactory::keys();
Expand Down Expand Up @@ -327,6 +329,41 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

cmbLegendDoubleClickAction->setCurrentIndex( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() );

//
// Raster properties
//
spnRed->setValue( settings.value( "/Raster/defaultRedBand", 1 ).toInt() );
spnGreen->setValue( settings.value( "/Raster/defaultGreenBand", 2 ).toInt() );
spnBlue->setValue( settings.value( "/Raster/defaultBlueBand", 3 ).toInt() );

//add items to the color enhanceContrast combo box
cboxContrastEnhancementAlgorithm->addItem( tr( "No Stretch" ) );
cboxContrastEnhancementAlgorithm->addItem( tr( "Stretch To MinMax" ) );
cboxContrastEnhancementAlgorithm->addItem( tr( "Stretch And Clip To MinMax" ) );
cboxContrastEnhancementAlgorithm->addItem( tr( "Clip To MinMax" ) );

QString contrastEnchacement = settings.value( "/Raster/defaultContrastEnhancementAlgorithm", "NoEnhancement" ).toString();
if ( contrastEnchacement == "NoEnhancement" )
{
cboxContrastEnhancementAlgorithm->setCurrentIndex( cboxContrastEnhancementAlgorithm->findText( tr( "No Stretch" ) ) );
}
if ( contrastEnchacement == "StretchToMinimumMaximum" )
{
cboxContrastEnhancementAlgorithm->setCurrentIndex( cboxContrastEnhancementAlgorithm->findText( tr( "Stretch To MinMax" ) ) );
}
else if ( contrastEnchacement == "StretchAndClipToMinimumMaximum" )
{
cboxContrastEnhancementAlgorithm->setCurrentIndex( cboxContrastEnhancementAlgorithm->findText( tr( "Stretch And Clip To MinMax" ) ) );
}
else if ( contrastEnchacement == "ClipToMinimumMaximum" )
{
cboxContrastEnhancementAlgorithm->setCurrentIndex( cboxContrastEnhancementAlgorithm->findText( tr( "Clip To MinMax" ) ) );
}

chkUseStandardDeviation->setChecked( settings.value( "/Raster/useStandardDeviation", false ).toBool() );
spnThreeBandStdDev->setValue( settings.value( "/Raster/defaultStandardDeviation", 2.0 ).toDouble() );
toggleStandardDeviation( chkUseStandardDeviation->checkState() );

//set the color for selections
int myRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt();
int myGreen = settings.value( "/qgis/default_selection_color_green", 255 ).toInt();
Expand Down Expand Up @@ -559,6 +596,18 @@ void QgsOptions::fontSizeChanged( const QString &fontSize )
QgisApp::instance()->setFontSize( fontSize.toInt() );
}

void QgsOptions::toggleStandardDeviation( int state )
{
if ( Qt::Checked == state )
{
spnThreeBandStdDev->setEnabled( true );
}
else
{
spnThreeBandStdDev->setEnabled( false );
}
}

QString QgsOptions::theme()
{
// returns the current theme (as selected in the cmbTheme combo box)
Expand Down Expand Up @@ -688,6 +737,32 @@ void QgsOptions::saveOptions()
settings.setValue( "/IconSize", cmbIconSize->currentText() );
settings.setValue( "/fontPointSize", spinFontSize->value() );

// rasters settings
settings.setValue( "/Raster/defaultRedBand", spnRed->value() );
settings.setValue( "/Raster/defaultGreenBand", spnGreen->value() );
settings.setValue( "/Raster/defaultBlueBand", spnBlue->value() );

if ( cboxContrastEnhancementAlgorithm->currentText() == tr( "No Stretch" ) )
{
settings.setValue( "/Raster/defaultContrastEnhancementAlgorithm", "NoEnhancement" );
}
else if ( cboxContrastEnhancementAlgorithm->currentText() == tr( "Stretch To MinMax" ) )
{
settings.setValue( "/Raster/defaultContrastEnhancementAlgorithm", "StretchToMinimumMaximum" );
}
else if ( cboxContrastEnhancementAlgorithm->currentText() == tr( "Stretch And Clip To MinMax" ) )
{
settings.setValue( "/Raster/defaultContrastEnhancementAlgorithm", "StretchAndClipToMinimumMaximum" );
}
else if ( cboxContrastEnhancementAlgorithm->currentText() == tr( "Clip To MinMax" ) )
{
settings.setValue( "/Raster/defaultContrastEnhancementAlgorithm", "ClipToMinimumMaximum" );
}

settings.setValue( "/Raster/useStandardDeviation", chkUseStandardDeviation->isChecked() );
settings.setValue( "/Raster/defaultStandardDeviation", spnThreeBandStdDev->value() );


settings.setValue( "/Map/updateThreshold", spinBoxUpdateThreshold->value() );
//check behaviour so default projection when new layer is added with no
//projection defined...
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase

void fontSizeChanged( const QString &fontSize );

void toggleStandardDeviation( int );

/**
* Return the desired state of newly added layers. If a layer
* is to be drawn when added to the map, this function returns
Expand Down
53 changes: 4 additions & 49 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
pbnDefaultValues->setIcon( QgisApp::getThemeIcon( "/mActionCopySelected.png" ) );
pbnImportTransparentPixelValues->setIcon( QgisApp::getThemeIcon( "/mActionFileOpen.png" ) );
pbnExportTransparentPixelValues->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
pbtnMakeBandCombinationDefault->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
pbtnMakeStandardDeviationDefault->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );

pbtnLoadColorMapFromBand->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) );
pbtnExportColorMapToFile->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
Expand Down Expand Up @@ -620,6 +617,8 @@ void QgsRasterLayerProperties::sync()
}
}

mDefaultStandardDeviation = myQSettings.value( "/Raster/defaultStandardDeviation", 2.0 ).toDouble();

if ( mRasterLayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGBDataType )
{
if ( rbtnThreeBand->isChecked() )
Expand Down Expand Up @@ -763,8 +762,8 @@ void QgsRasterLayerProperties::sync()
{
labelDefaultContrastEnhancementAlgorithm->setText( tr( "No Stretch" ) );
}
mDefaultStandardDeviation = myQSettings.value( "/Raster/defaultStandardDeviation", 2.0 ).toDouble();
sboxThreeBandStdDev->setValue( mDefaultStandardDeviation );
//mDefaultStandardDeviation = myQSettings.value( "/Raster/defaultStandardDeviation", 2.0 ).toDouble();
//sboxThreeBandStdDev->setValue( mDefaultStandardDeviation );
}

QgsDebugMsg( "populate transparency tab" );
Expand Down Expand Up @@ -2757,50 +2756,6 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
}
}

void QgsRasterLayerProperties::on_pbtnMakeBandCombinationDefault_clicked()
{
mDefaultRedBand = cboRed->currentIndex() + 1;
mDefaultGreenBand = cboGreen->currentIndex() + 1;
mDefaultBlueBand = cboBlue->currentIndex() + 1;
labelDefaultBandCombination->setText( tr( "Default R:%1 G:%2 B:%3" ).arg( mDefaultRedBand ).arg( mDefaultGreenBand ).arg( mDefaultBlueBand ) );
}

void QgsRasterLayerProperties::on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked()
{
if ( cboxContrastEnhancementAlgorithm->currentText() != tr( "User Defined" ) )
{
if ( cboxContrastEnhancementAlgorithm->currentText() == tr( "No Stretch" ) )
{
mDefaultContrastEnhancementAlgorithm = "NoEnhancement";
labelDefaultContrastEnhancementAlgorithm->setText( cboxContrastEnhancementAlgorithm->currentText() );
}
else if ( cboxContrastEnhancementAlgorithm->currentText() == tr( "Stretch To MinMax" ) )
{
mDefaultContrastEnhancementAlgorithm = "StretchToMinimumMaximum";
labelDefaultContrastEnhancementAlgorithm->setText( cboxContrastEnhancementAlgorithm->currentText() );
}
else if ( cboxContrastEnhancementAlgorithm->currentText() == tr( "Stretch And Clip To MinMax" ) )
{
mDefaultContrastEnhancementAlgorithm = "StretchAndClipToMinimumMaximum";
labelDefaultContrastEnhancementAlgorithm->setText( cboxContrastEnhancementAlgorithm->currentText() );
}
else if ( cboxContrastEnhancementAlgorithm->currentText() == tr( "Clip To MinMax" ) )
{
mDefaultContrastEnhancementAlgorithm = "ClipToMinimumMaximum";
labelDefaultContrastEnhancementAlgorithm->setText( cboxContrastEnhancementAlgorithm->currentText() );
}
else
{
//do nothing
}
}
}

void QgsRasterLayerProperties::on_pbtnMakeStandardDeviationDefault_clicked()
{
mDefaultStandardDeviation = sboxThreeBandStdDev->value();
}

void QgsRasterLayerProperties::on_pbtnSortColorMap_clicked()
{
bool inserted = false;
Expand Down
6 changes: 0 additions & 6 deletions src/app/qgsrasterlayerproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
void on_pbtnLoadColorMapFromFile_clicked();
/** This slot loads the minimum and maximum values from the raster band and updates the gui */
void on_pbtnLoadMinMax_clicked();
/** This slot sets the default band combination variable to current band combination */
void on_pbtnMakeBandCombinationDefault_clicked();
/** This slot sets the default contrast enhancement variable to current contrast enhancement algorithm */
void on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked();
/** This slot sets the standard deviation default */
void on_pbtnMakeStandardDeviationDefault_clicked();
/** This slot will sort the color map in ascending order */
void on_pbtnSortColorMap_clicked();
/** Load the default style when appropriate button is pressed. */
Expand Down
10 changes: 6 additions & 4 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,9 +2443,10 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
mDrawingStyle = MultiBandColor; //sensible default

// read standard deviations
if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum )
if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum &&
myQSettings.value( "/Raster/useStandardDeviation", false ).toBool() )
{
setStandardDeviations( myQSettings.value( "/Raster/defaultStandardDeviation", 2.0 ).toInt() );
setStandardDeviations( myQSettings.value( "/Raster/defaultStandardDeviation", 2.0 ).toDouble() );
}
}
else //GrayOrUndefined
Expand All @@ -2466,9 +2467,10 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
}

// read standard deviations
if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum )
if ( mContrastEnhancementAlgorithm == QgsContrastEnhancement::StretchToMinimumMaximum &&
myQSettings.value( "/Raster/useStandardDeviation", false ).toBool() )
{
setStandardDeviations( myQSettings.value( "/Raster/defaultStandardDeviation", 2.0 ).toInt() );
setStandardDeviations( myQSettings.value( "/Raster/defaultStandardDeviation", 2.0 ).toDouble() );
}
}
// Debug
Expand Down
Loading