#include <graphicswidget.h>

Inheritance diagram for GraphicsWidget:
Collaboration diagram for GraphicsWidget:

Public Slots

void getSelectedItems ()
 Emits selected nodes and edges to Graph and MW Called by QGraphicsScene::selectionChanged signal whenever the user makes a selection on the canvas. Emits selectedNodes and selectedEdges lists to Graph::graphSelectionChanged() which then signals to MW::slotEditSelectionChanged to display counts on app window. More...
 
void relationSet (int relation)
 GraphicsWidget::relationSet Called from Graph::signalRelationChangedToGW(int) signal. More...
 
void drawNode (const int &num, const int &nodeSize, const QString &nodeShape, const QString &nodeColor, const bool &showNumbers, const bool &numberInsideNode, const QString &numberColor, const int &numberSize, const int &numberDistance, const bool &showLabels, const QString &nodeLabel, const QString &labelColor, const int &labelSize, const int &labelDistance, const QPointF &p)
 GraphicsWidget::drawNode Adds a new node onto the scene Called from Graph::vertexCreate method primarily when we load files It is also called in the end when the user presses "Add Node" button or the user double clicks (mouseDoubleClickEvent() calls Graph::vertexCreate) More...
 
void eraseNode (const long int &number)
 GraphicsWidget::eraseNode Called from Graph signal eraseNode(int) More...
 
void setNodeVisibility (long int, bool)
 
void nodeClicked (Node *)
 
void moveNode (const int &num, const qreal &x, const qreal &y)
 GraphicsWidget::moveNode Called from activeGraph to update node coordinates on the canvas. More...
 
bool setNodeSize (const long int &nodeNumber, const int &size=0)
 GraphicsWidget::setNodeSize. More...
 
void setAllNodeSize (const int &size=0)
 GraphicsWidget::setAllNodeSize. More...
 
bool setNodeShape (const long int &nodeNumber, const QString &shape)
 
bool setNodeColor (const long int &, const QString &color)
 GraphicsWidget::setNodeColor Sets the color of an node. Called from MW when the user changes the color of a node (right-clicking). More...
 
void setNodeNumberVisibility (const bool &toggle)
 
bool setNodeNumberSize (const long int &, const int &size=0)
 GraphicsWidget::setNodeNumberSize. More...
 
bool setNodeNumberDistance (const long int &, const int &distance=0)
 GraphicsWidget::setNodeNumberDistance. More...
 
void setNodeLabelsVisibility (const bool &toggle)
 
bool setNodeLabelColor (const long int &number, const QString &color="green")
 GraphicsWidget::setNodeLabelColor. More...
 
bool setNodeLabelSize (const long int &, const int &size=0)
 GraphicsWidget::setNodeLabelSize. More...
 
bool setNodeLabel (long int, QString)
 GraphicsWidget::setNodeLabel Sets the label of an node. Called from MW. More...
 
bool setNodeLabelDistance (const long int &, const int &distance=0)
 GraphicsWidget::setNodeLabelDistance. More...
 
void drawEdge (const int &source, const int &target, const float &weight, const QString &label="", const QString &color="black", const int &type=0, const bool &drawArrows=true, const bool &bezier=false, const bool &weightNumbers=false)
 GraphicsWidget::drawEdge Draws an edge from source to target Node. Used when we do not have references to nodes but only nodeNumbers: a) when we load a network file b) when the user clicks on the AddLink button on the MW. More...
 
void eraseEdge (const long int &source, const long int &target)
 GraphicsWidget::eraseEdge Called from MW/Graph when erasing edges using vertex numbers Also called when transforming directed edges to undirected. More...
 
void setEdgeVisibility (int relation, int, int, bool)
 
bool setEdgeUndirected (const long int &, const long int &, const float &)
 GraphicsWidget::setEdgeUndirected Makes an edge undirected. More...
 
bool setEdgeWeight (const long int &, const long int &, const float &)
 
void setEdgeLabel (const long int &, const long int &, const QString &)
 GraphicsWidget::setEdgeLabel Sets the label of an edge. Called from MW when the user changes the label of an edge (right-clicking). More...
 
