ORE Studio 0.0.4
Loading...
Searching...
No Matches
TradeDetailDialog.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_TRADE_DETAIL_DIALOG_HPP
21#define ORES_QT_TRADE_DETAIL_DIALOG_HPP
22
23#include <map>
24#include <vector>
25#include <QTabWidget>
26#include <QTimer>
27#include "ores.qt/ClientManager.hpp"
28#include "ores.qt/ImageCache.hpp"
29#include "ores.qt/DetailDialogBase.hpp"
30#include "ores.qt/ProvenanceWidget.hpp"
31#include "ores.qt/IInstrumentForm.hpp"
32#include "ores.qt/InstrumentFormRegistry.hpp"
33#include "ores.logging/make_logger.hpp"
34#include "ores.trading.api/domain/trade.hpp"
35#include "ores.trading.api/domain/trade_type.hpp"
36#include "ores.trading.api/messaging/trade_protocol.hpp"
37#include "ores.refdata.api/domain/book.hpp"
38#include "ores.refdata.api/domain/counterparty.hpp"
39
40namespace Ui {
41class TradeDetailDialog;
42}
43
44namespace ores::qt {
45
59class TradeDetailDialog final : public DetailDialogBase {
60 Q_OBJECT
61
62private:
63 inline static std::string_view logger_name =
64 "ores.qt.trade_detail_dialog";
65
66 [[nodiscard]] static auto& lg() {
67 using namespace ores::logging;
68 static auto instance = make_logger(logger_name);
69 return instance;
70 }
71
72public:
73 explicit TradeDetailDialog(QWidget* parent = nullptr);
74 ~TradeDetailDialog() override;
75
76 void setClientManager(ClientManager* clientManager);
77 void setUsername(const std::string& username);
78 void setImageCache(ImageCache* cache);
79
90 void setCreateMode(bool createMode);
91 void setReadOnly(bool readOnly);
92
93protected:
94 QTabWidget* tabWidget() const override;
95 QWidget* provenanceTab() const override;
96 ProvenanceWidget* provenanceWidget() const override;
97 bool hasUnsavedChanges() const override {
98 return hasChanges_ || instrumentHasChanges_;
99 }
100 void showEvent(QShowEvent* event) override;
101
102signals:
103 void tradeSaved(const QString& code);
104 void tradeDeleted(const QString& code);
105
106private slots:
107 void onSaveClicked();
108 void onDeleteClicked();
109 void onCodeChanged(const QString& text);
110 void onFieldChanged();
111 void onInstrumentFieldChanged();
112 void onCreateTradeTypeChanged(const QString& text);
113
114private:
115 void setupUi();
116 void setupConnections();
117 void loadBooks();
118 void selectCurrentBook();
119 void loadCounterparties();
120 void selectCurrentCounterparty();
121 void loadTradeTypes();
122 void updateUiFromTrade();
123 void updateTradeFromUi();
124 void updateSaveButtonState();
125 bool validateInput();
126 void connectFormSignals(IInstrumentForm* form);
127 void activateForm(IInstrumentForm* form, const std::string& tradeTypeCode);
128 IInstrumentForm* findForm(trading::domain::product_type pt,
129 const std::string& trade_type_code);
130 void applyCreateTradeType();
131
132 void saveTrade(const trading::domain::trade& trade);
133
134 Ui::TradeDetailDialog* ui_;
135 ClientManager* clientManager_;
136 ImageCache* imageCache_ = nullptr;
137 std::string username_;
139 std::vector<refdata::domain::book> books_;
140 std::vector<refdata::domain::counterparty> counterparties_;
141 bool createMode_{true};
142 bool readOnly_{false};
143 bool hasChanges_{false};
144
145 // All IInstrumentForm pages live in instrumentStack. formMap_ gives O(1)
146 // access by product_type; typeFormMap_ gives O(1) access by trade_type_code
147 // for families that register dedicated per-sub-type forms.
148 // findForm() prefers typeFormMap_ over formMap_.
149 InstrumentFormRegistry instrumentFormRegistry_;
150 std::map<trading::domain::product_type, IInstrumentForm*> formMap_;
151 std::map<std::string, IInstrumentForm*> typeFormMap_;
152 IInstrumentForm* activeForm_ = nullptr;
153
154 // Trade-type reference data cached on connect for flag lookups.
155 std::map<std::string, trading::domain::trade_type> tradeTypeCache_;
156 // Zero-interval timer that coalesces rapid tradeTypeEdit keystrokes into
157 // a single applyCreateTradeType() call per event-loop cycle.
158 QTimer* createTypeTimer_ = nullptr;
159
160 bool instrumentLoaded_{false};
161 bool instrumentHasChanges_{false};
162};
163
164}
165
166#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123
Base class for all detail dialogs.
Definition DetailDialogBase.hpp:75
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:54
Widget displaying the 6 standard record provenance fields.
Definition ProvenanceWidget.hpp:40
Pure-virtual interface implemented by every per-family instrument form widget hosted in TradeDetailDi...
Definition IInstrumentForm.hpp:73
Detail dialog for viewing and editing a trade and its linked instrument.
Definition TradeDetailDialog.hpp:59
ProvenanceWidget * provenanceWidget() const override
Returns the promoted ProvenanceWidget (named "provenanceWidget" in .ui).
Definition TradeDetailDialog.cpp:119
bool hasUnsavedChanges() const override
Definition TradeDetailDialog.hpp:97
QTabWidget * tabWidget() const override
Returns the dialog's QTabWidget (named "tabWidget" in .ui).
Definition TradeDetailDialog.cpp:117
void setTradeBundle(const trading::messaging::trade_export_item &bundle)
Populate the dialog with a trade bundle (trade + instrument).
Definition TradeDetailDialog.cpp:410
QWidget * provenanceTab() const override
Returns the Provenance tab widget (named "provenanceTab" in .ui).
Definition TradeDetailDialog.cpp:118
Trade capturing FpML Trade Header properties.
Definition trade.hpp:39
One trade plus its resolved instrument data.
Definition trade_protocol.hpp:48