Skip to content
Permalink
Browse files

Use QgsFeedback in QgsGridFileWriter instead of QProgressDialog

  • Loading branch information
nyalldawson committed Aug 18, 2017
1 parent a07ea33 commit 356588abf0d6c3f44f97f2ba635c668f836f735e
@@ -1348,6 +1348,13 @@ QgsGraduatedRenderer {#qgis_api_break_3_0_QgsGraduatedRenderer}
- setInvertedColorRamp() and invertedColorRamp() functions are gone, QgsColorRamp now responsible for invert
- createRenderer() and updateColorRamp()'s inverted parameter is gone


QgsGridFileWriter {#qgis_api_break_3_0_QgsGridFileWriter}
-----------------

- writeFile() now takes an optional QgsFeedback argument instead of using a QProgressDialog


QgsGroupWMSDataDialog {#qgis_api_break_3_0_QgsGroupWMSDataDialog}
---------------------

@@ -20,10 +20,10 @@ class QgsGridFileWriter
QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY );


int writeFile( bool showProgressDialog = false );
int writeFile( QgsFeedback *feedback = 0 );
%Docstring
Writes the grid file.
\param showProgressDialog shows a dialog with the possibility to cancel
\param feedback optional feedback object for progress reports and cancelation support
:return: 0 in case of success*
:rtype: int
%End
@@ -180,5 +180,5 @@ def processAlgorithm(self, parameters, context, feedback):
cellsizeX,
cellsizeY)

writer.writeFile()
writer.writeFile(feedback)
return {self.OUTPUT: output}
@@ -18,9 +18,9 @@
#include "qgsgridfilewriter.h"
#include "qgsinterpolator.h"
#include "qgsvectorlayer.h"
#include "qgsfeedback.h"
#include <QFile>
#include <QFileInfo>
#include <QProgressDialog>

QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY )
: mInterpolator( i )
@@ -44,7 +44,7 @@ QgsGridFileWriter::QgsGridFileWriter()

}

int QgsGridFileWriter::writeFile( bool showProgressDialog )
int QgsGridFileWriter::writeFile( QgsFeedback *feedback )
{
QFile outputFile( mOutputFilePath );

@@ -67,13 +67,6 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
double currentXValue;
double interpolatedValue;

QProgressDialog *progressDialog = nullptr;
if ( showProgressDialog )
{
progressDialog = new QProgressDialog( QObject::tr( "Interpolating..." ), QObject::tr( "Abort" ), 0, mNumRows, nullptr );
progressDialog->setWindowModality( Qt::WindowModal );
}

for ( int i = 0; i < mNumRows; ++i )
{
currentXValue = mInterpolationExtent.xMinimum() + mCellSizeX / 2.0; //calculate value in the center of the cell
@@ -92,14 +85,14 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
outStream << endl;
currentYValue -= mCellSizeY;

if ( showProgressDialog )
if ( feedback )
{
if ( progressDialog->wasCanceled() )
if ( feedback->isCanceled() )
{
outputFile.remove();
return 3;
}
progressDialog->setValue( i );
feedback->setProgress( 100.0 * i / static_cast< double >( mNumRows ) );
}
}

@@ -120,7 +113,6 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
prjStream << endl;
prjFile.close();

delete progressDialog;
return 0;
}

@@ -24,6 +24,7 @@
#include "qgis_analysis.h"

class QgsInterpolator;
class QgsFeedback;

/** \ingroup analysis
* A class that does interpolation to a grid and writes the results to an ascii grid*/
@@ -34,10 +35,10 @@ class ANALYSIS_EXPORT QgsGridFileWriter
QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY );

/** Writes the grid file.
\param showProgressDialog shows a dialog with the possibility to cancel
\param feedback optional feedback object for progress reports and cancelation support
\returns 0 in case of success*/

int writeFile( bool showProgressDialog = false );
int writeFile( QgsFeedback *feedback = nullptr );

private:

@@ -140,7 +140,7 @@ QgsMapLayer *QgsInterpolationLayerBuilder::createMapLayer( const QDomElement &el

QgsRectangle extent = mVectorLayer->extent();
QgsGridFileWriter gridWriter( interpolator, tmpFile->fileName(), extent, nCols, nRows, extent.width() / nCols, extent.height() / nRows );
if ( gridWriter.writeFile( false ) != 0 )
if ( gridWriter.writeFile() != 0 )
{
QgsDebugMsg( "Interpolation of raster failed" );
return nullptr;

0 comments on commit 356588a

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