libyui  3.4.2
YGraph.cc
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.cc
20 
21  Author: Arvin Schnell <aschnell@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui-graph"
27 #include "YUILog.h"
28 
29 #include "YGraph.h"
30 
31 
33 {
34  YGraphPrivate( std::string filename, std::string layoutAlgorithm )
35  : filename( filename ),
36  layoutAlgorithm( layoutAlgorithm )
37  {}
38 
39  std::string filename;
40  std::string layoutAlgorithm;
41 };
42 
43 
44 YGraph::YGraph( YWidget * parent, const std::string & filename, const std::string & layoutAlgorithm )
45  : YWidget( parent )
46  , priv( new YGraphPrivate( filename, layoutAlgorithm ) )
47 {
48  setDefaultStretchable( YD_HORIZ, true );
49  setDefaultStretchable( YD_VERT, true );
50 }
51 
52 
53 YGraph::YGraph( YWidget * parent, /* graph_t */ void * graph )
54  : YWidget( parent )
55  , priv( new YGraphPrivate( "", "" ) )
56 {
57  setDefaultStretchable( YD_HORIZ, true );
58  setDefaultStretchable( YD_VERT, true );
59 }
60 
61 
63 {
64  // NOP
65 }
66 
67 
68 std::string
70 {
71  return priv->filename;
72 }
73 
74 
75 void
76 YGraph::setFilename( const std::string & filename )
77 {
78  priv->filename = filename;
79  renderGraph( filename, layoutAlgorithm() );
80 }
81 
82 
83 std::string
85 {
86  return priv->layoutAlgorithm;
87 }
88 
89 
90 void
91 YGraph::setGraph( /* graph_t */ void * graph )
92 {
93  priv->filename.clear();
94  renderGraph( graph );
95 }
96 
97 
98 void
100 {
101  priv->layoutAlgorithm = layoutAlgorithm;
102 }
103 
104 
105 std::string
107 {
108  return "";
109 }
110 
111 
112 const YPropertySet &
114 {
115  static YPropertySet propSet;
116 
117  if ( propSet.isEmpty() )
118  {
119  /*
120  * @property std::string Filename name of the file describing the graph
121  * @property std::string Layout layout-algorithm used from the graph
122  * @property std::string Item activated node (read-only)
123  */
124  propSet.add( YProperty( YUIProperty_Filename, YStringProperty ) );
125  propSet.add( YProperty( YUIProperty_Layout, YStringProperty ) );
126  propSet.add( YProperty( YUIProperty_Item, YStringProperty, true ) );
127  propSet.add( YWidget::propertySet() );
128  }
129 
130  return propSet;
131 }
132 
133 
134 bool
135 YGraph::setProperty( const std::string & propertyName, const YPropertyValue & val )
136 {
137  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
138 
139  if ( propertyName == YUIProperty_Filename ) setFilename( val.stringVal() );
140  else if ( propertyName == YUIProperty_Layout ) setLayoutAlgorithm( val.stringVal() );
141  else
142  {
143  return YWidget::setProperty( propertyName, val );
144  }
145 
146  return true; // success -- no special processing necessary
147 }
148 
149 
151 YGraph::getProperty( const std::string & propertyName )
152 {
153  propertySet().check( propertyName ); // throws exceptions if not found
154 
155  if ( propertyName == YUIProperty_Filename ) return YPropertyValue( filename() );
156  else if ( propertyName == YUIProperty_Layout ) return YPropertyValue( layoutAlgorithm() );
157  else if ( propertyName == YUIProperty_Item ) return YPropertyValue( activatedNode() );
158  else
159  {
160  return YWidget::getProperty( propertyName );
161  }
162 }
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
bool isEmpty() const
Returns &#39;true&#39; if this property set does not contain anything.
Definition: YProperty.h:263
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
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:145
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:430
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 YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YWidget.cc:393
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YGraph.cc:113
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:455
std::string stringVal() const
Methods to get the value of this property.
Definition: YProperty.h:180
virtual void setGraph(void *graph)
Render the graph.
Definition: YGraph.cc:91
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:564
virtual ~YGraph()
Destructor.
Definition: YGraph.cc:62
Class for widget properties.
Definition: YProperty.h:51
virtual void renderGraph(const std::string &filename, const std::string &layoutAlgorithm)=0
Render the graph from the filename.
void check(const std::string &propertyName) const
Check if a property &#39;propertyName&#39; exists in this property set.
Definition: YProperty.cc:87
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
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169