wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
WorkSpace Class Reference

A widget containing a complete circuit editing environment. More...

#include <Workspace.h>

Inheritance diagram for WorkSpace:
[legend]

Public Types

enum class  SaveOutcome { Saved , ReadOnlyTarget }

Public Member Functions

QString dolphinFileName () const
 Returns the path of the associated BeWavedDolphin waveform file.
void fileChanged (const QFileInfo &fileInfo)
 Emitted whenever the file info of this workspace changes (load/save).
QFileInfo fileInfo () const
 Returns the file info for the currently open circuit file.
void flushPendingAutosave ()
 Forces any pending debounced autosave to run synchronously.
void icBlobSaved (int icElementId, const QByteArray &blob)
 Emitted when an inline IC tab saves its blob (propagated to parent).
const QString & inlineBlobName () const
 Returns the blob name being edited (for tab title).
bool isFromNewerVersion () const
 Returns true if the loaded file was saved by a newer version of wiRedPanda.
bool isInlineIC () const
 Returns true if this workspace is editing an embedded IC blob (not a file).
bool isRecovered () const
int lastId () const
 Returns the highest element ID assigned in this workspace.
void load (const QString &fileName)
 Loads a circuit from the file at fileName.
void load (QDataStream &stream, const QVersionNumber &version, const QString &contextDir)
 Loads a circuit from stream using the given format version and optional contextDir.
void loadFromBlob (const QByteArray &blob, WorkSpace *parent, int icElementId, const QString &parentContextDir)
 Loads a blob for editing in an inline tab.
void onChildICBlobSaved (int icElementId, const QByteArray &blob)
 Receives a saved blob from a child inline tab.
int parentICElementId () const
 Returns the element ID of the IC in the parent scene being edited.
WorkSpaceparentWorkspace () const
 Returns the parent workspace (for inline IC tabs).
void removeEmbeddedIC (const QString &blobName)
 Removes all IC instances with the given blob name.
SaveOutcome save (const QString &fileName)
 Saves the current circuit to fileName.
void save (QDataStream &stream)
 Saves the current circuit to stream.
Scenescene ()
 Returns the Scene embedded in this workspace.
const Scenescene () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void setAutosaveFile ()
 Creates or replaces the autosave temporary file.
void setDolphinFileName (const QString &fileName)
 Sets the associated BeWavedDolphin waveform file path to fileName.
void setExerciseOverlay (ExerciseOverlay *overlay)
void setInlineBlobName (const QString &blobName)
void setLastId (int newLastId)
 Forces the element-ID counter to newLastId.
void setMinimapVisible (bool visible)
void setRecovered (bool recovered)
void setUntitledTitle (const QString &title)
Simulationsimulation ()
 Returns the embedded Simulation.
const QString & untitledTitle () const
GraphicsViewview ()
 Returns the GraphicsView embedded in this workspace.
 WorkSpace (QWidget *parent=nullptr)
 Constructs the workspace with optional parent widget.
 ~WorkSpace () override
 Flushes any pending debounced autosave on destruction.

Protected Member Functions

void resizeEvent (QResizeEvent *event) override
void showEvent (QShowEvent *event) override

Friends

class TestWorkspaceUnit

Detailed Description

A widget containing a complete circuit editing environment.

WorkSpace serves as a container for all components needed for circuit editing, including the GraphicsView for visualization and interaction, Scene for element management, and Simulation for circuit simulation. It also handles file operations like loading, saving, and autosaving.

Definition at line 32 of file Workspace.h.

Member Enumeration Documentation

◆ SaveOutcome

enum class WorkSpace::SaveOutcome
strong

