00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "edge.h"
00022 #include "node.h"
00023 #include "NodeItem.h"
00024 #include "graph.h"
00025 #include "DynamicPropertiesList.h"
00026 #include <KDebug>
00027
00028 Edge::Edge( Graph* parent, Node* from, Node* to, QGraphicsSvgItem* cFrom, QGraphicsSvgItem* cTo ) :
00029 QObject( parent ),
00030 _from( from ),
00031 _to( to )
00032
00033 {
00034 _graph = parent;
00035 _color = _graph->edgeDefaultColor();
00036
00037 if( from == to )
00038 {
00039 connect( from, SIGNAL( changed() ), this, SIGNAL( changed() ) );
00040 from -> addSelfEdge( this );
00041 }
00042 else
00043 {
00044 connect( from, SIGNAL( changed() ), this, SIGNAL( changed() ) );
00045 from -> addOutEdge( this );
00046 connect( to, SIGNAL( changed() ), this, SIGNAL( changed() ) );
00047 to -> addInEdge( this );
00048 }
00049 connect( parent, SIGNAL( complexityChanged( bool ) ), this, SIGNAL( changed() ) );
00050
00051 _relativeIndex = _to -> edges( _from ).size();
00052 _showName = true;
00053 _showValue = true;
00054 _style = "solid";
00055 _width = 1;
00056 _cFrom = cFrom;
00057 _cTo = cTo;
00058 }
00059
00060 Edge::~Edge()
00061 {
00062 if( _from == _to )
00063 {
00064 _from->removeEdge( this, Node::Self );
00065 }
00066 else
00067 {
00068 _from->removeEdge( this, Node::Out );
00069 _to->removeEdge( this, Node::In );
00070 }
00071 _from = 0;
00072 _to = 0;
00073 emit removed();
00074 }
00075
00076 void Edge::remove()
00077 {
00078 _graph->remove( this );
00079 }
00080
00081 QString Edge::fromConnector()
00082 {
00083 return qobject_cast<NodeItem*>( _from->nodeItem() )->connectors().key( _cFrom );
00084 }
00085
00086 QString Edge::toConnector()
00087 {
00088 return qobject_cast<NodeItem*>( _to->nodeItem() )->connectors().key( _cTo );
00089 }
00090
00091 QString Edge::fromNode()
00092 {
00093 return _from->name();
00094 }
00095
00096 QString Edge::toNode()
00097 {
00098 return _to->name();
00099 }
00100
00101
00102 bool Edge::showName()
00103 {
00104 return _showName;
00105 }
00106
00107 bool Edge::showValue()
00108 {
00109 return _showValue;
00110 }
00111
00112 void Edge::hideName( bool b )
00113 {
00114 _showName = b;
00115 emit changed();
00116 kDebug() << "Hide Name: " << b;
00117 }
00118
00119 void Edge::hideValue( bool b )
00120 {
00121 _showValue = b;
00122 emit changed();
00123 kDebug() << "Hide Value: " << b;
00124 }
00125
00126 void Edge::addDynamicProperty( QString property, QVariant value )
00127 {
00128 this->setProperty( property.toUtf8(), value );
00129 if( value.isValid() )
00130 {
00131 DynamicPropertiesList::New()->addProperty( this, property );
00132 }
00133 }
00134
00135 void Edge::removeDynamicProperty( QString property )
00136 {
00137 addDynamicProperty( property.toUtf8(), QVariant::Invalid );
00138 DynamicPropertiesList::New()->removeProperty( this, property );
00139 }