Skip to content
Permalink
Browse files
rename QgsStrategy to QgsNetworkStrategy to avoid possible future
confusion when we will have other stuff with strategies. Also
rename corresponding subclasses
  • Loading branch information
alexbruy committed Nov 21, 2016
1 parent f9be179 commit a61e8bbdec66e580d6dabac180022224f078af9f
@@ -54,9 +54,9 @@
%Include raster/qgstotalcurvaturefilter.sip

%Include network/qgsgraph.sip
%Include network/qgsstrategy.sip
%Include network/qgsspeedstrategy.sip
%Include network/qgsdistancestrategy.sip
%Include network/qgsnetworkstrategy.sip
%Include network/qgsnetworkspeedstrategy.sip
%Include network/qgsnetworkdistancestrategy.sip
%Include network/qgsgraphbuilderinterface.sip
%Include network/qgsgraphbuilder.sip
%Include network/qgsgraphdirector.sip
@@ -42,7 +42,7 @@ class QgsGraphDirector : QObject
QVector< QgsPoint > &snappedPoints /Out/ ) const;

//! Add optimization strategy
void addStrategy( QgsStrategy* prop /Transfer/);
void addStrategy( QgsNetworkStrategy* prop /Transfer/);

//! Returns director name
virtual QString name() const = 0;
@@ -1,7 +1,7 @@
class QgsDistanceStrategy : QgsStrategy
class QgsNetworkDistanceStrategy : QgsNetworkStrategy
{
%TypeHeaderCode
#include <qgsdistancestrategy.h>
#include <qgsnetworkdistancestrategy.h>
%End

public:
@@ -0,0 +1,13 @@
class QgsNetworkSpeedStrategy : QgsNetworkStrategy
{
%TypeHeaderCode
#include <qgsnetworkspeedstrategy.h>
%End

public:
QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor );

QVariant cost( double distance, const QgsFeature& f ) const;

QgsAttributeList requiredAttributes() const;
};
@@ -0,0 +1,50 @@
%ModuleHeaderCode
#include <qgsnetworkspeedstrategy.h>
#include <qgsnetworkdistancestrategy.h>
%End

/**
* \ingroup analysis
* \class QgsNetworkStrategy
* \brief QgsNetworkStrategy defines strategy used for calculation of the edge cost. For example it can
* take into account travel distance, amount of time or money. Currently there are two strategies
* implemented in the analysis library: QgsNetworkDistanceStrategy and QgsNetworkSpeedStrategy.
* QgsNetworkStrategy implemented using "strategy" design pattern.
*/
class QgsNetworkStrategy
{
%TypeHeaderCode
#include <qgsnetworkstrategy.h>
%End

%ConvertToSubClassCode
if ( dynamic_cast< QgsNetworkDistanceStrategy* > ( sipCpp ) != NULL )
sipType = sipType_QgsNetworkDistanceStrategy;
else if ( dynamic_cast< QgsNetworkSpeedStrategy* > ( sipCpp ) != NULL )
sipType = sipType_QgsNetworkSpeedStrategy;
else
sipType = NULL;
%End


public:

/**
* Default constructor
*/
QgsNetworkStrategy();

virtual ~QgsNetworkStrategy();

/**
* Returns list of the source layer attributes needed for cost calculation.
* This method called by QgsGraphDirector.
* \return list of required attributes
*/
virtual QgsAttributeList requiredAttributes() const;

/**
* Returns edge cost
*/
virtual QVariant cost( double distance, const QgsFeature &f ) const = 0;
};

This file was deleted.

This file was deleted.

@@ -49,8 +49,8 @@ SET(QGIS_ANALYSIS_SRCS

network/qgsgraph.cpp
network/qgsgraphbuilder.cpp
network/qgsspeedstrategy.cpp
network/qgsdistancestrategy.cpp
network/qgsnetworkspeedstrategy.cpp
network/qgsnetworkdistancestrategy.cpp
network/qgslinevectorlayerdirector.cpp
network/qgsgraphanalyzer.cpp
)
@@ -146,9 +146,9 @@ SET(QGIS_ANALYSIS_HDRS
network/qgsgraph.h
network/qgsgraphbuilderinterface.h
network/qgsgraphbuilder.h
network/qgsstrategy.h
network/qgsspeedstrategy.h
network/qgsdistancestrategy.h
network/qgsnetworkstrategy.h
network/qgsnetworkspeedstrategy.h
network/qgsnetworkdistancestrategy.h
network/qgsgraphdirector.h
network/qgslinevectorlayerdirector.h
network/qgsgraphanalyzer.h
@@ -21,7 +21,7 @@
#include <QList>

#include <qgspoint.h>
#include "qgsstrategy.h"
#include "qgsnetworkstrategy.h"

class QgsGraphBuilderInterface;

@@ -60,7 +60,7 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject
}

//! Add optimization strategy
void addStrategy( QgsStrategy* prop )
void addStrategy( QgsNetworkStrategy* prop )
{
mStrategies.push_back( prop );
}
@@ -69,7 +69,7 @@ class ANALYSIS_EXPORT QgsGraphDirector : public QObject
virtual QString name() const = 0;

