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,
69  NEVER,
70  ASK,
71  };
72 
73  // Constructors / Destructor
74  WorkspaceSettings() = delete;
75  WorkspaceSettings(const WorkspaceSettings& other) = delete;
76  explicit WorkspaceSettings(const FilePath& fp, QObject* parent = nullptr);
77  ~WorkspaceSettings() noexcept;
78 
82  void restoreDefaults() noexcept;
83 
87  void saveToFile() const;
88 
89  // Operator Overloadings
90  WorkspaceSettings& operator=(const WorkspaceSettings& rhs) = delete;
91 
92 private: // Methods
98  QList<WorkspaceSettingsItem*> getAllItems() const noexcept;
99 
101  void serialize(SExpression& root) const override;
102 
103 private: // Data
105 
106 public:
107  // All settings item objects below, in the same order as they are safed in
108  // the settings file.
109  //
110  // Note: Generally we don't make member variables public, but in this case
111  // it would create a lot of boilerplate to wrap all objects with
112  // both const- and non-const methods, and it's totally safe to access
113  // them directly.
114 
123 
132 
139 
146 
153 
166 
175 
185 
192 
199 
206 };
207 
208 /*******************************************************************************
209  * End of File
210  ******************************************************************************/
211 
212 } // namespace workspace
213 
214 // Serialize settings values
215 template <>
218  using namespace workspace;
219  switch (b) {
221  return SExpression::createToken("always");
223  return SExpression::createToken("never");
225  return SExpression::createToken("ask");
226  default:
227  throw LogicError(__FILE__, __LINE__);
228  };
229 }
230 
231 template <>
233  const SExpression& sexpr, bool throwIfEmpty) {
234  using namespace workspace;
235  QString str = sexpr.getStringOrToken(throwIfEmpty);
236  if (str == QLatin1String("always"))
238  else if (str == QLatin1String("never"))
240  else if (str == QLatin1String("ask"))
242  else
243  throw RuntimeError(__FILE__, __LINE__, str);
244 }
245 
246 } // namespace librepcb
247 
248 #endif // LIBREPCB_WORKSPACESETTINGS_H
The LogicError class.
Definition: exceptions.h:179
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
FilePath mFilePath
path to the "settings.lp" file
Definition: workspacesettings.h:104
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:138
WorkspaceSettingsItem_GenericValue< QString > userName
User name.
Definition: workspacesettings.h:122
WorkspaceSettingsItem_GenericValue< QString > pdfReaderCommand
Custom command to open a PDF reader.
Definition: workspacesettings.h:198
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:278
WorkspaceSettingsItem_GenericValue< bool > useCustomPdfReader
Use a PDF Reader other than the system default.
Definition: workspacesettings.h:191
WorkspaceSettingsItem_GenericValueList< QList< QUrl > > repositoryUrls
The list of API repository URLs in the right order.
Definition: workspacesettings.h:184
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:165
WorkspaceSettingsItem_GenericValue< PdfOpenBehavior > pdfOpenBehavior
Behavior after a PDF has been exported.
Definition: workspacesettings.h:205
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:216
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:131
WorkspaceSettingsItem_GenericValue< bool > useOpenGl
Use OpenGL hardware acceleration.
Definition: workspacesettings.h:152
WorkspaceSettingsItem_GenericValue< uint > projectAutosaveIntervalSeconds
Project autosave interval [seconds] (0 = autosave disabled)
Definition: workspacesettings.h:145
WorkspaceSettingsItem_GenericValueList< QStringList > libraryNormOrder
Preferred library norms (like "DIN EN 81346") in the right order.
Definition: workspacesettings.h:174
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