Code Documentation 3.1
Social Network Visualizer
|
#include <graphicswidget.h>
Public Slots | |
void | handleSelectionChanged () |
Handles the event of selection change in the scene. | |
void | relationSet (int relation) |
Changes the current relation. | |
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. | |
void | removeNode (const int &nodeNum) |
Deletes the node with the given number from the scene, if exists. | |
void | setNodeVisibility (const int &nodeNum, const bool &toggle) |
Changes the visibility of a Node. | |
void | setNodeClicked (GraphicsNode *) |
Clears clickedEdge and emits a signal to Graph. | |
void | moveNode (const int &num, const qreal &x, const qreal &y) |
Moves the node with the given number to the new coordinates. | |
bool | setNodeSize (const int &nodeNumber, const int &size=0) |
Changes the size of a node. | |
void | setNodeSizeAll (const int &size=0) |
Changes the size of all nodes. | |
bool | setNodeShape (const int &nodeNum, const QString &shape, const QString &iconPath=QString()) |
Sets the shape of an node. | |
bool | setNodeColor (const int &nodeNum, const QString &color) |
Sets the color of an node. | |
void | setNodeNumberColor (const int &nodeNum, const QString &color) |
Changes the color of a node number. | |
void | setNodeNumberVisibility (const bool &toggle) |
Toggles the visibility of node numbers. | |
bool | setNodeNumberSize (const int &nodeNum, const int &size=0) |
Changes the size of the number of a node. | |
bool | setNodeNumberDistance (const int &, const int &distance=0) |
Changes the distance of the number of a node. | |
void | setNodeLabelsVisibility (const bool &toggle) |
Toggles the visibility of all node labels. | |
bool | setNodeLabelColor (const int &nodeNum, const QString &color="green") |
Changes the label color of a node to 'color'. | |
bool | setNodeLabelSize (const int &, const int &size=0) |
Changes the label size of a node to 'size'. | |
bool | setNodeLabel (const int &, const QString &label) |
Sets the label of an node. | |
bool | setNodeLabelDistance (const int &, const int &distance=0) |
Changes the distance of the label of the given node. | |
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. | |
void | removeEdge (const int &source, const int &target, const bool &removeOpposite=false) |
Removes the edge from node sourceNum to node targetNum from the scene. | |
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. | |
bool | setEdgeDirectionType (const int &source, const int &target, const int &dirType=false) |
Changes the direction type of an existing edge. | |
bool | setEdgeWeight (const int &, const int &, const qreal &) |
Sets the weight of an edge. | |
void | setEdgeLabel (const int &source, const int &target, const QString &label) |
Sets the label of an edge. | |
void | setEdgeColor (const int &, const int &, const QString &) |
Sets the color of an edge. | |
void | setEdgeClicked (GraphicsEdge *, const bool &openMenu=false) |
Sets the clicked edge. | |
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. | |
void | setEdgeArrowsVisibility (const bool &toggle) |
Toggles the visibility of all edge arrows. | |
void | setEdgeWeightNumbersVisibility (const bool &toggle) |
Toggles all edge weight numbers visibility. | |
void | setEdgeLabelsVisibility (const bool &toggle) |
Toggles all edge labels visibility. | |
void | setEdgeHighlighting (const bool &toggle) |
Enables or disables edge highlighting. | |
void | handleDoubleClickOnNode (GraphicsNode *node) |
Handles double-clicks (or middle-clicks) on the given node, creating a new edge if needed. | |
void | clearGuides () |
void | addGuideCircle (const double &x0, const double &y0, const double &radius) |
Adds a circular guideline. | |
void | addGuideHLine (const double &y0) |
Adds a horizonal guideline. | |
void | zoomIn (const int step=1) |
Increases the numerical zoom index of the scene by the given step. | |
void | zoomOut (const int step=1) |
Decreases the numerical zoom index of the scene by the given step. | |
void | rotateLeft () |
Decreases the numerical rotation Rotates the view to the left, by a fixed angle. | |
void | rotateRight () |
Rotates the view to the right, by a fixed angle. | |
void | changeMatrixScale (const int value) |
Does the actual zoom in or out while preserving current rotation. | |
void | changeMatrixRotation (int angle) |
Rotates the view transformation by angle degrees clockwise, while preserving the current scale. | |
void | reset () |
Resets to default rotation, zoom and scale. | |
void | setOptionsOpenGL (const bool &enabled=false) |
Toggles openGL. | |
void | setOptionsAntialiasing (const bool &toggle) |
Toggles QPainter render hints for primitive edges and text antialiasing. | |
void | setOptionsNoAntialiasingAutoAdjust (const bool &toggle) |
Toggles QGraphicsView's antialiasing auto-adjustment of exposed areas. | |
Signals | |
void | userDoubleClickNewNode (const QPointF &) |
void | userMiddleClicked (const int &sourceNum, const int &targetNum, const qreal &weight=1) |
void | userClickOnEmptySpace (const QPointF &p) |
void | openNodeMenu () |
void | openContextMenu (const QPointF p) |
void | userNodeMoved (const int &, const int &, const int &) |
void | userSelectedItems (const QList< int > selectedNodes, const QList< SelectedEdge > selectedEdges) |
void | userClickedNode (const int &nodeNumber, const QPointF &p) |
void | userClickedEdge (const int &source, const int &target, const bool &openMenu=false) |
void | zoomChanged (const int) |
void | rotationChanged (const int) |
void | resized (const int, const int) |
void | setCursor (Qt::CursorShape) |
Public Member Functions | |
GraphicsWidget (QGraphicsScene *m_scene, MainWindow *m_parent) | |
Constructs a GraphicsWidget object. | |
~GraphicsWidget () | |
Destructor. Calls the method to clear the data. | |
void | clear () |
Clears the scene and all hashes, lists, var etc. | |
QString | createEdgeName (const int &v1, const int &v2, const int &relation=-1) |
Creates a QString with the edge name. | |
void | setInitNodeSize (int) |
Sets initial node size from MW. | |
void | setInitZoomIndex (const int &) |
Sets the initial zoom setting. Use setMaxZoomIndex() instead. | |
void | setMaxZoomIndex (const int &) |
Sets the max zoom allowed (and the initial zoom as half of it). Called from MW on startup. | |
GraphicsNode * | hasNode (QString text) |
Checks if a node with label or nodeNum 'text' exists and returns it. | |
void | setSelectedNodes (QList< int > list) |
Selects all nodes in the given list. | |
QList< QGraphicsItem * > | selectedItems () |
Returns a list of all selected QGraphicsItem(s) | |
QList< int > | selectedNodes () |
Returns a List of selected node numbers. | |
QList< SelectedEdge > | selectedEdges () |
Returns a QList of selected directed edges structs in the form of v1,v2. | |
void | selectAll () |
Forces the scene to select all items. Also signals that no node is clicked. | |
void | selectNone () |
Clears any item selection from the scene. Also signals that no node is clicked. | |
void | removeItem (GraphicsEdge *) |
Removes an edge item from the scene. | |
void | removeItem (GraphicsEdgeWeight *edgeWeight) |
Removes an edge weight number item from the scene. | |
void | removeItem (GraphicsEdgeLabel *edgeLabel) |
Removes an edge label item from the scene. | |
void | removeItem (GraphicsNode *) |
Removes a node item from the scene. | |
void | removeItem (GraphicsNodeNumber *) |
Removes a node number item from the scene. | |
void | removeItem (GraphicsNodeLabel *) |
Removes a node label item from the scene. | |
void | setNumbersInsideNodes (const bool &toggle) |
Toggles displaying node numbers in or out of nodes. | |
void | setAllItemsVisibility (int, bool) |
Toggles the visibility of all items of the given type. | |
void | removeAllItems (int) |
Removes all items of the given type. | |
Protected Member Functions | |
void | wheelEvent (QWheelEvent *event) |
Handles the mouse wheel event. If CTRL is pressed, zooms in or out. | |
void | mouseDoubleClickEvent (QMouseEvent *e) |
Handles user double-clicks. | |
void | mousePressEvent (QMouseEvent *e) |
Handles the mouse press event. | |
void | mouseReleaseEvent (QMouseEvent *e) |
Handles the mouse release events. | |
void | resizeEvent (QResizeEvent *e) |
Handles the canvas resize event. | |
Private Attributes | |
H_NumToNode | nodeHash |
H_StrToEdge | edgesHash |
QList< int > | m_selectedNodes |
QList< SelectedEdge > | m_selectedEdges |
int | m_curRelation |
int | m_nodeSize |
int | m_currentRotationAngle |
int | m_zoomIndex |
int | m_zoomIndexInit |
int | m_zoomIndexMax |
int | markedEdgeSourceOrigSize |
int | markedEdgeTargetOrigSize |
int | m_edgeMinOffsetFromNode |
double | m_currentScaleFactor |
qreal | fX |
qreal | fY |
qreal | factor |
QString | m_nodeLabel |
QString | m_numberColor |
QString | m_labelColor |
QString | edgeName |
bool | m_isTransformationActive |
bool | hasDoubleClickedNode |
bool | clickedEdgeExists |
bool | m_nodeNumbersInside |
bool | m_nodeNumberVisibility |
bool | m_nodeLabelVisibility |
bool | m_edgeHighlighting |
GraphicsNode * | firstDoubleClickedNode |
GraphicsNode * | secondDoubleClickedNode |
GraphicsNode * | markedEdgeSource |
GraphicsNode * | markedEdgeTarget |
GraphicsEdge * | clickedEdge |
GraphicsWidget::GraphicsWidget | ( | QGraphicsScene * | sc, |
MainWindow * | m_parent | ||
) |
Constructs a GraphicsWidget object.
sc | |
m_parent |
GraphicsWidget::~GraphicsWidget | ( | ) |
Destructor. Calls the method to clear the data.
|
slot |
Adds a circular guideline.
x0 | |
y0 | |
radius |
|
slot |
Adds a horizonal guideline.
y0 |
|
slot |
Rotates the view transformation by angle degrees clockwise, while preserving the current scale.
angle |
|
slot |
Does the actual zoom in or out while preserving current rotation.
Scales the view transformation by the given value (0..m_zoomIndexMax)
value |
void GraphicsWidget::clear | ( | ) |
Clears the scene and all hashes, lists, var etc.
|
slot |
QString GraphicsWidget::createEdgeName | ( | const int & | v1, |
const int & | v2, | ||
const int & | relation = -1 |
||
) |
Creates a QString with the edge name.
Edge names are used in edgesHash
v1 | |
v2 | |
relation |
|
slot |
Draws a new edge in the scene, from node with sourceNum to node with targetNum.
Used when we do not have references to nodes but only node numbers: a) when we load a network file b) when the user clicks on the AddLink button on the MW.
sourceNum | |
targetNum | |
weight | |
label | |
color | |
type | |
drawArrows | |
bezier | |
weightNumbers |
|
slot |
Draws a new node in the scene.
Called when we load files, or when the user presses "Add Node" button or the user double clicks on the canvas.
nodeNum | |
nodeSize | |
nodeColor | |
numberColor | |
numberSize | |
nodeLabel | |
labelColor | |
labelSize | |
p | |
nodeShape | |
showLabels | |
numberInsideNode | |
showNumbers |
|
slot |
Handles double-clicks (or middle-clicks) on the given node, creating a new edge if needed.
If it is the first double/middle-click on a node, it saves the first node as source. On a second double/middle-click on a node, it saves the second node as target and signals MW to notify activeGraph, which will create a new edge from source to target and will signal back to GW to draw the edge on the canvas.
node |
|
slot |
Handles the event of selection change in the scene.
Emits selected nodes and edges to Graph
GraphicsNode * GraphicsWidget::hasNode | ( | QString | text | ) |
Checks if a node with label or nodeNum 'text' exists and returns it.
text |
|
protected |
Handles user double-clicks.
If the double-click was on empty space, it initiates the new node creation process. Otherwise, it the user double-clicks on a node, starts the new edge creation process.
QMouseEvent |
|
protected |
Handles the mouse press event.
e |
|
protected |
Handles the mouse release events.
Called when the user releases a mouse button, after a click. First sees what was in the position where the user clicked If a node was underneath, it signals for every node in scene selectedItems
e |
|
slot |
Moves the node with the given number to the new coordinates.
Called while creating random networks.
nodeNum | |
x | |
y |
|
signal |
|
signal |
|
slot |
Changes the current relation.
relation |
void GraphicsWidget::removeAllItems | ( | int | type | ) |
Removes all items of the given type.
type |
|
slot |
Removes the edge from node sourceNum to node targetNum from the scene.
Called when erasing edges using vertex numbers. Also called when transforming directed edges to undirected.
sourceNum | |
targetNum | |
removeReverse |
void GraphicsWidget::removeItem | ( | GraphicsEdge * | edge | ) |
Removes an edge item from the scene.
Called from GraphicsEdge::~GraphicsEdge() to remove itself from edgesHash, scene and be deleted
edge |
void GraphicsWidget::removeItem | ( | GraphicsEdgeLabel * | edgeLabel | ) |
Removes an edge label item from the scene.
edgeLabel |
void GraphicsWidget::removeItem | ( | GraphicsEdgeWeight * | edgeWeight | ) |
Removes an edge weight number item from the scene.
edgeWeight |
void GraphicsWidget::removeItem | ( | GraphicsNode * | node | ) |
Removes a node item from the scene.
Called from GraphicsNode::~GraphicsNode() to remove itself from nodeHash, scene and be deleted
node |
void GraphicsWidget::removeItem | ( | GraphicsNodeLabel * | nodeLabel | ) |
Removes a node label item from the scene.
nodeLabel |
void GraphicsWidget::removeItem | ( | GraphicsNodeNumber * | nodeNumber | ) |
Removes a node number item from the scene.
nodeNumber |
|
slot |
Deletes the node with the given number from the scene, if exists.
Called from Graph
nodeNum |
|
slot |
Resets to default rotation, zoom and scale.
|
signal |
|
protected |
|
slot |
Decreases the numerical rotation Rotates the view to the left, by a fixed angle.
|
slot |
Rotates the view to the right, by a fixed angle.
|
signal |
void GraphicsWidget::selectAll | ( | ) |
Forces the scene to select all items. Also signals that no node is clicked.
QList< SelectedEdge > GraphicsWidget::selectedEdges | ( | ) |
Returns a QList of selected directed edges structs in the form of v1,v2.
QList< QGraphicsItem * > GraphicsWidget::selectedItems | ( | ) |
Returns a list of all selected QGraphicsItem(s)
QList< int > GraphicsWidget::selectedNodes | ( | ) |
Returns a List of selected node numbers.
void GraphicsWidget::selectNone | ( | ) |
Clears any item selection from the scene. Also signals that no node is clicked.
void GraphicsWidget::setAllItemsVisibility | ( | int | type, |
bool | visible | ||
) |
Toggles the visibility of all items of the given type.
type | |
visible |
|
signal |
|
slot |
Toggles the visibility of all edge arrows.
toggle |
|
slot |
Sets the clicked edge.
Emits signal to Graph to:
edge | |
openMenu |
|
slot |
Sets the color of an edge.
Called when the user changes the color of an edge (right-clicking). Also called from Graph when all edge colors need to be changed.
source | |
target | |
color |
|
slot |
Changes the direction type of an existing edge.
source | |
target | |
dirType |
|
slot |
Enables or disables edge highlighting.
If enabled, an edge will be highlighted on mouse hover and edges connected to a node will be highlighted when the user selects that node.
toggle |
|
slot |
Sets the label of an edge.
Called when the user changes the label of an edge (right-clicking).
source | |
target | |
label |
|
slot |
Toggles all edge labels visibility.
toggle |
|
slot |
Changes the offset of an edge (or all edges) from source and target nodes.
source | |
target | |
offset |
|
slot |
Toggles the visibility of the given edge.
relation | |
sourceNum | |
targetNum | |
visible | |
preserveReverseEdge |
|
slot |
Sets the weight of an edge.
Called when the user changes the weight of an edge (right-clicking).
source | |
target | |
weight |
|
slot |
Toggles all edge weight numbers visibility.
toggle |
void GraphicsWidget::setInitNodeSize | ( | int | size | ) |
Sets initial node size from MW.
It is called from MW on startup and when user changes it.
size |
void GraphicsWidget::setInitZoomIndex | ( | const int & | zoomIndex | ) |
Sets the initial zoom setting. Use setMaxZoomIndex() instead.
zoomIndex |
void GraphicsWidget::setMaxZoomIndex | ( | const int & | maxZoomIndex | ) |
Sets the max zoom allowed (and the initial zoom as half of it). Called from MW on startup.
zoomIndex |
|
slot |
Clears clickedEdge and emits a signal to Graph.
The signal is used to
Called when the user clicks or double-clicks on a node.
node |
|
slot |
Sets the color of an node.
Called when the user changes the color of a node (right-clicking).
nodeNumber | |
color |
|
slot |
Sets the label of an node.
nodeNumber | |
label |
|
slot |
Changes the label color of a node to 'color'.
nodeNum | |
color |
|
slot |
Changes the distance of the label of the given node.
nodeNum | |
distance |
|
slot |
Changes the label size of a node to 'size'.
nodeNum | |
size |
|
slot |
Toggles the visibility of all node labels.
toggle |
|
slot |
Changes the color of a node number.
nodeNumber | |
color |
|
slot |
Changes the distance of the number of a node.
nodeNum | |
distance |
|
slot |
Changes the size of the number of a node.
nodeNum | |
size |
|
slot |
Toggles the visibility of node numbers.
toggle |
|
slot |
Sets the shape of an node.
nodeNumber | |
shape | |
iconPath |
|
slot |
Changes the size of a node.
nodeNum | |
size |
|
slot |
Changes the size of all nodes.
size |
|
slot |
Changes the visibility of a Node.
nodeNum | |
toggle |
void GraphicsWidget::setNumbersInsideNodes | ( | const bool & | toggle | ) |
Toggles displaying node numbers in or out of nodes.
numIn |
|
slot |
Toggles QPainter render hints for primitive edges and text antialiasing.
toggle |
|
slot |
Toggles QGraphicsView's antialiasing auto-adjustment of exposed areas.
Default: false Items that render antialiased lines on the boundaries of their QGraphicsItem::boundingRect() can end up rendering parts of the line outside. To prevent rendering artifacts, QGraphicsView expands all exposed regions by 2 pixels in all directions. If you enable this flag, QGraphicsView will no longer perform these adjustments, minimizing the areas that require redrawing, which improves performance. A common side effect is that items that do draw with antialiasing can leave painting traces behind on the scene as they are moved.
toggle |
|
slot |
Toggles openGL.
enabled |
void GraphicsWidget::setSelectedNodes | ( | QList< int > | list | ) |
Selects all nodes in the given list.
list |
|
signal |
|
signal |
|
signal |
|
signal |
|
signal |
|
signal |
|
signal |
|
protected |
Handles the mouse wheel event. If CTRL is pressed, zooms in or out.
e |
|
signal |
|
slot |
Increases the numerical zoom index of the scene by the given step.
Signals to MW to update the UI and do the rest.
level |
|
slot |
Decreases the numerical zoom index of the scene by the given step.
Signals to MW to update the UI and do the rest.
level |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |