wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ConnectionManager.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <QCoreApplication>
11#include <QList>
12#include <QPair>
13#include <QPointer>
14#include <QPointF>
15
16class GraphicElement;
17class PortHoverLabel;
18class Connection;
19class InputPort;
20class OutputPort;
21class Port;
22class Scene;
23
33{
34 Q_DECLARE_TR_FUNCTIONS(ConnectionManager)
36
37public:
38 explicit ConnectionManager(Scene *scene);
39
40 // --- Wire creation workflow ---
41
43 void startFromOutput(OutputPort *startPort);
44
46 void startFromInput(InputPort *endPort);
47
54 void tryComplete(const QPointF &scenePos);
55
57 void cancel();
58
64 void detach(InputPort *endPort);
65
66 // --- In-progress wire state ---
67
69 [[nodiscard]] bool hasEditedConnection() const;
70
72 [[nodiscard]] Connection *editedConnection() const;
73
75 void updateEditedEnd(const QPointF &scenePos);
76
77 // --- Hover feedback ---
78
80 void updateHover(const QPointF &scenePos);
81
83 void clearHover();
84
91 void showHoverLabels(Port *port);
92
93 // --- Validation ---
94
105 static bool isConnectionAllowed(OutputPort *startPort, InputPort *endPort);
106
110 static QString connectionRejectionReason(OutputPort *startPort, InputPort *endPort);
111
112private:
113 void setEditedConnection(Connection *connection);
114 void deleteEditedConnection();
115
116 void setHoverPort(Port *port);
117 void releaseHoverPort();
118 [[nodiscard]] Port *hoverPort();
119
121 [[nodiscard]] static QList<Port *> connectedPeers(Port *port);
122
124 void clearHoverLabels();
125
126 Scene *m_scene = nullptr;
127
129 int m_editedConnectionId = 0;
130
132 int m_hoverPortElmId = 0;
133 int m_hoverPortNumber = 0;
134
136 QList<QPointer<PortHoverLabel>> m_peerLabels;
137
143 QList<QPair<int, int>> m_highlightedPeers;
144};
void clearHover()
Clears the current hover state (unhighlights the port, resets cursor).
void detach(InputPort *endPort)
Detaches the existing wire on endPort and starts a new one from the same output.
bool hasEditedConnection() const
Returns true if a wire is currently being drawn.
void tryComplete(const QPointF &scenePos)
Attempts to complete the in-progress wire at the port under scenePos.
void startFromOutput(OutputPort *startPort)
Begins a new in-progress wire anchored at startPort (output port).
Connection * editedConnection() const
Returns the in-progress wire, or nullptr.
static bool isConnectionAllowed(OutputPort *startPort, InputPort *endPort)
Returns true if a wire from startPort to endPort is permitted.
void showHoverLabels(Port *port)
Shows in-situ label chips for port itself and every port connected to it.
void updateHover(const QPointF &scenePos)
Updates the hover state for the port under scenePos.
friend class TestConnectionManager
ConnectionManager(Scene *scene)
void updateEditedEnd(const QPointF &scenePos)
Updates the free end of the in-progress wire to follow scenePos.
void cancel()
Cancels and deletes the in-progress wire, if any.
static QString connectionRejectionReason(OutputPort *startPort, InputPort *endPort)
void startFromInput(InputPort *endPort)
Begins a new in-progress wire anchored at endPort (input port).
A bezier-curve wire connecting an output port to an input port in the scene.
Definition Connection.h:38
Abstract base class for all graphical circuit elements in wiRedPanda.
A port that receives a signal (the destination end of a wire).
Definition Port.h:229
A port that drives a signal (the source end of a wire).
Definition Port.h:261
A small floating label drawn next to a port while a connected port is hovered.
Abstract base class for circuit element ports (connection endpoints).
Definition Port.h:39
Main circuit editing scene.
Definition Scene.h:56