Skip to content

Commit 3e7267a

Browse files
author
timlinux
committed
Added callback functions and hooked it up to the raster properties dialogs so that building pyramids and computing histogram now shows progress bar indication. Also change cursor to hourglass while computing histograms.
git-svn-id: http://svn.osgeo.org/qgis/trunk@8957 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d29a50a commit 3e7267a

File tree

4 files changed

+159
-127
lines changed

4 files changed

+159
-127
lines changed

src/app/qgsrasterlayerproperties.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,7 @@ void QgsRasterLayerProperties::on_buttonBox_helpRequested()
15701570
void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
15711571
{
15721572

1573+
connect(mRasterLayer, SIGNAL(progressUpdate(int)), mPyramidProgress, SLOT(setValue(int)));
15731574
//
15741575
// Go through the list marking any files that are selected in the listview
15751576
// as true so that we can generate pyramids for them.
@@ -1592,6 +1593,7 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
15921593
QApplication::setOverrideCursor(Qt::WaitCursor);
15931594
QString res = mRasterLayer->buildPyramids(myPyramidList,cboResamplingMethod->currentText());
15941595
QApplication::restoreOverrideCursor();
1596+
disconnect(mRasterLayer, SIGNAL(progressUpdate(int)), mPyramidProgress, SLOT(setValue(int)));
15951597
if (!res.isNull())
15961598
{
15971599
if (res == "ERROR_WRITE_ACCESS")
@@ -1867,6 +1869,8 @@ void QgsRasterLayerProperties::on_pbnExportTransparentPixelValues_clicked()
18671869

18681870
void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
18691871
{
1872+
connect(mRasterLayer, SIGNAL(progressUpdate(int)), mHistogramProgress, SLOT(setValue(int)));
1873+
QApplication::setOverrideCursor(Qt::WaitCursor);
18701874
#ifdef QGISDEBUG
18711875
std::cout << "QgsRasterLayerProperties::on_pbnHistRefresh_clicked" << std::endl;
18721876
#endif
@@ -1960,6 +1964,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
19601964
myFirstItemFlag=false;
19611965
}
19621966
}
1967+
disconnect(mRasterLayer, SIGNAL(progressUpdate(int)), mHistogramProgress, SLOT(setValue(int)));
19631968
#ifdef QGISDEBUG
19641969
std::cout << "max " << myYAxisMax << std::endl;
19651970
std::cout << "min " << myYAxisMin << std::endl;
@@ -2289,6 +2294,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
22892294
//
22902295
myPainter.end();
22912296
pixHistogram->setPixmap(myPixmap);
2297+
QApplication::restoreOverrideCursor();
22922298
}
22932299

22942300
void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked()

src/core/raster/qgsrasterlayer.cpp

+57-4
Original file line numberDiff line numberDiff line change
@@ -3728,18 +3728,18 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid
37283728
if(theResamplingMethod==tr("Average Magphase"))
37293729
{
37303730
myError = GDALBuildOverviews( mGdalDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
3731-
GDALDummyProgress, NULL );
3731+
progressCallback, this); //this is the arg for the gdal progress callback
37323732
}
37333733
else if(theResamplingMethod==tr("Average"))
37343734

