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
104 // General Methods
105 virtual RuleCheckMessageList runChecks() const;
106 virtual void save();
107 virtual void saveTo(TransactionalDirectory& dest);
108 virtual void moveTo(TransactionalDirectory& dest);
111
112 // Operator Overloadings
114
115 // Static Methods
116 template <typename ElementType>
117 static bool isValidElementDirectory(const FilePath& dir) noexcept {
118 return dir.getPathTo(".librepcb-" % ElementType::getShortElementName())
119 .isExistingFile();
120 }
121 template <typename ElementType>
123 const QString& path) noexcept {
124 return dir.fileExists((path.isEmpty() ? path : path % "/") % ".librepcb-" %
125 ElementType::getShortElementName());
126 }
127
128protected: // Methods
134 virtual void serialize(SExpression& root) const;
135
136 void serializeMessageApprovals(SExpression& root) const;
137
139
140 static Version readFileFormat(const TransactionalDirectory& directory,
141 const QString& fileName);
142
143protected: // Data
144 // General Attributes
145 const QString mShortElementName;
146 const QString mLongElementName;
147 std::unique_ptr<TransactionalDirectory> mDirectory;
148
149 // General Library Element Attributes
152 QString mAuthor;
153 QDateTime mCreated;
158
159 // Library element check
160 QSet<SExpression> mMessageApprovals;
161};
162
163/*******************************************************************************
164 * End of File
165 ******************************************************************************/
166
167} // namespace librepcb
168
169#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:174
QDateTime mCreated
Definition librarybaseelement.h:153
const TransactionalDirectory & getDirectory() const noexcept
Definition librarybaseelement.h:68
QSet< SExpression > mMessageApprovals
Definition librarybaseelement.h:160
LocalizedKeywordsMap mKeywords
Definition librarybaseelement.h:157
const QString mShortElementName
e.g. "lib", "cmpcat"
Definition librarybaseelement.h:145
const LocalizedKeywordsMap & getKeywords() const noexcept
Definition librarybaseelement.h:83
const LocalizedNameMap & getNames() const noexcept
Definition librarybaseelement.h:79
bool mIsDeprecated
Definition librarybaseelement.h:154
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:151
Uuid mUuid
Definition librarybaseelement.h:150
void removeObsoleteMessageApprovals()
Definition librarybaseelement.cpp:182
void setNames(const LocalizedNameMap &names) noexcept
Definition librarybaseelement.h:93
virtual void moveIntoParentDirectory(TransactionalDirectory &dest)
Definition librarybaseelement.cpp:150
virtual void saveTo(TransactionalDirectory &dest)
Definition librarybaseelement.cpp:135
LocalizedDescriptionMap mDescriptions
Definition librarybaseelement.h:156
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:155
static bool isValidElementDirectory(const TransactionalDirectory &dir, const QString &path) noexcept
Definition librarybaseelement.h:122
virtual void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition librarybaseelement.cpp:155
virtual void save()
Definition librarybaseelement.cpp:122
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:187
LibraryBaseElement(const LibraryBaseElement &other)=delete
static bool isValidElementDirectory(const FilePath &dir) noexcept
Definition librarybaseelement.h:117
virtual void saveIntoParentDirectory(TransactionalDirectory &dest)
Definition librarybaseelement.cpp:145
std::unique_ptr< TransactionalDirectory > mDirectory
Definition librarybaseelement.h:147
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:140
const QString mLongElementName
e.g. "library", "component_category"
Definition librarybaseelement.h:146
virtual RuleCheckMessageList runChecks() const
Definition librarybaseelement.cpp:117
void setAuthor(const QString &author) noexcept
Definition librarybaseelement.h:91
QString mAuthor
Definition librarybaseelement.h:152
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:76
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition rulecheckmessage.h:104
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84