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

Manages interactive wire creation, deletion, validation and hover feedback. More...

#include <ConnectionManager.h>

Public Member Functions

void cancel ()
 Cancels and deletes the in-progress wire, if any.
void clearHover ()
 Clears the current hover state (unhighlights the port, resets cursor).
 ConnectionManager (Scene *scene)
void detach (InputPort *endPort)
 Detaches the existing wire on endPort and starts a new one from the same output.
ConnectioneditedConnection () const
 Returns the in-progress wire, or nullptr.
bool hasEditedConnection () const
 Returns true if a wire is currently being drawn.
void showHoverLabels (Port *port)
 Shows in-situ label chips for port itself and every port connected to it.
void startFromInput (InputPort *endPort)
 Begins a new in-progress wire anchored at endPort (input port).
void startFromOutput (OutputPort *startPort)
 Begins a new in-progress wire anchored at startPort (output port).
void tryComplete (const QPointF &scenePos)
 Attempts to complete the in-progress wire at the port under scenePos.
void updateEditedEnd (const QPointF &scenePos)
 Updates the free end of the in-progress wire to follow scenePos.
void updateHover (const QPointF &scenePos)
 Updates the hover state for the port under scenePos.

Static Public Member Functions

static QString connectionRejectionReason (OutputPort *startPort, InputPort *endPort)
static bool isConnectionAllowed (OutputPort *startPort, InputPort *endPort)
 Returns true if a wire from startPort to endPort is permitted.

Friends

class TestConnectionManager

Detailed Description

Manages interactive wire creation, deletion, validation and hover feedback.

Extracted from Scene to decouple connection-editing concerns from the main circuit scene. Owns the in-progress connection state and hover-port tracking; delegates item addition/removal and undo commands back to the owning Scene.

Definition at line 32 of file ConnectionManager.h.

Constructor & Destructor Documentation

◆ ConnectionManager()

ConnectionManager::ConnectionManager ( Scene * scene)
explicit

Definition at line 73 of file ConnectionManager.cpp.

Referenced by TestConnectionManager.

Member Function Documentation

◆ cancel()

void ConnectionManager::cancel ( )

Cancels and deletes the in-progress wire, if any.

Definition at line 147 of file ConnectionManager.cpp.

References editedConnection(), and sentryBreadcrumb().

Referenced by TestConnectionManager.

◆ clearHover()

void ConnectionManager::clearHover ( )

Clears the current hover state (unhighlights the port, resets cursor).

Definition at line 242 of file ConnectionManager.cpp.

Referenced by TestConnectionManager.

◆ connectionRejectionReason()

QString ConnectionManager::connectionRejectionReason ( OutputPort * startPort,
InputPort * endPort )
static

Returns a short, user-facing explanation of why the connection from startPort to endPort is disallowed, or an empty string if it is allowed. Single source of truth for isConnectionAllowed() and the status-bar feedback shown when a wire is rejected.

Definition at line 254 of file ConnectionManager.cpp.

References Port::graphicElement(), Port::isConnected(), and GraphicElement::wirelessMode().

Referenced by isConnectionAllowed(), TestConnectionManager, and tryComplete().

◆ detach()

void ConnectionManager::detach ( InputPort * endPort)

Detaches the existing wire on endPort and starts a new one from the same output.

Lets the user "grab" an existing wire and re-route it to a different input.

Definition at line 155 of file ConnectionManager.cpp.

References Port::connections(), sentryBreadcrumb(), and startFromOutput().

Referenced by TestConnectionManager.

◆ editedConnection()

Connection * ConnectionManager::editedConnection ( ) const
nodiscard

Returns the in-progress wire, or nullptr.

Definition at line 181 of file ConnectionManager.cpp.

Referenced by cancel(), hasEditedConnection(), TestConnectionManager, tryComplete(), updateEditedEnd(), and updateHover().

◆ hasEditedConnection()

bool ConnectionManager::hasEditedConnection ( ) const
nodiscard

Returns true if a wire is currently being drawn.

Definition at line 176 of file ConnectionManager.cpp.

References editedConnection().

Referenced by TestConnectionManager.

◆ isConnectionAllowed()

bool ConnectionManager::isConnectionAllowed ( OutputPort * startPort,
InputPort * endPort )
static

Returns true if a wire from startPort to endPort is permitted.

A connection is rejected when:

  • Either port is null.
  • Both ports belong to the same element (self-loop).
  • The ports are already connected (duplicate).
  • endPort belongs to a wireless Rx node (physical wire would be ignored by simulation).
  • startPort belongs to a wireless Tx node (tunnel convention: output drives channel only).

Definition at line 249 of file ConnectionManager.cpp.

References connectionRejectionReason().

Referenced by Scene::isConnectionAllowed(), and TestConnectionManager.

◆ showHoverLabels()

void ConnectionManager::showHoverLabels ( Port * port)

Shows in-situ label chips for port itself and every port connected to it.

Called from Scene::helpEvent in place of the native tooltip, so the chips appear and disappear at the same wake-up delay a tooltip would. Replaces any chips already shown.

Definition at line 335 of file ConnectionManager.cpp.

Referenced by TestConnectionManager.

◆ startFromInput()

void ConnectionManager::startFromInput ( InputPort * endPort)

Begins a new in-progress wire anchored at endPort (input port).

Definition at line 92 of file ConnectionManager.cpp.

Referenced by TestConnectionManager.

◆ startFromOutput()

void ConnectionManager::startFromOutput ( OutputPort * startPort)

Begins a new in-progress wire anchored at startPort (output port).

Definition at line 80 of file ConnectionManager.cpp.

References sentryBreadcrumb().

Referenced by detach(), and TestConnectionManager.

◆ tryComplete()

void ConnectionManager::tryComplete ( const QPointF & scenePos)

Attempts to complete the in-progress wire at the port under scenePos.

If the port is compatible the wire is committed via an AddItemsCommand; otherwise the in-progress wire is deleted.

Definition at line 103 of file ConnectionManager.cpp.

References connectionRejectionReason(), editedConnection(), and sentryBreadcrumb().

Referenced by TestConnectionManager.

◆ updateEditedEnd()

void ConnectionManager::updateEditedEnd ( const QPointF & scenePos)

Updates the free end of the in-progress wire to follow scenePos.

Definition at line 186 of file ConnectionManager.cpp.

References editedConnection().

Referenced by TestConnectionManager.

◆ updateHover()

void ConnectionManager::updateHover ( const QPointF & scenePos)

Updates the hover state for the port under scenePos.

Definition at line 213 of file ConnectionManager.cpp.

References editedConnection(), and Port::isOutput().

Referenced by TestConnectionManager.

◆ TestConnectionManager


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