LibrePCB Developers Documentation
workspace.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_WORKSPACE_H
21 #define LIBREPCB_WORKSPACE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
28 
29 #include <QtCore>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 namespace library {
37 class Library;
38 }
39 
40 namespace project {
41 class Project;
42 }
43 
44 namespace workspace {
45 
46 class ProjectTreeModel;
47 class RecentProjectsModel;
48 class FavoriteProjectsModel;
49 class WorkspaceSettings;
50 class WorkspaceLibraryDb;
51 
52 /*******************************************************************************
53  * Class Workspace
54  ******************************************************************************/
55 
62 class Workspace final : public QObject {
63  Q_OBJECT
64 
65 public:
66  // Constructors / Destructor
67  Workspace() = delete;
68  Workspace(const Workspace& other) = delete;
69 
81  explicit Workspace(const FilePath& wsPath,
82  DirectoryLock::LockHandlerCallback lockCallback = nullptr);
83 
87  ~Workspace() noexcept;
88 
89  // Getters
90 
94  const FilePath& getPath() const { return mPath; }
95 
99  const FilePath& getProjectsPath() const { return mProjectsPath; }
100 
104  const FilePath& getMetadataPath() const { return mMetadataPath; }
105 
109  const FilePath& getLibrariesPath() const { return mLibrariesPath; }
110 
115  return mLibrariesPath.getPathTo("local");
116  }
117 
122  return mLibrariesPath.getPathTo("remote");
123  }
124 
125  ProjectTreeModel& getProjectTreeModel() const noexcept;
126  RecentProjectsModel& getRecentProjectsModel() const noexcept;
127  FavoriteProjectsModel& getFavoriteProjectsModel() const noexcept;
128 
132  WorkspaceSettings& getSettings() const { return *mWorkspaceSettings; }
133 
134  // Library Management
135 
139  WorkspaceLibraryDb& getLibraryDb() const { return *mLibraryDb; }
140 
141  // Project Management
142 
147  void setLastRecentlyUsedProject(const FilePath& filepath) noexcept;
148 
157  bool isFavoriteProject(const FilePath& filepath) const noexcept;
158 
164  void addFavoriteProject(const FilePath& filepath) noexcept;
165 
171  void removeFavoriteProject(const FilePath& filepath) noexcept;
172 
173  // Operator Overloadings
174  Workspace& operator=(const Workspace& rhs) = delete;
175 
176  // Static Methods
177 
186  static bool isValidWorkspacePath(const FilePath& path) noexcept;
187 
193  static QList<Version> getFileFormatVersionsOfWorkspace(
194  const FilePath& path) noexcept;
195 
201  static tl::optional<Version> getHighestFileFormatVersionOfWorkspace(
202  const FilePath& path) noexcept;
203 
211  static void createNewWorkspace(const FilePath& path);
212 
218  static FilePath getMostRecentlyUsedWorkspacePath() noexcept;
219 
225  static void setMostRecentlyUsedWorkspacePath(const FilePath& path) noexcept;
226 
234  static Version FILE_FORMAT_VERSION() noexcept {
235  return Version::fromString("0.1");
236  }
237 
238 private: // Data
241 
244 
247 
250 
253 
255  QScopedPointer<WorkspaceSettings> mWorkspaceSettings;
256 
258  QScopedPointer<WorkspaceLibraryDb> mLibraryDb;
259 
261  QScopedPointer<ProjectTreeModel> mProjectTreeModel;
262 
264  QScopedPointer<RecentProjectsModel> mRecentProjectsModel;
265 
267  QScopedPointer<FavoriteProjectsModel> mFavoriteProjectsModel;
268 };
269 
270 /*******************************************************************************
271  * End of File
272  ******************************************************************************/
273 
274 } // namespace workspace
275 } // namespace librepcb
276 
277 #endif // LIBREPCB_WORKSPACE_H
WorkspaceSettings & getSettings() const
Get the workspace settings.
Definition: workspace.h:132
QScopedPointer< WorkspaceLibraryDb > mLibraryDb
the library database
Definition: workspace.h:258
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
FilePath mMetadataPath
the subdirectory of the current file format version
Definition: workspace.h:246
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
Definition: airwiresbuilder.cpp:32
DirectoryLock mLock
to lock the version directory (mMetadataPath)
Definition: workspace.h:252
WorkspaceLibraryDb & getLibraryDb() const
Get the workspace library database.
Definition: workspace.h:139
QScopedPointer< WorkspaceSettings > mWorkspaceSettings
the WorkspaceSettings object
Definition: workspace.h:255
std::function< bool(const FilePath &dir, LockStatus status, const QString &user)> LockHandlerCallback
Callback type used to determine whether a lock should be overridden or not.
Definition: directorylock.h:194
FilePath mProjectsPath
the directory "projects"
Definition: workspace.h:243
const FilePath & getProjectsPath() const
Get the filepath to the "projects" directory in the workspace.
Definition: workspace.h:99
const FilePath & getLibrariesPath() const
Get the filepath to the "v#/libraries" directory in the workspace.
Definition: workspace.h:109
FilePath mLibrariesPath
the directory "v#/libraries"
Definition: workspace.h:249
QScopedPointer< ProjectTreeModel > mProjectTreeModel
a tree model for the whole projects directory
Definition: workspace.h:261
The FavoriteProjectsModel class.
Definition: favoriteprojectsmodel.h:48
FilePath mPath
a FilePath object which represents the workspace directory
Definition: workspace.h:240
The RecentProjectsModel class.
Definition: recentprojectsmodel.h:48
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QScopedPointer< RecentProjectsModel > mRecentProjectsModel
a list model of all recent projects
Definition: workspace.h:264
FilePath getPathTo(const QString &filename) const noexcept
Get the filepath to a file or directory which is relative to this filepath.
Definition: filepath.cpp:167
static Version FILE_FORMAT_VERSION() noexcept
Current workspace file format version (constant)
Definition: workspace.h:234
const FilePath & getPath() const
Get the filepath to the workspace directory.
Definition: workspace.h:94
FilePath getRemoteLibrariesPath() const
Get the filepath to the "v#/libraries/remote" directory.
Definition: workspace.h:121
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:52
static Version fromString(const QString &str)
Create a Version object from a string.
Definition: version.cpp:87
The ProjectTreeModel class.
Definition: projecttreemodel.h:44
Container for all workspace related settings.
Definition: workspacesettings.h:58
This class can be used to implement file-based directory locks.
Definition: directorylock.h:155
QScopedPointer< FavoriteProjectsModel > mFavoriteProjectsModel
a list model of all favorite projects
Definition: workspace.h:267
FilePath getLocalLibrariesPath() const
Get the filepath to the "v#/libraries/local" directory.
Definition: workspace.h:114
const FilePath & getMetadataPath() const
Get the filepath to the version directory (v#) in the workspace.
Definition: workspace.h:104