LibrePCB Developers Documentation
library.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_LIBRARY_H
21 #define LIBREPCB_CORE_LIBRARY_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../types/uuid.h"
27 #include "librarybaseelement.h"
28 
29 #include <QtCore>
30 
31 #include <memory>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 /*******************************************************************************
39  * Class Library
40  ******************************************************************************/
41 
45 class Library final : public LibraryBaseElement {
46  Q_OBJECT
47 
48 public:
49  // Constructors / Destructor
50  Library() = delete;
51  Library(const Library& other) = delete;
52  Library(const Uuid& uuid, const Version& version, const QString& author,
53  const ElementName& name_en_US, const QString& description_en_US,
54  const QString& keywords_en_US);
55  ~Library() noexcept;
56 
57  // Getters
58  template <typename ElementType>
59  QString getElementsDirectoryName() const noexcept;
60  const QUrl& getUrl() const noexcept { return mUrl; }
61  const QSet<Uuid>& getDependencies() const noexcept { return mDependencies; }
62  const QByteArray& getIcon() const noexcept { return mIcon; }
63  QPixmap getIconAsPixmap() const noexcept;
64 
65  // Setters
66  void setUrl(const QUrl& url) noexcept { mUrl = url; }
67  void setDependencies(const QSet<Uuid>& deps) noexcept {
68  mDependencies = deps;
69  }
70  void setIcon(const QByteArray& png) noexcept { mIcon = png; }
71 
72  // General Methods
73  virtual void save() override;
74  virtual void moveTo(TransactionalDirectory& dest) override;
75  template <typename ElementType>
76  QStringList searchForElements() const noexcept;
77 
78  // Operator Overloadings
79  Library& operator=(const Library& rhs) = delete;
80 
81  // Static Methods
82  static std::unique_ptr<Library> open(
83  std::unique_ptr<TransactionalDirectory> directory);
84  static QString getShortElementName() noexcept {
85  return QStringLiteral("lib");
86  }
87  static QString getLongElementName() noexcept {
88  return QStringLiteral("library");
89  }
90 
91 protected:
92  virtual void serialize(SExpression& root) const override;
93 
94 private: // Methods
95  Library(std::unique_ptr<TransactionalDirectory> directory,
96  const SExpression& root);
97 
98 private: // Data
99  QUrl mUrl;
100  QSet<Uuid> mDependencies;
101  QByteArray mIcon;
102 };
103 
104 /*******************************************************************************
105  * End of File
106  ******************************************************************************/
107 
108 } // namespace librepcb
109 
110 #endif
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
The LibraryBaseElement class.
Definition: librarybaseelement.h:48
static QString getLongElementName() noexcept
Definition: library.h:87
const QUrl & getUrl() const noexcept
Definition: library.h:60
const QByteArray & getIcon() const noexcept
Definition: library.h:62
QString getElementsDirectoryName() const noexcept
Definition: library.cpp:92
Definition: occmodel.cpp:76
static std::unique_ptr< Library > open(std::unique_ptr< TransactionalDirectory > directory)
Definition: library.cpp:166
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:51
~Library() noexcept
Definition: library.cpp:84
QByteArray mIcon
Definition: library.h:101
QSet< Uuid > mDependencies
Definition: library.h:100
void setUrl(const QUrl &url) noexcept
Definition: library.h:66
static QString getShortElementName() noexcept
Definition: library.h:84
virtual void save() override
Definition: library.cpp:116
Library & operator=(const Library &rhs)=delete
const QSet< Uuid > & getDependencies() const noexcept
Definition: library.h:61
virtual void moveTo(TransactionalDirectory &dest) override
Definition: library.cpp:127
void setIcon(const QByteArray &png) noexcept
Definition: library.h:70
QStringList searchForElements() const noexcept
Definition: library.cpp:141
The Library class represents a library directory.
Definition: library.h:45
void setDependencies(const QSet< Uuid > &deps) noexcept
Definition: library.h:67
QPixmap getIconAsPixmap() const noexcept
Definition: library.cpp:106
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:56
The SExpression class.
Definition: sexpression.h:66
QUrl mUrl
Definition: library.h:99
virtual void serialize(SExpression &root) const override
Serialize into librepcb::SExpression node.
Definition: library.cpp:193
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:93