libyui  3.3.1
YGraph.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YGraph.h
20 
21  Author: Arvin Schnell <aschnell@suse.de>
22 
23 /-*/
24 
25 #ifndef YGraph_h
26 #define YGraph_h
27 
28 #include "YWidget.h"
29 
30 /*
31  * Do not include graphviz/types.h here since it conflicts with ncurses
32  * headers. People should finally start to use C++ and namespaces!
33  *
34  * The previous workaround of inserting the graph_t definition here does not
35  * work with graphviz >= 2.30.0 since it depends on the define WITH_CGRAPH.
36  *
37  * For that reason a lot of functions simply take a void* instead of graph_t*.
38  */
39 
40 class YGraphPrivate;
41 
42 /**
43  * A graph with nodes and edges, rendered with Graphviz.
44  **/
45 class YGraph : public YWidget
46 {
47 protected:
48 
49  /**
50  * Constructor.
51  *
52  * Loads a graph in DOT format from filename and uses the layout algorithm
53  * layoutAlgorithm to layout and then render the graph. The layout
54  * algorithm can be any string accepted by the function gvLayout from
55  * graphviz, e.g. "dot" or "neato".
56  **/
57  YGraph( YWidget * parent, const std::string & filename, const std::string & layoutAlgorithm );
58 
59  /**
60  * Constructor.
61  *
62  * Renders the graph. The graph must already contain layout information.
63  **/
64  YGraph( YWidget * parent, /* graph_t */ void * graph );
65 
66 public:
67 
68  /**
69  * Destructor.
70  **/
71  virtual ~YGraph();
72 
73  /**
74  * Returns a descriptive name of this widget class for logging,
75  * debugging etc.
76  **/
77  virtual const char * widgetClass() const { return "YGraph"; }
78 
79  /**
80  * Set a property.
81  * Reimplemented from YWidget.
82  *
83  * This function may throw YUIPropertyExceptions.
84  *
85  * This function returns 'true' if the value was successfully set and
86  * 'false' if that value requires special handling (not in error cases:
87  * those are covered by exceptions).
88  **/
89  virtual bool setProperty( const std::string & propertyName,
90  const YPropertyValue & val );
91 
92  /**
93  * Get a property.
94  * Reimplemented from YWidget.
95  *
96  * This method may throw YUIPropertyExceptions.
97  **/
98  virtual YPropertyValue getProperty( const std::string & propertyName );
99 
100  /**
101  * Return this class's property set.
102  * This also initializes the property upon the first call.
103  *
104  * Reimplemented from YWidget.
105  **/
106  virtual const YPropertySet & propertySet();
107 
108  /**
109  * Return the filename that describes the graph.
110  **/
111  std::string filename() const;
112 
113  /**
114  * Set the filename that describes the graph and render the graph.
115  * Derived classes can reimplent this, but they should call this base
116  * class method in the new implementation. Most derived classes only need
117  * to implement renderGraph().
118  **/
119  virtual void setFilename( const std::string & filename );
120 
121  /**
122  * Return the layout-algorithm used for the graph.
123  **/
124  std::string layoutAlgorithm() const;
125 
126  /**
127  * Set the layout-algorithm used for the graph. Derived classes can
128  * reimplent this, but they should call this base class method in the new
129  * implementation.
130  **/
131  virtual void setLayoutAlgorithm( const std::string & filename );
132 
133  /**
134  * Render the graph. Derived classes can reimplent this, but they should
135  * call this base class method in the new implementation. Most derived
136  * classes only need to implement renderGraph().
137  **/
138  virtual void setGraph( /* graph_t */ void * graph );
139 
140  /**
141  * Return name of activated node. Activation can happen due to e.g. single
142  * right mouse click (context menu) or double left mouse click.
143  */
144  virtual std::string activatedNode() const;
145 
146 protected:
147 
148  /**
149  * Render the graph from the filename. Derived classes are required to
150  * implement this.
151  **/
152  virtual void renderGraph( const std::string & filename, const std::string & layoutAlgorithm ) = 0;
153 
154  /**
155  * Render the graph. Derived classes are required to implement this.
156  **/
157  virtual void renderGraph( /* graph_t */ void * graph ) = 0;
158 
159 private:
160 
162 
163 };
164 
165 
166 #endif // YGraph_h
std::string layoutAlgorithm() const
Return the layout-algorithm used for the graph.
Definition: YGraph.cc:84
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YGraph.cc:151
virtual void setFilename(const std::string &filename)
Set the filename that describes the graph and render the graph.
Definition: YGraph.cc:76
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YGraph.cc:135
Transport class for the value of simple properties.
Definition: YProperty.h:104
A set of properties to check names and types against.
Definition: YProperty.h:197
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
virtual std::string activatedNode() const
Return name of activated node.
Definition: YGraph.cc:106
virtual void setLayoutAlgorithm(const std::string &filename)
Set the layout-algorithm used for the graph.
Definition: YGraph.cc:99
YGraph(YWidget *parent, const std::string &filename, const std::string &layoutAlgorithm)
Constructor.
Definition: YGraph.cc:44
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YGraph.h:77
A graph with nodes and edges, rendered with Graphviz.
Definition: YGraph.h:45
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YGraph.cc:113
virtual void setGraph(void *graph)
Render the graph.
Definition: YGraph.cc:91
virtual ~YGraph()
Destructor.
Definition: YGraph.cc:62
virtual void renderGraph(const std::string &filename, const std::string &layoutAlgorithm)=0
Render the graph from the filename.
Abstract base class of all UI widgets.
Definition: YWidget.h:54
std::string filename() const
Return the filename that describes the graph.
Definition: YGraph.cc:69