37353735
{
37363736
myError = GDALBuildOverviews( mGdalDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
3737-
GDALDummyProgress, NULL );
3737+
progressCallback, this); //this is the arg for the gdal progress callback
37383738
}
37393739
else // fall back to nearest neighbor
37403740
{
37413741
myError = GDALBuildOverviews( mGdalDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
3742-
GDALDummyProgress, NULL );
3742+
progressCallback, this); //this is the arg for the gdal progress callback
37433743
}
37443744
if (myError == CE_Failure || CPLGetLastErrorNo()==CPLE_NotSupported )
37453745
{
@@ -4749,7 +4749,10 @@ void QgsRasterLayer::populateHistogram(int theBandNo, int theBinCount,bool theIg
47494749
* )
47504750
*/
47514751
double myerval = (myRasterBandStats.maxVal-myRasterBandStats.minVal)/theBinCount;
4752-
GDALGetRasterHistogram( myGdalBand, myRasterBandStats.minVal-0.1*myerval, myRasterBandStats.maxVal+0.1*myerval, theBinCount, myHistogramArray ,theIgnoreOutOfRangeFlag ,theHistogramEstimatedFlag , GDALDummyProgress, NULL );
4752+
GDALGetRasterHistogram( myGdalBand, myRasterBandStats.minVal-0.1*myerval,
4753+
myRasterBandStats.maxVal+0.1*myerval, theBinCount, myHistogramArray
4754+
,theIgnoreOutOfRangeFlag ,theHistogramEstimatedFlag , progressCallback,
4755+
this ); //this is the arg for our custome gdal progress callback
47534756

47544757
for (int myBin = 0; myBin <theBinCount; myBin++)
47554758
{
@@ -5219,3 +5222,53 @@ void QgsRasterLayer::setContrastEnhancementAlgorithm(QString theAlgorithm, bool
52195222
setContrastEnhancementAlgorithm(QgsContrastEnhancement::NO_STRETCH, theGenerateLookupTableFlag);
52205223
}
52215224
}
5225+
5226+
void QgsRasterLayer::showProgress(int theValue)
5227+
{
5228+
emit progressUpdate(theValue);
5229+
}
5230+
//
5231+
// global callback function
5232+
//
5233+
int CPL_STDCALL progressCallback( double dfComplete,
5234+
const char * pszMessage,
5235+
void * pProgressArg)
5236+
{
5237+
static double dfLastComplete = -1.0;
5238+
5239+
QgsRasterLayer * mypLayer = (QgsRasterLayer *) pProgressArg;
5240+
5241+
if( dfLastComplete > dfComplete )
5242+
{
5243+
if( dfLastComplete >= 1.0 )
5244+
dfLastComplete = -1.0;
5245+
else
5246+
dfLastComplete = dfComplete;
5247+
}
5248+
5249+
if( floor(dfLastComplete*10) != floor(dfComplete*10) )
5250+
{
5251+
int nPercent = (int) floor(dfComplete*100);
5252+
5253+
if( nPercent == 0 && pszMessage != NULL )
5254+
{
5255+
//fprintf( stdout, "%s:", pszMessage );
5256+
}
5257+
5258+
if( nPercent == 100 )
5259+
{
5260+
//fprintf( stdout, "%d - done.\n", (int) floor(dfComplete*100) );
5261+
mypLayer->showProgress(100);
5262+
}
5263+
else
5264+
{
5265+
int myProgress = (int) floor(dfComplete*100);
5266+
//fprintf( stdout, "%d.", myProgress);
5267+
mypLayer->showProgress(myProgress);
5268+
//fflush( stdout );
5269+
}
5270+
}
5271+
dfLastComplete = dfComplete;
5272+
5273+
return TRUE;
5274+
}

src/core/raster/qgsrasterlayer.h

+14-12
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,17 @@
137137
#include "qgsrastertransparency.h"
138138
#include "qgsrastershader.h"
139139
#include "qgsrastershaderfunction.h"
140-
141-
/*
142-
*
143-
* New includes that will convert this class to a data provider interface
144-
* (B Morley)
145-
*
146-
*/
147-
148140
#include "qgsrasterdataprovider.h"
149141

150-
/*
151-
* END
152-
*/
153142

154143
#define CPL_SUPRESS_CPLUSPLUS
155-
156144
#include <gdal.h>
157145

146+
int CPL_STDCALL progressCallback( double dfComplete,
147+
const char *pszMessage,
148+
void * pProgressArg );
149+
150+
158151
//
159152
// Forward declarations
160153
//
@@ -1113,10 +1106,19 @@ public slots:
11131106
//! Which provider is being used for this Raster Layer?
11141107
QString providerKey();
11151108

1109+
/** A wrapper function to emit a progress update signal.
1110+
* For example used by gdal callback to show pyramid building progress.
1111+
*/
1112+
void showProgress(int theValue);
1113+
11161114
public slots:
11171115

11181116
void showStatusMessage(const QString & theMessage);
11191117

1118+
signals:
1119+
//for notifying listeners of long running processes
1120+
void progressUpdate(int theValue);
1121+
11201122

11211123
private:
11221124

0 commit comments

Comments
 (0)