wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
Led.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
11
19class Led : public GraphicElement
20{
21 Q_OBJECT
22
23 friend class TestLED;
24
25public:
28 static constexpr const char *kDefaultColor = "White";
29
30 // --- Lifecycle ---
31
33 explicit Led(QGraphicsItem *parent = nullptr);
34
35 // --- Color State ---
36
38 QString color() const override;
39
41 QString genericProperties() override;
43 void setColor(const QString &color) override;
44
45 // --- Visual ---
46
48 void refresh() override;
50 void setAppearance(const bool useDefaultAppearance, const QString &fileName) override;
52 QList<std::pair<int, QString>> appearanceStates() const override;
53
55 void updateLogic() override;
56
58 void updatePortsProperties() override;
59
60 // --- Serialization ---
61
63 void load(QDataStream &stream, SerializationContext &context) override;
65 void save(QDataStream &stream, SerializationOptions options) const override;
66
67private:
68 // --- Internal methods ---
69
70 int colorIndex();
71
72 // --- Members ---
73
74 QString m_color = kDefaultColor;
75 int m_colorIndex = 0; /* white = 0, red = 2, green = 4, blue = 6, purple = 8 */
76};
Abstract base class for all graphical circuit elements.
GraphicElement(ElementType type, QGraphicsItem *parent=nullptr)
Constructs a graphic element of the given type, fetching all properties from the metadata registry.
Led(QGraphicsItem *parent=nullptr)
Constructs the element with optional parent.
Definition Led.cpp:77
QString color() const override
Returns the current LED color name.
Definition Led.cpp:168
friend class TestLED
Definition Led.h:23
void updateLogic() override
Propagates input values to matching outputs.
Definition Led.cpp:292
QList< std::pair< int, QString > > appearanceStates() const override
Definition Led.cpp:243
void setColor(const QString &color) override
Sets the LED color to color.
Definition Led.cpp:159
void load(QDataStream &stream, SerializationContext &context) override
Definition Led.cpp:187
void updatePortsProperties() override
Updates port positions when input count changes.
Definition Led.cpp:212
void save(QDataStream &stream, SerializationOptions options) const override
Definition Led.cpp:173
QString genericProperties() override
Returns a string describing the current color for the element editor.
Definition Led.cpp:207
void setAppearance(const bool useDefaultAppearance, const QString &fileName) override
Definition Led.cpp:227
void refresh() override
Refreshes the visual appearance based on current state.
Definition Led.cpp:154
static constexpr const char * kDefaultColor
Definition Led.h:28
Bundles all per-deserialization state so that load() overrides receive it through one explicit parame...
Options passed to GraphicElement::save() (and friends); the save-side counterpart of SerializationCon...