wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
Workspace.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <QFileInfo>
11#include <QPointer>
12#include <QTimer>
13#include <QUndoStack>
14
15#include "App/Core/Settings.h"
17#include "App/Scene/Scene.h"
18
19class ExerciseOverlay;
20class GraphicsView;
21class Simulation;
22
32class WorkSpace : public QWidget
33{
34 Q_OBJECT
35
36 friend class TestWorkspaceUnit;
37
38public:
46
47 // --- Lifecycle ---
48
50 explicit WorkSpace(QWidget *parent = nullptr);
51
53 ~WorkSpace() override;
54
55 // --- Component Access ---
56
60 Scene *scene();
62 const Scene *scene() const;
63
66
67 // --- File Operations ---
68
70 QFileInfo fileInfo() const;
72 void load(const QString &fileName);
74 void load(QDataStream &stream, const QVersionNumber &version, const QString &contextDir);
75
85 SaveOutcome save(const QString &fileName);
87 void save(QDataStream &stream);
89 void setAutosaveFile();
90
93
94 // --- Inline IC Tab ---
95
97 void loadFromBlob(const QByteArray &blob, WorkSpace *parent, int icElementId, const QString &parentContextDir);
98
100 bool isInlineIC() const { return m_isInlineIC; }
101
103 WorkSpace *parentWorkspace() const { return m_parentWorkspace; }
104
106 int parentICElementId() const { return m_parentICElementId; }
107
109 const QString &inlineBlobName() const { return m_inlineBlobName; }
110
114 void setInlineBlobName(const QString &blobName) { m_inlineBlobName = blobName; }
115
119 const QString &untitledTitle() const { return m_untitledTitle; }
120 void setUntitledTitle(const QString &title) { m_untitledTitle = title; }
121
124 bool isRecovered() const { return m_isRecovered; }
125 void setRecovered(bool recovered) { m_isRecovered = recovered; }
126
128 void removeEmbeddedIC(const QString &blobName);
129
130 // Minimap control
131 void setMinimapVisible(bool visible);
132
133 // --- Waveform Integration ---
134
136 QString dolphinFileName() const;
138 void setDolphinFileName(const QString &fileName);
139
140 // --- ID Management ---
141
143 bool isFromNewerVersion() const;
144
146 int lastId() const;
147
152 void setLastId(int newLastId);
153
156 void setExerciseOverlay(ExerciseOverlay *overlay);
157
158protected:
159 void resizeEvent(QResizeEvent *event) override;
160 void showEvent(QShowEvent *event) override;
161
162signals:
167 void fileChanged(const QFileInfo &fileInfo);
168
170 void icBlobSaved(int icElementId, const QByteArray &blob);
171
172public slots:
174 void onChildICBlobSaved(int icElementId, const QByteArray &blob);
175
176private:
177 // --- Internal methods ---
178
179 void autosave();
180 void createVersionedBackup(const QString &fileName, const QVersionNumber &version);
181 void setAutosaveFileName();
182
184 void setCurrentFile(const QString &filePath);
185
190 void applyMinimapGeometry();
191
193 void onMinimapGeometryChangeFinished(const QRect &geometry);
194
195 // --- Members ---
196
197 GraphicsView m_view;
198 Scene m_scene;
199 QFileInfo m_fileInfo;
200 QString m_dolphinFileName;
201 QString m_autosaveFileName;
202 QTimer m_autosaveDebounceTimer;
203 QVersionNumber m_loadedVersion;
204 int m_lastId = 0;
205
206 // Minimap overview widget (small, shows full scene and viewport)
207 class MinimapWidget *m_minimap = nullptr;
211 bool m_minimapPositioned = false;
212
213 // Inline IC tab state
214 bool m_isInlineIC = false;
215 QPointer<WorkSpace> m_parentWorkspace;
216 int m_parentICElementId = -1;
217 QString m_inlineBlobName;
218 QString m_untitledTitle;
219 bool m_isRecovered = false;
220
221 // Exercise overlay — non-owning pointer
222 ExerciseOverlay *m_exerciseOverlay = nullptr;
223};
Extended QGraphicsView with zoom, pan, and fast-rendering modes.
Main circuit editing scene with undo/redo and user interaction.
Typed wrappers around QSettings for all application preferences.
Semi-transparent overlay displayed at the bottom of the canvas during a circuit exercise.
Extended QGraphicsView with enhanced navigation capabilities.
Main circuit editing scene.
Definition Scene.h:56
Manages the digital circuit simulation loop.
Definition Simulation.h:38
A widget containing a complete circuit editing environment.
Definition Workspace.h:33
void setLastId(int newLastId)
Forces the element-ID counter to newLastId.
void setDolphinFileName(const QString &fileName)
Sets the associated BeWavedDolphin waveform file path to fileName.
void icBlobSaved(int icElementId, const QByteArray &blob)
Emitted when an inline IC tab saves its blob (propagated to parent).
bool isFromNewerVersion() const
Returns true if the loaded file was saved by a newer version of wiRedPanda.
bool isRecovered() const
Definition Workspace.h:124
const QString & untitledTitle() const
Definition Workspace.h:119
bool isInlineIC() const
Returns true if this workspace is editing an embedded IC blob (not a file).
Definition Workspace.h:100
friend class TestWorkspaceUnit
Definition Workspace.h:36
void setAutosaveFile()
Creates or replaces the autosave temporary file.
void fileChanged(const QFileInfo &fileInfo)
Emitted whenever the file info of this workspace changes (load/save).
const QString & inlineBlobName() const
Returns the blob name being edited (for tab title).
Definition Workspace.h:109
Scene * scene()
Returns the Scene embedded in this workspace.
void onChildICBlobSaved(int icElementId, const QByteArray &blob)
Receives a saved blob from a child inline tab.
WorkSpace(QWidget *parent=nullptr)
Constructs the workspace with optional parent widget.
Definition Workspace.cpp:50
void setInlineBlobName(const QString &blobName)
Definition Workspace.h:114
void setMinimapVisible(bool visible)
void removeEmbeddedIC(const QString &blobName)
Removes all IC instances with the given blob name.
QString dolphinFileName() const
Returns the path of the associated BeWavedDolphin waveform file.
int lastId() const
Returns the highest element ID assigned in this workspace.
~WorkSpace() override
Flushes any pending debounced autosave on destruction.
Definition Workspace.cpp:93
int parentICElementId() const
Returns the element ID of the IC in the parent scene being edited.
Definition Workspace.h:106
void flushPendingAutosave()
Forces any pending debounced autosave to run synchronously.
void setExerciseOverlay(ExerciseOverlay *overlay)
void loadFromBlob(const QByteArray &blob, WorkSpace *parent, int icElementId, const QString &parentContextDir)
Loads a blob for editing in an inline tab.
void load(const QString &fileName)
Loads a circuit from the file at fileName.
void setRecovered(bool recovered)
Definition Workspace.h:125
WorkSpace * parentWorkspace() const
Returns the parent workspace (for inline IC tabs).
Definition Workspace.h:103
void resizeEvent(QResizeEvent *event) override
Simulation * simulation()
Returns the embedded Simulation.
GraphicsView * view()
Returns the GraphicsView embedded in this workspace.
void setUntitledTitle(const QString &title)
Definition Workspace.h:120
void showEvent(QShowEvent *event) override
SaveOutcome save(const QString &fileName)
Saves the current circuit to fileName.
QFileInfo fileInfo() const
Returns the file info for the currently open circuit file.