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

Abstract base class for all graphical circuit elements in wiRedPanda. More...

#include <GraphicElement.h>

Inheritance diagram for GraphicElement:
[legend]

Public Types

enum  { Type = QGraphicsItem::UserType + 3 }

Public Member Functions

QVector< Port * > allPorts () const
 Returns a combined list of all input and output ports as Port pointers.
QPixmap appearancePreviewPixmap (const int index, const QSize &size) const
 Returns a small preview pixmap for the appearance at index (see appearanceStates()).
virtual QList< std::pair< int, QString > > appearanceStates () const
 Returns the list of editable appearance states for this element. Each pair is (appearance list index, human-readable state description). Override in subclasses with multi-state appearances (e.g., Led).
virtual QString audio () const
 Returns the name of the audio file currently associated with this element.
void beginDeferredCommit ()
virtual const QString & blobName () const
 Returns the blob name for embedded ICs, empty string otherwise. Base returns empty.
QRectF boundingRect () const override
 Returns the bounding rectangle of this element in local coordinates.
bool canChangeAppearance () const
 Returns true if the user is allowed to choose a custom appearance for this element.
void clearOutputChanged ()
 Clears the simulation output-changed flag.
virtual QString color () const
 Returns the name of the color currently applied to this element.
void commitDeferredOutputs ()
void connectPredecessor (const int inputIndex, GraphicElement *source, const int outputPort)
 Connects simulation input inputIndex to output outputPort of source element.
virtual double delay () const
 Returns the clock phase delay in seconds (overridden by Clock; returns 0 for other elements).
QList< PropertyDescriptoreditableProperties () const
 Returns the list of editable properties this element exposes in the ElementEditor.
ElementGroup elementGroup () const
 Returns the group this element belongs to.
ElementType elementType () const
 Returns the type identifier for this element.
virtual QStringList externalFiles () const
virtual double frequency () const
 Returns the clock frequency in Hz (overridden by Clock; returns 0 for other elements).
virtual QString genericProperties ()
 Returns a string encoding element-specific properties for serialization or display.
 GraphicElement (ElementType type, QGraphicsItem *parent=nullptr)
 Constructs a graphic element of the given type, fetching all properties from the metadata registry.
bool hasAudio () const
 Returns true if this element type supports audio output.
bool hasAudioBox () const
 Returns true if this element type shows an audio selection box.
bool hasColors () const
 Returns true if this element type supports color selection.
bool hasDelay () const
 Returns true if this element type exposes a configurable clock phase delay.
bool hasFrequency () const
 Returns true if this element type exposes a configurable clock frequency.
bool hasLabel () const
 Returns true if this element type supports a user-editable label.
bool hasTrigger () const
 Returns true if this element type supports a keyboard trigger.
bool hasTruthTable () const
 Returns true if this element type has an editable truth table.
bool hasVolume () const
 Returns true if this element type supports volume control.
virtual bool hasWirelessMode () const
 Returns true if this element supports a configurable wireless routing mode.
void initSimulationVectors (const int inputCount, const int outputCount)
 Allocates simulation I/O vectors with inputs inputs and outputs outputs.
void inlineEditRequested (GraphicElement *element)
InputPortinputPort (const int index=0) const
 Returns the input port at index (default 0).
const QVector< InputPort * > & inputs () const
 Returns a const reference to the vector of all input ports.
int inputSize () const
 Returns the current number of input ports.
virtual bool isEmbedded () const
 Returns true if this element is an embedded IC (not file-backed). Base returns false.
bool isFlippedX () const
 Returns true if this element is mirrored along the X axis (horizontal flip).
bool isFlippedY () const
 Returns true if this element is mirrored along the Y axis (vertical flip).
bool isValid ()
 Returns true if the element is fully initialised and connected correctly.
QString label () const
 Returns the user-visible label text for this element.
QRectF labelSceneBoundingRect () const
virtual void load (QDataStream &stream, SerializationContext &context)
 Loads the graphic element through a binary data stream.
virtual void loadFromDrop (const QString &fileName, const QString &contextDir)
 Polymorphic interface for drag-drop initialization (replaces elementType() == IC checks).
int maxInputSize () const
 Returns the maximum allowed number of input ports.
int maxOutputSize () const
 Returns the maximum allowed number of output ports.
int minInputSize () const
 Returns the minimum allowed number of input ports.
int minOutputSize () const
 Returns the minimum allowed number of output ports.
QString nextColor () const
 Returns the name of the next color in the element's color list.
bool outputChanged () const
OutputPortoutputPort (const int index=0) const
 Returns the output port at index (default 0).
const QVector< OutputPort * > & outputs () const
 Returns a const reference to the vector of all output ports.
int outputSize () const
 Returns the current number of output ports.
Status outputValue (const int index=0) const
 Returns the four-state signal value on simulation output port index.
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 Paints the element onto the scene.
QPointF pixmapCenter () const
 Returns the centre point of the element's pixmap in local coordinates.
QString previousColor () const
 Returns the name of the previous color in the element's color list.
void reapplyAppearanceOrientation ()
virtual void refresh ()
 Forces a visual refresh of the element's pixmap and ports.
virtual void resetSimState ()
 Resets all simulation-visible state to power-on defaults.
virtual void resettleCombinational ()
 Re-evaluates combinational outputs after the synchronous sequential commit, propagating just-committed flip-flop/latch state to downstream logic and IC output boundaries within the same tick.
void retranslate ()
 Updates the translated display name, tooltip, and port object name after a locale change.
void rotatePorts ()
bool rotatesGraphic () const
qreal rotation () const
 Returns the current rotation angle of this element in degrees.
virtual void save (QDataStream &stream, SerializationOptions options) const
virtual void setAppearance (const bool defaultAppearance, const QString &fileName)
 Switches the element's appearance.
void setAppearanceAt (const int index, const QString &fileName)
 Sets a custom appearance at a specific index in the appearance list.
virtual void setAudio (const QString &audio)
 Sets the audio file associated with this element to audio.
virtual void setColor (const QString &color)
 Sets the element color to color and refreshes the pixmap.
virtual void setDelay (const double delay)
 Sets the clock phase delay to delay (overridden by clock elements).
