ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientFxInstrumentModel.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_FX_INSTRUMENT_MODEL_HPP
21#define ORES_QT_CLIENT_FX_INSTRUMENT_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include <QAbstractTableModel>
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.trading.api/domain/fx_instrument.hpp"
31
32namespace ores::qt {
33
37class ClientFxInstrumentModel final : public QAbstractTableModel {
38 Q_OBJECT
39
40private:
41 inline static std::string_view logger_name =
42 "ores.qt.client_fx_instrument_model";
43
44 [[nodiscard]] static auto& lg() {
45 using namespace ores::logging;
46 static auto instance = make_logger(logger_name);
47 return instance;
48 }
49
50public:
51 enum Column {
52 Id,
53 TradeType,
54 BoughtCurrency,
55 BoughtAmount,
56 SoldCurrency,
57 SoldAmount,
58 ValueDate,
59 Version,
60 ModifiedBy,
61 RecordedAt,
62 ColumnCount
63 };
64
65 explicit ClientFxInstrumentModel(ClientManager* clientManager,
66 QObject* parent = nullptr);
67 ~ClientFxInstrumentModel() override = default;
68
69 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
70 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
71 QVariant data(const QModelIndex& index,
72 int role = Qt::DisplayRole) const override;
73 QVariant headerData(int section, Qt::Orientation orientation,
74 int role = Qt::DisplayRole) const override;
75
76 void refresh();
77 void load_page(std::uint32_t offset, std::uint32_t limit);
78
79 const trading::domain::fx_instrument* getFxInstrument(int row) const;
80
81 std::uint32_t page_size() const { return page_size_; }
82 void set_page_size(std::uint32_t size);
83 std::uint32_t total_available_count() const { return total_available_count_; }
84
85signals:
86 void dataLoaded();
87 void loadError(const QString& error_message, const QString& details = {});
88
89private slots:
90 void onFxInstrumentsLoaded();
91 void onPulseStateChanged(bool isOn);
92 void onPulsingComplete();
93
94private:
95 QVariant recency_foreground_color(const std::string& key) const;
96
97 struct FetchResult {
98 bool success;
99 std::vector<trading::domain::fx_instrument> instruments;
100 std::uint32_t total_available_count;
101 QString error_message;
102 QString error_details;
103 };
104
105 void fetch_fx_instruments(std::uint32_t offset, std::uint32_t limit);
106
107 ClientManager* clientManager_;
108 std::vector<trading::domain::fx_instrument> instruments_;
109 QFutureWatcher<FetchResult>* watcher_;
110 std::uint32_t page_size_{100};
111 std::uint32_t total_available_count_{0};
112 bool is_fetching_{false};
113
114 using KeyExtractor = std::string(*)(const trading::domain::fx_instrument&);
116 RecencyPulseManager* pulseManager_;
117};
118
119}
120
121#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Model for displaying FX instruments fetched from the server.
Definition ClientFxInstrumentModel.hpp:37
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Manages the pulsing animation for recently-changed items in models.
Definition RecencyPulseManager.hpp:42
Tracks recently-modified records for recency highlighting.
Definition RecencyTracker.hpp:75
FX instrument economics for FxForward, FxSwap, and FxOption trades.
Definition fx_instrument.hpp:36