LibrePCB Developers Documentation
workspacesettings.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_WORKSPACESETTINGS_H
21 #define LIBREPCB_WORKSPACESETTINGS_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
28 
32 
33 #include <QtCore>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 namespace workspace {
40 
41 /*******************************************************************************
42  * Class WorkspaceSettings
43  ******************************************************************************/
44 
58 class WorkspaceSettings final : public QObject, public SerializableObject {
59  Q_OBJECT
60 
61 public:
62  // Enums for n-state settings
63 
65  // The underlying type int is needed to map QButtonGroup IDs
66  // to values in this enum. See for ex. WorkspaceSettingsDialog::loadSettings()
67  enum class PdfOpenBehavior : int {
68  ALWAYS, NEVER, ASK,
69  };
70 
71  // Constructors / Destructor
72  WorkspaceSettings() = delete;
73  WorkspaceSettings(const WorkspaceSettings& other) = delete;
74  explicit WorkspaceSettings(const FilePath& fp, QObject* parent = nullptr);
75  ~WorkspaceSettings() noexcept;
76 
80  void restoreDefaults() noexcept;
81 
85  void saveToFile() const;
86 
87  // Operator Overloadings
88  WorkspaceSettings& operator=(const WorkspaceSettings& rhs) = delete;
89 
90 private: // Methods
96  QList<WorkspaceSettingsItem*> getAllItems() const noexcept;
97 
99  void serialize(SExpression& root) const override;
100 
101 private: // Data
103 
104 public:
105  // All settings item objects below, in the same order as they are safed in
106  // the settings file.
107  //
108  // Note: Generally we don't make member variables public, but in this case
109  // it would create a lot of boilerplate to wrap all objects with
110  // both const- and non-const methods, and it's totally safe to access
111  // them directly.
112 
121 
130 
137 
144 
151 
164 
173 
183 
190 
197 
204 };
205 
206 /*******************************************************************************
207  * End of File
208  ******************************************************************************/
209 
210 } // namespace workspace
211 
212 // Serialize settings values
213 template<>
216  using namespace workspace;
217  switch (b) {
219  return SExpression::createToken("always");
221  return SExpression::createToken("never");
223  return SExpression::createToken("ask");
224  default:
225  throw LogicError(__FILE__, __LINE__);
226  };
227 }
228 
229 template<>
231  deserializeFromSExpression(const SExpression& sexpr, bool throwIfEmpty) {
232 
233  using namespace workspace;
234  QString str = sexpr.getStringOrToken(throwIfEmpty);
235  if (str == QLatin1String("always"))
237  else if (str == QLatin1String("never"))
239  else if (str == QLatin1String("ask"))
241  else
242  throw RuntimeError(__FILE__, __LINE__, str);
243 }
244 
245 } // namespace librepcb
246 
247 #endif // LIBREPCB_WORKSPACESETTINGS_H
The LogicError class.
Definition: exceptions.h:182
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
FilePath mFilePath
path to the "settings.lp" file
Definition: workspacesettings.h:102
Definition: airwiresbuilder.cpp:32
QList< WorkspaceSettingsItem * > getAllItems() const noexcept
Get all librepcb::workspace::WorkspaceSettingsItem objects.
Definition: workspacesettings.cpp:97
WorkspaceSettingsItem_GenericValue< LengthUnit > defaultLengthUnit
The application&#39;s default length unit.
Definition: workspacesettings.h:136
WorkspaceSettingsItem_GenericValue< QString > userName
User name.
Definition: workspacesettings.h:120
WorkspaceSettingsItem_GenericValue< QString > pdfReaderCommand
Custom command to open a PDF reader.
Definition: workspacesettings.h:196
WorkspaceSettings & operator=(const WorkspaceSettings &rhs)=delete
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:76
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:90
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:280
WorkspaceSettingsItem_GenericValue< bool > useCustomPdfReader
Use a PDF Reader other than the system default.
Definition: workspacesettings.h:189
WorkspaceSettingsItem_GenericValueList< QList< QUrl > > repositoryUrls
The list of API repository URLs in the right order.
Definition: workspacesettings.h:182
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: workspacesettings.cpp:101
WorkspaceSettingsItem_GenericValueList< QStringList > libraryLocaleOrder
Preferred library locales (like "de_CH") in the right order.
Definition: workspacesettings.h:163
WorkspaceSettingsItem_GenericValue< PdfOpenBehavior > pdfOpenBehavior
Behavior after a PDF has been exported.
Definition: workspacesettings.h:203
PdfOpenBehavior
Definition: workspacesettings.h:67
void restoreDefaults() noexcept
Reset all settings to their default value.
Definition: workspacesettings.cpp:82
The RuntimeError class.
Definition: exceptions.h:219
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
WorkspaceSettingsItem_GenericValue< QString > applicationLocale
The application&#39;s locale (e.g. "en_US")
Definition: workspacesettings.h:129
WorkspaceSettingsItem_GenericValue< bool > useOpenGl
Use OpenGL hardware acceleration.
Definition: workspacesettings.h:150
WorkspaceSettingsItem_GenericValue< uint > projectAutosaveIntervalSeconds
Project autosave interval [seconds] (0 = autosave disabled)
Definition: workspacesettings.h:143
WorkspaceSettingsItem_GenericValueList< QStringList > libraryNormOrder
Preferred library norms (like "DIN EN 81346") in the right order.
Definition: workspacesettings.h:172
Container for all workspace related settings.
Definition: workspacesettings.h:58
The SExpression class.
Definition: sexpression.h:57
~WorkspaceSettings() noexcept
Definition: workspacesettings.cpp:75
void saveToFile() const
Save all settings to the file.
Definition: workspacesettings.cpp:88