Skip to content

Commit

Permalink
progress signals
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15538 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 19, 2011
1 parent 50850e3 commit b76c962
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -107,6 +107,13 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
/*! Max current value */ ColorInterpretationMax = 16
};

// Progress types
enum Progress
{
ProgressHistogram = 0,
ProgressPyramids = 1
};

QgsRasterDataProvider();

QgsRasterDataProvider( QString const & uri );
Expand Down Expand Up @@ -460,6 +467,11 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
/** \brief Set null value in char */
QByteArray noValueBytes( int theBandNo );

signals:
/** Emit a signal to notify of the progress event.
* Emited theProgress is in percents (0.0-100.0) */
void progress( int theType, double theProgress, QString theMessage );

protected:
/**Dots per intch. Extended WMS (e.g. QGIS mapserver) support DPI dependent output and therefore
are suited for printing. A value of -1 means it has not been set
Expand Down
12 changes: 12 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -2483,6 +2483,12 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
mRasterTransparency.initializeTransparentPixelList( mNoDataValue );
}

// Connect provider signals
connect(
mDataProvider, SIGNAL( progress( int, double, QString ) ),
this, SLOT( onProgress( int, double, QString ) )
);

//mark the layer as valid
mValid = true;

Expand Down Expand Up @@ -2945,6 +2951,12 @@ void QgsRasterLayer::updateProgress( int theProgress, int theMax )
emit drawingProgress( theProgress, theMax );
}

void QgsRasterLayer::onProgress( int theType, double theProgress, QString theMesssage )
{
QgsDebugMsg( QString( "theProgress = %1" ).arg( theProgress ) );
emit progressUpdate(( int )theProgress );
}

//////////////////////////////////////////////////////////
//
// Protected methods
Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -674,6 +674,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Propagate progress updates from GDAL up to the parent app */
void updateProgress( int, int );

/** \brief recieve progress signal from provider */
void onProgress( int, double, QString );

signals:
/** \brief Signal for notifying listeners of long running processes */
void progressUpdate( int theValue );
Expand Down
40 changes: 30 additions & 10 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -55,16 +55,23 @@
static QString PROVIDER_KEY = "gdal";
static QString PROVIDER_DESCRIPTION = "GDAL provider";

struct QgsGdalProgress
{
int type;
QgsGdalProvider *provider;
};
//
// global callback function
//
int CPL_STDCALL progressCallback( double dfComplete,
const char * pszMessage,
void * pProgressArg )
{
// TODO: add signals to providers
static double dfLastComplete = -1.0;

QgsGdalProgress *prog = static_cast<QgsGdalProgress *>( pProgressArg );
QgsGdalProvider *mypProvider = prog->provider;

if ( dfLastComplete > dfComplete )
{
if ( dfLastComplete >= 1.0 )
Expand All @@ -84,16 +91,18 @@ int CPL_STDCALL progressCallback( double dfComplete,

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

mypProvider->emitProgress( prog->type, dfComplete * 100, QString( pszMessage ) );
}
dfLastComplete = dfComplete;

Expand Down Expand Up @@ -547,9 +556,9 @@ void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *bl
// TODO!!!: Check data alignment!!! May it happen that nearest value which
// is not nearest is assigned to an output cell???

QgsDebugMsg( "Entered" );
//QgsDebugMsg( "Entered" );

QgsDebugMsg( "yBlock = " + QString::number( yBlock ) );
//QgsDebugMsg( "yBlock = " + QString::number( yBlock ) );

GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
//GDALReadBlock( myGdalBand, xBlock, yBlock, block );
Expand Down Expand Up @@ -1312,11 +1321,15 @@ void QgsGdalProvider::populateHistogram( int theBandNo, QgsRasterBandStats & t
* void * pProgressData
* )
*/

QgsGdalProgress myProg;
myProg.type = ProgressHistogram;
myProg.provider = this;
double myerval = ( theBandStats.maximumValue - theBandStats.minimumValue ) / theBinCount;
GDALGetRasterHistogram( myGdalBand, theBandStats.minimumValue - 0.1*myerval,
theBandStats.maximumValue + 0.1*myerval, theBinCount, myHistogramArray,
theIgnoreOutOfRangeFlag, theHistogramEstimatedFlag, progressCallback,
this ); //this is the arg for our custome gdal progress callback
&myProg ); //this is the arg for our custome gdal progress callback

for ( int myBin = 0; myBin < theBinCount; myBin++ )
{
Expand Down Expand Up @@ -1443,21 +1456,24 @@ QString QgsGdalProvider::buildPyramids( QList<QgsRasterPyramid> const & theRaste
//to create corrupted images. The images can be repaired
//by running one of the other resampling strategies below.
//see ticket #284
QgsGdalProgress myProg;
myProg.type = ProgressPyramids;
myProg.provider = this;
if ( theResamplingMethod == tr( "Average Magphase" ) )
{
myError = GDALBuildOverviews( mGdalBaseDataset, "MODE", 1, myOverviewLevelsArray, 0, NULL,
progressCallback, this ); //this is the arg for the gdal progress callback
progressCallback, &myProg ); //this is the arg for the gdal progress callback
}
else if ( theResamplingMethod == tr( "Average" ) )

{
myError = GDALBuildOverviews( mGdalBaseDataset, "AVERAGE", 1, myOverviewLevelsArray, 0, NULL,
progressCallback, this ); //this is the arg for the gdal progress callback
progressCallback, &myProg ); //this is the arg for the gdal progress callback
}
else // fall back to nearest neighbor
{
myError = GDALBuildOverviews( mGdalBaseDataset, "NEAREST", 1, myOverviewLevelsArray, 0, NULL,
progressCallback, this ); //this is the arg for the gdal progress callback
progressCallback, &myProg ); //this is the arg for the gdal progress callback
}

if ( myError == CE_Failure || CPLGetLastErrorNo() == CPLE_NotSupported )
Expand Down Expand Up @@ -1587,6 +1603,10 @@ QStringList QgsGdalProvider::subLayers() const
return subLayers_( mGdalDataset );
}

void QgsGdalProvider::emitProgress( int theType, double theProgress, QString theMessage )
{
emit progress( theType, theProgress, theMessage );
}

/**
* Class factory to return a pointer to a newly created
Expand Down
2 changes: 2 additions & 0 deletions src/providers/gdal/qgsgdalprovider.h
Expand Up @@ -247,6 +247,8 @@ class QgsGdalProvider : public QgsRasterDataProvider
/** \brief Close data set and release related data */
void closeDataset();

/** Emit a signal to notify of the progress event. */
void emitProgress( int theType, double theProgress, QString theMessage );

private:
// initialize CRS from wkt
Expand Down

0 comments on commit b76c962

Please sign in to comment.