ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientRoleModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 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_ROLE_MODEL_HPP
21#define ORES_QT_CLIENT_ROLE_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include <QAbstractTableModel>
26#include "ores.qt/ClientManager.hpp"
27#include "ores.logging/make_logger.hpp"
28#include "ores.iam/domain/role.hpp"
29
30namespace ores::qt {
31
38class ClientRoleModel final : public QAbstractTableModel {
39 Q_OBJECT
40
41private:
42 inline static std::string_view logger_name =
43 "ores.qt.client_role_model";
44
45 [[nodiscard]] static auto& lg() {
46 using namespace ores::logging;
47 static auto instance = make_logger(logger_name);
48 return instance;
49 }
50
51public:
52 explicit ClientRoleModel(ClientManager* clientManager,
53 QObject* parent = nullptr);
54 ~ClientRoleModel() override = default;
55
56 // QAbstractTableModel interface
57 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
58 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
59 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
60 QVariant headerData(int section, Qt::Orientation orientation,
61 int role = Qt::DisplayRole) const override;
62
66 void refresh();
67
74 const iam::domain::role* getRole(int row) const;
75
81 std::vector<iam::domain::role> getRoles() const;
82
83signals:
87 void dataLoaded();
88
92 void loadError(const QString& error_message, const QString& details = {});
93
94private slots:
95 void onRolesLoaded();
96
97private:
101 enum Column {
102 Name,
103 Description,
104 PermissionCount,
105 Version,
106 RecordedBy,
107 RecordedAt,
108 ColumnCount
109 };
110
111 struct FetchResult {
112 bool success;
113 std::vector<iam::domain::role> roles;
114 QString error_message;
115 QString error_details;
116 };
117
118 using FutureWatcherResult = FetchResult;
119
120 ClientManager* clientManager_;
121 std::vector<iam::domain::role> roles_;
122 QFutureWatcher<FutureWatcherResult>* watcher_;
123 bool is_fetching_{false};
124};
125
126}
127
128#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Represents a named collection of permissions that can be assigned to accounts.
Definition role.hpp:39
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
Model for displaying roles fetched from the server via client.
Definition ClientRoleModel.hpp:38
void refresh()
Refresh role data from server asynchronously.
Definition ClientRoleModel.cpp:100
void dataLoaded()
Emitted when data has been successfully loaded.
std::vector< iam::domain::role > getRoles() const
Get all roles.
Definition ClientRoleModel.cpp:191
void loadError(const QString &error_message, const QString &details={})
Emitted when an error occurs during data loading.
const iam::domain::role * getRole(int row) const
Get role at the specified row.
Definition ClientRoleModel.cpp:184