QGIS API Documentation  2.99.0-Master (9fdd060)
qgsgraph.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgraph.h
3  --------------------------------------
4  Date : 2011-04-01
5  Copyright : (C) 2010 by Yakushev Sergey
6  Email : YakushevS <at> list.ru
7 ****************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 /*
17  * This file describes the built-in QGIS classes for modeling a mathematical graph.
18  * Vertices are identified by their geographic coordinates and have no additional
19  * properties. Number of strategies for calculating edge cost is not limited.
20  * Graph may have incidence edges.
21  *
22  * \file qgsgraph.h
23  */
24 
25 #ifndef QGSGRAPH_H
26 #define QGSGRAPH_H
27 
28 #include <QList>
29 #include <QVector>
30 #include <QVariant>
31 
32 #include "qgspointxy.h"
33 #include "qgis_analysis.h"
34 
35 class QgsGraphVertex;
36 
43 class ANALYSIS_EXPORT QgsGraphEdge
44 {
45  public:
46 
50  QgsGraphEdge() = default;
51 
56  QVariant cost( int strategyIndex ) const;
57 
61  QVector< QVariant > strategies() const;
62 
66  int outVertex() const;
67 
71  int inVertex() const;
72 
73  private:
74 
75  QVector< QVariant > mStrategies;
76 
77  int mOut = 0;
78  int mIn = 0;
79 
80  friend class QgsGraph;
81 };
82 
83 
84 typedef QList< int > QgsGraphEdgeIds;
85 
91 class ANALYSIS_EXPORT QgsGraphVertex
92 {
93  public:
94 
99 
104  QgsGraphVertex( const QgsPointXY &point );
105 
109  QgsGraphEdgeIds outEdges() const;
110 
114  QgsGraphEdgeIds inEdges() const;
115 
119  QgsPointXY point() const;
120 
121  private:
122  QgsPointXY mCoordinate;
123  QgsGraphEdgeIds mOutEdges;
124  QgsGraphEdgeIds mInEdges;
125 
126  friend class QgsGraph;
127 };
128 
135 class ANALYSIS_EXPORT QgsGraph
136 {
137  public:
138 
142  QgsGraph() = default;
143 
144  // Graph constructing methods
145 
149  int addVertex( const QgsPointXY &pt );
150 
154  int addEdge( int outVertexIdx, int inVertexIdx, const QVector< QVariant > &strategies );
155 
159  int vertexCount() const;
160 
164  const QgsGraphVertex &vertex( int idx ) const;
165 
169  int edgeCount() const;
170 
174  const QgsGraphEdge &edge( int idx ) const;
175 
180  int findVertex( const QgsPointXY &pt ) const;
181 
182  private:
183  QVector<QgsGraphVertex> mGraphVertices;
184 
185  QVector<QgsGraphEdge> mGraphEdges;
186 };
187 
188 #endif // QGSGRAPH_H
A class to represent a 2D point.
Definition: qgspointxy.h:43
Mathematical graph representation.
Definition: qgsgraph.h:135
This class implements a graph vertex.
Definition: qgsgraph.h:91
QgsGraphVertex()
Default constructor.
Definition: qgsgraph.h:98
QList< int > QgsGraphEdgeIds
Definition: qgsgraph.h:84
This class implements a graph edge.
Definition: qgsgraph.h:43