25
25
#include "canvassubgraph.h"
26
26
#include "dotdefaults.h"
32
34
GraphSubgraph::GraphSubgraph() :
35
GraphElement(), m_content()
39
void GraphSubgraph::updateWithSubgraph(const GraphSubgraph& subgraph)
41
kDebug() << id() << subgraph.id();
42
GraphElement::updateWithElement(subgraph);
45
foreach (GraphElement* updatingge, subgraph.content())
47
foreach (GraphElement* ge, content())
49
if (ge->id() == updatingge->id())
52
if (dynamic_cast<GraphNode*>(ge) != 0)
54
dynamic_cast<GraphNode*>(ge)->updateWithNode(*dynamic_cast<GraphNode*>(updatingge));
55
// kDebug() << "node " << ngn->id();
57
else if (dynamic_cast<GraphSubgraph*>(ge) != 0)
59
dynamic_cast<GraphSubgraph*>(ge)->updateWithSubgraph(*dynamic_cast<GraphSubgraph*>(updatingge));
63
kError() << "Updated element is neither a node nor a subgraph";
71
if (dynamic_cast<GraphNode*>(updatingge) != 0)
73
GraphNode* newgn = new GraphNode(*dynamic_cast<GraphNode*>(updatingge));
74
// kDebug() << "new created";
75
content().push_back(newgn);
76
// kDebug() << "new inserted";
78
else if (dynamic_cast<GraphSubgraph*>(updatingge) != 0)
80
GraphSubgraph* newsg = new GraphSubgraph(*dynamic_cast<GraphSubgraph*>(updatingge));
81
content().push_back(newsg);
88
canvasSubgraph()->modelChanged();
89
canvasSubgraph()->computeBoundingRect();
91
// kDebug() << "done";
37
95
QString GraphSubgraph::backColor() const
57
115
return DOT_DEFAULT_BACKCOLOR;
119
void GraphSubgraph::removeElement(GraphElement* element)
121
m_content.removeAll(element);
124
GraphElement* GraphSubgraph::elementNamed(const QString& id)
126
if (this->id() == id) return this;
127
foreach (GraphElement* element, content())
129
if (element->id() == id)
133
else if (dynamic_cast<GraphSubgraph*>(element))
135
GraphElement* subgraphElement = dynamic_cast<GraphSubgraph*>(element)->elementNamed(id);
136
if (subgraphElement != 0)
138
return subgraphElement;
145
bool GraphSubgraph::setElementSelected(
146
GraphElement* element,
151
kDebug() << element->id() << selectValue << unselectOthers;
155
if (isSelected() != selectValue)
157
setSelected(selectValue);
158
canvasElement()->update();
162
else if (isSelected() && unselectOthers)
165
canvasElement()->update();
167
foreach (GraphElement* el, content())
169
if (dynamic_cast<GraphSubgraph*>(el) != 0)
171
bool subres = dynamic_cast<GraphSubgraph*>(el)->setElementSelected(element, selectValue, unselectOthers);
172
if (!res) res = subres;
174
else if (element == el)
177
if (el->isSelected() != selectValue)
179
el->setSelected(selectValue);
180
el->canvasElement()->update();
185
if (unselectOthers && el->isSelected())
187
el->setSelected(false);
188
el->canvasElement()->update();
195
void GraphSubgraph::retrieveSelectedElementsIds(QList<QString> selection)
199
selection.push_back(id());
201
foreach (GraphElement* el, content())
203
if (dynamic_cast<GraphSubgraph*>(el) != 0)
205
dynamic_cast<GraphSubgraph*>(el)->retrieveSelectedElementsIds(selection);
207
else if (el->isSelected())
209
selection.push_back(el->id());
65
214
QTextStream& operator<<(QTextStream& s, const GraphSubgraph& sg)