Qt 4.8
Classes | Public Functions | Protected Functions | Properties | List of all members
Graph< Vertex, EdgeData > Class Template Reference

#include <qgraph_p.h>

Classes

class  const_iterator
 

Public Functions

QList< Vertex * > adjacentVertices (Vertex *vertex) const
 
QList< QPair< Vertex *, Vertex * > > connections () const
 
const_iterator constBegin () const
 
const_iterator constEnd () const
 
void createEdge (Vertex *first, Vertex *second, EdgeData *data)
 
EdgeData * edgeData (Vertex *first, Vertex *second)
 
 Graph ()
 
void removeEdge (Vertex *first, Vertex *second)
 
QString serializeToDot ()
 
EdgeData * takeEdge (Vertex *first, Vertex *second)
 
QSet< Vertex * > vertices () const
 

Protected Functions

void createDirectedEdge (Vertex *from, Vertex *to, EdgeData *data)
 
void removeDirectedEdge (Vertex *from, Vertex *to)
 

Properties

QHash< Vertex *, QHash< Vertex *, EdgeData * > * > m_graph
 

Detailed Description

template<typename Vertex, typename EdgeData>
class Graph< Vertex, EdgeData >

Definition at line 66 of file qgraph_p.h.

Constructors and Destructors

◆ Graph()

template<typename Vertex, typename EdgeData>
Graph< Vertex, EdgeData >::Graph ( )
inline

Definition at line 69 of file qgraph_p.h.

69 {}

Functions

◆ adjacentVertices()

template<typename Vertex, typename EdgeData>
QList<Vertex *> Graph< Vertex, EdgeData >::adjacentVertices ( Vertex *  vertex) const
inline

Definition at line 195 of file qgraph_p.h.

Referenced by QGraphicsAnchorLayoutPrivate::calculateVertexPositions(), QGraphicsAnchorLayoutPrivate::removeCenterAnchors(), QGraphicsAnchorLayoutPrivate::removeVertex(), QGraphicsAnchorLayoutPrivate::restoreVertices(), Graph< AnchorVertex, AnchorData >::serializeToDot(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), and QGraphicsAnchorLayoutPrivate::simplifyVertices().

196  {
199  if (row)
200  l = row->keys();
201  return l;
202  }
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QHash< Vertex *, QHash< Vertex *, EdgeData * > * > m_graph
Definition: qgraph_p.h:281
QFactoryLoader * l
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ connections()

template<typename Vertex, typename EdgeData>
QList<QPair<Vertex*, Vertex*> > Graph< Vertex, EdgeData >::connections ( ) const
inline

Definition at line 212 of file qgraph_p.h.

Referenced by QGraphicsAnchorLayoutPrivate::refreshAllSizeHints(), QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(), and QGraphicsAnchorLayoutPrivate::updateAnchorSizes().

212  {
214  for (const_iterator it = constBegin(); it != constEnd(); ++it) {
215  Vertex *from = it.from();
216  Vertex *to = it.to();
217  // do not return (from,to) *and* (to,from)
218  if (from < to) {
219  conns.append(qMakePair(from, to));
220  }
221  }
222  return conns;
223  }
#define it(className, varName)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
const_iterator constBegin() const
Definition: qgraph_p.h:128
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Definition: qgraph_p.h:132

◆ constBegin()

template<typename Vertex, typename EdgeData>
const_iterator Graph< Vertex, EdgeData >::constBegin ( ) const
inline

Definition at line 128 of file qgraph_p.h.

Referenced by Graph< AnchorVertex, AnchorData >::connections(), and Graph< AnchorVertex, AnchorData >::vertices().

128  {
129  return const_iterator(this,true);
130  }

◆ constEnd()

template<typename Vertex, typename EdgeData>
const_iterator Graph< Vertex, EdgeData >::constEnd ( ) const
inline

Definition at line 132 of file qgraph_p.h.

Referenced by Graph< AnchorVertex, AnchorData >::connections(), and Graph< AnchorVertex, AnchorData >::vertices().

132  {
133  return const_iterator(this,false);
134  }

◆ createDirectedEdge()

template<typename Vertex, typename EdgeData>
void Graph< Vertex, EdgeData >::createDirectedEdge ( Vertex *  from,
Vertex *  to,
EdgeData *  data 
)
inlineprotected

Definition at line 257 of file qgraph_p.h.

Referenced by Graph< AnchorVertex, AnchorData >::createEdge().

258  {
259  QHash<Vertex *, EdgeData *> *adjacentToFirst = m_graph.value(from);
260  if (!adjacentToFirst) {
261  adjacentToFirst = new QHash<Vertex *, EdgeData *>();
262  m_graph.insert(from, adjacentToFirst);
263  }
264  adjacentToFirst->insert(to, data);
265  }
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QHash< Vertex *, QHash< Vertex *, EdgeData * > * > m_graph
Definition: qgraph_p.h:281
static const char * data(const QByteArray &arr)

