LibrePCB Developers Documentation
workspacesettingsitem.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_WORKSPACESETTINGSITEM_H
21 #define LIBREPCB_CORE_WORKSPACESETTINGSITEM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../serialization/sexpression.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 /*******************************************************************************
36  * Class WorkspaceSettingsItem
37  ******************************************************************************/
38 
49 class WorkspaceSettingsItem : public QObject {
50  Q_OBJECT
51 
52 public:
53  // Constructors / Destructor
54  WorkspaceSettingsItem() = delete;
55  explicit WorkspaceSettingsItem(const QString& key,
56  QObject* parent = nullptr) noexcept;
57  WorkspaceSettingsItem(const WorkspaceSettingsItem& other) = delete;
58  virtual ~WorkspaceSettingsItem() noexcept;
59 
65  const QString& getKey() const noexcept { return mKey; }
66 
73  bool isDefaultValue() const noexcept { return mIsDefault; }
74 
81  bool isEdited() const noexcept { return mEdited; }
82 
86  void restoreDefault() noexcept;
87 
93  void load(const SExpression& root);
94 
100  void serialize(SExpression& root) const;
101 
102  // Operator Overloadings
104 
105 signals:
109  void edited();
110 
111 protected:
112  void valueModified() noexcept;
113 
120  virtual void restoreDefaultImpl() noexcept = 0;
121 
133  virtual void loadImpl(const SExpression& root) = 0;
134 
140  virtual void serializeImpl(SExpression& root) const = 0;
141 
142 private:
143  QString mKey;
144  bool mIsDefault;
145  mutable bool mEdited;
146 };
147 
148 /*******************************************************************************
149  * End of File
150  ******************************************************************************/
151 
152 } // namespace librepcb
153 
154 #endif
virtual void loadImpl(const SExpression &root)=0
Load value from S-Expression node.
void serialize(SExpression &root) const
Serialize the value into S-Expression nodes.
Definition: workspacesettingsitem.cpp:66
virtual void restoreDefaultImpl() noexcept=0
Restore default value.
WorkspaceSettingsItem & operator=(const WorkspaceSettingsItem &rhs)=delete
Definition: occmodel.cpp:77
bool mIsDefault
Setting is at default value.
Definition: workspacesettingsitem.h:144
void valueModified() noexcept
Definition: workspacesettingsitem.cpp:48
bool isDefaultValue() const noexcept
Check whether this setting is at its default value (not modified)
Definition: workspacesettingsitem.h:73
void load(const SExpression &root)
Load value from S-Expression file.
Definition: workspacesettingsitem.cpp:60
bool isEdited() const noexcept
Check whether this setting was edited sinc the last load or save.
Definition: workspacesettingsitem.h:81
void restoreDefault() noexcept
Restore default value.
Definition: workspacesettingsitem.cpp:54
void edited()
Signal to notify about changes of the settings value.
Base class for all workspace settings items.
Definition: workspacesettingsitem.h:49
virtual ~WorkspaceSettingsItem() noexcept
Definition: workspacesettingsitem.cpp:41
virtual void serializeImpl(SExpression &root) const =0
Serialize the value into S-Expression node.
bool mEdited
Edited since last load or save.
Definition: workspacesettingsitem.h:145
QString mKey
Key used for serialization.
Definition: workspacesettingsitem.h:143
const QString & getKey() const noexcept
Get the setting key used for serialization.
Definition: workspacesettingsitem.h:65
The SExpression class.
Definition: sexpression.h:69