LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
78  explicit Workspace(const FilePath& wsPath);
79 
83  ~Workspace() noexcept;
84 
85  // Getters
86 
90  const FilePath& getPath() const { return mPath; }
91 
95  const FilePath& getProjectsPath() const { return mProjectsPath; }
96 
100  const FilePath& getMetadataPath() const { return mMetadataPath; }
101 
105  const FilePath& getLibrariesPath() const { return mLibrariesPath; }
106 
111  return mLibrariesPath.getPathTo("local");
112  }
113 
118  return mLibrariesPath.getPathTo("remote");
119  }
120 
121  ProjectTreeModel& getProjectTreeModel() const noexcept;
124 
129 
130  // Library Management
131 
136 
137  // Project Management
138 
143  void setLastRecentlyUsedProject(const FilePath& filepath) noexcept;
144 
153  bool isFavoriteProject(const FilePath& filepath) const noexcept;
154 
160  void addFavoriteProject(const FilePath& filepath) noexcept;
161 
167  void removeFavoriteProject(const FilePath& filepath) noexcept;
168 
169  // Operator Overloadings
170  Workspace& operator=(const Workspace& rhs) = delete;
171 
172  // Static Methods
173 
182  static bool isValidWorkspacePath(const FilePath& path) noexcept;
183 
189  static QList<Version> getFileFormatVersionsOfWorkspace(
190  const FilePath& path) noexcept;
191 
197  static tl::optional<Version> getHighestFileFormatVersionOfWorkspace(
198  const FilePath& path) noexcept;
199 
207  static void createNewWorkspace(const FilePath& path);
208 
214  static FilePath getMostRecentlyUsedWorkspacePath() noexcept;
215 
221  static void setMostRecentlyUsedWorkspacePath(const FilePath& path) noexcept;
222 
229  static FilePath chooseWorkspacePath() noexcept;
230 
238  static Version FILE_FORMAT_VERSION() noexcept {
239  return Version::fromString("0.1");
240  }
241 
242 private: // Data
245 
248 
251 
254 
257 
259  QScopedPointer<WorkspaceSettings> mWorkspaceSettings;
260 
262  QScopedPointer<WorkspaceLibraryDb> mLibraryDb;
263 
265  QScopedPointer<ProjectTreeModel> mProjectTreeModel;
266 
268  QScopedPointer<RecentProjectsModel> mRecentProjectsModel;
269 
271  QScopedPointer<FavoriteProjectsModel> mFavoriteProjectsModel;
272 };
273 
274 /*******************************************************************************
275  * End of File
276  ******************************************************************************/
277 
278 } // namespace workspace
279 } // namespace librepcb
280 
281 #endif // LIBREPCB_WORKSPACE_H
RecentProjectsModel & getRecentProjectsModel() const noexcept
Definition: workspace.cpp:139
QScopedPointer< WorkspaceLibraryDb > mLibraryDb
the library database
Definition: workspace.h:262
FavoriteProjectsModel & getFavoriteProjectsModel() const noexcept
Definition: workspace.cpp:143
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
static FilePath getMostRecentlyUsedWorkspacePath() noexcept
Get the most recently used workspace path.
Definition: workspace.cpp:211
static tl::optional< Version > getHighestFileFormatVersionOfWorkspace(const FilePath &path) noexcept
getHighestFileFormatVersionOfWorkspace
Definition: workspace.cpp:195
FilePath mMetadataPath
the subdirectory of the current file format version
Definition: workspace.h:250
static FilePath chooseWorkspacePath() noexcept
Let the user choose a workspace path (with a directory chooser dialog)
Definition: workspace.cpp:223
static void createNewWorkspace(const FilePath &path)
Create a new workspace.
Definition: workspace.cpp:205
const FilePath & getPath() const
Get the filepath to the workspace directory.
Definition: workspace.h:90
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
ProjectTreeModel & getProjectTreeModel() const noexcept
Definition: workspace.cpp:135
DirectoryLock mLock
to lock the version directory (#mVersionPath)
Definition: workspace.h:256
bool isFavoriteProject(const FilePath &filepath) const noexcept
Check whether a project is in the favorite project list or not.
Definition: workspace.cpp:155
const FilePath & getMetadataPath() const
Get the filepath to the version directory (v#) in the workspace.
Definition: workspace.h:100
QScopedPointer< WorkspaceSettings > mWorkspaceSettings
the WorkspaceSettings object
Definition: workspace.h:259
WorkspaceSettings & getSettings() const
Get the workspace settings.
Definition: workspace.h:128
FilePath mProjectsPath
the directory "projects"
Definition: workspace.h:247
~Workspace() noexcept
Definition: workspace.cpp:128
WorkspaceLibraryDb & getLibraryDb() const
Get the workspace library database.
Definition: workspace.h:135
FilePath mLibrariesPath
the directory "v#/libraries"
Definition: workspace.h:253
QScopedPointer< ProjectTreeModel > mProjectTreeModel
a tree model for the whole projects directory
Definition: workspace.h:265
The FavoriteProjectsModel class.
Definition: favoriteprojectsmodel.h:45
static void setMostRecentlyUsedWorkspacePath(const FilePath &path) noexcept
Set the most recently used workspace path.
Definition: workspace.cpp:217
FilePath mPath
a FilePath object which represents the workspace directory
Definition: workspace.h:244
The RecentProjectsModel class.
Definition: recentprojectsmodel.h:45
static QList< Version > getFileFormatVersionsOfWorkspace(const FilePath &path) noexcept
getFileFormatVersionsOfWorkspace
Definition: workspace.cpp:175
const FilePath & getLibrariesPath() const
Get the filepath to the "v#/libraries" directory in the workspace.
Definition: workspace.h:105
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
const FilePath & getProjectsPath() const
Get the filepath to the "projects" directory in the workspace.
Definition: workspace.h:95
FilePath getLocalLibrariesPath() const
Get the filepath to the "v#/libraries/local" directory.
Definition: workspace.h:110
Workspace & operator=(const Workspace &rhs)=delete
static bool isValidWorkspacePath(const FilePath &path) noexcept
Check whether a filepath points to a valid workspace directory or not.
Definition: workspace.cpp:171
QScopedPointer< RecentProjectsModel > mRecentProjectsModel
a list model of all recent projects
Definition: workspace.h:268
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:238
void setLastRecentlyUsedProject(const FilePath &filepath) noexcept
setLastRecentlyUsedProject
Definition: workspace.cpp:151
void addFavoriteProject(const FilePath &filepath) noexcept
Add a project to the favorite projects list.
Definition: workspace.cpp:159
FilePath getRemoteLibrariesPath() const
Get the filepath to the "v#/libraries/remote" directory.
Definition: workspace.h:117
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:52
void removeFavoriteProject(const FilePath &filepath) noexcept
Remove a project from the favorite projects list.
Definition: workspace.cpp:163
static Version fromString(const QString &str)
Create a Version object from a string.
Definition: version.cpp:87
The ProjectTreeModel class.
Definition: projecttreemodel.h:44
The WorkspaceSettings class manages all workspace related settings.
Definition: workspacesettings.h:66
This class can be used to implement file-based directory locks.
Definition: directorylock.h:159
QScopedPointer< FavoriteProjectsModel > mFavoriteProjectsModel
a list model of all favorite projects
Definition: workspace.h:271