QGIS API Documentation  3.37.0-Master (a5b4d9743e8)
Public Member Functions | Protected Attributes | List of all members
QgsGraph Class Reference

Mathematical graph representation. More...

#include <qgsgraph.h>

Public Member Functions

 QgsGraph ()=default
 Constructor for QgsGraph. More...
 
int addEdge (int fromVertexIdx, int toVertexIdx, const QVector< QVariant > &strategies)
 Add an edge to the graph, going from the fromVertexIdx to toVertexIdx. More...
 
int addVertex (const QgsPointXY &pt)
 Add a vertex to the graph. More...
 
const QgsGraphEdgeedge (int idx) const
 Returns the edge at the given index. More...
 
int edgeCount () const
 Returns number of graph edges. More...
 
int findOppositeEdge (int index) const
 Finds the first edge which is the opposite of the edge with the specified index. More...
 
int findVertex (const QgsPointXY &pt) const
 Find vertex by associated point. More...
 
bool hasEdge (int index) const
 Returns whether the edge of the given index exists. More...
 
bool hasVertex (int index) const
 Returns whether the vertex of the given index exists. More...
 
void removeEdge (int index)
 Removes the edge at specified index. More...
 
void removeVertex (int index)
 Removes the vertex at specified index. More...
 
const QgsGraphVertexvertex (int idx) const
 Returns the vertex at the given index. More...
 
int vertexCount () const
 Returns number of graph vertices. More...
 

Protected Attributes

QHash< int, QgsGraphEdgemGraphEdges
 Graph edges. More...
 
QHash< int, QgsGraphVertexmGraphVertices
 Graph vertices. More...
 

Detailed Description

Mathematical graph representation.

Definition at line 139 of file qgsgraph.h.

Constructor & Destructor Documentation

◆ QgsGraph()

QgsGraph::QgsGraph ( )
default

Constructor for QgsGraph.

Member Function Documentation

◆ addEdge()

int QgsGraph::addEdge ( int  fromVertexIdx,
int  toVertexIdx,
const QVector< QVariant > &  strategies 
)

Add an edge to the graph, going from the fromVertexIdx to toVertexIdx.

Definition at line 30 of file qgsgraph.cpp.

◆ addVertex()

int QgsGraph::addVertex ( const QgsPointXY pt)

Add a vertex to the graph.

Definition at line 24 of file qgsgraph.cpp.

◆ edge()

const QgsGraphEdge & QgsGraph::edge ( int  idx) const

Returns the edge at the given index.

Definition at line 76 of file qgsgraph.cpp.

◆ edgeCount()

int QgsGraph::edgeCount ( ) const

Returns number of graph edges.

Definition at line 120 of file qgsgraph.cpp.

◆ findOppositeEdge()

int QgsGraph::findOppositeEdge ( int  index) const

Finds the first edge which is the opposite of the edge with the specified index.

This represents the edge which has the same vertices as the specified edge, but the opposite direction in the graph.(I.e. the edge which starts at the "from" vertex of the specified edge and ends at the "to" vertex.)

Returns -1 if no opposite edge exists.

Since
QGIS 3.24

Definition at line 150 of file qgsgraph.cpp.

◆ findVertex()

int QgsGraph::findVertex ( const QgsPointXY pt) const

Find vertex by associated point.

Returns
vertex index

Definition at line 125 of file qgsgraph.cpp.

◆ hasEdge()

bool QgsGraph::hasEdge ( int  index) const

Returns whether the edge of the given index exists.

Since
QGIS 3.24

Definition at line 144 of file qgsgraph.cpp.

◆ hasVertex()

bool QgsGraph::hasVertex ( int  index) const

Returns whether the vertex of the given index exists.

Since
QGIS 3.24

Definition at line 138 of file qgsgraph.cpp.

◆ removeEdge()

void QgsGraph::removeEdge ( int  index)

Removes the edge at specified index.

The incoming and outgoing edges for all graph vertices will be updated accordingly. Vertices which no longer have any incoming or outgoing edges as a result will be removed from the graph automatically.

Since
QGIS 3.24

Definition at line 87 of file qgsgraph.cpp.

◆ removeVertex()

void QgsGraph::removeVertex ( int  index)

Removes the vertex at specified index.

All edges which are incoming or outgoing edges for the vertex will also be removed.

Since
QGIS 3.24

Definition at line 58 of file qgsgraph.cpp.

◆ vertex()

const QgsGraphVertex & QgsGraph::vertex ( int  idx) const

Returns the vertex at the given index.

Definition at line 47 of file qgsgraph.cpp.

◆ vertexCount()

int QgsGraph::vertexCount ( ) const

Returns number of graph vertices.

Definition at line 115 of file qgsgraph.cpp.

Member Data Documentation

◆ mGraphEdges

QHash<int, QgsGraphEdge> QgsGraph::mGraphEdges
protected

Graph edges.

Definition at line 366 of file qgsgraph.h.

◆ mGraphVertices

QHash<int, QgsGraphVertex> QgsGraph::mGraphVertices
protected

Graph vertices.

Definition at line 363 of file qgsgraph.h.


The documentation for this class was generated from the following files: