ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientPartyModel.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_CLIENT_PARTY_MODEL_HPP
21#define ORES_QT_CLIENT_PARTY_MODEL_HPP
22
23#include <vector>
24#include <unordered_map>
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
27#include "ores.qt/AbstractClientModel.hpp"
28#include "ores.qt/ClientManager.hpp"
29#include "ores.qt/ImageCache.hpp"
30#include "ores.qt/RecencyPulseManager.hpp"
31#include "ores.qt/RecencyTracker.hpp"
32#include "ores.logging/make_logger.hpp"
33#include "ores.refdata.api/domain/party.hpp"
34
35namespace ores::qt {
36
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.client_party_model";
49
50 [[nodiscard]] static auto& lg() {
51 using namespace ores::logging;
52 static auto instance = make_logger(logger_name);
53 return instance;
54 }
55
56public:
60 enum Column {
61 BusinessCenterCode,
62 ShortCode,
63 Codename,
64 FullName,
65 TransliteratedName,
66 PartyCategory,
67 PartyType,
68 Status,
69 Version,
70 ModifiedBy,
71 RecordedAt,
72 ColumnCount
73 };
74
75 explicit ClientPartyModel(ClientManager* clientManager,
76 ImageCache* imageCache,
77 QObject* parent = nullptr);
78 ~ClientPartyModel() override = default;
79
80 // QAbstractTableModel interface
81 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
82 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
83 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
84 QVariant headerData(int section, Qt::Orientation orientation,
85 int role = Qt::DisplayRole) const override;
86
92 void refresh(bool replace = true);
93
100 void load_page(std::uint32_t offset, std::uint32_t limit);
101
108 const refdata::domain::party* getParty(int row) const;
109
113 std::uint32_t page_size() const { return page_size_; }
114
120 void set_page_size(std::uint32_t size);
121
125 std::uint32_t total_available_count() const { return total_available_count_; }
126
127signals:
136private slots:
137 void onPartysLoaded();
138 void onPulseStateChanged(bool isOn);
139 void onPulsingComplete();
140
141private:
142 QVariant recency_foreground_color(const std::string& code) const;
143
144 struct FetchResult {
145 bool success;
146 std::vector<refdata::domain::party> parties;
147 std::uint32_t total_available_count;
148 QString error_message;
149 QString error_details;
150 };
151
152 void fetch_parties(std::uint32_t offset, std::uint32_t limit);
153 void fetch_business_centres();
154
155 ClientManager* clientManager_;
156 ImageCache* imageCache_;
157 std::vector<refdata::domain::party> parties_;
158 QFutureWatcher<FetchResult>* watcher_;
159 std::uint32_t page_size_{100};
160 std::uint32_t total_available_count_{0};
161 bool is_fetching_{false};
162
163 using PartyKeyExtractor = std::string(*)(const refdata::domain::party&);
164 RecencyTracker<refdata::domain::party, PartyKeyExtractor> recencyTracker_;
165 RecencyPulseManager* pulseManager_;
166
167 std::unordered_map<std::string, std::string> bc_code_to_image_id_;
168};
169
170}
171
172#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Model for displaying parties fetched from the server.
Definition ClientPartyModel.hpp:43
const refdata::domain::party * getParty(int row) const
Get party at the specified row.
Definition ClientPartyModel.cpp:316
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientPartyModel.cpp:269
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientPartyModel.hpp:125
void refresh(bool replace=true)
Refresh party data from server asynchronously.
Definition ClientPartyModel.cpp:174
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of party data.
Definition ClientPartyModel.cpp:200
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientPartyModel.hpp:113
Column
Enumeration of table columns for type-safe column access.
Definition ClientPartyModel.hpp:60
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:53
An internal legal entity participating in financial transactions.
Definition party.hpp:37