Skip to content

Commit a61e8bb

Browse files
committed
rename QgsStrategy to QgsNetworkStrategy to avoid possible future
confusion when we will have other stuff with strategies. Also rename corresponding subclasses
1 parent f9be179 commit a61e8bb

16 files changed

+116
-116
lines changed

python/analysis/analysis.sip

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
%Include raster/qgstotalcurvaturefilter.sip
5555

5656
%Include network/qgsgraph.sip
57-
%Include network/qgsstrategy.sip
58-
%Include network/qgsspeedstrategy.sip
59-
%Include network/qgsdistancestrategy.sip
57+
%Include network/qgsnetworkstrategy.sip
58+
%Include network/qgsnetworkspeedstrategy.sip
59+
%Include network/qgsnetworkdistancestrategy.sip
6060
%Include network/qgsgraphbuilderinterface.sip
6161
%Include network/qgsgraphbuilder.sip
6262
%Include network/qgsgraphdirector.sip

python/analysis/network/qgsgraphdirector.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class QgsGraphDirector : QObject
4242
QVector< QgsPoint > &snappedPoints /Out/ ) const;
4343

4444
//! Add optimization strategy
45-
void addStrategy( QgsStrategy* prop /Transfer/);
45+
void addStrategy( QgsNetworkStrategy* prop /Transfer/);
4646

4747
//! Returns director name
4848
virtual QString name() const = 0;

python/analysis/network/qgsdistancestrategy.sip renamed to python/analysis/network/qgsnetworkdistancestrategy.sip

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
class QgsDistanceStrategy : QgsStrategy
1+
class QgsNetworkDistanceStrategy : QgsNetworkStrategy
22
{
33
%TypeHeaderCode
4-
#include <qgsdistancestrategy.h>
4+
#include <qgsnetworkdistancestrategy.h>
55
%End
66

77
public:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class QgsNetworkSpeedStrategy : QgsNetworkStrategy
2+
{
3+
%TypeHeaderCode
4+
#include <qgsnetworkspeedstrategy.h>
5+
%End
6+
7+
public:
8+
QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor );
9+
10+
QVariant cost( double distance, const QgsFeature& f ) const;
11+
12+
QgsAttributeList requiredAttributes() const;
13+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
%ModuleHeaderCode
2+
#include <qgsnetworkspeedstrategy.h>
3+
#include <qgsnetworkdistancestrategy.h>
4+
%End
5+
6+
/**
7+
* \ingroup analysis
8+
* \class QgsNetworkStrategy
9+
* \brief QgsNetworkStrategy defines strategy used for calculation of the edge cost. For example it can
10+
* take into account travel distance, amount of time or money. Currently there are two strategies
11+
* implemented in the analysis library: QgsNetworkDistanceStrategy and QgsNetworkSpeedStrategy.
12+
* QgsNetworkStrategy implemented using "strategy" design pattern.
13+
*/
14+
class QgsNetworkStrategy
15+
{
16+
%TypeHeaderCode
17+
#include <qgsnetworkstrategy.h>
18+
%End
19+
20+
%ConvertToSubClassCode
21+
if ( dynamic_cast< QgsNetworkDistanceStrategy* > ( sipCpp ) != NULL )
22+
sipType = sipType_QgsNetworkDistanceStrategy;
23+
else if ( dynamic_cast< QgsNetworkSpeedStrategy* > ( sipCpp ) != NULL )
24+
sipType = sipType_QgsNetworkSpeedStrategy;
25+
else
26+
sipType = NULL;
27+
%End
28+
29+
30+
public:
31+
32+
/**
33+
* Default constructor
34+
*/
35+
QgsNetworkStrategy();
36+
37+
virtual ~QgsNetworkStrategy();
38+
39+
/**
40+
* Returns list of the source layer attributes needed for cost calculation.
41+
* This method called by QgsGraphDirector.
42+
* \return list of required attributes
43+
*/
44+
virtual QgsAttributeList requiredAttributes() const;
45+
46+
/**
47+
* Returns edge cost
48+
*/
49+
virtual QVariant cost( double distance, const QgsFeature &f ) const = 0;
50+
};

python/analysis/network/qgsspeedstrategy.sip

-13
This file was deleted.

python/analysis/network/qgsstrategy.sip

-50
This file was deleted.

src/analysis/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ SET(QGIS_ANALYSIS_SRCS
4949

5050
network/qgsgraph.cpp
5151
network/qgsgraphbuilder.cpp
52-
network/qgsspeedstrategy.cpp
53-
network/qgsdistancestrategy.cpp
52+
network/qgsnetworkspeedstrategy.cpp
53+
network/qgsnetworkdistancestrategy.cpp
5454
network/qgslinevectorlayerdirector.cpp
5555
network/qgsgraphanalyzer.cpp
5656
)
@@ -146,9 +146,9 @@ SET(QGIS_ANALYSIS_HDRS
146146
network/qgsgraph.h
147147
network/qgsgraphbuilderinterface.h
148148
network/qgsgraphbuilder.h
149-
network/qgsstrategy.h
150-
network/qgsspeedstrategy.h
151-
network/qgsdistancestrategy.h
149+
network/qgsnetworkstrategy.h
150+
network/qgsnetworkspeedstrategy.h
151+
network/qgsnetworkdistancestrategy.h
152152
network/qgsgraphdirector.h
153153
network/qgslinevectorlayerdirector.h
154154
network/qgsgraphanalyzer.h

src/analysis/network/qgsgraphdirector.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <QList>
2222

2323
#include <qgspoint.h>
24-
#include "qgsstrategy.h"
24+
#include "qgsnetworkstrategy.h"
2525

2626
class QgsGraphBuilderInterface;
2727

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

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

7171
protected:
72-
QList<QgsStrategy*> mStrategies;
72+
QList<QgsNetworkStrategy*> mStrategies;
7373
};
7474

7575
#endif // QGSGRAPHDIRECTOR_H

src/analysis/network/qgslinevectorlayerdirector.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
253253
tmpAttr.push_back( mDirectionFieldId );
254254
}
255255

