20#ifndef LIBREPCB_CORE_WORKSPACELIBRARYDB_H
21#define LIBREPCB_CORE_WORKSPACELIBRARYDB_H
26#include "../attribute/attribute.h"
27#include "../attribute/attributetype.h"
28#include "../fileio/filepath.h"
29#include "../library/resource.h"
30#include "../types/uuid.h"
31#include "../types/version.h"
43class ComponentCategory;
49class WorkspaceLibraryScanner;
72 if (
mpn.isEmpty() != rhs.mpn.isEmpty()) {
73 return mpn.count() < rhs.mpn.count();
82 collator.setNumericMode(
true);
83 collator.setCaseSensitivity(Qt::CaseInsensitive);
84 collator.setIgnorePunctuation(
false);
85 for (
int i = 0; i < std::max(
attributes.
count(), rhs.attributes.count());
88 auto b = rhs.attributes.value(i);
91 }
else if ((!a) && b) {
93 }
else if (a->getKey() != b->getKey()) {
94 return a->getKey() < b->getKey();
95 }
else if (&a->getType() != &b->getType()) {
96 return a->getType().getName() < b->getType().getName();
97 }
else if (a->getValueTr(
true) != b->getValueTr(
true)) {
98 return collator(a->getValueTr(
true), b->getValueTr(
true));
156 template <typename ElementType>
158 const
std::optional<
Uuid>& uuid =
std::nullopt,
160 return getAll(getTable<ElementType>(), uuid, lib);
172 template <
typename ElementType>
186 template <
typename ElementType>
187 QList<Uuid>
find(
const QString& keyword)
const;
211 const QString& keyword)
const;
233 template <
typename ElementType>
235 QString* name =
nullptr, QString* description =
nullptr,
236 QString* keywords =
nullptr)
const {
237 return getTranslations(getTable<ElementType>(), elemDir, localeOrder, name,
238 description, keywords);
257 template <
typename ElementType>
260 bool* deprecated =
nullptr)
const {
261 return getMetadata(getTable<ElementType>(), elemDir, uuid, version,
279 QString* manufacturer =
nullptr)
const;
293 template <
typename ElementType>
295 std::optional<Uuid>* parent =
nullptr)
const {
296 static_assert(std::is_same<ElementType, ComponentCategory>::value ||
297 std::is_same<ElementType, PackageCategory>::value,
298 "Unsupported ElementType");
315 Uuid* pkgUuid =
nullptr)
const;
330 template <
typename ElementType>
331 QSet<Uuid>
getChilds(
const std::optional<Uuid>& parent)
const {
332 static_assert(std::is_same<ElementType, ComponentCategory>::value ||
333 std::is_same<ElementType, PackageCategory>::value,
334 "Unsupported ElementType");
335 return getChilds(getTable<ElementType>(), parent);
355 template <
typename ElementType>
357 int limit = -1)
const {
358 static_assert(std::is_same<ElementType, Symbol>::value ||
359 std::is_same<ElementType, Package>::value ||
360 std::is_same<ElementType, Component>::value ||
361 std::is_same<ElementType, Device>::value,
362 "Unsupported ElementType");
364 getCategoryTable<ElementType>(), category, limit);
377 template <
typename ElementType>
379 static_assert(std::is_same<ElementType, Symbol>::value ||
380 std::is_same<ElementType, Package>::value ||
381 std::is_same<ElementType, Component>::value ||
382 std::is_same<ElementType, Device>::value,
383 "Unsupported ElementType");
384 return getGenerated(getTable<ElementType>(), generatedBy);
396 template <
typename ElementType>
398 static_assert(std::is_same<ElementType, Component>::value ||
399 std::is_same<ElementType, Device>::value,
400 "Unsupported ElementType");
443 const
std::optional<
Uuid>& uuid,
447 QList<
Uuid>
find(const QString& elementsTable, const QString& keyword) const;
449 const QStringList& localeOrder, QString* name,
450 QString* description, QString* keywords) const;
452 Uuid* uuid,
Version* version,
bool* deprecated) const;
455 std::optional<
Uuid>* parent) const;
458 const
std::optional<
Uuid>& categoryUuid) const;
460 const QString& categoryTable,
461 const
std::optional<
Uuid>& category,
464 const QString& generatedBy) const;
469 template <typename ElementType>
471 template <typename ElementType>
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The SQLiteDatabase class.
Definition sqlitedatabase.h:43
int count() const noexcept
Definition serializableobjectlist.h:199
std::shared_ptr< T > value(int index) noexcept
Definition serializableobjectlist.h:254
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
The Version class represents a version number in the format "1.42.7".
Definition version.h:58
The WorkspaceLibraryDb class.
Definition workspacelibrarydb.h:58
ResourceList getResources(const FilePath elemDir) const
Get resources of a specific library element.
Definition workspacelibrarydb.h:397
WorkspaceLibraryDb(const WorkspaceLibraryDb &other)=delete
QSet< Uuid > getGenerated(const QString &generatedBy) const
Get elements generated by a given "generated_by" identifier.
Definition workspacelibrarydb.h:378
bool getLibraryMetadata(const FilePath libDir, QPixmap *icon=nullptr, QString *manufacturer=nullptr) const
Get additional metadata of a specific library.
Definition workspacelibrarydb.cpp:198
void scanProgressUpdate(int percent)
static const int sCurrentDbVersion
Definition workspacelibrarydb.h:481
~WorkspaceLibraryDb() noexcept
Definition workspacelibrarydb.cpp:103
QMultiMap< Version, FilePath > getAll(const std::optional< Uuid > &uuid=std::nullopt, const FilePath &lib=FilePath()) const
Get elements, optionally matching some criteria.
Definition workspacelibrarydb.h:157
FilePath getLatestVersionFilePath(const QMultiMap< Version, FilePath > &list) const noexcept
Definition workspacelibrarydb.cpp:340
bool getDeviceMetadata(const FilePath &devDir, Uuid *cmpUuid=nullptr, Uuid *pkgUuid=nullptr) const
Get additional metadata of a specific device.
Definition workspacelibrarydb.cpp:222
void scanFailed(QString errorMsg)
QList< Uuid > find(const QString &keyword) const
Find elements by keyword.
Definition workspacelibrarydb.cpp:115
QScopedPointer< SQLiteDatabase > mDb
The SQLite database.
Definition workspacelibrarydb.h:477
void scanSucceeded(int elementCount)
const FilePath & getFilePath() const noexcept
Get the file path of the SQLite database.
Definition workspacelibrarydb.h:127
AttributeList getPartAttributes(int partId) const
Definition workspacelibrarydb.cpp:467
void scanLibraryListUpdated(int libraryCount)
FilePath getLatest(const Uuid &uuid) const
Get an element of a specific UUID and the highest version.
Definition workspacelibrarydb.h:173
QSet< Uuid > getChilds(const std::optional< Uuid > &parent) const
Get children categories of a specific category.
Definition workspacelibrarydb.h:331
bool getMetadata(const FilePath elemDir, Uuid *uuid=nullptr, Version *version=nullptr, bool *deprecated=nullptr) const
Get metadata of a specific element.
Definition workspacelibrarydb.h:258
static QString getTable() noexcept
Definition workspacelibrarydb.cpp:620
QList< Part > getDeviceParts(const Uuid &device) const
Get all parts of a specific device.
Definition workspacelibrarydb.cpp:260
WorkspaceLibraryDb()=delete
QSet< Uuid > getByCategory(const std::optional< Uuid > &category, int limit=-1) const
Get elements of a specific category.
Definition workspacelibrarydb.h:356
void startLibraryRescan() noexcept
Rescan the whole library directory and update the SQLite database.
Definition workspacelibrarydb.cpp:283
bool getCategoryMetadata(const FilePath catDir, std::optional< Uuid > *parent=nullptr) const
Get additional metadata of a specific category.
Definition workspacelibrarydb.h:294
bool isScanInProgress() const noexcept
Check if there is currently a library scan in progress.
Definition workspacelibrarydb.h:134
static QString getCategoryTable() noexcept
Definition workspacelibrarydb.cpp:634
QScopedPointer< WorkspaceLibraryScanner > mLibraryScanner
Definition workspacelibrarydb.h:478
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:234
int getScanProgressPercent() const noexcept
Get the current progress of the library rescan.
Definition workspacelibrarydb.cpp:110
static QSet< Uuid > getUuidSet(QSqlQuery &query)
Definition workspacelibrarydb.cpp:592
int getDbVersion() const noexcept
Definition workspacelibrarydb.cpp:600
QSet< Uuid > getComponentDevices(const Uuid &component) const
Get all devices of a specific component.
Definition workspacelibrarydb.cpp:249
const FilePath mLibrariesPath
Path to workspace libraries directory.
Definition workspacelibrarydb.h:475
const FilePath mFilePath
Path to the SQLite database file.
Definition workspacelibrarydb.h:476
QList< Uuid > findDevicesOfParts(const QString &keyword) const
Find parts by keyword.
Definition workspacelibrarydb.cpp:154
QList< Part > findPartsOfDevice(const Uuid &device, const QString &keyword) const
Find parts of device by keyword.
Definition workspacelibrarydb.cpp:176
The WorkspaceLibraryScanner class.
Definition workspacelibraryscanner.h:52
Definition occmodel.cpp:76
Definition workspacelibrarydb.h:62
QString mpn
Definition workspacelibrarydb.h:63
bool operator==(const Part &rhs) const noexcept
Definition workspacelibrarydb.h:67
QString manufacturer
Definition workspacelibrarydb.h:64
bool operator<(const Part &rhs) const noexcept
Definition workspacelibrarydb.h:71
AttributeList attributes
Definition workspacelibrarydb.h:65