Sat, 08 Apr 2023 12:55:11 +0300
Fix BFC formatting not working due to being evaluated after comment format
#ifndef SETTINGS_H #define SETTINGS_H #include <QSettings> #include <QMdiArea> #include "src/libraries.h" #include "src/gl/common.h" template<class> struct SettingInfo{}; #define SETTING(NAME, DEFVALUE) \ namespace Setting { class NAME; } \ template<> \ struct SettingInfo<Setting::NAME> \ { \ using type = decltype((DEFVALUE)); \ static constexpr char name[] = #NAME; \ static const auto& defaultValue() { \ static const auto value = DEFVALUE; \ return value; \ } \ }; // ----------------------------------------------------------------------------- // Setting definitions Q_DECLARE_METATYPE(QMdiArea::ViewMode) Q_DECLARE_METATYPE(Qt::ToolButtonStyle) // Rendering options 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(Wireframe, false) SETTING(DrawAxes, true) SETTING(MainWindowGeometry, QByteArray{}) SETTING(MainWindowState, QByteArray{}) SETTING(MainSplitterState, QByteArray{}) SETTING(RecentFiles, QStringList{}) SETTING(ViewMode, QMdiArea::TabbedView) SETTING(LogOpenGLDebugMessages, false) SETTING(ToolButtonStyle, Qt::ToolButtonFollowStyle) // File management options SETTING(Libraries, Libraries{}) // End of setting definitions // ----------------------------------------------------------------------------- #undef SETTING template<class X> using SettingType_t = typename SettingInfo<X>::type; static_assert(std::is_same_v<SettingType_t<Setting::DrawAxes>, bool>); template<class X> const char* settingName = SettingInfo<X>::name; template<class X> inline auto settingDefaultValue() { return SettingInfo<X>::defaultValue(); } // get() - get setting by enumerator template<class X> inline SettingType_t<X> setting() { static const QVariant defvariant = QVariant::fromValue(settingDefaultValue<X>()); const QVariant var = QSettings{}.value(settingName<X>, defvariant); return var.value<SettingType_t<X>>(); } // setSetting() - set value of setting template<class X> inline void setSetting(const SettingType_t<X>& value) { if (false/*value == settingDefaultValue<X>()*/) { QSettings{}.remove(settingName<X>); } else { QSettings{}.setValue(settingName<X>, QVariant::fromValue(value)); } } #endif // SETTINGS_H