-Fixed problem restoring min max values from project file

-Closes ticket #945
-Added ability choose in the GUI to load estimated or actual min max values from the band
-Cleaned and reorganized raster properties gui a little
-Added a set default constrast enhancement option in gui that is persistent between sessions
-Closes ticket #1055 and #778

git-svn-id: http://svn.osgeo.org/qgis/trunk@8398 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
ersts 2008-05-06 03:21:12 +00:00
parent 759fb39413
commit ce7c48f907
6 changed files with 1430 additions and 968 deletions

View File

@ -260,6 +260,12 @@ public:
void setMaximumValue(QString theBand, double theValue, bool theGenerateLookupTableFlag=true);
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates(int theBand, double* theMinMax);
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates(QString theBand, double* theMinMax);
QgsContrastEnhancement* getContrastEnhancement(unsigned int theBand);
//

View File

@ -42,7 +42,7 @@
#include <QPolygonF>
#include <QColorDialog>
#include <QList>
#include <QSettings>
#include <iostream>
@ -298,6 +298,7 @@ mRasterLayer( dynamic_cast<QgsRasterLayer*>(lyr) )
pbnDefaultValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionCopySelected.png")));
pbnImportTransparentPixelValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileOpen.png")));
pbnExportTransparentPixelValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSave.png")));
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSave.png")));
// Only do pyramids if dealing directly with GDAL.
if (mRasterLayerIsGdal)
@ -613,11 +614,6 @@ void QgsRasterLayerProperties::sync()
cboxInvertColorMap->setChecked(false);
}
//set the transparency slider
sliderTransparency->setValue(255 - mRasterLayer->getTransparency());
//update the transparency percentage label
sliderTransparency_valueChanged(255 - mRasterLayer->getTransparency());
//set the combos to the correct values
cboRed->setCurrentText(mRasterLayer->getRedBandName());
cboGreen->setCurrentText(mRasterLayer->getGreenBandName());
@ -712,6 +708,32 @@ void QgsRasterLayerProperties::sync()
{
cboxContrastEnhancementAlgorithm->setCurrentText(tr("No Scaling"));
}
//Display the current default contrast enhancement algorithm
QSettings myQSettings;
QString myDefaultAlgorithm = myQSettings.value("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH").toString();
if(myDefaultAlgorithm == "NO_STRETCH")
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("No Scaling"));
}
if(myDefaultAlgorithm == "STRETCH_TO_MINMAX")
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("Stretch To MinMax"));
}
else if(myDefaultAlgorithm == "STRETCH_AND_CLIP_TO_MINMAX")
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("Stretch And Clip To MinMax"));
}
else if(myDefaultAlgorithm == "CLIP_TO_MINMAX")
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("Clip To MinMax"));
}
else
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("No Scaling"));
}
#ifdef QGISDEBUG
QgsDebugMsg("QgsRasterLayerProperties::sync populate transparency tab");
@ -719,6 +741,12 @@ void QgsRasterLayerProperties::sync()
/*
* Transparent Pixel Tab
*/
//set the transparency slider
sliderTransparency->setValue(255 - mRasterLayer->getTransparency());
//update the transparency percentage label
sliderTransparency_valueChanged(255 - mRasterLayer->getTransparency());
int myIndex = cboxTransparencyLayer->findText(mRasterLayer->getTransparentLayerName());
if(-1 != myIndex)
{
@ -2697,22 +2725,87 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
if(rbtnThreeBand->isChecked())
{
rbtnThreeBandMinMax->setChecked(true);
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboRed->currentText()));
leRedMin->setText(QString::number(myRasterBandStats.minVal));
leRedMax->setText(QString::number(myRasterBandStats.maxVal));
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGreen->currentText()));
leGreenMin->setText(QString::number(myRasterBandStats.minVal));
leGreenMax->setText(QString::number(myRasterBandStats.maxVal));
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboBlue->currentText()));
leBlueMin->setText(QString::number(myRasterBandStats.minVal));
leBlueMax->setText(QString::number(myRasterBandStats.maxVal));
if(rbtnActualMinMax->isChecked())
{
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboRed->currentText()));
leRedMin->setText(QString::number(myRasterBandStats.minVal));
leRedMax->setText(QString::number(myRasterBandStats.maxVal));
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGreen->currentText()));
leGreenMin->setText(QString::number(myRasterBandStats.minVal));
leGreenMax->setText(QString::number(myRasterBandStats.maxVal));
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboBlue->currentText()));
leBlueMin->setText(QString::number(myRasterBandStats.minVal));
leBlueMax->setText(QString::number(myRasterBandStats.maxVal));
}
else
{
rbtnEstimateMinMax->setChecked(true);
double myMinimumMaximum[2];
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboRed->currentText()), myMinimumMaximum);
leRedMin->setText(QString::number(myMinimumMaximum[0]));
leRedMax->setText(QString::number(myMinimumMaximum[1]));
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboGreen->currentText()), myMinimumMaximum);
leGreenMin->setText(QString::number(myMinimumMaximum[0]));
leGreenMax->setText(QString::number(myMinimumMaximum[1]));
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboBlue->currentText()), myMinimumMaximum);
leBlueMin->setText(QString::number(myMinimumMaximum[0]));
leBlueMax->setText(QString::number(myMinimumMaximum[1]));
}
}
else
{
rbtnSingleBandMinMax->setChecked(true);
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGray->currentText()));
leGrayMin->setText(QString::number(myRasterBandStats.minVal));
leGrayMax->setText(QString::number(myRasterBandStats.maxVal));
if(rbtnActualMinMax->isChecked())
{
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGray->currentText()));
leGrayMin->setText(QString::number(myRasterBandStats.minVal));
leGrayMax->setText(QString::number(myRasterBandStats.maxVal));
}
else
{
rbtnEstimateMinMax->setChecked(true);
double myMinimumMaximum[2];
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboGray->currentText()), myMinimumMaximum);
leGrayMin->setText(QString::number(myMinimumMaximum[0]));
leGrayMax->setText(QString::number(myMinimumMaximum[1]));
}
}
}
}
void QgsRasterLayerProperties::on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked()
{
//Like some of the other functionality in the raster properties GUI this deviated a little from the
//best practice of GUI design as this pressing cancel will not undo setting the default
//contrast enhancement algorithm
if(cboxContrastEnhancementAlgorithm->currentText() != tr("User Defined"))
{
QSettings myQSettings;
if(cboxContrastEnhancementAlgorithm->currentText() == tr("No Stretch"))
{
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH");
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
}
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Stretch To MinMax"))
{
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "STRETCH_TO_MINMAX");
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
}
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Stretch And Clip To MinMax"))
{
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "STRETCH_AND_CLIP_TO_MINMAX");
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
}
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Clip To MinMax"))
{
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "CLIP_TO_MINMAX");
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
}
else
{
//do nothing
}
}
}