void setEdgeColor (const long int &, const long int &, const QString &)
 GraphicsWidget::setEdgeColor Sets the color of an edge. Called from MW when the user changes the color of an edge (right-clicking). Also called from Graph when all edge colors need to be changed. More...
 
void edgeClicked (Edge *)
 
void setEdgeWeightNumbersVisibility (const bool &toggle)
 
void setEdgeLabelsVisibility (const bool &toggle)
 
void startEdge (Node *node)
 
void clearGuides ()
 
void addGuideCircle (const double &x0, const double &y0, const double &radius)
 
void addGuideHLine (const double &y0)
 
void zoomIn (int level=1)
 GraphicsWidget::zoomIn. More...
 
void zoomOut (int level=1)
 GraphicsWidget::zoomOut. More...
 
void rotateLeft ()
 GraphicsWidget::rotateLeft. More...
 
void rotateRight ()
 GraphicsWidget::rotateRight. More...
 
void changeMatrixScale (const int value)
 GraphicsWidget::changeMatrixScale. More...
 
void changeMatrixRotation (int angle)
 GraphicsWidget::changeMatrixRotation. More...
 
void reset ()
 GraphicsWidget::reset Resets the transformation matrix to the identity matrix ( default zoom and scale ) More...
 

Signals

void userDoubleClickNewNode (const QPointF &)
 
void userMiddleClicked (const int &, const int &)
 
void userClickOnEmptySpace (const QPointF &p)
 
void openNodeMenu ()
 
void openEdgeMenu ()
 
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)
 
void userClickedEdge (const int &source, const int &target)
 
void zoomChanged (const int)
 
void rotationChanged (const int)
 
void resized (const int, const int)
 
void setCursor (Qt::CursorShape)
 

Public Member Functions

 GraphicsWidget (QGraphicsScene *, MainWindow *parent)
 
 ~GraphicsWidget ()
 
void clear ()
 GraphicsWidget::clear Clears the scene and all hashes, lists, var etc. More...
 
void setInitNodeSize (int)
 
void setInitZoomIndex (int)
 GraphicsWidget::setInitZoomIndex Passes initial zoom setting Called from MW on startup. More...
 
NodehasNode (QString text)
 
bool setMarkedNode (QString text)
 
QList< QGraphicsItem * > selectedItems ()
 Returns a QList of all selected QGraphicsItem(s) More...
 
QList< int > selectedNodes ()
 Returns a QList of selected node numbers Called by GW::getSelectedItems and MW::selectedNodes. More...
 
QList< SelectedEdgeselectedEdges ()
 Returns a QList of selected directed edges structs in the form of v1,v2. More...
 
void selectAll ()
 GraphicsWidget::selectAll Called from MW. Clears any clickedNode info and sets a selection rect in the scene, which signals QGraphicsScene::selectionChanged signal to update selectedNodes and selectedEdges. More...
 
void selectNone ()
 GraphicsWidget::selectNone Called from MW. Clears any clickedNode info and any previous selection rect in the scene, which again signals selectionChanged() to update selectedNodes and selectedEdges to zero. More...
 
void removeItem (Edge *)
 GraphicsWidget::removeItem. More...
 
void removeItem (EdgeWeight *edgeWeight)
 GraphicsWidget::removeItem. More...
 
void removeItem (EdgeLabel *edgeLabel)
 GraphicsWidget::removeItem. More...
 
void removeItem (Node *)
 GraphicsWidget::removeItem. More...
 
void removeItem (NodeNumber *)
 GraphicsWidget::removeItem. More...
 
void removeItem (NodeLabel *)
 GraphicsWidget::removeItem. More...
 
void setNumbersInsideNodes (bool)
 GraphicsWidget::setNumbersInsideNodes Toggles node numbers displayed inside or out of nodes Called from MW. More...
 
void setAllItemsVisibility (int, bool)
 
void removeAllItems (int)
 

Protected Member Functions

void wheelEvent (QWheelEvent *event)
 
