[QGIS Commit] r14031 - in trunk/qgis: python/core src/app/legend
src/core/raster
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Aug 8 21:20:59 EDT 2010
Author: ersts
Date: 2010-08-09 01:20:59 +0000 (Mon, 09 Aug 2010)
New Revision: 14031
Modified:
trunk/qgis/python/core/qgsrasterlayer.sip
trunk/qgis/src/app/legend/qgslegend.cpp
trunk/qgis/src/app/legend/qgslegend.h
trunk/qgis/src/app/legend/qgslegendlayer.cpp
trunk/qgis/src/core/raster/qgsrasterlayer.cpp
trunk/qgis/src/core/raster/qgsrasterlayer.h
Log:
-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
Modified: trunk/qgis/python/core/qgsrasterlayer.sip
===================================================================
--- trunk/qgis/python/core/qgsrasterlayer.sip 2010-08-08 16:11:42 UTC (rev 14030)
+++ trunk/qgis/python/core/qgsrasterlayer.sip 2010-08-09 01:20:59 UTC (rev 14031)
@@ -417,6 +417,9 @@
/** \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 );
Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp 2010-08-08 16:11:42 UTC (rev 14030)
+++ trunk/qgis/src/app/legend/qgslegend.cpp 2010-08-09 01:20:59 UTC (rev 14031)
@@ -1624,6 +1624,35 @@
}
}
+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" );
Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h 2010-08-08 16:11:42 UTC (rev 14030)
+++ trunk/qgis/src/app/legend/qgslegend.h 2010-08-09 01:20:59 UTC (rev 14031)
@@ -253,10 +253,14 @@
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:
Modified: trunk/qgis/src/app/legend/qgslegendlayer.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegendlayer.cpp 2010-08-08 16:11:42 UTC (rev 14030)
+++ trunk/qgis/src/app/legend/qgslegendlayer.cpp 2010-08-09 01:20:59 UTC (rev 14031)
@@ -395,6 +395,12 @@
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
Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2010-08-08 16:11:42 UTC (rev 14030)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2010-08-09 01:20:59 UTC (rev 14031)
@@ -3490,6 +3490,35 @@
}
}
+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() )
Modified: trunk/qgis/src/core/raster/qgsrasterlayer.h
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.h 2010-08-08 16:11:42 UTC (rev 14030)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.h 2010-08-09 01:20:59 UTC (rev 14031)
@@ -583,6 +583,9 @@
/** \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 );
More information about the QGIS-commit
mailing list