wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
Connection Class Reference

A bezier-curve wire connecting an output port to an input port in the scene. More...

#include <Connection.h>

Inheritance diagram for Connection:
[legend]

Public Types

enum  { Type = QGraphicsItem::UserType + 2 }

Public Member Functions

double angle ()
 Returns the current angle of the bezier midpoint in radians.
QRectF boundingRect () const override
 Connection (QGraphicsItem *parent=nullptr)
 Constructs an unconnected wire.
InputPortendPort () const
 Returns the input port this connection leads to.
bool highLight ()
 Returns true if this connection is highlighted.
void load (QDataStream &stream, SerializationContext &context)
 Deserializes the connection from stream, resolving ports via context.
PortotherPort (const Port *port) const
 Returns the port at the other end of this connection from port.
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void save (QDataStream &stream) const
 Serializes the connection endpoints to stream.
void setEndPort (InputPort *port)
 Sets the input port this connection leads to.
void setEndPos (const QPointF point)
 Sets the visual end position to point (used when dragging).
void setHighLight (const bool highLight)
 Enables or disables connection highlighting.
void setStartPort (OutputPort *port)
 Sets the output port this connection originates from.
void setStartPos (const QPointF point)
 Sets the visual start position to point (used when dragging).
void setStatus (const Status status)
 Sets the connection status and triggers a visual refresh.
QPainterPath shape () const override
OutputPortstartPort () const
 Returns the output port this connection originates from.
Status status () const
 Returns the current four-state signal status (Active/Inactive/Unknown/Error).
QPen statusPen () const
 Returns the pen paint() draws the wire with for its current status.
int type () const override
void updatePath ()
 Recomputes the bezier control points from the current start/end positions.
void updatePosFromPorts ()
 Moves the wire endpoints to match the current port positions.
void updateTheme ()
 Refreshes wire colours from the current ThemeManager palette.
 ~Connection () override
Public Member Functions inherited from ItemWithId
int id () const
 Returns the unique integer identifier of this item, or -1 if unassigned.
 ItemWithId ()=default
 Constructs a new ItemWithId with an unassigned ID of -1.
void setId (const int id)
 Sets the identifier to id.
virtual ~ItemWithId ()
 Self-unregisters from the current SceneItemRegistry, if any.

Protected Member Functions

QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
bool sceneEvent (QEvent *event) override

Detailed Description

A bezier-curve wire connecting an output port to an input port in the scene.

Connection draws a smooth path between its start (output) and end (input) ports. It is coloured according to its logical status (active/inactive/unknown/selected) and can be highlighted when the cursor hovers over it. Connections are serializable and participate in the undo/redo system.

Definition at line 37 of file Connection.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Type 

Definition at line 40 of file Connection.h.

Constructor & Destructor Documentation

◆ Connection()

Connection::Connection ( QGraphicsItem * parent = nullptr)
explicit

Constructs an unconnected wire.

Definition at line 22 of file Connection.cpp.

References updateTheme().

◆ ~Connection()

Connection::~Connection ( )
override

Definition at line 38 of file Connection.cpp.

Member Function Documentation

◆ angle()

double Connection::angle ( )

Returns the current angle of the bezier midpoint in radians.

Definition at line 156 of file Connection.cpp.

References Port::isOutput().

Referenced by SplitCommand::SplitCommand().

◆ boundingRect()

QRectF Connection::boundingRect ( ) const
override
Reimplemented from base class.

Definition at line 322 of file Connection.cpp.

◆ endPort()

InputPort * Connection::endPort ( ) const

Returns the input port this connection leads to.

Definition at line 151 of file Connection.cpp.

Referenced by Port::detachConnection(), itemChange(), ConnectionSerializer::save(), setStatus(), and SplitCommand::SplitCommand().

◆ highLight()

bool Connection::highLight ( )

Returns true if this connection is highlighted.

Definition at line 311 of file Connection.cpp.

Referenced by setHighLight().

◆ itemChange()

QVariant Connection::itemChange ( GraphicsItemChange change,
const QVariant & value )
overrideprotected
Reimplemented from base class.

Definition at line 294 of file Connection.cpp.

References endPort(), Port::hoverEnter(), Port::hoverLeave(), and startPort().

