QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
QgsGraph Class Reference

Mathematical graph representation. More...

#include <qgsgraph.h>

Public Member Functions

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

Protected Attributes

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

Detailed Description

Mathematical graph representation.

Definition at line 133 of file qgsgraph.h.

Constructor & Destructor Documentation

◆ QgsGraph()

QgsGraph::QgsGraph ( )
default

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 357 of file qgsgraph.h.

◆ mGraphVertices

QHash<int, QgsGraphVertex> QgsGraph::mGraphVertices
protected

Graph vertices.

Definition at line 354 of file qgsgraph.h.


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