Skip to content

Commit e8ef91c

Browse files
committedApr 3, 2017
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
1 parent 144e5d0 commit e8ef91c

File tree

11 files changed

+32
-82
lines changed

11 files changed

+32
-82
lines changed
 

‎doc/api_break.dox

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,8 @@ QgsRasterDataProvider {#qgis_api_break_3_0_QgsRasterDataProvider}
16631663
- setUseSrcNoDataValue() has been renamed to setUseSourceNoDataValue()
16641664
- srcNoDataValue() has been renamed to sourceNoDataValue()
16651665
- draw() has been removed from the interface as it was not used anywhere.
1666-
1666+
- The progress and progressUpdate signals were removed. Methods which previously emitted these
1667+
signals now accept a QgsRasterBlockFeedback argument for reporting progress updates.
16671668

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

16891694
QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}
16901695
------------------

‎python/core/raster/qgsrasterdataprovider.sip

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
150150
virtual QString buildPyramids( const QList<QgsRasterPyramid> & pyramidList,
151151
const QString & resamplingMethod = "NEAREST",
152152
QgsRaster::RasterPyramidsFormat format = QgsRaster::PyramidsGTiff,
153-
const QStringList & configOptions = QStringList() );
153+
const QStringList & configOptions = QStringList(),
154+
QgsRasterBlockFeedback *feedback = 0 );
154155

155156
/** \brief Accessor for the raster layers pyramid list.
156157
* @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
317318
virtual int stepHeight() const;
318319

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

325322
/** Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
326323
* @note added in 2.14

‎python/core/raster/qgsrasterlayer.sip

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ class QgsRasterLayer : QgsMapLayer
158158
/** \brief Set default contrast enhancement */
159159
void setDefaultContrastEnhancement();
160160

161-
/** \brief [ data provider interface ] A wrapper function to emit a progress update signal */
162-
void showProgress( int value );
163-
164161
/** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
165162
virtual QStringList subLayers() const;
166163

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

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

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

198191
/**
199192
* This is emitted whenever data or metadata (e.g. color table, extent) has changed

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,9 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
10281028
{
10291029
QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
10301030

1031-
connect( provider, &QgsRasterDataProvider::progressUpdate, mPyramidProgress, &QProgressBar::setValue );
1031+
std::unique_ptr< QgsRasterBlockFeedback > feedback( new QgsRasterBlockFeedback() );
1032+
1033+
connect( feedback.get(), &QgsRasterBlockFeedback::progressChanged, mPyramidProgress, &QProgressBar::setValue );
10321034
//
10331035
// Go through the list marking any files that are selected in the listview
10341036
// as true so that we can generate pyramids for them.
@@ -1056,14 +1058,19 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
10561058
QString res = provider->buildPyramids(
10571059
myPyramidList,
10581060
resamplingMethod,
1059-
( QgsRaster::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex() );
1061+
( QgsRaster::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex(),
1062+
QStringList(),
1063+
feedback.get() );
10601064
QApplication::restoreOverrideCursor();
10611065
mPyramidProgress->setValue( 0 );
10621066
buttonBuildPyramids->setEnabled( false );
1063-
disconnect( provider, &QgsRasterDataProvider::progressUpdate, mPyramidProgress, &QProgressBar::setValue );
10641067
if ( !res.isNull() )
10651068
{
1066-
if ( res == QLatin1String( "ERROR_WRITE_ACCESS" ) )
1069+
if ( res == QLatin1String( "CANCELED" ) )
1070+
{
1071+
// user canceled
1072+
}
1073+
else if ( res == QLatin1String( "ERROR_WRITE_ACCESS" ) )
10671074
{
10681075
QMessageBox::warning( this, tr( "Write access denied" ),
10691076
tr( "Write access denied. Adjust the file permissions and try again." ) );

‎src/core/raster/qgsrasterdataprovider.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,14 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
262262
virtual QString buildPyramids( const QList<QgsRasterPyramid> &pyramidList,
263263
const QString &resamplingMethod = "NEAREST",
264264
QgsRaster::RasterPyramidsFormat format = QgsRaster::PyramidsGTiff,
265-
const QStringList &configOptions = QStringList() )
265+
const QStringList &configOptions = QStringList(),
266+
QgsRasterBlockFeedback *feedback = nullptr )
266267
{
267268
Q_UNUSED( pyramidList );
268269
Q_UNUSED( resamplingMethod );
269270
Q_UNUSED( format );
270271
Q_UNUSED( configOptions );
272+
Q_UNUSED( feedback );
271273
return QStringLiteral( "FAILED_NOT_SUPPORTED" );
272274
}
273275

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

460462
signals:
461463

462-
/** Emit a signal to notify of the progress event.
463-
* Emitted progress is in percents (0.0-100.0) */
464-
void progress( int type, double progress, const QString &message );
465-
void progressUpdate( int progress );
466-
467464
/** Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
468465
* \since QGIS 2.14
469466
*/

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,6 @@ void QgsRasterLayer::setDataProvider( QString const &provider )
798798
// TODO move to provider
799799
mLastModified = lastModified( mDataSource );
800800

