SILICON
Loading...
Searching...
No Matches
DiagramSceneSerializer Class Reference

Handles DiagramScene persistence, clipboard payloads, and reconstruction. More...

#include <diagramSceneSerializer.hpp>

Collaboration diagram for DiagramSceneSerializer:

Public Member Functions

 DiagramSceneSerializer (DiagramScene &scene)
 Constructs a serializer bound to a scene.
std::string serialize () const
 Serializes the full editor scene to the persisted JSON format.
nlohmann::ordered_json serializeSelection () const
 Serializes the current selection to the clipboard payload format.
nlohmann::ordered_json serializeItems (const std::vector< QGraphicsItem * > &sceneItems) const
 Serializes arbitrary scene items using the selection payload format.
void deserialize (const std::string &jsonStr, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry)
 Deserializes a full scene from persisted JSON.
std::shared_ptr< SceneLoadPlan > prepareDeserialize (const std::string &jsonStr, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry)
 Parses a scene payload without touching the host scene.
void applyDeserialize (std::shared_ptr< SceneLoadPlan > plan)
 Replaces the host scene with a plan built by prepareDeserialize.
void loadCircuit (std::shared_ptr< Circuit > circuit, GUIComponentFactory &guiFactory, bool resolveSubcircuitMetadata=true)
bool insertSelection (const nlohmann::json &payload, GUIComponentFactory &guiFactory, const ComponentRegistry &coreRegistry, QPointF targetOrigin, bool isPaste)
 Inserts a serialized selection payload into the current scene.
bool removeSelection (const nlohmann::json &payload)
 Removes items matching a serialized selection payload from the scene.

Private Attributes

DiagramScene & scene
 Host scene whose items and lookup tables back serialization operations.

Detailed Description

Handles DiagramScene persistence, clipboard payloads, and reconstruction.

This helper encapsulates the JSON formats used by the editor for full-scene saves, clipboard selections, undo payloads, and scene reconstruction. It keeps the payload semantics identical to the original DiagramScene implementation while moving the serialization concern out of the scene coordinator.

Definition at line 51 of file diagramSceneSerializer.hpp.

Constructor & Destructor Documentation

◆ DiagramSceneSerializer()

DiagramSceneSerializer ( DiagramScene & scene)
explicit

Constructs a serializer bound to a scene.

Parameters
sceneHost scene whose items and topology are serialized

Definition at line 352 of file diagramSceneSerializer.cpp.

Member Function Documentation

◆ applyDeserialize()

void applyDeserialize ( std::shared_ptr< SceneLoadPlan > plan)

Replaces the host scene with a plan built by prepareDeserialize.

This is the only step that clears the scene, so callers can validate a document before committing to it.

Parameters
planPlan produced by prepareDeserialize, consumed by this call

Definition at line 535 of file diagramSceneSerializer.cpp.

◆ deserialize()

void deserialize ( const std::string & jsonStr,
GUIComponentFactory & guiFactory,
const ComponentRegistry & coreRegistry )

Deserializes a full scene from persisted JSON.

Parameters
jsonStrJSON string to load
guiFactoryFactory for graphical component construction
coreRegistryRegistry for core component construction

Definition at line 499 of file diagramSceneSerializer.cpp.

◆ insertSelection()

bool insertSelection ( const nlohmann::json & payload,
GUIComponentFactory & guiFactory,
const ComponentRegistry & coreRegistry,
QPointF targetOrigin,
bool isPaste )

Inserts a serialized selection payload into the current scene.

Parameters
payloadDecoded clipboard or undo payload
guiFactoryFactory for graphical component construction
coreRegistryRegistry for core component construction
targetOriginScene position where the payload origin should land
isPasteTrue when the payload comes from paste and needs fresh runtime ids
Returns
True when at least one item was inserted

Definition at line 591 of file diagramSceneSerializer.cpp.

◆ loadCircuit()

void loadCircuit ( std::shared_ptr< Circuit > circuit,
GUIComponentFactory & guiFactory,
bool resolveSubcircuitMetadata = true )

Builds an autoplaced graphical scene around an already-created core circuit.

Definition at line 566 of file diagramSceneSerializer.cpp.

◆ prepareDeserialize()

std::shared_ptr< SceneLoadPlan > prepareDeserialize ( const std::string & jsonStr,
GUIComponentFactory & guiFactory,
const ComponentRegistry & coreRegistry )
nodiscard

Parses a scene payload without touching the host scene.

Every operation that can fail on an invalid payload happens here: the JSON is parsed, the logical circuit is deserialized, and the graphical items are built detached from the scene. The returned plan can therefore be discarded, leaving the current drawing untouched.

Parameters
jsonStrJSON string to load
guiFactoryFactory for graphical component construction
coreRegistryRegistry for core component construction
Returns
A detached plan consumed by applyDeserialize
Exceptions
std::exceptionwhen the payload cannot be deserialized

Definition at line 507 of file diagramSceneSerializer.cpp.

◆ removeSelection()

bool removeSelection ( const nlohmann::json & payload)

Removes items matching a serialized selection payload from the scene.

Parameters
payloadSerialized selection payload
Returns
True when any matching item was removed

Definition at line 638 of file diagramSceneSerializer.cpp.

◆ serialize()

std::string serialize ( ) const
nodiscard

Serializes the full editor scene to the persisted JSON format.

Returns
JSON string representation of the scene

Definition at line 354 of file diagramSceneSerializer.cpp.

◆ serializeItems()

nlohmann::ordered_json serializeItems ( const std::vector< QGraphicsItem * > & sceneItems) const
nodiscard

Serializes arbitrary scene items using the selection payload format.

Parameters
sceneItemsItems to serialize
Returns
Ordered JSON payload containing the provided items

Definition at line 415 of file diagramSceneSerializer.cpp.

◆ serializeSelection()

nlohmann::ordered_json serializeSelection ( ) const
nodiscard

Serializes the current selection to the clipboard payload format.

Returns
Ordered JSON payload for clipboard and undo flows

Definition at line 410 of file diagramSceneSerializer.cpp.

Member Data Documentation

◆ scene

DiagramScene& scene
private

Host scene whose items and lookup tables back serialization operations.

Definition at line 142 of file diagramSceneSerializer.hpp.


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