File indexing completed on 2024-05-19 15:27:49
0001 /* This file is part of KGraphViewer. 0002 Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KGraphViewer is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; if not, write to the Free Software 0015 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0016 02110-1301, USA 0017 */ 0018 0019 /* This file was callgraphview.cpp, part of KCachegrind. 0020 Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0021 0022 KCachegrind is free software; you can redistribute it and/or 0023 modify it under the terms of the GNU General Public 0024 License as published by the Free Software Foundation, version 2. 0025 */ 0026 0027 #include "graphedge.h" 0028 #include "canvasedge.h" 0029 #include "dotdefaults.h" 0030 #include "graphnode.h" 0031 #include "graphsubgraph.h" 0032 #include "kgraphviewerlib_debug.h" 0033 0034 namespace KGraphViewer 0035 { 0036 /* 0037 * Graph Edge 0038 */ 0039 0040 GraphEdge::GraphEdge() 0041 : GraphElement() 0042 , m_fromNode(nullptr) 0043 , m_toNode(nullptr) 0044 , m_visible(true) 0045 , m_colors() 0046 , m_dir(DOT_DEFAULT_EDGE_DIR) 0047 , m_arrowheads() 0048 { 0049 // qCDebug(KGRAPHVIEWERLIB_LOG) ; 0050 } 0051 0052 GraphEdge::~GraphEdge() 0053 { 0054 // qCDebug(KGRAPHVIEWERLIB_LOG) ; 0055 } 0056 0057 GraphEdge::GraphEdge(const GraphEdge &edge) 0058 : GraphElement(edge) 0059 { 0060 m_fromNode = nullptr; 0061 m_toNode = nullptr; 0062 m_visible = edge.m_visible; 0063 m_colors = edge.m_colors; 0064 m_dir = edge.m_dir; 0065 m_arrowheads = edge.m_arrowheads; 0066 } 0067 0068 void GraphEdge::colors(const QString &cs) 0069 { 0070 m_colors = cs.split(':'); 0071 // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << ": nb colors: " << m_colors.size(); 0072 } 0073 0074 const QString GraphEdge::color(uint i) 0075 { 0076 if (i >= (uint)m_colors.count() && m_attributes.find(KEY_COLOR) != m_attributes.end()) { 0077 colors(m_attributes[KEY_COLOR]); 0078 } 0079 if (i < (uint)m_colors.count()) { 0080 // std::cerr << "edge color " << i << " is " << m_colors[i] << std::endl; 0081 // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << "color" << i << "is" << m_colors[i]; 0082 return m_colors[i]; 0083 } else { 0084 // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << "no edge color " << i << ". returning " << DOT_DEFAULT_EDGE_COLOR; 0085 return DOT_DEFAULT_EDGE_COLOR; 0086 } 0087 } 0088 0089 void GraphEdge::updateWithEdge(const GraphEdge &edge) 0090 { 0091 qCDebug(KGRAPHVIEWERLIB_LOG) << id() << edge.id(); 0092 m_arrowheads = edge.arrowheads(); 0093 m_colors = edge.colors(); 0094 m_dir = edge.dir(); 0095 GraphElement::updateWithElement(edge); 0096 if (canvasEdge()) { 0097 canvasEdge()->computeBoundingRect(); 0098 canvasEdge()->modelChanged(); 0099 } 0100 } 0101 0102 void GraphEdge::updateWithEdge(edge_t *edge) 0103 { 0104 qCDebug(KGRAPHVIEWERLIB_LOG); 0105 DotRenderOpVec ops; 0106 // decrease mem peak 0107 setRenderOperations(ops); 0108 0109 if (agget(edge, (char *)"_draw_")) { 0110 parse_renderop(agget(edge, (char *)"_draw_"), ops); 0111 qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); 0112 } 0113 if (agget(edge, (char *)"_ldraw_")) { 0114 parse_renderop(agget(edge, (char *)"_ldraw_"), ops); 0115 qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); 0116 } 0117 if (agget(edge, (char *)"_hdraw_")) { 0118 parse_renderop(agget(edge, (char *)"_hdraw_"), ops); 0119 qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); 0120 } 0121 if (agget(edge, (char *)"_tdraw_")) { 0122 parse_renderop(agget(edge, (char *)"_tdraw_"), ops); 0123 qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); 0124 } 0125 if (agget(edge, (char *)"_hldraw_")) { 0126 parse_renderop(agget(edge, (char *)"_hldraw_"), ops); 0127 qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); 0128 } 0129 if (agget(edge, (char *)"_tldraw_")) { 0130 parse_renderop(agget(edge, (char *)"_tldraw_"), ops); 0131 qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); 0132 } 0133 setRenderOperations(ops); 0134 Agsym_t *attr = agnxtattr(agraphof(agtail(edge)), AGEDGE, nullptr); 0135 while (attr) { 0136 qCDebug(KGRAPHVIEWERLIB_LOG) /*<< edge->name*/ << ":" << attr->name << agxget(edge, attr); 0137 m_attributes[attr->name] = agxget(edge, attr); 0138 attr = agnxtattr(agraphof(agtail(edge)), AGEDGE, attr); 0139 } 0140 } 0141 0142 QTextStream &operator<<(QTextStream &s, const GraphEdge &e) 0143 { 0144 QString srcLabel = e.fromNode()->id(); 0145 if (dynamic_cast<const GraphSubgraph *>(e.fromNode())) { 0146 srcLabel = QString("subgraph ") + srcLabel; 0147 } 0148 QString tgtLabel = e.toNode()->id(); 0149 if (dynamic_cast<const GraphSubgraph *>(e.toNode())) { 0150 tgtLabel = QString("subgraph ") + tgtLabel; 0151 } 0152 s << srcLabel << " -> " << tgtLabel << " [" << dynamic_cast<const GraphElement &>(e) << "];" << Qt::endl; 0153 0154 return s; 0155 } 0156 0157 } 0158 0159 #include "moc_graphedge.cpp"