Outcome of a save attempt: whether it wrote to disk, or the target turned out to be read-only/unwritable (the caller decides whether to re-prompt for a different path or throw, depending on whether it's running interactively).

Enumerator
Saved 
ReadOnlyTarget 

Definition at line 42 of file Workspace.h.

Constructor & Destructor Documentation

◆ WorkSpace()

WorkSpace::WorkSpace ( QWidget * parent = nullptr)
explicit

Constructs the workspace with optional parent widget.

Refresh the parent's tab title (which shows "*" while dirty) whenever the undo stack's clean state flips — needed for inline-IC saves that push UpdateBlobCommand to a non-current parent workspace.

Definition at line 50 of file Workspace.cpp.

References Scene::circuitHasChanged(), MinimapWidget::geometryChangeFinished(), Scene::resizeScene(), and GraphicsView::zoomChanged().

Referenced by loadFromBlob(), and parentWorkspace().

◆ ~WorkSpace()

WorkSpace::~WorkSpace ( )
override

Flushes any pending debounced autosave on destruction.

Block signals for the rest of this object's lifetime — including member destruction below, where m_scene's QUndoStack emits cleanChanged on teardown. Without this, the cleanChanged → fileChanged chain would reach a parent MainWindow whose destructor has already begun. (RAII QSignalBlocker won't do: it releases when this body returns, before m_scene is destroyed.)

m_minimap is a QObject child of this WorkSpace, so Qt would normally destroy it automatically – but only as part of ~QObject(), which runs after all of WorkSpace's own members (including m_view and m_scene) have already been destructed. m_minimap holds a raw pointer to m_view and has an event filter installed on m_view's viewport, so destroying m_view first would leave that filter dereferencing a dangling GraphicsView mid-teardown. Delete it explicitly, here, before any member destruction begins.

Mirror the pre-debounce QTemporaryFile semantics: a clean Workspace destruction discards its autosave so it isn't recovered next launch. (On a real crash the destructor doesn't run, so the recovery file remains.)

Definition at line 93 of file Workspace.cpp.

References Settings::autosaveFiles(), and Settings::setAutosaveFiles().

Member Function Documentation

◆ dolphinFileName()

QString WorkSpace::dolphinFileName ( ) const

Returns the path of the associated BeWavedDolphin waveform file.

Definition at line 608 of file Workspace.cpp.

◆ fileChanged()

void WorkSpace::fileChanged ( const QFileInfo & fileInfo)

Emitted whenever the file info of this workspace changes (load/save).

Parameters
fileInfoNew file info.

References fileInfo().

Referenced by WorkspaceManager::createNewTab(), load(), and save().

◆ fileInfo()

QFileInfo WorkSpace::fileInfo ( ) const

Returns the file info for the currently open circuit file.

Definition at line 243 of file Workspace.cpp.

Referenced by fileChanged(), WorkspaceManager::icListFile(), and MainWindow::refreshICButtonsEnabled().

◆ flushPendingAutosave()

void WorkSpace::flushPendingAutosave ( )

Forces any pending debounced autosave to run synchronously.

Definition at line 741 of file Workspace.cpp.

◆ icBlobSaved()

void WorkSpace::icBlobSaved ( int icElementId,
const QByteArray & blob )

Emitted when an inline IC tab saves its blob (propagated to parent).

Referenced by WorkspaceManager::openICInTab(), and save().

◆ inlineBlobName()

const QString & WorkSpace::inlineBlobName ( ) const
inline

Returns the blob name being edited (for tab title).

Definition at line 109 of file Workspace.h.

Referenced by WorkspaceManager::openICInTab().

◆ isFromNewerVersion()

bool WorkSpace::isFromNewerVersion ( ) const

Returns true if the loaded file was saved by a newer version of wiRedPanda.

Definition at line 238 of file Workspace.cpp.

References FormatRev::current.

Referenced by save().

◆ isInlineIC()

bool WorkSpace::isInlineIC ( ) const
inline

Returns true if this workspace is editing an embedded IC blob (not a file).

Definition at line 100 of file Workspace.h.

Referenced by WorkspaceManager::icListFile(), and WorkspaceManager::openICInTab().

◆ isRecovered()

bool WorkSpace::isRecovered ( ) const
inline

True if this tab was restored from an autosave on launch. Surfaced as a "(recovered)" title marker until the user saves it to a real file, so recovered work is obvious.

Definition at line 124 of file Workspace.h.

◆ lastId()

int WorkSpace::lastId ( ) const

Returns the highest element ID assigned in this workspace.

Definition at line 624 of file Workspace.cpp.

◆ load() [1/2]

void WorkSpace::load ( const QString & fileName)

Loads a circuit from the file at fileName.

Definition at line 467 of file Workspace.cpp.

References FormatRev::current, fileChanged(), load(), Application::migrationEnabled, PANDACEPTION, qCDebug, ReadOnlyTarget, Serialization::readPandaHeader(), save(), and sentryBreadcrumb().

Referenced by load().

◆ load() [2/2]

void WorkSpace::load ( QDataStream & stream,
const QVersionNumber & version,
const QString & contextDir )

◆ loadFromBlob()

void WorkSpace::loadFromBlob ( const QByteArray & blob,
WorkSpace * parent,
int icElementId,
const QString & parentContextDir )

◆ onChildICBlobSaved()

void WorkSpace::onChildICBlobSaved ( int icElementId,
const QByteArray & blob )

◆ parentICElementId()

int WorkSpace::parentICElementId ( ) const
inline

Returns the element ID of the IC in the parent scene being edited.

Definition at line 106 of file Workspace.h.

◆ parentWorkspace()

WorkSpace * WorkSpace::parentWorkspace ( ) const
inline

Returns the parent workspace (for inline IC tabs).

Definition at line 103 of file Workspace.h.

References WorkSpace().

Referenced by WorkspaceManager::icListFile(), and WorkspaceManager::openICInTab().

◆ removeEmbeddedIC()

void WorkSpace::removeEmbeddedIC ( const QString & blobName)

Removes all IC instances with the given blob name.

Definition at line 852 of file Workspace.cpp.

References GraphicElement::Type.

◆ resizeEvent()

void WorkSpace::resizeEvent ( QResizeEvent * event)
overrideprotected

Definition at line 127 of file Workspace.cpp.

◆ save() [1/2]

WorkSpace::SaveOutcome WorkSpace::save ( const QString & fileName)

Saves the current circuit to fileName.

Pure: fileName must already be a resolved, non-empty, ".panda"-suffixed path (inline-IC tabs are the one exception – they ignore it and serialize to a blob instead). Shows no dialogs and never recurses; a read-only/unwritable target is reported via the return value rather than retried in place, regardless of Application::interactiveMode – callers decide how to react to that themselves. Throws PANDACEPTION only on a genuine, non-read-only I/O error.

Definition at line 248 of file Workspace.cpp.

References Settings::autosaveFiles(), Serialization::copyPandaFile(), FileUtils::copyToDir(), AppVersion::current, FormatRev::current, IC::file(), fileChanged(), icBlobSaved(), Application::interactiveMode, isFromNewerVersion(), PANDACEPTION, qCDebug, ReadOnlyTarget, save(), Saved, sentryBreadcrumb(), Serialization::serialize(), Serialization::serializeBlobRegistry(), Settings::setAutosaveFiles(), Serialization::writePandaHeader(), and Serialization::writePayload().

Referenced by load(), and save().

◆ save() [2/2]

void WorkSpace::save ( QDataStream & stream)

Saves the current circuit to stream.

Definition at line 419 of file Workspace.cpp.

References IC::buildPortMetadata(), Serialization::serialize(), Serialization::serializeBlobRegistry(), and Serialization::writePayload().

◆ scene() [1/2]

Scene * WorkSpace::scene ( )

Returns the Scene embedded in this workspace.

Definition at line 218 of file Workspace.cpp.

Referenced by SceneUiBinder::bind(), BaseHandler::currentScene(), BaseHandler::currentScene(), loadFromBlob(), and main().

◆ scene() [2/2]

const Scene * WorkSpace::scene ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 223 of file Workspace.cpp.

◆ setAutosaveFile()

void WorkSpace::setAutosaveFile ( )

Creates or replaces the autosave temporary file.

Definition at line 732 of file Workspace.cpp.

◆ setDolphinFileName()

void WorkSpace::setDolphinFileName ( const QString & fileName)

Sets the associated BeWavedDolphin waveform file path to fileName.

Definition at line 603 of file Workspace.cpp.

◆ setExerciseOverlay()

void WorkSpace::setExerciseOverlay ( ExerciseOverlay * overlay)

Registers an exercise overlay so WorkSpace can reposition it on resize. Pass nullptr to detach. Does not take ownership.

Definition at line 905 of file Workspace.cpp.

◆ setInlineBlobName()

void WorkSpace::setInlineBlobName ( const QString & blobName)
inline

Updates the tracked blob name after the underlying blob is renamed elsewhere in the registry, so a later lookup/second rename still matches this tab. Does not itself touch the tab title – the caller (WorkspaceManager) also owns retitling the QTabWidget entry.

Definition at line 114 of file Workspace.h.

◆ setLastId()

void WorkSpace::setLastId ( int newLastId)

Forces the element-ID counter to newLastId.

Parameters
newLastIdNew minimum ID for the next allocated item.

Definition at line 629 of file Workspace.cpp.

◆ setMinimapVisible()

void WorkSpace::setMinimapVisible ( bool visible)

Definition at line 160 of file Workspace.cpp.

Referenced by MainWindow::MainWindow().

◆ setRecovered()

void WorkSpace::setRecovered ( bool recovered)
inline

Definition at line 125 of file Workspace.h.

◆ setUntitledTitle()

void WorkSpace::setUntitledTitle ( const QString & title)
inline

Definition at line 120 of file Workspace.h.

◆ showEvent()

void WorkSpace::showEvent ( QShowEvent * event)
overrideprotected

Definition at line 146 of file Workspace.cpp.

◆ simulation()

Simulation * WorkSpace::simulation ( )

Returns the embedded Simulation.

Definition at line 233 of file Workspace.cpp.

Referenced by SceneUiBinder::bind().

◆ untitledTitle()

const QString & WorkSpace::untitledTitle ( ) const
inline

Stable placeholder title for an unsaved tab, e.g. "New Project" or "New Project 2". Assigned once at creation so the tab keeps the same number across edits; unused once the workspace is saved to a real file.

Definition at line 119 of file Workspace.h.

◆ view()

GraphicsView * WorkSpace::view ( )

Returns the GraphicsView embedded in this workspace.

Definition at line 228 of file Workspace.cpp.

Referenced by SceneUiBinder::bind(), and MainWindow::setFastMode().

◆ TestWorkspaceUnit

friend class TestWorkspaceUnit
friend

Definition at line 36 of file Workspace.h.

References TestWorkspaceUnit.

Referenced by TestWorkspaceUnit.


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