src/settings.h

Thu, 15 Jun 2023 16:18:03 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Thu, 15 Jun 2023 16:18:03 +0300
changeset 383
530d23cd4e97
parent 356
65b4741b302d
permissions
-rw-r--r--

Refactor, make selecting elements from the model select the corresponding line from the editor as well

218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
1 #ifndef SETTINGS_H
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
2 #define SETTINGS_H
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
3 #include <QSettings>
221
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
4 #include <QMdiArea>
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
5 #include "src/libraries.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
6 #include "src/gl/common.h"
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
7
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
8 template<class>
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
9 struct SettingInfo{};
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
10
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
11 #define SETTING(NAME, DEFVALUE) \
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
12 namespace Setting { class NAME; } \
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
13 template<> \
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
14 struct SettingInfo<Setting::NAME> \
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
15 { \
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
16 using type = decltype((DEFVALUE)); \
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
17 static constexpr char name[] = #NAME; \
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
18 static const auto& defaultValue() { \
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
19 static const auto value = DEFVALUE; \
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
20 return value; \
250
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 240
diff changeset
21 } \
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
22 };
221
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
23
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
24 // -----------------------------------------------------------------------------
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
25 // Setting definitions
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
26
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
27 Q_DECLARE_METATYPE(QMdiArea::ViewMode)
335
c5830bce1c23 Fix crashing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
28 Q_DECLARE_METATYPE(Qt::ToolButtonStyle)
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
29
221
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
30 // Rendering options
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
31 SETTING(BackgroundColor, (QColor{48, 48, 48}))
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
32 SETTING(MainColor, (QColor{255, 255, 64}))
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
33 SETTING(SelectedColor, (QColor{32, 32, 224}))
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
34 SETTING(LineThickness, 2.0f)
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
35 SETTING(LineAntiAliasing, true)
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
36 SETTING(RenderStyle, gl::RenderStyle::Normal)
231
a9bf6bab5ea2 Add wireframe button
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 224
diff changeset
37 SETTING(Wireframe, false)
221
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
38 SETTING(DrawAxes, true)
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
39 SETTING(MainWindowGeometry, QByteArray{})
240
414d392b9ae6 some improvements to dock widget handling
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
40 SETTING(MainWindowState, QByteArray{})
221
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
41 SETTING(MainSplitterState, QByteArray{})
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
42 SETTING(RecentFiles, QStringList{})
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
43 SETTING(ViewMode, QMdiArea::TabbedView)
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 233
diff changeset
44 SETTING(LogOpenGLDebugMessages, false)
335
c5830bce1c23 Fix crashing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 296
diff changeset
45 SETTING(ToolButtonStyle, Qt::ToolButtonFollowStyle)
221
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
46
356
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 335
diff changeset
47 // Code editor options
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 335
diff changeset
48 SETTING(CodeEditorUseSystemFont, bool{true})
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 335
diff changeset
49 SETTING(CodeEditorFontFamily, QString{""})
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 335
diff changeset
50 SETTING(CodeEditorFontSize, int{10})
65b4741b302d Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 335
diff changeset
51
221
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
52 // File management options
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
53 SETTING(Libraries, Libraries{})
221
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
54
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
55 // End of setting definitions
e28f89b8ccdf simplify settings further
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 220
diff changeset
56 // -----------------------------------------------------------------------------
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
57 #undef SETTING
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
58
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
59 template<class X>
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
60 using SettingType_t = typename SettingInfo<X>::type;
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
61 static_assert(std::is_same_v<SettingType_t<Setting::DrawAxes>, bool>);
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
62
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
63 template<class X>
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
64 const char* settingName = SettingInfo<X>::name;
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
65
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
66 template<class X>
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
67 inline auto settingDefaultValue()
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
68 {
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
69 return SettingInfo<X>::defaultValue();
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
70 }
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
71
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
72 // get() - get setting by enumerator
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
73 template<class X>
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
74 inline SettingType_t<X> setting()
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
75 {
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
76 static const QVariant defvariant = QVariant::fromValue(settingDefaultValue<X>());
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
77 const QVariant var = QSettings{}.value(settingName<X>, defvariant);
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
78 return var.value<SettingType_t<X>>();
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
79 }
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
80
219
571e85c0d811 fix comment
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
81 // setSetting() - set value of setting
233
5509bec02c81 fix various things
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 231
diff changeset
82 template<class X>
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
83 inline void setSetting(const SettingType_t<X>& value)
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
84 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
85 if (false/*value == settingDefaultValue<X>()*/) {
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
86 QSettings{}.remove(settingName<X>);
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
87 }
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
88 else {
220
a6d937f8c0ac Further reduce settings.h
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 219
diff changeset
89 QSettings{}.setValue(settingName<X>, QVariant::fromValue(value));
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
90 }
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
91 }
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
92
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
93 #endif // SETTINGS_H

mercurial