LibrePCB Developers Documentation
Loading...
Searching...
No Matches
workspacelibrarydbwriter.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_WORKSPACELIBRARYDBWRITER_H
21#define LIBREPCB_CORE_WORKSPACELIBRARYDBWRITER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../fileio/filepath.h"
27#include "../types/elementname.h"
28#include "../types/simplestring.h"
29#include "workspacelibrarydb.h"
30
31#include <QtCore>
32
33#include <optional>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39
40class Attribute;
41class Component;
42class ComponentCategory;
43class Device;
44class Package;
45class PackageCategory;
46class SQLiteDatabase;
47class Symbol;
48class Uuid;
49class Version;
50
51/*******************************************************************************
52 * Class WorkspaceLibraryDbWriter
53 ******************************************************************************/
54
59public:
60 // Constructors / Destructor
63 WorkspaceLibraryDbWriter(const FilePath& librariesRoot, SQLiteDatabase& db);
65
66 // General Methods
67
73 void createAllTables();
74
81 void addInternalData(const QString& key, int value);
82
94 int addLibrary(const FilePath& fp, const Uuid& uuid, const Version& version,
95 bool deprecated, const QByteArray& iconPng,
96 const QString& manufacturer);
97
108 void updateLibrary(const FilePath& fp, const Uuid& uuid,
109 const Version& version, bool deprecated,
110 const QByteArray& iconPng, const QString& manufacturer);
111
124 template <typename ElementType>
125 int addElement(int libId, const FilePath& fp, const Uuid& uuid,
126 const Version& version, bool deprecated,
127 const QString& generatedBy) {
128 static_assert(std::is_same<ElementType, Symbol>::value ||
129 std::is_same<ElementType, Package>::value ||
130 std::is_same<ElementType, Component>::value,
131 "Unsupported ElementType");
132 return addElement(getElementTable<ElementType>(), libId, fp, uuid, version,
133 deprecated, generatedBy);
134 }
135
148 template <typename ElementType>
149 int addCategory(int libId, const FilePath& fp, const Uuid& uuid,
150 const Version& version, bool deprecated,
151 const std::optional<Uuid>& parent) {
152 static_assert(std::is_same<ElementType, ComponentCategory>::value ||
153 std::is_same<ElementType, PackageCategory>::value,
154 "Unsupported ElementType");
155 return addCategory(getElementTable<ElementType>(), libId, fp, uuid, version,
156 deprecated, parent);
157 }
158
172 int addDevice(int libId, const FilePath& fp, const Uuid& uuid,
173 const Version& version, bool deprecated,
174 const QString& generatedBy, const Uuid& component,
175 const Uuid& package);
176
185 int addPart(int devId, const QString& mpn, const QString& manufacturer);
186
194 int addPartAttribute(int partId, const Attribute& attribute);
195
213 int addOrganization(int libId, const FilePath& fp, const Uuid& uuid,
214 const Version& version, bool deprecated,
215 const QByteArray& logoPng, const QUrl& url,
216 const QString& country, const QStringList& fabs,
217 const QStringList& shipping, bool isSponsor,
218 int priority);
219
231 int addOrganizationPcbDesignRules(int orgId, const Uuid& uuid,
232 const QString& name,
233 const QString& description, const QUrl& url,
234 int maxLayers);
235
246 int addOrganizationOutputJob(int orgId,
248 const Uuid& uuid, const QString& type,
249 const QString& name);
250
260 template <typename ElementType>
261 void removeElement(const FilePath& fp) {
262 removeElement(getElementTable<ElementType>(), fp);
263 }
264
273 template <typename ElementType>
275 removeAllElements(getElementTable<ElementType>());
276 }
277
289 template <typename ElementType>
290 int addTranslation(int elementId, const QString& locale,
291 const std::optional<ElementName>& name,
292 const std::optional<QString>& description,
293 const std::optional<QString>& keywords) {
294 return addTranslation(getElementTable<ElementType>(), elementId, locale,
295 name, description, keywords);
296 }
297
303 template <typename ElementType>
305 removeAllTranslations(getElementTable<ElementType>());
306 }
307
316 template <typename ElementType>
317 int addToCategory(int elementId, const Uuid& category) {
318 static_assert(std::is_same<ElementType, Symbol>::value ||
319 std::is_same<ElementType, Package>::value ||
320 std::is_same<ElementType, Component>::value ||
321 std::is_same<ElementType, Device>::value,
322 "Unsupported ElementType");
323 return addToCategory(getElementTable<ElementType>(), elementId, category);
324 }
325
336 template <typename ElementType>
337 int addResource(int elementId, const QString& name, const QString& mediaType,
338 const QUrl& url) {
339 static_assert(std::is_same<ElementType, Component>::value ||
340 std::is_same<ElementType, Device>::value,
341 "Unsupported ElementType");
342 return addResource(getElementTable<ElementType>(), elementId, name,
343 mediaType, url);
344 }
345
354 int addAlternativeName(int pkgId, const ElementName& name,
355 const SimpleString& reference);
356
357 // Helper Functions
358
365 template <typename ElementType>
366 static QString getElementTable() noexcept;
367
375 template <typename ElementType>
376 static QString getCategoryTable() noexcept;
377
378 // Operator Overloadings
380 delete;
381
382private: // Methods
383 int addElement(const QString& elementsTable, int libId, const FilePath& fp,
384 const Uuid& uuid, const Version& version, bool deprecated,
385 const QString& generatedBy);
386 int addCategory(const QString& categoriesTable, int libId, const FilePath& fp,
387 const Uuid& uuid, const Version& version, bool deprecated,
388 const std::optional<Uuid>& parent);
389 void removeElement(const QString& elementsTable, const FilePath& fp);
390 void removeAllElements(const QString& elementsTable);
391 int addTranslation(const QString& elementsTable, int elementId,
392 const QString& locale,
393 const std::optional<ElementName>& name,
394 const std::optional<QString>& description,
395 const std::optional<QString>& keywords);
396 void removeAllTranslations(const QString& elementsTable);
397 int addToCategory(const QString& elementsTable, int elementId,
398 const Uuid& category);
399 int addResource(const QString& elementsTable, int elementId,
400 const QString& name, const QString& mediaType,
401 const QUrl& url);
402 QString filePathToString(const FilePath& fp) const noexcept;
403 static QString nonEmptyOrNull(const QString& s) noexcept;
404 static QString nonNull(const QString& s) noexcept;
405
406private: // Data
409};
410
411/*******************************************************************************
412 * End of File
413 ******************************************************************************/
414
415} // namespace librepcb
416
417#endif
The Attribute class.
Definition attribute.h:46
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The SQLiteDatabase class.
Definition sqlitedatabase.h:43
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
OutputJobKind
Definition workspacelibrarydb.h:112
Database write functions for librepcb::WorkspaceLibraryDb.
Definition workspacelibrarydbwriter.h:58
SQLiteDatabase & mDb
Definition workspacelibrarydbwriter.h:408
int addAlternativeName(int pkgId, const ElementName &name, const SimpleString &reference)
Add an alternative name to a previously added package.
Definition workspacelibrarydbwriter.cpp:526
int addTranslation(int elementId, const QString &locale, const std::optional< ElementName > &name, const std::optional< QString > &description, const std::optional< QString > &keywords)
Add a translation for a library element.
Definition workspacelibrarydbwriter.h:290
int addDevice(int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QString &generatedBy, const Uuid &component, const Uuid &package)
addElement() specialized for devices
Definition workspacelibrarydbwriter.cpp:418
int addPartAttribute(int partId, const Attribute &attribute)
Add an attribute to a previously added part.
Definition workspacelibrarydbwriter.cpp:453
static QString nonEmptyOrNull(const QString &s) noexcept
Definition workspacelibrarydbwriter.cpp:730
QString filePathToString(const FilePath &fp) const noexcept
Definition workspacelibrarydbwriter.cpp:725
void updateLibrary(const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QByteArray &iconPng, const QString &manufacturer)
Update library metadata.
Definition workspacelibrarydbwriter.cpp:401
int addPart(int devId, const QString &mpn, const QString &manufacturer)
Add a part to a previously added device.
Definition workspacelibrarydbwriter.cpp:441
void removeElement(const FilePath &fp)
Remove a library element.
Definition workspacelibrarydbwriter.h:261
int addToCategory(int elementId, const Uuid &category)
Add a library element to a category.
Definition workspacelibrarydbwriter.h:317
int addCategory(int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const std::optional< Uuid > &parent)
addElement() specialized for categories
Definition workspacelibrarydbwriter.h:149
void addInternalData(const QString &key, int value)
Add an integer value to the "internal" table.
Definition workspacelibrarydbwriter.cpp:374
FilePath mLibrariesRoot
Definition workspacelibrarydbwriter.h:407
int addLibrary(const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QByteArray &iconPng, const QString &manufacturer)
Add a library.
Definition workspacelibrarydbwriter.cpp:383
int addOrganizationOutputJob(int orgId, WorkspaceLibraryDb::OutputJobKind kind, const Uuid &uuid, const QString &type, const QString &name)
Add an output job to a previously added organization.
Definition workspacelibrarydbwriter.cpp:511
int addResource(int elementId, const QString &name, const QString &mediaType, const QUrl &url)
Add a resource for a library element.
Definition workspacelibrarydbwriter.h:337
static QString nonNull(const QString &s) noexcept
Definition workspacelibrarydbwriter.cpp:734
int addOrganization(int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QByteArray &logoPng, const QUrl &url, const QString &country, const QStringList &fabs, const QStringList &shipping, bool isSponsor, int priority)
addElement() specialized for organizations
Definition workspacelibrarydbwriter.cpp:469
~WorkspaceLibraryDbWriter() noexcept
Definition workspacelibrarydbwriter.cpp:57
int addElement(int libId, const FilePath &fp, const Uuid &uuid, const Version &version, bool deprecated, const QString &generatedBy)
Add a library element.
Definition workspacelibrarydbwriter.h:125
static QString getElementTable() noexcept
Get the table name of an element type.
void removeAllElements()
Remove all library elements of a specific type.
Definition workspacelibrarydbwriter.h:274
WorkspaceLibraryDbWriter(const WorkspaceLibraryDbWriter &other)=delete
int addOrganizationPcbDesignRules(int orgId, const Uuid &uuid, const QString &name, const QString &description, const QUrl &url, int maxLayers)
Add PCB design rules to a previously added organization.
Definition workspacelibrarydbwriter.cpp:495
void createAllTables()
Create all tables to initialize the database.
Definition workspacelibrarydbwriter.cpp:64
static QString getCategoryTable() noexcept
Get the category table name of an element type.
void removeAllTranslations()
Remove all translations for a library element type.
Definition workspacelibrarydbwriter.h:304
Definition occmodel.cpp:77
type_safe::constrained_type< QString, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition simplestring.h:79
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84
Definition uuid.h:186