Skip to content
Permalink
Browse files

Swap final uses of QProgressDialog in analysis lib to QgsFeedback

  • Loading branch information
nyalldawson committed Aug 26, 2017
1 parent 7cd5880 commit eb7ad7aebed252d8c6123d321035b9b90b46f08d
@@ -1908,7 +1908,8 @@ QgsRasterCalculator {#qgis_api_break_3_0_QgsRasterCalculator}
-------------------

- Cancelled (Result enum value) has been renamed to Canceled <!--#spellok-->

- processCalculation() now uses an optional QgsFeedback instead of QProgressDialog
for progress reports and cancelation.

QgsRasterDataProvider {#qgis_api_break_3_0_QgsRasterDataProvider}
---------------------
@@ -2350,6 +2351,12 @@ QgsTracer {#qgis_api_break_3_0_QgsTracer}

- hasCrsTransformEnabled() and setCrsTransformEnabled() were removed. CRS transformation is now always enabled when required.

QgsTransectSample {#qgis_api_break_3_0_QgsTransectSample}
-----------------

- createSample() now uses an optional QgsFeedback instead of QProgressDialog
for progress reports and cancelation.


QgsTreeWidgetItem {#qgis_api_break_3_0_QgsTreeWidgetItem}
-----------------
@@ -71,7 +71,7 @@ class QgsRasterCalculator
.. versionadded:: 2.10
%End

int processCalculation( QProgressDialog *p = 0 );
int processCalculation( QgsFeedback *feedback = 0 );
%Docstring
:rtype: int
%End
@@ -30,8 +30,11 @@ class QgsTransectSample
const QString &baselineStrataId, const QString &outputPointLayer, const QString &outputLineLayer, const QString &usedBaselineLayer, double minTransectLength = 0.0,
double baselineBufferDistance = -1.0, double baselineSimplificationTolerance = -1.0 );

int createSample( QProgressDialog *pd );
int createSample( QgsFeedback *feedback = 0 );
%Docstring
Creates the sample.

The optional ``feedback`` argument can be used for progress reporting and cancelation support.
:rtype: int
%End

@@ -22,8 +22,8 @@
#include "qgsrasterlayer.h"
#include "qgsrastermatrix.h"
#include "qgsrasterprojector.h"
#include "qgsfeedback.h"

#include <QProgressDialog>
#include <QFile>

#include <cpl_string.h>
@@ -56,7 +56,7 @@ QgsRasterCalculator::QgsRasterCalculator( const QString &formulaString, const QS
{
}

int QgsRasterCalculator::processCalculation( QProgressDialog *p )
int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )
{
//prepare search string / tree
QString errorString;
@@ -117,23 +117,18 @@ int QgsRasterCalculator::processCalculation( QProgressDialog *p )
float outputNodataValue = -FLT_MAX;
GDALSetRasterNoDataValue( outputRasterBand, outputNodataValue );

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

QgsRasterMatrix resultMatrix;
resultMatrix.setNodataValue( outputNodataValue );

//read / write line by line
for ( int i = 0; i < mNumOutputRows; ++i )
{
if ( p )
if ( feedback )
{
p->setValue( i );
feedback->setProgress( 100.0 * static_cast< double >( i ) / mNumOutputRows );
}

if ( p && p->wasCanceled() )
if ( feedback && feedback->isCanceled() )
{
break;
}
@@ -159,17 +154,17 @@ int QgsRasterCalculator::processCalculation( QProgressDialog *p )

}

if ( p )
if ( feedback )
{
p->setValue( mNumOutputRows );
feedback->setProgress( 100.0 );
}

//close datasets and release memory
delete calcNode;
qDeleteAll( inputBlocks );
inputBlocks.clear();

if ( p && p->wasCanceled() )
if ( feedback && feedback->isCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
@@ -26,7 +26,7 @@
#include "qgis_analysis.h"

class QgsRasterLayer;
class QProgressDialog;
class QgsFeedback;


struct ANALYSIS_EXPORT QgsRasterCalculatorEntry
@@ -85,11 +85,13 @@ class ANALYSIS_EXPORT QgsRasterCalculator
QgsRasterCalculator( const QString &formulaString, const QString &outputFile, const QString &outputFormat,
const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &outputCrs, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry> &rasterEntries );

/** Starts the calculation and writes new raster
\param p progress bar (or 0 if called from non-gui code)
\returns 0 in case of success*/
/** Starts the calculation and writes a new raster.
*
* The optional \a feedback argument can be used for progress reporting and cancelation support.
* \returns 0 in case of success
*/
//TODO QGIS 3.0 - return QgsRasterCalculator::Result
int processCalculation( QProgressDialog *p = nullptr );
int processCalculation( QgsFeedback *feedback = nullptr );

private:
//default constructor forbidden. We need formula, output file, output format and output raster resolution obligatory
@@ -20,7 +20,8 @@
#include "qgsvectorfilewriter.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include <QProgressDialog>
#include "qgsfeedback.h"

#include <QFileInfo>
#ifndef _MSC_VER
#include <cstdint>
@@ -60,10 +61,8 @@ QgsTransectSample::QgsTransectSample()
{
}

int QgsTransectSample::createSample( QProgressDialog *pd )
int QgsTransectSample::createSample( QgsFeedback *feedback )
{
Q_UNUSED( pd );

if ( !mStrataLayer || !mStrataLayer->isValid() )
{
return 1;
@@ -147,19 +146,20 @@ int QgsTransectSample::createSample( QProgressDialog *pd )
QgsFeature fet;
int nTotalTransects = 0;
int nFeatures = 0;
int totalFeatures = 0;

if ( pd )
if ( feedback )
{
pd->setMaximum( mStrataLayer->featureCount() );
totalFeatures = mStrataLayer->featureCount();
}

while ( strataIt.nextFeature( fet ) )
{
if ( pd )
if ( feedback )
{
pd->setValue( nFeatures );
feedback->setProgress( 100.0 * static_cast< double >( nFeatures ) / totalFeatures );
}
if ( pd && pd->wasCanceled() )
if ( feedback && feedback->isCanceled() )
{
break;
}
@@ -321,9 +321,9 @@ int QgsTransectSample::createSample( QProgressDialog *pd )
++nFeatures;
}

if ( pd )
if ( feedback )
{
pd->setValue( mStrataLayer->featureCount() );
feedback->setProgress( 100.0 );
}

return 0;
@@ -25,7 +25,7 @@ class QgsGeometry;
class QgsSpatialIndex;
class QgsVectorLayer;
class QgsPointXY;
class QProgressDialog;
class QgsFeedback;

/** \ingroup analysis
* A class for the creation of transect sample lines based on a set of strata polygons and baselines*/
@@ -44,7 +44,12 @@ class ANALYSIS_EXPORT QgsTransectSample
const QString &baselineStrataId, const QString &outputPointLayer, const QString &outputLineLayer, const QString &usedBaselineLayer, double minTransectLength = 0.0,
double baselineBufferDistance = -1.0, double baselineSimplificationTolerance = -1.0 );

int createSample( QProgressDialog *pd );
/**
* Creates the sample.
*
* The optional \a feedback argument can be used for progress reporting and cancelation support.
*/
int createSample( QgsFeedback *feedback = nullptr );

private:
QgsTransectSample(); //default constructor forbidden
@@ -5127,7 +5127,11 @@ void QgisApp::showRasterCalculator()

QProgressDialog p( tr( "Calculating..." ), tr( "Abort..." ), 0, 0 );
p.setWindowModality( Qt::WindowModal );
QgsRasterCalculator::Result res = static_cast< QgsRasterCalculator::Result >( rc.processCalculation( &p ) );
p.setMaximum( 100.0 );
QgsFeedback feedback;
connect( &feedback, &QgsFeedback::progressChanged, &p, &QProgressDialog::setValue );
connect( &feedback, &QgsFeedback::canceled, &p, &QProgressDialog::cancel );
QgsRasterCalculator::Result res = static_cast< QgsRasterCalculator::Result >( rc.processCalculation( &feedback ) );
switch ( res )
{
case QgsRasterCalculator::Success:

0 comments on commit eb7ad7a

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