ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientBusinessUnitModel.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_BUSINESS_UNIT_MODEL_HPP
21#define ORES_QT_CLIENT_BUSINESS_UNIT_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include <QAbstractTableModel>
26#include "ores.qt/AbstractClientModel.hpp"
27#include "ores.qt/ClientManager.hpp"
28#include "ores.qt/RecencyPulseManager.hpp"
29#include "ores.qt/RecencyTracker.hpp"
30#include "ores.logging/make_logger.hpp"
31#include "ores.refdata.api/domain/business_unit.hpp"
32
33namespace ores::qt {
34
35class ImageCache;
36
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.client_business_unit_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 BusinessCentreCode,
62 UnitCode,
63 UnitName,
64 Status,
65 Version,
66 ModifiedBy,
67 RecordedAt,
68 ColumnCount
69 };
70
71 explicit ClientBusinessUnitModel(ClientManager* clientManager,
72 ImageCache* imageCache,
73 QObject* parent = nullptr);
74 ~ClientBusinessUnitModel() override = default;
75
76 // QAbstractTableModel interface
77 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
78 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
79 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
80 QVariant headerData(int section, Qt::Orientation orientation,
81 int role = Qt::DisplayRole) const override;
82
86 void refresh();
87
94 const refdata::domain::business_unit* getUnit(int row) const;
95
99 void load_page(std::uint32_t offset, std::uint32_t limit);
100
104 std::uint32_t page_size() const { return page_size_; }
105
109 void set_page_size(std::uint32_t size);
110
114 std::uint32_t total_available_count() const { return total_available_count_; }
115
116signals:
125private slots:
126 void onUnitsLoaded();
127 void onPulseStateChanged(bool isOn);
128 void onPulsingComplete();
129
130private:
131 QVariant recency_foreground_color(const std::string& code) const;
132
133 struct FetchResult {
134 bool success;
135 std::vector<refdata::domain::business_unit> business_units;
136 std::uint32_t total_available_count;
137 QString error_message;
138 QString error_details;
139 };
140
141 void fetch_business_units(std::uint32_t offset, std::uint32_t limit);
142
143 ClientManager* clientManager_;
144 ImageCache* imageCache_;
145 std::vector<refdata::domain::business_unit> business_units_;
146 QFutureWatcher<FetchResult>* watcher_;
147 std::uint32_t page_size_{100};
148 std::uint32_t total_available_count_{0};
149 bool is_fetching_{false};
150
151 using BusinessUnitKeyExtractor = std::string(*)(const refdata::domain::business_unit&);
152 RecencyTracker<refdata::domain::business_unit, BusinessUnitKeyExtractor> recencyTracker_;
153 RecencyPulseManager* pulseManager_;
154};
155
156}
157
158#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
Model for displaying business units fetched from the server.
Definition ClientBusinessUnitModel.hpp:43
const refdata::domain::business_unit * getUnit(int row) const
Get business unit at the specified row.
Definition ClientBusinessUnitModel.cpp:303
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientBusinessUnitModel.cpp:291
void refresh()
Refresh business unit data from server asynchronously.
Definition ClientBusinessUnitModel.cpp:158
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientBusinessUnitModel.hpp:114
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientBusinessUnitModel.cpp:184
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientBusinessUnitModel.hpp:104
Column
Enumeration of table columns for type-safe column access.
Definition ClientBusinessUnitModel.hpp:60
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:53
Internal organizational unit within a party.
Definition business_unit.hpp:37