void setFlippedX (bool flipped)
 Sets the horizontal mirror state and updates the item transform.
void setFlippedY (bool flipped)
 Sets the vertical mirror state and updates the item transform.
virtual void setFrequency (const double freq)
 Sets the clock frequency to freq (overridden by clock elements).
void setInputs (const QVector< InputPort * > &inputs)
 Replaces the input port vector with inputs.
virtual void setInputSize (const int size)
 Adjusts the number of input ports to size, adding or removing ports as needed.
void setLabel (const QString &label)
 Sets the label text to label and refreshes the display.
virtual void setOutputSize (const int size)
 Adjusts the number of output ports to size, adding or removing ports as needed.
void setOutputValue (const bool value)
 Convenience overload — converts bool to Active/Inactive for port 0.
void setOutputValue (const int index, const bool value)
 Convenience overload — converts bool to Active/Inactive for port index.
void setOutputValue (const int index, const Status value)
 Sets simulation output port index to value.
void setOutputValue (const Status value)
 Sets simulation output port 0 to value.
void setPixmap (const int index)
 Loads and applies the appearance at position index in the appearance list.
void setPixmap (const QString &pixmapPath)
 Loads and applies the pixmap located at pixmapPath.
void setPortName (const QString &name)
 Sets the object name of all ports to name for identification.
void setRotation (const qreal angle)
 Rotates the element to angle degrees and updates port positions.
void setTrigger (const QKeySequence &trigger)
 Sets the keyboard shortcut to trigger and updates the label.
virtual void setVolume (float vol)
 Sets the audio playback volume to vol (0.0–1.0).
const QVector< Status > & simInputs () const
 Read-only view of the cached simulation input values.
const QVector< Status > & simOutputs () const
 Read-only view of the current simulation output values.
qsizetype simOutputSize () const
 Returns the number of simulation output slots.
QKeySequence trigger () const
 Returns the keyboard shortcut that activates this element.
int type () const override
 Returns the custom type identifier for this item.
void updateLabel ()
 Repositions and updates the label child item to reflect current state.
virtual void updateLogic ()
 Computes this element's output values from its current inputs.
virtual void updatePortsProperties ()
 Repositions and reconfigures all ports after the port count changes.
virtual void updateTheme ()
 Updates the element's visual theme according to the current dark/light palette.
virtual float volume () const
 Returns the audio playback volume (0.0–1.0).
virtual WirelessMode wirelessMode () const
 Returns the wireless routing mode for this element.
 ~GraphicElement () override
 Out-of-line so the unique_ptr to the forward-declared QSvgRenderer can be destroyed.
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.

Static Public Member Functions

static int colorNameToIndex (const QString &color)
 Maps a color name ("White","Red","Green","Blue","Purple") to indices 0–4.

Protected Member Functions

int decodeSelectValue (int offset, int count) const
 Decodes count select-line statuses from simInputs() into a binary index.
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 Handles item state changes such as position, rotation, and selection.
virtual void labelContentChanged ()
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override
 Requests inline label editing on double-click.
QPixmap pixmap () const
 Returns the pixmap currently displayed by this element.
QRectF portsBoundingRect () const
 Returns the bounding rectangle that encompasses all child ports.
QRectF renderBodyBounds () const
 Footprint of a "procedural render body" (IC/Mux/Demux/TruthTable): the nominal 64x64 body unioned with wherever the ports actually land, which extends past it once an instance has enough ports.
bool sceneEvent (QEvent *event) override
 Intercepts mouse-press and mouse-release events to handle Ctrl+click.
void setHasColors (const bool hasColors)
 Sets whether this element type supports color selection.
void setLabelAnchor (const QPointF &pos)
void setMaxInputSize (const int maxInputSize)
 Sets the maximum number of input ports to maxInputSize.
void setMaxOutputSize (const int maxOutputSize)
 Sets the maximum number of output ports to maxOutputSize.
void setMinInputSize (const int minInputSize)
 Sets the minimum number of input ports to minInputSize.
void setMinOutputSize (const int minOutputSize)
 Sets the minimum number of output ports to minOutputSize.
bool simUpdateInputs ()
 Snapshots each predecessor's output into the simulation input cache.
bool simUpdateInputsAllowUnknown ()
 Like simUpdateInputs(), but allows Unknown/Error values through.

Protected Attributes

ElementAppearance m_appearance {this}
QGraphicsSimpleTextItem * m_label = new QGraphicsSimpleTextItem(this)
 Child text item that displays the label and optional trigger shortcut.
QPointF m_labelAnchor
 The label's intended anchor point in the element's un-rotated local frame; see setLabelAnchor().
ElementPorts m_ports {this}
QString m_titleText
 Translated title text shown in UI panels (from metadata).
QString m_translatedName
 Translated element name used as tooltip and port object name.

Friends

class ElementAppearance
class GraphicElementSerializer

Detailed Description

Abstract base class for all graphical circuit elements in wiRedPanda.

Combines a QGraphicsObject (visual representation on the scene) with ItemWithId (stable numeric identity) to form the common interface that every circuit element must implement. Concrete subclasses cover gates, flip-flops, I/O elements, integrated circuits, and all other element types.

Responsibilities handled here:

  • Port management (input and output Port children).
  • Pixmap / appearance rendering with default and user-defined appearances.
  • Serialization to / from a versioned QDataStream (save/load).
  • Grid-snapping and wire-update callbacks via itemChange().
  • Label and keyboard-trigger display.
  • Theme-aware selection highlight painting.
  • Polymorphic hooks for clock frequency, audio, color, and truth-table features that only a subset of elements support.

Definition at line 58 of file GraphicElement.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Type 

Definition at line 64 of file GraphicElement.h.

Constructor & Destructor Documentation

◆ GraphicElement()

◆ ~GraphicElement()

GraphicElement::~GraphicElement ( )
overridedefault

Out-of-line so the unique_ptr to the forward-declared QSvgRenderer can be destroyed.

Member Function Documentation

◆ allPorts()

QVector< Port * > GraphicElement::allPorts ( ) const

Returns a combined list of all input and output ports as Port pointers.

Definition at line 154 of file GraphicElement.cpp.