void mouseDoubleClickEvent (QMouseEvent *e)
 
void mousePressEvent (QMouseEvent *e)
 
void mouseReleaseEvent (QMouseEvent *e)
 GraphicsWidget::mouseReleaseEvent. More...
 
void resizeEvent (QResizeEvent *e)
 GraphicsWidget::resizeEvent. More...
 
void paintEvent (QPaintEvent *event)
 

Private Attributes

H_NumToNode nodeHash
 
H_StrToEdge edgesHash
 
QList< int > m_selectedNodes
 
QList< SelectedEdgem_selectedEdges
 
int m_curRelation
 
int m_nodeSize
 
int m_currentRotationAngle
 
int m_zoomIndex
 
int markedNodeOrigSize
 
int markedEdgeSourceOrigSize
 
int markedEdgeTargetOrigSize
 
double m_currentScaleFactor
 
qreal fX
 
qreal fY
 
qreal factor
 
QString m_nodeLabel
 
QString m_numberColor
 
QString m_labelColor
 
QString edgeName
 
bool transformationActive
 
bool secondDoubleClick
 
bool markedNodeExist
 
bool clickedEdgeExists
 
NodefirstNode
 
NodesecondNode
 
NodemarkedNode1
 
NodemarkedEdgeSource
 
NodemarkedEdgeTarget
 
NodetempNode
 

Constructor & Destructor Documentation

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

Constructor method. Called when a GraphicsWidget object is created in MW

GraphicsWidget::~GraphicsWidget ( )

Destructor.

Member Function Documentation

void GraphicsWidget::addGuideCircle ( const double &  x0,
const double &  y0,
const double &  radius 
)
slot
void GraphicsWidget::addGuideHLine ( const double &  y0)
slot
void GraphicsWidget::changeMatrixRotation ( int  angle)
slot
void GraphicsWidget::changeMatrixScale ( const int  value)
slot

GraphicsWidget::changeMatrixScale.

Parameters
valueInitiated from MW zoomSlider and rotateSlider widgets
void GraphicsWidget::clear ( )

GraphicsWidget::clear Clears the scene and all hashes, lists, var etc.

void GraphicsWidget::clearGuides ( )
slot
void GraphicsWidget::drawEdge ( const int &  source,
const int &  target,
const float &  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

GraphicsWidget::drawEdge Draws an edge from source to target Node. Used when we do not have references to nodes but only nodeNumbers: a) when we load a network file b) when the user clicks on the AddLink button on the MW.

Parameters
source
target
weight
reciprocal
drawArrows
color
bezier
void GraphicsWidget::drawNode ( const int &  num,
const int &  nodeSize,
const QString &  nodeShape,
const QString &  nodeColor,
const bool &  showNumbers,
const bool &  numberInsideNode,
const QString &  numberColor,
const int &  numberSize,
const int &  numberDistance,
const bool &  showLabels,
const QString &  nodeLabel,
const QString &  labelColor,
const int &  labelSize,
const int &  labelDistance,
const QPointF &  p 
)
slot

GraphicsWidget::drawNode Adds a new node onto the scene Called from Graph::vertexCreate method primarily when we load files It is also called in the end when the user presses "Add Node" button or the user double clicks (mouseDoubleClickEvent() calls Graph::vertexCreate)

Parameters
num
nodeSize
nodeColor
numberColor
numberSize
nodeLabel
labelColor
labelSize
p
nodeShape
showLabels
numberInsideNode
showNumbers
void GraphicsWidget::edgeClicked ( Edge edge)
slot

This is called from each edge when the user clicks on it. It emits the userClickedEdge signal to Graph which is used to

  • display edge info on the status bar
  • notify context menus for the clicked edge. Also, it makes source and target nodes to stand out of other nodes.
void GraphicsWidget::eraseEdge ( const long int &  source,
const long int &  target 
)
slot

GraphicsWidget::eraseEdge Called from MW/Graph when erasing edges using vertex numbers Also called when transforming directed edges to undirected.

Parameters
sourceNode
targetNode
void GraphicsWidget::eraseNode ( const long int &  number)
slot

