| 
    QGIS API Documentation
    3.26.3-Buenos Aires (65e4edfdad)
    
   | 
 
 
 
 
Go to the documentation of this file.
   27   return mNextVertexId++;
 
   30 int QgsGraph::addEdge( 
int fromVertexIdx, 
int toVertexIdx, 
const QVector< QVariant > &strategies )
 
   34   e.mStrategies = strategies;
 
   35   e.mToIdx = toVertexIdx;
 
   36   e.mFromIdx  = fromVertexIdx;
 
   42   mGraphVertices[ fromVertexIdx ].mOutgoingEdges.push_back( edgeIdx );
 
   51     return ( it ).value();
 
   52   Q_ASSERT_X( 
false, 
"QgsGraph::vertex()", 
"Invalid vertex ID" );
 
   55   return ( *
const_cast< QHash<int, QgsGraphVertex>* 
>( &
mGraphVertices ) )[ idx ];
 
   63     QSet< int > affectedEdges = qgis::listToSet( it->incomingEdges() );
 
   64     affectedEdges.unite( qgis::listToSet( it->outgoingEdges() ) );
 
   69     for ( 
int edgeId : std::as_const( affectedEdges ) )
 
   80     return ( it ).value();
 
   81   Q_ASSERT_X( 
false, 
"QgsGraph::edge()", 
"Invalid edge ID" );
 
   84   return ( *
const_cast< QHash<int, QgsGraphEdge>* 
>( &
mGraphEdges ) )[ idx ];
 
   92     const int fromVertex = it->fromVertex();
 
   93     const int toVertex = it->toVertex();
 
  100       vertexIt->mOutgoingEdges.removeAll( index );
 
  101       if ( vertexIt->mOutgoingEdges.empty() && vertexIt->mIncomingEdges.empty() )
 
  108       vertexIt->mIncomingEdges.removeAll( index );
 
  109       if ( vertexIt->mOutgoingEdges.empty() && vertexIt->mIncomingEdges.empty() )
 
  155     const int fromVertex = it->fromVertex();
 
  156     const int toVertex = it->toVertex();
 
  160     for ( 
int candidate : candidates )
 
  162       if ( 
mGraphEdges.value( candidate ).toVertex() == fromVertex )
 
  171   return mStrategies[ i ];
 
  190   : mCoordinate( point )
 
  197   return mIncomingEdges;
 
  202   return mOutgoingEdges;
 
  
QgsGraphEdgeIds outgoingEdges() const
Returns outgoing edge ids, i.e.
 
QgsPointXY point() const
Returns point associated with graph vertex.
 
This class implements a graph edge.
 
This class implements a graph vertex.
 
QHash< int, QgsGraphVertex > mGraphVertices
Graph vertices.
 
int addVertex(const QgsPointXY &pt)
Add a vertex to the graph.
 
QVector< QVariant > strategies() const
Returns array of available strategies.
 
int edgeCount() const
Returns number of graph edges.
 
int fromVertex() const
Returns the index of the vertex at the start of this edge.
 
const QgsGraphVertex & vertex(int idx) const
Returns the vertex at the given index.
 
QList< int > QgsGraphEdgeIds
 
bool hasVertex(int index) const
Returns whether the vertex of the given index exists.
 
const QgsGraphEdge & edge(int idx) const
Returns the edge at the given index.
 
QVariant cost(int strategyIndex) const
Returns edge cost calculated using specified strategy.
 
int toVertex() const
Returns the index of the vertex at the end of this edge.
 
int findVertex(const QgsPointXY &pt) const
Find vertex by associated point.
 
int findOppositeEdge(int index) const
Finds the first edge which is the opposite of the edge with the specified index.
 
QHash< int, QgsGraphEdge > mGraphEdges
Graph edges.
 
int vertexCount() const
Returns number of graph vertices.
 
A class to represent a 2D point.
 
void removeEdge(int index)
Removes the edge at specified index.
 
int addEdge(int fromVertexIdx, int toVertexIdx, const QVector< QVariant > &strategies)
Add an edge to the graph, going from the fromVertexIdx to toVertexIdx.
 
void removeVertex(int index)
Removes the vertex at specified index.
 
QgsGraphEdgeIds incomingEdges() const
Returns the incoming edge ids, i.e.
 
bool hasEdge(int index) const
Returns whether the edge of the given index exists.
 
QgsGraphVertex()=default
Default constructor.