ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientBookStatusModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 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_BOOK_STATUS_MODEL_HPP
21#define ORES_QT_CLIENT_BOOK_STATUS_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.refdata.api/domain/book_status.hpp"
34
35namespace ores::qt {
36
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.client_book_status_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 Name,
63 Description,
64 DisplayOrder,
65 Version,
66 ModifiedBy,
67 RecordedAt,
68 ColumnCount
69 };
70
76 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
77 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
78 {
79 .column = Code,
80 .header = std::string_view("Code"),
82 .hidden_by_default = false,
83 .default_width = kColumnWidthAuto
84 },
85 {
86 .column = Name,
87 .header = std::string_view("Name"),
89 .hidden_by_default = false,
90 .default_width = kColumnWidthAuto
91 },
92 {
93 .column = Description,
94 .header = std::string_view("Description"),
96 .hidden_by_default = false,
97 .default_width = kColumnWidthAuto
98 },
99 {
100 .column = DisplayOrder,
101 .header = std::string_view("Display Order"),
103 .hidden_by_default = false,
104 .default_width = 70
105 },
106 {
107 .column = Version,
108 .header = std::string_view("Version"),
110 .hidden_by_default = false,
111 .default_width = 70
112 },
113 {
114 .column = ModifiedBy,
115 .header = std::string_view("Modified By"),
117 .hidden_by_default = false,
118 .default_width = kColumnWidthAuto
119 },
120 {
121 .column = RecordedAt,
122 .header = std::string_view("Recorded At"),
124 .hidden_by_default = false,
125 .default_width = kColumnWidthAuto
126 }
127 }};
128
132 inline static const QSize kDefaultWindowSize = {900, 400};
133
137 static constexpr std::string_view kSettingsGroup = "BookStatusListWindow";
138
142 static std::vector<column_style> const& columnStyles() {
143 static std::vector<column_style> const kStylesVector = []() {
144 std::vector<column_style> result;
145 result.reserve(kColumnCount);
146 for (std::size_t i = 0; i < kColumnCount; ++i)
147 result.push_back(kColumns[i].style);
148 return result;
149 }();
150 return kStylesVector;
151 }
152
156 static QVector<int> defaultHiddenColumns() {
157 static QVector<int> const result =
158 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
159 return result;
160 }
161
162 explicit ClientBookStatusModel(ClientManager* clientManager,
163 QObject* parent = nullptr);
164 ~ClientBookStatusModel() override = default;
165
166 // QAbstractTableModel interface
167 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
168 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
169 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
170 QVariant headerData(int section, Qt::Orientation orientation,
171 int role = Qt::DisplayRole) const override;
172
176 void refresh();
177
184 const refdata::domain::book_status* getStatus(int row) const;
185
186signals:
195private slots:
196 void onStatusesLoaded();
197 void onPulseStateChanged(bool isOn);
198 void onPulsingComplete();
199
200private:
201 QVariant recency_foreground_color(const std::string& code) const;
202
203 struct FetchResult {
204 bool success;
205 std::vector<refdata::domain::book_status> statuses;
206 QString error_message;
207 QString error_details;
208 };
209
210 ClientManager* clientManager_;
211 std::vector<refdata::domain::book_status> statuses_;
212 QFutureWatcher<FetchResult>* watcher_;
213 bool is_fetching_{false};
214
215 using BookStatusKeyExtractor = std::string(*)(const refdata::domain::book_status&);
216 RecencyTracker<refdata::domain::book_status, BookStatusKeyExtractor> recencyTracker_;
217 RecencyPulseManager* pulseManager_;
218};
219
220}
221
222#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.
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Model for displaying book statuses fetched from the server.
Definition ClientBookStatusModel.hpp:43
static constexpr std::string_view kSettingsGroup
Settings group name for persisting window and column state.
Definition ClientBookStatusModel.hpp:137
static constexpr std::size_t kColumnCount
Column metadata: header text, style, visibility, and width.
Definition ClientBookStatusModel.hpp:76
static const QSize kDefaultWindowSize
Default window size for the book status list window.
Definition ClientBookStatusModel.hpp:132
static std::vector< column_style > const & columnStyles()
Returns a static vector of column styles (built once per process).
Definition ClientBookStatusModel.hpp:142
void refresh()
Refresh book status data from server asynchronously.
Definition ClientBookStatusModel.cpp:131
static QVector< int > defaultHiddenColumns()
Returns a static QVector of hidden column indices (built once per process).
Definition ClientBookStatusModel.hpp:156
const refdata::domain::book_status * getStatus(int row) const
Get book status at the specified row.
Definition ClientBookStatusModel.cpp:202
Column
Enumeration of table columns for type-safe column access.
Definition ClientBookStatusModel.hpp:60
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Lifecycle states for book records.
Definition book_status.hpp:38