Skip to content
Permalink
Browse files
Cleanup QgsRasterDataProvider/QgsRasterLayer progress reporting
Instead of progress changed signals on the provider/layer level,
instead use QgsFeedback arguments for methods which previously
emitted progress changed signals
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent 144e5d0 commit e8ef91ce98e4bbb77cc3c1c10b262d18b84021e3
@@ -1663,7 +1663,8 @@ QgsRasterDataProvider {#qgis_api_break_3_0_QgsRasterDataProvider}
- setUseSrcNoDataValue() has been renamed to setUseSourceNoDataValue()
- srcNoDataValue() has been renamed to sourceNoDataValue()
- draw() has been removed from the interface as it was not used anywhere.

- The progress and progressUpdate signals were removed. Methods which previously emitted these
signals now accept a QgsRasterBlockFeedback argument for reporting progress updates.

QgsRasterInterface {#qgis_api_break_3_0_QgsRasterInterface}
------------------
@@ -1685,6 +1686,10 @@ constructor variant which accepts a data provider string and loadDefaultStyleFla
- updateProgress() had no effect and was removed.
- CUMULATIVE_CUT_LOWER and CUMULATIVE_CUT_UPPER have been moved to QgsRasterMinMaxOrigin
- the second parameter of setContrastEnhancement() has changed type. It is now QgsRasterMinMaxOrigin::Limits
- showProgress() and onProgress() were removed
- The progressUpdate() signal was removed. Methods which previously emitted these
signals now accept a QgsRasterBlockFeedback argument for reporting progress updates.


QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}
------------------
@@ -150,7 +150,8 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
virtual QString buildPyramids( const QList<QgsRasterPyramid> & pyramidList,
const QString & resamplingMethod = "NEAREST",
QgsRaster::RasterPyramidsFormat format = QgsRaster::PyramidsGTiff,
const QStringList & configOptions = QStringList() );
const QStringList & configOptions = QStringList(),
QgsRasterBlockFeedback *feedback = 0 );

/** \brief Accessor for the raster layers pyramid list.
* @param overviewList used to construct the pyramid list (optional), when empty the list is defined by the provider.
@@ -317,10 +318,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
virtual int stepHeight() const;

signals:
/** Emit a signal to notify of the progress event.
* Emitted progress is in percents (0.0-100.0) */
void progress( int type, double progress, const QString& message );
void progressUpdate( int progress );

/** Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
* @note added in 2.14
@@ -158,9 +158,6 @@ class QgsRasterLayer : QgsMapLayer
/** \brief Set default contrast enhancement */
void setDefaultContrastEnhancement();

/** \brief [ data provider interface ] A wrapper function to emit a progress update signal */
void showProgress( int value );

/** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
virtual QStringList subLayers() const;

@@ -188,12 +185,8 @@ class QgsRasterLayer : QgsMapLayer
public slots:
void showStatusMessage( const QString & message );

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

signals:
/** \brief Signal for notifying listeners of long running processes */
void progressUpdate( int value );

