20 #ifndef LIBREPCB_CORE_WORKSPACELIBRARYDB_H 21 #define LIBREPCB_CORE_WORKSPACELIBRARYDB_H 26 #include "../fileio/filepath.h" 27 #include "../types/uuid.h" 28 #include "../types/version.h" 40 class ComponentCategory;
43 class PackageCategory;
46 class WorkspaceLibraryScanner;
110 template <
typename ElementType>
112 const tl::optional<Uuid>& uuid = tl::nullopt,
114 return getAll(getTable<ElementType>(), uuid, lib);
126 template <
typename ElementType>
140 template <
typename ElementType>
141 QList<Uuid>
find(
const QString& keyword)
const {
142 return find(getTable<ElementType>(), keyword);
165 template <
typename ElementType>
167 QString* name =
nullptr, QString* description =
nullptr,
168 QString* keywords =
nullptr)
const {
169 return getTranslations(getTable<ElementType>(), elemDir, localeOrder, name,
170 description, keywords);
189 template <
typename ElementType>
192 bool* deprecated =
nullptr)
const {
193 return getMetadata(getTable<ElementType>(), elemDir, uuid, version,
221 template <
typename ElementType>
223 tl::optional<Uuid>* parent =
nullptr)
const {
224 static_assert(std::is_same<ElementType, ComponentCategory>::value ||
225 std::is_same<ElementType, PackageCategory>::value,
226 "Unsupported ElementType");
243 Uuid* pkgUuid =
nullptr)
const;
258 template <
typename ElementType>
259 QSet<Uuid>
getChilds(
const tl::optional<Uuid>& parent)
const {
260 static_assert(std::is_same<ElementType, ComponentCategory>::value ||
261 std::is_same<ElementType, PackageCategory>::value,
262 "Unsupported ElementType");
263 return getChilds(getTable<ElementType>(), parent);
283 template <
typename ElementType>
285 int limit = -1)
const {
286 static_assert(std::is_same<ElementType, Symbol>::value ||
287 std::is_same<ElementType, Package>::value ||
288 std::is_same<ElementType, Component>::value ||
289 std::is_same<ElementType, Device>::value,
290 "Unsupported ElementType");
292 getCategoryTable<ElementType>(), category, limit);
324 QMultiMap<Version, FilePath>
getAll(
const QString& elementsTable,
325 const tl::optional<Uuid>& uuid,
328 const QMultiMap<Version, FilePath>& list)
const noexcept;
329 QList<Uuid>
find(
const QString& elementsTable,
const QString& keyword)
const;
331 const QStringList& localeOrder, QString* name,
332 QString* description, QString* keywords)
const;
334 Uuid* uuid,
Version* version,
bool* deprecated)
const;
337 tl::optional<Uuid>* parent)
const;
338 QSet<Uuid>
getChilds(
const QString& categoriesTable,
339 const tl::optional<Uuid>& categoryUuid)
const;
341 const QString& categoryTable,
342 const tl::optional<Uuid>& category,
int limit)
const;
343 static QSet<Uuid>
getUuidSet(QSqlQuery& query);
345 template <
typename ElementType>
347 template <
typename ElementType>
353 QScopedPointer<SQLiteDatabase>
mDb;
static QSet< Uuid > getUuidSet(QSqlQuery &query)
Definition: workspacelibrarydb.cpp:414
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
QList< Uuid > find(const QString &keyword) const
Find elements by keyword.
Definition: workspacelibrarydb.h:141
QSet< Uuid > getComponentDevices(const Uuid &component) const
Get all devices of a specific component.
Definition: workspacelibrarydb.cpp:153
static const int sCurrentDbVersion
Definition: workspacelibrarydb.h:357
void scanLibraryListUpdated(int libraryCount)
static QString getCategoryTable() noexcept
Definition: workspacelibrarydb.cpp:456
Definition: airwiresbuilder.cpp:34
void scanFailed(QString errorMsg)
int getDbVersion() const noexcept
Definition: workspacelibrarydb.cpp:422
const FilePath mFilePath
Path to the SQLite database file.
Definition: workspacelibrarydb.h:352
QSet< Uuid > getByCategory(const tl::optional< Uuid > &category, int limit=-1) const
Get elements of a specific category.
Definition: workspacelibrarydb.h:284
const FilePath & getFilePath() const noexcept
Get the file path of the SQLite database.
Definition: workspacelibrarydb.h:81
void scanSucceeded(int elementCount)
QMultiMap< Version, FilePath > getAll(const tl::optional< Uuid > &uuid=tl::nullopt, const FilePath &lib=FilePath()) const
Get elements, optionally matching some criteria.
Definition: workspacelibrarydb.h:111
bool isScanInProgress() const noexcept
Check if there is currently a library scan in progress.
Definition: workspacelibrarydb.h:88
QScopedPointer< WorkspaceLibraryScanner > mLibraryScanner
Definition: workspacelibrarydb.h:354
~WorkspaceLibraryDb() noexcept
Definition: workspacelibrarydb.cpp:95
static QString getTable() noexcept
Definition: workspacelibrarydb.cpp:442
bool getCategoryMetadata(const FilePath catDir, tl::optional< Uuid > *parent=nullptr) const
Get additional metadata of a specific category.
Definition: workspacelibrarydb.h:222
QScopedPointer< SQLiteDatabase > mDb
The SQLite database.
Definition: workspacelibrarydb.h:353
void scanProgressUpdate(int percent)
bool getLibraryMetadata(const FilePath libDir, QPixmap *icon=nullptr) const
Get additional metadata of a specific library.
Definition: workspacelibrarydb.cpp:106
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
const FilePath mLibrariesPath
Path to workspace libraries directory.
Definition: workspacelibrarydb.h:351
bool getMetadata(const FilePath elemDir, Uuid *uuid=nullptr, Version *version=nullptr, bool *deprecated=nullptr) const
Get metadata of a specific element.
Definition: workspacelibrarydb.h:190
WorkspaceLibraryDb()=delete
int getScanProgressPercent() const noexcept
Get the current progress of the library rescan.
Definition: workspacelibrarydb.cpp:102
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:56
bool getDeviceMetadata(const FilePath &devDir, Uuid *cmpUuid=nullptr, Uuid *pkgUuid=nullptr) const
Get additional metadata of a specific device.
Definition: workspacelibrarydb.cpp:126
FilePath getLatest(const Uuid &uuid) const
Get an element of a specific UUID and the highest version.
Definition: workspacelibrarydb.h:127
bool getTranslations(const FilePath &elemDir, const QStringList &localeOrder, QString *name=nullptr, QString *description=nullptr, QString *keywords=nullptr) const
Get translations of a specific element.
Definition: workspacelibrarydb.h:166
FilePath getLatestVersionFilePath(const QMultiMap< Version, FilePath > &list) const noexcept
Definition: workspacelibrarydb.cpp:225
WorkspaceLibraryDb & operator=(const WorkspaceLibraryDb &rhs)=delete
void startLibraryRescan() noexcept
Rescan the whole library directory and update the SQLite database.
Definition: workspacelibrarydb.cpp:168
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:55
QSet< Uuid > getChilds(const tl::optional< Uuid > &parent) const
Get children categories of a specific category.
Definition: workspacelibrarydb.h:259