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(const FilePath& elementDirectory, bool dirnameMustBeUuid,
66  const QString& shortElementName,
67  const QString& longElementName, bool readOnly);
68  virtual ~LibraryBaseElement() noexcept;
69 
70  // Getters: General
71  const FilePath& getFilePath() const noexcept { return mDirectory; }
72  const QString& getShortElementName() const noexcept {
73  return mShortElementName;
74  }
75  const QString& getLongElementName() const noexcept {
76  return mLongElementName;
77  }
78  bool isOpenedReadOnly() const noexcept { return mOpenedReadOnly; }
79 
80  // Getters: Attributes
81  const Uuid& getUuid() const noexcept { return mUuid; }
82  const Version& getVersion() const noexcept { return mVersion; }
83  const QString& getAuthor() const noexcept { return mAuthor; }
84  const QDateTime& getCreated() const noexcept { return mCreated; }
85  bool isDeprecated() const noexcept { return mIsDeprecated; }
86  const LocalizedNameMap& getNames() const noexcept { return mNames; }
87  const LocalizedDescriptionMap& getDescriptions() const noexcept {
88  return mDescriptions;
89  }
90  const LocalizedKeywordsMap& getKeywords() const noexcept { return mKeywords; }
91  QStringList getAllAvailableLocales() const noexcept;
92 
93  // Setters
94  void setVersion(const Version& version) noexcept { mVersion = version; }
95  void setAuthor(const QString& author) noexcept { mAuthor = author; }
96  void setDeprecated(bool deprecated) noexcept { mIsDeprecated = deprecated; }
97  void setNames(const LocalizedNameMap& names) noexcept { mNames = names; }
98  void setDescriptions(const LocalizedDescriptionMap& descriptions) noexcept {
99  mDescriptions = descriptions;
100  }
101  void setKeywords(const LocalizedKeywordsMap& keywords) noexcept {
102  mKeywords = keywords;
103  }
104 
105  // General Methods
107  virtual void save();
108  virtual void saveTo(const FilePath& destination);
109  virtual void saveIntoParentDirectory(const FilePath& parentDir);
110  virtual void moveTo(const FilePath& destination);
111  virtual void moveIntoParentDirectory(const FilePath& parentDir);
112 
113  // Operator Overloadings
114  LibraryBaseElement& operator=(const LibraryBaseElement& rhs) = delete;
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 
123 protected:
124  // Protected Methods
125  virtual void cleanupAfterLoadingElementFromFile() noexcept;
126  virtual void copyTo(const FilePath& destination, bool removeSource);
127 
129  virtual void serialize(SExpression& root) const override;
130 
131  // General Attributes
133  mutable bool mDirectoryIsTemporary;
138 
139  // Members required for loading elements from file
141 
142  // General Library Element Attributes
145  QString mAuthor;
146  QDateTime mCreated;
151 };
152 
153 /*******************************************************************************
154  * End of File
155  ******************************************************************************/
156 
157 } // namespace library
158 } // namespace librepcb
159 
160 #endif // LIBREPCB_LIBRARY_LIBRARYBASEELEMENT_H
void setNames(const LocalizedNameMap &names) noexcept
Definition: librarybaseelement.h:97
virtual LibraryElementCheckMessageList runChecks() const
Definition: librarybaseelement.cpp:180
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:95
const QString & getAuthor() const noexcept
Definition: librarybaseelement.h:83
const LocalizedDescriptionMap & getDescriptions() const noexcept
Definition: librarybaseelement.h:87
virtual ~LibraryBaseElement() noexcept
Definition: librarybaseelement.cpp:153
const QDateTime & getCreated() const noexcept
Definition: librarybaseelement.h:84
virtual void copyTo(const FilePath &destination, bool removeSource)
Definition: librarybaseelement.cpp:235
virtual void moveIntoParentDirectory(const FilePath &parentDir)
Definition: librarybaseelement.cpp:222
const LocalizedKeywordsMap & getKeywords() const noexcept
Definition: librarybaseelement.h:90
void setKeywords(const LocalizedKeywordsMap &keywords) noexcept
Definition: librarybaseelement.h:101
SExpression mLoadingFileDocument
Definition: librarybaseelement.h:140
bool mDirectoryNameMustBeUuid
Definition: librarybaseelement.h:135
virtual void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: librarybaseelement.cpp:292
QString mLongElementName
e.g. "library", "component_category", "symbol"
Definition: librarybaseelement.h:137
const FilePath & getFilePath() const noexcept
Definition: librarybaseelement.h:71
virtual void cleanupAfterLoadingElementFromFile() noexcept
Definition: librarybaseelement.cpp:231
virtual void saveIntoParentDirectory(const FilePath &parentDir)
Definition: librarybaseelement.cpp:212
bool mDirectoryIsTemporary
Definition: librarybaseelement.h:133
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
void setDescriptions(const LocalizedDescriptionMap &descriptions) noexcept
Definition: librarybaseelement.h:98
bool mIsDeprecated
Definition: librarybaseelement.h:147
LocalizedNameMap mNames
Definition: librarybaseelement.h:148
const QString & getLongElementName() const noexcept
Definition: librarybaseelement.h:75
void setDeprecated(bool deprecated) noexcept
Definition: librarybaseelement.h:96
The LibraryBaseElement class.
Definition: librarybaseelement.h:52
QDateTime mCreated
Definition: librarybaseelement.h:146
static bool isValidElementDirectory(const FilePath &dir) noexcept
Definition: librarybaseelement.h:118
virtual void moveTo(const FilePath &destination)
Definition: librarybaseelement.cpp:217
const Version & getVersion() const noexcept
Definition: librarybaseelement.h:82
QString mAuthor
Definition: librarybaseelement.h:145
virtual void saveTo(const FilePath &destination)
Definition: librarybaseelement.cpp:207
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
Uuid mUuid
Definition: librarybaseelement.h:143
bool isOpenedReadOnly() const noexcept
Definition: librarybaseelement.h:78
LocalizedDescriptionMap mDescriptions
Definition: librarybaseelement.h:149
virtual void save()
Definition: librarybaseelement.cpp:185
LibraryBaseElement & operator=(const LibraryBaseElement &rhs)=delete
Version mVersion
Definition: librarybaseelement.h:144
const QString & getShortElementName() const noexcept
Definition: librarybaseelement.h:72
QString mShortElementName
e.g. "lib", "cmpcat", "sym"
Definition: librarybaseelement.h:136
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
bool isDeprecated() const noexcept
Definition: librarybaseelement.h:85
const Uuid & getUuid() const noexcept
Definition: librarybaseelement.h:81
void setVersion(const Version &version) noexcept
Definition: librarybaseelement.h:94
const LocalizedNameMap & getNames() const noexcept
Definition: librarybaseelement.h:86
FilePath mDirectory
Definition: librarybaseelement.h:132
The SExpression class.
Definition: sexpression.h:60
QStringList getAllAvailableLocales() const noexcept
Definition: librarybaseelement.cpp:166
LocalizedKeywordsMap mKeywords
Definition: librarybaseelement.h:150
bool mOpenedReadOnly
Definition: librarybaseelement.h:134
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92