protected:
QList<QgsStrategy*> mStrategies;
QList<QgsNetworkStrategy*> mStrategies;
};

#endif // QGSGRAPHDIRECTOR_H
@@ -253,7 +253,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
tmpAttr.push_back( mDirectionFieldId );
}

QList< QgsStrategy* >::const_iterator it;
QList< QgsNetworkStrategy* >::const_iterator it;
QgsAttributeList::const_iterator it2;

for ( it = mStrategies.begin(); it != mStrategies.end(); ++it )
@@ -366,7 +366,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
{
double distance = builder->distanceArea()->measureLine( pt1, pt2 );
QVector< QVariant > prop;
QList< QgsStrategy* >::const_iterator it;
QList< QgsNetworkStrategy* >::const_iterator it;
for ( it = mStrategies.begin(); it != mStrategies.end(); ++it )
{
prop.push_back(( *it )->cost( distance, feature ) );
@@ -13,9 +13,9 @@
* *
***************************************************************************/

#include "qgsdistancestrategy.h"
#include "qgsnetworkdistancestrategy.h"

QVariant QgsDistanceStrategy::cost( double distance, const QgsFeature& f ) const
QVariant QgsNetworkDistanceStrategy::cost( double distance, const QgsFeature& f ) const
{
Q_UNUSED( f );
return QVariant( distance );
@@ -1,5 +1,5 @@
/***************************************************************************
qgsdistancestrategy.h
qgsnetworkdistancestrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
@@ -13,21 +13,21 @@
* *
***************************************************************************/

#ifndef QGSDISTANCESTRATEGY_H
#define QGSDISTANCESTRATEGY_H
#ifndef QGSNETWORKDISTANCESTRATEGY_H
#define QGSNETWORKDISTANCESTRATEGY_H

#include <qgsstrategy.h>
#include <qgsnetworkstrategy.h>

/** \ingroup analysis
* \class QgsDistanceStrategy
* \class QgsNetworkDistanceStrategy
* \note added in QGIS 3.0
* \brief Strategy for caclucating edge cost based on its length. Should be
* \brief Strategy for caclulating edge cost based on its length. Should be
* used for finding shortest path between two points.
*/
class ANALYSIS_EXPORT QgsDistanceStrategy : public QgsStrategy
class ANALYSIS_EXPORT QgsNetworkDistanceStrategy : public QgsNetworkStrategy
{
public:
virtual QVariant cost( double distance, const QgsFeature& ) const override;
};

#endif // QGSDISTANCEARCPROPERTER_H
#endif // QGSNETWORKDISTANCESTRATEGY_H
@@ -13,16 +13,16 @@
* *
***************************************************************************/

#include "qgsspeedstrategy.h"
#include "qgsnetworkspeedstrategy.h"

QgsSpeedStrategy::QgsSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor )
QgsNetworkSpeedStrategy::QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor )
{
mAttributeId = attributeId;
mDefaultValue = defaultValue;
mToMetricFactor = toMetricFactor;
}

QVariant QgsSpeedStrategy::cost( double distance, const QgsFeature& f ) const
QVariant QgsNetworkSpeedStrategy::cost( double distance, const QgsFeature& f ) const
{
QgsAttributes attrs = f.attributes();

@@ -36,7 +36,7 @@ QVariant QgsSpeedStrategy::cost( double distance, const QgsFeature& f ) const
return QVariant( val );
}

QgsAttributeList QgsSpeedStrategy::requiredAttributes() const
QgsAttributeList QgsNetworkSpeedStrategy::requiredAttributes() const
{
QgsAttributeList l;
l.push_back( mAttributeId );
@@ -1,5 +1,5 @@
/***************************************************************************
qgsspeedstrategy.h
qgsnetworkspeedstrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
@@ -13,25 +13,25 @@
* *
***************************************************************************/

#ifndef QGSSPEEDSTRATEGY_H
#define QGSSPEEDSTRATEGY_H
#ifndef QGSNETWORKSPEEDSTRATEGY_H
#define QGSNETWORKSPEEDSTRATEGY_H

#include <qgsstrategy.h>
#include <qgsnetworkstrategy.h>

/** \ingroup analysis
* \class QgsSpeedStrategy
* \note added in QGIS 3.0
* \brief Strategy for caclucating edge cost based on travel time. Should be
* used for finding fastest path between two points.
*/
class ANALYSIS_EXPORT QgsSpeedStrategy : public QgsStrategy
class ANALYSIS_EXPORT QgsNetworkSpeedStrategy : public QgsNetworkStrategy
{
public:

/**
* Default constructor
*/
QgsSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor );
QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor );

//! Returns edge cost
QVariant cost( double distance, const QgsFeature& f ) const override;
@@ -49,4 +49,4 @@ class ANALYSIS_EXPORT QgsSpeedStrategy : public QgsStrategy

};

#endif // QGSSPEEDSTRATEGY_H
#endif // QGSNETWORKSPEEDSTRATEGY_H

0 comments on commit a61e8bb

Please sign in to comment.