Skip to content
Permalink
Browse files

Use a QgsFeedback object in QgsRelief instead of QProgressDialog

  • Loading branch information
nyalldawson committed Aug 18, 2017
1 parent f6600f2 commit be48f17e2c77e8138b1b0b1f0ee80fb27f907f5b
@@ -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}
----------------
@@ -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
@@ -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}
@@ -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>

@@ -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;
@@ -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;
}
@@ -269,9 +266,9 @@ int QgsRelief::processRaster( QProgressDialog *p )
}
}

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

CPLFree( resultRedLine );
@@ -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() );
@@ -28,7 +28,7 @@
class QgsAspectFilter;
class QgsSlopeFilter;
class QgsHillshadeFilter;
class QProgressDialog;
class QgsFeedback;

/** \ingroup analysis
* Produces colored relief rasters from DEM*/
@@ -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; }

0 comments on commit be48f17

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