Skip to content

Commit be48f17

Browse files
committed
Use a QgsFeedback object in QgsRelief instead of QProgressDialog
1 parent f6600f2 commit be48f17

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

doc/api_break.dox

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,11 @@ QgsRelation {#qgis_api_break_3_0_QgsRelation}
19731973
- `setRelationName()` has been renamed to `QgsRelation::setName()`
19741974
- `setRelationId()` has been renamed to `QgsRelation::setId()`
19751975

1976+
QgsRelief {#qgis_api_break_3_0_QgsRelief}
1977+
---------
1978+
1979+
- processRaster() now uses a QgsFeedback object instead of a QProgressDialog
1980+
19761981

19771982
QgsRenderChecker {#qgis_api_break_3_0_QgsRenderChecker}
19781983
----------------

python/analysis/raster/qgsrelief.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class QgsRelief
3232
~QgsRelief();
3333

3434

35-
int processRaster( QProgressDialog *p );
35+
int processRaster( QgsFeedback *feedback = 0 );
3636
%Docstring
3737
Starts the calculation, reads from mInputFile and stores the result in mOutputFile
38-
\param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
38+
\param feedback feedback object that receives update and that is checked for cancelation.
3939
:return: 0 in case of success*
4040
:rtype: int
4141
%End

python/plugins/processing/algs/qgis/Relief.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def processAlgorithm(self, parameters, context, feedback):
154154

155155
relief.setReliefColors(reliefColors)
156156
relief.setZFactor(zFactor)
157-
relief.exportFrequencyDistributionToCsv(frequencyDistribution)
158-
relief.processRaster(None)
157+
if frequencyDistribution:
158+
relief.exportFrequencyDistributionToCsv(frequencyDistribution)
159+
relief.processRaster(feedback)
159160

160161
return {self.OUTPUT: outputFile, self.FREQUENCY_DISTRIBUTION: frequencyDistribution}

src/analysis/raster/qgsrelief.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
#include "qgsaspectfilter.h"
2121
#include "qgshillshadefilter.h"
2222
#include "qgsslopefilter.h"
23+
#include "qgsfeedback.h"
2324
#include "qgis.h"
2425
#include "cpl_string.h"
25-
#include <QProgressDialog>
2626
#include <cfloat>
2727

28+
#include <QVector>
29+
#include <QColor>
2830
#include <QFile>
2931
#include <QTextStream>
3032

@@ -78,7 +80,7 @@ void QgsRelief::setDefaultReliefColors()
7880
addReliefColorClass( ReliefColor( QColor( 255, 255, 255 ), 4000, 9000 ) );
7981
}
8082

81-
int QgsRelief::processRaster( QProgressDialog *p )
83+
int QgsRelief::processRaster( QgsFeedback *feedback )
8284
{
8385
//open input file
8486
int xSize, ySize;
@@ -170,22 +172,17 @@ int QgsRelief::processRaster( QProgressDialog *p )
170172
unsigned char *resultGreenLine = ( unsigned char * ) CPLMalloc( sizeof( unsigned char ) * xSize );
171173
unsigned char *resultBlueLine = ( unsigned char * ) CPLMalloc( sizeof( unsigned char ) * xSize );
172174

173-
if ( p )
174-
{
175-
p->setMaximum( ySize );
176-
}
177-
178175
bool resultOk;
179176

180177
//values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
181178
for ( int i = 0; i < ySize; ++i )
182179
{
183-
if ( p )
180+
if ( feedback )
184181
{
185-
p->setValue( i );
182+
feedback->setProgress( 100.0 * i / static_cast< double >( ySize ) );
186183
}
187184

188-
if ( p && p->wasCanceled() )
185+
if ( feedback && feedback->isCanceled() )
189186
{
190187
break;
191188
}
@@ -269,9 +266,9 @@ int QgsRelief::processRaster( QProgressDialog *p )
269266
}
270267
}
271268

272-
if ( p )
269+
if ( feedback )
273270
{
274-
p->setValue( ySize );
271+
feedback->setProgress( 100 );
275272
}
276273

277274
CPLFree( resultRedLine );
@@ -283,7 +280,7 @@ int QgsRelief::processRaster( QProgressDialog *p )
283280

284281
GDALClose( inputDataset );
285282

286-
if ( p && p->wasCanceled() )
283+
if ( feedback && feedback->isCanceled() )
287284
{
288285
//delete the dataset without closing (because it is faster)
289286
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );

src/analysis/raster/qgsrelief.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class QgsAspectFilter;
2929
class QgsSlopeFilter;
3030
class QgsHillshadeFilter;
31-
class QProgressDialog;
31+
class QgsFeedback;
3232

3333
/** \ingroup analysis
3434
* Produces colored relief rasters from DEM*/
@@ -52,9 +52,9 @@ class ANALYSIS_EXPORT QgsRelief
5252
QgsRelief &operator=( const QgsRelief &rh ) = delete;
5353

5454
/** Starts the calculation, reads from mInputFile and stores the result in mOutputFile
55-
\param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
55+
\param feedback feedback object that receives update and that is checked for cancelation.
5656
\returns 0 in case of success*/
57-
int processRaster( QProgressDialog *p );
57+
int processRaster( QgsFeedback *feedback = nullptr );
5858

5959
double zFactor() const { return mZFactor; }
6060
void setZFactor( double factor ) { mZFactor = factor; }

0 commit comments

Comments
 (0)