ORE Studio 0.0.4
Loading...
Searching...
No Matches
OrgExplorerTradeModel.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_ORG_EXPLORER_TRADE_MODEL_HPP
21#define ORES_QT_ORG_EXPLORER_TRADE_MODEL_HPP
22
23#include <string>
24#include <vector>
25#include <optional>
26#include <unordered_map>
27#include <QFutureWatcher>
28#include <QAbstractTableModel>
29#include <boost/uuid/uuid.hpp>
30#include "ores.logging/make_logger.hpp"
31#include "ores.qt/ClientManager.hpp"
32#include "ores.qt/PortfolioExplorerTradeModel.hpp"
33#include "ores.trading.api/domain/trade.hpp"
34
35namespace ores::qt {
36
43class OrgExplorerTradeModel final : public QAbstractTableModel {
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.org_explorer_trade_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:
57 enum Column {
58 ExternalId,
59 TradeType,
60 CounterpartyShortCode,
61 CounterpartyName,
62 LifecycleEvent,
63 TradeDate,
64 EffectiveDate,
65 TerminationDate,
66 Version,
67 ModifiedBy,
68 RecordedAt,
69 ColumnCount
70 };
71
72 explicit OrgExplorerTradeModel(ClientManager* clientManager,
73 QObject* parent = nullptr);
74 ~OrgExplorerTradeModel() override = default;
75
76 // QAbstractTableModel interface
77 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
78 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
79 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
80 QVariant headerData(int section, Qt::Orientation orientation,
81 int role = Qt::DisplayRole) const override;
82
86 void set_filter(std::optional<boost::uuids::uuid> book_id,
87 std::optional<boost::uuids::uuid> business_unit_id);
88
93 std::unordered_map<std::string, CounterpartyInfo> cpty_map);
94
98 void refresh();
99
103 void load_page(std::uint32_t offset, std::uint32_t limit);
104
108 std::uint32_t total_available_count() const { return total_available_count_; }
109
113 const trading::domain::trade* get_trade(int row) const;
114
115signals:
116 void dataLoaded();
117 void loadError(const QString& error_message, const QString& details = {});
118
119private slots:
120 void onTradesLoaded();
121
122private:
123 struct FetchResult {
124 bool success;
125 std::vector<trading::domain::trade> trades;
126 std::uint32_t total_available_count;
127 QString error_message;
128 QString error_details;
129 };
130
131 void fetch_trades(std::uint32_t offset, std::uint32_t limit);
132
133 ClientManager* clientManager_;
134 std::vector<trading::domain::trade> trades_;
135 QFutureWatcher<FetchResult>* watcher_;
136 std::uint32_t total_available_count_{0};
137 bool is_fetching_{false};
138
139 std::optional<boost::uuids::uuid> filter_book_id_;
140 std::optional<boost::uuids::uuid> filter_business_unit_id_;
141 std::unordered_map<std::string, CounterpartyInfo> cpty_map_;
142};
143
144}
145
146#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Table model for filtered trades in the org/BU tree window.
Definition OrgExplorerTradeModel.hpp:43
const trading::domain::trade * get_trade(int row) const
Get the trade at the given row.
Definition OrgExplorerTradeModel.cpp:262
void refresh()
Refresh trade data from server using current filter.
Definition OrgExplorerTradeModel.cpp:149
std::uint32_t total_available_count() const
Get total available count from last fetch.
Definition OrgExplorerTradeModel.hpp:108
void set_counterparty_map(std::unordered_map< std::string, CounterpartyInfo > cpty_map)
Set the counterparty lookup map (UUID string -> CounterpartyInfo).
Definition OrgExplorerTradeModel.cpp:139
void set_filter(std::optional< boost::uuids::uuid > book_id, std::optional< boost::uuids::uuid > business_unit_id)
Set book / business_unit filter and clear existing data.
Definition OrgExplorerTradeModel.cpp:132
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page.
Definition OrgExplorerTradeModel.cpp:171
Trade capturing FpML Trade Header properties.
Definition trade.hpp:38