ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientChangeReasonCategoryModel.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_CHANGE_REASON_CATEGORY_MODEL_HPP
21#define ORES_QT_CLIENT_CHANGE_REASON_CATEGORY_MODEL_HPP
22
23#include <vector>
24#include <QSize>
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
27#include "ores.qt/AbstractClientModel.hpp"
28#include "ores.qt/ClientManager.hpp"
29#include "ores.qt/ColumnMetadata.hpp"
30#include "ores.qt/RecencyPulseManager.hpp"
31#include "ores.qt/RecencyTracker.hpp"
32#include "ores.logging/make_logger.hpp"
33#include "ores.dq.api/domain/change_reason_category.hpp"
34
35namespace ores::qt {
36
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.client_change_reason_category_model";
49
50 [[nodiscard]] static auto& lg() {
51 using namespace ores::logging;
52 static auto instance = make_logger(logger_name);
53 return instance;
54 }
55
56public:
60 enum Column {
61 Code,
62 Description,
63 Version,
64 ModifiedBy,
65 RecordedAt,
66 ColumnCount
67 };
68
74 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
75 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
76 {
77 .column = Code,
78 .header = std::string_view("Code"),
80 .hidden_by_default = false,
81 .default_width = kColumnWidthAuto
82 },
83 {
84 .column = Description,
85 .header = std::string_view("Description"),
87 .hidden_by_default = false,
88 .default_width = kColumnWidthAuto
89 },
90 {
91 .column = Version,
92 .header = std::string_view("Version"),
94 .hidden_by_default = false,
95 .default_width = 70
96 },
97 {
98 .column = ModifiedBy,
99 .header = std::string_view("Modified By"),
101 .hidden_by_default = false,
102 .default_width = kColumnWidthAuto
103 },
104 {
105 .column = RecordedAt,
106 .header = std::string_view("Recorded At"),
108 .hidden_by_default = false,
109 .default_width = kColumnWidthAuto
110 }
111 }};
112
116 inline static const QSize kDefaultWindowSize = {900, 400};
117
121 static constexpr std::string_view kSettingsGroup = "ChangeReasonCategoryListWindow";
125 static std::vector<column_style> const& columnStyles() {
126 static std::vector<column_style> const kStylesVector = []() {
127 std::vector<column_style> result;
128 result.reserve(kColumnCount);
129 for (std::size_t i = 0; i < kColumnCount; ++i)
130 result.push_back(kColumns[i].style);
131 return result;
132 }();
133 return kStylesVector;
134 }
135
139 static QVector<int> defaultHiddenColumns() {
140 static QVector<int> const result =
141 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
142 return result;
143 }
144
145 explicit ClientChangeReasonCategoryModel(ClientManager* clientManager,
146 QObject* parent = nullptr);
147 ~ClientChangeReasonCategoryModel() override = default;
148
149 // QAbstractTableModel interface
150 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
151 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
152 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
153 QVariant headerData(int section, Qt::Orientation orientation,
154 int role = Qt::DisplayRole) const override;
155
159 void refresh();
160
168
169signals:
178private slots:
179 void onCategoriesLoaded();
180 void onPulseStateChanged(bool isOn);
181 void onPulsingComplete();
182
183private:
184 QVariant recency_foreground_color(const std::string& code) const;
185
186 struct FetchResult {
187 bool success;
188 std::vector<dq::domain::change_reason_category> categories;
189 QString error_message;
190 QString error_details;
191 };
192
193 ClientManager* clientManager_;
194 std::vector<dq::domain::change_reason_category> categories_;
195 QFutureWatcher<FetchResult>* watcher_;
196 bool is_fetching_{false};
197
198 // Recency highlighting
199 using ChangeReasonCategoryKeyExtractor = std::string(*)(const dq::domain::change_reason_category&);
200 RecencyTracker<dq::domain::change_reason_category, ChangeReasonCategoryKeyExtractor> recencyTracker_;
201 RecencyPulseManager* pulseManager_;
202};
203
204}
205
206#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
constexpr int kColumnWidthAuto
Sentinel value for column default width meaning "auto-size to contents".
Definition ColumnMetadata.hpp:37
@ mono_center
Monospace, centered.
@ text_left
Proportional font, left-aligned (default).
@ mono_left
Monospace, left-aligned.
Groups change reasons into logical categories.
Definition change_reason_category.hpp:46
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Model for displaying change reason categories fetched from the server.
Definition ClientChangeReasonCategoryModel.hpp:43
static constexpr std::string_view kSettingsGroup
Settings group name for persisting window and column state.
Definition ClientChangeReasonCategoryModel.hpp:121
const dq::domain::change_reason_category * getCategory(int row) const
Get category at the specified row.
Definition ClientChangeReasonCategoryModel.cpp:195
static constexpr std::size_t kColumnCount
Column metadata: header text, style, visibility, and width.
Definition ClientChangeReasonCategoryModel.hpp:74
static const QSize kDefaultWindowSize
Default window size for the change reason category list window.
Definition ClientChangeReasonCategoryModel.hpp:116
static std::vector< column_style > const & columnStyles()
Returns a static vector of column styles (built once per process).
Definition ClientChangeReasonCategoryModel.hpp:125
void refresh()
Refresh category data from server asynchronously.
Definition ClientChangeReasonCategoryModel.cpp:124
static QVector< int > defaultHiddenColumns()
Returns a static QVector of hidden column indices (built once per process).
Definition ClientChangeReasonCategoryModel.hpp:139
Column
Enumeration of table columns for type-safe column access.
Definition ClientChangeReasonCategoryModel.hpp:60
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109