ORE Studio 0.0.4
Loading...
Searching...
No Matches
OrgExplorerMdiWindow.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_ORG_EXPLORER_MDI_WINDOW_HPP
21#define ORES_QT_ORG_EXPLORER_MDI_WINDOW_HPP
22
23#include <vector>
24#include <QList>
25#include <QLabel>
26#include <QAction>
27#include <QToolBar>
28#include <QSplitter>
29#include <QTreeView>
30#include <QWidget>
31#include <QTableView>
32#include <QDateTime>
33#include <QFutureWatcher>
34#include <QItemSelection>
35#include <QSortFilterProxyModel>
36#include <QToolButton>
37#include "ores.logging/make_logger.hpp"
38#include "ores.qt/ClientManager.hpp"
39#include "ores.qt/EntityListMdiWindow.hpp"
40#include "ores.qt/PaginationWidget.hpp"
41#include "ores.qt/OrgExplorerTreeModel.hpp"
42#include "ores.qt/OrgExplorerTradeModel.hpp"
43#include "ores.refdata.api/domain/business_unit.hpp"
44#include "ores.refdata.api/domain/book.hpp"
45
46namespace ores::qt {
47
48class BusinessUnitController;
49class BookController;
50class TradeController;
51
60 Q_OBJECT
61
62private:
63 inline static std::string_view logger_name =
64 "ores.qt.org_explorer_mdi_window";
65
66 [[nodiscard]] static auto& lg() {
67 using namespace ores::logging;
68 static auto instance = make_logger(logger_name);
69 return instance;
70 }
71
72 // Event names for subscription
73 static constexpr const char* book_event = "ores.refdata.book_changed";
74 static constexpr const char* business_unit_event =
75 "ores.refdata.business_unit_changed";
76 static constexpr const char* trade_event = "ores.trading.trade_changed";
77
78public:
79 explicit OrgExplorerMdiWindow(
80 ClientManager* clientManager,
81 BusinessUnitController* businessUnitController,
82 BookController* bookController,
83 TradeController* tradeController,
84 const QString& username,
85 QWidget* parent = nullptr);
86 ~OrgExplorerMdiWindow() override = default;
87
88 QSize sizeHint() const override { return QSize(1200, 700); }
89
90public slots:
96 void doReload() override;
97
98signals:
99 void statusChanged(const QString& msg);
100
101protected:
102 QString normalRefreshTooltip() const override {
103 return tr("Refresh organisational tree");
104 }
105
106private slots:
107 void onTreeSelectionChanged(const QItemSelection& selected,
108 const QItemSelection& deselected);
109 void onNotificationReceived(const QString& eventType,
110 const QDateTime& timestamp,
111 const QStringList& entityIds,
112 const QString& tenantId);
113 void onUnitsLoaded();
114 void onBooksLoaded();
115 void onCounterpartiesLoaded();
116 void onEditSelected();
117 void onHistorySelected();
118 void onTradeDoubleClicked(const QModelIndex& index);
119 void updateActionStates();
120
121private:
122 void setupUi();
123 void setupToolbar();
124 void setupTree();
125 void setupTradePanel();
126 void setupConnections();
127 void setupEventSubscriptions();
128 void rebuildTree();
129 void updateBreadcrumb(const OrgTreeNode* node);
130 void collectBookUuids(const QModelIndex& parent,
131 QList<boost::uuids::uuid>& uuids);
132
133 // Fetch result types
134 struct UnitFetchResult {
135 bool success;
136 std::vector<refdata::domain::business_unit> units;
137 QString error_message;
138 QString error_details;
139 };
140
141 struct BookFetchResult {
142 bool success;
143 std::vector<refdata::domain::book> books;
144 QString error_message;
145 QString error_details;
146 };
147
148 struct CounterpartyFetchResult {
149 bool success;
150 std::unordered_map<std::string, CounterpartyInfo> cpty_map;
151 QString error_message;
152 QString error_details;
153 };
154
155 struct CountResult {
156 boost::uuids::uuid book_id;
157 std::uint32_t count{0};
158 bool success{false};
159 QString error_message;
160 QString error_details;
161 };
162
163 ClientManager* clientManager_;
164 QString username_;
165
166 // Controllers (not owned — lifetime guaranteed by MainWindow)
167 BusinessUnitController* businessUnitController_{nullptr};
168 BookController* bookController_{nullptr};
169 TradeController* tradeController_{nullptr};
170
171 // Layout
172 QToolBar* toolbar_{nullptr};
173 QAction* reloadAction_{nullptr};
174 QAction* editAction_{nullptr};
175 QAction* historyAction_{nullptr};
176
177 QSplitter* splitter_{nullptr};
178
179 // Left: tree
180 QTreeView* treeView_{nullptr};
181 OrgExplorerTreeModel* treeModel_{nullptr};
182
183 // Right: trade panel
184 QWidget* breadcrumbBar_{nullptr};
185 QTableView* tradeTableView_{nullptr};
186 OrgExplorerTradeModel* tradeModel_{nullptr};
187 QSortFilterProxyModel* tradeProxyModel_{nullptr};
188 PaginationWidget* paginationWidget_{nullptr};
189
190 // Async watchers
191 QFutureWatcher<UnitFetchResult>* unitWatcher_{nullptr};
192 QFutureWatcher<BookFetchResult>* bookWatcher_{nullptr};
193 QFutureWatcher<CounterpartyFetchResult>* counterpartyWatcher_{nullptr};
194 QList<QFutureWatcher<CountResult>*> countWatchers_;
195
196 // Data
197 std::vector<refdata::domain::business_unit> units_;
198 std::vector<refdata::domain::book> books_;
199 bool units_loaded_{false};
200 bool books_loaded_{false};
201};
202
203}
204
205#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Controller for managing book windows and operations.
Definition BookController.hpp:45
Controller for managing business unit windows and operations.
Definition BusinessUnitController.hpp:45
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Base class for entity list MDI windows providing stale indicator support.
Definition EntityListMdiWindow.hpp:62
MDI window showing the organisational hierarchy with a filtered trade table.
Definition OrgExplorerMdiWindow.hpp:59
void doReload() override
Reload all data from server.
Definition OrgExplorerMdiWindow.cpp:239
QString normalRefreshTooltip() const override
Get the normal (non-stale) tooltip text for the refresh action.
Definition OrgExplorerMdiWindow.hpp:102
A single node in the organisational hierarchy tree.
Definition OrgExplorerTreeModel.hpp:56
Controller for managing trade windows and operations.
Definition TradeController.hpp:43