ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientBusinessUnitTypeModel.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_TYPE_MODEL_HPP
21#define ORES_QT_CLIENT_BUSINESS_UNIT_TYPE_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_type.hpp"
32
33namespace ores::qt {
34
42 Q_OBJECT
43
44private:
45 inline static std::string_view logger_name =
46 "ores.qt.client_business_unit_type_model";
47
48 [[nodiscard]] static auto& lg() {
49 using namespace ores::logging;
50 static auto instance = make_logger(logger_name);
51 return instance;
52 }
53
54public:
58 enum Column {
59 Code,
60 Name,
61 Level,
62 CodingScheme,
63 Description,
64 Version,
65 ModifiedBy,
66 ColumnCount
67 };
68
69 explicit ClientBusinessUnitTypeModel(ClientManager* clientManager,
70 QObject* parent = nullptr);
71 ~ClientBusinessUnitTypeModel() override = default;
72
73 // QAbstractTableModel interface
74 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
75 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
76 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
77 QVariant headerData(int section, Qt::Orientation orientation,
78 int role = Qt::DisplayRole) const override;
79
83 void refresh();
84
91 const refdata::domain::business_unit_type* getType(int row) const;
92
96 void load_page(std::uint32_t offset, std::uint32_t limit);
97
101 std::uint32_t page_size() const { return page_size_; }
102
106 void set_page_size(std::uint32_t size);
107
111 std::uint32_t total_available_count() const { return total_available_count_; }
112
113signals:
122private slots:
123 void onTypesLoaded();
124 void onPulseStateChanged(bool isOn);
125 void onPulsingComplete();
126
127private:
128 QVariant recency_foreground_color(const std::string& code) const;
129
130 struct FetchResult {
131 bool success;
132 std::vector<refdata::domain::business_unit_type> types;
133 std::uint32_t total_available_count;
134 QString error_message;
135 QString error_details;
136 };
137
138 void fetch_types(std::uint32_t offset, std::uint32_t limit);
139
140 ClientManager* clientManager_;
141 std::vector<refdata::domain::business_unit_type> types_;
142 QFutureWatcher<FetchResult>* watcher_;
143 std::uint32_t page_size_{100};
144 std::uint32_t total_available_count_{0};
145 bool is_fetching_{false};
146
147 using BusinessUnitTypeKeyExtractor =
148 std::string(*)(const refdata::domain::business_unit_type&);
150 BusinessUnitTypeKeyExtractor> recencyTracker_;
151 RecencyPulseManager* pulseManager_;
152};
153
154}
155
156#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 unit types fetched from the server.
Definition ClientBusinessUnitTypeModel.hpp:41
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientBusinessUnitTypeModel.cpp:265
const refdata::domain::business_unit_type * getType(int row) const
Get business unit type at the specified row.
Definition ClientBusinessUnitTypeModel.cpp:277
void refresh()
Refresh business unit type data from server asynchronously.
Definition ClientBusinessUnitTypeModel.cpp:132
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientBusinessUnitTypeModel.hpp:111
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientBusinessUnitTypeModel.cpp:158
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientBusinessUnitTypeModel.hpp:101
Column
Enumeration of table columns for type-safe column access.
Definition ClientBusinessUnitTypeModel.hpp:58
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Classification of organisational unit roles within a hierarchy.
Definition business_unit_type.hpp:37