|
wiRedPanda
Logic Circuit Simulator
|
Abstract base class for circuit element ports (connection endpoints). More...
#include <Port.h>
Public Types | |
| enum | { Type = QGraphicsItem::UserType + 1 } |
Public Member Functions | |
| void | attachConnection (Connection *conn) |
| Registers conn as a connection attached to this port. | |
| QRectF | boundingRect () const override |
| const QList< Connection * > & | connections () const |
| Returns the list of wires attached to this port. | |
| QPen | currentPen () const |
| Returns the pen paint() draws the port outline with for its current status. | |
| Status | defaultValue () const |
| Returns the default status applied when the port is unconnected. | |
| void | detachConnection (Connection *conn) |
| Removes conn from this port's connection list. | |
| int | globalIndex () const |
| GraphicElement * | graphicElement () |
| Returns the graphic element that owns this port. | |
| const GraphicElement * | graphicElement () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| void | hoverEnter () |
| Applies hover-enter visual feedback. | |
| void | hoverLeave () |
| Reverts hover-enter visual feedback. | |
| int | index () const |
| Returns the port's visual/logical index within the element. | |
| bool | isConnected (Port *otherPort) |
Returns true if this port is connected to otherPort via any wire. | |
| virtual bool | isInput () const =0 |
Returns true if this is an input port. Pure virtual. | |
| virtual bool | isOutput () const =0 |
Returns true if this is an output port. Pure virtual. | |
| bool | isRequired () const |
Returns true if a connection to this port is mandatory. | |
| virtual bool | isValid () const =0 |
Returns true if the port satisfies its connection requirement. Pure virtual. | |
| QString | name () const |
| Returns the port's label text. | |
| void | paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override |
| Port (QGraphicsItem *parent=nullptr) | |
| Constructs the port with optional parent item. | |
| void | setCurrentBrush (const QBrush ¤tBrush) |
| Sets the brush used to fill the port shape. | |
| void | setDefaultStatus (const Status defaultStatus) |
| Sets the status applied when the port has no connection. | |
| void | setGraphicElement (GraphicElement *graphicElement) |
| Binds this port to graphicElement. | |
| void | setIndex (const int index) |
| Sets the port's visual index within the element. | |
| void | setName (const QString &name) |
| Sets the label text shown next to the port. | |
| void | setRequired (const bool required) |
| Marks whether a wire to this port is mandatory. | |
| virtual void | setStatus (Status status)=0 |
| QPainterPath | shape () const override |
| Status | status () const |
| Returns the current logical status (Active/Inactive/Unknown/Error). | |
| int | type () const override |
| void | updateConnections () |
| Triggers a path update on all attached connections. | |
| void | updateTheme () |
| Reapplies the status-based pen and brush from the current ThemeManager palette. | |
| virtual | ~Port ()=default |
Static Public Member Functions | |
| static quint64 | makeSerialId (quint64 elementBase, int globalIndex) |
Protected Member Functions | |
| void | drainConnections (bool isInput) |
| Drains all attached connections, breaking back-references before deletion. | |
| QVariant | itemChange (GraphicsItemChange change, const QVariant &value) override |
Protected Attributes | |
| QList< Connection * > | m_connections |
| QBrush | m_currentBrush |
| QPen | m_currentPen |
| Status | m_defaultStatus = Status::Unknown |
| GraphicElement * | m_graphicElement = nullptr |
| int | m_index = 0 |
| QString | m_name |
| bool | m_required = true |
| Status | m_status = Status::Unknown |
Static Protected Attributes | |
| static constexpr int | kRadius = 5 |
Abstract base class for circuit element ports (connection endpoints).
A port is the small glyph drawn at the edge of a graphic element where wires attach — a circle for inputs, a right-pointing triangle for outputs. It stores a reference to the owning GraphicElement, all attached Connections, and its current logical status.
Concrete subclasses InputPort and OutputPort differentiate direction.
|
explicit |
Constructs the port with optional parent item.
Definition at line 16 of file Port.cpp.
Referenced by InputPort::InputPort(), isConnected(), and OutputPort::OutputPort().
|
virtualdefault |
| void Port::attachConnection | ( | Connection * | conn | ) |
Registers conn as a connection attached to this port.
Definition at line 62 of file Port.cpp.
References m_connections, and updateConnections().
|
override |
| const QList< Connection * > & Port::connections | ( | ) | const |
Returns the list of wires attached to this port.
Definition at line 57 of file Port.cpp.
References m_connections.
Referenced by ConnectionManager::detach(), CommandUtils::drainPortConnections(), ChangePortSizeCommand::redo(), and OutputPort::setStatus().
|
inline |
Returns the pen paint() draws the port outline with for its current status.
Definition at line 147 of file Port.h.
References m_currentPen.
|
inline |
Returns the default status applied when the port is unconnected.
Definition at line 76 of file Port.h.
References m_defaultStatus.
Referenced by updateConnections().
| void Port::detachConnection | ( | Connection * | conn | ) |
Removes conn from this port's connection list.
| conn | Wire to detach. |
Definition at line 77 of file Port.cpp.
References Connection::endPort(), m_connections, Connection::setEndPort(), Connection::setStartPort(), Connection::startPort(), and updateConnections().
|
protected |
Drains all attached connections, breaking back-references before deletion.
| isInput | True if this is an input port (sets endPort to nullptr); false for output. |
Called from the InputPort and OutputPort destructors to avoid re-entrant disconnect() calls into a partially destroyed port.
Definition at line 260 of file Port.cpp.
References isInput(), and m_connections.
Referenced by InputPort::~InputPort(), and OutputPort::~OutputPort().
| int Port::globalIndex | ( | ) | const |
Returns this port's index within the element's combined input+output port sequence: index() for input ports, index() + graphicElement()->inputSize() for output ports. The single source of truth for the port-ordering half of the serial-ID formula.
Definition at line 148 of file Port.cpp.
References isOutput(), m_graphicElement, and m_index.
Referenced by makeSerialId().
|
inline |
Returns the graphic element that owns this port.
Definition at line 66 of file Port.h.
References m_graphicElement.
Referenced by UpdateBlobCommand::captureConnections(), ConnectionManager::connectionRejectionReason(), ChangePortSizeCommand::redo(), setGraphicElement(), and SplitCommand::SplitCommand().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 68 of file Port.h.
References m_graphicElement.
| void Port::hoverEnter | ( | ) |
Applies hover-enter visual feedback.
Definition at line 218 of file Port.cpp.
References ThemeManager::attributes().
Referenced by Connection::itemChange().
| void Port::hoverLeave | ( | ) |
Reverts hover-enter visual feedback.
Definition at line 213 of file Port.cpp.
Referenced by Connection::itemChange().
| int Port::index | ( | ) | const |
Returns the port's visual/logical index within the element.
Definition at line 138 of file Port.cpp.
References m_index.
Referenced by UpdateBlobCommand::captureConnections(), and setIndex().
| bool Port::isConnected | ( | Port * | otherPort | ) |
Returns true if this port is connected to otherPort via any wire.
| otherPort | Port to check for an existing connection. |
Definition at line 94 of file Port.cpp.
References m_connections, and Port().
Referenced by ConnectionManager::connectionRejectionReason().
|
pure virtual |
Returns true if this is an input port. Pure virtual.
Implemented in InputPort, and OutputPort.
Referenced by drainConnections(), ConnectionSerializer::load(), and updateConnections().
|
pure virtual |
Returns true if this is an output port. Pure virtual.
Implemented in InputPort, and OutputPort.
Referenced by Connection::angle(), globalIndex(), ConnectionSerializer::load(), and ConnectionManager::updateHover().
| bool Port::isRequired | ( | ) | const |
Returns true if a connection to this port is mandatory.
Definition at line 194 of file Port.cpp.
References m_required.
Referenced by InputPort::isValid().
|
pure virtual |
Returns true if the port satisfies its connection requirement. Pure virtual.
Implemented in InputPort, and OutputPort.
Referenced by updateConnections().
|
overrideprotected |
Definition at line 129 of file Port.cpp.
References updateConnections().
|
static |
Packs elementBase and globalIndex into a serial ID: (elementBase << 16) | (globalIndex & 0xFFFF). The single source of truth for the serial-ID format used to resolve connection endpoints across save/load.
Definition at line 156 of file Port.cpp.
References globalIndex().
Referenced by ConnectionSerializer::save(), and GraphicElementSerializer::save().
| QString Port::name | ( | ) | const |
|
override |
Definition at line 44 of file Port.cpp.
References m_currentPen.
| void Port::setCurrentBrush | ( | const QBrush & | currentBrush | ) |
Sets the brush used to fill the port shape.
| currentBrush | New brush. |
Definition at line 183 of file Port.cpp.
References m_currentBrush.
Referenced by updateTheme().
| void Port::setDefaultStatus | ( | const Status | defaultStatus | ) |
Sets the status applied when the port has no connection.
| defaultStatus | Default status value. |
Definition at line 172 of file Port.cpp.
References m_defaultStatus, and setStatus().
Referenced by DFlipFlop::updatePortsProperties(), DLatch::updatePortsProperties(), JKFlipFlop::updatePortsProperties(), SRFlipFlop::updatePortsProperties(), SRLatch::updatePortsProperties(), and TFlipFlop::updatePortsProperties().
| void Port::setGraphicElement | ( | GraphicElement * | graphicElement | ) |
Binds this port to graphicElement.
| graphicElement | Owning graphic element. |
Definition at line 208 of file Port.cpp.
References graphicElement(), and m_graphicElement.
Referenced by ElementPorts::addPort().
| void Port::setIndex | ( | const int | index | ) |
| void Port::setName | ( | const QString & | name | ) |
Sets the label text shown next to the port.
| name | Label string (e.g. "A", "CLK"). |
Definition at line 166 of file Port.cpp.
References m_name, and name().
Referenced by ElementPorts::addPort(), Demux::updatePortsProperties(), DFlipFlop::updatePortsProperties(), Display14::updatePortsProperties(), Display16::updatePortsProperties(), DLatch::updatePortsProperties(), InputRotary::updatePortsProperties(), JKFlipFlop::updatePortsProperties(), Mux::updatePortsProperties(), SRFlipFlop::updatePortsProperties(), SRLatch::updatePortsProperties(), and TFlipFlop::updatePortsProperties().
| void Port::setRequired | ( | const bool | required | ) |
Marks whether a wire to this port is mandatory.
| required | true if a connection is required for valid simulation. |
Definition at line 199 of file Port.cpp.
References m_required, and updateConnections().
Referenced by Node::Node(), Node::setWirelessMode(), DFlipFlop::updatePortsProperties(), JKFlipFlop::updatePortsProperties(), SRFlipFlop::updatePortsProperties(), and TFlipFlop::updatePortsProperties().
|
pure virtual |
Implemented in InputPort, and OutputPort.
References status().
Referenced by setDefaultStatus(), and updateConnections().
|
override |
|
inline |
Returns the current logical status (Active/Inactive/Unknown/Error).
Definition at line 79 of file Port.h.
References m_status.
Referenced by Display7::paint(), Connection::setStartPort(), InputPort::setStatus(), OutputPort::setStatus(), and setStatus().
| void Port::updateConnections | ( | ) |
Triggers a path update on all attached connections.
Definition at line 100 of file Port.cpp.
References defaultValue(), isInput(), isValid(), m_connections, and setStatus().
Referenced by attachConnection(), detachConnection(), itemChange(), ElementOrientation::orientPort(), and setRequired().
| void Port::updateTheme | ( | ) |
Reapplies the status-based pen and brush from the current ThemeManager palette.
Definition at line 223 of file Port.cpp.
References ThemeManager::attributes(), m_currentPen, m_status, and setCurrentBrush().
Referenced by InputPort::InputPort(), OutputPort::OutputPort(), InputPort::setStatus(), and OutputPort::setStatus().
|
staticconstexprprotected |
Hit-area / glyph half-size in pixels. ±kRadius gives a 10×10 px clickable square, large enough to hit reliably without obscuring nearby elements.
Definition at line 199 of file Port.h.
Referenced by InputPort::InputPort(), OutputPort::OutputPort(), and shape().
|
protected |
Definition at line 210 of file Port.h.
Referenced by attachConnection(), connections(), detachConnection(), drainConnections(), isConnected(), InputPort::isValid(), and updateConnections().
|
protected |
Definition at line 204 of file Port.h.
Referenced by setCurrentBrush().
|
protected |
Pen paint() actually draws the outline with, kept separate from the item's own QGraphicsPathItem pen – see updateTheme() for why (avoids an unneeded BSP-tree re-index on every status colour change; all four status pens share the same width, so unlike Connection this never needs to fall back to the item's real pen).
Definition at line 209 of file Port.h.
Referenced by currentPen(), paint(), and updateTheme().
|
protected |
Definition at line 212 of file Port.h.
Referenced by defaultValue(), and setDefaultStatus().
|
protected |
Definition at line 203 of file Port.h.
Referenced by globalIndex(), graphicElement(), graphicElement(), and setGraphicElement().
|
protected |
Definition at line 215 of file Port.h.
Referenced by globalIndex(), index(), and setIndex().
|
protected |
|
protected |
Definition at line 214 of file Port.h.
Referenced by isRequired(), and setRequired().
|
protected |
Definition at line 213 of file Port.h.
Referenced by InputPort::InputPort(), InputPort::setStatus(), OutputPort::setStatus(), status(), and updateTheme().