ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientInstrumentModel.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_INSTRUMENT_MODEL_HPP
21#define ORES_QT_CLIENT_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/instrument.hpp"
31
32namespace ores::qt {
33
40class ClientInstrumentModel final : public QAbstractTableModel {
41 Q_OBJECT
42
43private:
44 inline static std::string_view logger_name =
45 "ores.qt.client_instrument_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 TradeType,
60 Notional,
61 Currency,
62 StartDate,
63 MaturityDate,
64 Version,
65 ModifiedBy,
66 RecordedAt,
67 ColumnCount
68 };
69
70 explicit ClientInstrumentModel(ClientManager* clientManager,
71 QObject* parent = nullptr);
72 ~ClientInstrumentModel() override = default;
73
74 // QAbstractTableModel interface
75 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
76 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
77 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
78 QVariant headerData(int section, Qt::Orientation orientation,
79 int role = Qt::DisplayRole) const override;
80
84 void refresh();
85
92 const trading::domain::instrument* getInstrument(int row) const;
93
97 void load_page(std::uint32_t offset, std::uint32_t limit);
98
102 std::uint32_t page_size() const { return page_size_; }
103
107 void set_page_size(std::uint32_t size);
108
112 std::uint32_t total_available_count() const { return total_available_count_; }
113
114signals:
119
123 void loadError(const QString& error_message, const QString& details = {});
124
125private slots:
126 void onInstrumentsLoaded();
127 void onPulseStateChanged(bool isOn);
128 void onPulsingComplete();
129
130private:
131 QVariant recency_foreground_color(const std::string& key) const;
132
133 struct FetchResult {
134 bool success;
135 std::vector<trading::domain::instrument> instruments;
136 std::uint32_t total_available_count;
137 QString error_message;
138 QString error_details;
139 };
140
141 void fetch_instruments(std::uint32_t offset, std::uint32_t limit);
142
143 ClientManager* clientManager_;
144 std::vector<trading::domain::instrument> instruments_;
145 QFutureWatcher<FetchResult>* watcher_;
146 std::uint32_t page_size_{100};
147 std::uint32_t total_available_count_{0};
148 bool is_fetching_{false};
149
150 using InstrumentKeyExtractor = std::string(*)(const trading::domain::instrument&);
151 RecencyTracker<trading::domain::instrument, InstrumentKeyExtractor> recencyTracker_;
152 RecencyPulseManager* pulseManager_;
153};
154
155}
156
157#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 instruments fetched from the server.
Definition ClientInstrumentModel.hpp:40
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientInstrumentModel.cpp:276
void refresh()
Refresh instrument data from server asynchronously.
Definition ClientInstrumentModel.cpp:142
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientInstrumentModel.hpp:112
void dataLoaded()
Emitted when data has been successfully loaded.
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientInstrumentModel.cpp:168
void loadError(const QString &error_message, const QString &details={})
Emitted when an error occurs during data loading.
const trading::domain::instrument * getInstrument(int row) const
Get instrument at the specified row.
Definition ClientInstrumentModel.cpp:288
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientInstrumentModel.hpp:102
Column
Enumeration of table columns for type-safe column access.
Definition ClientInstrumentModel.hpp:57
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Parent instrument record holding economic terms for a trade.
Definition instrument.hpp:40