Skip to content
Permalink
Browse files

Use a QgsFeedback instead of QProgressBar for QgsNineCellFilter

Gives progress reports and allows cancelation of processing
aspect algorithm
  • Loading branch information
nyalldawson committed Jun 28, 2017
1 parent d2b9652 commit 144d733b126f24286a59b8cc420e4ed9b460065c
@@ -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}
-------------

@@ -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
@@ -84,6 +84,6 @@ def processAlgorithm(self, parameters, context, feedback):

aspect = QgsAspectFilter(inputFile, outputFile, outputFormat)
aspect.setZFactor(zFactor)
aspect.processRaster(None)
aspect.processRaster(feedback)

return {self.OUTPUT_LAYER: outputFile}
@@ -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,22 +104,17 @@ 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 )
if ( feedback && feedback->isCanceled() )
{
p->setValue( i );
break;
}

if ( p && p->wasCanceled() )
if ( feedback )
{
break;
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
}

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

if ( p )
{
p->setValue( ySize );
}

CPLFree( resultLine );
CPLFree( scanLine1 );
CPLFree( scanLine2 );
CPLFree( scanLine3 );

GDALClose( inputDataset );

if ( p && p->wasCanceled() )
if ( feedback && feedback->isCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
@@ -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; }

0 comments on commit 144d733

Please sign in to comment.
You can’t perform that action at this time.