ORE Studio 0.0.4
Loading...
Searching...
No Matches
Classes | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Static Protected Member Functions | List of all members
DetailDialogBase Class Referenceabstract

Base class for all detail dialogs. More...

#include <DetailDialogBase.hpp>

Inheritance diagram for DetailDialogBase:
Inheritance graph
Collaboration diagram for DetailDialogBase:
Collaboration graph

Classes

struct  change_reason_selection
 Result of a successful change reason prompt. More...
 

Signals

void closeRequested ()
 Emitted when the dialog wants to close its container window.
 
void statusMessage (const QString &message)
 Emitted to show a status message in the status bar.
 
void errorMessage (const QString &message)
 Emitted when an error occurs that should be shown to the user.
 

Public Member Functions

virtual bool hasUnsavedChanges () const
 
bool isCloseConfirmed () const
 Returns true if the user has already confirmed closing this dialog.
 
void setChangeReasonCache (ChangeReasonCache *cache)
 Inject the shared change reason cache.
 

Protected Slots

void onCloseClicked ()
 Called when the Close button is clicked.
 

Protected Member Functions

void requestClose ()
 Request closure of the container window.
 
void notifySaveSuccess (const QString &message)
 Notify that a save operation completed successfully.
 
virtual QTabWidget * tabWidget () const =0
 Returns the dialog's QTabWidget (named "tabWidget" in .ui).
 
virtual QWidget * provenanceTab () const =0
 Returns the Provenance tab widget (named "provenanceTab" in .ui).
 
virtual ProvenanceWidgetprovenanceWidget () const =0
 Returns the promoted ProvenanceWidget (named "provenanceWidget" in .ui).
 
void setProvenanceEnabled (bool enabled)
 Enable or disable the Provenance tab.
 
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.
 
void clearProvenance ()
 Clear all fields in the embedded ProvenanceWidget.
 
std::optional< change_reason_selectionpromptChangeReason (ChangeReasonDialog::OperationType opType, bool isDirty, std::string_view category="system")
 Show the change reason dialog and return the user's selection.
 

Static Protected Member Functions

template<typename T >
static std::optional< T > nulloptIfZero (T v)
 Return std::optional(v) when v is non-zero, std::nullopt otherwise.
 

Detailed Description

Base class for all detail dialogs.

Provides common functionality for detail dialogs including:

Tab / Provenance Pattern

Every derived dialog exposes its QTabWidget and provenance tab via three pure-virtual one-liners, then calls the shared helpers from its setCreateMode() and updateUiFrom*() implementations:

// In derived .hpp:
QTabWidget* tabWidget() const override { return ui_->tabWidget; }
QWidget* provenanceTab() const override { return ui_->provenanceTab; }
ProvenanceWidget* provenanceWidget() const override { return ui_->provenanceWidget; }
// In setCreateMode():
setProvenanceEnabled(!createMode);
// In updateUiFromEntity():
populateProvenance(entity_.version, entity_.modified_by, entity_.performed_by,
entity_.recorded_at, entity_.change_reason_code,
entity_.change_commentary);
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).
virtual QTabWidget * tabWidget() const =0
Returns the dialog's QTabWidget (named "tabWidget" in .ui).

Save Success Pattern

After a successful save operation, dialogs should:

  1. Emit their entity-specific "saved" signal (e.g., dimensionSaved)
  2. Call notifySaveSuccess() with a status message

Member Function Documentation

◆ hasUnsavedChanges()

virtual bool hasUnsavedChanges ( ) const
virtual

◆ isCloseConfirmed()

bool isCloseConfirmed ( ) const

Returns true if the user has already confirmed closing this dialog.

Set by onCloseClicked() after the user acknowledges unsaved changes. Used by DetachableMdiSubWindow::closeEvent() to avoid showing a second confirmation when the close was initiated via the dialog's Close button.

◆ setChangeReasonCache()

void setChangeReasonCache ( ChangeReasonCache cache)

Inject the shared change reason cache.

Controllers call this immediately after constructing any detail dialog. Once set, derived classes can call promptChangeReason() without passing the cache explicitly.

◆ closeRequested

void closeRequested ( )
signal

Emitted when the dialog wants to close its container window.

Controllers should connect this signal to the container window's close() slot to enable decoupled window management.

Here is the caller graph for this function:

◆ statusMessage

void statusMessage ( const QString &  message)
signal

Emitted to show a status message in the status bar.

Controllers should connect this signal to the main window's status bar.

Here is the caller graph for this function:

◆ onCloseClicked

void onCloseClicked ( )
protectedslot

Called when the Close button is clicked.

Warns the user if there are unsaved changes, then calls requestClose().

◆ tabWidget()

virtual QTabWidget * tabWidget ( ) const
protectedpure virtual

◆ provenanceTab()

virtual QWidget * provenanceTab ( ) const
protectedpure virtual

◆ provenanceWidget()

virtual ProvenanceWidget * provenanceWidget ( ) const
protectedpure virtual

◆ nulloptIfZero()

template<typename T >
static std::optional< T > nulloptIfZero ( v)
staticprotected

Return std::optional(v) when v is non-zero, std::nullopt otherwise.

Use when reading a spin box value that maps to a nullable database column where zero means "not set".

◆ setProvenanceEnabled()

void setProvenanceEnabled ( bool  enabled)
protected

Enable or disable the Provenance tab.

Call with false in create mode (no provenance data exists yet) and with true after loading an existing record.

◆ populateProvenance()

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 
)
protected

Populate the embedded ProvenanceWidget with entity data.

Parameters
recorded_atPass a default-constructed time_point to leave the Recorded At field blank for entities that do not track this column.

◆ promptChangeReason()

std::optional< DetailDialogBase::change_reason_selection > promptChangeReason ( ChangeReasonDialog::OperationType  opType,
bool  isDirty,
std::string_view  category = "system" 
)
protected

Show the change reason dialog and return the user's selection.

Handles all three operation types (Create, Amend, Delete) uniformly. Uses the cache injected via setChangeReasonCache(). Returns std::nullopt if the cache is not ready, no reasons are available, or the user cancels.

Usage in onSaveClicked():

const auto opType = createMode_
const auto sel = promptChangeReason(opType, hasChanges_,
createMode_ ? "system" : "common");
if (!sel) return;
entity_.change_reason_code = sel->reason_code;
entity_.change_commentary = sel->commentary;
@ Amend
Updating an existing entity.
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
Parameters
opTypeCreate, Amend, or Delete.
isDirtyWhether any fields have been modified (used by Amend to enable/disable the non-material-update reason).
categoryCategory code to filter reasons (default: "system" for Create; use "common" for Amend/Delete).