libyui  3.0.13
 All Classes Functions Variables Enumerations Friends
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 class YGraph : public YWidget
44 {
45 protected:
46 
47  /**
48  * Constructor.
49  *
50  * Loads a graph in DOT format from filename and uses the layout algorithm
51  * layoutAlgorithm to layout and then render the graph. The layout
52  * algorithm can be any string accepted by the function gvLayout from
53  * graphviz, e.g. "dot" or "neato".
54  **/
55  YGraph( YWidget * parent, const std::string & filename, const std::string & layoutAlgorithm );
56 
57  /**
58  * Constructor.
59  *
60  * Renders the graph. The graph must already contain layout information.
61  **/
62  YGraph( YWidget * parent, /* graph_t */ void * graph );
63 
64 public:
65 
66  /**
67  * Destructor.
68  **/
69  virtual ~YGraph();
70 
71  /**
72  * Returns a descriptive name of this widget class for logging,
73  * debugging etc.
74  **/
75  virtual const char * widgetClass() const { return "YGraph"; }
76 
77  /**
78  * Set a property.
79  * Reimplemented from YWidget.
80  *
81  * This function may throw YUIPropertyExceptions.
82  *
83  * This function returns 'true' if the value was successfully set and
84  * 'false' if that value requires special handling (not in error cases:
85  * those are covered by exceptions).
86  **/
87  virtual bool setProperty( const std::string & propertyName,
88  const YPropertyValue & val );
89 
90  /**
91  * Get a property.
92  * Reimplemented from YWidget.
93  *
94  * This method may throw YUIPropertyExceptions.
95  **/
96  virtual YPropertyValue getProperty( const std::string & propertyName );
97 
98  /**
99  * Return this class's property set.
100  * This also initializes the property upon the first call.
101  *
102  * Reimplemented from YWidget.
103  **/
104  virtual const YPropertySet & propertySet();
105 
106  /**
107  * Return the filename that describes the graph.
108  **/
109  std::string filename() const;
110 
111  /**
112  * Set the filename that describes the graph and render the graph.
113  * Derived classes can reimplent this, but they should call this base
114  * class method in the new implementation. Most derived classes only need
115  * to implement renderGraph().
116  **/
117  virtual void setFilename( const std::string & filename );
118 
119  /**
120  * Return the layout-algorithm used for the graph.
121  **/
122  std::string layoutAlgorithm() const;
123 
124  /**
125  * Set the layout-algorithm used for the graph. Derived classes can
126  * reimplent this, but they should call this base class method in the new
127  * implementation.
128  **/
129  virtual void setLayoutAlgorithm( const std::string & filename );
130 
131  /**
132  * Render the graph. Derived classes can reimplent this, but they should
133  * call this base class method in the new implementation. Most derived
134  * classes only need to implement renderGraph().
135  **/
136  virtual void setGraph( /* graph_t */ void * graph );
137 
138  /**
139  * Return name of activated node. Activation can happen due to e.g. single
140  * right mouse click (context menu) or double left mouse click.
141  */
142  virtual std::string activatedNode() const;
143 
144 protected:
145 
146  /**
147  * Render the graph from the filename. Derived classes are required to
148  * implement this.
149  **/
150  virtual void renderGraph( const std::string & filename, const std::string & layoutAlgorithm ) = 0;
151 
152  /**
153  * Render the graph. Derived classes are required to implement this.
154  **/
155  virtual void renderGraph( /* graph_t */ void * graph ) = 0;
156 
157 private:
158 
160 
161 };
162 
163 
164 #endif // YGraph_h
virtual YPropertyValue getProperty(const std::string &propertyName)
Definition: YGraph.cc:151
virtual void setFilename(const std::string &filename)
Definition: YGraph.cc:76
YWidget * parent() const
Definition: YWidget.cc:269
virtual const char * widgetClass() const
Definition: YGraph.h:75
std::string filename() const
Definition: YGraph.cc:69
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Definition: YGraph.cc:135
virtual std::string activatedNode() const
Definition: YGraph.cc:106
virtual void setLayoutAlgorithm(const std::string &filename)
Definition: YGraph.cc:99
YGraph(YWidget *parent, const std::string &filename, const std::string &layoutAlgorithm)
Definition: YGraph.cc:44
Definition: YGraph.h:43
virtual const YPropertySet & propertySet()
Definition: YGraph.cc:113
virtual void setGraph(void *graph)
Definition: YGraph.cc:91
std::string layoutAlgorithm() const
Definition: YGraph.cc:84
virtual ~YGraph()
Definition: YGraph.cc:62
virtual void renderGraph(const std::string &filename, const std::string &layoutAlgorithm)=0