LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
librarybaseelement.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_LIBRARY_LIBRARYBASEELEMENT_H
21 #define LIBREPCB_LIBRARY_LIBRARYBASEELEMENT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
32 #include <librepcb/common/uuid.h>
34 
35 #include <QObject>
36 
37 #include <memory>
38 
39 /*******************************************************************************
40  * Namespace / Forward Declarations
41  ******************************************************************************/
42 namespace librepcb {
43 namespace library {
44 
45 /*******************************************************************************
46  * Class LibraryBaseElement
47  ******************************************************************************/
48 
52 class LibraryBaseElement : public QObject, public SerializableObject {
53  Q_OBJECT
54 
55 public:
56  // Constructors / Destructor
57  LibraryBaseElement() = delete;
58  LibraryBaseElement(const LibraryBaseElement& other) = delete;
59  LibraryBaseElement(bool dirnameMustBeUuid, const QString& shortElementName,
60  const QString& longElementName, const Uuid& uuid,
61  const Version& version, const QString& author,
62  const ElementName& name_en_US,
63  const QString& description_en_US,
64  const QString& keywords_en_US);
65  LibraryBaseElement(std::unique_ptr<TransactionalDirectory> directory,
66  bool dirnameMustBeUuid, const QString& shortElementName,
67  const QString& longElementName);
68  virtual ~LibraryBaseElement() noexcept;
69 
70  // Getters: General
71  const TransactionalDirectory& getDirectory() const noexcept {
72  return *mDirectory;
73  }
75  const QString& getShortElementName() const noexcept {
76  return mShortElementName;
77  }
78  const QString& getLongElementName() const noexcept {
79  return mLongElementName;
80  }
81 
82  // Getters: Attributes
83  const Uuid& getUuid() const noexcept { return mUuid; }
84  const Version& getVersion() const noexcept { return mVersion; }
85  const QString& getAuthor() const noexcept { return mAuthor; }
86  const QDateTime& getCreated() const noexcept { return mCreated; }
87  bool isDeprecated() const noexcept { return mIsDeprecated; }
88  const LocalizedNameMap& getNames() const noexcept { return mNames; }
89  const LocalizedDescriptionMap& getDescriptions() const noexcept {
90  return mDescriptions;
91  }
92  const LocalizedKeywordsMap& getKeywords() const noexcept { return mKeywords; }
93  QStringList getAllAvailableLocales() const noexcept;
94 
95  // Setters
96  void setVersion(const Version& version) noexcept { mVersion = version; }
97  void setAuthor(const QString& author) noexcept { mAuthor = author; }
98  void setDeprecated(bool deprecated) noexcept { mIsDeprecated = deprecated; }
99  void setNames(const LocalizedNameMap& names) noexcept { mNames = names; }
100  void setDescriptions(const LocalizedDescriptionMap& descriptions) noexcept {
101  mDescriptions = descriptions;
102  }
103  void setKeywords(const LocalizedKeywordsMap& keywords) noexcept {
104  mKeywords = keywords;
105  }
106 
107  // General Methods
109  virtual void save();
110  virtual void saveTo(TransactionalDirectory& dest);
111  virtual void moveTo(TransactionalDirectory& dest);
114 
115  // Operator Overloadings
116  LibraryBaseElement& operator=(const LibraryBaseElement& rhs) = delete;
117 
118  // Static Methods
119  template <typename ElementType>
120  static bool isValidElementDirectory(const FilePath& dir) noexcept {
121  return dir.getPathTo(".librepcb-" % ElementType::getShortElementName())
122  .isExistingFile();
123  }
124  template <typename ElementType>
126  const QString& path) noexcept {
127  return dir.fileExists((path.isEmpty() ? path : path % "/") % ".librepcb-" %
128  ElementType::getShortElementName());
129  }
130 
131 protected:
132  // Protected Methods
133  virtual void cleanupAfterLoadingElementFromFile() noexcept;
134 
136  virtual void serialize(SExpression& root) const override;
137 
138  // General Attributes
143 
144  // Members required for loading elements from file
146 
147  // General Library Element Attributes
150  QString mAuthor;
151  QDateTime mCreated;
156 };
157 
158 /*******************************************************************************
159  * End of File
160  ******************************************************************************/
161 
162 } // namespace library
163 } // namespace librepcb
164 
165 #endif // LIBREPCB_LIBRARY_LIBRARYBASEELEMENT_H
void setNames(const LocalizedNameMap &names) noexcept
Definition: librarybaseelement.h:99
virtual LibraryElementCheckMessageList runChecks() const
Definition: librarybaseelement.cpp:161
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
void setAuthor(const QString &author) noexcept
Definition: librarybaseelement.h:97
const QString & getAuthor() const noexcept
Definition: librarybaseelement.h:85
const LocalizedDescriptionMap & getDescriptions() const noexcept
Definition: librarybaseelement.h:89
virtual ~LibraryBaseElement() noexcept
Definition: librarybaseelement.cpp:140
const QDateTime & getCreated() const noexcept
Definition: librarybaseelement.h:86
const LocalizedKeywordsMap & getKeywords() const noexcept
Definition: librarybaseelement.h:92
void setKeywords(const LocalizedKeywordsMap &keywords) noexcept
Definition: librarybaseelement.h:103
SExpression mLoadingFileDocument
Definition: librarybaseelement.h:145
bool mDirectoryNameMustBeUuid
Definition: librarybaseelement.h:140
virtual void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: librarybaseelement.cpp:205
QString mLongElementName
e.g. "library", "component_category", "symbol"
Definition: librarybaseelement.h:142
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:52
virtual void cleanupAfterLoadingElementFromFile() noexcept
Definition: librarybaseelement.cpp:201
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
void setDescriptions(const LocalizedDescriptionMap &descriptions) noexcept
Definition: librarybaseelement.h:100
bool mIsDeprecated
Definition: librarybaseelement.h:152
LocalizedNameMap mNames
Definition: librarybaseelement.h:153
const QString & getLongElementName() const noexcept
Definition: librarybaseelement.h:78
void setDeprecated(bool deprecated) noexcept
Definition: librarybaseelement.h:98
The LibraryBaseElement class.
Definition: librarybaseelement.h:52
static bool isValidElementDirectory(const TransactionalDirectory &dir, const QString &path) noexcept
Definition: librarybaseelement.h:125
QDateTime mCreated
Definition: librarybaseelement.h:151
static bool isValidElementDirectory(const FilePath &dir) noexcept
Definition: librarybaseelement.h:120
const Version & getVersion() const noexcept
Definition: librarybaseelement.h:84
QString mAuthor
Definition: librarybaseelement.h:150
const TransactionalDirectory & getDirectory() const noexcept
Definition: librarybaseelement.h:71
virtual void moveIntoParentDirectory(TransactionalDirectory &dest)
Definition: librarybaseelement.cpp:192
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: librarybaseelement.h:139
Uuid mUuid
Definition: librarybaseelement.h:148
LocalizedDescriptionMap mDescriptions
Definition: librarybaseelement.h:154
virtual void saveIntoParentDirectory(TransactionalDirectory &dest)
Definition: librarybaseelement.cpp:187
virtual void save()
Definition: librarybaseelement.cpp:166
LibraryBaseElement & operator=(const LibraryBaseElement &rhs)=delete
Version mVersion
Definition: librarybaseelement.h:149
const QString & getShortElementName() const noexcept
Definition: librarybaseelement.h:75
QString mShortElementName
e.g. "lib", "cmpcat", "sym"
Definition: librarybaseelement.h:141
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
virtual void saveTo(TransactionalDirectory &dest)
Definition: librarybaseelement.cpp:177
bool isDeprecated() const noexcept
Definition: librarybaseelement.h:87
const Uuid & getUuid() const noexcept
Definition: librarybaseelement.h:83
void setVersion(const Version &version) noexcept
Definition: librarybaseelement.h:96
TransactionalDirectory & getDirectory() noexcept
Definition: librarybaseelement.h:74
const LocalizedNameMap & getNames() const noexcept
Definition: librarybaseelement.h:88
The SExpression class.
Definition: sexpression.h:57
QStringList getAllAvailableLocales() const noexcept
Definition: librarybaseelement.cpp:147
LocalizedKeywordsMap mKeywords
Definition: librarybaseelement.h:155
virtual void moveTo(TransactionalDirectory &dest)
Definition: librarybaseelement.cpp:182
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92