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 "../types/uuid.h" 30 #include "../types/version.h" 42 class ComponentCategory;
45 class PackageCategory;
48 class WorkspaceLibraryScanner;
67 return (mpn == rhs.mpn) && (manufacturer == rhs.manufacturer) &&
68 (attributes == rhs.attributes);
71 if (mpn.isEmpty() != rhs.mpn.isEmpty()) {
72 return mpn.count() < rhs.mpn.count();
77 if (manufacturer != rhs.manufacturer) {
78 return manufacturer < rhs.manufacturer;
81 collator.setNumericMode(
true);
82 collator.setCaseSensitivity(Qt::CaseInsensitive);
83 collator.setIgnorePunctuation(
false);
84 for (
int i = 0; i < std::max(attributes.
count(), rhs.attributes.count());
86 auto a = attributes.
value(i);
87 auto b = rhs.attributes.value(i);
90 }
else if ((!a) && b) {
92 }
else if (a->getKey() != b->getKey()) {
93 return a->getKey() < b->getKey();
94 }
else if (&a->getType() != &b->getType()) {
95 return a->getType().getName() < b->getType().getName();
96 }
else if (a->getValueTr(
true) != b->getValueTr(
true)) {
97 return collator(a->getValueTr(
true), b->getValueTr(
true));
155 template <
typename ElementType>
157 const tl::optional<Uuid>& uuid = tl::nullopt,
159 return getAll(getTable<ElementType>(), uuid, lib);
171 template <
typename ElementType>
185 template <
typename ElementType>
186 QList<Uuid>
find(
const QString& keyword)
const;
210 const QString& keyword)
const;
232 template <
typename ElementType>
234 QString* name =
nullptr, QString* description =
nullptr,
235 QString* keywords =
nullptr)
const {
236 return getTranslations(getTable<ElementType>(), elemDir, localeOrder, name,
237 description, keywords);
256 template <
typename ElementType>
259 bool* deprecated =
nullptr)
const {
260 return getMetadata(getTable<ElementType>(), elemDir, uuid, version,
292 template <
typename ElementType>
294 tl::optional<Uuid>* parent =
nullptr)
const {
295 static_assert(std::is_same<ElementType, ComponentCategory>::value ||
296 std::is_same<ElementType, PackageCategory>::value,
297 "Unsupported ElementType");
314 Uuid* pkgUuid =
nullptr)
const;
329 template <
typename ElementType>
330 QSet<Uuid>
getChilds(
const tl::optional<Uuid>& parent)
const {
331 static_assert(std::is_same<ElementType, ComponentCategory>::value ||
332 std::is_same<ElementType, PackageCategory>::value,
333 "Unsupported ElementType");
334 return getChilds(getTable<ElementType>(), parent);
354 template <
typename ElementType>
356 int limit = -1)
const {
357 static_assert(std::is_same<ElementType, Symbol>::value ||
358 std::is_same<ElementType, Package>::value ||
359 std::is_same<ElementType, Component>::value ||
360 std::is_same<ElementType, Device>::value,
361 "Unsupported ElementType");
363 getCategoryTable<ElementType>(), category, limit);
404 QMultiMap<Version, FilePath>
getAll(
const QString& elementsTable,
405 const tl::optional<Uuid>& uuid,
408 const QMultiMap<Version, FilePath>& list)
const noexcept;
409 QList<Uuid>
find(
const QString& elementsTable,
const QString& keyword)
const;
411 const QStringList& localeOrder, QString* name,
412 QString* description, QString* keywords)
const;
414 Uuid* uuid,
Version* version,
bool* deprecated)
const;
417 tl::optional<Uuid>* parent)
const;
419 QSet<Uuid>
getChilds(
const QString& categoriesTable,
420 const tl::optional<Uuid>& categoryUuid)
const;
422 const QString& categoryTable,
423 const tl::optional<Uuid>& category,
int limit)
const;
424 static QSet<Uuid>
getUuidSet(QSqlQuery& query);
426 template <
typename ElementType>
428 template <
typename ElementType>
434 QScopedPointer<SQLiteDatabase>
mDb;
static QSet< Uuid > getUuidSet(QSqlQuery &query)
Definition: workspacelibrarydb.cpp:553
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
QSet< Uuid > getComponentDevices(const Uuid &component) const
Get all devices of a specific component.
Definition: workspacelibrarydb.cpp:250
QString manufacturer
Definition: workspacelibrarydb.h:63
static const int sCurrentDbVersion
Definition: workspacelibrarydb.h:438
std::shared_ptr< T > value(int index) noexcept
Definition: serializableobjectlist.h:254
void scanLibraryListUpdated(int libraryCount)
QList< Uuid > findDevicesOfParts(const QString &keyword) const
Find parts by keyword.
Definition: workspacelibrarydb.cpp:155
static QString getCategoryTable() noexcept
Definition: workspacelibrarydb.cpp:595
bool getLibraryMetadata(const FilePath libDir, QPixmap *icon=nullptr, QString *manufacturer=nullptr) const
Get additional metadata of a specific library.
Definition: workspacelibrarydb.cpp:199
Definition: occmodel.cpp:77
void scanFailed(QString errorMsg)
QList< Part > findPartsOfDevice(const Uuid &device, const QString &keyword) const
Find parts of device by keyword.
Definition: workspacelibrarydb.cpp:177
int count() const noexcept
Definition: serializableobjectlist.h:199
AttributeList getPartAttributes(int partId) const
Definition: workspacelibrarydb.cpp:468
int getDbVersion() const noexcept
Definition: workspacelibrarydb.cpp:561
const FilePath mFilePath
Path to the SQLite database file.
Definition: workspacelibrarydb.h:433
QSet< Uuid > getByCategory(const tl::optional< Uuid > &category, int limit=-1) const
Get elements of a specific category.
Definition: workspacelibrarydb.h:355
const FilePath & getFilePath() const noexcept
Get the file path of the SQLite database.
Definition: workspacelibrarydb.h:126
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:156
bool isScanInProgress() const noexcept
Check if there is currently a library scan in progress.
Definition: workspacelibrarydb.h:133
QList< Part > getDeviceParts(const Uuid &device) const
Get all parts of a specific device.
Definition: workspacelibrarydb.cpp:261
QScopedPointer< WorkspaceLibraryScanner > mLibraryScanner
Definition: workspacelibrarydb.h:435
~WorkspaceLibraryDb() noexcept
Definition: workspacelibrarydb.cpp:104
QString mpn
Definition: workspacelibrarydb.h:62
static QString getTable() noexcept
Definition: workspacelibrarydb.cpp:581
bool getCategoryMetadata(const FilePath catDir, tl::optional< Uuid > *parent=nullptr) const
Get additional metadata of a specific category.
Definition: workspacelibrarydb.h:293
QScopedPointer< SQLiteDatabase > mDb
The SQLite database.
Definition: workspacelibrarydb.h:434
void scanProgressUpdate(int percent)
AttributeList attributes
Definition: workspacelibrarydb.h:64
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
Definition: workspacelibrarydb.h:61
const FilePath mLibrariesPath
Path to workspace libraries directory.
Definition: workspacelibrarydb.h:432
bool getMetadata(const FilePath elemDir, Uuid *uuid=nullptr, Version *version=nullptr, bool *deprecated=nullptr) const
Get metadata of a specific element.
Definition: workspacelibrarydb.h:257
WorkspaceLibraryDb()=delete
QList< Uuid > find(const QString &keyword) const
Find elements by keyword.
Definition: workspacelibrarydb.cpp:116
bool operator<(const Part &rhs) const noexcept
Definition: workspacelibrarydb.h:70
int getScanProgressPercent() const noexcept
Get the current progress of the library rescan.
Definition: workspacelibrarydb.cpp:111
bool operator==(const Part &rhs) const noexcept
Definition: workspacelibrarydb.h:66
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
bool getDeviceMetadata(const FilePath &devDir, Uuid *cmpUuid=nullptr, Uuid *pkgUuid=nullptr) const
Get additional metadata of a specific device.
Definition: workspacelibrarydb.cpp:223
FilePath getLatest(const Uuid &uuid) const
Get an element of a specific UUID and the highest version.
Definition: workspacelibrarydb.h:172
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:233
FilePath getLatestVersionFilePath(const QMultiMap< Version, FilePath > &list) const noexcept
Definition: workspacelibrarydb.cpp:341
WorkspaceLibraryDb & operator=(const WorkspaceLibraryDb &rhs)=delete
void startLibraryRescan() noexcept
Rescan the whole library directory and update the SQLite database.
Definition: workspacelibrarydb.cpp:284
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:57
QSet< Uuid > getChilds(const tl::optional< Uuid > &parent) const
Get children categories of a specific category.
Definition: workspacelibrarydb.h:330