QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsgraph.h
Go to the documentation of this file.
1 /***************************************************************************
2  graph.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 modeling a mathematical graph.
18  * Vertex is identified by its geographic coordinates (but you can add two vertex
19  * with unique coordinate), no additional properties it can not be assigned.
20  * Count the number of properties not limited along the arc. Graph may
21  * be have incidence arcs.
22  *
23  * \file qgsgraph.h
24  */
25 
26 #ifndef QGSGRAPHH
27 #define QGSGRAPHH
28 
29 // QT4 includes
30 #include <QList>
31 #include <QVector>
32 #include <QVariant>
33 
34 // QGIS includes
35 #include "qgspoint.h"
36 
37 class QgsGraphVertex;
38 
44 class ANALYSIS_EXPORT QgsGraphArc
45 {
46  public:
47  QgsGraphArc();
48 
53  QVariant property( int propertyIndex ) const;
54 
58  QVector< QVariant > properties() const;
59 
63  int outVertex() const;
64 
68  int inVertex() const;
69 
70  private:
71 
72  QVector< QVariant > mProperties;
73 
74  int mOut;
75  int mIn;
76 
77  friend class QgsGraph;
78 };
79 
80 
81 typedef QList< int > QgsGraphArcIdList;
82 
88 class ANALYSIS_EXPORT QgsGraphVertex
89 {
90  public:
95 
100  QgsGraphVertex( const QgsPoint& point );
101 
105  QgsGraphArcIdList outArc() const;
106 
110  QgsGraphArcIdList inArc() const;
111 
115  QgsPoint point() const;
116 
117  private:
118  QgsPoint mCoordinate;
119  QgsGraphArcIdList mOutArc;
120  QgsGraphArcIdList mInArc;
121 
122  friend class QgsGraph;
123 };
124 
131 class ANALYSIS_EXPORT QgsGraph
132 {
133  public:
134  QgsGraph();
135 
136  ~QgsGraph();
137 
138  // begin graph constructing methods
142  int addVertex( const QgsPoint& pt );
143 
147  int addArc( int outVertexIdx, int inVertexIdx, const QVector< QVariant >& properties );
148 
152  int vertexCount() const;
153 
157  const QgsGraphVertex& vertex( int idx ) const;
158 
162  int arcCount() const;
163 
167  const QgsGraphArc& arc( int idx ) const;
168 
173  int findVertex( const QgsPoint& pt ) const;
174 
175  private:
176  QVector<QgsGraphVertex> mGraphVertexes;
177 
178  QVector<QgsGraphArc> mGraphArc;
179 };
180 
181 #endif //QGSGRAPHH