Use a QgsFeedback instead of QProgressBar for QgsNineCellFilter

Gives progress reports and allows cancelation of processing
aspect algorithm
This commit is contained in:
Nyall Dawson 2017-06-28 18:36:23 +10:00
parent d2b9652d4b
commit 144d733b12
5 changed files with 21 additions and 24 deletions

View File

@ -1663,6 +1663,12 @@ QgsNewVectorLayerDialog {#qgis_api_break_3_0_QgsNewVectorLayerDialog}
- selectedCrsId() was removed. Use crs() instead.
QgsNineCellFilter {#qgis_api_break_3_0_QgsNineCellFilter}
-----------------
- The QProgressBar argument for processRaster was changed to a QgsFeedback object.
QgsOSMElement {#qgis_api_break_3_0_QgsOSMElement}
-------------

View File

@ -29,10 +29,10 @@ Constructor that takes input file, output file and output format (GDAL string)
%End
virtual ~QgsNineCellFilter();
int processRaster( QProgressDialog *p );
int processRaster( QgsFeedback *feedback = 0 );
%Docstring
Starts the calculation, reads from mInputFile and stores the result in mOutputFile
\param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
\param feedback feedback object that receives update and that is checked for cancelation.
:return: 0 in case of success*
:rtype: int
%End

View File

@ -84,6 +84,6 @@ class Aspect(QgisAlgorithm):
aspect = QgsAspectFilter(inputFile, outputFile, outputFormat)
aspect.setZFactor(zFactor)
aspect.processRaster(None)
aspect.processRaster(feedback)
return {self.OUTPUT_LAYER: outputFile}

View File

@ -18,6 +18,7 @@
#include "qgsninecellfilter.h"
#include "qgslogger.h"
#include "cpl_string.h"
#include "qgsfeedback.h"
#include <QProgressDialog>
#include <QFile>
@ -43,7 +44,7 @@ QgsNineCellFilter::QgsNineCellFilter()
{
}
int QgsNineCellFilter::processRaster( QProgressDialog *p )
int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
{
GDALAllRegister();
@ -103,24 +104,19 @@ int QgsNineCellFilter::processRaster( QProgressDialog *p )
float *resultLine = ( float * ) CPLMalloc( sizeof( float ) * xSize );
if ( p )
{
p->setMaximum( ySize );
}
//values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
for ( int i = 0; i < ySize; ++i )
{
if ( p )
{
p->setValue( i );
}
if ( p && p->wasCanceled() )
if ( feedback && feedback->isCanceled() )
{
break;
}
if ( feedback )
{
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
}
if ( i == 0 )
{
//fill scanline 1 with (input) nodata for the values above the first row and feed scanline2 with the first row
@ -182,11 +178,6 @@ int QgsNineCellFilter::processRaster( QProgressDialog *p )
}
}
if ( p )
{
p->setValue( ySize );
}
CPLFree( resultLine );
CPLFree( scanLine1 );
CPLFree( scanLine2 );
@ -194,7 +185,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog *p )
GDALClose( inputDataset );
if ( p && p->wasCanceled() )
if ( feedback && feedback->isCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );

View File

@ -22,7 +22,7 @@
#include "gdal.h"
#include "qgis_analysis.h"
class QProgressDialog;
class QgsFeedback;
/** \ingroup analysis
* 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
virtual ~QgsNineCellFilter() = default;
/** Starts the calculation, reads from mInputFile and stores the result in mOutputFile
\param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
\param feedback feedback object that receives update and that is checked for cancelation.
\returns 0 in case of success*/
int processRaster( QProgressDialog *p );
int processRaster( QgsFeedback *feedback = nullptr );
double cellSizeX() const { return mCellSizeX; }
void setCellSizeX( double size ) { mCellSizeX = size; }