Code Documentation 3.7
Social Network Visualizer
Loading...
Searching...
No Matches
GraphicsWidget Class Reference

#include <graphicswidget.h>

Inheritance diagram for GraphicsWidget:
Collaboration diagram for GraphicsWidget:

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.
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.
void setEdgesVisibilityBatch (const QList< EdgeVisibilityChange > &changes)
 Applies a batch of edge visibility changes in one call (WS3 M2).
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 setEdgeArrowSize (const int &size)
 Sets the arrow size for all edges and stores it as the default for new edges.
void setEdgeWeightNumbersVisibility (const bool &toggle)
 Toggles all edge weight numbers visibility.
void setEdgeLabelsVisibility (const bool &toggle)
 Toggles all edge labels visibility.
void setEdgesBezier (const bool &toggle)
 Toggles bezier-curve rendering for all edges currently in the scene.
void setEdgeHighlighting (const bool &toggle)
 Enables or disables edge highlighting.
void selectPath (const QList< int > &path)
 Selects the edges that form a shortest path, exactly as if the user had Shift-clicked each edge in turn.
void handleDoubleClickOnNode (GraphicsNode *node)
 Handles double-clicks (or middle-clicks) on the given node, creating a new edge if needed.
void clearGuides ()
 Removes and deletes all guide items previously added via addGuideCircle()/addGuideHLine(), without scanning the scene.
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 zoomToFit ()
 Scales and centres the view so that the full network is visible.
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 &)
 Double-click on empty canvas space; MW creates a new node at this scene position.
void userMiddleClicked (const int &sourceNum, const int &targetNum, const qreal &weight=1)
 Two consecutive middle-clicks (or double-clicks) on two different nodes; MW/Graph creates a new edge from the first node to the second.
void userClickOnEmptySpace (const QPointF &p)
 Left-click on empty canvas space, at scene position p.
void openNodeMenu ()
 Right-click on a node; MW opens the node context menu for the currently clicked node.
void openContextMenu (const QPointF p)
 Right-click on empty canvas space, at scene position p; MW opens the general context menu.
void userNodeMoved (const int &, const int &, const int &)
 One node from the current selection finished being dragged to a new position (nodeNumber, x, y); emitted once per selected node on mouse release.
void userSelectedItems (const QList< int > selectedNodes, const QList< SelectedEdge > selectedEdges)
 The full current node/edge selection, emitted whenever it changes (single emission per change, not per item).
void userClickedNode (const int &nodeNumber, const QPointF &p)
 A node was clicked (nodeNumber, scene position); also used with nodeNumber=0 as a generic "selection changed" notification from selectAll()/selectNone().
void userClickedEdge (const int &source, const int &target, const bool &openMenu=false)
 An edge was clicked (source, target); openMenu requests MW open its context menu.
void zoomChanged (const int)
 Current zoom index changed; keeps the MW zoom slider in sync.
void rotationChanged (const int)
 Current rotation angle changed; keeps the MW rotation slider in sync.
void resized (const int, const int)
 Canvas viewport was resized (debounced to fire once, 150ms after the last resize event).
void setCursor (Qt::CursorShape)
 Requests MW change the application cursor shape (e.g. while creating an edge).

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.
bool isClearing () const
 True while a bulk clear() is in progress; false otherwise.
