Skip to content
Permalink
Browse files
-Added a new option to the legend menu that will stretch the current …
…layer using the min and max pixel values of the current extent

-Added a convenience function QgsRasterLayer::setMinimumMaximumUsingLastExtent that will set the min max of the current band or bands being displayed using the pixel values from the last extent

git-svn-id: http://svn.osgeo.org/qgis/trunk@14031 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts committed Aug 9, 2010
1 parent 68e21e7 commit d5e0f6bffdf64bf1469157ef0af9ba3c64c67926
@@ -417,6 +417,9 @@ public:
/** \brief Mutator for setting the maximum value for contrast enhancement */
void setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );

/** \brief Sets the minimum and maximum values for the band(s) currently being displayed using the only pixel values from the last/current extent */
void setMinimumMaximumUsingLastExtent();

/** \brief Mutator for setting the minimum value for contrast enhancement */
void setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );

@@ -1624,6 +1624,35 @@ void QgsLegend::legendLayerZoomNative()
}
}

void QgsLegend::legendLayerStretchUsingCurrentExtent()
{
//find current Layer
QgsLegendLayer* currentLayer = dynamic_cast<QgsLegendLayer *>( currentItem() );
if ( !currentLayer )
return;

QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( currentLayer->layer() );
if ( layer )
{
if ( layer->drawingStyle() == QgsRasterLayer::SingleBandPseudoColor )
{
layer->setDrawingStyle( QgsRasterLayer::SingleBandGray );
}
else if ( layer->drawingStyle() == QgsRasterLayer::MultiBandSingleBandPseudoColor )
{
layer->setDrawingStyle( QgsRasterLayer::MultiBandSingleGandGray );
}

if ( layer->contrastEnhancementAlgorithmAsString() == "NoEnhancement" )
{
layer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" );
}

layer->setMinimumMaximumUsingLastExtent();
mMapCanvas->refresh();
}
}

void QgsLegend::readProject( const QDomDocument & doc )
{
QDomNodeList nodes = doc.elementsByTagName( "legend" );
@@ -253,10 +253,14 @@ class QgsLegend : public QTreeWidget
legend layer files*/
void legendLayerZoom();

/***Zooms so that the pixels of the raster layer occupies exactly one screen pixel.
/**Zooms so that the pixels of the raster layer occupies exactly one screen pixel.
Only works on raster layers*/
void legendLayerZoomNative();

/**Stretches the raster layer, if stretching is active, based on the min and max of the current extent.
Only workds on raster layers*/
void legendLayerStretchUsingCurrentExtent();

/**Updates check states when the map canvas layer set is changed */
void refreshCheckStates();
protected:
@@ -395,6 +395,12 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
if ( lyr->type() == QgsMapLayer::RasterLayer )
{
theMenu.addAction( tr( "&Zoom to best scale (100%)" ), legend(), SLOT( legendLayerZoomNative() ) );

QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( lyr );
if( rasterLayer && rasterLayer->rasterType() != QgsRasterLayer::Palette )
{
theMenu.addAction( tr( "&Stretch using current extent" ), legend(), SLOT( legendLayerStretchUsingCurrentExtent() ) );
}
}

// show in overview
@@ -3490,6 +3490,35 @@ void QgsRasterLayer::setMaximumValue( QString theBand, double theValue, bool the
}
}

void QgsRasterLayer::setMinimumMaximumUsingLastExtent()
{
double myMinMax[2];
if ( rasterType() == QgsRasterLayer::GrayOrUndefined || drawingStyle() == QgsRasterLayer::SingleBandGray || drawingStyle() == QgsRasterLayer::MultiBandSingleGandGray )
{
computeMinimumMaximumFromLastExtent( grayBandName(), myMinMax );
setMinimumValue( grayBandName(), myMinMax[0] );
setMaximumValue( grayBandName(), myMinMax[1] );

setUserDefinedGrayMinimumMaximum( true );
}
else if ( rasterType() == QgsRasterLayer::Multiband )
{
computeMinimumMaximumFromLastExtent( redBandName(), myMinMax );
setMinimumValue( redBandName(), myMinMax[0], false );
setMaximumValue( redBandName(), myMinMax[1], false );

computeMinimumMaximumFromLastExtent( greenBandName(), myMinMax );
setMinimumValue( greenBandName(), myMinMax[0], false );
setMaximumValue( greenBandName(), myMinMax[1], false );

computeMinimumMaximumFromLastExtent( blueBandName(), myMinMax );
setMinimumValue( blueBandName(), myMinMax[0], false );
setMaximumValue( blueBandName(), myMinMax[1], false );

setUserDefinedRGBMinimumMaximum( true );
}
}

void QgsRasterLayer::setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag )
{
if ( 0 < theBand && theBand <= bandCount() )
@@ -583,6 +583,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Mutator for setting the maximum value for contrast enhancement */
void setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );

/** \brief Sets the minimum and maximum values for the band(s) currently being displayed using the only pixel values from the last/current extent */
void setMinimumMaximumUsingLastExtent();

/** \brief Mutator for setting the minimum value for contrast enhancement */
void setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );

0 comments on commit d5e0f6b

Please sign in to comment.