Changeset View
Changeset View
Standalone View
Standalone View
src/part/graphedge.cpp
Show All 19 Lines | 19 | /* This file was callgraphview.cpp, part of KCachegrind. | |||
---|---|---|---|---|---|
20 | Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> | 20 | Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> | ||
21 | 21 | | |||
22 | KCachegrind is free software; you can redistribute it and/or | 22 | KCachegrind is free software; you can redistribute it and/or | ||
23 | modify it under the terms of the GNU General Public | 23 | modify it under the terms of the GNU General Public | ||
24 | License as published by the Free Software Foundation, version 2. | 24 | License as published by the Free Software Foundation, version 2. | ||
25 | */ | 25 | */ | ||
26 | 26 | | |||
27 | #include "graphedge.h" | 27 | #include "graphedge.h" | ||
28 | #include "graphnode.h" | | |||
29 | #include "graphsubgraph.h" | | |||
30 | #include "canvasedge.h" | 28 | #include "canvasedge.h" | ||
31 | #include "dotdefaults.h" | 29 | #include "dotdefaults.h" | ||
30 | #include "graphnode.h" | ||||
31 | #include "graphsubgraph.h" | ||||
32 | #include "kgraphviewerlib_debug.h" | 32 | #include "kgraphviewerlib_debug.h" | ||
33 | 33 | | |||
34 | namespace KGraphViewer | 34 | namespace KGraphViewer | ||
35 | { | 35 | { | ||
36 | | ||||
37 | /* | 36 | /* | ||
38 | * Graph Edge | 37 | * Graph Edge | ||
39 | */ | 38 | */ | ||
40 | 39 | | |||
41 | GraphEdge::GraphEdge() : | 40 | GraphEdge::GraphEdge() | ||
42 | GraphElement(), | 41 | : GraphElement() | ||
43 | m_fromNode(nullptr), | 42 | , m_fromNode(nullptr) | ||
44 | m_toNode(nullptr), | 43 | , m_toNode(nullptr) | ||
45 | m_visible(true), | 44 | , m_visible(true) | ||
46 | m_colors(), | 45 | , m_colors() | ||
47 | m_dir(DOT_DEFAULT_EDGE_DIR), | 46 | , m_dir(DOT_DEFAULT_EDGE_DIR) | ||
48 | m_arrowheads() | 47 | , m_arrowheads() | ||
49 | { | 48 | { | ||
50 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | 49 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | ||
51 | } | 50 | } | ||
52 | 51 | | |||
53 | GraphEdge::~GraphEdge() | 52 | GraphEdge::~GraphEdge() | ||
54 | { | 53 | { | ||
55 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | 54 | // qCDebug(KGRAPHVIEWERLIB_LOG) ; | ||
56 | } | 55 | } | ||
57 | 56 | | |||
58 | GraphEdge::GraphEdge(const GraphEdge& edge) : | 57 | GraphEdge::GraphEdge(const GraphEdge &edge) | ||
59 | GraphElement(edge) | 58 | : GraphElement(edge) | ||
60 | { | 59 | { | ||
61 | m_fromNode = nullptr; | 60 | m_fromNode = nullptr; | ||
62 | m_toNode = nullptr; | 61 | m_toNode = nullptr; | ||
63 | m_visible = edge.m_visible; | 62 | m_visible = edge.m_visible; | ||
64 | m_colors = edge.m_colors; | 63 | m_colors = edge.m_colors; | ||
65 | m_dir = edge.m_dir; | 64 | m_dir = edge.m_dir; | ||
66 | m_arrowheads = edge.m_arrowheads; | 65 | m_arrowheads = edge.m_arrowheads; | ||
67 | } | 66 | } | ||
68 | 67 | | |||
69 | void GraphEdge::colors(const QString& cs) | 68 | void GraphEdge::colors(const QString &cs) | ||
70 | { | 69 | { | ||
71 | m_colors = cs.split(':'); | 70 | m_colors = cs.split(':'); | ||
72 | // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << ": nb colors: " << m_colors.size(); | 71 | // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << ": nb colors: " << m_colors.size(); | ||
73 | } | 72 | } | ||
74 | 73 | | |||
75 | const QString GraphEdge::color(uint i) | 74 | const QString GraphEdge::color(uint i) | ||
76 | { | 75 | { | ||
77 | if (i >= (uint)m_colors.count() && m_attributes.find(KEY_COLOR) != m_attributes.end()) | 76 | if (i >= (uint)m_colors.count() && m_attributes.find(KEY_COLOR) != m_attributes.end()) { | ||
78 | { | | |||
79 | colors(m_attributes[KEY_COLOR]); | 77 | colors(m_attributes[KEY_COLOR]); | ||
80 | } | 78 | } | ||
81 | if (i < (uint)m_colors.count()) | 79 | if (i < (uint)m_colors.count()) { | ||
82 | { | | |||
83 | // std::cerr << "edge color " << i << " is " << m_colors[i] << std::endl; | 80 | // std::cerr << "edge color " << i << " is " << m_colors[i] << std::endl; | ||
84 | // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << "color" << i << "is" << m_colors[i]; | 81 | // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << "color" << i << "is" << m_colors[i]; | ||
85 | return m_colors[i]; | 82 | return m_colors[i]; | ||
86 | } | 83 | } else { | ||
87 | else | | |||
88 | { | | |||
89 | // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << "no edge color " << i << ". returning " << DOT_DEFAULT_EDGE_COLOR; | 84 | // qCDebug(KGRAPHVIEWERLIB_LOG) << fromNode()->id() << " -> " << toNode()->id() << "no edge color " << i << ". returning " << DOT_DEFAULT_EDGE_COLOR; | ||
90 | return DOT_DEFAULT_EDGE_COLOR; | 85 | return DOT_DEFAULT_EDGE_COLOR; | ||
91 | } | 86 | } | ||
92 | } | 87 | } | ||
93 | 88 | | |||
94 | void GraphEdge::updateWithEdge(const GraphEdge& edge) | 89 | void GraphEdge::updateWithEdge(const GraphEdge &edge) | ||
95 | { | 90 | { | ||
96 | qCDebug(KGRAPHVIEWERLIB_LOG) << id() << edge.id(); | 91 | qCDebug(KGRAPHVIEWERLIB_LOG) << id() << edge.id(); | ||
97 | m_arrowheads = edge.arrowheads(); | 92 | m_arrowheads = edge.arrowheads(); | ||
98 | m_colors = edge.colors(); | 93 | m_colors = edge.colors(); | ||
99 | m_dir = edge.dir(); | 94 | m_dir = edge.dir(); | ||
100 | GraphElement::updateWithElement(edge); | 95 | GraphElement::updateWithElement(edge); | ||
101 | if (canvasEdge()) | 96 | if (canvasEdge()) { | ||
102 | { | | |||
103 | canvasEdge()->computeBoundingRect(); | 97 | canvasEdge()->computeBoundingRect(); | ||
104 | canvasEdge()->modelChanged(); | 98 | canvasEdge()->modelChanged(); | ||
105 | } | 99 | } | ||
106 | } | 100 | } | ||
107 | 101 | | |||
108 | void GraphEdge::updateWithEdge(edge_t* edge) | 102 | void GraphEdge::updateWithEdge(edge_t *edge) | ||
109 | { | 103 | { | ||
110 | qCDebug(KGRAPHVIEWERLIB_LOG); | 104 | qCDebug(KGRAPHVIEWERLIB_LOG); | ||
111 | DotRenderOpVec ops; | 105 | DotRenderOpVec ops; | ||
112 | // decrease mem peak | 106 | // decrease mem peak | ||
113 | setRenderOperations(ops); | 107 | setRenderOperations(ops); | ||
114 | 108 | | |||
115 | if (agget(edge, (char*)"_draw_")) | 109 | if (agget(edge, (char *)"_draw_")) { | ||
116 | { | | |||
117 | parse_renderop(agget(edge, (char*)"_draw_"), ops); | 110 | parse_renderop(agget(edge, (char *)"_draw_"), ops); | ||
118 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | 111 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | ||
119 | } | 112 | } | ||
120 | if (agget(edge, (char*)"_ldraw_")) | 113 | if (agget(edge, (char *)"_ldraw_")) { | ||
121 | { | | |||
122 | parse_renderop(agget(edge, (char*)"_ldraw_"), ops); | 114 | parse_renderop(agget(edge, (char *)"_ldraw_"), ops); | ||
123 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | 115 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | ||
124 | } | 116 | } | ||
125 | if (agget(edge, (char*)"_hdraw_")) | 117 | if (agget(edge, (char *)"_hdraw_")) { | ||
126 | { | | |||
127 | parse_renderop(agget(edge, (char*)"_hdraw_"), ops); | 118 | parse_renderop(agget(edge, (char *)"_hdraw_"), ops); | ||
128 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | 119 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | ||
129 | } | 120 | } | ||
130 | if (agget(edge, (char*)"_tdraw_")) | 121 | if (agget(edge, (char *)"_tdraw_")) { | ||
131 | { | | |||
132 | parse_renderop(agget(edge, (char*)"_tdraw_"), ops); | 122 | parse_renderop(agget(edge, (char *)"_tdraw_"), ops); | ||
133 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | 123 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | ||
134 | } | 124 | } | ||
135 | if (agget(edge, (char*)"_hldraw_")) | 125 | if (agget(edge, (char *)"_hldraw_")) { | ||
136 | { | | |||
137 | parse_renderop(agget(edge, (char*)"_hldraw_"), ops); | 126 | parse_renderop(agget(edge, (char *)"_hldraw_"), ops); | ||
138 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | 127 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | ||
139 | } | 128 | } | ||
140 | if (agget(edge, (char*)"_tldraw_")) | 129 | if (agget(edge, (char *)"_tldraw_")) { | ||
141 | { | | |||
142 | parse_renderop(agget(edge, (char*)"_tldraw_"), ops); | 130 | parse_renderop(agget(edge, (char *)"_tldraw_"), ops); | ||
143 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | 131 | qCDebug(KGRAPHVIEWERLIB_LOG) << "element renderOperations size is now " << ops.size(); | ||
144 | } | 132 | } | ||
145 | setRenderOperations(ops); | 133 | setRenderOperations(ops); | ||
146 | Agsym_t *attr = agnxtattr(agraphof(agtail(edge)), AGEDGE, nullptr); | 134 | Agsym_t *attr = agnxtattr(agraphof(agtail(edge)), AGEDGE, nullptr); | ||
147 | while(attr) | 135 | while (attr) { | ||
148 | { | | |||
149 | qCDebug(KGRAPHVIEWERLIB_LOG) /*<< edge->name*/ << ":" << attr->name << agxget(edge,attr); | 136 | qCDebug(KGRAPHVIEWERLIB_LOG) /*<< edge->name*/ << ":" << attr->name << agxget(edge, attr); | ||
150 | m_attributes[attr->name] = agxget(edge,attr); | 137 | m_attributes[attr->name] = agxget(edge, attr); | ||
151 | attr = agnxtattr(agraphof(agtail(edge)), AGEDGE, attr); | 138 | attr = agnxtattr(agraphof(agtail(edge)), AGEDGE, attr); | ||
152 | } | 139 | } | ||
153 | | ||||
154 | } | 140 | } | ||
155 | 141 | | |||
156 | QTextStream& operator<<(QTextStream& s, const GraphEdge& e) | 142 | QTextStream &operator<<(QTextStream &s, const GraphEdge &e) | ||
157 | { | 143 | { | ||
158 | QString srcLabel = e.fromNode()->id(); | 144 | QString srcLabel = e.fromNode()->id(); | ||
159 | if (dynamic_cast<const GraphSubgraph*>(e.fromNode())) | 145 | if (dynamic_cast<const GraphSubgraph *>(e.fromNode())) { | ||
160 | { | | |||
161 | srcLabel = QString("subgraph ") + srcLabel; | 146 | srcLabel = QString("subgraph ") + srcLabel; | ||
162 | } | 147 | } | ||
163 | QString tgtLabel = e.toNode()->id(); | 148 | QString tgtLabel = e.toNode()->id(); | ||
164 | if (dynamic_cast<const GraphSubgraph*>(e.toNode())) | 149 | if (dynamic_cast<const GraphSubgraph *>(e.toNode())) { | ||
165 | { | | |||
166 | tgtLabel = QString("subgraph ") + tgtLabel; | 150 | tgtLabel = QString("subgraph ") + tgtLabel; | ||
167 | } | 151 | } | ||
168 | s << srcLabel << " -> " << tgtLabel << " [" | 152 | s << srcLabel << " -> " << tgtLabel << " [" << dynamic_cast<const GraphElement &>(e) << "];" << endl; | ||
169 | << dynamic_cast<const GraphElement&>(e) << "];" << endl; | | |||
170 | 153 | | |||
171 | return s; | 154 | return s; | ||
172 | } | 155 | } | ||
173 | 156 | | |||
174 | } | 157 | } |