wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
WorkspaceManager.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 <QDir>
11#include <QFileInfo>
12#include <QObject>
13#include <QString>
14
15class MainWindowHost;
16class QByteArray;
17class QTabBar;
18class QTabWidget;
19class WorkSpace;
20
34class WorkspaceManager : public QObject
35{
36 Q_OBJECT
37
38public:
41 WorkspaceManager(QTabWidget *tab, MainWindowHost &host, QObject *parent = nullptr);
42
43 // --- Accessors (MainWindow's DolphinHost/MainWindowHost delegate here) ---
44
45 [[nodiscard]] WorkSpace *currentTab() const { return m_currentTab; }
46 [[nodiscard]] QFileInfo currentFile() const;
49 [[nodiscard]] QString currentTabName() const;
50 [[nodiscard]] QDir currentDir() const;
51 [[nodiscard]] QFileInfo icListFile() const;
52 [[nodiscard]] QString dolphinFileName() const;
53 void setDolphinFileName(const QString &fileName);
54
55 // --- Headless operations (called by CLI batch mode, the MCP server, and tests) ---
56
57 void createNewTab();
58 void loadPandaFile(const QString &fileName);
59 void openICInTab(const QString &blobName, int icElementId, const QByteArray &blob);
60 void save(const QString &fileName = {});
61 void loadAutosaveFiles();
62
63 [[nodiscard]] bool hasModifiedFiles();
64 bool closeFiles();
65 int confirmSave(bool multiple);
66
67public slots:
69 void onCurrentIndexChanged(int newIndex);
71 bool closeTab(int tabIndex);
72
73 // Interactive file-menu handlers (each guards its own body).
74 void newTab();
75 void openFile();
76 void saveFile();
77 void saveFileAs();
78 void reloadFile();
79
81 void setCurrentFile(const QFileInfo &fileInfo);
82
83signals:
87 void recentFileAdded(const QString &filePath);
91
92protected:
94 bool eventFilter(QObject *watched, QEvent *event) override;
95
96private:
97 int closeTabAnyway();
98 [[nodiscard]] int findTabWithFile(const QString &fileName) const;
99
103 [[nodiscard]] QString displayName(const WorkSpace *ws, const QFileInfo &fileInfo) const;
104
107 [[nodiscard]] QString nextUntitledTitle() const;
108
111 bool warnIfOpenInAnotherTab(const QString &fileName);
112
116 void onBlobRenamed(const QString &oldName, const QString &newName);
117
122 QString promptSavePath(const QString &fileName);
123
124 QTabWidget *m_tab;
128 QTabBar *m_tabBar = nullptr;
129 MainWindowHost &m_host;
130 WorkSpace *m_currentTab = nullptr;
131 int m_tabIndex = -1;
132};
Interface MainWindow provides to its extracted controllers (export, IC, …).
A widget containing a complete circuit editing environment.
Definition Workspace.h:33
void recentFileAdded(const QString &filePath)
Emitted when a file-backed tab is (re)named, to feed the recent-files list.
QString currentTabName() const
int confirmSave(bool multiple)
QFileInfo currentFile() const
bool closeTab(int tabIndex)
Closes the tab at tabIndex (prompting to save if needed). Returns false if cancelled.
void setDolphinFileName(const QString &fileName)
WorkspaceManager(QTabWidget *tab, MainWindowHost &host, QObject *parent=nullptr)
QString dolphinFileName() const
bool eventFilter(QObject *watched, QEvent *event) override
Closes the tab under the cursor when its tab bar is middle-clicked.
void openICInTab(const QString &blobName, int icElementId, const QByteArray &blob)
QDir currentDir() const
void onCurrentIndexChanged(int newIndex)
Reacts to QTabWidget::currentChanged: updates the current tab and emits currentTabChanged.
void save(const QString &fileName={})
void currentTabChanged(WorkSpace *tab)
Emitted when the active tab changes (or becomes null); the shell rebinds the chrome.
QFileInfo icListFile() const
WorkSpace * currentTab() const
void setCurrentFile(const QFileInfo &fileInfo)
Updates the tab title / tooltip / recent files for the workspace that emitted fileChanged.
void loadPandaFile(const QString &fileName)