ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientScriptedInstrumentModel.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_SCRIPTED_INSTRUMENT_MODEL_HPP
21#define ORES_QT_CLIENT_SCRIPTED_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/scripted_instrument.hpp"
31
32namespace ores::qt {
33
37class ClientScriptedInstrumentModel final : public QAbstractTableModel {
38 Q_OBJECT
39
40private:
41 inline static std::string_view logger_name =
42 "ores.qt.client_scripted_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 ScriptName,
55 Description,
56 Version,
57 ModifiedBy,
58 RecordedAt,
59 ColumnCount
60 };
61
62 explicit ClientScriptedInstrumentModel(ClientManager* clientManager,
63 QObject* parent = nullptr);
64 ~ClientScriptedInstrumentModel() override = default;
65
66 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
67 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
68 QVariant data(const QModelIndex& index,
69 int role = Qt::DisplayRole) const override;
70 QVariant headerData(int section, Qt::Orientation orientation,
71 int role = Qt::DisplayRole) const override;
72
73 void refresh();
74 void load_page(std::uint32_t offset, std::uint32_t limit);
75
77 getScriptedInstrument(int row) const;
78
79 std::uint32_t page_size() const { return page_size_; }
80 void set_page_size(std::uint32_t size);
81 std::uint32_t total_available_count() const { return total_available_count_; }
82
83signals:
84 void dataLoaded();
85 void loadError(const QString& error_message, const QString& details = {});
86
87private slots:
88 void onScriptedInstrumentsLoaded();
89 void onPulseStateChanged(bool isOn);
90 void onPulsingComplete();
91
92private:
93 QVariant recency_foreground_color(const std::string& key) const;
94
95 struct FetchResult {
96 bool success;
97 std::vector<trading::domain::scripted_instrument> instruments;
98 std::uint32_t total_available_count;
99 QString error_message;
100 QString error_details;
101 };
102
103 void fetch_scripted_instruments(std::uint32_t offset, std::uint32_t limit);
104
105 ClientManager* clientManager_;
106 std::vector<trading::domain::scripted_instrument> instruments_;
107 QFutureWatcher<FetchResult>* watcher_;
108 std::uint32_t page_size_{100};
109 std::uint32_t total_available_count_{0};
110 bool is_fetching_{false};
111
112 using KeyExtractor =
113 std::string(*)(const trading::domain::scripted_instrument&);
115 recencyTracker_;
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
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Model for displaying scripted instruments fetched from the server.
Definition ClientScriptedInstrumentModel.hpp:37
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
Scripted instrument economics for ORE AMC script-based product types.
Definition scripted_instrument.hpp:38