GraphicsWidget::eraseNode Called from Graph signal eraseNode(int)

Parameters
number
void GraphicsWidget::getSelectedItems ( )
slot

Emits selected nodes and edges to Graph and MW Called by QGraphicsScene::selectionChanged signal whenever the user makes a selection on the canvas. Emits selectedNodes and selectedEdges lists to Graph::graphSelectionChanged() which then signals to MW::slotEditSelectionChanged to display counts on app window.

Node * GraphicsWidget::hasNode ( QString  text)
void GraphicsWidget::mouseDoubleClickEvent ( QMouseEvent *  e)
protected

Starts a new node when the user double-clicks somewhere Emits userDoubleClicked to MW::slotEditNodeAddWithMouse() which

void GraphicsWidget::mousePressEvent ( QMouseEvent *  e)
protected
void GraphicsWidget::mouseReleaseEvent ( QMouseEvent *  e)
protected

GraphicsWidget::mouseReleaseEvent.

Parameters
eCalled when user releases a mouse button, after a click. First sees what was in the canvas position where the user clicked If a node was underneath, it calls userNodeMoved() signal for every node in scene selectedItems
void GraphicsWidget::moveNode ( const int &  num,
const qreal &  x,
const qreal &  y 
)
slot

GraphicsWidget::moveNode Called from activeGraph to update node coordinates on the canvas.

Parameters
num
x
y
void GraphicsWidget::nodeClicked ( Node node)
slot

This is called from each node when the user clicks on it. It emits the userClickedNode signal to MW which is used to

  • display node info on the status bar
  • notify context menus for the clicked node.
void GraphicsWidget::openContextMenu ( const QPointF  p)
signal
void GraphicsWidget::openEdgeMenu ( )
signal
void GraphicsWidget::openNodeMenu ( )
signal
void GraphicsWidget::paintEvent ( QPaintEvent *  event)
protected
void GraphicsWidget::relationSet ( int  relation)
slot

GraphicsWidget::relationSet Called from Graph::signalRelationChangedToGW(int) signal.

Parameters
relation
void GraphicsWidget::removeAllItems ( int  type)

Removes all items of certain type (i.e. number, label, edge, etc)

void GraphicsWidget::removeItem ( Edge edge)

GraphicsWidget::removeItem.

Parameters
edgeCalled from Edge::~Edge() to remove itself from edgesHash and scene and be deleted
void GraphicsWidget::removeItem ( EdgeWeight edgeWeight)

GraphicsWidget::removeItem.

Parameters
edgeWeight
void GraphicsWidget::removeItem ( EdgeLabel edgeLabel)

GraphicsWidget::removeItem.

Parameters
edgeLabel
void GraphicsWidget::removeItem ( Node node)

GraphicsWidget::removeItem.

Parameters
nodeCalled from Node::~Node() to remove itself from nodeHash, scene and be deleted
void GraphicsWidget::removeItem ( NodeNumber nodeNumber)

GraphicsWidget::removeItem.

Parameters
nodeNumber
void GraphicsWidget::removeItem ( NodeLabel nodeLabel)

GraphicsWidget::removeItem.

Parameters
nodeLabel
void GraphicsWidget::reset ( )
slot

GraphicsWidget::reset Resets the transformation matrix to the identity matrix ( default zoom and scale )

void GraphicsWidget::resized ( const int  ,
const int   
)
signal
void GraphicsWidget::resizeEvent ( QResizeEvent *  e)
protected

GraphicsWidget::resizeEvent.

Parameters
eRepositions guides then emits resized() signal to MW and eventually Graph which does the node repositioning maintaining proportions
void GraphicsWidget::rotateLeft ( )
slot
void GraphicsWidget::rotateRight ( )
slot
void GraphicsWidget::rotationChanged ( const int  )
signal
void GraphicsWidget::selectAll ( )

GraphicsWidget::selectAll Called from MW. Clears any clickedNode info and sets a selection rect in the scene, which signals QGraphicsScene::selectionChanged signal to update selectedNodes and selectedEdges.