References m_ports.

Referenced by itemChange().

◆ appearancePreviewPixmap()

QPixmap GraphicElement::appearancePreviewPixmap ( const int index,
const QSize & size ) const

Returns a small preview pixmap for the appearance at index (see appearanceStates()).

Definition at line 263 of file GraphicElement.cpp.

References m_appearance.

◆ appearanceStates()

QList< std::pair< int, QString > > GraphicElement::appearanceStates ( ) const
virtual

Returns the list of editable appearance states for this element. Each pair is (appearance list index, human-readable state description). Override in subclasses with multi-state appearances (e.g., Led).

Reimplemented in Clock, InputButton, InputSwitch, and Led.

Definition at line 257 of file GraphicElement.cpp.

◆ audio()

QString GraphicElement::audio ( ) const
virtual

Returns the name of the audio file currently associated with this element.

Reimplemented in AudioBox.

Definition at line 597 of file GraphicElement.cpp.

Referenced by setAudio().

◆ beginDeferredCommit()

void GraphicElement::beginDeferredCommit ( )
inline

Begins a deferred (non-blocking) output commit window; routes subsequent setOutputValue() calls to a staging buffer so peers read the pre-tick value.

Definition at line 430 of file GraphicElement.h.

◆ blobName()

virtual const QString & GraphicElement::blobName ( ) const
inlinevirtual

Returns the blob name for embedded ICs, empty string otherwise. Base returns empty.

Reimplemented in IC.

Definition at line 200 of file GraphicElement.h.

Referenced by WorkSpace::onChildICBlobSaved().

◆ boundingRect()

QRectF GraphicElement::boundingRect ( ) const
override

Returns the bounding rectangle of this element in local coordinates.

Definition at line 169 of file GraphicElement.cpp.

References pixmap(), and portsBoundingRect().

Referenced by Text::boundingRect(), and paint().

◆ canChangeAppearance()

bool GraphicElement::canChangeAppearance ( ) const

Returns true if the user is allowed to choose a custom appearance for this element.

Definition at line 658 of file GraphicElement.cpp.

Referenced by editableProperties().

◆ clearOutputChanged()

void GraphicElement::clearOutputChanged ( )
inline

Clears the simulation output-changed flag.

Definition at line 426 of file GraphicElement.h.

◆ color()

QString GraphicElement::color ( ) const
virtual

Returns the name of the color currently applied to this element.

Reimplemented in Display14, Display16, Display7, and Led.

Definition at line 577 of file GraphicElement.cpp.

Referenced by colorNameToIndex(), nextColor(), previousColor(), setColor(), and Node::setWirelessMode().

◆ colorNameToIndex()

int GraphicElement::colorNameToIndex ( const QString & color)
static

Maps a color name ("White","Red","Green","Blue","Purple") to indices 0–4.

Definition at line 582 of file GraphicElement.cpp.

References color().

Referenced by Display14::setColor(), Display16::setColor(), Display7::setColor(), and Led::setColor().

◆ commitDeferredOutputs()

void GraphicElement::commitDeferredOutputs ( )
inline

Ends the deferred-commit window and publishes staged outputs through the normal change-detecting path so visuals refresh correctly.

Definition at line 434 of file GraphicElement.h.

◆ connectPredecessor()

void GraphicElement::connectPredecessor ( const int inputIndex,
GraphicElement * source,
const int outputPort )

Connects simulation input inputIndex to output outputPort of source element.

Definition at line 740 of file GraphicElement.cpp.

References GraphicElement(), and outputPort().

◆ decodeSelectValue()

int GraphicElement::decodeSelectValue ( int offset,
int count ) const
inlineprotected

Decodes count select-line statuses from simInputs() into a binary index.

Parameters
offsetIndex of the first select-line input in simInputs().
countNumber of select lines to read.
Returns
An integer where bit i is 1 if simInputs()[offset+i] == Active.

Used by Mux and Demux to convert select-line signals into a data-port index.

Definition at line 627 of file GraphicElement.h.

Referenced by Demux::updateLogic(), and Mux::updateLogic().

◆ delay()

double GraphicElement::delay ( ) const
virtual

Returns the clock phase delay in seconds (overridden by Clock; returns 0 for other elements).

Reimplemented in Clock.

Definition at line 720 of file GraphicElement.cpp.

Referenced by setDelay().

◆ editableProperties()

QList< PropertyDescriptor > GraphicElement::editableProperties ( ) const

◆ elementGroup()

ElementGroup GraphicElement::elementGroup ( ) const

Returns the group this element belongs to.

Definition at line 99 of file GraphicElement.cpp.

Referenced by ICLoader::buildPortMetadata().

◆ elementType()

ElementType GraphicElement::elementType ( ) const

Returns the type identifier for this element.

Definition at line 94 of file GraphicElement.cpp.

Referenced by addElementAction(), PropertyShortcutHandler::nextElement(), PropertyShortcutHandler::prevElement(), and GraphicElementSerializer::save().

◆ externalFiles()

QStringList GraphicElement::externalFiles ( ) const
virtual

Returns the list of external (non-resource) file paths this element depends on. Used by the save infrastructure to copy files into the project directory.

Reimplemented in AudioBox, and IC.

Definition at line 109 of file GraphicElement.cpp.

References m_appearance.

Referenced by AudioBox::externalFiles().

◆ frequency()

double GraphicElement::frequency ( ) const
virtual

Returns the clock frequency in Hz (overridden by Clock; returns 0 for other elements).

Reimplemented in Buzzer, and Clock.

Definition at line 710 of file GraphicElement.cpp.

◆ genericProperties()

QString GraphicElement::genericProperties ( )
virtual

Returns a string encoding element-specific properties for serialization or display.

Reimplemented in Clock, and Led.

Definition at line 404 of file GraphicElement.cpp.

◆ hasAudio()

bool GraphicElement::hasAudio ( ) const

Returns true if this element type supports audio output.

Definition at line 388 of file GraphicElement.cpp.

Referenced by editableProperties().

◆ hasAudioBox()

bool GraphicElement::hasAudioBox ( ) const

Returns true if this element type shows an audio selection box.

Definition at line 622 of file GraphicElement.cpp.

