ORE Studio 0.0.4
Loading...
Searching...
No Matches
PortfolioExplorerTradeModel.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_PORTFOLIO_EXPLORER_TRADE_MODEL_HPP
21#define ORES_QT_PORTFOLIO_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.trading.api/domain/trade.hpp"
33
34namespace ores::qt {
35
40 std::string short_code;
41 std::string full_name;
42};
43
50class PortfolioExplorerTradeModel final : public QAbstractTableModel {
51 Q_OBJECT
52
53private:
54 inline static std::string_view logger_name =
55 "ores.qt.portfolio_explorer_trade_model";
56
57 [[nodiscard]] static auto& lg() {
58 using namespace ores::logging;
59 static auto instance = make_logger(logger_name);
60 return instance;
61 }
62
63public:
64 enum Column {
65 ExternalId,
66 TradeType,
67 CounterpartyShortCode,
68 CounterpartyName,
69 LifecycleEvent,
70 TradeDate,
71 EffectiveDate,
72 TerminationDate,
73 Version,
74 ModifiedBy,
75 RecordedAt,
76 ColumnCount
77 };
78
79 explicit PortfolioExplorerTradeModel(ClientManager* clientManager,
80 QObject* parent = nullptr);
81 ~PortfolioExplorerTradeModel() override = default;
82
83 // QAbstractTableModel interface
84 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
85 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
86 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
87 QVariant headerData(int section, Qt::Orientation orientation,
88 int role = Qt::DisplayRole) const override;
89
93 void set_filter(std::optional<boost::uuids::uuid> book_id,
94 std::optional<boost::uuids::uuid> portfolio_id);
95
100 std::unordered_map<std::string, CounterpartyInfo> cpty_map);
101
105 void refresh();
106
110 void load_page(std::uint32_t offset, std::uint32_t limit);
111
115 std::uint32_t total_available_count() const { return total_available_count_; }
116
120 const trading::domain::trade* get_trade(int row) const;
121
122signals:
123 void dataLoaded();
124 void loadError(const QString& error_message, const QString& details = {});
125
126private slots:
127 void onTradesLoaded();
128
129private:
130 struct FetchResult {
131 bool success;
132 std::vector<trading::domain::trade> trades;
133 std::uint32_t total_available_count;
134 QString error_message;
135 QString error_details;
136 };
137
138 void fetch_trades(std::uint32_t offset, std::uint32_t limit);
139
140 ClientManager* clientManager_;
141 std::vector<trading::domain::trade> trades_;
142 QFutureWatcher<FetchResult>* watcher_;
143 std::uint32_t total_available_count_{0};
144 bool is_fetching_{false};
145
146 std::optional<boost::uuids::uuid> filter_book_id_;
147 std::optional<boost::uuids::uuid> filter_portfolio_id_;
148 std::unordered_map<std::string, CounterpartyInfo> cpty_map_;
149};
150
151}
152
153#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
Short counterparty display info.
Definition PortfolioExplorerTradeModel.hpp:39
Table model for filtered trades in the portfolio/book tree window.
Definition PortfolioExplorerTradeModel.hpp:50
const trading::domain::trade * get_trade(int row) const
Get the trade at the given row.
Definition PortfolioExplorerTradeModel.cpp:263
void refresh()
Refresh trade data from server using current filter.
Definition PortfolioExplorerTradeModel.cpp:149
std::uint32_t total_available_count() const
Get total available count from last fetch.
Definition PortfolioExplorerTradeModel.hpp:115
void set_counterparty_map(std::unordered_map< std::string, CounterpartyInfo > cpty_map)
Set the counterparty lookup map (UUID string -> CounterpartyInfo).
Definition PortfolioExplorerTradeModel.cpp:139
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page.
Definition PortfolioExplorerTradeModel.cpp:171
void set_filter(std::optional< boost::uuids::uuid > book_id, std::optional< boost::uuids::uuid > portfolio_id)
Set book/portfolio filter and clear existing data.
Definition PortfolioExplorerTradeModel.cpp:132
Trade capturing FpML Trade Header properties.
Definition trade.hpp:38