QList< SelectedEdge > GraphicsWidget::selectedEdges ( )

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

Returns
a QList of selected directed edges structs
QList< QGraphicsItem * > GraphicsWidget::selectedItems ( )

Returns a QList of all selected QGraphicsItem(s)

Returns
a QList of all selected QGraphicsItem(s)
QList< int > GraphicsWidget::selectedNodes ( )

Returns a QList of selected node numbers Called by GW::getSelectedItems and MW::selectedNodes.

Returns
a QList of integers: the selected node numbers
void GraphicsWidget::selectNone ( )

GraphicsWidget::selectNone Called from MW. Clears any clickedNode info and any previous selection rect in the scene, which again signals selectionChanged() to update selectedNodes and selectedEdges to zero.

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

Changes the visibility of all items of certain type (i.e. number, label, edge, etc)

void GraphicsWidget::setAllNodeSize ( const int &  size = 0)
slot

GraphicsWidget::setAllNodeSize.

Parameters
size
Returns
void GraphicsWidget::setCursor ( Qt::CursorShape  )
signal
void GraphicsWidget::setEdgeColor ( const long int &  source,
const long int &  target,
const QString &  color 
)
slot

GraphicsWidget::setEdgeColor Sets the color of an edge. Called from MW 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
void GraphicsWidget::setEdgeLabel ( const long int &  source,
const long int &  target,
const QString &  label 
)
slot

GraphicsWidget::setEdgeLabel Sets the label of an edge. Called from MW when the user changes the label of an edge (right-clicking).

Parameters
source
target
label
void GraphicsWidget::setEdgeLabelsVisibility ( const bool &  toggle)
slot
bool GraphicsWidget::setEdgeUndirected ( const long int &  source,
const long int &  target,
const float &  weight 
)
slot

GraphicsWidget::setEdgeUndirected Makes an edge undirected.

Parameters
source
target
weight
Returns
void GraphicsWidget::setEdgeVisibility ( int  relation,
int  source,
int  target,
bool  toggle 
)
slot

Changes the visibility of an GraphicsView edge (number, label, edge, etc)

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

Changes/Sets the weight of an edge. Called from MW when the user changes the weight of an edge (right-clicking).

void GraphicsWidget::setEdgeWeightNumbersVisibility ( const bool &  toggle)
slot
void GraphicsWidget::setInitNodeSize ( int  size)

Sets initial node size from MW. It is Called from MW on startup and when user changes it.

void GraphicsWidget::setInitZoomIndex ( int  zoomIndex)

GraphicsWidget::setInitZoomIndex Passes initial zoom setting Called from MW on startup.

bool GraphicsWidget::setMarkedNode ( QString  nodeText)

Marks (by double-sizing and highlighting) or unmarks a node, given its number or label. Called by MW:slotEditNodeFind()

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

GraphicsWidget::setNodeColor Sets the color of an node. Called from MW when the user changes the color of a node (right-clicking).

Parameters
nodeNumber
color
Returns
bool GraphicsWidget::setNodeLabel ( long int  nodeNumber,
QString  label 
)
slot

GraphicsWidget::setNodeLabel Sets the label of an node. Called from MW.

Parameters
nodeNumber
label
Returns
bool GraphicsWidget::setNodeLabelColor ( const long int &  number,
const QString &  color = "green" 
)
slot

GraphicsWidget::setNodeLabelColor.

Parameters
number
color
bool GraphicsWidget::setNodeLabelDistance ( const long int &  number,
const int &  distance = 0 
)
slot

GraphicsWidget::setNodeLabelDistance.

Parameters
number
distance
bool GraphicsWidget::setNodeLabelSize ( const long int &  number,
const int &  size = 0 
)
slot

GraphicsWidget::setNodeLabelSize.

Parameters
number
size
void GraphicsWidget::setNodeLabelsVisibility ( const bool &  toggle)
slot
bool GraphicsWidget::setNodeNumberDistance ( const long int &  number,
const int &  distance = 0 
)
slot

GraphicsWidget::setNodeNumberDistance.