Referenced by editableProperties().

◆ hasColors()

bool GraphicElement::hasColors ( ) const

Returns true if this element type supports color selection.

Definition at line 557 of file GraphicElement.cpp.

Referenced by editableProperties(), and setHasColors().

◆ hasDelay()

bool GraphicElement::hasDelay ( ) const

Returns true if this element type exposes a configurable clock phase delay.

Definition at line 607 of file GraphicElement.cpp.

Referenced by editableProperties().

◆ hasFrequency()

bool GraphicElement::hasFrequency ( ) const

Returns true if this element type exposes a configurable clock frequency.

Definition at line 602 of file GraphicElement.cpp.

Referenced by editableProperties().

◆ hasLabel()

bool GraphicElement::hasLabel ( ) const

Returns true if this element type supports a user-editable label.

Definition at line 612 of file GraphicElement.cpp.

Referenced by editableProperties(), and mouseDoubleClickEvent().

◆ hasTrigger()

bool GraphicElement::hasTrigger ( ) const

Returns true if this element type supports a keyboard trigger.

Definition at line 562 of file GraphicElement.cpp.

Referenced by editableProperties(), and updateLabel().

◆ hasTruthTable()

bool GraphicElement::hasTruthTable ( ) const

Returns true if this element type has an editable truth table.

Definition at line 617 of file GraphicElement.cpp.

Referenced by editableProperties().

◆ hasVolume()

bool GraphicElement::hasVolume ( ) const

Returns true if this element type supports volume control.

Definition at line 627 of file GraphicElement.cpp.

Referenced by editableProperties().

◆ hasWirelessMode()

bool GraphicElement::hasWirelessMode ( ) const
virtual

Returns true if this element supports a configurable wireless routing mode.

Returns false in the base class. Node overrides this to return true.

Returns
true when the element has a wirelessMode() that can be set.

Reimplemented in Node.

Definition at line 144 of file GraphicElement.cpp.

Referenced by editableProperties().

◆ initSimulationVectors()

void GraphicElement::initSimulationVectors ( const int inputCount,
const int outputCount )

Allocates simulation I/O vectors with inputs inputs and outputs outputs.

Definition at line 745 of file GraphicElement.cpp.

References m_ports.

◆ inlineEditRequested()

void GraphicElement::inlineEditRequested ( GraphicElement * element)

Emitted on double-click for a labelable element (hasLabel()) whose type doesn't already claim double-click for something else (IC/TruthTable override mouseDoubleClickEvent() directly and this signal never fires for them). The owning Scene listens and drives the actual inline edit widget – see InlineLabelEditor.

References GraphicElement(), and label().

Referenced by Scene::addItem(), and mouseDoubleClickEvent().

◆ inputPort()

◆ inputs()

◆ inputSize()

int GraphicElement::inputSize ( ) const

◆ isEmbedded()

virtual bool GraphicElement::isEmbedded ( ) const
inlinevirtual

Returns true if this element is an embedded IC (not file-backed). Base returns false.

Reimplemented in IC.

Definition at line 197 of file GraphicElement.h.

◆ isFlippedX()

bool GraphicElement::isFlippedX ( ) const
inline

Returns true if this element is mirrored along the X axis (horizontal flip).

Definition at line 348 of file GraphicElement.h.

Referenced by ICRenderer::drawBody(), and GraphicElementSerializer::save().

◆ isFlippedY()

bool GraphicElement::isFlippedY ( ) const
inline

Returns true if this element is mirrored along the Y axis (vertical flip).

Definition at line 351 of file GraphicElement.h.

Referenced by ICRenderer::drawBody(), and GraphicElementSerializer::save().

◆ isValid()

bool GraphicElement::isValid ( )

Returns true if the element is fully initialised and connected correctly.

Definition at line 534 of file GraphicElement.cpp.

References m_ports, and qCDebug.

Referenced by AudioOutputElement::refresh().

◆ itemChange()

QVariant GraphicElement::itemChange ( GraphicsItemChange change,
const QVariant & value )
overrideprotected

Handles item state changes such as position, rotation, and selection.

Three change types are intercepted:

  • ItemPositionChange: snaps the new position to half the scene grid size.
  • ItemScenePositionHasChanged / ItemRotationHasChanged / ItemTransformHasChanged: calls updateConnections() on all ports to redraw attached wires.
  • ItemSelectedHasChanged: toggles connection highlight via highlight().
    Parameters
    changeThe type of change that occurred.
    valueThe new value associated with the change.
    Returns
    The (possibly modified) value to use, or the base class result.

Definition at line 326 of file GraphicElement.cpp.

References allPorts(), Constants::gridSize, and qCDebug.

◆ label()

QString GraphicElement::label ( ) const

◆ labelContentChanged()

virtual void GraphicElement::labelContentChanged ( )
inlineprotectedvirtual

Hook called whenever the label text is set (including on construction and on inline-edit commit). Base is a no-op; Text overrides it to toggle its empty-state hint.

Reimplemented in Text.

Definition at line 526 of file GraphicElement.h.

Referenced by updateLabel().

◆ labelSceneBoundingRect()

QRectF GraphicElement::labelSceneBoundingRect ( ) const

Returns the label child item's bounding rect in scene coordinates – used to position the inline rename editor over the visible label. Empty when the label has no text yet (a caller should fall back to the element's own sceneBoundingRect() in that case).

Definition at line 488 of file GraphicElement.cpp.

References m_label.

Referenced by InlineLabelEditor::start().

◆ load()

void GraphicElement::load ( QDataStream & stream,
SerializationContext & context )
virtual

Loads the graphic element through a binary data stream.

Parameters
contextcarries portMap, version, contextDir and optional copy-operation state.

Reimplemented in AudioBox, Buzzer, Clock, Display14, Display16, Display7, IC, InputButton, InputRotary, InputSwitch, Led, Node, and TruthTable.

Definition at line 86 of file GraphicElementSerializer.cpp.

References GraphicElementSerializer::load().

Referenced by AudioBox::load(), Buzzer::load(), Clock::load(), Display14::load(), Display16::load(), Display7::load(), IC::load(), InputButton::load(), InputRotary::load(), InputSwitch::load(), Led::load(), Node::load(), and TruthTable::load().