801-
// Connect provider signals
802-
connect( mDataProvider, &QgsRasterDataProvider::progress, this, &QgsRasterLayer::onProgress );
803-
804801
// Do a passthrough for the status bar text
805802
connect( mDataProvider, &QgsRasterDataProvider::statusChanged, this, &QgsRasterLayer::statusChanged );
806803

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

1245-
void QgsRasterLayer::showProgress( int value )
1246-
{
1247-
emit progressUpdate( value );
1248-
}
1249-
1250-
12511242
void QgsRasterLayer::showStatusMessage( QString const &message )
12521243
{
12531244
// QgsDebugMsg(QString("entered with '%1'.").arg(theMessage));
@@ -1314,14 +1305,6 @@ QImage QgsRasterLayer::previewAsImage( QSize size, const QColor &bgColor, QImage
13141305
return myQImage;
13151306
}
13161307

1317-
void QgsRasterLayer::onProgress( int type, double progress, const QString &message )
1318-
{
1319-
Q_UNUSED( type );
1320-
Q_UNUSED( message );
1321-
QgsDebugMsgLevel( QString( "theProgress = %1" ).arg( progress ), 4 );
1322-
emit progressUpdate( static_cast< int >( progress ) );
1323-
}
1324-
13251308
//////////////////////////////////////////////////////////
13261309
//
13271310
// Protected methods

‎src/core/raster/qgsrasterlayer.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
323323
//! \brief Set default contrast enhancement
324324
void setDefaultContrastEnhancement();
325325

326-
//! \brief [ data provider interface ] A wrapper function to emit a progress update signal
327-
void showProgress( int value );
328-
329326
//! \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS
330327
virtual QStringList subLayers() const override;
331328

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

356-
//! \brief receive progress signal from provider
357-
void onProgress( int, double, const QString & );
358-
359-
signals:
360-
//! \brief Signal for notifying listeners of long running processes
361-
void progressUpdate( int value );
362-
363353
protected:
364354
//! \brief Read the symbology for the current layer from the Dom node supplied
365355
bool readSymbology( const QDomNode &node, QString &errorMessage ) override;

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ int CPL_STDCALL progressCallback( double dfComplete,
7171
const char *pszMessage,
7272
void *pProgressArg )
7373
{
74+
Q_UNUSED( pszMessage );
75+
7476
static double sDfLastComplete = -1.0;
7577

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

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

8788
if ( floor( sDfLastComplete * 10 ) != floor( dfComplete * 10 ) )
8889
{
89-
mypProvider->emitProgress( prog->type, dfComplete * 100, QString( pszMessage ) );
90-
mypProvider->emitProgressUpdate( dfComplete * 100 );
9190
if ( prog->feedback )
9291
prog->feedback->setProgress( dfComplete * 100 );
9392
}
@@ -1454,7 +1453,7 @@ QgsRasterHistogram QgsGdalProvider::histogram( int bandNo,
14541453
*/
14551454
QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyramidList,
14561455
const QString &resamplingMethod, QgsRaster::RasterPyramidsFormat format,
1457-
const QStringList &configOptions )
1456+
const QStringList &configOptions, QgsRasterBlockFeedback *feedback )
14581457
{
14591458
//TODO: Consider making rasterPyramidList modifyable by this method to indicate if the pyramid exists after build attempt
14601459
//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
14661465
// into the same file (if supported)
14671466
//
14681467

1469-
1470-
// TODO add signal and connect from rasterlayer
1471-
//emit drawingProgress( 0, 0 );
1472-
14731468
if ( mGdalDataset != mGdalBaseDataset )
14741469
{
14751470
QgsLogger::warning( QStringLiteral( "Pyramid building not currently supported for 'warped virtual dataset'." ) );
@@ -1606,12 +1601,13 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyr
16061601
QgsGdalProgress myProg;
16071602
myProg.type = QgsRaster::ProgressPyramids;
16081603
myProg.provider = this;
1604+
myProg.feedback = feedback;
16091605
myError = GDALBuildOverviews( mGdalBaseDataset, method,
16101606
myOverviewLevelsVector.size(), myOverviewLevelsVector.data(),
16111607
0, nullptr,
16121608
progressCallback, &myProg ); //this is the arg for the gdal progress callback
16131609

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

1624-
//emit drawingProgress( 0, 0 );
1625-
16261620
// restore former configOptions
16271621
for ( QgsStringMap::const_iterator it = myConfigOptionsOld.begin();
16281622
it != myConfigOptionsOld.end(); ++it )
@@ -1633,6 +1627,9 @@ QString QgsGdalProvider::buildPyramids( const QList<QgsRasterPyramid> &rasterPyr
16331627
}
16341628

16351629
// TODO print exact error message
1630+
if ( feedback && feedback->isCanceled() )
1631+
return QStringLiteral( "CANCELED" );
1632+
16361633
return QStringLiteral( "FAILED_NOT_SUPPORTED" );
16371634
}
16381635
else
@@ -1848,16 +1845,6 @@ QStringList QgsGdalProvider::subLayers() const
18481845
return mSubLayers;
18491846
}
18501847

1851-
void QgsGdalProvider::emitProgress( int type, double value, const QString &message )
1852-
{
1853-
emit progress( type, value, message );
1854-
}
1855-
1856-
void QgsGdalProvider::emitProgressUpdate( int progress )
1857-
{
1858-
emit progressUpdate( progress );
1859-
}
1860-
18611848
/**
18621849
* Class factory to return a pointer to a newly created
18631850
* QgsGdalProvider object

‎src/providers/gdal/qgsgdalprovider.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,13 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
136136
QString buildPyramids( const QList<QgsRasterPyramid> &rasterPyramidList,
137137
const QString &resamplingMethod = "NEAREST",
138138
QgsRaster::RasterPyramidsFormat format = QgsRaster::PyramidsGTiff,
139-
const QStringList &createOptions = QStringList() ) override;
139+
const QStringList &createOptions = QStringList(),
140+
QgsRasterBlockFeedback *feedback = nullptr ) override;
140141
QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) override;
141142

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

145-
//! Emit a signal to notify of the progress event.
146-
void emitProgress( int type, double value, const QString &message );
147-
void emitProgressUpdate( int progress );
148-
149146
static QMap<QString, QString> supportedMimes();
150147

151148
bool isEditable() const override;

‎src/providers/wcs/qgswcsprovider.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
194194

195195
signals:
196196

197-
//! \brief emit a signal to notify of a progress event
198-
void progressChanged( int progress, int totalSteps );
199-
200197
void dataChanged();
201198

202199
private:

‎src/providers/wms/qgswmsprovider.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ class QgsWmsProvider : public QgsRasterDataProvider
255255

256256
signals:
257257

258-
//! \brief emit a signal to notify of a progress event
259-
void progressChanged( int progress, int totalSteps );
260-
261258
void dataChanged();
262259

263260
private slots:

0 commit comments

Comments
 (0)
Please sign in to comment.