Parameters
number
distance
bool GraphicsWidget::setNodeNumberSize ( const long int &  number,
const int &  size = 0 
)
slot

GraphicsWidget::setNodeNumberSize.

Parameters
number
size
void GraphicsWidget::setNodeNumberVisibility ( const bool &  toggle)
slot
bool GraphicsWidget::setNodeShape ( const long int &  nodeNumber,
const QString &  shape 
)
slot

Sets the shape of an node. Called from MW when the user changes the shape of a node

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

GraphicsWidget::setNodeSize.

Parameters
number
size
Returns
void GraphicsWidget::setNodeVisibility ( long int  number,
bool  toggle 
)
slot

Changes the visibility of a Node

void GraphicsWidget::setNumbersInsideNodes ( bool  numIn)

GraphicsWidget::setNumbersInsideNodes Toggles node numbers displayed inside or out of nodes Called from MW.

Parameters
numIn
void GraphicsWidget::startEdge ( Node node)
slot

Called when the user middle-clicks on two nodes consecutively. . It saves the source & target nodes that were clicked On the second middle-click, it emits the userMiddleClicked() signal to MW, which will notify activeGraph, which in turn will signal back to drawEdge()...

void GraphicsWidget::userClickedEdge ( const int &  source,
const int &  target 
)
signal
void GraphicsWidget::userClickedNode ( const int &  nodeNumber)
signal
void GraphicsWidget::userClickOnEmptySpace ( const QPointF &  p)
signal
void GraphicsWidget::userDoubleClickNewNode ( const QPointF &  )
signal
void GraphicsWidget::userMiddleClicked ( const int &  ,
const int &   
)
signal
void GraphicsWidget::userNodeMoved ( const int &  ,
const int &  ,
const int &   
)
signal
void GraphicsWidget::userSelectedItems ( const QList< int > &  selectedNodes,
const QList< SelectedEdge > &  selectedEdges 
)
signal
void GraphicsWidget::wheelEvent ( QWheelEvent *  e)
protected

Calls the scaleView() when the user spins the mouse wheel It passes delta as new m_scale

void GraphicsWidget::zoomChanged ( const int  )
signal
void GraphicsWidget::zoomIn ( int  level = 1)
slot

GraphicsWidget::zoomIn.

Parameters
levelCalled from MW magnifier button
void GraphicsWidget::zoomOut ( int  level = 1)
slot

GraphicsWidget::zoomOut.

Parameters
levelCalled from MW magnifier button

Member Data Documentation

bool GraphicsWidget::clickedEdgeExists
private
QString GraphicsWidget::edgeName
private
H_StrToEdge GraphicsWidget::edgesHash
private
qreal GraphicsWidget::factor
private
Node* GraphicsWidget::firstNode
private
qreal GraphicsWidget::fX
private
qreal GraphicsWidget::fY
private
int GraphicsWidget::m_curRelation
private
int GraphicsWidget::m_currentRotationAngle
private
double GraphicsWidget::m_currentScaleFactor
private
QString GraphicsWidget::m_labelColor
private
QString GraphicsWidget::m_nodeLabel
private
int GraphicsWidget::m_nodeSize
private
QString GraphicsWidget::m_numberColor
private
QList<SelectedEdge> GraphicsWidget::m_selectedEdges
private
QList<int> GraphicsWidget::m_selectedNodes
private
int GraphicsWidget::m_zoomIndex
private
Node * GraphicsWidget::markedEdgeSource
private
int GraphicsWidget::markedEdgeSourceOrigSize
private
Node* GraphicsWidget::markedEdgeTarget
private
int GraphicsWidget::markedEdgeTargetOrigSize
private
Node * GraphicsWidget::markedNode1
private
bool GraphicsWidget::markedNodeExist
private
int GraphicsWidget::markedNodeOrigSize
private
H_NumToNode GraphicsWidget::nodeHash
private
bool GraphicsWidget::secondDoubleClick
private
Node * GraphicsWidget::secondNode
private
Node * GraphicsWidget::tempNode
private
bool GraphicsWidget::transformationActive
private

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