simplify settings further

Tue, 14 Jun 2022 22:31:39 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 14 Jun 2022 22:31:39 +0300
changeset 221
e28f89b8ccdf
parent 220
a6d937f8c0ac
child 222
72b456f2f3c2

simplify settings further

CMakeLists.txt file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/settingdefs.h file | annotate | diff | comparison | revisions
src/settings.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Tue Jun 14 20:44:07 2022 +0300
+++ b/CMakeLists.txt	Tue Jun 14 22:31:39 2022 +0300
@@ -71,7 +71,6 @@
 	src/polygoncache.h
 	src/ring.h
 	src/settings.h
-	src/settingdefs.h
 	src/typeconversions.h
 	src/uiutilities.h
 	src/version.h
--- a/src/main.cpp	Tue Jun 14 20:44:07 2022 +0300
+++ b/src/main.cpp	Tue Jun 14 22:31:39 2022 +0300
@@ -342,7 +342,6 @@
 		setSetting<Setting::RecentFiles>(recentlyOpenedFiles);
 		setSetting<Setting::RenderStyle>(renderPreferences.style);
 		setSetting<Setting::DrawAxes>(renderPreferences.drawAxes);
-		setSetting<Setting::DrawAxes>("hello world");
 		libraries.storeToSettings();
 	};
 	const auto updateRecentlyOpenedDocumentsMenu = [&]{
--- a/src/settingdefs.h	Tue Jun 14 20:44:07 2022 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-#include <QMdiArea>
-#include "libraries.h"
-#include "gl/common.h"
-
-#ifndef SETTING
-enum class Setting {
-# define SETTING(NAME, DEFVALUE) NAME,
-# define AUTOMATIC_SETTINGS_DEF
-#endif
-
-// Rendering options
-SETTING(Locale, QString{"system"})
-SETTING(BackgroundColor, (QColor{48, 48, 48}))
-SETTING(MainColor, (QColor{255, 255, 64}))
-SETTING(SelectedColor, (QColor{32, 32, 224}))
-SETTING(LineThickness, 2.0f)
-SETTING(LineAntiAliasing, true)
-SETTING(RenderStyle, gl::RenderStyle::Normal)
-SETTING(DrawWireframe, false)
-SETTING(DrawAxes, true)
-SETTING(MainWindowGeometry, QByteArray{})
-SETTING(MainSplitterState, QByteArray{})
-SETTING(RecentFiles, QStringList{})
-SETTING(ViewMode, QMdiArea::TabbedView)
-
-// File management options
-SETTING(Libraries, QVector<Library>{})
-
-#ifdef AUTOMATIC_SETTINGS_DEF
-};
-# undef SETTING
-# undef AUTOMATIC_SETTINGS_DEF
-#endif
--- a/src/settings.h	Tue Jun 14 20:44:07 2022 +0300
+++ b/src/settings.h	Tue Jun 14 22:31:39 2022 +0300
@@ -1,13 +1,20 @@
 #ifndef SETTINGS_H
 #define SETTINGS_H
 #include <QSettings>
-#include "settingdefs.h"
+#include <QMdiArea>
+#include "libraries.h"
+#include "gl/common.h"
 
 // SettingType - get type of setting by enumerator
-template<Setting>
+template<typename>
+struct SettingId{};
+
+template<SettingId>
 struct SettingInfo{};
 
 #define SETTING(NAME, DEFVALUE) \
+	namespace SettingIdTypes { class NAME; } \
+	namespace Setting { constexpr SettingId<class NAME##_SettingType> NAME; } \
 	template<> \
 	struct SettingInfo<Setting::NAME> \
 	{ \
@@ -18,24 +25,47 @@
 			return value; \
 		}; \
 	};
-#include "settingdefs.h"
+
+// -----------------------------------------------------------------------------
+// Setting definitions
+
+// Rendering options
+SETTING(Locale, QStringLiteral("system"))
+SETTING(BackgroundColor, (QColor{48, 48, 48}))
+SETTING(MainColor, (QColor{255, 255, 64}))
+SETTING(SelectedColor, (QColor{32, 32, 224}))
+SETTING(LineThickness, 2.0f)
+SETTING(LineAntiAliasing, true)
+SETTING(RenderStyle, gl::RenderStyle::Normal)
+SETTING(DrawWireframe, false)
+SETTING(DrawAxes, true)
+SETTING(MainWindowGeometry, QByteArray{})
+SETTING(MainSplitterState, QByteArray{})
+SETTING(RecentFiles, QStringList{})
+SETTING(ViewMode, QMdiArea::TabbedView)
+
+// File management options
+SETTING(Libraries, QVector<Library>{})
+
+// End of setting definitions
+// -----------------------------------------------------------------------------
 #undef SETTING
 
-template<Setting X>
+template<SettingId X>
 using SettingType_t = typename SettingInfo<X>::type;
 static_assert(std::is_same_v<SettingType_t<Setting::DrawAxes>, bool>);
 
-template<Setting X>
+template<SettingId X>
 const char* settingName = SettingInfo<X>::name;
 
-template<Setting X>
+template<SettingId X>
 inline auto settingDefaultValue()
 {
 	return SettingInfo<X>::defaultValue();
 }
 
 // get() - get setting by enumerator
-template<Setting X>
+template<SettingId X>
 inline SettingType_t<X> setting()
 {
 	static const QVariant defvariant = QVariant::fromValue(settingDefaultValue<X>());
@@ -44,7 +74,7 @@
 }
 
 // setSetting() - set value of setting
-template<Setting X>
+template<SettingId X>
 inline void setSetting(const SettingType_t<X>& value)
 {
 	if (value == settingDefaultValue<X>()) {

mercurial