ORE Studio 0.0.4
Loading...
Searching...
No Matches
InstrumentFormRegistry.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_INSTRUMENT_FORM_REGISTRY_HPP
21#define ORES_QT_INSTRUMENT_FORM_REGISTRY_HPP
22
23#include <functional>
24#include <map>
25#include <vector>
26#include <QString>
27#include <QWidget>
28#include "ores.trading.api/domain/product_type.hpp"
29
30namespace ores::qt {
31
32class IInstrumentForm;
33
48public:
49 using product_type = ores::trading::domain::product_type;
50 using Factory = std::function<IInstrumentForm*(QWidget* parent)>;
51
52 // --- per-family registration ---
53
54 void registerForm(product_type pt, QString displayName, Factory factory);
55
56 [[nodiscard]] bool contains(product_type pt) const noexcept;
57 [[nodiscard]] IInstrumentForm* createForm(
58 product_type pt, QWidget* parent) const;
59 [[nodiscard]] QString displayName(product_type pt) const;
60 [[nodiscard]] std::vector<product_type> registeredTypes() const;
61
62 // --- per-trade-type-code registration ---
63
65 void registerTypeForm(const QString& trade_type_code, Factory factory);
66
67 [[nodiscard]] bool containsTypeForm(
68 const QString& trade_type_code) const noexcept;
69 [[nodiscard]] IInstrumentForm* createTypeForm(
70 const QString& trade_type_code, QWidget* parent) const;
71
73 [[nodiscard]] std::vector<QString> registeredTypeCodes() const;
74
75private:
76 struct Entry {
77 QString displayName;
78 Factory factory;
79 };
80 std::vector<product_type> order_;
81 std::map<product_type, Entry> entries_;
82
83 struct TypeEntry { Factory factory; };
84 std::vector<QString> typeOrder_;
85 std::map<QString, TypeEntry> typeEntries_;
86};
87
96
97}
98
99#endif
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
void register_default_forms(InstrumentFormRegistry &registry)
Register every shipping instrument form on registry.
Definition InstrumentFormRegistry.cpp:93
Pure-virtual interface implemented by every per-family instrument form widget hosted in TradeDetailDi...
Definition IInstrumentForm.hpp:73
Maps instrument families and specific trade type codes to form widget factories.
Definition InstrumentFormRegistry.hpp:47
std::vector< QString > registeredTypeCodes() const
All registered type codes, in registration order.
Definition InstrumentFormRegistry.cpp:89
void registerTypeForm(const QString &trade_type_code, Factory factory)
Register a dedicated form for a single trade type code.
Definition InstrumentFormRegistry.cpp:70