The ObserverDotWriter class generate dot scripts to create dot
graphs for an observer tree.
More...
#include <ObserverDotWriter.h>
Public Member Functions | |
bool | addEdgeAttribute (Observer *parent, QObject *child, const QString &attribute, const QString &value) |
Adds an edge attribute between two nodes in the graph. | |
bool | addGraphAttribute (const QString &attribute, const QString &value) |
Adds a node attribute to a node in the graph. | |
bool | addNodeAttribute (QObject *node, const QString &attribute, const QString &value) |
Adds a node attribute to a node in the graph. | |
QHash< QByteArray, QString > | edgeAttributes (Observer *parent, QObject *child) const |
Returns a list of all attributes on a node in the graph. | |
QString | generateDotScript () const |
Function which will generate the dot script for the specified observer context. | |
QHash< QString, QString > | graphAttributes () const |
Returns a list of all attributes on a node in the graph. | |
QHash< QByteArray, QString > | nodeAttributes (QObject *node) const |
Returns a list of all attributes on a node in the graph. | |
Observer * | observerContext () const |
Gets a pointer to the observer context. | |
ObserverDotWriter (Observer *observer=0) | |
Default constructor. | |
ObserverDotWriter (const ObserverDotWriter &other) | |
Copy constructor. | |
ObserverDotWriter & | operator= (const ObserverDotWriter &other) |
Overloaded = operator. | |
bool | removeEdgeAttribute (Observer *parent, QObject *child, const QString &attribute) |
Removes a node attribute from a node in the graph. | |
bool | removeGraphAttribute (const QString &attribute) |
Removes a node attribute from a node in the graph. | |
bool | removeNodeAttribute (QObject *node, const QString &attribute) |
Removes a node attribute from a node in the graph. | |
virtual bool | saveToFile (const QString &fileName) const |
Saves the dot script to a file. | |
bool | setObserverContext (Observer *observer) |
Sets the observer context. | |
virtual | ~ObserverDotWriter () |
Destructor. |
The ObserverDotWriter class generate dot scripts to create dot
graphs for an observer tree.
The ObserverDotWriter class is used to generate scripts in the dot
language which can be parsed by a number of program to create dot
graphs. For an overview of the dot
language, a good place to start is The Dot Guide. To find software which can generate graphs from dot
scripts, a good place to start is Graphviz.
To create a dot
script for an observer tree is easy. For example:
The resulting dot
script looks like this:
Next we can run the script using the Gvedit
application found in the GraphViz
distribution to create graph. Different layout engines are available for the scripts created by ObserverDotWriter and here we will only show a couple of them. First the output of the dot
layout engine is shown:
Next the output of the circo
layout engine is shown:
Since tree items can be attached to multiple nodes, it is possible to create more complex graphs easily as well. Lets look at an example:
The resulting dot
script looks like this:
The graph produced by the dot
layout engine is shown below:
The same graph produced by the twopi
layout engine is shown below:
The ObserverDotWriter class allows complete customization of the graph it creates. Before looking at the different ways to customize a graph, a short overview of the parts of the graph to which properties can be applied must be given.
The properties that can be applied to each of these are detailed in the The Dot Guide and will not be repeated here. For all properties the defaults of the dot
language is used since ObserverDotWriter does not add them to the script if they are not specified.
It is possible to add any graph attribute specified in the dot language to a your graph. For example:
The resulting dot
script looks like this:
It is possible to add any node attribute specified in the dot language to a node in your graph. For example:
The resulting dot
script looks like this:
It is possible to add any edge attribute specified in the dot language between two nodes in your graph. For example:
The resulting dot
script looks like this:
Note the needed extra "
characters for the label
attribute.
Combining all of the different attributes that we've set above, we get a graph like this:
This class was added in Qtilities v1.0.
Qtilities::Core::ObserverDotWriter::ObserverDotWriter | ( | Observer * | observer = 0 | ) |
Default constructor.
observer | The observer for which the script must be generated. The observer will also become the parent of this class. |
bool Qtilities::Core::ObserverDotWriter::addEdgeAttribute | ( | Observer * | parent, |
QObject * | child, | ||
const QString & | attribute, | ||
const QString & | value | ||
) |
Adds an edge attribute between two nodes in the graph.
See The Dot Guide for a list of possible edge attributes. Overwrites existing attribute with the same name if it exists. If either of the nodes you specify are not part of the top level observer tree (see observerContext()) then this function will fail and return false.
parent | A pointer to the parent observer. |
child | The child underneath the parent observer. |
attribute | The name of the attribute to be added. |
value | The value of the attribute. |
bool Qtilities::Core::ObserverDotWriter::addGraphAttribute | ( | const QString & | attribute, |
const QString & | value | ||
) |
Adds a node attribute to a node in the graph.
See The Dot Guide for a list of possible graph attributes. Overwrites existing attribute with the same name if it exists.
attribute | The name of the attribute to be added. |
value | The value of the attribute. |
bool Qtilities::Core::ObserverDotWriter::addNodeAttribute | ( | QObject * | node, |
const QString & | attribute, | ||
const QString & | value | ||
) |
Adds a node attribute to a node in the graph.
See The Dot Guide for a list of possible node attributes. Overwrites existing attribute with the same name if it exists. If the node you specify is not part of the observer tree (see observerContext()) then this function will fail and return false.
node | A pointer to the node. |
attribute | The name of the attribute to be added. |
value | The value of the attribute. |
QHash< QByteArray, QString > Qtilities::Core::ObserverDotWriter::edgeAttributes | ( | Observer * | parent, |
QObject * | child | ||
) | const |
Returns a list of all attributes on a node in the graph.
QString Qtilities::Core::ObserverDotWriter::generateDotScript | ( | ) | const |
Function which will generate the dot script for the specified observer context.
QHash< QString, QString > Qtilities::Core::ObserverDotWriter::graphAttributes | ( | ) | const |
Returns a list of all attributes on a node in the graph.
QHash< QByteArray, QString > Qtilities::Core::ObserverDotWriter::nodeAttributes | ( | QObject * | node | ) | const |
Returns a list of all attributes on a node in the graph.
bool Qtilities::Core::ObserverDotWriter::removeEdgeAttribute | ( | Observer * | parent, |
QObject * | child, | ||
const QString & | attribute | ||
) |
Removes a node attribute from a node in the graph.
node | A pointer to the node. |
attribute | The name of the attribute to be removed. |
bool Qtilities::Core::ObserverDotWriter::removeGraphAttribute | ( | const QString & | attribute | ) |
Removes a node attribute from a node in the graph.
attribute | The name of the attribute to be removed. |
bool Qtilities::Core::ObserverDotWriter::removeNodeAttribute | ( | QObject * | node, |
const QString & | attribute | ||
) |
Removes a node attribute from a node in the graph.
node | A pointer to the node. |
attribute | The name of the attribute to be removed. |
|
virtual |
Saves the dot script to a file.
Function which will write the dot script generated using the generateDotScript() function to the specified file.
Qtilities : Reference Documentation | Back to top |
Copyright © 2009-2013, Jaco Naudé
|