LibrePCB Developers Documentation
WorkspaceLibraryDb Class Referencefinal

The WorkspaceLibraryDb class. More...

#include <workspacelibrarydb.h>

Inherits QObject.

+ Collaboration diagram for WorkspaceLibraryDb:

Signals

void scanStarted ()
 
void scanLibraryListUpdated (int libraryCount)
 
void scanProgressUpdate (int percent)
 
void scanSucceeded (int elementCount)
 
void scanFailed (QString errorMsg)
 
void scanFinished ()
 

Public Member Functions

 WorkspaceLibraryDb ()=delete
 
 WorkspaceLibraryDb (const WorkspaceLibraryDb &other)=delete
 
 WorkspaceLibraryDb (const FilePath &librariesPath)
 Constructor to open the library database of an existing workspace. More...
 
 ~WorkspaceLibraryDb () noexcept
 
const FilePathgetFilePath () const noexcept
 Get the file path of the SQLite database. More...
 
template<typename ElementType >
QMultiMap< Version, FilePathgetAll (const tl::optional< Uuid > &uuid=tl::nullopt, const FilePath &lib=FilePath()) const
 Get elements, optionally matching some criteria. More...
 
template<typename ElementType >
FilePath getLatest (const Uuid &uuid) const
 Get an element of a specific UUID and the highest version. More...
 
template<typename ElementType >
QList< Uuidfind (const QString &keyword) const
 Find elements by keyword. More...
 
template<typename ElementType >
bool getTranslations (const FilePath &elemDir, const QStringList &localeOrder, QString *name=nullptr, QString *description=nullptr, QString *keywords=nullptr) const
 Get translations of a specific element. More...
 
template<typename ElementType >
bool getMetadata (const FilePath elemDir, Uuid *uuid=nullptr, Version *version=nullptr, bool *deprecated=nullptr) const
 Get metadata of a specific element. More...
 
bool getLibraryMetadata (const FilePath libDir, QPixmap *icon=nullptr) const
 Get additional metadata of a specific library. More...
 
template<typename ElementType >
bool getCategoryMetadata (const FilePath catDir, tl::optional< Uuid > *parent=nullptr) const
 Get additional metadata of a specific category. More...
 
bool getDeviceMetadata (const FilePath &devDir, Uuid *cmpUuid=nullptr, Uuid *pkgUuid=nullptr) const
 Get additional metadata of a specific device. More...
 
template<typename ElementType >
QSet< UuidgetChilds (const tl::optional< Uuid > &parent) const
 Get children categories of a specific category. More...
 
template<typename ElementType >
QSet< UuidgetByCategory (const tl::optional< Uuid > &category, int limit=-1) const
 Get elements of a specific category. More...
 
QSet< UuidgetComponentDevices (const Uuid &component) const
 Get all devices of a specific component. More...
 
void startLibraryRescan () noexcept
 Rescan the whole library directory and update the SQLite database. More...
 
WorkspaceLibraryDboperator= (const WorkspaceLibraryDb &rhs)=delete
 

Private Member Functions

QMultiMap< Version, FilePathgetAll (const QString &elementsTable, const tl::optional< Uuid > &uuid, const FilePath &lib) const
 
FilePath getLatestVersionFilePath (const QMultiMap< Version, FilePath > &list) const noexcept
 
QList< Uuidfind (const QString &elementsTable, const QString &keyword) const
 
bool getTranslations (const QString &elementsTable, const FilePath &elemDir, const QStringList &localeOrder, QString *name, QString *description, QString *keywords) const
 
bool getMetadata (const QString &elementsTable, const FilePath elemDir, Uuid *uuid, Version *version, bool *deprecated) const
 
bool getCategoryMetadata (const QString &categoriesTable, const FilePath catDir, tl::optional< Uuid > *parent) const
 
QSet< UuidgetChilds (const QString &categoriesTable, const tl::optional< Uuid > &categoryUuid) const
 
QSet< UuidgetByCategory (const QString &elementsTable, const QString &categoryTable, const tl::optional< Uuid > &category, int limit) const
 
int getDbVersion () const noexcept
 

Static Private Member Functions

static QSet< UuidgetUuidSet (QSqlQuery &query)
 
template<typename ElementType >
static QString getTable () noexcept
 
template<typename ElementType >
static QString getCategoryTable () noexcept
 

Private Attributes

const FilePath mLibrariesPath
 Path to workspace libraries directory. More...
 
const FilePath mFilePath
 Path to the SQLite database file. More...
 
QScopedPointer< SQLiteDatabasemDb
 The SQLite database. More...
 
QScopedPointer< WorkspaceLibraryScannermLibraryScanner
 

Static Private Attributes

static const int sCurrentDbVersion = 3
 

Detailed Description

The WorkspaceLibraryDb class.

Constructor & Destructor Documentation

◆ WorkspaceLibraryDb() [1/3]

