Code Documentation 3.6
Social Network Visualizer
Loading...
Searching...
No Matches
graphicswidget.h
Go to the documentation of this file.
1
15
16
17#ifndef GRAPHICSWIDGET_H
18#define GRAPHICSWIDGET_H
19
20
21#include <QGraphicsView>
22#include <QHash>
23#include "global.h"
24
26
27class MainWindow;
28class GraphicsNode;
29class GraphicsEdge;
32class GraphicsGuide;
35
36typedef QHash<QString, GraphicsEdge*> H_StrToEdge;
37typedef QHash <int, GraphicsNode*> H_NumToNode;
38
39
40
41class GraphicsWidget : public QGraphicsView {
42 Q_OBJECT
43
44public:
45
46 GraphicsWidget(QGraphicsScene *m_scene, MainWindow *m_parent);
48
49 void clear();
50
51 QString createEdgeName(const int &v1,
52 const int &v2,
53 const int &relation=-1);
54
55 void setInitNodeSize(int);
56
57 void setInitZoomIndex (const int &);
58 void setMaxZoomIndex (const int &);
59
60 GraphicsNode* hasNode(QString text);
61 void setSelectedNodes(QList<int> list);
62
63 QList<QGraphicsItem *> selectedItems();
64 QList<int> selectedNodes();
65 QList<SelectedEdge> selectedEdges();
66
67 void selectAll();
68 void selectNone();
69
71 void removeItem(GraphicsEdgeWeight *edgeWeight);
72 void removeItem(GraphicsEdgeLabel *edgeLabel);
76
77 void setNumbersInsideNodes(const bool &toggle);
78
79 void setAllItemsVisibility(int, bool);
80
81 void removeAllItems(int);
82
83protected:
84
85 void wheelEvent(QWheelEvent *event);
86 void mouseDoubleClickEvent ( QMouseEvent * e );
87 void mousePressEvent ( QMouseEvent * e );
88 void mouseReleaseEvent(QMouseEvent * e );
89 void resizeEvent( QResizeEvent *e );
90
91public slots:
92
94
95 void relationSet(int relation);
96
97 void drawNode(const QPointF &p,
98 const int &num,
99 const int &nodeSize,
100 const QString &nodeShape,
101 const QString &nodeIconPath,
102 const QString &nodeColor,
103 const QString &numberColor,
104 const int &numberSize,
105 const int &numberDistance,
106 const QString &nodeLabel,
107 const QString &labelColor,
108 const int &labelSize,
109 const int &labelDistance);
110 void removeNode(const int &nodeNum);
111 void setNodeVisibility(const int &nodeNum, const bool &toggle ); //Called from Graph via MW
113 void moveNode(const int &num, const qreal &x, const qreal &y);
114
115 bool setNodeSize(const int &nodeNumber, const int &size=0);
116 void setNodeSizeAll(const int &size=0);
117
118 bool setNodeShape(const int &nodeNum,
119 const QString &shape,
120 const QString &iconPath=QString());
121 bool setNodeColor(const int &nodeNum, const QString &color);
122
123 void setNodeNumberColor(const int &nodeNum, const QString &color);
124 void setNodeNumberVisibility(const bool &toggle);
125 bool setNodeNumberSize(const int &nodeNum, const int &size=0);
126 bool setNodeNumberDistance(const int &, const int &distance=0);
127
128 void setNodeLabelsVisibility(const bool &toggle);
129 bool setNodeLabelColor(const int &nodeNum, const QString &color="green");
130 bool setNodeLabelSize(const int &, const int &size=0);
131 bool setNodeLabel(const int & , const QString &label);
132 bool setNodeLabelDistance(const int &, const int &distance=0);
133
134 void drawEdge(const int &source,
135 const int &target,
136 const qreal &weight,
137 const QString &label="",
138 const QString &color="black",
139 const int &type=0,
140 const bool &drawArrows=true,
141 const bool &bezier=false,
142 const bool &weightNumbers=false);
143
144 void removeEdge(const int &source,
145 const int &target,
146 const bool &removeOpposite=false);
147
148 void setEdgeVisibility (const int &relation,
149 const int &sourceNum,
150 const int &targetNum,
151 const bool &visible,
152 const bool &preserveReverseEdge=false,
153 const int &edgeWeight=1,
154 const int &reverseEdgeWeight=1);
155
156 bool setEdgeDirectionType(const int &source,
157 const int &target,
158 const int &dirType=false);
159
160 bool setEdgeWeight(const int &, const int &, const qreal &);
161
162 void setEdgeLabel(const int &source, const int &target, const QString &label);
163
164 void setEdgeColor(const int &, const int&, const QString &);
165
166 void setEdgeClicked(GraphicsEdge *, const bool &openMenu=false);
167
168 void setEdgeOffsetFromNode(const int &source,
169 const int &target,
170 const int &offset);
171 void setEdgeArrowsVisibility(const bool &toggle);
172 void setEdgeArrowSize(const int &size);
173 void setEdgeWeightNumbersVisibility (const bool &toggle);
174 void setEdgeLabelsVisibility(const bool &toggle);
175
176 void setEdgesBezier(const bool &toggle);
177
178 void setEdgeHighlighting(const bool &toggle);
179
181
182 void clearGuides();
183 void addGuideCircle( const double&x0, const double&y0, const double&radius);
184 void addGuideHLine(const double &y0);
185
186 void zoomIn(const int step = 1);
187 void zoomOut(const int step = 1);
188 void rotateLeft();
189 void rotateRight();
190 void changeMatrixScale(const int value);
191 void changeMatrixRotation(int angle);
192 void reset();
193
194 void setOptionsOpenGL(const bool &enabled=false);
195 void setOptionsAntialiasing(const bool &toggle);
196 void setOptionsNoAntialiasingAutoAdjust(const bool &toggle);
197
198signals:
199 void userDoubleClickNewNode(const QPointF &);
200 void userMiddleClicked(const int &sourceNum, const int &targetNum, const qreal &weight=1);
201 void userClickOnEmptySpace(const QPointF &p);
203 void openContextMenu(const QPointF p);
204 void userNodeMoved(const int &, const int &, const int &);
205 //void userSelectedItems(const int nodes, const int edges);
206 void userSelectedItems(const QList<int> selectedNodes,
207 const QList<SelectedEdge> selectedEdges);
208 void userClickedNode(const int &nodeNumber, const QPointF &p);
209 void userClickedEdge(const int &source, const int &target, const bool &openMenu=false);
210 void zoomChanged(const int);
211 void rotationChanged(const int);
212 void resized(const int, const int);
213 void setCursor(Qt::CursorShape);
214
215
216private:
217
218 H_NumToNode nodeHash; //Our basic hash table for node items
219 H_StrToEdge edgesHash; // Our basic hash table for edge items
220 QList<int> m_selectedNodes;
221 QList<SelectedEdge> m_selectedEdges;
229 qreal fX,fY, factor;
231 QString edgeName;
241};
242
243#endif
Definition graphicsedge.h:51
Definition graphicsedgelabel.h:28
Definition graphicsedgeweight.h:28
Definition graphicsguide.h:30
Definition graphicsnode.h:49
Definition graphicsnodelabel.h:26
Definition graphicsnodenumber.h:27
int m_edgeMinOffsetFromNode
Definition graphicswidget.h:226
void moveNode(const int &num, const qreal &x, const qreal &y)
Moves the node with the given number to the new coordinates.
Definition graphicswidget.cpp:441
void drawEdge(const int &source, const int &target, const qreal &weight, const QString &label="", const QString &color="black", const int &type=0, const bool &drawArrows=true, const bool &bezier=false, const bool &weightNumbers=false)
Draws a new edge in the scene, from node with sourceNum to node with targetNum.
Definition graphicswidget.cpp:292
int m_zoomIndex
Definition graphicswidget.h:224
QString m_labelColor
Definition graphicswidget.h:230
void setNodeSizeAll(const int &size=0)
Changes the size of all nodes.
Definition graphicswidget.cpp:796
bool setNodeLabelSize(const int &, const int &size=0)
Changes the label size of a node to 'size'.
Definition graphicswidget.cpp:906
void setInitNodeSize(int)
Sets initial node size from MW.
Definition graphicswidget.cpp:717
void selectNone()
Clears any item selection from the scene. Also signals that no node is clicked.
Definition graphicswidget.cpp:1415
void setNodeNumberColor(const int &nodeNum, const QString &color)
Changes the color of a node number.
Definition graphicswidget.cpp:832
QString m_numberColor
Definition graphicswidget.h:230
QList< QGraphicsItem * > selectedItems()
Returns a list of all selected QGraphicsItem(s).
Definition graphicswidget.cpp:1440
void setEdgeColor(const int &, const int &, const QString &)
Sets the color of an edge.
Definition graphicswidget.cpp:1017
bool setEdgeDirectionType(const int &source, const int &target, const int &dirType=false)
Changes the direction type of an existing edge.
Definition graphicswidget.cpp:1042
void userDoubleClickNewNode(const QPointF &)
int m_arrowSize
Definition graphicswidget.h:227
void userMiddleClicked(const int &sourceNum, const int &targetNum, const qreal &weight=1)
QList< SelectedEdge > m_selectedEdges
Definition graphicswidget.h:221
void userNodeMoved(const int &, const int &, const int &)
~GraphicsWidget()
Destructor. Calls the method to clear the data.
Definition graphicswidget.cpp:1879
GraphicsNode * secondDoubleClickedNode
Definition graphicswidget.h:237
void resized(const int, const int)
void userClickedEdge(const int &source, const int &target, const bool &openMenu=false)
bool hasDoubleClickedNode
Definition graphicswidget.h:233
void setNodeLabelsVisibility(const bool &toggle)
Toggles the visibility of all node labels.
Definition graphicswidget.cpp:664
bool setNodeNumberSize(const int &nodeNum, const int &size=0)
Changes the size of the number of a node.
Definition graphicswidget.cpp:849
void changeMatrixRotation(int angle)
Rotates the view transformation by angle degrees clockwise, while preserving the current scale.
Definition graphicswidget.cpp:1790
int markedEdgeSourceOrigSize
Definition graphicswidget.h:225
GraphicsWidget(QGraphicsScene *m_scene, MainWindow *m_parent)
Constructs a GraphicsWidget object.
Definition graphicswidget.cpp:48
bool setEdgeWeight(const int &, const int &, const qreal &)
Sets the weight of an edge.
Definition graphicswidget.cpp:1073
void reset()
Resets to default rotation, zoom and scale.
Definition graphicswidget.cpp:1807
void userClickedNode(const int &nodeNumber, const QPointF &p)
bool setNodeLabelColor(const int &nodeNum, const QString &color="green")
Changes the label color of a node to 'color'.
Definition graphicswidget.cpp:888
int m_zoomIndexInit
Definition graphicswidget.h:224
void selectAll()
Forces the scene to select all items. Also signals that no node is clicked.
Definition graphicswidget.cpp:1399
void drawNode(const QPointF &p, const int &num, const int &nodeSize, const QString &nodeShape, const QString &nodeIconPath, const QString &nodeColor, const QString &numberColor, const int &numberSize, const int &numberDistance, const QString &nodeLabel, const QString &labelColor, const int &labelSize, const int &labelDistance)
Draws a new node in the scene.
Definition graphicswidget.cpp:231
void userClickOnEmptySpace(const QPointF &p)
void setEdgeArrowSize(const int &size)
Sets the arrow size for all edges and stores it as the default for new edges.
Definition graphicswidget.cpp:1128
H_NumToNode nodeHash
Definition graphicswidget.h:218
qreal fY
Definition graphicswidget.h:229
bool m_isTransformationActive
Definition graphicswidget.h:232
QList< SelectedEdge > selectedEdges()
Returns a QList of selected directed edges structs in the form of v1,v2.
Definition graphicswidget.cpp:1467
void setEdgeClicked(GraphicsEdge *, const bool &openMenu=false)
Sets the clicked edge.
Definition graphicswidget.cpp:407
void setNumbersInsideNodes(const bool &toggle)
Toggles displaying node numbers in or out of nodes.
Definition graphicswidget.cpp:696
void setOptionsOpenGL(const bool &enabled=false)
Toggles openGL.
Definition graphicswidget.cpp:107
void zoomIn(const int step=1)
Increases the numerical zoom index of the scene by the given step.
Definition graphicswidget.cpp:1720
void setNodeClicked(GraphicsNode *)
Clears clickedEdge and emits a signal to Graph.
Definition graphicswidget.cpp:381
void setMaxZoomIndex(const int &)
Sets the max zoom allowed (and the initial zoom as half of it). Called from MW on startup.
Definition graphicswidget.cpp:739
void removeNode(const int &nodeNum)
Deletes the node with the given number from the scene, if exists.
Definition graphicswidget.cpp:455
bool setNodeShape(const int &nodeNum, const QString &shape, const QString &iconPath=QString())
Sets the shape of an node.
Definition graphicswidget.cpp:647
bool setNodeLabelDistance(const int &, const int &distance=0)
Changes the distance of the label of the given node.
Definition graphicswidget.cpp:928
bool setNodeNumberDistance(const int &, const int &distance=0)
Changes the distance of the number of a node.
Definition graphicswidget.cpp:868
void relationSet(int relation)
Changes the current relation.
Definition graphicswidget.cpp:204
void userSelectedItems(const QList< int > selectedNodes, const QList< SelectedEdge > selectedEdges)
void mousePressEvent(QMouseEvent *e)
Handles the mouse press event.
Definition graphicswidget.cpp:1524
QList< int > m_selectedNodes
Definition graphicswidget.h:220
void addGuideCircle(const double &x0, const double &y0, const double &radius)
Adds a circular guideline.
Definition graphicswidget.cpp:1349
bool clickedEdgeExists
Definition graphicswidget.h:233
bool m_edgesBezier
Definition graphicswidget.h:236
void zoomOut(const int step=1)
Decreases the numerical zoom index of the scene by the given step.
Definition graphicswidget.cpp:1700
QList< int > selectedNodes()
Returns a List of selected node numbers.
Definition graphicswidget.cpp:1450
void handleSelectionChanged()
Handles the event of selection change in the scene.
Definition graphicswidget.cpp:1429
int m_nodeSize
Definition graphicswidget.h:222
double m_currentScaleFactor
Definition graphicswidget.h:228
void setEdgeOffsetFromNode(const int &source, const int &target, const int &offset)
Changes the offset of an edge (or all edges) from source and target nodes.
Definition graphicswidget.cpp:1144
void resizeEvent(QResizeEvent *e)
Handles the canvas resize event.
Definition graphicswidget.cpp:1825
void setAllItemsVisibility(int, bool)
Toggles the visibility of all items of the given type.
Definition graphicswidget.cpp:1320
void clearGuides()
Definition graphicswidget.cpp:1389
bool setNodeSize(const int &nodeNumber, const int &size=0)
Changes the size of a node.
Definition graphicswidget.cpp:770
void setSelectedNodes(QList< int > list)
Selects all nodes in the given list.
Definition graphicswidget.cpp:971
void setEdgesBezier(const bool &toggle)
Definition graphicswidget.cpp:1225
void setEdgeLabel(const int &source, const int &target, const QString &label)
Sets the label of an edge.
Definition graphicswidget.cpp:992
GraphicsNode * markedEdgeSource
Definition graphicswidget.h:238
void rotateRight()
Rotates the view to the right, by a fixed angle.
Definition graphicswidget.cpp:1779
void setOptionsAntialiasing(const bool &toggle)
Toggles QPainter render hints for primitive edges and text antialiasing.
Definition graphicswidget.cpp:133
void removeEdge(const int &source, const int &target, const bool &removeOpposite=false)
Removes the edge from node sourceNum to node targetNum from the scene.
Definition graphicswidget.cpp:479
int markedEdgeTargetOrigSize
Definition graphicswidget.h:225
void zoomChanged(const int)
QString createEdgeName(const int &v1, const int &v2, const int &relation=-1)
Creates a QString with the edge name.
Definition graphicswidget.cpp:170
void setOptionsNoAntialiasingAutoAdjust(const bool &toggle)
Toggles QGraphicsView's antialiasing auto-adjustment of exposed areas.
Definition graphicswidget.cpp:151
void clear()
Clears the scene and all hashes, lists, var etc.
Definition graphicswidget.cpp:181
void mouseReleaseEvent(QMouseEvent *e)
Handles the mouse release events.
Definition graphicswidget.cpp:1634
qreal fX
Definition graphicswidget.h:229
void openContextMenu(const QPointF p)
void addGuideHLine(const double &y0)
Adds a horizonal guideline.
Definition graphicswidget.cpp:1362
void setEdgeArrowsVisibility(const bool &toggle)
Toggles the visibility of all edge arrows.
Definition graphicswidget.cpp:1108
void setEdgeVisibility(const int &relation, const int &sourceNum, const int &targetNum, const bool &visible, const bool &preserveReverseEdge=false, const int &edgeWeight=1, const int &reverseEdgeWeight=1)
Toggles the visibility of the given edge.
Definition graphicswidget.cpp:1244
bool m_nodeLabelVisibility
Definition graphicswidget.h:234
void setCursor(Qt::CursorShape)
void setEdgeLabelsVisibility(const bool &toggle)
Toggles all edge labels visibility.
Definition graphicswidget.cpp:1190
QString edgeName
Definition graphicswidget.h:231
void setNodeVisibility(const int &nodeNum, const bool &toggle)
Changes the visibility of a Node.
Definition graphicswidget.cpp:753
int m_curRelation
Definition graphicswidget.h:222
void mouseDoubleClickEvent(QMouseEvent *e)
Handles user double-clicks.
Definition graphicswidget.cpp:1490
void rotateLeft()
Decreases the numerical rotation Rotates the view to the left, by a fixed angle.
Definition graphicswidget.cpp:1770
void openNodeMenu()
QString m_nodeLabel
Definition graphicswidget.h:230
void rotationChanged(const int)
void setNodeNumberVisibility(const bool &toggle)
Toggles the visibility of node numbers.
Definition graphicswidget.cpp:813
void changeMatrixScale(const int value)
Does the actual zoom in or out while preserving current rotation.
Definition graphicswidget.cpp:1741
int m_zoomIndexMax
Definition graphicswidget.h:224
GraphicsEdge * clickedEdge
Definition graphicswidget.h:240
GraphicsNode * firstDoubleClickedNode
Definition graphicswidget.h:237
bool m_edgeHighlighting
Definition graphicswidget.h:235
void setEdgeWeightNumbersVisibility(const bool &toggle)
Toggles all edge weight numbers visibility.
Definition graphicswidget.cpp:1175
void handleDoubleClickOnNode(GraphicsNode *node)
Handles double-clicks (or middle-clicks) on the given node, creating a new edge if needed.
Definition graphicswidget.cpp:351
bool setNodeLabel(const int &, const QString &label)
Sets the label of an node.
Definition graphicswidget.cpp:682
bool m_nodeNumberVisibility
Definition graphicswidget.h:234
bool m_nodeNumbersInside
Definition graphicswidget.h:234
GraphicsNode * markedEdgeTarget
Definition graphicswidget.h:239
void setInitZoomIndex(const int &)
Sets the initial zoom setting. Use setMaxZoomIndex() instead.
Definition graphicswidget.cpp:729
void removeItem(GraphicsEdge *)
Removes an edge item from the scene.
Definition graphicswidget.cpp:555
void removeAllItems(int)
Removes all items of the given type.
Definition graphicswidget.cpp:1373
void setEdgeHighlighting(const bool &toggle)
Enables or disables edge highlighting.
Definition graphicswidget.cpp:1211
bool setNodeColor(const int &nodeNum, const QString &color)
Sets the color of an node.
Definition graphicswidget.cpp:631
GraphicsNode * hasNode(QString text)
Checks if a node with label or nodeNum 'text' exists and returns it.
Definition graphicswidget.cpp:949
qreal factor
Definition graphicswidget.h:229
void wheelEvent(QWheelEvent *event)
Handles the mouse wheel event. If CTRL is pressed, zooms in or out.
Definition graphicswidget.cpp:1679
int m_currentRotationAngle
Definition graphicswidget.h:223
H_StrToEdge edgesHash
Definition graphicswidget.h:219
The base window of SocNetV contains all widgets and functionality.
Definition mainwindow.h:112
Global definitions, constants, enumerations, and utility types for SocNetV.
#define SOCNETV_USE_NAMESPACE
Definition global.h:28
QHash< int, GraphicsNode * > H_NumToNode
Definition graphicswidget.h:37
QHash< QString, GraphicsEdge * > H_StrToEdge
Definition graphicswidget.h:36