nsbaci 1.0
Loading...
Searching...
No Matches
errorDialogFactory.h File Reference

Factory for creating error dialogs from UIError objects. More...

Include dependency graph for errorDialogFactory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  nsbaci::ui::ErrorDialogFactory
 Factory for creating error dialogs from UIError objects. More...

Namespaces

namespace  nsbaci
 Root namespace for the nsbaci application.
namespace  nsbaci::ui
 User interface namespace for nsbaci.

Detailed Description

Factory for creating error dialogs from UIError objects.

This module provides a factory that converts UIError objects into ready-to-show QMessageBox dialogs. It is private to the UI layer.

Overview

The ErrorDialogFactory operates in two modes:

1. Deferred Mode (Factory Pattern)

Returns a DialogInvoker - a callable (std::function) that encapsulates all dialog data but does NOT show the dialog immediately. The caller decides when to invoke it. This is similar to a "lazy evaluation" or "thunk" pattern.

// Create the invoker (dialog is NOT shown yet)
auto dialogInvoker = ErrorDialogFactory::getDialogFromUIError(error, this);
// ... do other work, validation, logging, etc.
// Show the dialog when ready (blocks until user clicks)
QMessageBox::StandardButton clicked = dialogInvoker();
// React to user choice
if (clicked == QMessageBox::Close) {
QApplication::quit();
}

2. Immediate Mode (Convenience)

Shows the dialog immediately and returns the result. Internally, this creates an invoker and calls it right away. Use this when you don't need to defer the dialog display.

// Show immediately - blocks until user clicks
ErrorDialogFactory::showError(error, this);
// Or capture the result
auto clicked = ErrorDialogFactory::showError(error, this);

Why Return Callables?

The DialogInvoker pattern provides:

  • Separation of concerns: Factory knows HOW to build, caller knows WHEN to show
  • Deferred execution: Prepare dialogs ahead of time, show when appropriate
  • User response handling: The return value indicates which button was clicked
  • Flexibility: Batch prepare multiple dialogs, show conditionally, etc.

The callable captures all necessary data by value, so the original UIError can be destroyed before the dialog is shown.

Author
Nicolás Serrano García