WorkspaceLibraryDb ( )
delete

◆ WorkspaceLibraryDb() [2/3]

WorkspaceLibraryDb ( const WorkspaceLibraryDb other)
delete

◆ WorkspaceLibraryDb() [3/3]

WorkspaceLibraryDb ( const FilePath librariesPath)
explicit

Constructor to open the library database of an existing workspace.

Parameters
librariesPathPath to the workspace libraries directory.
Exceptions
ExceptionIf the library could not be opened, this constructor throws an exception.
+ Here is the call graph for this function:

◆ ~WorkspaceLibraryDb()

~WorkspaceLibraryDb ( )
noexcept

Member Function Documentation

◆ getFilePath()

const FilePath& getFilePath ( ) const
inlinenoexcept

Get the file path of the SQLite database.

Returns
Path to the *.sqlite file

◆ getAll() [1/2]

QMultiMap<Version, FilePath> getAll ( const tl::optional< Uuid > &  uuid = tl::nullopt,
const FilePath lib = FilePath() 
) const
inline

Get elements, optionally matching some criteria.

Template Parameters
ElementTypeType of the library element.
Parameters
uuidIf not nullopt, only elements with this UUID are returned.
libIf valid, only elements from this library are returned. Attention: Must not be used when ElementType is Library!
Returns
Version and filepath of all elements matching the criteria.
+ Here is the caller graph for this function:

◆ getLatest()

FilePath getLatest ( const Uuid uuid) const
inline

Get an element of a specific UUID and the highest version.

Parameters
uuidThe UUID of the element to get.
Returns
Filepath of the element with the highest version number and the specified UUID. If no element is found, an invalid filepath will be returned.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find() [1/2]

QList<Uuid> find ( const QString &  keyword) const
inline

Find elements by keyword.

Parameters
keywordKeyword to search for. Note that the translations for all languages will be taken into account.
Returns
UUIDs of elements matching the filter, sorted alphabetically and without duplicates. Empty if no elements were found.
+ Here is the caller graph for this function:

◆ getTranslations() [1/2]

bool getTranslations ( const FilePath elemDir,
const QStringList &  localeOrder,
QString *  name = nullptr,
QString *  description = nullptr,
QString *  keywords = nullptr 
) const
inline

Get translations of a specific element.

Template Parameters
ElementTypeType of the library element.
Parameters
elemDirLibrary element directory. If it does not exist, all translations will be set to an empty string.
localeOrderLocale order (highest priority first).
nameIf not nullptr, name will be written here. Set to an empty string if the requested data does not exist.
descriptionIf not nullptr, desc. will be written here. Set to an empty string if the requested data does not exist.
keywordsIf not nullptr, keywords will be written here. Set to an empty string if the requested data does not exist.
Return values
trueIf the element and corresponding translations were found in the database.
falseIf the element was not found or contains no translations ar all.
+ Here is the caller graph for this function:

◆ getMetadata() [1/2]

bool getMetadata ( const FilePath  elemDir,
Uuid uuid = nullptr,
Version version = nullptr,
bool *  deprecated = nullptr 
) const
inline

Get metadata of a specific element.

Template Parameters
ElementTypeType of the library element.
Parameters
elemDirLibrary element directory.
uuidIf not nullptr and the element was found, its UUID will be written here.
versionIf not nullptr and the element was found, its version will be written here.
deprecatedIf not nullptr and the element was found, its deprecation flag will be written here.
Return values
trueIf the element was found in the database.
falseIf the element was not found.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLibraryMetadata()

bool getLibraryMetadata ( const FilePath  libDir,
QPixmap *  icon = nullptr 
) const

Get additional metadata of a specific library.

Parameters
libDirLibrary directory.
iconIf not nullptr and the library was found, its icon will be written here.
Return values
trueIf the library was found in the database.
falseIf the library was not found.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCategoryMetadata() [1/2]

bool getCategoryMetadata ( const FilePath  catDir,
tl::optional< Uuid > *  parent = nullptr 
) const
inline

Get additional metadata of a specific category.

Template Parameters
ElementTypeType of the library element.
Parameters
catDirCategory directory.
parentIf not nullptr and the category was found, its parent will be written here.
Return values
trueIf the category was found in the database.
falseIf the category was not found.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDeviceMetadata()

bool getDeviceMetadata ( const FilePath devDir,
Uuid cmpUuid = nullptr,
Uuid pkgUuid = nullptr 
) const

Get additional metadata of a specific device.

Parameters
devDirDevice directory.
pkgUuidIf not nullptr and the device was found, its package UUID will be written here.
cmpUuidIf not nullptr and the device was found, its component UUID will be written here.
Return values
trueIf the device was found in the database.
falseIf the device was not found.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChilds() [1/2]

QSet<Uuid> getChilds ( const tl::optional< Uuid > &  parent) const
inline

Get children categories of a specific category.

Template Parameters
ElementTypeType of the category.
Parameters
parentCategory to get the children of. If nullopt, all root categories, and categories with inexistent parent will be returned (this ensures that all elements are discoverable by getByCategory()).
Returns
UUIDs of children categories. Empty if the passed category doesn't exist.
+ Here is the caller graph for this function:

◆ getByCategory() [1/2]

QSet<Uuid> getByCategory ( const tl::optional< Uuid > &  category,
int  limit = -1 
) const
inline

Get elements of a specific category.

Template Parameters
ElementTypeType of the library element.
Parameters
categoryCategory to get the elements of. If nullopt, all elements with no category at all, or with only inexistent categories are returned.
limitIf not -1, the number of results is limited to this value. This can be used for performance reasons, for example if you only want to know if there are any elements in the given category, the limit can be set to 1, which is much faster than retrieving all results.
Returns
UUIDs of elements. Empty if the passed category doesn't exist.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getComponentDevices()

QSet< Uuid > getComponentDevices ( const Uuid component) const

Get all devices of a specific component.

Parameters
componentComponent UUID to get the devices of.
Returns
UUIDs of devices. Empty if the passed component doesn't exist.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startLibraryRescan()

void startLibraryRescan ( )
noexcept

Rescan the whole library directory and update the SQLite database.

+ Here is the caller graph for this function:

◆ operator=()

WorkspaceLibraryDb& operator= ( const WorkspaceLibraryDb rhs)
delete
+ Here is the caller graph for this function:

◆ scanStarted

void scanStarted ( )
signal
+ Here is the caller graph for this function:

◆ scanLibraryListUpdated

void scanLibraryListUpdated ( int  libraryCount)
signal
+ Here is the caller graph for this function:

◆ scanProgressUpdate

void scanProgressUpdate ( int  percent)
signal
+ Here is the caller graph for this function:

◆ scanSucceeded

void scanSucceeded ( int  elementCount)
signal
+ Here is the caller graph for this function:

◆ scanFailed

void scanFailed ( QString  errorMsg)
signal
+ Here is the caller graph for this function:

◆ scanFinished

void scanFinished ( )
signal
+ Here is the caller graph for this function:

◆ getAll() [2/2]

QMultiMap< Version, FilePath > getAll ( const QString &  elementsTable,
const tl::optional< Uuid > &  uuid,
const FilePath lib 
) const
private
+ Here is the call graph for this function:

◆ getLatestVersionFilePath()

FilePath getLatestVersionFilePath ( const QMultiMap< Version, FilePath > &  list) const
privatenoexcept
+ Here is the caller graph for this function:

◆ find() [2/2]

QList< Uuid > find ( const QString &  elementsTable,
const QString &  keyword 
) const
private
+ Here is the call graph for this function:

◆ getTranslations() [2/2]

bool getTranslations ( const QString &  elementsTable,
const FilePath elemDir,
const QStringList &  localeOrder,
QString *  name,
QString *  description,
QString *  keywords 
) const
private
+ Here is the call graph for this function:

◆ getMetadata() [2/2]

bool getMetadata ( const QString &  elementsTable,
const FilePath  elemDir,
Uuid uuid,
Version version,
bool *  deprecated 
) const
private
+ Here is the call graph for this function:

◆ getCategoryMetadata() [2/2]

bool getCategoryMetadata ( const QString &  categoriesTable,
const FilePath  catDir,
tl::optional< Uuid > *  parent 
) const
private
+ Here is the call graph for this function:

◆ getChilds() [2/2]

QSet< Uuid > getChilds ( const QString &  categoriesTable,
const tl::optional< Uuid > &  categoryUuid 
) const
private
+ Here is the call graph for this function:

◆ getByCategory() [2/2]

QSet< Uuid > getByCategory ( const QString &  elementsTable,
const QString &  categoryTable,
const tl::optional< Uuid > &  category,
int  limit 
) const
private
+ Here is the call graph for this function:

◆ getUuidSet()

QSet< Uuid > getUuidSet ( QSqlQuery &  query)
staticprivate
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDbVersion()

int getDbVersion ( ) const
privatenoexcept
+ Here is the caller graph for this function:

◆ getTable()

template QString getTable< Device > ( )
staticprivatenoexcept
+ Here is the caller graph for this function:

◆ getCategoryTable()

template QString getCategoryTable< Device > ( )
staticprivatenoexcept
+ Here is the caller graph for this function:

Member Data Documentation

◆ mLibrariesPath

const FilePath mLibrariesPath
private

Path to workspace libraries directory.

◆ mFilePath

const FilePath mFilePath
private

Path to the SQLite database file.

◆ mDb

QScopedPointer<SQLiteDatabase> mDb
private

The SQLite database.

◆ mLibraryScanner

QScopedPointer<WorkspaceLibraryScanner> mLibraryScanner
private

◆ sCurrentDbVersion

const int sCurrentDbVersion = 3
staticprivate

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