ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientBusinessCentreModel.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_BUSINESS_CENTRE_MODEL_HPP
21#define ORES_QT_CLIENT_BUSINESS_CENTRE_MODEL_HPP
22
23#include <vector>
24#include <cstdint>
25#include <QSize>
26#include <QFutureWatcher>
27#include <QAbstractTableModel>
28#include "ores.qt/AbstractClientModel.hpp"
29#include "ores.qt/ClientManager.hpp"
30#include "ores.qt/ColumnMetadata.hpp"
31#include "ores.qt/ImageCache.hpp"
32#include "ores.qt/RecencyPulseManager.hpp"
33#include "ores.qt/RecencyTracker.hpp"
34#include "ores.logging/make_logger.hpp"
35#include "ores.refdata.api/domain/business_centre.hpp"
36
37namespace ores::qt {
38
46 Q_OBJECT
47
48private:
49 inline static std::string_view logger_name =
50 "ores.qt.client_business_centre_model";
51
52 [[nodiscard]] static auto& lg() {
53 using namespace ores::logging;
54 static auto instance = make_logger(logger_name);
55 return instance;
56 }
57
58public:
62 enum Column {
63 CountryAlpha2,
64 Code,
65 City,
66 Source,
67 Description,
68 CodingScheme,
69 Version,
70 ModifiedBy,
71 RecordedAt,
72 ColumnCount
73 };
74
80 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
81 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
82 {
83 .column = CountryAlpha2,
84 .header = std::string_view("Country"),
86 .hidden_by_default = false,
87 .default_width = kColumnWidthAuto
88 },
89 {
90 .column = Code,
91 .header = std::string_view("Code"),
93 .hidden_by_default = false,
94 .default_width = kColumnWidthAuto
95 },
96 {
97 .column = City,
98 .header = std::string_view("City"),
100 .hidden_by_default = false,
101 .default_width = kColumnWidthAuto
102 },
103 {
104 .column = Source,
105 .header = std::string_view("Source"),
107 .hidden_by_default = false,
108 .default_width = kColumnWidthAuto
109 },
110 {
111 .column = Description,
112 .header = std::string_view("Description"),
114 .hidden_by_default = true,
115 .default_width = kColumnWidthAuto
116 },
117 {
118 .column = CodingScheme,
119 .header = std::string_view("Coding Scheme"),
121 .hidden_by_default = true,
122 .default_width = kColumnWidthAuto
123 },
124 {
125 .column = Version,
126 .header = std::string_view("Version"),
128 .hidden_by_default = false,
129 .default_width = 70
130 },
131 {
132 .column = ModifiedBy,
133 .header = std::string_view("Modified By"),
135 .hidden_by_default = false,
136 .default_width = kColumnWidthAuto
137 },
138 {
139 .column = RecordedAt,
140 .header = std::string_view("Recorded At"),
142 .hidden_by_default = false,
143 .default_width = 155
144 }
145 }};
146
150 inline static const QSize kDefaultWindowSize = {900, 400};
151
155 static constexpr std::string_view kSettingsGroup = "BusinessCentreListWindow";
156
160 static std::vector<column_style> const& columnStyles() {
161 static std::vector<column_style> const kStylesVector = []() {
162 std::vector<column_style> result;
163 result.reserve(kColumnCount);
164 for (std::size_t i = 0; i < kColumnCount; ++i)
165 result.push_back(kColumns[i].style);
166 return result;
167 }();
168 return kStylesVector;
169 }
170
174 static QVector<int> defaultHiddenColumns() {
175 static QVector<int> const result =
176 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
177 return result;
178 }
179
180 explicit ClientBusinessCentreModel(ClientManager* clientManager,
181 ImageCache* imageCache,
182 QObject* parent = nullptr);
183 ~ClientBusinessCentreModel() override = default;
184
185 // QAbstractTableModel interface
186 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
187 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
188 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
189 QVariant headerData(int section, Qt::Orientation orientation,
190 int role = Qt::DisplayRole) const override;
191
200 void refresh(bool replace = true);
201
208 void load_page(std::uint32_t offset, std::uint32_t limit);
209
217
218 std::uint32_t page_size() const { return page_size_; }
219 void set_page_size(std::uint32_t size);
220 std::uint32_t total_available_count() const { return total_available_count_; }
221
222signals:
231private slots:
232 void onBusinessCentresLoaded();
233 void onPulseStateChanged(bool isOn);
234 void onPulsingComplete();
235
236private:
237 QVariant recency_foreground_color(const std::string& code) const;
238
239 struct FetchResult {
240 bool success;
241 std::vector<refdata::domain::business_centre> business_centres;
242 std::uint32_t total_available_count;
243 QString error_message;
244 QString error_details;
245 };
246
247 void fetch_business_centres(std::uint32_t offset, std::uint32_t limit);
248
249 ClientManager* clientManager_;
250 ImageCache* imageCache_;
251 std::vector<refdata::domain::business_centre> business_centres_;
252 QFutureWatcher<FetchResult>* watcher_;
253 std::uint32_t page_size_{100};
254 std::uint32_t total_available_count_{0};
255 bool is_fetching_{false};
256
257 using BusinessCentreKeyExtractor = std::string(*)(const refdata::domain::business_centre&);
258 RecencyTracker<refdata::domain::business_centre, BusinessCentreKeyExtractor> recencyTracker_;
259 RecencyPulseManager* pulseManager_;
260};
261
262}
263
264#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_bold_left
Monospace bold, left-aligned.
@ mono_bold_center
Monospace bold, centered.
@ mono_left
Monospace, left-aligned.
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Model for displaying business centres fetched from the server.
Definition ClientBusinessCentreModel.hpp:45
static constexpr std::string_view kSettingsGroup
Settings group name for persisting window and column state.
Definition ClientBusinessCentreModel.hpp:155
static constexpr std::size_t kColumnCount
Column metadata: header text, style, visibility, and width.
Definition ClientBusinessCentreModel.hpp:80
static const QSize kDefaultWindowSize
Default window size for the tenant list window.
Definition ClientBusinessCentreModel.hpp:150
static std::vector< column_style > const & columnStyles()
Returns a static vector of column styles (built once per process).
Definition ClientBusinessCentreModel.hpp:160
static QVector< int > defaultHiddenColumns()
Returns a static QVector of hidden column indices (built once per process).
Definition ClientBusinessCentreModel.hpp:174
void refresh(bool replace=true)
Refresh business centre data from server asynchronously.
Definition ClientBusinessCentreModel.cpp:174
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of business centre data.
Definition ClientBusinessCentreModel.cpp:200
const refdata::domain::business_centre * getBusinessCentre(int row) const
Get business centre at the specified row.
Definition ClientBusinessCentreModel.cpp:308
Column
Enumeration of table columns for type-safe column access.
Definition ClientBusinessCentreModel.hpp:62
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:53
Represents a business centre using FpML-style codes.
Definition business_centre.hpp:37