◆ createEdge()

template<typename Vertex, typename EdgeData>
void Graph< Vertex, EdgeData >::createEdge ( Vertex *  first,
Vertex *  second,
EdgeData *  data 
)
inline

Definition at line 148 of file qgraph_p.h.

Referenced by QGraphicsAnchorLayoutPrivate::addAnchor_helper(), QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(), QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(), and QGraphicsAnchorLayoutPrivate::restoreVertices().

149  {
150  // Creates a bidirectional edge
151 #if defined(QT_DEBUG) && 0
152  qDebug("Graph::createEdge(): %s",
154  .arg(first->toString()).arg(second->toString())));
155 #endif
156  if (edgeData(first, second)) {
157 #ifdef QT_DEBUG
158  qWarning("%s-%s already has an edge", qPrintable(first->toString()), qPrintable(second->toString()));
159 #endif
160  }
161  createDirectedEdge(first, second, data);
162  createDirectedEdge(second, first, data);
163  }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
EdgeData * edgeData(Vertex *first, Vertex *second)
Definition: qgraph_p.h:143
Q_CORE_EXPORT void qDebug(const char *,...)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
#define qPrintable(string)
Definition: qglobal.h:1750
void createDirectedEdge(Vertex *from, Vertex *to, EdgeData *data)
Definition: qgraph_p.h:257

◆ edgeData()

template<typename Vertex, typename EdgeData>
EdgeData* Graph< Vertex, EdgeData >::edgeData ( Vertex *  first,
Vertex *  second 
)
inline
Warning
This function is not part of the public interface.

If there is an edge between first and second, it will return a structure containing the data associated with the edge, otherwise it will return 0.

Definition at line 143 of file qgraph_p.h.

Referenced by QGraphicsAnchorLayoutPrivate::calculateVertexPositions(), QGraphicsAnchorLayoutPrivate::constraintsFromSizeHints(), Graph< AnchorVertex, AnchorData >::createEdge(), QGraphicsAnchorLayoutPrivate::findPaths(), QGraphicsAnchorLayoutPrivate::getAnchor(), QGraphicsAnchorLayoutPrivate::getGraphParts(), QGraphicsAnchorLayoutPrivate::refreshAllSizeHints(), QGraphicsAnchorLayoutPrivate::removeCenterAnchors(), QGraphicsAnchorLayoutPrivate::removeCenterConstraints(), Graph< AnchorVertex, AnchorData >::removeEdge(), QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(), Graph< AnchorVertex, AnchorData >::serializeToDot(), QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(), QGraphicsAnchorLayoutPrivate::simplifyVertices(), Graph< AnchorVertex, AnchorData >::takeEdge(), and QGraphicsAnchorLayoutPrivate::updateAnchorSizes().

143  {
145  return row ? row->value(second) : 0;
146  }
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QHash< Vertex *, QHash< Vertex *, EdgeData * > * > m_graph
Definition: qgraph_p.h:281

◆ removeDirectedEdge()

template<typename Vertex, typename EdgeData>
void Graph< Vertex, EdgeData >::removeDirectedEdge ( Vertex *  from,
Vertex *  to 
)
inlineprotected

Definition at line 267 of file qgraph_p.h.

Referenced by Graph< AnchorVertex, AnchorData >::removeEdge(), and Graph< AnchorVertex, AnchorData >::takeEdge().

268  {
269  QHash<Vertex *, EdgeData *> *adjacentToFirst = m_graph.value(from);
270  Q_ASSERT(adjacentToFirst);
271 
272  adjacentToFirst->remove(to);
273  if (adjacentToFirst->isEmpty()) {
274  //nobody point to 'from' so we can remove it from the graph
275  m_graph.remove(from);
276  delete adjacentToFirst;
277  }
278  }
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QHash< Vertex *, QHash< Vertex *, EdgeData * > * > m_graph
Definition: qgraph_p.h:281
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297

◆ removeEdge()

template<typename Vertex, typename EdgeData>
void Graph< Vertex, EdgeData >::removeEdge ( Vertex *  first,
Vertex *  second 
)
inline

Definition at line 165 of file qgraph_p.h.

Referenced by QGraphicsAnchorLayoutPrivate::removeAnchor_helper(), and QGraphicsAnchorLayoutPrivate::removeVertex().

