ORE Studio 0.0.4
Loading...
Searching...
No Matches
DetailDialogBase.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_DETAIL_DIALOG_BASE_HPP
21#define ORES_QT_DETAIL_DIALOG_BASE_HPP
22
23#include <chrono>
24#include <optional>
25#include <string>
26#include <string_view>
27#include <QWidget>
28#include "ores.qt/ChangeReasonDialog.hpp"
29#include "ores.qt/export.hpp"
30
31class QTabWidget;
32
33namespace ores::qt {
34
35class ChangeReasonCache;
36class ProvenanceWidget;
37
75class ORES_QT_API DetailDialogBase : public QWidget {
76 Q_OBJECT
77
78public:
79 using QWidget::QWidget;
80 ~DetailDialogBase() override;
81
83 virtual bool hasUnsavedChanges() const { return false; }
84
92 bool isCloseConfirmed() const { return closeConfirmed_; }
93
101 void setChangeReasonCache(ChangeReasonCache* cache) { changeReasonCache_ = cache; }
102
103signals:
111
117 void statusMessage(const QString& message);
118
122 void errorMessage(const QString& message);
123
124protected slots:
130 void onCloseClicked();
131
132protected:
136 void requestClose() { emit closeRequested(); }
137
141 void notifySaveSuccess(const QString& message) {
142 emit statusMessage(message);
143 requestClose();
144 }
145
146 // -------------------------------------------------------------------------
147 // Pure-virtual accessors — each derived dialog provides one-liner overrides
148 // that return the corresponding widget from its own ui_ object.
149 // -------------------------------------------------------------------------
150
152 virtual QTabWidget* tabWidget() const = 0;
153
155 virtual QWidget* provenanceTab() const = 0;
156
158 virtual ProvenanceWidget* provenanceWidget() const = 0;
159
160 // -------------------------------------------------------------------------
161 // Shared helpers — call from setCreateMode() and updateUiFrom*()
162 // -------------------------------------------------------------------------
163
170 template<typename T>
171 static std::optional<T> nulloptIfZero(T v) {
172 return v != T{} ? std::optional<T>(v) : std::nullopt;
173 }
174
181 void setProvenanceEnabled(bool enabled);
182
190 void populateProvenance(int version,
191 const std::string& modified_by,
192 const std::string& performed_by,
193 std::chrono::system_clock::time_point recorded_at,
194 const std::string& change_reason_code,
195 const std::string& change_commentary);
196
198 void clearProvenance();
199
200 // -------------------------------------------------------------------------
201 // Change reason prompt — centralised for all operation types
202 // -------------------------------------------------------------------------
203
208 std::string reason_code;
209 std::string commentary;
210 };
211
237 std::optional<change_reason_selection>
238 promptChangeReason(ChangeReasonDialog::OperationType opType,
239 bool isDirty,
240 std::string_view category = "system");
241
242private:
243 bool closeConfirmed_ = false;
244 ChangeReasonCache* changeReasonCache_ = nullptr;
245};
246
247}
248
249#endif
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Shared cache for change reasons used across all entity dialogs.
Definition ChangeReasonCache.hpp:48
OperationType
Type of operation requiring a change reason.
Definition ChangeReasonDialog.hpp:58
Base class for all detail dialogs.
Definition DetailDialogBase.hpp:75
virtual bool hasUnsavedChanges() const
Definition DetailDialogBase.hpp:83
virtual ProvenanceWidget * provenanceWidget() const =0
Returns the promoted ProvenanceWidget (named "provenanceWidget" in .ui).
virtual QWidget * provenanceTab() const =0
Returns the Provenance tab widget (named "provenanceTab" in .ui).
void statusMessage(const QString &message)
Emitted to show a status message in the status bar.
virtual QTabWidget * tabWidget() const =0
Returns the dialog's QTabWidget (named "tabWidget" in .ui).
bool isCloseConfirmed() const
Returns true if the user has already confirmed closing this dialog.
Definition DetailDialogBase.hpp:92
void notifySaveSuccess(const QString &message)
Notify that a save operation completed successfully.
Definition DetailDialogBase.hpp:141
static std::optional< T > nulloptIfZero(T v)
Return std::optional(v) when v is non-zero, std::nullopt otherwise.
Definition DetailDialogBase.hpp:171
void closeRequested()
Emitted when the dialog wants to close its container window.
void requestClose()
Request closure of the container window.
Definition DetailDialogBase.hpp:136
void setChangeReasonCache(ChangeReasonCache *cache)
Inject the shared change reason cache.
Definition DetailDialogBase.hpp:101
void errorMessage(const QString &message)
Emitted when an error occurs that should be shown to the user.
Result of a successful change reason prompt.
Definition DetailDialogBase.hpp:207
Widget displaying the 6 standard record provenance fields.
Definition ProvenanceWidget.hpp:40