◆ loadFromDrop()

void GraphicElement::loadFromDrop ( const QString & fileName,
const QString & contextDir )
virtual

Polymorphic interface for drag-drop initialization (replaces elementType() == IC checks).

Reimplemented in IC.

Definition at line 813 of file GraphicElement.cpp.

◆ maxInputSize()

int GraphicElement::maxInputSize ( ) const

Returns the maximum allowed number of input ports.

Definition at line 765 of file GraphicElement.cpp.

Referenced by setMaxInputSize().

◆ maxOutputSize()

int GraphicElement::maxOutputSize ( ) const

Returns the maximum allowed number of output ports.

Definition at line 760 of file GraphicElement.cpp.

Referenced by setMaxOutputSize(), and Demux::setOutputSize().

◆ minInputSize()

int GraphicElement::minInputSize ( ) const

Returns the minimum allowed number of input ports.

Definition at line 755 of file GraphicElement.cpp.

Referenced by setMinInputSize().

◆ minOutputSize()

int GraphicElement::minOutputSize ( ) const

Returns the minimum allowed number of output ports.

Definition at line 750 of file GraphicElement.cpp.

Referenced by setMinOutputSize(), and Demux::setOutputSize().

◆ mouseDoubleClickEvent()

void GraphicElement::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

Requests inline label editing on double-click.

Only fires for hasLabel() elements; other types fall through to the base Qt behavior unchanged. IC and TruthTable override this method themselves (to open a sub-circuit / the truth-table editor instead), so this base implementation is never reached for them – ordinary virtual dispatch, no elementType() check needed here.

Definition at line 377 of file GraphicElement.cpp.

References hasLabel(), and inlineEditRequested().

◆ nextColor()

QString GraphicElement::nextColor ( ) const

Returns the name of the next color in the element's color list.

Definition at line 506 of file GraphicElement.cpp.

References color().

◆ outputChanged()

bool GraphicElement::outputChanged ( ) const
inline

Returns true if any simulation output changed since the flag was last cleared (it does NOT reset the flag — see clearOutputChanged()).

Definition at line 423 of file GraphicElement.h.

◆ outputPort()

◆ outputs()

const QVector< OutputPort * > & GraphicElement::outputs ( ) const

Returns a const reference to the vector of all output ports.

Definition at line 124 of file GraphicElement.cpp.

References m_ports.

Referenced by ICLoader::buildPortMetadata(), InputGnd::InputGnd(), InputVcc::InputVcc(), IC::load(), InputRotary::outputSize(), TruthTable::updatePortsProperties(), and BaseHandler::validatePortRange().

◆ outputSize()

int GraphicElement::outputSize ( ) const

Returns the current number of output ports.

Definition at line 700 of file GraphicElement.cpp.

References m_ports.

Referenced by BaseHandler::availablePorts(), BaseHandler::outputPortByLabel(), Demux::updateLogic(), TruthTable::updateLogic(), and Demux::updatePortsProperties().

◆ outputValue()

Status GraphicElement::outputValue ( const int index = 0) const
inline

Returns the four-state signal value on simulation output port index.

Definition at line 401 of file GraphicElement.h.

◆ paint()

void GraphicElement::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget )
override

Paints the element onto the scene.

Draws a rounded selection rectangle when the item is selected, then draws the current pixmap at the item origin.

Parameters
painterPainter provided by the graphics view framework.
optionStyle options (unused).
widgetTarget widget (unused).

Definition at line 200 of file GraphicElement.cpp.

References boundingRect(), and m_appearance.

Referenced by Display14::paint(), Display16::paint(), Display7::paint(), and InputRotary::paint().

◆ pixmap()

QPixmap GraphicElement::pixmap ( ) const
protected

Returns the pixmap currently displayed by this element.

Definition at line 104 of file GraphicElement.cpp.

References m_appearance.

Referenced by boundingRect(), and ICRenderer::drawBody().

◆ pixmapCenter()

QPointF GraphicElement::pixmapCenter ( ) const

Returns the centre point of the element's pixmap in local coordinates.

Definition at line 164 of file GraphicElement.cpp.

References m_appearance.

Referenced by InputRotary::paint().

◆ portsBoundingRect()

QRectF GraphicElement::portsBoundingRect ( ) const
protected

Returns the bounding rectangle that encompasses all child ports.

Iterates over childItems(), mapping each Port's bounding rect into the element's local coordinate space.

Returns
Combined bounding QRectF of all port children.

Definition at line 174 of file GraphicElement.cpp.

Referenced by boundingRect(), and renderBodyBounds().

◆ previousColor()

QString GraphicElement::previousColor ( ) const

Returns the name of the previous color in the element's color list.

Definition at line 496 of file GraphicElement.cpp.

References color().

◆ reapplyAppearanceOrientation()

void GraphicElement::reapplyAppearanceOrientation ( )
inline

Forwards the appearance's orientation re-application after a rotation/flip transform change, and keeps the name label counter-oriented to match. Public because ElementOrientation (a sibling collaborator, not a subclass) calls it back after updating the item transform.

Definition at line 343 of file GraphicElement.h.

References m_appearance.

◆ refresh()

void GraphicElement::refresh ( )
virtual

Forces a visual refresh of the element's pixmap and ports.

Reimplemented in AudioOutputElement, Display14, Display16, Display7, IC, InputRotary, and Led.

Definition at line 319 of file GraphicElement.cpp.

References setPixmap().

◆ renderBodyBounds()

QRectF GraphicElement::renderBodyBounds ( ) const
protected

Footprint of a "procedural render body" (IC/Mux/Demux/TruthTable): the nominal 64x64 body unioned with wherever the ports actually land, which extends past it once an instance has enough ports.

Single source of truth for boundingRect(), the sizing pixmap, and the selection-highlight rect on those four element types, so they can never drift out of sync with each other.

Definition at line 188 of file GraphicElement.cpp.

References portsBoundingRect().

Referenced by Demux::boundingRect(), IC::boundingRect(), Mux::boundingRect(), TruthTable::boundingRect(), ICRenderer::generatePixmap(), and TruthTable::updatePortsProperties().

