LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
projectmetadata.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_PROJECT_PROJECTMETADATA_H
21 #define LIBREPCB_PROJECT_PROJECTMETADATA_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
30 
31 #include <QtCore>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 class SmartSExprFile;
39 
40 namespace project {
41 
42 class Project;
43 
44 /*******************************************************************************
45  * Class ProjectMetadata
46  ******************************************************************************/
47 
54 class ProjectMetadata final : public QObject, public SerializableObject {
55  Q_OBJECT
56 
57 public:
58  // Constructors / Destructor
59  ProjectMetadata() = delete;
60  ProjectMetadata(const ProjectMetadata& other) = delete;
61  ProjectMetadata(Project& project, bool restore, bool readOnly, bool create);
62  ~ProjectMetadata() noexcept;
63 
64  // Getters
65  Project& getProject() const noexcept { return mProject; }
66  const Uuid& getUuid() const noexcept { return mUuid; }
67 
73  const ElementName& getName() const noexcept { return mName; }
74 
80  const QString& getAuthor() const noexcept { return mAuthor; }
81 
87  const QString& getVersion() const noexcept { return mVersion; }
88 
94  const QDateTime& getCreated() const noexcept { return mCreated; }
95 
104  const QDateTime& getLastModified() const noexcept { return mLastModified; }
105 
111  const AttributeList& getAttributes() const noexcept { return mAttributes; }
112 
113  // Setters
114 
122  void setName(const ElementName& newName) noexcept;
123 
131  void setAuthor(const QString& newAuthor) noexcept;
132 
140  void setVersion(const QString& newVersion) noexcept;
141 
149  void setAttributes(const AttributeList& newAttributes) noexcept;
150 
154  void updateLastModified() noexcept;
155 
156  // General Methods
157  bool save(bool toOriginal, QStringList& errors) noexcept;
158 
159  // Operator Overloadings
160  ProjectMetadata& operator=(const ProjectMetadata& rhs) = delete;
161 
162 signals:
163  void attributesChanged();
164 
165 private: // Methods
167  void serialize(SExpression& root) const override;
168 
169 private: // Data
170  // General
172 
173  // File "project/metadata.lp"
175  QScopedPointer<SmartSExprFile> mFile;
176 
177  // Metadata
180  QString mAuthor;
181  QString mVersion;
182  QDateTime mCreated;
183  QDateTime mLastModified;
185 };
186 
187 /*******************************************************************************
188  * End of File
189  ******************************************************************************/
190 
191 } // namespace project
192 } // namespace librepcb
193 
194 #endif // LIBREPCB_PROJECT_PROJECTMETADATA_H
const QString & getAuthor() const noexcept
Get the author of the project.
Definition: projectmetadata.h:80
void setAuthor(const QString &newAuthor) noexcept
Set the author of the project.
Definition: projectmetadata.cpp:97
const QString & getVersion() const noexcept
Get the version of the project.
Definition: projectmetadata.h:87
void setName(const ElementName &newName) noexcept
Set the name of the project.
Definition: projectmetadata.cpp:90
Project & getProject() const noexcept
Definition: projectmetadata.h:65
The Project class represents a whole (opened) project with all its content.
Definition: project.h:84
bool save(bool toOriginal, QStringList &errors) noexcept
Definition: projectmetadata.cpp:128
The ProjectMetadata class.
Definition: projectmetadata.h:54
ElementName mName
the name of the project
Definition: projectmetadata.h:179
QString mAuthor
the author of the project
Definition: projectmetadata.h:180
AttributeList mAttributes
all attributes in a specific order
Definition: projectmetadata.h:184
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
const QDateTime & getCreated() const noexcept
Get the date and time when the project was created.
Definition: projectmetadata.h:94
void setVersion(const QString &newVersion) noexcept
Set the version of the project.
Definition: projectmetadata.cpp:104
Project & mProject
a reference to the Project object (from the ctor)
Definition: projectmetadata.h:171
The SmartSExprFile class represents an S-Expressions file and provides methods to load/save DOM trees...
Definition: smartsexprfile.h:56
const QDateTime & getLastModified() const noexcept
Get the date and time when the project was last modified.
Definition: projectmetadata.h:104
void setAttributes(const AttributeList &newAttributes) noexcept
Set all project attributes.
Definition: projectmetadata.cpp:111
QDateTime mLastModified
the datetime of the last project modification
Definition: projectmetadata.h:183
QDateTime mCreated
the datetime of the project creation
Definition: projectmetadata.h:182
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: projectmetadata.cpp:146
void updateLastModified() noexcept
Update the last modified datetime.
Definition: projectmetadata.cpp:119
FilePath mFilepath
Definition: projectmetadata.h:174
QString mVersion
the version of the project (arbitrary string)
Definition: projectmetadata.h:181
QScopedPointer< SmartSExprFile > mFile
Definition: projectmetadata.h:175
const AttributeList & getAttributes() const noexcept
Get the list of attributes.
Definition: projectmetadata.h:111
Uuid mUuid
the UUID of the project
Definition: projectmetadata.h:178
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
const ElementName & getName() const noexcept
Get the name of the project.
Definition: projectmetadata.h:73
~ProjectMetadata() noexcept
Definition: projectmetadata.cpp:83
The SExpression class.
Definition: sexpression.h:60
const Uuid & getUuid() const noexcept
Definition: projectmetadata.h:66
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92