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
30class QTabWidget;
31
32namespace ores::qt {
33
34class ChangeReasonCache;
35class ProvenanceWidget;
36
74class DetailDialogBase : public QWidget {
75 Q_OBJECT
76
77public:
78 using QWidget::QWidget;
79 ~DetailDialogBase() override;
80
82 virtual bool hasUnsavedChanges() const { return false; }
83
91 bool isCloseConfirmed() const { return closeConfirmed_; }
92
100 void setChangeReasonCache(ChangeReasonCache* cache) { changeReasonCache_ = cache; }
101
102signals:
110
116 void statusMessage(const QString& message);
117
121 void errorMessage(const QString& message);
122
123protected slots:
129 void onCloseClicked();
130
131protected:
135 void requestClose() { emit closeRequested(); }
136
140 void notifySaveSuccess(const QString& message) {
141 emit statusMessage(message);
142 requestClose();
143 }
144
145 // -------------------------------------------------------------------------
146 // Pure-virtual accessors — each derived dialog provides one-liner overrides
147 // that return the corresponding widget from its own ui_ object.
148 // -------------------------------------------------------------------------
149
151 virtual QTabWidget* tabWidget() const = 0;
152
154 virtual QWidget* provenanceTab() const = 0;
155
157 virtual ProvenanceWidget* provenanceWidget() const = 0;
158
159 // -------------------------------------------------------------------------
160 // Shared helpers — call from setCreateMode() and updateUiFrom*()
161 // -------------------------------------------------------------------------
162
169 template<typename T>
170 static std::optional<T> nulloptIfZero(T v) {
171 return v != T{} ? std::optional<T>(v) : std::nullopt;
172 }
173
180 void setProvenanceEnabled(bool enabled);
181
189 void populateProvenance(int version,
190 const std::string& modified_by,
191 const std::string& performed_by,
192 std::chrono::system_clock::time_point recorded_at,
193 const std::string& change_reason_code,
194 const std::string& change_commentary);
195
197 void clearProvenance();
198
199 // -------------------------------------------------------------------------
200 // Change reason prompt — centralised for all operation types
201 // -------------------------------------------------------------------------
202
207 std::string reason_code;
208 std::string commentary;
209 };
210
236 std::optional<change_reason_selection>
238 bool isDirty,
239 std::string_view category = "system");
240
241private:
242 bool closeConfirmed_ = false;
243 ChangeReasonCache* changeReasonCache_ = nullptr;
244};
245
246}
247
248#endif
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Shared cache for change reasons used across all entity dialogs.
Definition ChangeReasonCache.hpp:47
OperationType
Type of operation requiring a change reason.
Definition ChangeReasonDialog.hpp:57
Base class for all detail dialogs.
Definition DetailDialogBase.hpp:74
virtual bool hasUnsavedChanges() const
Definition DetailDialogBase.hpp:82
void setProvenanceEnabled(bool enabled)
Enable or disable the Provenance tab.
Definition DetailDialogBase.cpp:34
void populateProvenance(int version, const std::string &modified_by, const std::string &performed_by, std::chrono::system_clock::time_point recorded_at, const std::string &change_reason_code, const std::string &change_commentary)
Populate the embedded ProvenanceWidget with entity data.
Definition DetailDialogBase.cpp:47
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:91
void notifySaveSuccess(const QString &message)
Notify that a save operation completed successfully.
Definition DetailDialogBase.hpp:140
static std::optional< T > nulloptIfZero(T v)
Return std::optional(v) when v is non-zero, std::nullopt otherwise.
Definition DetailDialogBase.hpp:170
void closeRequested()
Emitted when the dialog wants to close its container window.
std::optional< change_reason_selection > promptChangeReason(ChangeReasonDialog::OperationType opType, bool isDirty, std::string_view category="system")
Show the change reason dialog and return the user's selection.
Definition DetailDialogBase.cpp:67
void clearProvenance()
Clear all fields in the embedded ProvenanceWidget.
Definition DetailDialogBase.cpp:60
void requestClose()
Request closure of the container window.
Definition DetailDialogBase.hpp:135
void onCloseClicked()
Called when the Close button is clicked.
Definition DetailDialogBase.cpp:102
void setChangeReasonCache(ChangeReasonCache *cache)
Inject the shared change reason cache.
Definition DetailDialogBase.hpp:100
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:206
Widget displaying the 6 standard record provenance fields.
Definition ProvenanceWidget.hpp:39