Code Documentation 3.4
Social Network Visualizer
Loading...
Searching...
No Matches
graphicswidget.h
Go to the documentation of this file.
1
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 setEdgeWeightNumbersVisibility (const bool &toggle);
173 void setEdgeLabelsVisibility(const bool &toggle);
174
175 void setEdgeHighlighting(const bool &toggle);
176
178
179 void clearGuides();
180 void addGuideCircle( const double&x0, const double&y0, const double&radius);
181 void addGuideHLine(const double &y0);
182
183 void zoomIn(const int step = 1);
184 void zoomOut(const int step = 1);
185 void rotateLeft();
186 void rotateRight();
187 void changeMatrixScale(const int value);
188 void changeMatrixRotation(int angle);
189 void reset();
190
191 void setOptionsOpenGL(const bool &enabled=false);
192 void setOptionsAntialiasing(const bool &toggle);
193 void setOptionsNoAntialiasingAutoAdjust(const bool &toggle);
194
195signals:
196 void userDoubleClickNewNode(const QPointF &);
197 void userMiddleClicked(const int &sourceNum, const int &targetNum, const qreal &weight=1);
198 void userClickOnEmptySpace(const QPointF &p);
200 void openContextMenu(const QPointF p);
201 void userNodeMoved(const int &, const int &, const int &);
202 //void userSelectedItems(const int nodes, const int edges);
203 void userSelectedItems(const QList<int> selectedNodes,
204 const QList<SelectedEdge> selectedEdges);
205 void userClickedNode(const int &nodeNumber, const QPointF &p);
206 void userClickedEdge(const int &source, const int &target, const bool &openMenu=false);
207 void zoomChanged(const int);
208 void rotationChanged(const int);
209 void resized(const int, const int);
210 void setCursor(Qt::CursorShape);
211
212
213private:
214
215 H_NumToNode nodeHash; //Our basic hash table for node items
216 H_StrToEdge edgesHash; // Our basic hash table for edge items
217 QList<int> m_selectedNodes;
218 QList<SelectedEdge> m_selectedEdges;
225 qreal fX,fY, factor;
227 QString edgeName;
236};
237
238#endif
Definition graphicsedgelabel.h:28
Definition graphicsedgeweight.h:28
Definition graphicsedge.h:49
Definition graphicsguide.h:30
Definition graphicsnodelabel.h:26
Definition graphicsnodenumber.h:27
Definition graphicsnode.h:47
Definition graphicswidget.h:41
int m_edgeMinOffsetFromNode
Definition graphicswidget.h:223
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:437
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:289
int m_zoomIndex
Definition graphicswidget.h:221
QString m_labelColor
Definition graphicswidget.h:226
void setNodeSizeAll(const int &size=0)
Changes the size of all nodes.
Definition graphicswidget.cpp:788
bool setNodeLabelSize(const int &, const int &size=0)
Changes the label size of a node to 'size'.
Definition graphicswidget.cpp:894
void setInitNodeSize(int)
Sets initial node size from MW.
Definition graphicswidget.cpp:709
void selectNone()
Clears any item selection from the scene. Also signals that no node is clicked.
Definition graphicswidget.cpp:1360
void setNodeNumberColor(const int &nodeNum, const QString &color)
Changes the color of a node number.
Definition graphicswidget.cpp:820
QString m_numberColor
Definition graphicswidget.h:226
QList< QGraphicsItem * > selectedItems()
Returns a list of all selected QGraphicsItem(s)
Definition graphicswidget.cpp:1388
void setEdgeColor(const int &, const int &, const QString &)
Sets the color of an edge.
Definition graphicswidget.cpp:1005
bool setEdgeDirectionType(const int &source, const int &target, const int &dirType=false)
Changes the direction type of an existing edge.
Definition graphicswidget.cpp:1030
void userDoubleClickNewNode(const QPointF &)
void userMiddleClicked(const int &sourceNum, const int &targetNum, const qreal &weight=1)
QList< SelectedEdge > m_selectedEdges
Definition graphicswidget.h:218
void userNodeMoved(const int &, const int &, const int &)
~GraphicsWidget()
Destructor. Calls the method to clear the data.
Definition graphicswidget.cpp:1818
GraphicsNode * secondDoubleClickedNode
Definition graphicswidget.h:232
void resized(const int, const int)
void userClickedEdge(const int &source, const int &target, const bool &openMenu=false)
bool hasDoubleClickedNode
Definition graphicswidget.h:229
void setNodeLabelsVisibility(const bool &toggle)
Toggles the visibility of all node labels.
Definition graphicswidget.cpp:660
bool setNodeNumberSize(const int &nodeNum, const int &size=0)
Changes the size of the number of a node.
Definition graphicswidget.cpp:837
void changeMatrixRotation(int angle)
Rotates the view transformation by angle degrees clockwise, while preserving the current scale.
Definition graphicswidget.cpp:1729
int markedEdgeSourceOrigSize
Definition graphicswidget.h:222
bool setEdgeWeight(const int &, const int &, const qreal &)
Sets the weight of an edge.
Definition graphicswidget.cpp:1061
void reset()
Resets to default rotation, zoom and scale.
Definition graphicswidget.cpp:1746
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:876
int m_zoomIndexInit
Definition graphicswidget.h:221
void selectAll()
Forces the scene to select all items. Also signals that no node is clicked.
Definition graphicswidget.cpp:1344
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:228
void userClickOnEmptySpace(const QPointF &p)
H_NumToNode nodeHash
Definition graphicswidget.h:215
qreal fY
Definition graphicswidget.h:225
bool m_isTransformationActive
Definition graphicswidget.h:228
QList< SelectedEdge > selectedEdges()
Returns a QList of selected directed edges structs in the form of v1,v2.
Definition graphicswidget.cpp:1417
void setEdgeClicked(GraphicsEdge *, const bool &openMenu=false)
Sets the clicked edge.
Definition graphicswidget.cpp:403
void setNumbersInsideNodes(const bool &toggle)
Toggles displaying node numbers in or out of nodes.
Definition graphicswidget.cpp:690
void setOptionsOpenGL(const bool &enabled=false)
Toggles openGL.
Definition graphicswidget.cpp:104
void zoomIn(const int step=1)
Increases the numerical zoom index of the scene by the given step.
Definition graphicswidget.cpp:1659
void setNodeClicked(GraphicsNode *)
Clears clickedEdge and emits a signal to Graph.
Definition graphicswidget.cpp:377
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:731
void removeNode(const int &nodeNum)
Deletes the node with the given number from the scene, if exists.
Definition graphicswidget.cpp:451
bool setNodeShape(const int &nodeNum, const QString &shape, const QString &iconPath=QString())
Sets the shape of an node.
Definition graphicswidget.cpp:643
bool setNodeLabelDistance(const int &, const int &distance=0)
Changes the distance of the label of the given node.
Definition graphicswidget.cpp:916
bool setNodeNumberDistance(const int &, const int &distance=0)
Changes the distance of the number of a node.
Definition graphicswidget.cpp:856
void relationSet(int relation)
Changes the current relation.
Definition graphicswidget.cpp:201
void userSelectedItems(const QList< int > selectedNodes, const QList< SelectedEdge > selectedEdges)
void mousePressEvent(QMouseEvent *e)
Handles the mouse press event.
Definition graphicswidget.cpp:1475
QList< int > m_selectedNodes
Definition graphicswidget.h:217
void addGuideCircle(const double &x0, const double &y0, const double &radius)
Adds a circular guideline.
Definition graphicswidget.cpp:1294
bool clickedEdgeExists
Definition graphicswidget.h:229
void zoomOut(const int step=1)
Decreases the numerical zoom index of the scene by the given step.
Definition graphicswidget.cpp:1639
QList< int > selectedNodes()
Returns a List of selected node numbers.
Definition graphicswidget.cpp:1399
void handleSelectionChanged()
Handles the event of selection change in the scene.
Definition graphicswidget.cpp:1374
int m_nodeSize
Definition graphicswidget.h:219
double m_currentScaleFactor
Definition graphicswidget.h:224
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:1113
void resizeEvent(QResizeEvent *e)
Handles the canvas resize event.
Definition graphicswidget.cpp:1764
void setAllItemsVisibility(int, bool)
Toggles the visibility of all items of the given type.
Definition graphicswidget.cpp:1275
void clearGuides()
Definition graphicswidget.cpp:1334
bool setNodeSize(const int &nodeNumber, const int &size=0)
Changes the size of a node.
Definition graphicswidget.cpp:762
void setSelectedNodes(QList< int > list)
Selects all nodes in the given list.
Definition graphicswidget.cpp:959
void setEdgeLabel(const int &source, const int &target, const QString &label)
Sets the label of an edge.
Definition graphicswidget.cpp:980
GraphicsNode * markedEdgeSource
Definition graphicswidget.h:233
void rotateRight()
Rotates the view to the right, by a fixed angle.
Definition graphicswidget.cpp:1718
void setOptionsAntialiasing(const bool &toggle)
Toggles QPainter render hints for primitive edges and text antialiasing.
Definition graphicswidget.cpp:130
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:475
int markedEdgeTargetOrigSize
Definition graphicswidget.h:222
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:167
void setOptionsNoAntialiasingAutoAdjust(const bool &toggle)
Toggles QGraphicsView's antialiasing auto-adjustment of exposed areas.
Definition graphicswidget.cpp:148
void clear()
Clears the scene and all hashes, lists, var etc.
Definition graphicswidget.cpp:178
void mouseReleaseEvent(QMouseEvent *e)
Handles the mouse release events.
Definition graphicswidget.cpp:1573
qreal fX
Definition graphicswidget.h:225
void openContextMenu(const QPointF p)
void addGuideHLine(const double &y0)
Adds a horizonal guideline.
Definition graphicswidget.cpp:1307
void setEdgeArrowsVisibility(const bool &toggle)
Toggles the visibility of all edge arrows.
Definition graphicswidget.cpp:1096
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:1207
bool m_nodeLabelVisibility
Definition graphicswidget.h:230
void setCursor(Qt::CursorShape)
void setEdgeLabelsVisibility(const bool &toggle)
Toggles all edge labels visibility.
Definition graphicswidget.cpp:1164
QString edgeName
Definition graphicswidget.h:227
void setNodeVisibility(const int &nodeNum, const bool &toggle)
Changes the visibility of a Node.
Definition graphicswidget.cpp:745
int m_curRelation
Definition graphicswidget.h:219
void mouseDoubleClickEvent(QMouseEvent *e)
Handles user double-clicks.
Definition graphicswidget.cpp:1441
void rotateLeft()
Decreases the numerical rotation Rotates the view to the left, by a fixed angle.
Definition graphicswidget.cpp:1709
void openNodeMenu()
QString m_nodeLabel
Definition graphicswidget.h:226
void rotationChanged(const int)
void setNodeNumberVisibility(const bool &toggle)
Toggles the visibility of node numbers.
Definition graphicswidget.cpp:803
void changeMatrixScale(const int value)
Does the actual zoom in or out while preserving current rotation.
Definition graphicswidget.cpp:1680
int m_zoomIndexMax
Definition graphicswidget.h:221
GraphicsEdge * clickedEdge
Definition graphicswidget.h:235
GraphicsNode * firstDoubleClickedNode
Definition graphicswidget.h:232
bool m_edgeHighlighting
Definition graphicswidget.h:231
void setEdgeWeightNumbersVisibility(const bool &toggle)
Toggles all edge weight numbers visibility.
Definition graphicswidget.cpp:1151
void handleDoubleClickOnNode(GraphicsNode *node)
Handles double-clicks (or middle-clicks) on the given node, creating a new edge if needed.
Definition graphicswidget.cpp:347
bool setNodeLabel(const int &, const QString &label)
Sets the label of an node.
Definition graphicswidget.cpp:676
bool m_nodeNumberVisibility
Definition graphicswidget.h:230
bool m_nodeNumbersInside
Definition graphicswidget.h:230
GraphicsNode * markedEdgeTarget
Definition graphicswidget.h:234
void setInitZoomIndex(const int &)
Sets the initial zoom setting. Use setMaxZoomIndex() instead.
Definition graphicswidget.cpp:721
void removeItem(GraphicsEdge *)
Removes an edge item from the scene.
Definition graphicswidget.cpp:551
void removeAllItems(int)
Removes all items of the given type.
Definition graphicswidget.cpp:1318
void setEdgeHighlighting(const bool &toggle)
Enables or disables edge highlighting.
Definition graphicswidget.cpp:1183
bool setNodeColor(const int &nodeNum, const QString &color)
Sets the color of an node.
Definition graphicswidget.cpp:627
GraphicsNode * hasNode(QString text)
Checks if a node with label or nodeNum 'text' exists and returns it.
Definition graphicswidget.cpp:937
qreal factor
Definition graphicswidget.h:225
void wheelEvent(QWheelEvent *event)
Handles the mouse wheel event. If CTRL is pressed, zooms in or out.
Definition graphicswidget.cpp:1618
int m_currentRotationAngle
Definition graphicswidget.h:220
H_StrToEdge edgesHash
Definition graphicswidget.h:216
The base window of SocNetV contains all widgets and functionality.
Definition mainwindow.h:104
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