libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YGraph.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YGraph.cc
00020 
00021   Author:       Arvin Schnell <aschnell@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #define YUILogComponent "ui-graph"
00027 #include "YUILog.h"
00028 
00029 #include "YGraph.h"
00030 
00031 
00032 struct YGraphPrivate
00033 {
00034     YGraphPrivate( std::string filename, std::string layoutAlgorithm )
00035         : filename( filename ),
00036           layoutAlgorithm( layoutAlgorithm )
00037         {}
00038 
00039     std::string filename;
00040     std::string layoutAlgorithm;
00041 };
00042 
00043 
00044 YGraph::YGraph( YWidget * parent, const std::string & filename, const std::string & layoutAlgorithm )
00045     : YWidget( parent )
00046     , priv( new YGraphPrivate( filename, layoutAlgorithm ) )
00047 {
00048     setDefaultStretchable( YD_HORIZ, true );
00049     setDefaultStretchable( YD_VERT,  true );
00050 }
00051 
00052 
00053 YGraph::YGraph( YWidget * parent, /* graph_t */ void * graph )
00054     : YWidget( parent )
00055     , priv( new YGraphPrivate( "", "" ) )
00056 {
00057     setDefaultStretchable( YD_HORIZ, true );
00058     setDefaultStretchable( YD_VERT,  true );
00059 }
00060 
00061 
00062 YGraph::~YGraph()
00063 {
00064     // NOP
00065 }
00066 
00067 
00068 std::string
00069 YGraph::filename() const
00070 {
00071     return priv->filename;
00072 }
00073 
00074 
00075 void
00076 YGraph::setFilename( const std::string & filename )
00077 {
00078     priv->filename = filename;
00079     renderGraph( filename, layoutAlgorithm() );
00080 }
00081 
00082 
00083 std::string
00084 YGraph::layoutAlgorithm() const
00085 {
00086     return priv->layoutAlgorithm;
00087 }
00088 
00089 
00090 void
00091 YGraph::setGraph( /* graph_t */ void * graph )
00092 {
00093     priv->filename.clear();
00094     renderGraph( graph );
00095 }
00096 
00097 
00098 void
00099 YGraph::setLayoutAlgorithm( const std::string & layoutAlgorithm )
00100 {
00101     priv->layoutAlgorithm = layoutAlgorithm;
00102 }
00103 
00104 
00105 std::string
00106 YGraph::activatedNode() const
00107 {
00108     return "";
00109 }
00110 
00111 
00112 const YPropertySet &
00113 YGraph::propertySet()
00114 {
00115     static YPropertySet propSet;
00116 
00117     if ( propSet.isEmpty() )
00118     {
00119         /*
00120          * @property std::string        Filename        name of the file describing the graph
00121          * @property std::string        Layout          layout-algorithm used from the graph
00122          * @property std::string        Item            activated node (read-only)
00123          */
00124         propSet.add( YProperty( YUIProperty_Filename,           YStringProperty  ) );
00125         propSet.add( YProperty( YUIProperty_Layout,             YStringProperty  ) );
00126         propSet.add( YProperty( YUIProperty_Item,               YStringProperty, true ) );
00127         propSet.add( YWidget::propertySet() );
00128     }
00129 
00130     return propSet;
00131 }
00132 
00133 
00134 bool
00135 YGraph::setProperty( const std::string & propertyName, const YPropertyValue & val )
00136 {
00137     propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
00138 
00139     if      ( propertyName == YUIProperty_Filename      )       setFilename( val.stringVal() );
00140     else if ( propertyName == YUIProperty_Layout        )       setLayoutAlgorithm( val.stringVal() );
00141     else
00142     {
00143         return YWidget::setProperty( propertyName, val );
00144     }
00145 
00146     return true; // success -- no special processing necessary
00147 }
00148 
00149 
00150 YPropertyValue
00151 YGraph::getProperty( const std::string & propertyName )
00152 {
00153     propertySet().check( propertyName ); // throws exceptions if not found
00154 
00155     if      ( propertyName == YUIProperty_Filename      )       return YPropertyValue( filename() );
00156     else if ( propertyName == YUIProperty_Layout        )       return YPropertyValue( layoutAlgorithm() );
00157     else if ( propertyName == YUIProperty_Item          )       return YPropertyValue( activatedNode() );
00158     else
00159     {
00160         return YWidget::getProperty( propertyName );
00161     }
00162 }
 All Classes Functions Variables Enumerations Friends