LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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 ******************************************************************************/
33namespace librepcb {
34
35/*******************************************************************************
36 * Class WorkspaceSettingsItem
37 ******************************************************************************/
38
49class WorkspaceSettingsItem : public QObject {
50 Q_OBJECT
51
52public:
53 // Constructors / Destructor
55 explicit WorkspaceSettingsItem(const QString& key,
56 QObject* parent = nullptr) noexcept;
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
103 WorkspaceSettingsItem& operator=(const WorkspaceSettingsItem& rhs) = delete;
104
105signals:
109 void edited();
110
111protected:
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
142private:
143 QString mKey;
145 mutable bool mEdited;
146};
147
148/*******************************************************************************
149 * End of File
150 ******************************************************************************/
151
152} // namespace librepcb
153
154#endif
The SExpression class.
Definition sexpression.h:69
Base class for all workspace settings items.
Definition workspacesettingsitem.h:49
const QString & getKey() const noexcept
Get the setting key used for serialization.
Definition workspacesettingsitem.h:65
void edited()
Signal to notify about changes of the settings value.
bool isEdited() const noexcept
Check whether this setting was edited sinc the last load or save.
Definition workspacesettingsitem.h:81
virtual void serializeImpl(SExpression &root) const =0
Serialize the value into S-Expression node.
void load(const SExpression &root)
Load value from S-Expression file.
Definition workspacesettingsitem.cpp:60
bool mEdited
Edited since last load or save.
Definition workspacesettingsitem.h:145
void restoreDefault() noexcept
Restore default value.
Definition workspacesettingsitem.cpp:54
virtual void restoreDefaultImpl() noexcept=0
Restore default value.
bool mIsDefault
Setting is at default value.
Definition workspacesettingsitem.h:144
void serialize(SExpression &root) const
Serialize the value into S-Expression nodes.
Definition workspacesettingsitem.cpp:66
QString mKey
Key used for serialization.
Definition workspacesettingsitem.h:143
bool isDefaultValue() const noexcept
Check whether this setting is at its default value (not modified)
Definition workspacesettingsitem.h:73
void valueModified() noexcept
Definition workspacesettingsitem.cpp:48
virtual void loadImpl(const SExpression &root)=0
Load value from S-Expression node.
Definition occmodel.cpp:76