|
wiRedPanda
Logic Circuit Simulator
|
A widget containing a complete circuit editing environment. More...
#include <Workspace.h>
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. | |
| WorkSpace * | parentWorkspace () 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. | |
| Scene * | scene () |
| Returns the Scene embedded in this workspace. | |
| const Scene * | scene () 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) |
| Simulation * | simulation () |
| Returns the embedded Simulation. | |
| const QString & | untitledTitle () const |
| GraphicsView * | view () |
| 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 |
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.
|
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.
|
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().
|
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().
| QString WorkSpace::dolphinFileName | ( | ) | const |
Returns the path of the associated BeWavedDolphin waveform file.
Definition at line 608 of file Workspace.cpp.
| void WorkSpace::fileChanged | ( | const QFileInfo & | fileInfo | ) |
Emitted whenever the file info of this workspace changes (load/save).
| fileInfo | New file info. |
References fileInfo().
Referenced by WorkspaceManager::createNewTab(), load(), and save().
| 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().
| void WorkSpace::flushPendingAutosave | ( | ) |
Forces any pending debounced autosave to run synchronously.
Definition at line 741 of file Workspace.cpp.
| 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().
|
inline |
Returns the blob name being edited (for tab title).
Definition at line 109 of file Workspace.h.
Referenced by WorkspaceManager::openICInTab().
| 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().
|
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().
|
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.
| int WorkSpace::lastId | ( | ) | const |
Returns the highest element ID assigned in this workspace.
Definition at line 624 of file Workspace.cpp.
| 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().
| void WorkSpace::load | ( | QDataStream & | stream, |
| const QVersionNumber & | version, | ||
| const QString & | contextDir ) |
Loads a circuit from stream using the given format version and optional contextDir.
Definition at line 519 of file Workspace.cpp.
References FormatRev::current, Serialization::deserialize(), Serialization::deserializeBlobRegistry(), VersionInfo::hasMetadata(), VersionInfo::hasUnifiedMetadata(), Application::interactiveMode, Serialization::loadDolphinFileName(), Serialization::loadRect(), PortableFile, qCDebug, Serialization::readBoundedMetadata(), and Serialization::readPayload().
| void WorkSpace::loadFromBlob | ( | const QByteArray & | blob, |
| WorkSpace * | parent, | ||
| int | icElementId, | ||
| const QString & | parentContextDir ) |
Loads a blob for editing in an inline tab.
Definition at line 754 of file Workspace.cpp.
References Serialization::deserialize(), Serialization::deserializeBlobRegistry(), Scene::itemById(), PortableFile, Serialization::readPreamble(), scene(), and WorkSpace().
| void WorkSpace::onChildICBlobSaved | ( | int | icElementId, |
| const QByteArray & | blob ) |
Receives a saved blob from a child inline tab.
Definition at line 805 of file Workspace.cpp.
References GraphicElement::blobName(), UpdateBlobCommand::captureConnections(), ICRegistry::captureSnapshot(), IC::loadFromBlob(), and ICRegistry::rollbackElements().
Referenced by WorkspaceManager::openICInTab().
|
inline |
Returns the element ID of the IC in the parent scene being edited.
Definition at line 106 of file Workspace.h.
|
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().
| 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.
|
overrideprotected |
Definition at line 127 of file Workspace.cpp.
| 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().
| 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 * 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().
| 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.
| void WorkSpace::setAutosaveFile | ( | ) |
Creates or replaces the autosave temporary file.
Definition at line 732 of file Workspace.cpp.
| void WorkSpace::setDolphinFileName | ( | const QString & | fileName | ) |
Sets the associated BeWavedDolphin waveform file path to fileName.
Definition at line 603 of file Workspace.cpp.
| 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.
|
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.
| void WorkSpace::setLastId | ( | int | newLastId | ) |
Forces the element-ID counter to newLastId.
| newLastId | New minimum ID for the next allocated item. |
Definition at line 629 of file Workspace.cpp.
| void WorkSpace::setMinimapVisible | ( | bool | visible | ) |
Definition at line 160 of file Workspace.cpp.
Referenced by MainWindow::MainWindow().
|
inline |
Definition at line 125 of file Workspace.h.
|
inline |
Definition at line 120 of file Workspace.h.
|
overrideprotected |
Definition at line 146 of file Workspace.cpp.
| Simulation * WorkSpace::simulation | ( | ) |
Returns the embedded Simulation.
Definition at line 233 of file Workspace.cpp.
Referenced by SceneUiBinder::bind().
|
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.
| 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().
|
friend |
Definition at line 36 of file Workspace.h.
References TestWorkspaceUnit.
Referenced by TestWorkspaceUnit.