ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientFraConventionModel.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_FRA_CONVENTION_MODEL_HPP
21#define ORES_QT_CLIENT_FRA_CONVENTION_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include "ores.qt/AbstractClientModel.hpp"
26#include "ores.qt/ClientManager.hpp"
27#include "ores.qt/RecencyPulseManager.hpp"
28#include "ores.qt/RecencyTracker.hpp"
29#include "ores.logging/make_logger.hpp"
30#include "ores.refdata.api/domain/fra_convention.hpp"
31
32namespace ores::qt {
33
41 Q_OBJECT
42
43private:
44 inline static std::string_view logger_name =
45 "ores.qt.client_fra_convention_model";
46
47 [[nodiscard]] static auto& lg() {
48 using namespace ores::logging;
49 static auto instance = make_logger(logger_name);
50 return instance;
51 }
52
53public:
57 enum Column {
58 Id,
59 Index,
60 Version,
61 ModifiedBy,
62 RecordedAt,
63 ColumnCount
64 };
65
66 explicit ClientFraConventionModel(ClientManager* clientManager,
67 QObject* parent = nullptr);
68 ~ClientFraConventionModel() override = default;
69
70 // QAbstractTableModel interface
71 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
72 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
73 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
74 QVariant headerData(int section, Qt::Orientation orientation,
75 int role = Qt::DisplayRole) const override;
76
80 void refresh();
81
89
93 void load_page(std::uint32_t offset, std::uint32_t limit);
94
98 std::uint32_t page_size() const { return page_size_; }
99
103 void set_page_size(std::uint32_t size);
104
108 std::uint32_t total_available_count() const { return total_available_count_; }
109
110private slots:
111 void onConventionsLoaded();
112 void onPulseStateChanged(bool isOn);
113 void onPulsingComplete();
114
115private:
116 QVariant recency_foreground_color(const std::string& code) const;
117
118 struct FetchResult {
119 bool success;
120 std::vector<refdata::domain::fra_convention> fra_conventions;
121 std::uint32_t total_available_count;
122 QString error_message;
123 QString error_details;
124 };
125
126 void fetch_fra_conventions(std::uint32_t offset, std::uint32_t limit);
127
128 ClientManager* clientManager_;
129 std::vector<refdata::domain::fra_convention> fra_conventions_;
130 QFutureWatcher<FetchResult>* watcher_;
131 std::uint32_t page_size_{100};
132 std::uint32_t total_available_count_{0};
133 bool is_fetching_{false};
134
135 using FraConventionKeyExtractor = std::string(*)(const refdata::domain::fra_convention&);
136 RecencyTracker<refdata::domain::fra_convention, FraConventionKeyExtractor> recencyTracker_;
137 RecencyPulseManager* pulseManager_;
138};
139
140}
141
142#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:37
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123
Model for displaying FRA conventions fetched from the server.
Definition ClientFraConventionModel.hpp:40
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientFraConventionModel.cpp:253
void refresh()
Refresh FRA convention data from server asynchronously.
Definition ClientFraConventionModel.cpp:123
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientFraConventionModel.hpp:108
const refdata::domain::fra_convention * getConvention(int row) const
Get FRA convention at the specified row.
Definition ClientFraConventionModel.cpp:265
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientFraConventionModel.cpp:149
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientFraConventionModel.hpp:98
Column
Enumeration of table columns for type-safe column access.
Definition ClientFraConventionModel.hpp:57
Conventions for a forward rate agreement (FRA).
Definition fra_convention.hpp:36