Skip to content

Commit

Permalink
Use a QgsFeedback instead of QProgressBar for QgsNineCellFilter
Browse files Browse the repository at this point in the history
Gives progress reports and allows cancelation of processing
aspect algorithm
  • Loading branch information
nyalldawson committed Jun 28, 2017
1 parent d2b9652 commit 144d733
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
6 changes: 6 additions & 0 deletions doc/api_break.dox
Expand Up @@ -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}
-------------

Expand Down
4 changes: 2 additions & 2 deletions python/analysis/raster/qgsninecellfilter.sip
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/Aspect.py
Expand Up @@ -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}
23 changes: 7 additions & 16 deletions src/analysis/raster/qgsninecellfilter.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsninecellfilter.h"
#include "qgslogger.h"
#include "cpl_string.h"
#include "qgsfeedback.h"
#include <QProgressDialog>
#include <QFile>

Expand All @@ -43,7 +44,7 @@ QgsNineCellFilter::QgsNineCellFilter()
{
}

int QgsNineCellFilter::processRaster( QProgressDialog *p )
int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
{
GDALAllRegister();

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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() );
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/raster/qgsninecellfilter.h
Expand Up @@ -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
Expand All @@ -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; }
Expand Down

0 comments on commit 144d733

Please sign in to comment.