Skip to content

Commit

Permalink
Use a QgsFeedback object in QgsRelief instead of QProgressDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 18, 2017
1 parent f6600f2 commit be48f17
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
5 changes: 5 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1973,6 +1973,11 @@ QgsRelation {#qgis_api_break_3_0_QgsRelation}
- `setRelationName()` has been renamed to `QgsRelation::setName()`
- `setRelationId()` has been renamed to `QgsRelation::setId()`

QgsRelief {#qgis_api_break_3_0_QgsRelief}
---------

- processRaster() now uses a QgsFeedback object instead of a QProgressDialog


QgsRenderChecker {#qgis_api_break_3_0_QgsRenderChecker}
----------------
Expand Down
4 changes: 2 additions & 2 deletions python/analysis/raster/qgsrelief.sip
Expand Up @@ -32,10 +32,10 @@ class QgsRelief
~QgsRelief();


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
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/Relief.py
Expand Up @@ -154,7 +154,8 @@ def processAlgorithm(self, parameters, context, feedback):

relief.setReliefColors(reliefColors)
relief.setZFactor(zFactor)
relief.exportFrequencyDistributionToCsv(frequencyDistribution)
relief.processRaster(None)
if frequencyDistribution:
relief.exportFrequencyDistributionToCsv(frequencyDistribution)
relief.processRaster(feedback)

return {self.OUTPUT: outputFile, self.FREQUENCY_DISTRIBUTION: frequencyDistribution}
23 changes: 10 additions & 13 deletions src/analysis/raster/qgsrelief.cpp
Expand Up @@ -20,11 +20,13 @@
#include "qgsaspectfilter.h"
#include "qgshillshadefilter.h"
#include "qgsslopefilter.h"
#include "qgsfeedback.h"
#include "qgis.h"
#include "cpl_string.h"
#include <QProgressDialog>
#include <cfloat>

#include <QVector>
#include <QColor>
#include <QFile>
#include <QTextStream>

Expand Down Expand Up @@ -78,7 +80,7 @@ void QgsRelief::setDefaultReliefColors()
addReliefColorClass( ReliefColor( QColor( 255, 255, 255 ), 4000, 9000 ) );
}

int QgsRelief::processRaster( QProgressDialog *p )
int QgsRelief::processRaster( QgsFeedback *feedback )
{
//open input file
int xSize, ySize;
Expand Down Expand Up @@ -170,22 +172,17 @@ int QgsRelief::processRaster( QProgressDialog *p )
unsigned char *resultGreenLine = ( unsigned char * ) CPLMalloc( sizeof( unsigned char ) * xSize );
unsigned char *resultBlueLine = ( unsigned char * ) CPLMalloc( sizeof( unsigned char ) * xSize );

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

bool resultOk;

//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 )
{
p->setValue( i );
feedback->setProgress( 100.0 * i / static_cast< double >( ySize ) );
}

if ( p && p->wasCanceled() )
if ( feedback && feedback->isCanceled() )
{
break;
}
Expand Down Expand Up @@ -269,9 +266,9 @@ int QgsRelief::processRaster( QProgressDialog *p )
}
}

if ( p )
if ( feedback )
{
p->setValue( ySize );
feedback->setProgress( 100 );
}

CPLFree( resultRedLine );
Expand All @@ -283,7 +280,7 @@ int QgsRelief::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() );
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/raster/qgsrelief.h
Expand Up @@ -28,7 +28,7 @@
class QgsAspectFilter;
class QgsSlopeFilter;
class QgsHillshadeFilter;
class QProgressDialog;
class QgsFeedback;

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

/** 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 zFactor() const { return mZFactor; }
void setZFactor( double factor ) { mZFactor = factor; }
Expand Down

0 comments on commit be48f17

Please sign in to comment.