ORE Studio 0.0.4
Loading...
Searching...
No Matches
OrgExplorerTreeModel.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_TREE_MODEL_HPP
21#define ORES_QT_ORG_EXPLORER_TREE_MODEL_HPP
22
23#include <cstdint>
24#include <memory>
25#include <vector>
26#include <optional>
27#include <unordered_map>
28#include <QString>
29#include <QAbstractItemModel>
30#include <boost/uuid/uuid.hpp>
31#include "ores.logging/make_logger.hpp"
32#include "ores.refdata.api/domain/business_unit.hpp"
33#include "ores.refdata.api/domain/book.hpp"
34
35namespace ores::qt {
36
44 std::optional<boost::uuids::uuid> book_id;
45 std::optional<boost::uuids::uuid> business_unit_id;
46};
47
57 enum class Kind { Party, BusinessUnit, Book };
58
59 Kind kind;
60 QString party_name; // valid when kind == Party
61 refdata::domain::business_unit unit; // valid when kind == BusinessUnit
62 refdata::domain::book book; // valid when kind == Book
63 OrgTreeNode* parent = nullptr;
64 std::vector<std::unique_ptr<OrgTreeNode>> children;
65 int row_in_parent = 0;
66};
67
77class OrgExplorerTreeModel final : public QAbstractItemModel {
78 Q_OBJECT
79
80private:
81 inline static std::string_view logger_name =
82 "ores.qt.org_explorer_tree_model";
83
84 [[nodiscard]] static auto& lg() {
85 using namespace ores::logging;
86 static auto instance = make_logger(logger_name);
87 return instance;
88 }
89
90public:
91 explicit OrgExplorerTreeModel(QObject* parent = nullptr);
92 ~OrgExplorerTreeModel() override = default;
93
101 void load(const QString& party_name,
102 std::vector<refdata::domain::business_unit> units,
103 std::vector<refdata::domain::book> books);
104
112 OrgTreeNodeFilter selected_filter(const QModelIndex& index) const;
113
120 void set_trade_count(const boost::uuids::uuid& book_id, std::uint32_t count);
121
125 OrgTreeNode* node_from_index(const QModelIndex& index) const;
126
127 // QAbstractItemModel interface
128 QModelIndex index(int row, int col,
129 const QModelIndex& parent = QModelIndex()) const override;
130 QModelIndex parent(const QModelIndex& index) const override;
131 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
132 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
133 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
134
135private:
136 void build_unit_subtree(OrgTreeNode* parent_node,
137 const std::vector<refdata::domain::business_unit>& units,
138 const std::vector<refdata::domain::book>& books,
139 const std::optional<boost::uuids::uuid>& parent_unit_id);
140
141 QModelIndex find_book_index(const boost::uuids::uuid& id) const;
142 std::uint32_t subtree_count(const OrgTreeNode* node) const;
143
144 std::unique_ptr<OrgTreeNode> root_;
145 std::unordered_map<std::string, std::uint32_t> trade_counts_;
146};
147
148}
149
150#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Filter result from a tree node selection.
Definition OrgExplorerTreeModel.hpp:43
A single node in the organisational hierarchy tree.
Definition OrgExplorerTreeModel.hpp:56
Tree model for the organisational hierarchy.
Definition OrgExplorerTreeModel.hpp:77
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 OrgExplorerTreeModel.cpp:172
OrgTreeNodeFilter selected_filter(const QModelIndex &index) const
Returns the filter for the selected index.
Definition OrgExplorerTreeModel.cpp:134
OrgTreeNode * node_from_index(const QModelIndex &index) const
Returns the node for a given index, or nullptr if invalid.
Definition OrgExplorerTreeModel.cpp:206
void load(const QString &party_name, std::vector< refdata::domain::business_unit > units, std::vector< refdata::domain::book > books)
Rebuild the tree from raw business unit and book data.
Definition OrgExplorerTreeModel.cpp:33
Operational ledger leaf that holds trades.
Definition book.hpp:37
Internal organizational unit within a party.
Definition business_unit.hpp:37