LibrePCB Developers Documentation
Loading...
Searching...
No Matches
Workspace Class Referencefinal

The Workspace class represents a workspace with all its data (library, projects, settings, ...) More...

#include <workspace.h>

Inherits QObject.

+ Collaboration diagram for Workspace:

Public Member Functions

 Workspace ()=delete
 
 Workspace (const Workspace &other)=delete
 
 Workspace (const FilePath &wsPath, const QString &dataDirName, DirectoryLock::LockHandlerCallback lockCallback=nullptr)
 Constructor to open an existing workspace.
 
 ~Workspace () noexcept
 
const FilePathgetPath () const
 Get the filepath to the workspace directory.
 
const FilePathgetProjectsPath () const
 Get the filepath to the "projects" directory in the workspace.
 
const FilePathgetDataPath () const
 Get the filepath to the data directory in the workspace.
 
const FilePathgetLibrariesPath () const
 Get the filepath to the "data/libraries" directory in the workspace.
 
FilePath getLocalLibrariesPath () const
 Get the filepath to the "data/libraries/local" directory.
 
FilePath getRemoteLibrariesPath () const
 Get the filepath to the "data/libraries/remote" directory.
 
WorkspaceSettingsgetSettings ()
 Get the workspace settings.
 
const WorkspaceSettingsgetSettings () const
 Get the workspace settings.
 
WorkspaceLibraryDbgetLibraryDb () const
 Get the workspace library database.
 
void saveSettings ()
 Save all (modified) settings to disk.
 
Workspaceoperator= (const Workspace &rhs)=delete
 

Static Public Member Functions

static bool checkCompatibility (const FilePath &wsRoot, QString *errorMsg=nullptr)
 Check the existence & compatibility of a workspace directory.
 
static QMap< QString, VersionfindDataDirectories (const FilePath &wsRoot)
 Find all data directories of a workspace.
 
static QString determineDataDirectory (const QMap< QString, Version > &dataDirs, QString &copyFromDir, QString &copyToDir) noexcept
 Decide which data directory to open, and how to do it.
 
static void createNewWorkspace (const FilePath &path)
 Create a new workspace.
 
static FilePath getMostRecentlyUsedWorkspacePath () noexcept
 Get the most recently used workspace path.
 
static void setMostRecentlyUsedWorkspacePath (const FilePath &path) noexcept
 Set the most recently used workspace path.
 
static Version FILE_FORMAT_VERSION () noexcept
 Current workspace file format version (constant)
 

Private Member Functions

void saveSettingsToTransactionalFileSystem ()
 Save the workspace settings to the transactional file system.
 

Private Attributes

FilePath mPath
 a FilePath object which represents the workspace directory
 
FilePath mProjectsPath
 the directory "projects"
 
FilePath mDataPath
 the subdirectory of the current file format version
 
FilePath mLibrariesPath
 the directory "data/libraries"
 
std::shared_ptr< TransactionalFileSystemmFileSystem
 to lock the version directory (mDataPath)
 
QScopedPointer< WorkspaceSettingsmWorkspaceSettings
 the WorkspaceSettings object
 
QScopedPointer< WorkspaceLibraryDbmLibraryDb
 the library database
 

Detailed Description

The Workspace class represents a workspace with all its data (library, projects, settings, ...)

To access the settings of the workspace, use the method getSettings().

Constructor & Destructor Documentation

◆ Workspace() [1/3]

Workspace ( )
delete

◆ Workspace() [2/3]

Workspace ( const Workspace other)
delete

◆ Workspace() [3/3]

Workspace ( const FilePath wsPath,
const QString &  dataDirName,
DirectoryLock::LockHandlerCallback  lockCallback = nullptr 
)
explicit

Constructor to open an existing workspace.

Parameters
wsPathThe filepath to the workspace directory.
dataDirNameSubdirectory name where data files are stored (e.g. "data" or "v0.1").
lockCallbackA callback which gets called if the workspace directory is locked, to decide what to do in this case.
Exceptions
ExceptionIf the workspace could not be opened, this constructor throws an exception.
+ Here is the call graph for this function:

◆ ~Workspace()

~Workspace ( )
noexcept

The destructor

Member Function Documentation

◆ getPath()

const FilePath & getPath ( ) const
inline

Get the filepath to the workspace directory.

+ Here is the caller graph for this function:

◆ getProjectsPath()

const FilePath & getProjectsPath ( ) const
inline

Get the filepath to the "projects" directory in the workspace.

