ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientCounterpartyModel.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_COUNTERPARTY_MODEL_HPP
21#define ORES_QT_CLIENT_COUNTERPARTY_MODEL_HPP
22
23#include <vector>
24#include <cstdint>
25#include <unordered_map>
26#include <unordered_set>
27#include <QFutureWatcher>
28#include <QAbstractTableModel>
29#include "ores.qt/AbstractClientModel.hpp"
30#include "ores.qt/ClientManager.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/counterparty.hpp"
36
37namespace ores::qt {
38
46 Q_OBJECT
47
48private:
49 inline static std::string_view logger_name =
50 "ores.qt.client_counterparty_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 BusinessCenterCode,
64 ShortCode,
65 FullName,
66 TransliteratedName,
67 PartyType,
68 Status,
69 Version,
70 ModifiedBy,
71 RecordedAt,
72 ColumnCount
73 };
74
75 explicit ClientCounterpartyModel(ClientManager* clientManager,
76 ImageCache* imageCache,
77 QObject* parent = nullptr);
78 ~ClientCounterpartyModel() override = default;
79
80 // QAbstractTableModel interface
81 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
82 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
83 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
84 QVariant headerData(int section, Qt::Orientation orientation,
85 int role = Qt::DisplayRole) const override;
86
95 void refresh(bool replace = true);
96
103 void load_page(std::uint32_t offset, std::uint32_t limit);
104
112
113 std::uint32_t page_size() const { return page_size_; }
114 void set_page_size(std::uint32_t size);
115 std::uint32_t total_available_count() const { return total_available_count_; }
116
117signals:
126private slots:
127 void onCounterpartysLoaded();
128 void onPulseStateChanged(bool isOn);
129 void onPulsingComplete();
130
131private:
132 QVariant recency_foreground_color(const std::string& code) const;
133
134 struct FetchResult {
135 bool success;
136 std::vector<refdata::domain::counterparty> counterparties;
137 std::uint32_t total_available_count;
138 QString error_message;
139 QString error_details;
140 };
141
142 void fetch_counterparties(std::uint32_t offset, std::uint32_t limit);
143 void fetch_business_centres();
144
145 ClientManager* clientManager_;
146 ImageCache* imageCache_;
147 std::vector<refdata::domain::counterparty> counterparties_;
148 QFutureWatcher<FetchResult>* watcher_;
149 std::uint32_t page_size_{100};
150 std::uint32_t total_available_count_{0};
151 bool is_fetching_{false};
152
153 using CounterpartyKeyExtractor = std::string(*)(const refdata::domain::counterparty&);
154 RecencyTracker<refdata::domain::counterparty, CounterpartyKeyExtractor> recencyTracker_;
155 RecencyPulseManager* pulseManager_;
156
157 std::unordered_map<std::string, std::string> bc_code_to_image_id_;
158};
159
160}
161
162#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
Model for displaying counterparties fetched from the server.
Definition ClientCounterpartyModel.hpp:45
const refdata::domain::counterparty * getCounterparty(int row) const
Get counterparty at the specified row.
Definition ClientCounterpartyModel.cpp:300
void refresh(bool replace=true)
Refresh counterparty data from server asynchronously.
Definition ClientCounterpartyModel.cpp:166
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of counterparty data.
Definition ClientCounterpartyModel.cpp:192
Column
Enumeration of table columns for type-safe column access.
Definition ClientCounterpartyModel.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
An external trading partner participating in financial transactions.
Definition counterparty.hpp:37