forked from OpenDDS/OpenDDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cpp
79 lines (65 loc) · 1.56 KB
/
Node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
*
*
* Distributed under the OpenDDS License.
* See: http://www.opendds.org/license.html
*/
// Tell GCC to ignore implicitly declared copy methods as long as
// Qt is not compliant.
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-copy"
#endif
#include <QtWidgets/QMenu>
#include <QtWidgets/QGraphicsSceneContextMenuEvent>
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif
#include <vector>
#include "Node.h"
#include "Edge.h"
#include "NodeGenerator.h"
Monitor::Node::Node(QString& text, qreal x, qreal y, TreeNode *t, QGraphicsItem * parent):
QGraphicsTextItem(text, parent),
treeNode_(t)
{
setX(x);
setY(y);
setFlag(ItemIsMovable);
setFlag(ItemIsSelectable);
setFlag(ItemSendsGeometryChanges);
setCacheMode(DeviceCoordinateCache);
setZValue(2);
}
void
Monitor::Node::addEdge(Edge *edge)
{
edges_.push_back(edge);
}
void
Monitor::Node::updateEdges()
{
for (unsigned int i = 0; i < edges_.size(); ++i) {
edges_[i]->adjust();
edges_[i]->update();
}
}
void
Monitor::Node::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
{
// set the node color
QPen pen;
pen.setColor(treeNode_->color(1).value<QColor>());
painter->setPen(pen);
// call the base class to draw the text.
this->QGraphicsTextItem::paint(painter, option, widget);
// put a border around the node
painter->drawRect (boundingRect().adjusted(2, 2, -2, -2));
}
void
Monitor::Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
update();
updateEdges();
QGraphicsItem::mouseReleaseEvent(event);
}