ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientCommodityInstrumentModel.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_COMMODITY_INSTRUMENT_MODEL_HPP
21#define ORES_QT_CLIENT_COMMODITY_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/commodity_instrument.hpp"
31
32namespace ores::qt {
33
37class ClientCommodityInstrumentModel final : public QAbstractTableModel {
38 Q_OBJECT
39
40private:
41 inline static std::string_view logger_name =
42 "ores.qt.client_commodity_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 CommodityCode,
55 Currency,
56 Quantity,
57 Maturity,
58 Version,
59 ModifiedBy,
60 RecordedAt,
61 ColumnCount
62 };
63
64 explicit ClientCommodityInstrumentModel(ClientManager* clientManager,
65 QObject* parent = nullptr);
66 ~ClientCommodityInstrumentModel() override = default;
67
68 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
69 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
70 QVariant data(const QModelIndex& index,
71 int role = Qt::DisplayRole) const override;
72 QVariant headerData(int section, Qt::Orientation orientation,
73 int role = Qt::DisplayRole) const override;
74
75 void refresh();
76 void load_page(std::uint32_t offset, std::uint32_t limit);
77
78 const trading::domain::commodity_instrument* getCommodityInstrument(int row) const;
79
80 std::uint32_t page_size() const { return page_size_; }
81 void set_page_size(std::uint32_t size);
82 std::uint32_t total_available_count() const { return total_available_count_; }
83
84signals:
85 void dataLoaded();
86 void loadError(const QString& error_message, const QString& details = {});
87
88private slots:
89 void onCommodityInstrumentsLoaded();
90 void onPulseStateChanged(bool isOn);
91 void onPulsingComplete();
92
93private:
94 QVariant recency_foreground_color(const std::string& key) const;
95
96 struct FetchResult {
97 bool success;
98 std::vector<trading::domain::commodity_instrument> instruments;
99 std::uint32_t total_available_count;
100 QString error_message;
101 QString error_details;
102 };
103
104 void fetch_commodity_instruments(std::uint32_t offset, std::uint32_t limit);
105
106 ClientManager* clientManager_;
107 std::vector<trading::domain::commodity_instrument> instruments_;
108 QFutureWatcher<FetchResult>* watcher_;
109 std::uint32_t page_size_{100};
110 std::uint32_t total_available_count_{0};
111 bool is_fetching_{false};
112
113 using KeyExtractor = std::string(*)(const trading::domain::commodity_instrument&);
115 RecencyPulseManager* pulseManager_;
116};
117
118}
119
120#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 commodity instruments fetched from the server.
Definition ClientCommodityInstrumentModel.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
Commodity instrument economics for all commodity ORE product types.
Definition commodity_instrument.hpp:48