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