Skip to content
Permalink
Browse files

progress signals

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15538 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 19, 2011
1 parent 30be1e5 commit 5827908145fefd3d04ce43b522fe70860ed6c314
@@ -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 );
@@ -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
@@ -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;

@@ -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
@@ -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 );
@@ -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 )
@@ -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;

@@ -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 );
@@ -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++ )
{
@@ -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 )
@@ -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
@@ -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

0 comments on commit 5827908

Please sign in to comment.
You can’t perform that action at this time.