Skip to content

Commit 60e98be

Browse files
committedNov 2, 2017
Pass QgsFeedback to methods in interpolation for more responsive
cancelation and progress reports
1 parent 151fb08 commit 60e98be

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed
 

‎src/analysis/interpolation/qgsgridfilewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int QgsGridFileWriter::writeFile( QgsFeedback *feedback )
6060
currentXValue = mInterpolationExtent.xMinimum() + mCellSizeX / 2.0; //calculate value in the center of the cell
6161
for ( int j = 0; j < mNumColumns; ++j )
6262
{
63-
if ( mInterpolator->interpolatePoint( currentXValue, currentYValue, interpolatedValue ) == 0 )
63+
if ( mInterpolator->interpolatePoint( currentXValue, currentYValue, interpolatedValue, feedback ) == 0 )
6464
{
6565
outStream << interpolatedValue << ' ';
6666
}

‎src/analysis/interpolation/qgsidwinterpolator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ QgsIDWInterpolator::QgsIDWInterpolator()
3131

3232
}
3333

34-
int QgsIDWInterpolator::interpolatePoint( double x, double y, double &result )
34+
int QgsIDWInterpolator::interpolatePoint( double x, double y, double &result, QgsFeedback *feedback )
3535
{
3636
if ( !mDataIsCached )
3737
{
38-
cacheBaseData();
38+
cacheBaseData( feedback );
3939
}
4040

4141
double currentWeight;

‎src/analysis/interpolation/qgsidwinterpolator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class ANALYSIS_EXPORT QgsIDWInterpolator: public QgsInterpolator
3030
public:
3131
QgsIDWInterpolator( const QList<QgsInterpolator::LayerData> &layerData );
3232

33+
int interpolatePoint( double x, double y, double &result, QgsFeedback *feedback = nullptr ) override;
34+
3335
/**
3436
* Calculates interpolation value for map coordinates x, y
3537
\param x x-coordinate (in map units)

‎src/analysis/interpolation/qgsinterpolator.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
#include "qgsvectordataprovider.h"
2121
#include "qgsvectorlayer.h"
2222
#include "qgsgeometry.h"
23-
#include "qgswkbptr.h"
23+
#include "qgsfeedback.h"
2424

2525
QgsInterpolator::QgsInterpolator( const QList<LayerData> &layerData )
2626
: mLayerData( layerData )
2727
{
2828

2929
}
3030

31-
int QgsInterpolator::cacheBaseData()
31+
QgsInterpolator::Result QgsInterpolator::cacheBaseData( QgsFeedback *feedback )
3232
{
3333
if ( mLayerData.empty() )
3434
{
@@ -41,10 +41,8 @@ int QgsInterpolator::cacheBaseData()
4141

4242
Q_FOREACH ( const LayerData &layer, mLayerData )
4343
{
44-
if ( !layer.vectorLayer )
45-
{
46-
continue;
47-
}
44+
if ( feedback && feedback->isCanceled() )
45+
return Canceled;
4846

4947
QgsVectorLayer *vlayer = layer.vectorLayer;
5048
if ( !vlayer )
@@ -61,12 +59,21 @@ int QgsInterpolator::cacheBaseData()
6159

6260
double attributeValue = 0.0;
6361
bool attributeConversionOk = false;
62+
double progress = layerCount * layerStep;
6463

6564
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( attList ) );
65+
double featureStep = source->featureCount() > 0 ? layerStep / source->featureCount() : layerStep;
6666

6767
QgsFeature feature;
6868
while ( fit.nextFeature( feature ) )
6969
{
70+
if ( feedback && feedback->isCanceled() )
71+
return Canceled;
72+
73+
progress += featureStep;
74+
if ( feedback )
75+
feedback->setProgress( progress );
76+
7077
if ( !layer.zCoordInterpolation )
7178
{
7279
QVariant attributeVariant = feature.attribute( layer.interpolationAttribute );

‎src/analysis/interpolation/qgsinterpolator.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
class QgsVectorLayer;
2626
class QgsGeometry;
27+
class QgsFeedback;
2728

2829
struct ANALYSIS_EXPORT vertexData
2930
{
@@ -63,11 +64,12 @@ class ANALYSIS_EXPORT QgsInterpolator
6364

6465
/**
6566
* Calculates interpolation value for map coordinates x, y
66-
\param x x-coordinate (in map units)
67-
\param y y-coordinate (in map units)
68-
\param result out: interpolation result
69-
\returns 0 in case of success*/
70-
virtual int interpolatePoint( double x, double y, double &result ) = 0;
67+
* \param x x-coordinate (in map units)
68+
* \param y y-coordinate (in map units)
69+
* \param result out: interpolation result
70+
* \param feedback optional feedback object for progress and cancelation support
71+
* \returns 0 in case of success*/
72+
virtual int interpolatePoint( double x, double y, double &result, QgsFeedback *feedback = nullptr ) = 0;
7173

7274
//! \note not available in Python bindings
7375
QList<LayerData> layerData() const { return mLayerData; } SIP_SKIP

‎src/analysis/interpolation/qgstininterpolator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ QgsTINInterpolator::~QgsTINInterpolator()
4343
delete mTriangleInterpolator;
4444
}
4545

46-
int QgsTINInterpolator::interpolatePoint( double x, double y, double &result )
46+
int QgsTINInterpolator::interpolatePoint( double x, double y, double &result, QgsFeedback * )
4747
{
4848
if ( !mIsInitialized )
4949
{

‎src/analysis/interpolation/qgstininterpolator.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
5050
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, QgsFeedback *feedback = nullptr );
5151
~QgsTINInterpolator();
5252

53-
/**
54-
* Calculates interpolation value for map coordinates x, y
55-
\param x x-coordinate (in map units)
56-
\param y y-coordinate (in map units)
57-
\param result out: interpolation result
58-
\returns 0 in case of success*/
59-
int interpolatePoint( double x, double y, double &result ) override;
53+
int interpolatePoint( double x, double y, double &result, QgsFeedback *feedback ) override;
6054

6155
/**
6256
* Returns the fields output by features when saving the triangulation.

0 commit comments

Comments
 (0)
Please sign in to comment.