◆ resetSimState()

void GraphicElement::resetSimState ( )
virtual

Resets all simulation-visible state to power-on defaults.

The base implementation resets each output slot to its port's defaultStatus(). Sequential elements (flip-flops, latches) override this to also clear their internal edge-detection variables (m_simLastClk, etc.) so that BeWavedDolphin can start every sweep from a known, reproducible state.

Reimplemented in DFlipFlop, JKFlipFlop, SRFlipFlop, and TFlipFlop.

Definition at line 735 of file GraphicElement.cpp.

References m_ports.

Referenced by DFlipFlop::resetSimState(), JKFlipFlop::resetSimState(), SRFlipFlop::resetSimState(), and TFlipFlop::resetSimState().

◆ resettleCombinational()

virtual void GraphicElement::resettleCombinational ( )
inlinevirtual

Re-evaluates combinational outputs after the synchronous sequential commit, propagating just-committed flip-flop/latch state to downstream logic and IC output boundaries within the same tick.

Called only on non-sequential elements (the simulation skips ElementGroup::Memory so their edge state is not disturbed). The default recomputes via updateLogic(); IC overrides it to recurse through its internals while skipping its own sequential elements.

Reimplemented in IC.

Definition at line 398 of file GraphicElement.h.

References updateLogic().

◆ retranslate()

void GraphicElement::retranslate ( )

Updates the translated display name, tooltip, and port object name after a locale change.

Queries ElementFactory for the new translated name and propagates it to setPortName() and setToolTip().

Definition at line 805 of file GraphicElement.cpp.

References m_translatedName, setPortName(), and ElementFactory::translatedName().

◆ rotatePorts()

void GraphicElement::rotatePorts ( )

Re-applies the combined rotation + flip orientation to every port. Used by non-rotatable elements, which keep their pixmap fixed and move only their ports around the centre.

Definition at line 227 of file GraphicElement.cpp.

Referenced by Display14::updatePortsProperties(), Display16::updatePortsProperties(), and Display7::updatePortsProperties().

◆ rotatesGraphic()

bool GraphicElement::rotatesGraphic ( ) const

Returns true if rotating/flipping re-orients this element's graphic. When false the icon stays fixed and only the ports reposition around the centre (the element still rotates).

Definition at line 663 of file GraphicElement.cpp.

Referenced by updatePortsProperties(), and TruthTable::updatePortsProperties().

◆ rotation()

qreal GraphicElement::rotation ( ) const

Returns the current rotation angle of this element in degrees.

Definition at line 232 of file GraphicElement.cpp.

Referenced by ICRenderer::drawBody(), and GraphicElementSerializer::save().

◆ save()

void GraphicElement::save ( QDataStream & stream,
SerializationOptions options ) const
virtual

Saves the graphic element through a binary data stream. options has no default – every caller must state whether this builds a genuine .panda file or an in-session snapshot; see SerializationPurpose.

Reimplemented in AudioBox, Buzzer, Clock, Display14, Display16, Display7, IC, InputButton, InputRotary, InputSwitch, Led, Node, and TruthTable.

Definition at line 81 of file GraphicElementSerializer.cpp.

References GraphicElementSerializer::save().

Referenced by ChangePortSizeCommand::redo(), AudioBox::save(), Buzzer::save(), Clock::save(), Display14::save(), Display16::save(), Display7::save(), IC::save(), InputButton::save(), InputRotary::save(), InputSwitch::save(), Led::save(), Node::save(), and TruthTable::save().

◆ sceneEvent()

bool GraphicElement::sceneEvent ( QEvent * event)
overrideprotected

Intercepts mouse-press and mouse-release events to handle Ctrl+click.

When Ctrl is held during a mouse press or release, the event is consumed here and not forwarded, preventing accidental multi-selection.

Parameters
eventThe scene event to inspect.
Returns
true if the event was consumed; otherwise the base class result.

Definition at line 362 of file GraphicElement.cpp.

◆ setAppearance()

void GraphicElement::setAppearance ( const bool defaultAppearance,
const QString & fileName )
virtual

Switches the element's appearance.

Parameters
defaultAppearancetrue to restore the built-in default appearance.
fileNameFile path of the custom appearance image (used when defaultAppearance is false).

Reimplemented in GraphicElementInput, InputRotary, and Led.

Definition at line 247 of file GraphicElement.cpp.

References m_appearance.

◆ setAppearanceAt()

void GraphicElement::setAppearanceAt ( const int index,
const QString & fileName )

Sets a custom appearance at a specific index in the appearance list.

Parameters
indexAppearance list index.
fileNameFile path of the custom appearance image (empty restores default for that index).

Definition at line 252 of file GraphicElement.cpp.

References m_appearance.

◆ setAudio()

void GraphicElement::setAudio ( const QString & audio)
virtual

Sets the audio file associated with this element to audio.

Reimplemented in AudioBox, and Buzzer.

Definition at line 592 of file GraphicElement.cpp.

References audio().

◆ setColor()

void GraphicElement::setColor ( const QString & color)
virtual

Sets the element color to color and refreshes the pixmap.

Reimplemented in Display14, Display16, Display7, and Led.

Definition at line 567 of file GraphicElement.cpp.

References color().

◆ setDelay()

void GraphicElement::setDelay ( const double delay)
virtual

Sets the clock phase delay to delay (overridden by clock elements).

Reimplemented in Clock.

Definition at line 725 of file GraphicElement.cpp.

References delay().

◆ setFlippedX()

void GraphicElement::setFlippedX ( bool flipped)

Sets the horizontal mirror state and updates the item transform.

Definition at line 237 of file GraphicElement.cpp.

◆ setFlippedY()

void GraphicElement::setFlippedY ( bool flipped)

Sets the vertical mirror state and updates the item transform.

Definition at line 242 of file GraphicElement.cpp.

◆ setFrequency()

void GraphicElement::setFrequency ( const double freq)
virtual

Sets the clock frequency to freq (overridden by clock elements).

Reimplemented in Buzzer, and Clock.

Definition at line 715 of file GraphicElement.cpp.

◆ setHasColors()

void GraphicElement::setHasColors ( const bool hasColors)
protected

