Skip to content

Commit 144d733

Browse files
committed
Use a QgsFeedback instead of QProgressBar for QgsNineCellFilter
Gives progress reports and allows cancelation of processing aspect algorithm
1 parent d2b9652 commit 144d733

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

doc/api_break.dox

+6
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,12 @@ QgsNewVectorLayerDialog {#qgis_api_break_3_0_QgsNewVectorLayerDialog}
16631663
- selectedCrsId() was removed. Use crs() instead.
16641664

16651665

1666+
QgsNineCellFilter {#qgis_api_break_3_0_QgsNineCellFilter}
1667+
-----------------
1668+
1669+
- The QProgressBar argument for processRaster was changed to a QgsFeedback object.
1670+
1671+
16661672
QgsOSMElement {#qgis_api_break_3_0_QgsOSMElement}
16671673
-------------
16681674

python/analysis/raster/qgsninecellfilter.sip

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ Constructor that takes input file, output file and output format (GDAL string)
2929
%End
3030
virtual ~QgsNineCellFilter();
3131

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ def processAlgorithm(self, parameters, context, feedback):
8484

8585
aspect = QgsAspectFilter(inputFile, outputFile, outputFormat)
8686
aspect.setZFactor(zFactor)
87-
aspect.processRaster(None)
87+
aspect.processRaster(feedback)
8888

8989
return {self.OUTPUT_LAYER: outputFile}

src/analysis/raster/qgsninecellfilter.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsninecellfilter.h"
1919
#include "qgslogger.h"
2020
#include "cpl_string.h"
21+
#include "qgsfeedback.h"
2122
#include <QProgressDialog>
2223
#include <QFile>
2324

@@ -43,7 +44,7 @@ QgsNineCellFilter::QgsNineCellFilter()
4344
{
4445
}
4546

46-
int QgsNineCellFilter::processRaster( QProgressDialog *p )
47+
int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
4748
{
4849
GDALAllRegister();
4950

@@ -103,22 +104,17 @@ int QgsNineCellFilter::processRaster( QProgressDialog *p )
103104

104105
float *resultLine = ( float * ) CPLMalloc( sizeof( float ) * xSize );
105106

106-
if ( p )
107-
{
108-
p->setMaximum( ySize );
109-
}
110-
111107
//values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
112108
for ( int i = 0; i < ySize; ++i )
113109
{
114-
if ( p )
110+
if ( feedback && feedback->isCanceled() )
115111
{
116-
p->setValue( i );
112+
break;
117113
}
118114

119-
if ( p && p->wasCanceled() )
115+
if ( feedback )
120116
{
121-
break;
117+
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
122118
}
123119

124120
if ( i == 0 )
@@ -182,19 +178,14 @@ int QgsNineCellFilter::processRaster( QProgressDialog *p )
182178
}
183179
}
184180

185-
if ( p )
186-
{
187-
p->setValue( ySize );
188-
}
189-
190181
CPLFree( resultLine );
191182
CPLFree( scanLine1 );
192183
CPLFree( scanLine2 );
193184
CPLFree( scanLine3 );
194185

195186
GDALClose( inputDataset );
196187

197-
if ( p && p->wasCanceled() )
188+
if ( feedback && feedback->isCanceled() )
198189
{
199190
//delete the dataset without closing (because it is faster)
200191
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );

src/analysis/raster/qgsninecellfilter.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "gdal.h"
2323
#include "qgis_analysis.h"
2424

25-
class QProgressDialog;
25+
class QgsFeedback;
2626

2727
/** \ingroup analysis
2828
* Base class for raster analysis methods that work with a 3x3 cell filter and calculate the value of each cell based on
@@ -37,9 +37,9 @@ class ANALYSIS_EXPORT QgsNineCellFilter
3737
virtual ~QgsNineCellFilter() = default;
3838

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

4444
double cellSizeX() const { return mCellSizeX; }
4545
void setCellSizeX( double size ) { mCellSizeX = size; }

0 commit comments

Comments
 (0)