20 .type = ElementType::Display16,
21 .group = ElementGroup::Output,
24 .canChangeAppearance =
true,
27 .rotatesGraphic =
false,
29 static_assert(
validate(constraints));
34 meta.pixmapPath = []{
return QStringLiteral(
":/Components/Output/Counter/counter_16_on.svg"); };
35 meta.titleText = QT_TRANSLATE_NOOP(
"Display16",
"16-SEGMENT DISPLAY");
36 meta.translatedName = QT_TRANSLATE_NOOP(
"Display16",
"16-Segment Display");
37 meta.trContext =
"Display16";
38 meta.defaultAppearances = QStringList({
39 ":/Components/Output/Counter/counter_16_off.svg",
40 ":/Components/Output/Counter/counter_a1.svg",
41 ":/Components/Output/Counter/counter_a2.svg",
42 ":/Components/Output/Counter/counter_b.svg",
43 ":/Components/Output/Counter/counter_c.svg",
44 ":/Components/Output/Counter/counter_d1.svg",
45 ":/Components/Output/Counter/counter_d2.svg",
46 ":/Components/Output/Counter/counter_e.svg",
47 ":/Components/Output/Counter/counter_f.svg",
48 ":/Components/Output/Counter/counter_g1.svg",
49 ":/Components/Output/Counter/counter_g2.svg",
50 ":/Components/Output/Counter/counter_h.svg",
51 ":/Components/Output/Counter/counter_j.svg",
52 ":/Components/Output/Counter/counter_k.svg",
53 ":/Components/Output/Counter/counter_l.svg",
54 ":/Components/Output/Counter/counter_m.svg",
55 ":/Components/Output/Counter/counter_n.svg",
56 ":/Components/Output/Counter/counter_dp.svg",
122 for (
auto *port :
inputs()) {
123 port->setRequired(
false);
124 port->setDefaultStatus(Status::Inactive);
132void Display16::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
138 const QRectF body(0, 0, 64, 64);
139 if (
inputPort( 0)->status() == Status::Active) { g1.at(m_colorNumber)->render(painter, body); }
140 if (
inputPort( 1)->status() == Status::Active) { f.at(m_colorNumber)->render(painter, body); }
141 if (
inputPort( 2)->status() == Status::Active) { e.at(m_colorNumber)->render(painter, body); }
142 if (
inputPort( 3)->status() == Status::Active) { d1.at(m_colorNumber)->render(painter, body); }
143 if (
inputPort( 4)->status() == Status::Active) { d2.at(m_colorNumber)->render(painter, body); }
144 if (
inputPort( 5)->status() == Status::Active) { a1.at(m_colorNumber)->render(painter, body); }
145 if (
inputPort( 6)->status() == Status::Active) { a2.at(m_colorNumber)->render(painter, body); }
146 if (
inputPort( 7)->status() == Status::Active) { b.at(m_colorNumber)->render(painter, body); }
147 if (
inputPort( 8)->status() == Status::Active) { dp.at(m_colorNumber)->render(painter, body); }
148 if (
inputPort( 9)->status() == Status::Active) { c.at(m_colorNumber)->render(painter, body); }
149 if (
inputPort(10)->status() == Status::Active) { g2.at(m_colorNumber)->render(painter, body); }
150 if (
inputPort(11)->status() == Status::Active) { h.at(m_colorNumber)->render(painter, body); }
151 if (
inputPort(12)->status() == Status::Active) { j.at(m_colorNumber)->render(painter, body); }
152 if (
inputPort(13)->status() == Status::Active) { k.at(m_colorNumber)->render(painter, body); }
153 if (
inputPort(14)->status() == Status::Active) { l.at(m_colorNumber)->render(painter, body); }
154 if (
inputPort(15)->status() == Status::Active) { m.at(m_colorNumber)->render(painter, body); }
155 if (
inputPort(16)->status() == Status::Active) { n.at(m_colorNumber)->render(painter, body); }
173 QMap<QString, QVariant> map;
177 map.insert(
"color",
color());
197 if (map.contains(
"color")) {
198 setColor(map.value(
"color").toString());
Graphic element for the 16-segment LED display.
Graphic element for the 7-segment LED display.
Singleton factory for all circuit element types.
Self-registering element trait template and compile-time constraint validation.
ElementMetadata metadataFromConstraints(const ElementConstraints &c)
Converts ElementConstraints to an ElementMetadata with all constraint-derived fields set.
constexpr bool validate(const ElementConstraints &c)
Validates element constraints at compile time.
Enums::ElementType ElementType
Port classes: Port (base), InputPort, and OutputPort.
Deserialization/serialization context structs passed through load()/save() call chains.
Circuit and waveform file serialization/deserialization utilities.
Named version predicates for file-format compatibility checks.
16-segment LED display output element (16 segments + decimal point = 17 inputs).
void load(QDataStream &stream, SerializationContext &context) override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void setColor(const QString &color) override
Sets the display color.
void refresh() override
Refreshes the displayed segments based on current input states.
Display16(QGraphicsItem *parent=nullptr)
Constructs the element with optional parent.
QString color() const override
Returns the current display color name.
static constexpr const char * kDefaultColor
void updatePortsProperties() override
Updates port positions (fixed at 17 inputs).
void save(QDataStream &stream, SerializationOptions options) const override
Serializes the color selection to stream.
static QVector< std::shared_ptr< QSvgRenderer > > cachedSegmentRenderers(const QString &resourcePath)
static void registerCreator(ElementType type, std::function< GraphicElement *()> creator)
Registers a creator lambda for type, used by buildElement().
GraphicElement(ElementType type, QGraphicsItem *parent=nullptr)
Constructs a graphic element of the given type, fetching all properties from the metadata registry.
ElementAppearance m_appearance
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Paints the element onto the scene.
virtual void load(QDataStream &stream, SerializationContext &context)
Loads the graphic element through a binary data stream.
InputPort * inputPort(const int index=0) const
Returns the input port at index (default 0).
static int colorNameToIndex(const QString &color)
Maps a color name ("White","Red","Green","Blue","Purple") to indices 0–4.
virtual void save(QDataStream &stream, SerializationOptions options) const
const QVector< InputPort * > & inputs() const
Returns a const reference to the vector of all input ports.
void setName(const QString &name)
Sets the label text shown next to the port.
static QString readBoundedString(QDataStream &stream)
Reads a QString from stream, refusing to allocate more bytes than remain in the stream (prevents OOM ...
static QMap< QString, QVariant > readBoundedMetadata(QDataStream &stream)
Reads the file-level metadata QMap<QString,QVariant> from stream without calling QList::reserve() wit...
bool hasLockState(const QVersionNumber &v)
V3.1: Lock state for input elements; color for some display/button types.
bool hasQMapFormat(const QVersionNumber &v)
V4.1: Format changed from flat binary to keyed QMap; port serial IDs; rotation fix.
Compile-time-validatable subset of ElementMetadata.
static const bool registered
static ElementMetadata metadata()
static constexpr ElementConstraints constraints
Self-registering element information trait.
Bundles all per-deserialization state so that load() overrides receive it through one explicit parame...
QVersionNumber version
File-format version read from the stream header.
Options passed to GraphicElement::save() (and friends); the save-side counterpart of SerializationCon...
SerializationPurpose purpose
What this serialization is for; see SerializationPurpose. Mandatory, no default.