@@ -1209,6 +1209,12 @@ void QgisApp::createActions()
1209
1209
mWindowActions = new QActionGroup ( this );
1210
1210
#endif
1211
1211
1212
+ // Raster toolbar items
1213
+ mActionLocalHistogramStretch = new QAction ( getThemeIcon ( " mActionmRasterLocalHistogramStretch.png" ), tr ( " Local Histogram Stretch" ), this );
1214
+ mActionLocalHistogramStretch ->setStatusTip ( tr ( " Stretch histogram of active raster to view extents" ) );
1215
+ connect ( mActionLocalHistogramStretch , SIGNAL ( triggered () ), this , SLOT ( localHistogramStretch () ) );
1216
+
1217
+
1212
1218
// Help Menu Items
1213
1219
1214
1220
mActionHelpContents = new QAction ( getThemeIcon ( " mActionHelpContents.png" ), tr ( " Help Contents" ), this );
@@ -1864,6 +1870,14 @@ void QgisApp::createToolBars()
1864
1870
mHelpToolBar ->addAction ( mActionHelpContents );
1865
1871
mHelpToolBar ->addAction ( QWhatsThis::createAction () );
1866
1872
mToolbarMenu ->addAction ( mHelpToolBar ->toggleViewAction () );
1873
+
1874
+ //
1875
+ // Raster Toolbar
1876
+ mRasterToolBar = addToolBar ( tr ( " Raster" ) );
1877
+ mRasterToolBar ->setObjectName ( " Raster" );
1878
+ mRasterToolBar ->addAction ( mActionLocalHistogramStretch );
1879
+ mToolbarMenu ->addAction ( mRasterToolBar ->toggleViewAction () );
1880
+
1867
1881
1868
1882
// Label Toolbar
1869
1883
mLabelToolBar = addToolBar ( tr ( " Label" ) );
@@ -2070,6 +2084,7 @@ void QgisApp::setTheme( QString theThemeName )
2070
2084
mActionOptions ->setIcon ( getThemeIcon ( " /mActionOptions.png" ) );
2071
2085
mActionConfigureShortcuts ->setIcon ( getThemeIcon ( " /mActionOptions.png" ) );
2072
2086
mActionHelpContents ->setIcon ( getThemeIcon ( " /mActionHelpContents.png" ) );
2087
+ mActionLocalHistogramStretch ->setIcon ( getThemeIcon ( " /mActionLocalHistogramStretch.png" ) );
2073
2088
mActionQgisHomePage ->setIcon ( getThemeIcon ( " /mActionQgisHomePage.png" ) );
2074
2089
mActionAbout ->setIcon ( getThemeIcon ( " /mActionHelpAbout.png" ) );
2075
2090
mActionDraw ->setIcon ( getThemeIcon ( " /mActionDraw.png" ) );
@@ -5459,6 +5474,48 @@ void QgisApp::options()
5459
5474
delete optionsDialog;
5460
5475
}
5461
5476
5477
+ void QgisApp::localHistogramStretch ()
5478
+ {
5479
+ QgsMapLayer * layer = mMapLegend ->currentLayer ();
5480
+
5481
+ if ( !layer )
5482
+ {
5483
+ QMessageBox::information ( this ,
5484
+ tr ( " No Layer Selected" ),
5485
+ tr ( " To perform a local histogram stretch, you need to have a raster layer selected." ) );
5486
+ return ;
5487
+ }
5488
+
5489
+ QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
5490
+ if ( !rlayer )
5491
+ {
5492
+ QMessageBox::information ( this ,
5493
+ tr ( " No Raster Layer Selected" ),
5494
+ tr ( " To perform a local histogram stretch, you need to have a raster layer selected." ) );
5495
+ return ;
5496
+ }
5497
+ if ( rlayer->drawingStyle () == QgsRasterLayer::SingleBandGray ||
5498
+ rlayer->drawingStyle () == QgsRasterLayer::MultiBandSingleBandGray
5499
+ )
5500
+ {
5501
+ rlayer->setContrastEnhancementAlgorithm ( " StretchToMinimumMaximum" );
5502
+ rlayer->setMinimumMaximumUsingLastExtent ();
5503
+ rlayer->setCacheImage (NULL );
5504
+ // refreshLayerSymbology( rlayer->getLayerID() );
5505
+ mMapCanvas ->refresh ();
5506
+ return ;
5507
+ }
5508
+ else
5509
+ {
5510
+ QMessageBox::information ( this ,
5511
+ tr ( " No Valid Raster Layer Selected" ),
5512
+ tr ( " To perform a local histogram stretch, you need to have a grayscale "
5513
+ " (multiband single layer, or singleband grayscale) raster layer "
5514
+ " selected." ) );
5515
+ return ;
5516
+ }
5517
+ }
5518
+
5462
5519
void QgisApp::helpContents ()
5463
5520
{
5464
5521
openURL ( " index.html" );
0 commit comments