LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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_CORE_LIBRARYBASEELEMENT_H
21#define LIBREPCB_CORE_LIBRARYBASEELEMENT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../fileio/transactionaldirectory.h"
27#include "../rulecheck/rulecheckmessage.h"
28#include "../serialization/serializablekeyvaluemap.h"
29#include "../types/uuid.h"
30#include "../types/version.h"
31
32#include <QObject>
33
34#include <memory>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41/*******************************************************************************
42 * Class LibraryBaseElement
43 ******************************************************************************/
44
48class LibraryBaseElement : public QObject {
49 Q_OBJECT
50
51public:
52 // Constructors / Destructor
54 LibraryBaseElement(const LibraryBaseElement& other) = delete;
55 LibraryBaseElement(const QString& shortElementName,
56 const QString& longElementName, const Uuid& uuid,
57 const Version& version, const QString& author,
58 const ElementName& name_en_US,
59 const QString& description_en_US,
60 const QString& keywords_en_US);
61 LibraryBaseElement(const QString& shortElementName,
62 const QString& longElementName, bool dirnameMustBeUuid,
63 std::unique_ptr<TransactionalDirectory> directory,
64 const SExpression& root);
65 virtual ~LibraryBaseElement() noexcept;
66
67 // Getters: General
68 const TransactionalDirectory& getDirectory() const noexcept {
69 return *mDirectory;
70 }
72
73 // Getters: Attributes
74 const Uuid& getUuid() const noexcept { return mUuid; }
75 const Version& getVersion() const noexcept { return mVersion; }
76 const QString& getAuthor() const noexcept { return mAuthor; }
77 const QDateTime& getCreated() const noexcept { return mCreated; }
78 bool isDeprecated() const noexcept { return mIsDeprecated; }
79 const LocalizedNameMap& getNames() const noexcept { return mNames; }
80 const LocalizedDescriptionMap& getDescriptions() const noexcept {
81 return mDescriptions;
82 }
83 const LocalizedKeywordsMap& getKeywords() const noexcept { return mKeywords; }
84 QStringList getAllAvailableLocales() const noexcept;
85 const QSet<SExpression>& getMessageApprovals() const noexcept {
86 return mMessageApprovals;
87 }
88
89 // Setters
90 void setVersion(const Version& version) noexcept { mVersion = version; }
91 void setAuthor(const QString& author) noexcept { mAuthor = author; }
92 void setDeprecated(bool deprecated) noexcept { mIsDeprecated = deprecated; }
93 void setNames(const LocalizedNameMap& names) noexcept { mNames = names; }
94 void setDescriptions(const LocalizedDescriptionMap& descriptions) noexcept {
95 mDescriptions = descriptions;
96 }
97 void setKeywords(const LocalizedKeywordsMap& keywords) noexcept {
98 mKeywords = keywords;
99 }
100 void setMessageApprovals(const QSet<SExpression>& approvals) noexcept {
101 mMessageApprovals = approvals;
102 }
103 bool setMessageApproved(const SExpression& approval, bool approved) noexcept;
104
105 // General Methods
106 virtual RuleCheckMessageList runChecks() const;
107 virtual void save();
108 virtual void saveTo(TransactionalDirectory& dest);
109 virtual void moveTo(TransactionalDirectory& dest);
112
113 // Operator Overloadings
115
116 // Static Methods
117 template <typename ElementType>
118 static bool isValidElementDirectory(const FilePath& dir) noexcept {
119 return dir.getPathTo(".librepcb-" % ElementType::getShortElementName())
120 .isExistingFile();
121 }
122 template <typename ElementType>
124 const QString& path) noexcept {
125 return dir.fileExists((path.isEmpty() ? path : path % "/") % ".librepcb-" %
126 ElementType::getShortElementName());
127 }
128
129protected: // Methods
135 virtual void serialize(SExpression& root) const;
136
137 void serializeMessageApprovals(SExpression& root) const;
138
140
141 static Version readFileFormat(const TransactionalDirectory& directory,
142 const QString& fileName);
143
144protected: // Data
145 // General Attributes
146 const QString mShortElementName;
147 const QString mLongElementName;
148 std::unique_ptr<TransactionalDirectory> mDirectory;
149
150 // General Library Element Attributes
153 QString mAuthor;
154 QDateTime mCreated;
159
160 // Library element check
161 QSet<SExpression> mMessageApprovals;
162};
163
164/*******************************************************************************
165 * End of File
166 ******************************************************************************/
167
168} // namespace librepcb
169
170#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The LibraryBaseElement class.
Definition librarybaseelement.h:48
TransactionalDirectory & getDirectory() noexcept
Definition librarybaseelement.h:71
void serializeMessageApprovals(SExpression &root) const
Definition librarybaseelement.cpp:190
QDateTime mCreated
Definition librarybaseelement.h:154
const TransactionalDirectory & getDirectory() const noexcept
Definition librarybaseelement.h:68
QSet< SExpression > mMessageApprovals
Definition librarybaseelement.h:161
LocalizedKeywordsMap mKeywords
Definition librarybaseelement.h:158
const QString mShortElementName
e.g. "lib", "cmpcat"
Definition librarybaseelement.h:146
const LocalizedKeywordsMap & getKeywords() const noexcept
Definition librarybaseelement.h:83
const LocalizedNameMap & getNames() const noexcept
Definition librarybaseelement.h:79
bool mIsDeprecated
Definition librarybaseelement.h:155
void setVersion(const Version &version) noexcept
Definition librarybaseelement.h:90
void setKeywords(const LocalizedKeywordsMap &keywords) noexcept
Definition librarybaseelement.h:97
const QString & getAuthor() const noexcept
Definition librarybaseelement.h:76
LibraryBaseElement & operator=(const LibraryBaseElement &rhs)=delete
void setDeprecated(bool deprecated) noexcept
Definition librarybaseelement.h:92
QStringList getAllAvailableLocales() const noexcept
Definition librarybaseelement.cpp:103
void setMessageApprovals(const QSet< SExpression > &approvals) noexcept
Definition librarybaseelement.h:100
Version mVersion
Definition librarybaseelement.h:152
Uuid mUuid
Definition librarybaseelement.h:151
void removeObsoleteMessageApprovals()
Definition librarybaseelement.cpp:198
void setNames(const LocalizedNameMap &names) noexcept
Definition librarybaseelement.h:93
virtual void moveIntoParentDirectory(TransactionalDirectory &dest)
Definition librarybaseelement.cpp:166
bool setMessageApproved(const SExpression &approval, bool approved) noexcept
Definition librarybaseelement.cpp:117
virtual void saveTo(TransactionalDirectory &dest)
Definition librarybaseelement.cpp:151
LocalizedDescriptionMap mDescriptions
Definition librarybaseelement.h:157
bool isDeprecated() const noexcept
Definition librarybaseelement.h:78
const QSet< SExpression > & getMessageApprovals() const noexcept
Definition librarybaseelement.h:85
const QDateTime & getCreated() const noexcept
Definition librarybaseelement.h:77
virtual ~LibraryBaseElement() noexcept
Definition librarybaseelement.cpp:96
LocalizedNameMap mNames
Definition librarybaseelement.h:156
static bool isValidElementDirectory(const TransactionalDirectory &dir, const QString &path) noexcept
Definition librarybaseelement.h:123
virtual void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition librarybaseelement.cpp:171
virtual void save()
Definition librarybaseelement.cpp:138
const LocalizedDescriptionMap & getDescriptions() const noexcept
Definition librarybaseelement.h:80
const Uuid & getUuid() const noexcept
Definition librarybaseelement.h:74
static Version readFileFormat(const TransactionalDirectory &directory, const QString &fileName)
Definition librarybaseelement.cpp:203
LibraryBaseElement(const LibraryBaseElement &other)=delete
static bool isValidElementDirectory(const FilePath &dir) noexcept
Definition librarybaseelement.h:118
virtual void saveIntoParentDirectory(TransactionalDirectory &dest)
Definition librarybaseelement.cpp:161
std::unique_ptr< TransactionalDirectory > mDirectory
Definition librarybaseelement.h:148
void setDescriptions(const LocalizedDescriptionMap &descriptions) noexcept
Definition librarybaseelement.h:94
const Version & getVersion() const noexcept
Definition librarybaseelement.h:75
virtual void moveTo(TransactionalDirectory &dest)
Definition librarybaseelement.cpp:156
const QString mLongElementName
e.g. "library", "component_category"
Definition librarybaseelement.h:147
virtual RuleCheckMessageList runChecks() const
Definition librarybaseelement.cpp:133
void setAuthor(const QString &author) noexcept
Definition librarybaseelement.h:91
QString mAuthor
Definition librarybaseelement.h:153
The SExpression class.
Definition sexpression.h:69
Helper class to access a subdirectory of TransactionalFileSystem.
Definition transactionaldirectory.h:51
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
Definition occmodel.cpp:77
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition rulecheckmessage.h:104
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84