◆ load()

void Connection::load ( QDataStream & stream,
SerializationContext & context )

Deserializes the connection from stream, resolving ports via context.

Definition at line 180 of file Connection.cpp.

References ConnectionSerializer::load().

◆ otherPort()

Port * Connection::otherPort ( const Port * port) const

Returns the port at the other end of this connection from port.

Definition at line 185 of file Connection.cpp.

◆ paint()

void Connection::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget )
override
Reimplemented from base class.

Definition at line 265 of file Connection.cpp.

◆ save()

void Connection::save ( QDataStream & stream) const

Serializes the connection endpoints to stream.

Definition at line 175 of file Connection.cpp.

References ConnectionSerializer::save().

◆ sceneEvent()

bool Connection::sceneEvent ( QEvent * event)
overrideprotected
Reimplemented from base class.

Definition at line 358 of file Connection.cpp.

◆ setEndPort()

void Connection::setEndPort ( InputPort * port)

Sets the input port this connection leads to.

Definition at line 83 of file Connection.cpp.

References setEndPos(), InputPort::setStatus(), and status().

Referenced by Port::detachConnection(), and ConnectionSerializer::load().

◆ setEndPos()

void Connection::setEndPos ( const QPointF point)

Sets the visual end position to point (used when dragging).

Definition at line 54 of file Connection.cpp.

Referenced by setEndPort().

◆ setHighLight()

void Connection::setHighLight ( const bool highLight)

Enables or disables connection highlighting.

Definition at line 316 of file Connection.cpp.

References highLight().

◆ setStartPort()

void Connection::setStartPort ( OutputPort * port)

Sets the output port this connection originates from.

Definition at line 71 of file Connection.cpp.

References setStartPos(), setStatus(), and Port::status().

Referenced by Port::detachConnection(), and ConnectionSerializer::load().

◆ setStartPos()

void Connection::setStartPos ( const QPointF point)

Sets the visual start position to point (used when dragging).

Definition at line 49 of file Connection.cpp.

Referenced by setStartPort().

◆ setStatus()

void Connection::setStatus ( const Status status)

Sets the connection status and triggers a visual refresh.

Definition at line 199 of file Connection.cpp.

References endPort(), InputPort::setStatus(), and status().

Referenced by setStartPort().

◆ shape()

QPainterPath Connection::shape ( ) const
override
Reimplemented from base class. Cached, flattened stroke of the wire path – the QGraphicsPathItem default
re-strokes the Bézier on every call and keeps its cubics, making every shape-exact hit test (clicks, rubber-band selection) pay for stroking plus recursive curve subdivision. Invalidated when the path or the real pen width changes.

Definition at line 329 of file Connection.cpp.

◆ startPort()

OutputPort * Connection::startPort ( ) const

Returns the output port this connection originates from.

Definition at line 146 of file Connection.cpp.

Referenced by Port::detachConnection(), itemChange(), ConnectionSerializer::save(), and SplitCommand::SplitCommand().

◆ status()

Status Connection::status ( ) const

Returns the current four-state signal status (Active/Inactive/Unknown/Error).

Definition at line 194 of file Connection.cpp.

Referenced by setEndPort(), and setStatus().

◆ statusPen()

QPen Connection::statusPen ( ) const
inline

Returns the pen paint() draws the wire with for its current status.

Definition at line 78 of file Connection.h.

◆ type()

int Connection::type ( ) const
inlineoverride

Definition at line 41 of file Connection.h.

References Type.

◆ updatePath()

void Connection::updatePath ( )

Recomputes the bezier control points from the current start/end positions.

Definition at line 116 of file Connection.cpp.

References Application::renderingEnabled.

Referenced by updatePosFromPorts().

◆ updatePosFromPorts()

void Connection::updatePosFromPorts ( )

Moves the wire endpoints to match the current port positions.

Definition at line 96 of file Connection.cpp.

References updatePath().

Referenced by ConnectionSerializer::load().

◆ updateTheme()

void Connection::updateTheme ( )

Refreshes wire colours from the current ThemeManager palette.

Definition at line 249 of file Connection.cpp.

References ThemeManager::attributes().

Referenced by Connection().


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