6#include <QGraphicsSceneMouseEvent>
19 .type = ElementType::InputSwitch,
20 .group = ElementGroup::Input,
23 .canChangeAppearance =
true,
26 .rotatesGraphic =
false,
28 static_assert(
validate(constraints));
33 meta.pixmapPath = []{
return QStringLiteral(
":/Components/Input/switchOn.svg"); };
34 meta.titleText = QT_TRANSLATE_NOOP(
"InputSwitch",
"INPUT SWITCH");
35 meta.translatedName = QT_TRANSLATE_NOOP(
"InputSwitch",
"Input Switch");
36 meta.trContext =
"InputSwitch";
37 meta.defaultAppearances = QStringList({
38 ":/Components/Input/switchOff.svg",
39 ":/Components/Input/switchOn.svg",
81 if (!
m_locked && (event->button() == Qt::LeftButton)) {
87 auto *scene_ = qobject_cast<Scene *>(scene());
89 QDataStream stream(&oldData, QIODevice::WriteOnly);
98 scene_->receiveCommand(
new UpdateCommand({
this}, oldData, scene_));
102 QGraphicsItem::mousePressEvent(event);
111 QMap<QString, QVariant> map;
115 map.insert(
"isOn",
m_isOn);
141 if (map.contains(
"isOn")) {
142 m_isOn = map.value(
"isOn").toBool();
145 if (map.contains(
"locked")) {
146 m_locked = map.value(
"locked").toBool();
156 return {{0, tr(
"Off")}, {1, tr(
"On")}};
All QUndoCommand subclasses and the CommandUtils helper namespace.
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
Main circuit editing scene with undo/redo and user interaction.
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 void writePandaHeader(QDataStream &stream)
Writes the .panda circuit file header to stream.
static QMap< QString, QVariant > readBoundedMetadata(QDataStream &stream)
Reads the file-level metadata QMap<QString,QVariant> from stream without calling QList::reserve() wit...
Undo command for property changes (label, color, frequency, appearance, etc.).
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.