Skip to content

Commit f3d42a2

Browse files
committedJul 16, 2017
[network analysis] use QgsFeedback for progress reporting and
cancelation
1 parent 126a274 commit f3d42a2

File tree

6 files changed

+44
-27
lines changed

6 files changed

+44
-27
lines changed
 

‎doc/api_break.dox

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2510,11 +2510,18 @@ QgsRendererAbstractMetadata {#qgis_api_break_3_0_QgsRendererAbstractMetadata}
25102510

25112511
- createRenderer() now expects a reference to QgsReadWriteContext as the second argument
25122512

2513+
QgsGraphDirector {#qgis_api_break_3_0_QgsGraphDirector}
2514+
----------------
2515+
2516+
- makeGraph() now uses QgsFeedback for progress reporting and cancelation
2517+
- buildProgress() signal was removed
2518+
- buildMessage() signal was removed
2519+
25132520
QgsVectorLayerDirector {#qgis_api_break_3_0_QgsVectorLayerDirector}
25142521
----------------------
25152522

25162523
- QgsVectorLayerDirector() constructor now expects a reference to QgsFeatureSource as the first argument
2517-
2524+
- makeGraph() now uses QgsFeedback for progress reporting and cancelation
25182525

25192526
Processing {#qgis_api_break_3_0_Processing}
25202527
----------

‎python/analysis/network/qgsgraphdirector.sip

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,21 @@ class QgsGraphDirector : QObject
3131
else
3232
sipType = NULL;
3333
%End
34-
signals:
35-
void buildProgress( int, int ) const;
36-
%Docstring
37-
Emitted to report graph building progress
38-
%End
39-
void buildMessage( const QString & ) const;
40-
%Docstring
41-
Emitted to report information about graph building
42-
%End
43-
4434
public:
4535

4636
virtual ~QgsGraphDirector();
4737

4838
virtual void makeGraph( QgsGraphBuilderInterface *builder,
4939
const QVector< QgsPointXY > &additionalPoints,
50-
QVector< QgsPointXY > &snappedPoints /Out/ ) const;
40+
QVector< QgsPointXY > &snappedPoints /Out/,
41+
QgsFeedback *feedback ) const;
5142
%Docstring
5243
Make a graph using QgsGraphBuilder
5344

5445
\param builder the graph builder
5546
\param additionalPoints list of points that should be snapped to the graph
5647
\param snappedPoints list of snapped points
48+
\param feedback feedback object for reporting progress
5749
.. note::
5850

5951
if snappedPoints[i] == QgsPointXY(0.0,0.0) then snapping failed.

‎python/analysis/network/qgsvectorlayerdirector.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class QgsVectorLayerDirector : QgsGraphDirector
5151

5252
virtual void makeGraph( QgsGraphBuilderInterface *builder,
5353
const QVector< QgsPointXY > &additionalPoints,
54-
QVector< QgsPointXY> &snappedPoints /Out/ ) const;
54+
QVector< QgsPointXY> &snappedPoints /Out/,
55+
QgsFeedback *feedback ) const;
5556
%Docstring
5657
MANDATORY DIRECTOR PROPERTY DECLARATION
5758
%End

‎src/analysis/network/qgsgraphdirector.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
#include <QVector>
2121
#include <QList>
2222

23-
#include <qgis.h>
24-
#include <qgspoint.h>
23+
#include "qgis.h"
24+
#include "qgspoint.h"
25+
#include "qgsfeedback.h"
2526
#include "qgsnetworkstrategy.h"
2627
#include "qgis_analysis.h"
2728

@@ -53,12 +54,6 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject
5354

5455
Q_OBJECT
5556

56-
signals:
57-
//! Emitted to report graph building progress
58-
void buildProgress( int, int ) const;
59-
//! Emitted to report information about graph building
60-
void buildMessage( const QString & ) const;
61-
6257
public:
6358

6459
virtual ~QgsGraphDirector() { }
@@ -69,15 +64,18 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject
6964
* \param builder the graph builder
7065
* \param additionalPoints list of points that should be snapped to the graph
7166
* \param snappedPoints list of snapped points
67+
* \param feedback feedback object for reporting progress
7268
* \note if snappedPoints[i] == QgsPointXY(0.0,0.0) then snapping failed.
7369
*/
7470
virtual void makeGraph( QgsGraphBuilderInterface *builder,
7571
const QVector< QgsPointXY > &additionalPoints,
76-
QVector< QgsPointXY > &snappedPoints SIP_OUT ) const
72+
QVector< QgsPointXY > &snappedPoints SIP_OUT,
73+
QgsFeedback *feedback ) const
7774
{
7875
Q_UNUSED( builder );
7976
Q_UNUSED( additionalPoints );
8077
Q_UNUSED( snappedPoints );
78+
Q_UNUSED( feedback );
8179
}
8280

8381
//! Add optimization strategy

‎src/analysis/network/qgsvectorlayerdirector.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "qgspoint.h"
2828
#include "qgsgeometry.h"
2929
#include "qgsdistancearea.h"
30-
#include 'qgswkbtypes.h"
30+
#include "qgswkbtypes.h"
3131

3232
#include <QString>
3333
#include <QtAlgorithms>
@@ -124,7 +124,7 @@ QString QgsVectorLayerDirector::name() const
124124
}
125125