quint64 edgeKey (const int &v1, const int &v2, const int &relation=-1)
 Packs (relation, v1, v2) into a single quint64 key for edgesHash.
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.
void setSelectedNodes (const 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< SelectedEdgeselectedEdges ()
 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.

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.
void scrollContentsBy (int dx, int dy) override
 Tracks the user's pan position so zoom can anchor to it.

Private Attributes

H_NumToNode nodeHash
H_KeyToEdge edgesHash
QList< int > m_selectedNodes
QList< SelectedEdgem_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
int m_arrowSize
double m_currentScaleFactor
qreal fX
qreal fY
qreal factor
QString m_nodeLabel
QString m_numberColor
QString m_labelColor
quint64 m_edgeKey
QPointF m_viewCenter
bool m_viewCenterValid
bool m_isZooming
bool m_isTransformationActive
bool m_isClearing
bool hasDoubleClickedNode
bool clickedEdgeExists
bool m_nodeNumbersInside
bool m_nodeNumberVisibility
bool m_nodeLabelVisibility
bool m_edgeHighlighting
bool m_edgesBezier
QTimer m_resizeTimer
QList< GraphicsGuide * > m_guides
GraphicsNodefirstDoubleClickedNode
GraphicsNodesecondDoubleClickedNode
GraphicsNodemarkedEdgeSource
GraphicsNodemarkedEdgeTarget
GraphicsEdgeclickedEdge

Constructor & Destructor Documentation

◆ GraphicsWidget()

GraphicsWidget::GraphicsWidget ( QGraphicsScene * sc,
MainWindow * m_parent )

Constructs a GraphicsWidget object.

Parameters
sc
m_parent

◆ ~GraphicsWidget()

GraphicsWidget::~GraphicsWidget ( )

Destructor. Calls the method to clear the data.

Member Function Documentation

◆ addGuideCircle

void GraphicsWidget::addGuideCircle ( const double & x0,
const double & y0,
const double & radius )
slot

Adds a circular guideline.

Parameters
x0
y0
radius

◆ addGuideHLine

void GraphicsWidget::addGuideHLine ( const double & y0)
slot

Adds a horizonal guideline.

Parameters
y0

◆ changeMatrixRotation

void GraphicsWidget::changeMatrixRotation ( int angle)
slot

Rotates the view transformation by angle degrees clockwise, while preserving the current scale.

Parameters
angle

◆ changeMatrixScale

void GraphicsWidget::changeMatrixScale ( const int value)
slot

Does the actual zoom in or out while preserving current rotation.

Scales the view transformation by the given value (0..m_zoomIndexMax)

Parameters
value

◆ clear()

void GraphicsWidget::clear ( )

Clears the scene and all hashes, lists, var etc.

◆ clearGuides

void GraphicsWidget::clearGuides ( )
slot

Removes and deletes all guide items previously added via addGuideCircle()/addGuideHLine(), without scanning the scene.

GraphicsGuide::die() only clears geometry/visibility bookkeeping — it does not delete or schedule deletion — so a direct synchronous delete is safe.

◆ drawEdge

void GraphicsWidget::drawEdge ( const int & sourceNum,
const int & targetNum,
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 )
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.

Parameters
sourceNum
targetNum
weight
label
color
type
drawArrows
bezier
weightNumbers

◆ drawNode

void GraphicsWidget::drawNode ( const QPointF & p,
const int & nodeNum,
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 )
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.

Parameters
nodeNum
nodeSize
nodeColor
numberColor
numberSize
nodeLabel
labelColor
labelSize
p
nodeShape
showLabels
numberInsideNode
showNumbers

◆ edgeKey()

quint64 GraphicsWidget::edgeKey ( const int & v1,
const int & v2,
const int & relation = -1 )

Packs (relation, v1, v2) into a single quint64 key for edgesHash.

Used to be a QString built as "relation:v1>v2" (e.g. "0:3>7"), which cost several heap allocations per call (QString::number() x3 plus concatenation) and character-wise hashing on every lookup. This is purely a UI-layer lookup key for GraphicsWidget's own edgesHash (mapping a graph edge to its GraphicsEdge item) — it has nothing to do with Graph's own data model or any algorithm kernel.

The key is decimal-digit-packed, not bit-packed, so it stays readable in a debugger the same way the old string was: reading left to right you get relation, then v1, then v2 - e.g. relation=0, v1=3, v2=7 packs to 300000007. (Leading zeros aren't preserved by a plain integer print, so a value like relation=0 won't visually show its 3-digit field width unless printed zero-padded to 19 digits — this key is only ever used as an opaque hash bucket key, never parsed back into fields, so that's not a correctness concern.)

This is a positional encoding, not a mixing hash: as long as every field's value stays within its allocated width (relation < 1000, v1 < 100'000'000, v2 < 100'000'000), the mapping from (relation, v1, v2) to key is a true bijection - collisions between distinct triples are structurally impossible, not just statistically unlikely. The three asserts below exist because that guarantee only holds while every field stays under its digit budget; an overflow would silently bleed into the next field and could produce a genuine collision with a different triple.

Parameters
v1Source node number (must be < 100,000,000)
v2Target node number (must be < 100,000,000)
relationRelation index, or -1 to use the current relation (must be < 1000)
Returns
Packed key, unique per (relation, v1, v2) triple within the bounds above

◆ handleDoubleClickOnNode

void GraphicsWidget::handleDoubleClickOnNode ( GraphicsNode * node)
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.

Parameters
node

◆ handleSelectionChanged

void GraphicsWidget::handleSelectionChanged ( )
slot

Handles the event of selection change in the scene.

Queries scene()->selectedItems() once, populates m_selectedNodes and m_selectedEdges from a single pass, then emits both lists to Graph.

◆ isClearing()

bool GraphicsWidget::isClearing ( ) const
inline

True while a bulk clear() is in progress; false otherwise.

GraphicsNode/GraphicsEdge destructors check this to skip per-item unlinking work (edge-list removal from neighbours, individual scene/hash removal) that's pointless during a bulk teardown - scene()->clear() destroys every item anyway, so proactively unlinking each one from its neighbours' edge lists is pure wasted O(degree) work per edge, repeated across the whole network. See #260.

◆ mouseDoubleClickEvent()

void GraphicsWidget::mouseDoubleClickEvent ( QMouseEvent * e)
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.

Parameters
QMouseEvent

◆ mousePressEvent()

void GraphicsWidget::mousePressEvent ( QMouseEvent * e)
protected

Handles the mouse press event.

Parameters
e

◆ mouseReleaseEvent()

void GraphicsWidget::mouseReleaseEvent ( QMouseEvent * 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

Parameters
e

◆ moveNode

void GraphicsWidget::moveNode ( const int & nodeNum,
const qreal & x,
const qreal & y )
slot

Moves the node with the given number to the new coordinates.

Called while creating random networks.

Parameters
nodeNum
x
y

◆ openContextMenu

void GraphicsWidget::openContextMenu ( const QPointF p)
signal

Right-click on empty canvas space, at scene position p; MW opens the general context menu.

◆ openNodeMenu

void GraphicsWidget::openNodeMenu ( )
signal

Right-click on a node; MW opens the node context menu for the currently clicked node.

◆ relationSet

void GraphicsWidget::relationSet ( int relation)
slot

Changes the current relation.

Parameters
relation

◆ removeEdge

void GraphicsWidget::removeEdge ( const int & sourceNum,
const int & targetNum,
const bool & removeReverse = false )
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.

Parameters
sourceNum
targetNum
removeReverse

◆ removeItem() [1/6]

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

Parameters
edge

◆ removeItem() [2/6]

void GraphicsWidget::removeItem ( GraphicsEdgeLabel * edgeLabel)

Removes an edge label item from the scene.

Parameters
edgeLabel

◆ removeItem() [3/6]

void GraphicsWidget::removeItem ( GraphicsEdgeWeight * edgeWeight)

Removes an edge weight number item from the scene.

Parameters
edgeWeight

◆ removeItem() [4/6]

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

Parameters
node

◆ removeItem() [5/6]

void GraphicsWidget::removeItem ( GraphicsNodeLabel * nodeLabel)

Removes a node label item from the scene.

Parameters
nodeLabel

◆ removeItem() [6/6]

void GraphicsWidget::removeItem ( GraphicsNodeNumber * nodeNumber)

Removes a node number item from the scene.

Parameters
nodeNumber

◆ removeNode

void GraphicsWidget::removeNode ( const int & nodeNum)
slot

Deletes the node with the given number from the scene, if exists.

Called from Graph

Parameters
nodeNum

◆ reset

void GraphicsWidget::reset ( )
slot

Resets to default rotation, zoom and scale.

◆ resized

void GraphicsWidget::resized ( const int ,
const int  )
signal

Canvas viewport was resized (debounced to fire once, 150ms after the last resize event).

◆ resizeEvent()

void GraphicsWidget::resizeEvent ( QResizeEvent * e)
protected

Handles the canvas resize event.

Repositions guides then emits resized() signal to MW and eventually Graph which does the node repositioning maintaining proportions

Parameters
e

◆ rotateLeft

void GraphicsWidget::rotateLeft ( )
slot

Decreases the numerical rotation Rotates the view to the left, by a fixed angle.

◆ rotateRight

void GraphicsWidget::rotateRight ( )
slot

Rotates the view to the right, by a fixed angle.

◆ rotationChanged

void GraphicsWidget::rotationChanged ( const int )
signal

Current rotation angle changed; keeps the MW rotation slider in sync.

◆ scrollContentsBy()

void GraphicsWidget::scrollContentsBy ( int dx,
int dy )
overrideprotected

Tracks the user's pan position so zoom can anchor to it.

Called by Qt whenever the scroll position changes — user scroll bars, mouse wheel scroll, or programmatic centerOn(). The m_isZooming flag blocks updates during our own centerOn() call in changeMatrixScale(), so only genuine user pans update m_viewCenter.

◆ selectAll()

void GraphicsWidget::selectAll ( )

Forces the scene to select all items. Also signals that no node is clicked.

◆ selectedEdges()

QList< SelectedEdge > GraphicsWidget::selectedEdges ( )

Returns a QList of selected directed edges structs in the form of v1,v2.

Returns
QList<SelectedEdge>

◆ selectedItems()

QList< QGraphicsItem * > GraphicsWidget::selectedItems ( )

Returns a list of all selected QGraphicsItem(s).

Returns
QList<QGraphicsItem*>

◆ selectedNodes()

QList< int > GraphicsWidget::selectedNodes ( )

Returns a List of selected node numbers.

Returns
QList<int>

◆ selectNone()

void GraphicsWidget::selectNone ( )

Clears any item selection from the scene. Also signals that no node is clicked.

◆ selectPath

void GraphicsWidget::selectPath ( const QList< int > & path)
slot

Selects the edges that form a shortest path, exactly as if the user had Shift-clicked each edge in turn.

Uses QSignalBlocker so that scene()->selectionChanged fires only once (via the explicit handleSelectionChanged() call at the end), not once per edge. MainWindow then receives a single userSelectedItems() emission with the complete path edge set — same as any other multi-selection.

For each hop (path[i] → path[i+1]) the forward key is tried first; if the edge is not found (directed graph, path goes the "other way") the reverse key is tried.

Parameters
pathOrdered list of vertex numbers returned by Graph::graphGeodesicShortestPath().

◆ setAllItemsVisibility()

void GraphicsWidget::setAllItemsVisibility ( int type,
bool visible )

Toggles the visibility of all items of the given type.

Parameters
type
visible

◆ setCursor

void GraphicsWidget::setCursor ( Qt::CursorShape )
signal

Requests MW change the application cursor shape (e.g. while creating an edge).

◆ setEdgeArrowSize

void GraphicsWidget::setEdgeArrowSize ( const int & size)
slot

Sets the arrow size for all edges and stores it as the default for new edges.

Each edge only recomputes its four cached arrow-corner QPointFs and schedules a repaint — no full path rebuild is triggered.

Parameters
sizeArrow size in pixels (typically 2–20).

◆ setEdgeArrowsVisibility

void GraphicsWidget::setEdgeArrowsVisibility ( const bool & toggle)
slot

Toggles the visibility of all edge arrows.

Parameters
toggle

◆ setEdgeClicked

void GraphicsWidget::setEdgeClicked ( GraphicsEdge * edge,
const bool & openMenu = false )
slot

Sets the clicked edge.

Emits signal to Graph to:

  • display edge info on the status bar
  • notify context menus for the clicked edge.
Parameters
edge
openMenu

◆ setEdgeColor

void GraphicsWidget::setEdgeColor ( const int & source,
const int & target,
const QString & color )
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.

Parameters
source
target
color

◆ setEdgeDirectionType

bool GraphicsWidget::setEdgeDirectionType ( const int & source,
const int & target,
const int & dirType = false )
slot

Changes the direction type of an existing edge.

Parameters
source
target
dirType
Returns

◆ setEdgeHighlighting

void GraphicsWidget::setEdgeHighlighting ( const bool & toggle)
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.

Parameters
toggle

◆ setEdgeLabel

void GraphicsWidget::setEdgeLabel ( const int & source,
const int & target,
const QString & label )
slot

Sets the label of an edge.

Called when the user changes the label of an edge (right-clicking).

Parameters
source
target
label

◆ setEdgeLabelsVisibility

void GraphicsWidget::setEdgeLabelsVisibility ( const bool & toggle)
slot

Toggles all edge labels visibility.

Parameters
toggle

◆ setEdgeOffsetFromNode

void GraphicsWidget::setEdgeOffsetFromNode ( const int & source,
const int & target,
const int & offset )
slot

Changes the offset of an edge (or all edges) from source and target nodes.

Parameters
source
target
offset

◆ setEdgesBezier

void GraphicsWidget::setEdgesBezier ( const bool & toggle)
slot

Toggles bezier-curve rendering for all edges currently in the scene.

Also stores the toggle in m_edgesBezier so it applies to edges drawn afterwards. Viewport updates are disabled for the duration of the loop to avoid a repaint per edge.

Parameters
toggle

◆ setEdgesVisibilityBatch

void GraphicsWidget::setEdgesVisibilityBatch ( const QList< EdgeVisibilityChange > & changes)
slot

Applies a batch of edge visibility changes in one call (WS3 M2).

Reuses setEdgeVisibility() per entry unchanged - the only difference from N separate signal/slot dispatches is that this whole batch crosses from graphThread to the GUI thread as a single queued call, not one per edge. See Graph::signalSetEdgesVisibilityBatch.

Parameters
changes

◆ setEdgeVisibility

void GraphicsWidget::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 )
slot

Toggles the visibility of the given edge.

Parameters
relation
sourceNum
targetNum
visible
preserveReverseEdge

◆ setEdgeWeight

bool GraphicsWidget::setEdgeWeight ( const int & source,
const int & target,
const qreal & weight )
slot

Sets the weight of an edge.

Called when the user changes the weight of an edge (right-clicking).

Parameters
source
target
weight
Returns

◆ setEdgeWeightNumbersVisibility

void GraphicsWidget::setEdgeWeightNumbersVisibility ( const bool & toggle)
slot

Toggles all edge weight numbers visibility.

Parameters
toggle

◆ setInitNodeSize()

void GraphicsWidget::setInitNodeSize ( int size)

Sets initial node size from MW.

It is called from MW on startup and when user changes it.

Parameters
size

◆ setInitZoomIndex()

void GraphicsWidget::setInitZoomIndex ( const int & zoomIndex)

Sets the initial zoom setting. Use setMaxZoomIndex() instead.

Parameters
zoomIndex

◆ setMaxZoomIndex()

void GraphicsWidget::setMaxZoomIndex ( const int & maxZoomIndex)

Sets the max zoom allowed (and the initial zoom as half of it). Called from MW on startup.

Parameters
zoomIndex

◆ setNodeClicked

void GraphicsWidget::setNodeClicked ( GraphicsNode * node)
slot

Clears clickedEdge and emits a signal to Graph.

The signal is used to

  • display node info on the status bar
  • notify context menus for the clicked node.

Called when the user clicks or double-clicks on a node.

Parameters
node

◆ setNodeColor

bool GraphicsWidget::setNodeColor ( const int & nodeNum,
const QString & color )
slot

Sets the color of an node.

Called when the user changes the color of a node (right-clicking).

Parameters
nodeNumber
color
Returns

◆ setNodeLabel

bool GraphicsWidget::setNodeLabel ( const int & nodeNumber,
const QString & label )
slot

Sets the label of an node.

Parameters
nodeNumber
label
Returns

◆ setNodeLabelColor

bool GraphicsWidget::setNodeLabelColor ( const int & nodeNum,
const QString & color = "green" )
slot

Changes the label color of a node to 'color'.

Parameters
nodeNum
color

◆ setNodeLabelDistance

bool GraphicsWidget::setNodeLabelDistance ( const int & nodeNum,
const int & distance = 0 )
slot

Changes the distance of the label of the given node.

Parameters
nodeNum
distance

◆ setNodeLabelSize

bool GraphicsWidget::setNodeLabelSize ( const int & nodeNum,
const int & size = 0 )
slot

Changes the label size of a node to 'size'.

Parameters
nodeNum
size

◆ setNodeLabelsVisibility

void GraphicsWidget::setNodeLabelsVisibility ( const bool & toggle)
slot

Toggles the visibility of all node labels.

Parameters
toggle

◆ setNodeNumberColor

void GraphicsWidget::setNodeNumberColor ( const int & nodeNum,
const QString & color )
slot

Changes the color of a node number.

Parameters
nodeNumber
color

◆ setNodeNumberDistance

bool GraphicsWidget::setNodeNumberDistance ( const int & nodeNum,
const int & distance = 0 )
slot

Changes the distance of the number of a node.

Parameters
nodeNum
distance

◆ setNodeNumberSize

bool GraphicsWidget::setNodeNumberSize ( const int & nodeNum,
const int & size = 0 )
slot

Changes the size of the number of a node.

Parameters
nodeNum
size

◆ setNodeNumberVisibility

void GraphicsWidget::setNodeNumberVisibility ( const bool & toggle)
slot

Toggles the visibility of node numbers.

Parameters
toggle

◆ setNodeShape

bool GraphicsWidget::setNodeShape ( const int & nodeNum,
const QString & shape,
const QString & iconPath = QString() )
slot

Sets the shape of an node.

Parameters
nodeNumber
shape
iconPath
Returns

◆ setNodeSize

bool GraphicsWidget::setNodeSize ( const int & nodeNum,
const int & size = 0 )
slot

Changes the size of a node.

Parameters
nodeNum
size
Returns
bool

◆ setNodeVisibility

void GraphicsWidget::setNodeVisibility ( const int & nodeNum,
const bool & toggle )
slot

Changes the visibility of a Node.

Parameters
nodeNum
toggle

◆ setNumbersInsideNodes()

void GraphicsWidget::setNumbersInsideNodes ( const bool & toggle)

Toggles displaying node numbers in or out of nodes.

Parameters
numIn

◆ setOptionsAntialiasing

void GraphicsWidget::setOptionsAntialiasing ( const bool & toggle)
slot

Toggles QPainter render hints for primitive edges and text antialiasing.

Parameters
toggle

◆ setOptionsNoAntialiasingAutoAdjust

void GraphicsWidget::setOptionsNoAntialiasingAutoAdjust ( const bool & 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.

Parameters
toggle

◆ setOptionsOpenGL

void GraphicsWidget::setOptionsOpenGL ( const bool & enabled = false)
slot

Toggles openGL.

Parameters
enabled

◆ setSelectedNodes()

void GraphicsWidget::setSelectedNodes ( const QList< int > & list)

Selects all nodes in the given list.

Parameters
list

◆ userClickedEdge

void GraphicsWidget::userClickedEdge ( const int & source,
const int & target,
const bool & openMenu = false )
signal

An edge was clicked (source, target); openMenu requests MW open its context menu.

◆ userClickedNode

void GraphicsWidget::userClickedNode ( const int & nodeNumber,
const QPointF & p )
signal

A node was clicked (nodeNumber, scene position); also used with nodeNumber=0 as a generic "selection changed" notification from selectAll()/selectNone().

◆ userClickOnEmptySpace

void GraphicsWidget::userClickOnEmptySpace ( const QPointF & p)
signal

Left-click on empty canvas space, at scene position p.

◆ userDoubleClickNewNode

void GraphicsWidget::userDoubleClickNewNode ( const QPointF & )
signal

Double-click on empty canvas space; MW creates a new node at this scene position.

◆ userMiddleClicked

void GraphicsWidget::userMiddleClicked ( const int & sourceNum,
const int & targetNum,
const qreal & weight = 1 )
signal

Two consecutive middle-clicks (or double-clicks) on two different nodes; MW/Graph creates a new edge from the first node to the second.

◆ userNodeMoved

void GraphicsWidget::userNodeMoved ( const int & ,
const int & ,
const int &  )
signal

One node from the current selection finished being dragged to a new position (nodeNumber, x, y); emitted once per selected node on mouse release.

◆ userSelectedItems

void GraphicsWidget::userSelectedItems ( const QList< int > selectedNodes,
const QList< SelectedEdge > selectedEdges )
signal

The full current node/edge selection, emitted whenever it changes (single emission per change, not per item).

◆ wheelEvent()

void GraphicsWidget::wheelEvent ( QWheelEvent * e)
protected

Handles the mouse wheel event. If CTRL is pressed, zooms in or out.

Parameters
e

◆ zoomChanged

void GraphicsWidget::zoomChanged ( const int )
signal

Current zoom index changed; keeps the MW zoom slider in sync.

◆ zoomIn

void GraphicsWidget::zoomIn ( const int step = 1)
slot

Increases the numerical zoom index of the scene by the given step.

Signals to MW to update the UI and do the rest.

Parameters
level

◆ zoomOut

void GraphicsWidget::zoomOut ( const int step = 1)
slot

Decreases the numerical zoom index of the scene by the given step.

Signals to MW to update the UI and do the rest.

Parameters
level

◆ zoomToFit

void GraphicsWidget::zoomToFit ( )
slot

Scales and centres the view so that the full network is visible.

Computes the scale factor needed to fit the scene's bounding rect inside the viewport (with a 20 px margin on each side), maps it to the nearest discrete zoom index, updates m_viewCenter to the content centre, and applies the transform via changeMatrixScale(). zoomChanged() is also emitted to keep the zoom slider in sync, but the transform is applied unconditionally — not via the slider chain — so the view is always re-centred even when the computed zoom index equals the slider's current value.

Called automatically via a QueuedConnection on Graph::signalLayoutFinished, which is emitted after every layout algorithm completes. The queued delivery guarantees that all setNodePos signals (which move scene items to their new positions) have been processed before this slot runs — so itemsBoundingRect() reflects the finished layout.

After this call, subsequent zoom or pan operations anchor normally to the new view centre (the #248 behaviour is preserved).

Member Data Documentation

◆ clickedEdge

GraphicsEdge* GraphicsWidget::clickedEdge
private

◆ clickedEdgeExists

bool GraphicsWidget::clickedEdgeExists
private

◆ edgesHash

H_KeyToEdge GraphicsWidget::edgesHash
private

◆ factor

qreal GraphicsWidget::factor
private

◆ firstDoubleClickedNode

GraphicsNode* GraphicsWidget::firstDoubleClickedNode
private

◆ fX

qreal GraphicsWidget::fX
private

◆ fY

qreal GraphicsWidget::fY
private

◆ hasDoubleClickedNode

bool GraphicsWidget::hasDoubleClickedNode
private

◆ m_arrowSize

int GraphicsWidget::m_arrowSize
private

◆ m_curRelation

int GraphicsWidget::m_curRelation
private

◆ m_currentRotationAngle

int GraphicsWidget::m_currentRotationAngle
private

◆ m_currentScaleFactor

double GraphicsWidget::m_currentScaleFactor
private

◆ m_edgeHighlighting

bool GraphicsWidget::m_edgeHighlighting
private

◆ m_edgeKey

quint64 GraphicsWidget::m_edgeKey
private

◆ m_edgeMinOffsetFromNode

int GraphicsWidget::m_edgeMinOffsetFromNode
private

◆ m_edgesBezier

bool GraphicsWidget::m_edgesBezier
private

◆ m_guides

QList<GraphicsGuide *> GraphicsWidget::m_guides
private

◆ m_isClearing

bool GraphicsWidget::m_isClearing
private

◆ m_isTransformationActive

bool GraphicsWidget::m_isTransformationActive
private

◆ m_isZooming

bool GraphicsWidget::m_isZooming
private

◆ m_labelColor

QString GraphicsWidget::m_labelColor
private

◆ m_nodeLabel

QString GraphicsWidget::m_nodeLabel
private

◆ m_nodeLabelVisibility

bool GraphicsWidget::m_nodeLabelVisibility
private

◆ m_nodeNumbersInside

bool GraphicsWidget::m_nodeNumbersInside
private

◆ m_nodeNumberVisibility

bool GraphicsWidget::m_nodeNumberVisibility
private

◆ m_nodeSize

int GraphicsWidget::m_nodeSize
private

◆ m_numberColor

QString GraphicsWidget::m_numberColor
private

◆ m_resizeTimer

QTimer GraphicsWidget::m_resizeTimer
private

◆ m_selectedEdges

QList<SelectedEdge> GraphicsWidget::m_selectedEdges
private

◆ m_selectedNodes

QList<int> GraphicsWidget::m_selectedNodes
private

◆ m_viewCenter

QPointF GraphicsWidget::m_viewCenter
private

◆ m_viewCenterValid

bool GraphicsWidget::m_viewCenterValid
private

◆ m_zoomIndex

int GraphicsWidget::m_zoomIndex
private

◆ m_zoomIndexInit

int GraphicsWidget::m_zoomIndexInit
private

◆ m_zoomIndexMax

int GraphicsWidget::m_zoomIndexMax
private

◆ markedEdgeSource

GraphicsNode* GraphicsWidget::markedEdgeSource
private

◆ markedEdgeSourceOrigSize

int GraphicsWidget::markedEdgeSourceOrigSize
private

◆ markedEdgeTarget

GraphicsNode* GraphicsWidget::markedEdgeTarget
private

◆ markedEdgeTargetOrigSize

int GraphicsWidget::markedEdgeTargetOrigSize
private

◆ nodeHash

H_NumToNode GraphicsWidget::nodeHash
private

◆ secondDoubleClickedNode

GraphicsNode * GraphicsWidget::secondDoubleClickedNode
private

The documentation for this class was generated from the following files: