~ubuntu-branches/ubuntu/jaunty/kgraphviewer/jaunty

« back to all changes in this revision

Viewing changes to src/part/graphsubgraph.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve Stalcup
  • Date: 2008-08-30 21:38:37 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080830213837-m9yz9i817rdqt26d
Tags: 4:2.0.2-kde4.1.1-0ubuntu1
* New upstream release
* Removed debian/cdbs dir, using cdbs kde4.mk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "canvassubgraph.h"
26
26
#include "dotdefaults.h"
27
27
 
 
28
#include <kdebug.h>
 
29
 
28
30
//
29
31
// GraphSubgraph
30
32
//
31
33
 
32
34
GraphSubgraph::GraphSubgraph() :
33
 
    GraphElement()
34
 
{
35
 
}
 
35
    GraphElement(), m_content()
 
36
{
 
37
}
 
38
 
 
39
void GraphSubgraph::updateWithSubgraph(const GraphSubgraph& subgraph)
 
40
{
 
41
  kDebug() << id() << subgraph.id();
 
42
  GraphElement::updateWithElement(subgraph);
 
43
 
 
44
  bool found = false;
 
45
  foreach (GraphElement* updatingge, subgraph.content())
 
46
  {
 
47
    foreach (GraphElement* ge, content())
 
48
    {
 
49
      if (ge->id() == updatingge->id())
 
50
      {
 
51
        found = true;
 
52
        if (dynamic_cast<GraphNode*>(ge) != 0)
 
53
        {
 
54
          dynamic_cast<GraphNode*>(ge)->updateWithNode(*dynamic_cast<GraphNode*>(updatingge));
 
55
        //     kDebug() << "node " << ngn->id();
 
56
        }
 
57
        else if (dynamic_cast<GraphSubgraph*>(ge) != 0)
 
58
        {
 
59
          dynamic_cast<GraphSubgraph*>(ge)->updateWithSubgraph(*dynamic_cast<GraphSubgraph*>(updatingge));
 
60
        }
 
61
        else
 
62
        {
 
63
          kError() << "Updated element is neither a node nor a subgraph";
 
64
        }
 
65
        break;
 
66
      }
 
67
    }
 
68
    if (!found)
 
69
    {
 
70
  //       kDebug() << "new";
 
71
      if (dynamic_cast<GraphNode*>(updatingge) != 0)
 
72
      {
 
73
        GraphNode* newgn = new GraphNode(*dynamic_cast<GraphNode*>(updatingge));
 
74
  //       kDebug() << "new created";
 
75
        content().push_back(newgn);
 
76
  //       kDebug() << "new inserted";
 
77
      }
 
78
      else if (dynamic_cast<GraphSubgraph*>(updatingge) != 0)
 
79
      {
 
80
        GraphSubgraph* newsg = new GraphSubgraph(*dynamic_cast<GraphSubgraph*>(updatingge));
 
81
        content().push_back(newsg);
 
82
      }
 
83
    }
 
84
  }
 
85
 
 
86
  if (canvasSubgraph())
 
87
  {
 
88
    canvasSubgraph()->modelChanged();
 
89
    canvasSubgraph()->computeBoundingRect();
 
90
  }
 
91
//   kDebug() << "done";
 
92
}
 
93
 
36
94
 
37
95
QString GraphSubgraph::backColor() const
38
96
{
56
114
  {
57
115
    return DOT_DEFAULT_BACKCOLOR;
58
116
  }
59
 
 
60
 
 
61
 
 
62
 
}
63
 
 
 
117
}
 
118
 
 
119
void GraphSubgraph::removeElement(GraphElement* element)
 
120
{
 
121
  m_content.removeAll(element);
 
122
}
 
123
 
 
124
GraphElement* GraphSubgraph::elementNamed(const QString& id)
 
125
{
 
126
  if (this->id() == id) return this;
 
127
  foreach (GraphElement* element, content())
 
128
  {
 
129
    if (element->id() == id)
 
130
    {
 
131
      return element;
 
132
    }
 
133
    else if (dynamic_cast<GraphSubgraph*>(element))
 
134
    {
 
135
      GraphElement* subgraphElement = dynamic_cast<GraphSubgraph*>(element)->elementNamed(id);
 
136
      if (subgraphElement != 0)
 
137
      {
 
138
        return subgraphElement;
 
139
      }
 
140
    }
 
141
  }
 
142
  return 0;
 
143
}
 
144
 
 
145
bool GraphSubgraph::setElementSelected(
 
146
    GraphElement* element,
 
147
    bool selectValue,
 
148
    bool unselectOthers)
 
149
{
 
150
  if (element)
 
151
    kDebug() << element->id() << selectValue << unselectOthers;
 
152
  bool res = false;
 
153
  if (element == this)
 
154
  {
 
155
    if (isSelected() != selectValue)
 
156
    {
 
157
      setSelected(selectValue);
 
158
      canvasElement()->update();
 
159
    }
 
160
    res = true;
 
161
  }
 
162
  else if (isSelected() && unselectOthers)
 
163
  {
 
164
    setSelected(false);
 
165
    canvasElement()->update();
 
166
  }
 
167
  foreach (GraphElement* el, content())
 
168
  {
 
169
    if (dynamic_cast<GraphSubgraph*>(el) != 0)
 
170
    {
 
171
      bool subres = dynamic_cast<GraphSubgraph*>(el)->setElementSelected(element, selectValue, unselectOthers);
 
172
      if (!res) res = subres;
 
173
    }
 
174
    else if (element == el)
 
175
    {
 
176
      res = true;
 
177
      if (el->isSelected() != selectValue)
 
178
      {
 
179
        el->setSelected(selectValue);
 
180
        el->canvasElement()->update();
 
181
      }
 
182
    }
 
183
    else 
 
184
    {
 
185
      if (unselectOthers && el->isSelected())
 
186
      {
 
187
        el->setSelected(false);
 
188
        el->canvasElement()->update();
 
189
      }
 
190
    }
 
191
  }
 
192
  return res;
 
193
}
 
194
 
 
195
void GraphSubgraph::retrieveSelectedElementsIds(QList<QString> selection)
 
196
{
 
197
  if (isSelected())
 
198
  {
 
199
    selection.push_back(id());
 
200
  }
 
201
  foreach (GraphElement* el, content())
 
202
  {
 
203
    if (dynamic_cast<GraphSubgraph*>(el) != 0)
 
204
    {
 
205
      dynamic_cast<GraphSubgraph*>(el)->retrieveSelectedElementsIds(selection);
 
206
    }
 
207
    else  if (el->isSelected())
 
208
    {
 
209
      selection.push_back(el->id());
 
210
    }
 
211
  }
 
212
}
64
213
 
65
214
QTextStream& operator<<(QTextStream& s, const GraphSubgraph& sg)
66
215
{