View File

@ -108,7 +108,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
/**Callback for double clicks on the colormap entry widget*/
void handleColormapTreeWidgetDoubleClick(QTreeWidgetItem* item, int column);
/**This slot loads the minimum and maximum values from the raster band and updates the gui*/
void on_pbtnLoadMinMax_clicked();
void on_pbtnLoadMinMax_clicked();
/**This slot save the current contrast enhancement algorithm as the default algorithm */
void on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked();
signals:

View File

@ -60,7 +60,7 @@ email : tim at linfiniti.com
#include <QPixmap>
#include <QRegExp>
#include <QSlider>
#include <QSettings>
// workaround for MSVC compiler which already has defined macro max
// that interferes with calling std::numeric_limits<int>::max
#ifdef _MSC_VER
@ -592,7 +592,9 @@ bool QgsRasterLayer::readFile( QString const & fileName )
}
//defaults - Needs to be set after the Contrast list has been build
setContrastEnhancementAlgorithm(QgsContrastEnhancement::STRETCH_TO_MINMAX);
//Try to read the default contrast enhancement from the config file
QSettings myQSettings;
setContrastEnhancementAlgorithm(myQSettings.value("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH").toString());
//decide what type of layer this is...
//note that multiband images can have one or more 'undefindd' bands,
@ -4320,6 +4322,16 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
myElement = snode.toElement();
setStdDevsToPlot(myElement.text().toDouble());
snode = mnl.namedItem("mUserDefinedRGBMinMaxFlag");
myElement = snode.toElement();
myQVariant = (QVariant) myElement.attribute("boolean");
setUserDefinedRGBMinMax(myQVariant.toBool());
snode = mnl.namedItem("mUserDefinedGrayMinMaxFlag");
myElement = snode.toElement();
myQVariant = (QVariant) myElement.attribute("boolean");
setUserDefinedGrayMinMax(myQVariant.toBool());
snode = mnl.namedItem("mContrastEnhancementAlgorithm");
myElement = snode.toElement();
setContrastEnhancementAlgorithm(myElement.text(), false);
@ -4659,6 +4671,34 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
rasterPropertiesElement.appendChild( mStandardDeviationsElement );
// <mUserDefinedRGBMinMaxFlag>
QDomElement userDefinedRGBMinMaxFlag = document.createElement( "mUserDefinedRGBMinMaxFlag" );
if ( getUserDefinedRGBMinMax() )
{
userDefinedRGBMinMaxFlag.setAttribute( "boolean", "true" );
}
else
{
userDefinedRGBMinMaxFlag.setAttribute( "boolean", "false" );
}
rasterPropertiesElement.appendChild( userDefinedRGBMinMaxFlag );
// <mUserDefinedGrayMinMaxFlag>
QDomElement userDefinedGrayMinMaxFlag = document.createElement( "mUserDefinedGrayMinMaxFlag" );
if ( getUserDefinedGrayMinMax() )
{
userDefinedGrayMinMaxFlag.setAttribute( "boolean", "true" );
}
else
{
userDefinedGrayMinMaxFlag.setAttribute( "boolean", "false" );
}
rasterPropertiesElement.appendChild( userDefinedGrayMinMaxFlag );
// <contrastEnhancementAlgorithm>
QDomElement contrastEnhancementAlgorithmElement = document.createElement( "mContrastEnhancementAlgorithm" );
QDomText contrastEnhancementAlgorithmText = document.createTextNode( getContrastEnhancementAlgorithmAsQString() );
@ -5391,4 +5431,8 @@ void QgsRasterLayer::setContrastEnhancementAlgorithm(QString theAlgorithm, bool
{
setContrastEnhancementAlgorithm(QgsContrastEnhancement::USER_DEFINED, theGenerateLookupTableFlag);
}
else
{
setContrastEnhancementAlgorithm(QgsContrastEnhancement::NO_STRETCH, theGenerateLookupTableFlag);
}
}

