ORE Studio 0.0.4
Loading...
Searching...
No Matches
OreImportWizard.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_ORE_IMPORT_WIZARD_HPP
21#define ORES_QT_ORE_IMPORT_WIZARD_HPP
22
23#include <optional>
24#include <string>
25#include <boost/uuid/uuid.hpp>
26#include <QWizard>
27#include <QWizardPage>
28#include <QLabel>
29#include <QLineEdit>
30#include <QPushButton>
31#include <QProgressBar>
32#include <QTextEdit>
33#include <QRadioButton>
34#include <QCheckBox>
35#include <QListWidget>
36#include <QTreeWidget>
37#include <QComboBox>
38#include <QDateEdit>
39#include "ores.logging/make_logger.hpp"
40#include "ores.qt/ClientManager.hpp"
41#include "ores.ore/scanner/scan_result.hpp"
42#include "ores.ore/planner/import_choices.hpp"
43#include "ores.ore/planner/ore_import_plan.hpp"
44
45namespace ores::qt {
46
59class OreImportWizard final : public QWizard {
60 Q_OBJECT
61
62private:
63 inline static std::string_view logger_name = "ores.qt.ore_import_wizard";
64
65 [[nodiscard]] static auto& lg() {
66 using namespace ores::logging;
67 static auto instance = make_logger(logger_name);
68 return instance;
69 }
70
71public:
72 enum PageId {
73 Page_Welcome = 0,
74 Page_Directory,
75 Page_ScanSummary,
76 Page_Currency,
77 Page_Portfolio,
78 Page_TradeImport,
79 Page_Done
80 };
81
82 explicit OreImportWizard(ClientManager* clientManager,
83 std::optional<boost::uuids::uuid> parentPortfolioId = std::nullopt,
84 const std::string& parentPortfolioName = "",
85 QWidget* parent = nullptr);
86 ~OreImportWizard() override = default;
87
88 ClientManager* clientManager() const { return clientManager_; }
89
90 // Shared state — written by pages, read by subsequent pages
91 ore::scanner::scan_result& scanResult() { return scanResult_; }
92 ore::planner::import_choices& choices() { return choices_; }
93 ore::planner::ore_import_plan& importPlan() { return importPlan_; }
94
95 void setScanResult(ore::scanner::scan_result r) { scanResult_ = std::move(r); }
96
97 // Results set by Page_TradeImport
98 int savedCurrencies() const { return savedCurrencies_; }
99 int savedPortfolios() const { return savedPortfolios_; }
100 int savedBooks() const { return savedBooks_; }
101 int savedTrades() const { return savedTrades_; }
102 bool importSuccess() const { return importSuccess_; }
103 QString importError() const { return importError_; }
104
105 void setImportResults(int currencies, int portfolios, int books, int trades) {
106 savedCurrencies_ = currencies;
107 savedPortfolios_ = portfolios;
108 savedBooks_ = books;
109 savedTrades_ = trades;
110 }
111 void setImportSuccess(bool ok) { importSuccess_ = ok; }
112 void setImportError(const QString& msg) { importError_ = msg; }
113
114 // Existing ISO codes fetched on Page_Currency
115 const std::set<std::string>& existingIsoCodes() const { return existingIsoCodes_; }
116 void setExistingIsoCodes(std::set<std::string> codes) {
117 existingIsoCodes_ = std::move(codes);
118 }
119
120 // Existing portfolio names fetched on Page_Portfolio
121 const std::vector<std::string>& existingPortfolioNames() const {
122 return existingPortfolioNames_;
123 }
124 void setExistingPortfolioNames(std::vector<std::string> names) {
125 existingPortfolioNames_ = std::move(names);
126 }
127
128private:
129 void setupPages();
130
131 ClientManager* clientManager_;
132 ore::scanner::scan_result scanResult_;
135 std::set<std::string> existingIsoCodes_;
136 std::vector<std::string> existingPortfolioNames_;
137
138 int savedCurrencies_ = 0;
139 int savedPortfolios_ = 0;
140 int savedBooks_ = 0;
141 int savedTrades_ = 0;
142 bool importSuccess_ = false;
143 QString importError_;
144};
145
146// ============================================================================
147// Page declarations
148// ============================================================================
149
150class OreWelcomePage final : public QWizardPage {
151 Q_OBJECT
152public:
153 explicit OreWelcomePage(OreImportWizard* wizard);
154private:
155 OreImportWizard* wizard_;
156};
157
158class OreDirectoryPage final : public QWizardPage {
159 Q_OBJECT
160
161private:
162 inline static std::string_view logger_name = "ores.qt.ore_directory_page";
163 [[nodiscard]] static auto& lg() {
164 using namespace ores::logging;
165 static auto instance = make_logger(logger_name);
166 return instance;
167 }
168
169public:
170 explicit OreDirectoryPage(OreImportWizard* wizard);
171 bool isComplete() const override;
172 bool validatePage() override;
173
174private slots:
175 void onBrowseClicked();
176 void onScanFinished();
177
178private:
179 void startScan();
180
181 OreImportWizard* wizard_;
182 QLineEdit* dirEdit_;
183 QPushButton* browseBtn_;
184 QLabel* statusLabel_;
185 QProgressBar* progressBar_;
186 bool scanComplete_ = false;
187 bool scanning_ = false;
188};
189
190class OreScanSummaryPage final : public QWizardPage {
191 Q_OBJECT
192public:
193 explicit OreScanSummaryPage(OreImportWizard* wizard);
194 void initializePage() override;
195
196private slots:
197 void onExclusionAdded();
198 void onExclusionRemoved();
199
200private:
201 void refreshSummary();
202
203 OreImportWizard* wizard_;
204 QLabel* summaryLabel_;
205 QListWidget* exclusionList_;
206 QLineEdit* exclusionEdit_;
207 QPushButton* addBtn_;
208 QPushButton* removeBtn_;
209 QLabel* hierarchyLabel_;
210};
211
212class OreCurrencyPage final : public QWizardPage {
213 Q_OBJECT
214
215private:
216 inline static std::string_view logger_name = "ores.qt.ore_currency_page";
217 [[nodiscard]] static auto& lg() {
218 using namespace ores::logging;
219 static auto instance = make_logger(logger_name);
220 return instance;
221 }
222
223public:
224 explicit OreCurrencyPage(OreImportWizard* wizard);
225 void initializePage() override;
226
227private slots:
228 void onFetchFinished();
229 void onModeChanged();
230
231private:
232 OreImportWizard* wizard_;
233 QRadioButton* allRadio_;
234 QRadioButton* missingRadio_;
235 QLabel* statusLabel_;
236 QLabel* countLabel_;
237 bool fetchDone_ = false;
238};
239
240class OrePortfolioPage final : public QWizardPage {
241 Q_OBJECT
242
243private:
244 inline static std::string_view logger_name = "ores.qt.ore_portfolio_page";
245 [[nodiscard]] static auto& lg() {
246 using namespace ores::logging;
247 static auto instance = make_logger(logger_name);
248 return instance;
249 }
250
251public:
252 explicit OrePortfolioPage(OreImportWizard* wizard);
253 void initializePage() override;
254 bool validatePage() override;
255
256private slots:
257 void onCreateParentToggled(bool checked);
258 void onPortfoliosFetchFinished();
259
260private:
261 OreImportWizard* wizard_;
262 QLabel* parentContextLabel_{nullptr}; // shown when parent is pre-selected
263 QCheckBox* createParentCheck_;
264 QComboBox* parentCombo_;
265 QLabel* hierarchyPreviewLabel_;
266 QRadioButton* addTradesRadio_;
267 QRadioButton* newVersionsRadio_;
268 bool fetchDone_ = false;
269};
270
271class OreTradeImportPage final : public QWizardPage {
272 Q_OBJECT
273
274private:
275 inline static std::string_view logger_name = "ores.qt.ore_trade_import_page";
276 [[nodiscard]] static auto& lg() {
277 using namespace ores::logging;
278 static auto instance = make_logger(logger_name);
279 return instance;
280 }
281
282public:
283 explicit OreTradeImportPage(OreImportWizard* wizard);
284 void initializePage() override;
285 bool isComplete() const override;
286 bool validatePage() override;
287
288private slots:
289 void onActivityTypesFetchFinished();
290 void onCounterpartiesFetchFinished();
291 void onImportFinished();
292
293private:
294 void startImport();
295 void appendLog(const QString& msg);
296
297 OreImportWizard* wizard_;
298 QLineEdit* tradeDateEdit_;
299 QComboBox* lifecycleEventCombo_;
300 QComboBox* defaultCounterpartyCombo_;
301 QLabel* counterpartyStatusLabel_;
302 QLabel* statusLabel_;
303 QProgressBar* progressBar_;
304 QTextEdit* logOutput_;
305 bool importDone_ = false;
306 bool importStarted_ = false;
307};
308
309class OreDonePage final : public QWizardPage {
310 Q_OBJECT
311public:
312 explicit OreDonePage(OreImportWizard* wizard);
313 void initializePage() override;
314private:
315 OreImportWizard* wizard_;
316 QLabel* summaryLabel_;
317};
318
319}
320
321#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
User-supplied choices that drive the import plan.
Definition import_choices.hpp:69
Complete, ready-to-execute import plan produced by ore_import_planner.
Definition ore_import_plan.hpp:37
Result of scanning an ORE directory for importable files.
Definition scan_result.hpp:31
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
7-page wizard for importing ORE directory data into OreStudio.
Definition OreImportWizard.hpp:59