Sets whether this element type supports color selection.

Definition at line 572 of file GraphicElement.cpp.

References hasColors().

Referenced by Led::Led(), and Led::updatePortsProperties().

◆ setInputs()

void GraphicElement::setInputs ( const QVector< InputPort * > & inputs)

Replaces the input port vector with inputs.

Definition at line 159 of file GraphicElement.cpp.

References inputs(), and m_ports.

Referenced by Display7::load().

◆ setInputSize()

void GraphicElement::setInputSize ( const int size)
virtual

Adjusts the number of input ports to size, adding or removing ports as needed.

Definition at line 695 of file GraphicElement.cpp.

Referenced by GraphicElement(), and Demux::setOutputSize().

◆ setLabel()

void GraphicElement::setLabel ( const QString & label)

Sets the label text to label and refreshes the display.

Definition at line 477 of file GraphicElement.cpp.

References label(), and updateLabel().

Referenced by ICRegistry::initEmbeddedIC(), and ICLoader::loadFile().

◆ setLabelAnchor()

void GraphicElement::setLabelAnchor ( const QPointF & pos)
protected

Sets the label's anchor point in the element's un-rotated local frame, and repositions it there. pos is remembered (m_labelAnchor) so updateLabelOrientation() can always recompute the label's actual on-screen position from this original value, rather than from whatever rotation-adjusted position it last computed.

Definition at line 193 of file GraphicElement.cpp.

References m_label, and m_labelAnchor.

Referenced by AudioOutputElement::AudioOutputElement(), GraphicElement(), Node::Node(), and TruthTable::updatePortsProperties().

◆ setMaxInputSize()

void GraphicElement::setMaxInputSize ( const int maxInputSize)
protected

Sets the maximum number of input ports to maxInputSize.

Definition at line 770 of file GraphicElement.cpp.

References maxInputSize().

◆ setMaxOutputSize()

void GraphicElement::setMaxOutputSize ( const int maxOutputSize)
protected

Sets the maximum number of output ports to maxOutputSize.

Definition at line 775 of file GraphicElement.cpp.

References maxOutputSize().

◆ setMinInputSize()

void GraphicElement::setMinInputSize ( const int minInputSize)
protected

Sets the minimum number of input ports to minInputSize.

Definition at line 780 of file GraphicElement.cpp.

References minInputSize().

◆ setMinOutputSize()

void GraphicElement::setMinOutputSize ( const int minOutputSize)
protected

Sets the minimum number of output ports to minOutputSize.

Definition at line 785 of file GraphicElement.cpp.

References minOutputSize().

◆ setOutputSize()

void GraphicElement::setOutputSize ( const int size)
virtual

Adjusts the number of output ports to size, adding or removing ports as needed.

Reimplemented in Demux.

Definition at line 705 of file GraphicElement.cpp.

Referenced by GraphicElement(), and Demux::setOutputSize().

◆ setOutputValue() [1/4]

void GraphicElement::setOutputValue ( const bool value)
inline

Convenience overload — converts bool to Active/Inactive for port 0.

Definition at line 416 of file GraphicElement.h.

◆ setOutputValue() [2/4]

void GraphicElement::setOutputValue ( const int index,
const bool value )
inline

Convenience overload — converts bool to Active/Inactive for port index.

Definition at line 413 of file GraphicElement.h.

◆ setOutputValue() [3/4]

◆ setOutputValue() [4/4]

void GraphicElement::setOutputValue ( const Status value)
inline

Sets simulation output port 0 to value.

Definition at line 410 of file GraphicElement.h.

◆ setPixmap() [1/2]

void GraphicElement::setPixmap ( const int index)

Loads and applies the appearance at position index in the appearance list.

Definition at line 114 of file GraphicElement.cpp.

References m_appearance.

◆ setPixmap() [2/2]

◆ setPortName()

void GraphicElement::setPortName ( const QString & name)

Sets the object name of all ports to name for identification.

Definition at line 217 of file GraphicElement.cpp.

Referenced by GraphicElement(), and retranslate().

◆ setRotation()

void GraphicElement::setRotation ( const qreal angle)

Rotates the element to angle degrees and updates port positions.

Definition at line 222 of file GraphicElement.cpp.

◆ setTrigger()

void GraphicElement::setTrigger ( const QKeySequence & trigger)

Sets the keyboard shortcut to trigger and updates the label.

Definition at line 398 of file GraphicElement.cpp.

References trigger(), and updateLabel().

◆ setVolume()

void GraphicElement::setVolume ( float vol)
virtual

Sets the audio playback volume to vol (0.0–1.0).

Reimplemented in AudioOutputElement.

Definition at line 637 of file GraphicElement.cpp.

◆ simInputs()

◆ simOutputs()

const QVector< Status > & GraphicElement::simOutputs ( ) const
inline

Read-only view of the current simulation output values.

Definition at line 487 of file GraphicElement.h.

Referenced by DFlipFlop::updateLogic(), DLatch::updateLogic(), JKFlipFlop::updateLogic(), SRFlipFlop::updateLogic(), SRLatch::updateLogic(), and TFlipFlop::updateLogic().

◆ simOutputSize()

qsizetype GraphicElement::simOutputSize ( ) const
inline

Returns the number of simulation output slots.

Definition at line 404 of file GraphicElement.h.

Referenced by GraphicElementInput::updateOutputs().

◆ simUpdateInputs()

bool GraphicElement::simUpdateInputs ( )
inlineprotected

Snapshots each predecessor's output into the simulation input cache.

If any predecessor output is Unknown or Error, all outputs are set to Unknown and the method returns false so that sequential elements (flip-flops, latches) can skip computation with incomplete data. Unconnected inputs (null predecessor) use the corresponding port's defaultStatus(), replacing the old global GND/VCC approach.

Returns
true if all inputs are Active or Inactive (simulation can proceed).

Definition at line 609 of file GraphicElement.h.

References m_ports.

Referenced by DFlipFlop::updateLogic(), DLatch::updateLogic(), JKFlipFlop::updateLogic(), Led::updateLogic(), SRFlipFlop::updateLogic(), SRLatch::updateLogic(), and TFlipFlop::updateLogic().

