6#include <QGraphicsSceneMouseEvent>
17 .type = ElementType::InputButton,
18 .group = ElementGroup::Input,
21 .canChangeAppearance =
true,
24 .rotatesGraphic =
false,
26 static_assert(
validate(constraints));
31 meta.pixmapPath = []{
return QStringLiteral(
":/Components/Input/buttonOff.svg"); };
32 meta.titleText = QT_TRANSLATE_NOOP(
"InputButton",
"PUSH BUTTON");
33 meta.translatedName = QT_TRANSLATE_NOOP(
"InputButton",
"Push Button");
34 meta.trContext =
"InputButton";
35 meta.defaultAppearances = QStringList({
36 ":/Components/Input/buttonOff.svg",
37 ":/Components/Input/buttonOn.svg",
58 if (!
m_locked && (event->button() == Qt::LeftButton)) {
63 QGraphicsItem::mousePressEvent(event);
68 if (!
m_locked && (event->button() == Qt::LeftButton)) {
73 QGraphicsItem::mouseReleaseEvent(event);
80 QMap<QString, QVariant> map;
103 if (map.contains(
"locked")) {
104 m_locked = map.value(
"locked").toBool();
127 return {{0, tr(
"Released")}, {1, tr(
"Pressed")}};
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
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.
static void registerCreator(ElementType type, std::function< GraphicElement *()> creator)
Registers a creator lambda for type, used by buildElement().
virtual void load(QDataStream &stream, SerializationContext &context)
Loads the graphic element through a binary data stream.
virtual void save(QDataStream &stream, SerializationOptions options) const
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.
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.