◆ getDataPath()

const FilePath & getDataPath ( ) const
inline

Get the filepath to the data directory in the workspace.

◆ getLibrariesPath()

const FilePath & getLibrariesPath ( ) const
inline

Get the filepath to the "data/libraries" directory in the workspace.

+ Here is the caller graph for this function:

◆ getLocalLibrariesPath()

FilePath getLocalLibrariesPath ( ) const
inline

Get the filepath to the "data/libraries/local" directory.

+ Here is the call graph for this function:

◆ getRemoteLibrariesPath()

FilePath getRemoteLibrariesPath ( ) const
inline

Get the filepath to the "data/libraries/remote" directory.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSettings() [1/2]

WorkspaceSettings & getSettings ( )
inline

Get the workspace settings.

+ Here is the caller graph for this function:

◆ getSettings() [2/2]

const WorkspaceSettings & getSettings ( ) const
inline

Get the workspace settings.

◆ getLibraryDb()

WorkspaceLibraryDb & getLibraryDb ( ) const
inline

Get the workspace library database.

+ Here is the caller graph for this function:

◆ saveSettings()

void saveSettings ( )

Save all (modified) settings to disk.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

Workspace & operator= ( const Workspace rhs)
delete

◆ checkCompatibility()

bool checkCompatibility ( const FilePath wsRoot,
QString *  errorMsg = nullptr 
)
static

Check the existence & compatibility of a workspace directory.

Parameters
wsRootWorkspace directory root path to check.
errorMsgIf not nullptr, and the function returns false, an explanation error message will be written here.
Returns
True if the path is a compatible workspace directory, false otherwise.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findDataDirectories()

QMap< QString, Version > findDataDirectories ( const FilePath wsRoot)
static

Find all data directories of a workspace.

Parameters
wsRootWorkspace directory root path. Should be a valid path, checked with checkCompatibility().
Returns
All data directory names and their contained (resp. intended) file format version.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ determineDataDirectory()

QString determineDataDirectory ( const QMap< QString, Version > &  dataDirs,
QString &  copyFromDir,
QString &  copyToDir 
)
staticnoexcept

Decide which data directory to open, and how to do it.

Parameters
dataDirsAll available data directories, as returned by findDataDirectories().
copyFromDirIf the file format of the data directory needs to be upgraded, the source directory of the copy operation will be written out here.
copyToDirIf the file format of the data directory needs to be upgraded, the destination directory of the copy operation will be written out here.
Returns
Name of the data directory to open or create.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createNewWorkspace()

void createNewWorkspace ( const FilePath path)
static

Create a new workspace.

Parameters
pathA path to a directory where to create the new workspace
Exceptions
Exceptionon error.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMostRecentlyUsedWorkspacePath()

FilePath getMostRecentlyUsedWorkspacePath ( )
staticnoexcept

Get the most recently used workspace path.

Returns
The filepath to the last recently used workspace (may be invalid)
+ Here is the caller graph for this function:

◆ setMostRecentlyUsedWorkspacePath()

void setMostRecentlyUsedWorkspacePath ( const FilePath path)
staticnoexcept

Set the most recently used workspace path.

Parameters
pathThe filepath to the workspace directory
+ Here is the caller graph for this function:

◆ FILE_FORMAT_VERSION()

static Version FILE_FORMAT_VERSION ( )
inlinestaticnoexcept

Current workspace file format version (constant)

Warning
Don't change this value unless you know exactly what you're doing!
Returns
File format version
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveSettingsToTransactionalFileSystem()

void saveSettingsToTransactionalFileSystem ( )
private

Save the workspace settings to the transactional file system.

+ Here is the caller graph for this function:

Member Data Documentation

◆ mPath

FilePath mPath
private

a FilePath object which represents the workspace directory

◆ mProjectsPath

FilePath mProjectsPath
private

the directory "projects"

◆ mDataPath

FilePath mDataPath
private

the subdirectory of the current file format version

◆ mLibrariesPath

FilePath mLibrariesPath
private

the directory "data/libraries"

◆ mFileSystem

std::shared_ptr<TransactionalFileSystem> mFileSystem
private

to lock the version directory (mDataPath)

◆ mWorkspaceSettings

QScopedPointer<WorkspaceSettings> mWorkspaceSettings
private

the WorkspaceSettings object

◆ mLibraryDb

QScopedPointer<WorkspaceLibraryDb> mLibraryDb
private

the library database


The documentation for this class was generated from the following files: