Skip to content

Commit 090bb9b

Browse files
committed
Use QgsFeedback instead of QProgressDialog in tin interpolator
1 parent 000c86e commit 090bb9b

File tree

8 files changed

+39
-48
lines changed

8 files changed

+39
-48
lines changed

doc/api_break.dox

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,11 @@ QgsSymbolsListWidget {#qgis_api_break_3_0_QgsSymbolsListWidget}
23212321
- expressionContext(), setExpressionContext(), setMapCanvas() and mapCanvas() have been removed in favor of setContext()/context()
23222322

23232323

2324+
QgsTINInterpolator {#qgis_api_break_3_0_QgsTINInterpolator}
2325+
------------------
2326+
2327+
- The constructor takes a QgsFeedback argument instead of using a QProgressDialog.
2328+
23242329
QgsTolerance {#qgis_api_break_3_0_QgsTolerance}
23252330
------------
23262331

python/analysis/interpolation/NormVecDecorator.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Eliminates the horizontal triangles by swapping or by insertion of new points. I
5959
Estimates the first derivative a point. Return true in case of succes and false otherwise
6060
:rtype: bool
6161
%End
62-
bool estimateFirstDerivatives( QProgressDialog *d = 0 );
62+
bool estimateFirstDerivatives( QgsFeedback *feedback = 0 );
6363
%Docstring
6464
This method adds the functionality of estimating normals at the data points. Return true in the case of success and false otherwise
6565
:rtype: bool

python/analysis/interpolation/qgstininterpolator.sip

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ class QgsTINInterpolator: QgsInterpolator
2525
Linear,
2626
CloughTocher
2727
};
28-
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, bool showProgressDialog = false );
28+
29+
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, QgsFeedback *feedback = 0 );
30+
%Docstring
31+
Constructor for QgsTINInterpolator.
32+
The ``feedback`` object specifies an optional QgsFeedback object for progress reports and cancelation support.
33+
Ownership of ``feedback`` is not transferred and callers must ensure that it exists for the lifetime of this object.
34+
%End
2935
~QgsTINInterpolator();
3036

3137
virtual int interpolatePoint( double x, double y, double &result );

python/plugins/processing/algs/qgis/TinInterpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def processAlgorithm(self, parameters, context, feedback):
190190
else:
191191
interpolationMethod = QgsTINInterpolator.CloughTocher
192192

193-
interpolator = QgsTINInterpolator(layerData, interpolationMethod)
193+
interpolator = QgsTINInterpolator(layerData, interpolationMethod, feedback)
194194
if triangulation is not None and triangulation != '':
195195
interpolator.setExportTriangulationToFile(True)
196196
interpolator.setTriangulationFilePath(triangulation)

src/analysis/interpolation/NormVecDecorator.cc

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
***************************************************************************/
1616

1717
#include "NormVecDecorator.h"
18+
#include "qgsfeedback.h"
1819
#include "qgslogger.h"
1920
#include <QApplication>
20-
#include <QProgressDialog>
2121

2222
NormVecDecorator::~NormVecDecorator()
2323
{
@@ -511,29 +511,18 @@ bool NormVecDecorator::estimateFirstDerivative( int pointno )
511511
}
512512

513513
//weighted method of little
514-
bool NormVecDecorator::estimateFirstDerivatives( QProgressDialog *d )
514+
bool NormVecDecorator::estimateFirstDerivatives( QgsFeedback *feedback )
515515
{
516-
if ( d )
516+
int numberPoints = getNumberOfPoints();
517+
for ( int i = 0; i < numberPoints; i++ )
517518
{
518-
d->setMinimum( 0 );
519-
d->setMaximum( getNumberOfPoints() );
520-
d->setCancelButton( nullptr ); //we cannot cancel derivative estimation
521-
d->show();
522-
}
523-
524-
for ( int i = 0; i < getNumberOfPoints(); i++ )
525-
{
526-
if ( d )
519+
if ( feedback )
527520
{
528-
d->setValue( i );
521+
feedback->setProgress( 100.0 * static_cast< double >( i ) / numberPoints );
529522
}
530523
estimateFirstDerivative( i );
531524
}
532525

533-
if ( d )
534-
{
535-
d->setValue( getNumberOfPoints() );
536-
}
537526
return true;
538527
}
539528

src/analysis/interpolation/NormVecDecorator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "qgslogger.h"
2626
#include "qgis_analysis.h"
2727

28-
class QProgressDialog;
28+
class QgsFeedback;
2929

3030
/** \ingroup analysis
3131
* Decorator class which adds the functionality of estimating normals at the data points*/
@@ -50,7 +50,7 @@ class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
5050
//! Estimates the first derivative a point. Return true in case of succes and false otherwise
5151
bool estimateFirstDerivative( int pointno );
5252
//! This method adds the functionality of estimating normals at the data points. Return true in the case of success and false otherwise
53-
bool estimateFirstDerivatives( QProgressDialog *d = nullptr );
53+
bool estimateFirstDerivatives( QgsFeedback *feedback = nullptr );
5454
//! Returns a pointer to the normal vector for the point with the number n
5555
Vector3D *getNormal( int n ) const;
5656
//! Finds out, in which triangle a point with coordinates x and y is and assigns the triangle points to p1, p2, p3 and the estimated normals to v1, v2, v3. The vectors are normally taken from 'mNormVec', except if p1, p2 or p3 is a point on a breakline. In this case, the normal is calculated on-the-fly. Returns false, if something went wrong and true otherwise

