[network analysis] use QgsFeedback for progress reporting and

cancelation
This commit is contained in:
Alexander Bruy 2017-07-16 14:26:37 +03:00
parent 126a27425a
commit f3d42a2cda
6 changed files with 44 additions and 27 deletions

View File

@ -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}
----------

View File

@ -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.

View File

@ -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

View File

@ -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"
@ -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() { }
@ -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

View File

@ -27,7 +27,7 @@
#include "qgspoint.h"
#include "qgsgeometry.h"
#include "qgsdistancearea.h"
#include 'qgswkbtypes.h"
#include "qgswkbtypes.h"
#include <QString>
#include <QtAlgorithms>
@ -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;
@ -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();
@ -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
@ -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?
@ -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 )

View File

@ -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;