LibrePCB Developers Documentation
WorkspaceLibraryDb Class Referencefinal

The WorkspaceLibraryDb class. More...

#include <workspacelibrarydb.h>

Inherits QObject.

+ Collaboration diagram for WorkspaceLibraryDb:

Classes

struct  Part
 

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...
 
bool isScanInProgress () const noexcept
 Check if there is currently a library scan in progress. More...
 
int getScanProgressPercent () const noexcept
 Get the current progress of the library rescan. 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...
 
QList< UuidfindDevicesOfParts (const QString &keyword) const
 Find parts by keyword. More...
 
QList< PartfindPartsOfDevice (const Uuid &device, const QString &keyword) const
 Find parts of device 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, QString *manufacturer=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...
 
template<typename ElementType >
ResourceList getResources (const FilePath elemDir) const
 Get resources of a specific library element. More...
 
QSet< UuidgetComponentDevices (const Uuid &component) const
 Get all devices of a specific component. More...
 
QList< PartgetDeviceParts (const Uuid &device) const
 Get all parts of a specific device. More...
 
void startLibraryRescan () noexcept
 Rescan the whole library directory and update the SQLite database. More...
 
WorkspaceLibraryDboperator= (const WorkspaceLibraryDb &rhs)=delete
 
template<>
QList< Uuidfind (const QString &keyword) const
 

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
 
AttributeList getPartAttributes (int partId) 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
 
ResourceList getResources (const QString &elementsTable, const FilePath &elemDir) 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 = 6
 

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

◆ isScanInProgress()

bool isScanInProgress ( ) const
inlinenoexcept

Check if there is currently a library scan in progress.

Returns
Whether a scan is in progress or not.
+ Here is the call graph for this function:

◆ getScanProgressPercent()

int getScanProgressPercent ( ) const
noexcept

Get the current progress of the library rescan.

Returns
Progress in percent (100 = finished).
+ Here is the caller graph for this function:

◆ 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 call graph for this function:
+ 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/3]

template QList< Uuid > find< Device > ( const QString &  keyword) const

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 call graph for this function:
+ Here is the caller graph for this function:

◆ findDevicesOfParts()

QList< Uuid > findDevicesOfParts ( const QString &  keyword) const

Find parts by keyword.

Parameters
keywordKeyword to search for.
Returns
All devices which contain parts matching the filter, sorted alphabetically and without duplicates. Empty if no elements were found.
+ Here is the call graph for this function:

◆ findPartsOfDevice()

QList< WorkspaceLibraryDb::Part > findPartsOfDevice ( const Uuid device,
const QString &  keyword 
) const

Find parts of device by keyword.

Parameters
deviceDevice to search for parts.
keywordKeyword to search for.
Returns
All parts of the passed device matching the filter, sorted alphabetically and without duplicates. Empty if no elements were found or the device doesn't exist.
+ Here is the call 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 call graph for this function:
+ 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,
QString *  manufacturer = 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.
manufacturerIf not nullptr and the library was found, its manufacturer name will be written here (may be empty).
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:

◆ 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 call graph for this function:
+ 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:

◆ getResources() [1/2]

ResourceList getResources ( const FilePath  elemDir) const
inline

Get resources of a specific library element.

Template Parameters
ElementTypeType of the library element.
Parameters
elemDirLibrary element directory.
Returns
Element resources (empty if element 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:

◆ getDeviceParts()

QList< WorkspaceLibraryDb::Part > getDeviceParts ( const Uuid device) const

Get all parts of a specific device.

Parameters
deviceDevice UUID to get the parts of.
Returns
All parts. Empty if the passed device doesn't exist.
+ Here is the call 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

◆ 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/3]

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:

◆ getPartAttributes()

AttributeList getPartAttributes ( int  partId) const
private
+ Here is the call graph for this function:
+ Here is the caller 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:

◆ getResources() [2/2]

ResourceList getResources ( const QString &  elementsTable,
const FilePath elemDir 
) 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

◆ getCategoryTable()

template QString getCategoryTable< Device > ( )
staticprivatenoexcept

◆ find() [3/3]

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

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 = 6
staticprivate

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