Skip to content

Commit

Permalink
rename QgsStrategy to QgsNetworkStrategy to avoid possible future
Browse files Browse the repository at this point in the history
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 a61e8bb
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 116 deletions.
6 changes: 3 additions & 3 deletions python/analysis/analysis.sip
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/analysis/network/qgsgraphdirector.sip
Expand Up @@ -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;
Expand Down
@@ -1,7 +1,7 @@
class QgsDistanceStrategy : QgsStrategy
class QgsNetworkDistanceStrategy : QgsNetworkStrategy
{
%TypeHeaderCode
#include <qgsdistancestrategy.h>
#include <qgsnetworkdistancestrategy.h>
%End

public:
Expand Down
13 changes: 13 additions & 0 deletions python/analysis/network/qgsnetworkspeedstrategy.sip
@@ -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;
};
50 changes: 50 additions & 0 deletions python/analysis/network/qgsnetworkstrategy.sip
@@ -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;
};
13 changes: 0 additions & 13 deletions python/analysis/network/qgsspeedstrategy.sip

This file was deleted.

50 changes: 0 additions & 50 deletions python/analysis/network/qgsstrategy.sip

This file was deleted.

10 changes: 5 additions & 5 deletions src/analysis/CMakeLists.txt
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/network/qgsgraphdirector.h
Expand Up @@ -21,7 +21,7 @@
#include <QList>

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

class QgsGraphBuilderInterface;

Expand Down Expand Up @@ -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 );
}
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/analysis/network/qgslinevectorlayerdirector.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ) );
Expand Down
Expand Up @@ -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 );
Expand Down
@@ -1,5 +1,5 @@
/***************************************************************************
qgsdistancestrategy.h
qgsnetworkdistancestrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
Expand All @@ -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
Expand Up @@ -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();

Expand All @@ -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 );
Expand Down
@@ -1,5 +1,5 @@
/***************************************************************************
qgsspeedstrategy.h
qgsnetworkspeedstrategy.h
--------------------------------------
Date : 2011-04-01
Copyright : (C) 2010 by Yakushev Sergey
Expand All @@ -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;
Expand All @@ -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.