SILICON
Loading...
Searching...
No Matches
siliconSettings.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <filesystem>
21#include <functional>
22#include <optional>
23
24#include <QSettings>
25#include <QString>
26#include <QStyleHints>
27#include <QVariant>
28
29#include <ui/shell/theme.hpp>
30
31Q_DECLARE_METATYPE(std::filesystem::path)
32
33namespace SILICON::ui {
34
35namespace settings {
36 inline constexpr auto LIGHT_THEME = "light";
37 inline constexpr auto DARK_THEME = "dark";
38
39 using DefaultProvider = std::function<std::optional<QVariant>()>;
43 struct Definition {
44 QString name;
45 DefaultProvider defaultProvider = [] { return std::nullopt; };
46 QVariant defaultValue;
47 std::optional<QString> help = std::nullopt;
48
49 [[nodiscard]] QVariant getResolvedDefault() const
50 {
51 return defaultProvider().value_or(defaultValue);
52 }
53 };
54
55 [[nodiscard]] inline std::optional<QVariant> systemThemeDefault()
56 {
57 switch (QGuiApplication::styleHints()->colorScheme()) {
58 case Qt::ColorScheme::Dark: return QString::fromLatin1(DARK_THEME);
59
60 case Qt::ColorScheme::Light: return QString::fromLatin1(LIGHT_THEME);
61
62 default:
63 return std::nullopt;
64 }
65
66 std::unreachable();
67 }
68
69 inline const Definition Theme = {
70 .name = QStringLiteral("ui/theme"),
71 .defaultProvider = systemThemeDefault,
72 .defaultValue = QString::fromLatin1(LIGHT_THEME),
73 };
74
76 .name = QStringLiteral("simulation/maxSteps"),
77 .defaultValue = 100000,
78 .help = QStringLiteral("Maximum number of simulation steps before stopping a run."),
79 };
80
82 .name = QStringLiteral("simulation/maxTransitionsPerDeltaCycle"),
83 .defaultValue = 1000,
84 .help = QStringLiteral(
85 "Maximum number of signal transitions allowed within one delta cycle."),
86 };
87
94 [[nodiscard]] QVariant value(const QSettings& settings, const Definition& setting);
95} // namespace settings
96
106
110class SiliconSettings : public QSettings {
111public:
117 explicit SiliconSettings(const QString& appName, QObject* parent = nullptr);
118
123 [[nodiscard]] static QSettings::Format format();
124};
125
131[[nodiscard]] CommonSettingsValues readCommonSettings(const QSettings& settings);
132
138[[nodiscard]] SILICON::ui::theme::Mode themeModeFromText(const QString& value);
139
140} // namespace SILICON::ui
SiliconSettings(const QString &appName, QObject *parent=nullptr)
Opens the user-scoped settings store for a SILICON application.
static QSettings::Format format()
Returns the registered TOML-backed settings format.
std::optional< QVariant > systemThemeDefault()
std::function< std::optional< QVariant >()> DefaultProvider
QVariant value(const QSettings &settings, const Definition &setting)
Reads a setting value, falling back to its declared default when unset.
const Definition MaxSimulationSteps
const Definition MaxTransitionsPerDeltaCycle
SILICON::ui::theme::Mode themeModeFromText(const QString &value)
Converts a persisted theme string into a theme engine mode.
CommonSettingsValues readCommonSettings(const QSettings &settings)
Reads the common UI and simulation settings into a typed snapshot.
Snapshot of the common application settings used at runtime.
Describes a persisted setting entry.