126126
void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPointXY > &additionalPoints,
127-
QVector< QgsPointXY > &snappedPoints ) const
127+
QVector< QgsPointXY > &snappedPoints, QgsFeedback *feedback ) const
128128
{
129129
int featureCount = ( int ) mSource->featureCount() * 2;
130130
int step = 0;
@@ -158,6 +158,11 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
158158
QgsFeature feature;
159159
while ( fit.nextFeature( feature ) )
160160
{
161+
if ( feedback && feedback->isCanceled() )
162+
{
163+
return;
164+
}
165+
161166
QgsMultiPolyline mpl;
162167
if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::MultiLineString )
163168
mpl = feature.geometry().asMultiPolyline();
@@ -207,7 +212,11 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
207212
isFirstPoint = false;
208213
}
209214
}
210-
emit buildProgress( ++step, featureCount );
215+
if ( feedback )
216+
{
217+
feedback->setProgress( 100.0 * static_cast< double >( ++step ) / featureCount );
218+
}
219+
211220
}
212221
// end: tie points to graph
213222

@@ -274,6 +283,11 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
274283
fit = mSource->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( la ) );
275284
while ( fit.nextFeature( feature ) )
276285
{
286+
if ( feedback && feedback->isCanceled() )
287+
{
288+
return;
289+
}
290+
277291
Direction directionType = mDefaultDirection;
278292

279293
// What direction have feature?
@@ -382,6 +396,10 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
382396
isFirstPoint = false;
383397
} // for (it = pl.begin(); it != pl.end(); ++it)
384398
}
385-
emit buildProgress( ++step, featureCount );
399+
if ( feedback )
400+
{
401+
feedback->setProgress( 100.0 * static_cast< double >( ++step ) / featureCount );
402+
}
403+
386404
} // while( mSource->nextFeature(feature) )
387405
} // makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPointXY >& additionalPoints, QVector< QgsPointXY >& tiedPoint )

‎src/analysis/network/qgsvectorlayerdirector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class ANALYSIS_EXPORT QgsVectorLayerDirector : public QgsGraphDirector
7474
*/
7575
void makeGraph( QgsGraphBuilderInterface *builder,
7676
const QVector< QgsPointXY > &additionalPoints,
77-
QVector< QgsPointXY> &snappedPoints SIP_OUT ) const override;
77+
QVector< QgsPointXY> &snappedPoints SIP_OUT,
78+
QgsFeedback *feedback ) const override;
7879

7980
QString name() const override;
8081

0 commit comments

Comments
 (0)
Please sign in to comment.