LibrePCB Developers Documentation
workspacesettingsitem_genericvalue.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_GENERICVALUE_H
21#define LIBREPCB_CORE_WORKSPACESETTINGSITEM_GENERICVALUE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
27
28#include <QtCore>
29
30/*******************************************************************************
31 * Namespace / Forward Declarations
32 ******************************************************************************/
33namespace librepcb {
34
35/*******************************************************************************
36 * Class WorkspaceSettingsItem_GenericValue
37 ******************************************************************************/
38
43template <typename T>
45public:
46 // Constructors / Destructor
49 const WorkspaceSettingsItem_GenericValue& other) = delete;
51 const QString& key, const T& defaultValue,
52 QObject* parent = nullptr) noexcept
53 : WorkspaceSettingsItem(key, parent),
54 mDefaultValue(defaultValue),
55 mCurrentValue(defaultValue) {}
57
63 const T& get() const noexcept { return mCurrentValue; }
64
70 void set(const T& value) noexcept {
71 if (value != mCurrentValue) {
72 mCurrentValue = value;
74 }
75 }
76
82 const T& getDefault() const noexcept { return mDefaultValue; }
83
84 // Operator Overloadings
86 const WorkspaceSettingsItem_GenericValue& rhs) = delete;
87
88private: // Methods
92 virtual void restoreDefaultImpl() noexcept override { set(mDefaultValue); }
93
97 void loadImpl(const SExpression& root) override {
98 set(deserialize<T>(root.getChild("@0"))); // can throw
99 }
100
104 void serializeImpl(SExpression& root) const override {
106 }
107
108private:
111};
112
113/*******************************************************************************
114 * End of File
115 ******************************************************************************/
116
117} // namespace librepcb
118
119#endif
The SExpression class.
Definition: sexpression.h:69
SExpression & getChild(int index)
Definition: sexpression.cpp:86
void appendChild(std::unique_ptr< SExpression > child)
Definition: sexpression.cpp:217
Generic implementation of librepcb::WorkspaceSettingsItem for simple, value-type settings.
Definition: workspacesettingsitem_genericvalue.h:44
void loadImpl(const SExpression &root) override
Load value from S-Expression node.
Definition: workspacesettingsitem_genericvalue.h:97
T mCurrentValue
Current value.
Definition: workspacesettingsitem_genericvalue.h:110
WorkspaceSettingsItem_GenericValue(const WorkspaceSettingsItem_GenericValue &other)=delete
WorkspaceSettingsItem_GenericValue(const QString &key, const T &defaultValue, QObject *parent=nullptr) noexcept
Definition: workspacesettingsitem_genericvalue.h:50
void set(const T &value) noexcept
Set the value.
Definition: workspacesettingsitem_genericvalue.h:70
T mDefaultValue
Initial, default value.
Definition: workspacesettingsitem_genericvalue.h:109
~WorkspaceSettingsItem_GenericValue() noexcept
Definition: workspacesettingsitem_genericvalue.h:56
WorkspaceSettingsItem_GenericValue & operator=(const WorkspaceSettingsItem_GenericValue &rhs)=delete
void serializeImpl(SExpression &root) const override
Serialize the value into S-Expression node.
Definition: workspacesettingsitem_genericvalue.h:104
const T & getDefault() const noexcept
Get the default value.
Definition: workspacesettingsitem_genericvalue.h:82
const T & get() const noexcept
Get the current value.
Definition: workspacesettingsitem_genericvalue.h:63
virtual void restoreDefaultImpl() noexcept override
Restore default value.
Definition: workspacesettingsitem_genericvalue.h:92
Base class for all workspace settings items.
Definition: workspacesettingsitem.h:49
void valueModified() noexcept
Definition: workspacesettingsitem.cpp:48
Definition: occmodel.cpp:77