ORE Studio 0.0.4
Loading...
Searching...
No Matches
PortfolioExplorerTreeModel.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_PORTFOLIO_EXPLORER_TREE_MODEL_HPP
21#define ORES_QT_PORTFOLIO_EXPLORER_TREE_MODEL_HPP
22
23#include <memory>
24#include <vector>
25#include <optional>
26#include <unordered_map>
27#include <QString>
28#include <QAbstractItemModel>
29#include <boost/uuid/uuid.hpp>
30#include "ores.logging/make_logger.hpp"
31#include "ores.refdata.api/domain/portfolio.hpp"
32#include "ores.refdata.api/domain/book.hpp"
33
34namespace ores::qt {
35
43 enum class Kind { Party, Portfolio, Book };
44
45 Kind kind;
46 QString party_name; // valid when kind == Party
47 refdata::domain::portfolio portfolio; // valid when kind == Portfolio
48 refdata::domain::book book; // valid when kind == Book
49 PortfolioTreeNode* parent = nullptr;
50 std::vector<std::unique_ptr<PortfolioTreeNode>> children;
51 int row_in_parent = 0;
52};
53
58 std::optional<boost::uuids::uuid> book_id;
59 std::optional<boost::uuids::uuid> portfolio_id;
60};
61
69class PortfolioExplorerTreeModel final : public QAbstractItemModel {
70 Q_OBJECT
71
72private:
73 inline static std::string_view logger_name =
74 "ores.qt.portfolio_explorer_tree_model";
75
76 [[nodiscard]] static auto& lg() {
77 using namespace ores::logging;
78 static auto instance = make_logger(logger_name);
79 return instance;
80 }
81
82public:
83 explicit PortfolioExplorerTreeModel(QObject* parent = nullptr);
84 ~PortfolioExplorerTreeModel() override = default;
85
93 void load(const QString& party_name,
94 std::vector<refdata::domain::portfolio> portfolios,
95 std::vector<refdata::domain::book> books);
96
105 TreeNodeFilter selected_filter(const QModelIndex& index) const;
106
113 void set_trade_count(const boost::uuids::uuid& book_id, std::uint32_t count);
114
115 // QAbstractItemModel interface
116 QModelIndex index(int row, int col,
117 const QModelIndex& parent = QModelIndex()) const override;
118 QModelIndex parent(const QModelIndex& index) const override;
119 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
120 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
121 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
122
126 PortfolioTreeNode* node_from_index(const QModelIndex& index) const;
127
128private:
129 void build_subtree(PortfolioTreeNode* parent_node,
130 const std::vector<refdata::domain::portfolio>& portfolios,
131 const std::vector<refdata::domain::book>& books,
132 const std::optional<boost::uuids::uuid>& parent_id);
133
134 QModelIndex find_book_index(const boost::uuids::uuid& id) const;
135 std::uint32_t subtree_count(const PortfolioTreeNode* node) const;
136
137 std::unique_ptr<PortfolioTreeNode> root_;
138 std::unordered_map<std::string, std::uint32_t> trade_counts_;
139};
140
141}
142
143#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
A single node in the portfolio/book tree.
Definition PortfolioExplorerTreeModel.hpp:42
Filter result from a tree node selection.
Definition PortfolioExplorerTreeModel.hpp:57
Tree model for the portfolio/book hierarchy.
Definition PortfolioExplorerTreeModel.hpp:69
void set_trade_count(const boost::uuids::uuid &book_id, std::uint32_t count)
Update the trade count for a book and refresh its display.
Definition PortfolioExplorerTreeModel.cpp:136
void load(const QString &party_name, std::vector< refdata::domain::portfolio > portfolios, std::vector< refdata::domain::book > books)
Rebuild the tree from raw portfolio and book data.
Definition PortfolioExplorerTreeModel.cpp:33
PortfolioTreeNode * node_from_index(const QModelIndex &index) const
Returns the node for a given index, or nullptr if invalid.
Definition PortfolioExplorerTreeModel.cpp:171
TreeNodeFilter selected_filter(const QModelIndex &index) const
Returns the filter for the selected index.
Definition PortfolioExplorerTreeModel.cpp:107
Operational ledger leaf that holds trades.
Definition book.hpp:37
Logical aggregation node for risk and reporting.
Definition portfolio.hpp:37