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