256-
QList< QgsStrategy* >::const_iterator it;
256+
QList< QgsNetworkStrategy* >::const_iterator it;
257257
QgsAttributeList::const_iterator it2;
258258

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

src/analysis/network/qgsdistancestrategy.cpp renamed to src/analysis/network/qgsnetworkdistancestrategy.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* *
1414
***************************************************************************/
1515

16-
#include "qgsdistancestrategy.h"
16+
#include "qgsnetworkdistancestrategy.h"
1717

18-
QVariant QgsDistanceStrategy::cost( double distance, const QgsFeature& f ) const
18+
QVariant QgsNetworkDistanceStrategy::cost( double distance, const QgsFeature& f ) const
1919
{
2020
Q_UNUSED( f );
2121
return QVariant( distance );
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgsdistancestrategy.h
2+
qgsnetworkdistancestrategy.h
33
--------------------------------------
44
Date : 2011-04-01
55
Copyright : (C) 2010 by Yakushev Sergey
@@ -13,21 +13,21 @@
1313
* *
1414
***************************************************************************/
1515

16-
#ifndef QGSDISTANCESTRATEGY_H
17-
#define QGSDISTANCESTRATEGY_H
16+
#ifndef QGSNETWORKDISTANCESTRATEGY_H
17+
#define QGSNETWORKDISTANCESTRATEGY_H
1818

19-
#include <qgsstrategy.h>
19+
#include <qgsnetworkstrategy.h>
2020

2121
/** \ingroup analysis
22-
* \class QgsDistanceStrategy
22+
* \class QgsNetworkDistanceStrategy
2323
* \note added in QGIS 3.0
24-
* \brief Strategy for caclucating edge cost based on its length. Should be
24+
* \brief Strategy for caclulating edge cost based on its length. Should be
2525
* used for finding shortest path between two points.
2626
*/
27-
class ANALYSIS_EXPORT QgsDistanceStrategy : public QgsStrategy
27+
class ANALYSIS_EXPORT QgsNetworkDistanceStrategy : public QgsNetworkStrategy
2828
{
2929
public:
3030
virtual QVariant cost( double distance, const QgsFeature& ) const override;
3131
};
3232

33-
#endif // QGSDISTANCEARCPROPERTER_H
33+
#endif // QGSNETWORKDISTANCESTRATEGY_H

src/analysis/network/qgsspeedstrategy.cpp renamed to src/analysis/network/qgsnetworkspeedstrategy.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
* *
1414
***************************************************************************/
1515

16-
#include "qgsspeedstrategy.h"
16+
#include "qgsnetworkspeedstrategy.h"
1717

18-
QgsSpeedStrategy::QgsSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor )
18+
QgsNetworkSpeedStrategy::QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor )
1919
{
2020
mAttributeId = attributeId;
2121
mDefaultValue = defaultValue;
2222
mToMetricFactor = toMetricFactor;
2323
}
2424

25-
QVariant QgsSpeedStrategy::cost( double distance, const QgsFeature& f ) const
25+
QVariant QgsNetworkSpeedStrategy::cost( double distance, const QgsFeature& f ) const
2626
{
2727
QgsAttributes attrs = f.attributes();
2828

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

39-
QgsAttributeList QgsSpeedStrategy::requiredAttributes() const
39+
QgsAttributeList QgsNetworkSpeedStrategy::requiredAttributes() const
4040
{
4141
QgsAttributeList l;
4242
l.push_back( mAttributeId );

src/analysis/network/qgsspeedstrategy.h renamed to src/analysis/network/qgsnetworkspeedstrategy.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgsspeedstrategy.h
2+
qgsnetworkspeedstrategy.h
33
--------------------------------------
44
Date : 2011-04-01
55
Copyright : (C) 2010 by Yakushev Sergey
@@ -13,25 +13,25 @@
1313
* *
1414
***************************************************************************/
1515

16-
#ifndef QGSSPEEDSTRATEGY_H
17-
#define QGSSPEEDSTRATEGY_H
16+
#ifndef QGSNETWORKSPEEDSTRATEGY_H
17+
#define QGSNETWORKSPEEDSTRATEGY_H
1818

19-
#include <qgsstrategy.h>
19+
#include <qgsnetworkstrategy.h>
2020

2121
/** \ingroup analysis
2222
* \class QgsSpeedStrategy
2323
* \note added in QGIS 3.0
2424
* \brief Strategy for caclucating edge cost based on travel time. Should be
2525
* used for finding fastest path between two points.
2626
*/
27-
class ANALYSIS_EXPORT QgsSpeedStrategy : public QgsStrategy
27+
class ANALYSIS_EXPORT QgsNetworkSpeedStrategy : public QgsNetworkStrategy
2828
{
2929
public:
3030

3131
/**
3232
* Default constructor
3333
*/
34-
QgsSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor );
34+
QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor );
3535

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

5050
};
5151

52-
#endif // QGSSPEEDSTRATEGY_H
52+
#endif // QGSNETWORKSPEEDSTRATEGY_H

0 commit comments

Comments
 (0)