◆ simUpdateInputsAllowUnknown()

bool GraphicElement::simUpdateInputsAllowUnknown ( )
inlineprotected

Like simUpdateInputs(), but allows Unknown/Error values through.

Combinational gates use this so their domination rules (e.g. AND(0, X) = 0) can short-circuit even with unknown inputs. Only a truly unconnected input (null predecessor whose port default is Unknown) triggers an early all-outputs-Unknown return.

Definition at line 618 of file GraphicElement.h.

References m_ports.

Referenced by ICSimulation::resettle(), ICSimulation::update(), And::updateLogic(), Demux::updateLogic(), Mux::updateLogic(), Nand::updateLogic(), Node::updateLogic(), Nor::updateLogic(), Not::updateLogic(), Or::updateLogic(), TruthTable::updateLogic(), Xnor::updateLogic(), and Xor::updateLogic().

◆ trigger()

QKeySequence GraphicElement::trigger ( ) const

Returns the keyboard shortcut that activates this element.

Definition at line 393 of file GraphicElement.cpp.

Referenced by GraphicElementSerializer::save(), setTrigger(), and updateLabel().

◆ type()

int GraphicElement::type ( ) const
inlineoverride

Returns the custom type identifier for this item.

Definition at line 67 of file GraphicElement.h.

References Type.

Referenced by AudioOutputElement::AudioOutputElement(), GraphicElement(), and GraphicElementInput::GraphicElementInput().

◆ updateLabel()

void GraphicElement::updateLabel ( )

Repositions and updates the label child item to reflect current state.

Definition at line 409 of file GraphicElement.cpp.

References hasTrigger(), label(), labelContentChanged(), labelFont(), m_label, and trigger().

Referenced by setLabel(), and setTrigger().

◆ updateLogic()

void GraphicElement::updateLogic ( )
virtual

Computes this element's output values from its current inputs.

Override in subclasses to implement element-specific logic.

Reimplemented in And, Demux, DFlipFlop, DLatch, IC, JKFlipFlop, Led, Mux, Nand, Node, Nor, Not, Or, SRFlipFlop, SRLatch, TFlipFlop, TruthTable, Xnor, and Xor.

Definition at line 730 of file GraphicElement.cpp.

Referenced by resettleCombinational().

◆ updatePortsProperties()

void GraphicElement::updatePortsProperties ( )
virtual

Repositions and reconfigures all ports after the port count changes.

Distributes input ports vertically on the left edge (x=0) and output ports on the right edge (x=64), spaced by half the scene grid size. Also reapplies rotation for non-rotatable elements. Called after construction, loading, and any input/output size change.

Reimplemented in Demux, DFlipFlop, Display14, Display16, Display7, DLatch, InputRotary, JKFlipFlop, Led, Mux, Node, SRFlipFlop, SRLatch, TFlipFlop, and TruthTable.

Definition at line 268 of file GraphicElement.cpp.

References Constants::gridSize, m_ports, qCDebug, and rotatesGraphic().

Referenced by GraphicElement(), GraphicElementSerializer::load(), and Led::updatePortsProperties().

◆ updateTheme()

void GraphicElement::updateTheme ( )
virtual

◆ volume()

float GraphicElement::volume ( ) const
virtual

Returns the audio playback volume (0.0–1.0).

Reimplemented in AudioOutputElement.

Definition at line 632 of file GraphicElement.cpp.

◆ wirelessMode()

WirelessMode GraphicElement::wirelessMode ( ) const
virtual

Returns the wireless routing mode for this element.

Returns WirelessMode::None for all elements except Node, which overrides this to expose its configurable Tx/Rx mode.

Returns
WirelessMode::None for all base elements.

Reimplemented in Node.

Definition at line 139 of file GraphicElement.cpp.

Referenced by ConnectionManager::connectionRejectionReason().

◆ ElementAppearance

friend class ElementAppearance
friend

Calls prepareGeometryChange() before its pixmap mutation resizes boundingRect(), and invalidateRenderCache() when that mutation changes the pixmap size; see ElementAppearance::setPixmap()/setRenderPixmap().

Definition at line 639 of file GraphicElement.h.

References ElementAppearance.

Referenced by ElementAppearance.

◆ GraphicElementSerializer

friend class GraphicElementSerializer
friend

Reaches ports/orientation/appearance/context-directory state to implement save()/load(); see GraphicElementSerializer.

Definition at line 634 of file GraphicElement.h.

References GraphicElementSerializer.

Referenced by GraphicElementSerializer.

Member Data Documentation

◆ m_appearance

◆ m_label

QGraphicsSimpleTextItem* GraphicElement::m_label = new QGraphicsSimpleTextItem(this)
protected

Child text item that displays the label and optional trigger shortcut.

Definition at line 588 of file GraphicElement.h.

Referenced by GraphicElement(), IC::IC(), labelSceneBoundingRect(), setLabelAnchor(), updateLabel(), and updateTheme().

◆ m_labelAnchor

QPointF GraphicElement::m_labelAnchor
protected

The label's intended anchor point in the element's un-rotated local frame; see setLabelAnchor().

Definition at line 589 of file GraphicElement.h.

Referenced by setLabelAnchor().

◆ m_ports

ElementPorts GraphicElement::m_ports {this}
protected

Owns the input/output port vectors and their creation/resize lifecycle; this element forwards its port-access interface here. See ElementPorts.

Definition at line 582 of file GraphicElement.h.

Referenced by allPorts(), initSimulationVectors(), inputPort(), inputs(), inputSize(), isValid(), outputPort(), outputs(), outputSize(), resetSimState(), GraphicElementSerializer::save(), setInputs(), simUpdateInputs(), simUpdateInputsAllowUnknown(), updatePortsProperties(), and updateTheme().

◆ m_titleText

QString GraphicElement::m_titleText
protected

Translated title text shown in UI panels (from metadata).

Definition at line 593 of file GraphicElement.h.

Referenced by GraphicElement().

◆ m_translatedName

QString GraphicElement::m_translatedName
protected

Translated element name used as tooltip and port object name.

Definition at line 594 of file GraphicElement.h.

Referenced by GraphicElement(), and retranslate().


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