/**
* This is emitted whenever data or metadata (e.g. color table, extent) has changed
@@ -1028,7 +1028,9 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
{
QgsRasterDataProvider *provider = mRasterLayer->dataProvider();

connect( provider, &QgsRasterDataProvider::progressUpdate, mPyramidProgress, &QProgressBar::setValue );
std::unique_ptr< QgsRasterBlockFeedback > feedback( new QgsRasterBlockFeedback() );

connect( feedback.get(), &QgsRasterBlockFeedback::progressChanged, mPyramidProgress, &QProgressBar::setValue );
//
// Go through the list marking any files that are selected in the listview
// as true so that we can generate pyramids for them.
@@ -1056,14 +1058,19 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
QString res = provider->buildPyramids(
myPyramidList,
resamplingMethod,
( QgsRaster::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex() );
( QgsRaster::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex(),
QStringList(),
feedback.get() );
QApplication::restoreOverrideCursor();
mPyramidProgress->setValue( 0 );
buttonBuildPyramids->setEnabled( false );
disconnect( provider, &QgsRasterDataProvider::progressUpdate, mPyramidProgress, &QProgressBar::setValue );
if ( !res.isNull() )
{
if ( res == QLatin1String( "ERROR_WRITE_ACCESS" ) )
if ( res == QLatin1String( "CANCELED" ) )
{
// user canceled
}
else if ( res == QLatin1String( "ERROR_WRITE_ACCESS" ) )
{
QMessageBox::warning( this, tr( "Write access denied" ),
tr( "Write access denied. Adjust the file permissions and try again." ) );
@@ -262,12 +262,14 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
virtual QString buildPyramids( const QList<QgsRasterPyramid> &pyramidList,
const QString &resamplingMethod = "NEAREST",
QgsRaster::RasterPyramidsFormat format = QgsRaster::PyramidsGTiff,
const QStringList &configOptions = QStringList() )
const QStringList &configOptions = QStringList(),
QgsRasterBlockFeedback *feedback = nullptr )
{
Q_UNUSED( pyramidList );
Q_UNUSED( resamplingMethod );
Q_UNUSED( format );
Q_UNUSED( configOptions );
Q_UNUSED( feedback );
return QStringLiteral( "FAILED_NOT_SUPPORTED" );
}

@@ -459,11 +461,6 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast

signals:

/** Emit a signal to notify of the progress event.
* Emitted progress is in percents (0.0-100.0) */
void progress( int type, double progress, const QString &message );
void progressUpdate( int progress );

/** Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
* \since QGIS 2.14
*/
@@ -798,9 +798,6 @@ void QgsRasterLayer::setDataProvider( QString const &provider )
// TODO move to provider
mLastModified = lastModified( mDataSource );

// Connect provider signals
connect( mDataProvider, &QgsRasterDataProvider::progress, this, &QgsRasterLayer::onProgress );

// Do a passthrough for the status bar text
connect( mDataProvider, &QgsRasterDataProvider::statusChanged, this, &QgsRasterLayer::statusChanged );

@@ -1242,12 +1239,6 @@ void QgsRasterLayer::setRenderer( QgsRasterRenderer *renderer )
emit styleChanged();
}

void QgsRasterLayer::showProgress( int value )
{
emit progressUpdate( value );
}