src/analysis/interpolation/qgstininterpolator.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
#include "qgsgeometry.h"
2828
#include "qgsvectorlayer.h"
2929
#include "qgswkbptr.h"
30+
#include "qgsfeedback.h"
3031
#include <QProgressDialog>
3132

32-
QgsTINInterpolator::QgsTINInterpolator( const QList<LayerData> &inputData, TINInterpolation interpolation, bool showProgressDialog )
33+
QgsTINInterpolator::QgsTINInterpolator( const QList<LayerData> &inputData, TINInterpolation interpolation, QgsFeedback *feedback )
3334
: QgsInterpolator( inputData )
3435
, mTriangulation( nullptr )
3536
, mTriangleInterpolator( nullptr )
3637
, mIsInitialized( false )
37-
, mShowProgressDialog( showProgressDialog )
38+
, mFeedback( feedback )
3839
, mExportTriangulationToFile( false )
3940
, mInterpolation( interpolation )
4041
{
@@ -84,7 +85,7 @@ void QgsTINInterpolator::initialize()
8485
//get number of features if we use a progress bar
8586
int nFeatures = 0;
8687
int nProcessedFeatures = 0;
87-
if ( mShowProgressDialog )
88+
if ( mFeedback )
8889
{
8990
Q_FOREACH ( const LayerData &layer, mLayerData )
9091
{
@@ -95,14 +96,6 @@ void QgsTINInterpolator::initialize()
9596
}
9697
}
9798

98-
QProgressDialog *progressDialog = nullptr;
99-
if ( mShowProgressDialog )
100-
{
101-
progressDialog = new QProgressDialog( QObject::tr( "Building triangulation..." ), QObject::tr( "Abort" ), 0, nFeatures, nullptr );
102-
progressDialog->setWindowModality( Qt::WindowModal );
103-
}
104-
105-
10699
QgsFeature f;
107100
Q_FOREACH ( const LayerData &layer, mLayerData )
108101
{
@@ -118,36 +111,27 @@ void QgsTINInterpolator::initialize()
118111

119112
while ( fit.nextFeature( f ) )
120113
{
121-
if ( mShowProgressDialog )
114+
if ( mFeedback )
122115
{
123-
if ( progressDialog->wasCanceled() )
116+
if ( mFeedback->isCanceled() )
124117
{
125118
break;
126119
}
127-
progressDialog->setValue( nProcessedFeatures );
120+
mFeedback->setProgress( 100.0 * static_cast< double >( nProcessedFeatures ) / nFeatures );
128121
}
129122
insertData( &f, layer.zCoordInterpolation, layer.interpolationAttribute, layer.mInputType );
130123
++nProcessedFeatures;
131124
}
132125
}
133126
}
134127

135-
delete progressDialog;
136-
137128
if ( mInterpolation == CloughTocher )
138129
{
139130
CloughTocherInterpolator *ctInterpolator = new CloughTocherInterpolator();
140131
NormVecDecorator *dec = dynamic_cast<NormVecDecorator *>( mTriangulation );
141132
if ( dec )
142133
{
143-
QProgressDialog *progressDialog = nullptr;
144-
if ( mShowProgressDialog ) //show a progress dialog because it can take a long time...
145-
{
146-
progressDialog = new QProgressDialog();
147-
progressDialog->setLabelText( QObject::tr( "Estimating normal derivatives..." ) );
148-
}
149-
dec->estimateFirstDerivatives( progressDialog );
150-
delete progressDialog;
134+
dec->estimateFirstDerivatives( mFeedback );
151135
ctInterpolator->setTriangulation( dec );
152136
dec->setTriangleInterpolator( ctInterpolator );
153137
mTriangleInterpolator = ctInterpolator;

src/analysis/interpolation/qgstininterpolator.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
class Triangulation;
2626
class TriangleInterpolator;
2727
class QgsFeature;
28+
class QgsFeedback;
2829

2930
/** \ingroup analysis
3031
* Interpolation in a triangular irregular network*/
@@ -37,7 +38,13 @@ class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
3738
Linear,
3839
CloughTocher
3940
};
40-
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, bool showProgressDialog = false );
41+
42+
/**
43+
* Constructor for QgsTINInterpolator.
44+
* The \a feedback object specifies an optional QgsFeedback object for progress reports and cancelation support.
45+
* Ownership of \a feedback is not transferred and callers must ensure that it exists for the lifetime of this object.
46+
*/
47+
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, QgsFeedback *feedback = nullptr );
4148
~QgsTINInterpolator();
4249

4350
/** Calculates interpolation value for map coordinates x, y
@@ -54,7 +61,7 @@ class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
5461
Triangulation *mTriangulation = nullptr;
5562
TriangleInterpolator *mTriangleInterpolator = nullptr;
5663
bool mIsInitialized;
57-
bool mShowProgressDialog;
64+
QgsFeedback *mFeedback = nullptr;
5865
//! If true: export triangulation to shapefile after initialization
5966
bool mExportTriangulationToFile;
6067
//! File path to export the triangulation

0 commit comments

Comments
 (0)