Skip to content

Commit

Permalink
[network analysis] use QgsFeedback for progress reporting and
Browse files Browse the repository at this point in the history
cancelation
  • Loading branch information
alexbruy committed Jul 16, 2017
1 parent 126a274 commit f3d42a2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
9 changes: 8 additions & 1 deletion doc/api_break.dox
Expand Up @@ -2510,11 +2510,18 @@ QgsRendererAbstractMetadata {#qgis_api_break_3_0_QgsRendererAbstractMetadata}

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

QgsGraphDirector {#qgis_api_break_3_0_QgsGraphDirector}
----------------

- makeGraph() now uses QgsFeedback for progress reporting and cancelation
- buildProgress() signal was removed
- buildMessage() signal was removed

QgsVectorLayerDirector {#qgis_api_break_3_0_QgsVectorLayerDirector}
----------------------

- QgsVectorLayerDirector() constructor now expects a reference to QgsFeatureSource as the first argument

- makeGraph() now uses QgsFeedback for progress reporting and cancelation

Processing {#qgis_api_break_3_0_Processing}
----------
Expand Down
14 changes: 3 additions & 11 deletions python/analysis/network/qgsgraphdirector.sip
Expand Up @@ -31,29 +31,21 @@ class QgsGraphDirector : QObject
else
sipType = NULL;
%End
signals:
void buildProgress( int, int ) const;
%Docstring
Emitted to report graph building progress
%End
void buildMessage( const QString & ) const;
%Docstring
Emitted to report information about graph building
%End

public:

virtual ~QgsGraphDirector();

virtual void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY > &snappedPoints /Out/ ) const;
QVector< QgsPointXY > &snappedPoints /Out/,
QgsFeedback *feedback ) const;
%Docstring
Make a graph using QgsGraphBuilder

\param builder the graph builder
\param additionalPoints list of points that should be snapped to the graph
\param snappedPoints list of snapped points
\param feedback feedback object for reporting progress
.. note::

if snappedPoints[i] == QgsPointXY(0.0,0.0) then snapping failed.
Expand Down
3 changes: 2 additions & 1 deletion python/analysis/network/qgsvectorlayerdirector.sip
Expand Up @@ -51,7 +51,8 @@ class QgsVectorLayerDirector : QgsGraphDirector

virtual void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY> &snappedPoints /Out/ ) const;
QVector< QgsPointXY> &snappedPoints /Out/,
QgsFeedback *feedback ) const;
%Docstring
MANDATORY DIRECTOR PROPERTY DECLARATION
%End
Expand Down
16 changes: 7 additions & 9 deletions src/analysis/network/qgsgraphdirector.h
Expand Up @@ -20,8 +20,9 @@
#include <QVector>
#include <QList>

#include <qgis.h>
#include <qgspoint.h>
#include "qgis.h"
#include "qgspoint.h"
#include "qgsfeedback.h"
#include "qgsnetworkstrategy.h"
#include "qgis_analysis.h"

Expand Down Expand Up @@ -53,12 +54,6 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject

Q_OBJECT

signals:
//! Emitted to report graph building progress
void buildProgress( int, int ) const;
//! Emitted to report information about graph building
void buildMessage( const QString & ) const;

public:

virtual ~QgsGraphDirector() { }
Expand All @@ -69,15 +64,18 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject
* \param builder the graph builder
* \param additionalPoints list of points that should be snapped to the graph
* \param snappedPoints list of snapped points
* \param feedback feedback object for reporting progress
* \note if snappedPoints[i] == QgsPointXY(0.0,0.0) then snapping failed.
*/
virtual void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY > &snappedPoints SIP_OUT ) const
QVector< QgsPointXY > &snappedPoints SIP_OUT,
QgsFeedback *feedback ) const
{
Q_UNUSED( builder );
Q_UNUSED( additionalPoints );
Q_UNUSED( snappedPoints );
Q_UNUSED( feedback );
}

//! Add optimization strategy
Expand Down
26 changes: 22 additions & 4 deletions src/analysis/network/qgsvectorlayerdirector.cpp
Expand Up @@ -27,7 +27,7 @@
#include "qgspoint.h"
#include "qgsgeometry.h"
#include "qgsdistancearea.h"
#include 'qgswkbtypes.h"
#include "qgswkbtypes.h"

#include <QString>
#include <QtAlgorithms>
Expand Down Expand Up @@ -124,7 +124,7 @@ QString QgsVectorLayerDirector::name() const
}

void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY > &snappedPoints ) const
QVector< QgsPointXY > &snappedPoints, QgsFeedback *feedback ) const
{
int featureCount = ( int ) mSource->featureCount() * 2;
int step = 0;
Expand Down Expand Up @@ -158,6 +158,11 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
if ( feedback && feedback->isCanceled() )
{
return;
}

QgsMultiPolyline mpl;
if ( QgsWkbTypes::flatType( feature.geometry().geometry()->wkbType() ) == QgsWkbTypes::MultiLineString )
mpl = feature.geometry().asMultiPolyline();
Expand Down Expand Up @@ -207,7 +212,11 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
isFirstPoint = false;
}
}
emit buildProgress( ++step, featureCount );
if ( feedback )
{
feedback->setProgress( 100.0 * static_cast< double >( ++step ) / featureCount );
}

}
// end: tie points to graph

Expand Down Expand Up @@ -274,6 +283,11 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
fit = mSource->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( la ) );
while ( fit.nextFeature( feature ) )
{
if ( feedback && feedback->isCanceled() )
{
return;
}

Direction directionType = mDefaultDirection;

// What direction have feature?
Expand Down Expand Up @@ -382,6 +396,10 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
isFirstPoint = false;
} // for (it = pl.begin(); it != pl.end(); ++it)
}
emit buildProgress( ++step, featureCount );
if ( feedback )
{
feedback->setProgress( 100.0 * static_cast< double >( ++step ) / featureCount );
}

} // while( mSource->nextFeature(feature) )
} // makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPointXY >& additionalPoints, QVector< QgsPointXY >& tiedPoint )
3 changes: 2 additions & 1 deletion src/analysis/network/qgsvectorlayerdirector.h
Expand Up @@ -74,7 +74,8 @@ class ANALYSIS_EXPORT QgsVectorLayerDirector : public QgsGraphDirector
*/
void makeGraph( QgsGraphBuilderInterface *builder,
const QVector< QgsPointXY > &additionalPoints,
QVector< QgsPointXY> &snappedPoints SIP_OUT ) const override;
QVector< QgsPointXY> &snappedPoints SIP_OUT,
QgsFeedback *feedback ) const override;

QString name() const override;

Expand Down

0 comments on commit f3d42a2

Please sign in to comment.