Skip to content
Permalink
Browse files
Added callback functions and hooked it up to the raster properties di…
…alogs 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/qgis@8957 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 1, 2008
1 parent 57cb59a commit 3ac19d9
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 127 deletions.
@@ -1570,6 +1570,7 @@ void QgsRasterLayerProperties::on_buttonBox_helpRequested()
void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
{

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

void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
{
connect(mRasterLayer, SIGNAL(progressUpdate(int)), mHistogramProgress, SLOT(setValue(int)));
QApplication::setOverrideCursor(Qt::WaitCursor);
#ifdef QGISDEBUG
std::cout << "QgsRasterLayerProperties::on_pbnHistRefresh_clicked" << std::endl;
#endif
@@ -1960,6 +1964,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
myFirstItemFlag=false;
}
}
disconnect(mRasterLayer, SIGNAL(progressUpdate(int)), mHistogramProgress, SLOT(setValue(int)));
#ifdef QGISDEBUG
std::cout << "max " << myYAxisMax << std::endl;
std::cout << "min " << myYAxisMin << std::endl;
@@ -2289,6 +2294,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
//
myPainter.end();
pixHistogram->setPixmap(myPixmap);
QApplication::restoreOverrideCursor();
}

void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked()
@@ -3728,18 +3728,18 @@ QString QgsRasterLayer::buildPyramids(RasterPyramidList const & theRasterPyramid
if(theResamplingMethod==tr("Average Magphase"))
{
myError = GDALBuildOverviews( mGdalDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
GDALDummyProgress, NULL );
progressCallback, this); //this is the arg for the gdal progress callback
}
else if(theResamplingMethod==tr("Average"))

{
myError = GDALBuildOverviews( mGdalDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
GDALDummyProgress, NULL );
progressCallback, this); //this is the arg for the gdal progress callback
}
else // fall back to nearest neighbor
{
myError = GDALBuildOverviews( mGdalDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
GDALDummyProgress, NULL );
progressCallback, this); //this is the arg for the gdal progress callback
}
if (myError == CE_Failure || CPLGetLastErrorNo()==CPLE_NotSupported )
{
@@ -4749,7 +4749,10 @@ void QgsRasterLayer::populateHistogram(int theBandNo, int theBinCount,bool theIg
* )
*/
double myerval = (myRasterBandStats.maxVal-myRasterBandStats.minVal)/theBinCount;
GDALGetRasterHistogram( myGdalBand, myRasterBandStats.minVal-0.1*myerval, myRasterBandStats.maxVal+0.1*myerval, theBinCount, myHistogramArray ,theIgnoreOutOfRangeFlag ,theHistogramEstimatedFlag , GDALDummyProgress, NULL );
GDALGetRasterHistogram( myGdalBand, myRasterBandStats.minVal-0.1*myerval,
myRasterBandStats.maxVal+0.1*myerval, theBinCount, myHistogramArray
,theIgnoreOutOfRangeFlag ,theHistogramEstimatedFlag , progressCallback,
this ); //this is the arg for our custome gdal progress callback

for (int myBin = 0; myBin <theBinCount; myBin++)
{
@@ -5219,3 +5222,53 @@ void QgsRasterLayer::setContrastEnhancementAlgorithm(QString theAlgorithm, bool
setContrastEnhancementAlgorithm(QgsContrastEnhancement::NO_STRETCH, theGenerateLookupTableFlag);
}
}

void QgsRasterLayer::showProgress(int theValue)
{
emit progressUpdate(theValue);
}
//
// global callback function
//
int CPL_STDCALL progressCallback( double dfComplete,
const char * pszMessage,
void * pProgressArg)
{
static double dfLastComplete = -1.0;

QgsRasterLayer * mypLayer = (QgsRasterLayer *) pProgressArg;

if( dfLastComplete > dfComplete )
{
if( dfLastComplete >= 1.0 )
dfLastComplete = -1.0;
else
dfLastComplete = dfComplete;
}

if( floor(dfLastComplete*10) != floor(dfComplete*10) )
{
int nPercent = (int) floor(dfComplete*100);

if( nPercent == 0 && pszMessage != NULL )
{
//fprintf( stdout, "%s:", pszMessage );
}

if( nPercent == 100 )
{
//fprintf( stdout, "%d - done.\n", (int) floor(dfComplete*100) );
mypLayer->showProgress(100);
}
else
{
int myProgress = (int) floor(dfComplete*100);
//fprintf( stdout, "%d.", myProgress);
mypLayer->showProgress(myProgress);
//fflush( stdout );
}
}
dfLastComplete = dfComplete;

return TRUE;
}
@@ -137,24 +137,17 @@
#include "qgsrastertransparency.h"
#include "qgsrastershader.h"
#include "qgsrastershaderfunction.h"

/*
*
* New includes that will convert this class to a data provider interface
* (B Morley)
*
*/

#include "qgsrasterdataprovider.h"

/*
* END
*/

#define CPL_SUPRESS_CPLUSPLUS

#include <gdal.h>

int CPL_STDCALL progressCallback( double dfComplete,
const char *pszMessage,
void * pProgressArg );


//
// Forward declarations
//
@@ -1113,10 +1106,19 @@ public slots:
//! Which provider is being used for this Raster Layer?
QString providerKey();

/** A wrapper function to emit a progress update signal.
* For example used by gdal callback to show pyramid building progress.
*/
void showProgress(int theValue);

public slots:

void showStatusMessage(const QString & theMessage);

signals:
//for notifying listeners of long running processes
void progressUpdate(int theValue);


private:

0 comments on commit 3ac19d9

Please sign in to comment.