void QgsRasterLayer::showStatusMessage( QString const &message )
{
// QgsDebugMsg(QString("entered with '%1'.").arg(theMessage));
@@ -1314,14 +1305,6 @@ QImage QgsRasterLayer::previewAsImage( QSize size, const QColor &bgColor, QImage
return myQImage;
}

void QgsRasterLayer::onProgress( int type, double progress, const QString &message )
{
Q_UNUSED( type );
Q_UNUSED( message );
QgsDebugMsgLevel( QString( "theProgress = %1" ).arg( progress ), 4 );
emit progressUpdate( static_cast< int >( progress ) );
}

//////////////////////////////////////////////////////////
//
// Protected methods
@@ -323,9 +323,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
//! \brief Set default contrast enhancement
void setDefaultContrastEnhancement();

//! \brief [ data provider interface ] A wrapper function to emit a progress update signal
void showProgress( int value );

//! \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS
virtual QStringList subLayers() const override;

@@ -353,13 +350,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
public slots:
void showStatusMessage( const QString &message );

//! \brief receive progress signal from provider
void onProgress( int, double, const QString & );

signals:
//! \brief Signal for notifying listeners of long running processes
void progressUpdate( int value );

protected:
//! \brief Read the symbology for the current layer from the Dom node supplied
bool readSymbology( const QDomNode &node, QString &errorMessage ) override;
@@ -71,10 +71,11 @@ int CPL_STDCALL progressCallback( double dfComplete,
const char *pszMessage,
void *pProgressArg )
{
Q_UNUSED( pszMessage );

static double sDfLastComplete = -1.0;

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

if ( sDfLastComplete > dfComplete )
{
@@ -86,8 +87,6 @@ int CPL_STDCALL progressCallback( double dfComplete,

if ( floor( sDfLastComplete * 10 ) != floor( dfComplete * 10 ) )
{
mypProvider->emitProgress( prog->type, dfComplete * 100, QString( pszMessage ) );
mypProvider->emitProgressUpdate( dfComplete * 100 );
if ( prog->feedback )
prog->feedback->setProgress( dfComplete * 100 );
}
@@ -1454,7 +1453,7 @@ QgsRasterHistogram QgsGdalProvider::histogram( int bandNo,
*/
QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyramidList,
const QString &resamplingMethod, QgsRaster::RasterPyramidsFormat format,
const QStringList &configOptions )
const QStringList &configOptions, QgsRasterBlockFeedback *feedback )
{
//TODO: Consider making rasterPyramidList modifyable by this method to indicate if the pyramid exists after build attempt
//without requiring the user to rebuild the pyramid list to get the updated information
@@ -1466,10 +1465,6 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyr
// into the same file (if supported)
//


// TODO add signal and connect from rasterlayer
//emit drawingProgress( 0, 0 );

if ( mGdalDataset != mGdalBaseDataset )
{
QgsLogger::warning( QStringLiteral( "Pyramid building not currently supported for 'warped virtual dataset'." ) );
@@ -1606,12 +1601,13 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyr
QgsGdalProgress myProg;
myProg.type = QgsRaster::ProgressPyramids;
myProg.provider = this;
myProg.feedback = feedback;
myError = GDALBuildOverviews( mGdalBaseDataset, method,
myOverviewLevelsVector.size(), myOverviewLevelsVector.data(),
0, nullptr,
progressCallback, &myProg ); //this is the arg for the gdal progress callback

if ( myError == CE_Failure || CPLGetLastErrorNo() == CPLE_NotSupported )
if ( ( feedback && feedback->isCanceled() ) || myError == CE_Failure || CPLGetLastErrorNo() == CPLE_NotSupported )
{
QgsDebugMsg( QString( "Building pyramids failed using resampling method [%1]" ).arg( method ) );
//something bad happenend
@@ -1621,8 +1617,6 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyr
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
mGdalDataset = mGdalBaseDataset;

//emit drawingProgress( 0, 0 );

// restore former configOptions
for ( QgsStringMap::const_iterator it = myConfigOptionsOld.begin();
it != myConfigOptionsOld.end(); ++it )
@@ -1633,6 +1627,9 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyr
}

// TODO print exact error message
if ( feedback && feedback->isCanceled() )
return QStringLiteral( "CANCELED" );

return QStringLiteral( "FAILED_NOT_SUPPORTED" );
}
else
@@ -1848,16 +1845,6 @@ QStringList QgsGdalProvider::subLayers() const
return mSubLayers;
}

void QgsGdalProvider::emitProgress( int type, double value, const QString &message )
{
emit progress( type, value, message );
}

void QgsGdalProvider::emitProgressUpdate( int progress )
{
emit progressUpdate( progress );
}

/**
* Class factory to return a pointer to a newly created
* QgsGdalProvider object
@@ -136,16 +136,13 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
QString buildPyramids( const QList<QgsRasterPyramid> &rasterPyramidList,
const QString &resamplingMethod = "NEAREST",
QgsRaster::RasterPyramidsFormat format = QgsRaster::PyramidsGTiff,
const QStringList &createOptions = QStringList() ) override;
const QStringList &createOptions = QStringList(),
QgsRasterBlockFeedback *feedback = nullptr ) override;
QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) override;

//! \brief Close data set and release related data
void closeDataset();

//! Emit a signal to notify of the progress event.
void emitProgress( int type, double value, const QString &message );
void emitProgressUpdate( int progress );

static QMap<QString, QString> supportedMimes();

bool isEditable() const override;
@@ -194,9 +194,6 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase

signals:

//! \brief emit a signal to notify of a progress event
void progressChanged( int progress, int totalSteps );

void dataChanged();

private:
@@ -255,9 +255,6 @@ class QgsWmsProvider : public QgsRasterDataProvider

signals:

//! \brief emit a signal to notify of a progress event
void progressChanged( int progress, int totalSteps );

void dataChanged();

private slots:

0 comments on commit e8ef91c

Please sign in to comment.