Computer Assisted Medical Intervention Tool Kit version 6.0
 
Loading...
Searching...
No Matches
GraphDisplayWidget.h
Go to the documentation of this file.
1/*****************************************************************************
2 * $CAMITK_LICENCE_BEGIN$
3 *
4 * CamiTK - Computer Assisted Medical Intervention ToolKit
5 * (c) 2001-2025 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
6 *
7 * Visit http://camitk.imag.fr for more information
8 *
9 * This file is part of CamiTK.
10 *
11 * CamiTK is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * CamiTK is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22 *
23 * $CAMITK_LICENCE_END$
24 ****************************************************************************/
25
26
27#ifndef GRAPHDISPLAYWIDGET_H
28#define GRAPHDISPLAYWIDGET_H
29
30#include "CamiTKAPI.h"
31
32// Qt Stuff
33#include <QObject>
34#include <QGraphicsView>
35#include <QGraphicsScene>
36#include <QGraphicsItem>
37#include <QColor>
38#include <QPen>
39#include <QVector>
40#include <QMap>
41
42namespace camitk {
43
51class CAMITK_API GraphDisplayWidget : public QGraphicsView {
52 Q_OBJECT
53
54public:
56 GraphDisplayWidget(QWidget* parent = nullptr);
57
59 virtual ~GraphDisplayWidget();
60
64 void clear();
74 void addNode(const void* ptr, QString tooltip, QColor color, QColor lineColor, QString internalText = "");
85 void addLink(const void* ptr, const void* from, const void* to, QString tooltip, const QPen& pen, bool arrowHead);
86
90 void refresh();
91
95 void autoScale();
96
100 void setNodeDiameter(float d);
101
102signals:
107 void nodeSelectionChanged(const void* node);
108
113 void linkSelectionChanged(const void* link);
114
116 void nodeDoubleClicked(const void* node);
117
119 void linkDoubleClicked(const void* node);
120
121public slots:
126 void setSelectedNode(const void* node);
131 void setSelectedLink(const void* link);
132
134 void updateView();
135
136protected:
138 void mouseDoubleClickEvent(QMouseEvent*) override;
139
141 void resizeEvent(QResizeEvent*) override;
142
143 // make sure the scene fits all the potentially moved nodes
144 void mouseReleaseEvent(QMouseEvent* e) override;
145
146private:
148 double diameter;
149
151 double halfPenWidth;
152
155 QMap<const void*, QGraphicsEllipseItem*> node2item;
156 // same but for internal text decoration
157 QMap<const void*, QGraphicsSimpleTextItem*> node2textItem;
159 QMap<QGraphicsEllipseItem*, const void*> item2node;
161 QMap<QGraphicsSimpleTextItem*, const void*> textItem2node;
162
164 QMap<const void*, QGraphicsLineItem*> link2item;
165 // same but for the arrow heads
166 QMap<const void*, QGraphicsPolygonItem*> link2arrowHead;
168 QMap<QGraphicsLineItem*, const void*> item2link;
169
170 // Selections
171 const void* currentSelectedNode;
172 const void* currentSelectedLink;
173
174 // Pens to manage to selected/unselected
175 QPen selectedPen;
176 QMap<const void*, QPen> unselectedPen;
177
178 // For each link, from and to nodes
179 QMap<const void*, std::pair<const void*, const void*>> links;
180 // nodeArity[nodeObjectPtr] is the number of links from and to the node
181 QMap<const void*, int> nodeArity;
182
183 // Move the graphical representation of a node in the canvas
184 void moveNode(const void* ptr, float posX, float posY);
185 // Move the graphical representation of a link in the canvas
186 void moveLink(const void* ptr, float posX1, float posY1, float posX2, float posY2);
187
188
189
190 // update link position using the node (new) center, called when nodes are moved
191 void updateLinkPosition();
192
193 // currently being update, n
194};
195
196} // namespace camitk
197#endif // GRAPHDISPLAYWIDGET_H
#define CAMITK_API
Definition CamiTKAPI.h:66
GraphDisplayWidget is used to manage a Widget to display a graph with nodes and links onto a 2D canva...
Definition GraphDisplayWidget.h:51
void nodeDoubleClicked(const void *node)
node was double clicked
void linkSelectionChanged(const void *link)
Signal emitted when a link was selected in the 2D canvas It sends the pointer to the object represent...
void linkDoubleClicked(const void *node)
link was double clicked
void nodeSelectionChanged(const void *node)
Signal emitted when a node was selected in the 2D canvas It sends the pointer to the object represent...
Definition Action.cpp:40