166  {
167  // Removes a bidirectional edge
168 #if defined(QT_DEBUG) && 0
169  qDebug("Graph::removeEdge(): %s",
171  .arg(first->toString()).arg(second->toString())));
172 #endif
173  EdgeData *data = edgeData(first, second);
174  removeDirectedEdge(first, second);
175  removeDirectedEdge(second, first);
176  if (data) delete data;
177  }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
EdgeData * edgeData(Vertex *first, Vertex *second)
Definition: qgraph_p.h:143
Q_CORE_EXPORT void qDebug(const char *,...)
static const char * data(const QByteArray &arr)
void removeDirectedEdge(Vertex *from, Vertex *to)
Definition: qgraph_p.h:267
#define qPrintable(string)
Definition: qglobal.h:1750

◆ serializeToDot()

template<typename Vertex, typename EdgeData>
QString Graph< Vertex, EdgeData >::serializeToDot ( )
inline

Definition at line 226 of file qgraph_p.h.

Referenced by QGraphicsAnchorLayoutPrivate::dumpGraph().

226  { // traversal
227  QString strVertices;
228  QString edges;
229 
230  QSet<Vertex *> setOfVertices = vertices();
231  for (Q_TYPENAME QSet<Vertex*>::const_iterator it = setOfVertices.begin(); it != setOfVertices.end(); ++it) {
232  Vertex *v = *it;
233  QList<Vertex*> adjacents = adjacentVertices(v);
234  for (int i = 0; i < adjacents.count(); ++i) {
235  Vertex *v1 = adjacents.at(i);
236  EdgeData *data = edgeData(v, v1);
237  bool forward = data->from == v;
238  if (forward) {
239  edges += QString::fromAscii("\"%1\"->\"%2\" [label=\"[%3,%4,%5,%6,%7]\" color=\"#000000\"] \n")
240  .arg(v->toString())
241  .arg(v1->toString())
242  .arg(data->minSize)
243  .arg(data->minPrefSize)
244  .arg(data->prefSize)
245  .arg(data->maxPrefSize)
246  .arg(data->maxSize)
247  ;
248  }
249  }
250  strVertices += QString::fromAscii("\"%1\" [label=\"%2\"]\n").arg(v->toString()).arg(v->toString());
251  }
252  return QString::fromAscii("%1\n%2\n").arg(strVertices).arg(edges);
253  }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
#define it(className, varName)
QSet< Vertex * > vertices() const
Definition: qgraph_p.h:204
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
EdgeData * edgeData(Vertex *first, Vertex *second)
Definition: qgraph_p.h:143
iterator begin()
Definition: qset.h:166
#define Q_TYPENAME
Definition: qglobal.h:1717
QList< Vertex * > adjacentVertices(Vertex *vertex) const
Definition: qgraph_p.h:195
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
iterator end()
Definition: qset.h:169
static const char * data(const QByteArray &arr)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ takeEdge()

template<typename Vertex, typename EdgeData>
EdgeData* Graph< Vertex, EdgeData >::takeEdge ( Vertex *  first,
Vertex *  second 
)
inline

Definition at line 179 of file qgraph_p.h.

Referenced by QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(), createSequence(), QGraphicsAnchorLayoutPrivate::replaceVertex(), QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(), QGraphicsAnchorLayoutPrivate::restoreVertices(), and QGraphicsAnchorLayoutPrivate::simplifyVertices().

180  {
181 #if defined(QT_DEBUG) && 0
182  qDebug("Graph::takeEdge(): %s",
184  .arg(first->toString()).arg(second->toString())));
185 #endif
186  // Removes a bidirectional edge
187  EdgeData *data = edgeData(first, second);
188  if (data) {
189  removeDirectedEdge(first, second);
190  removeDirectedEdge(second, first);
191  }
192  return data;
193  }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
EdgeData * edgeData(Vertex *first, Vertex *second)
Definition: qgraph_p.h:143
Q_CORE_EXPORT void qDebug(const char *,...)
static const char * data(const QByteArray &arr)
void removeDirectedEdge(Vertex *from, Vertex *to)
Definition: qgraph_p.h:267
#define qPrintable(string)
Definition: qglobal.h:1750

◆ vertices()

template<typename Vertex, typename EdgeData>
QSet<Vertex*> Graph< Vertex, EdgeData >::vertices ( ) const
inline

Definition at line 204 of file qgraph_p.h.

Referenced by Graph< AnchorVertex, AnchorData >::serializeToDot().

204  {
205  QSet<Vertex *> setOfVertices;
206  for (const_iterator it = constBegin(); it != constEnd(); ++it) {
207  setOfVertices.insert(*it);
208  }
209  return setOfVertices;
210  }
#define it(className, varName)
const_iterator insert(const T &value)
Definition: qset.h:179
const_iterator constBegin() const
Definition: qgraph_p.h:128
const_iterator constEnd() const
Definition: qgraph_p.h:132

Properties

◆ m_graph

template<typename Vertex, typename EdgeData>
QHash<Vertex *, QHash<Vertex *, EdgeData *> *> Graph< Vertex, EdgeData >::m_graph
private

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