ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientSystemSettingModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_CLIENT_SYSTEM_SETTING_MODEL_HPP
21#define ORES_QT_CLIENT_SYSTEM_SETTING_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include <QAbstractTableModel>
26#include "ores.qt/AbstractClientModel.hpp"
27#include "ores.qt/ClientManager.hpp"
28#include "ores.qt/RecencyPulseManager.hpp"
29#include "ores.qt/RecencyTracker.hpp"
30#include "ores.logging/make_logger.hpp"
31#include "ores.variability.api/domain/system_setting.hpp"
32
33namespace ores::qt {
34
42 Q_OBJECT
43
44private:
45 inline static std::string_view logger_name =
46 "ores.qt.client_system_setting_model";
47
48 [[nodiscard]] static auto& lg() {
49 using namespace ores::logging;
50 static auto instance = make_logger(logger_name);
51 return instance;
52 }
53
54public:
58 enum Column {
59 Name,
60 Enabled,
61 Version,
62 ModifiedBy,
63 RecordedAt,
64 ColumnCount
65 };
66
67 explicit ClientSystemSettingModel(ClientManager* clientManager,
68 QObject* parent = nullptr);
69 ~ClientSystemSettingModel() override = default;
70
71 // QAbstractTableModel interface
72 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
73 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
74 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
75 QVariant headerData(int section, Qt::Orientation orientation,
76 int role = Qt::DisplayRole) const override;
77
81 void refresh();
82
90
91signals:
100private slots:
101 void onSystemSettingsLoaded();
102 void onPulseStateChanged(bool isOn);
103 void onPulsingComplete();
104
105private:
106 QVariant recency_foreground_color(const std::string& name) const;
107
108 struct FetchResult {
109 bool success;
110 std::vector<variability::domain::system_setting> flags;
111 QString error_message;
112 QString error_details;
113 };
114
115 ClientManager* clientManager_;
116 std::vector<variability::domain::system_setting> flags_;
117 QFutureWatcher<FetchResult>* watcher_;
118 bool is_fetching_{false};
119
120 using SystemSettingKeyExtractor = std::string(*)(const variability::domain::system_setting&);
121 RecencyTracker<variability::domain::system_setting, SystemSettingKeyExtractor> recencyTracker_;
122 RecencyPulseManager* pulseManager_;
123};
124
125}
126
127#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Model for displaying system settings fetched from the server.
Definition ClientSystemSettingModel.hpp:41
void refresh()
Refresh system setting data from server asynchronously.
Definition ClientSystemSettingModel.cpp:124
const variability::domain::system_setting * getSystemSetting(int row) const
Get system setting at the specified row.
Definition ClientSystemSettingModel.cpp:196
Column
Enumeration of table columns for type-safe column access.
Definition ClientSystemSettingModel.hpp:58
Represents a typed system setting in the domain layer.
Definition system_setting.hpp:35