ORE Studio 0.0.4
Loading...
Searching...
No Matches
AccountDetailDialog.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_ACCOUNT_DETAIL_DIALOG_HPP
21#define ORES_QT_ACCOUNT_DETAIL_DIALOG_HPP
22
23#include <QToolBar>
24#include <QAction>
25#include <memory>
26#include <optional>
27#include "ores.iam.api/domain/account.hpp"
28#include "ores.iam.api/domain/login_info.hpp"
29#include "ores.qt/ClientManager.hpp"
30#include "ores.qt/AccountRolesWidget.hpp"
31#include "ores.qt/AccountPartiesWidget.hpp"
32#include "ores.qt/DetailDialogBase.hpp"
33#include "ores.logging/make_logger.hpp"
34
35
36namespace Ui {
37
38class AccountDetailDialog;
39
40}
41
42namespace ores::qt {
43
57 Q_OBJECT
58
59private:
60 inline static std::string_view logger_name =
61 "ores.qt.account_detail_dialog";
62
63 [[nodiscard]] static auto& lg() {
64 using namespace ores::logging;
65 static auto instance = make_logger(logger_name);
66 return instance;
67 }
68
69public:
70 explicit AccountDetailDialog(QWidget* parent = nullptr);
71 ~AccountDetailDialog() override;
72
73 void setClientManager(ClientManager* clientManager);
74 void setUsername(const std::string& username);
75
84 void setAccount(const iam::domain::account& account);
85
94 void setLoginInfo(const std::optional<iam::domain::login_info>& loginInfo);
95
101 [[nodiscard]] iam::domain::account getAccount() const;
102
106 void clearDialog();
107
111 void save();
112
126 void setReadOnly(bool readOnly, int versionNumber = 0);
127
135 void markAsStale();
136
140 [[nodiscard]] QString accountId() const;
141
142signals:
143 void accountUpdated(const boost::uuids::uuid& account_id);
144 void accountCreated(const boost::uuids::uuid& account_id);
145 void accountDeleted(const boost::uuids::uuid& account_id);
146 void isDirtyChanged(bool isDirty);
147
153
154protected:
155 QTabWidget* tabWidget() const override;
156 QWidget* provenanceTab() const override;
157 ProvenanceWidget* provenanceWidget() const override;
158 bool hasUnsavedChanges() const override { return isDirty_; }
159
160private slots:
161 void onSaveClicked();
162 void onResetClicked();
163 void onDeleteClicked();
164 void onRevertClicked();
165 void onFieldChanged();
166
167private:
168 void updateSaveResetButtonState();
169 void setCreateMode(bool createMode);
170 void setFieldsReadOnly(bool readOnly);
171 bool validatePassword() const;
172
173private:
174 std::unique_ptr<Ui::AccountDetailDialog> ui_;
175 bool isDirty_;
176 bool isAddMode_;
177 bool isReadOnly_;
178 bool isStale_;
179 int historicalVersion_;
180 std::string modifiedByUsername_;
181 QToolBar* toolBar_;
182 QAction* revertAction_;
183
184 ClientManager* clientManager_;
185 iam::domain::account currentAccount_;
186 std::optional<iam::domain::login_info> currentLoginInfo_;
187 AccountRolesWidget* rolesWidget_;
188 AccountPartiesWidget* partiesWidget_;
189};
190
191}
192
193#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Represents an account for an entity in the system.
Definition account.hpp:34
Dialog widget for creating and editing user accounts.
Definition AccountDetailDialog.hpp:56
iam::domain::account getAccount() const
Gets the current account state from the form.
Definition AccountDetailDialog.cpp:255
void revertRequested(const iam::domain::account &account)
Emitted when user requests to revert to the displayed historical version.
ProvenanceWidget * provenanceWidget() const override
Returns the promoted ProvenanceWidget (named "provenanceWidget" in .ui).
Definition AccountDetailDialog.cpp:190
bool hasUnsavedChanges() const override
Definition AccountDetailDialog.hpp:158
QTabWidget * tabWidget() const override
Returns the dialog's QTabWidget (named "tabWidget" in .ui).
Definition AccountDetailDialog.cpp:188
void markAsStale()
Mark the dialog data as stale.
Definition AccountDetailDialog.cpp:870
void setReadOnly(bool readOnly, int versionNumber=0)
Sets the dialog to read-only mode for viewing historical versions.
Definition AccountDetailDialog.cpp:813
void setAccount(const iam::domain::account &account)
Sets the account to display/edit.
Definition AccountDetailDialog.cpp:192
void save()
Saves the account (create or update).
Definition AccountDetailDialog.cpp:319
void setLoginInfo(const std::optional< iam::domain::login_info > &loginInfo)
Sets the login info to display (read-only).
Definition AccountDetailDialog.cpp:286
void clearDialog()
Clears all form fields and resets dialog state.
Definition AccountDetailDialog.cpp:264
QString accountId() const
Returns the account ID of the account being edited.
Definition AccountDetailDialog.cpp:884
QWidget * provenanceTab() const override
Returns the Provenance tab widget (named "provenanceTab" in .ui).
Definition AccountDetailDialog.cpp:189
Widget for managing parties assigned to an account.
Definition AccountPartiesWidget.hpp:48
Widget for managing roles assigned to an account.
Definition AccountRolesWidget.hpp:41
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Base class for all detail dialogs.
Definition DetailDialogBase.hpp:74
Widget displaying the 6 standard record provenance fields.
Definition ProvenanceWidget.hpp:39