View File

@ -463,6 +463,7 @@ public:
// Accessor and mutator for minimum maximum values
//TODO: Move these out of the header file...
/** \brief Accessor for minimum value user for contrast enhancement */
double getMinimumValue(unsigned int theBand)
{
if(0 < theBand && theBand <= getBandCount())
@ -473,11 +474,13 @@ public:
return 0.0;
}
/** \brief Accessor for minimum value user for contrast enhancement */
double getMinimumValue(QString theBand)
{
return getMinimumValue(getRasterBandNumber(theBand));
}
/** \brief Mutator for setting the minimum value for contrast enhancement */
void setMinimumValue(unsigned int theBand, double theValue, bool theGenerateLookupTableFlag=true)
{
if(0 < theBand && theBand <= getBandCount())
@ -486,6 +489,7 @@ public:
}
}
/** \brief Mutator for setting the minimum value for contrast enhancement */
void setMinimumValue(QString theBand, double theValue, bool theGenerateLookupTableFlag=true)
{
if(theBand != tr("Not Set"))
@ -495,6 +499,7 @@ public:
}
/** \brief Accessor for maximum value user for contrast enhancement */
double getMaximumValue(unsigned int theBand)
{
if(0 < theBand && theBand <= getBandCount())
@ -505,6 +510,7 @@ public:
return 0.0;
}
/** \brief Accessor for maximum value user for contrast enhancement */
double getMaximumValue(QString theBand)
{
if(theBand != tr("Not Set"))
@ -515,6 +521,7 @@ public:
return 0.0;
}
/** \brief Mutator for setting the maximum value for contrast enhancement */
void setMaximumValue(unsigned int theBand, double theValue, bool theGenerateLookupTableFlag=true)
{
if(0 < theBand && theBand <= getBandCount())
@ -523,6 +530,7 @@ public:
}
}
/** \brief Mutator for setting the maximum value for contrast enhancement */
void setMaximumValue(QString theBand, double theValue, bool theGenerateLookupTableFlag=true)
{
if(theBand != tr("Not Set"))
@ -531,6 +539,22 @@ public:
}
}
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates(int theBand, double* theMinMax)
{
if(0 < theBand && theBand <= getBandCount())
{
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBand);
GDALComputeRasterMinMax( myGdalBand, 1, theMinMax );
}
}
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates(QString theBand, double* theMinMax)
{
computeMinimumMaximumEstimates(getRasterBandNumber(theBand), theMinMax);
}
QgsContrastEnhancement* getContrastEnhancement(unsigned int theBand)
{
return &mContrastEnhancementList[theBand - 1];

File diff suppressed because it is too large Load Diff