ORE Studio 0.0.4
Loading...
Searching...
No Matches
Signals | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EntityController Class Referenceabstract

Abstract base class for entity controllers. More...

#include <EntityController.hpp>

Inheritance diagram for EntityController:
Inheritance graph
Collaboration diagram for EntityController:
Collaboration graph

Signals

void statusMessage (const QString &message)
 Emitted when a status message should be shown to the user.
 
void errorMessage (const QString &message)
 Emitted when an error message should be shown to the user.
 
void detachableWindowCreated (DetachableMdiSubWindow *window)
 Emitted when a detachable window is created by this controller.
 
void detachableWindowDestroyed (DetachableMdiSubWindow *window)
 Emitted when a detachable window managed by this controller is destroyed.
 

Public Member Functions

 EntityController (QMainWindow *mainWindow, QMdiArea *mdiArea, ClientManager *clientManager, const QString &username, std::string_view eventName={}, QObject *parent=nullptr)
 Constructs an entity controller.
 
void setClientManager (ClientManager *clientManager, const QString &username)
 Updates the client manager and username (e.g. after re-login).
 
void setUsername (const QString &username)
 Updates just the username.
 
virtual void showListWindow ()=0
 Shows the main list window for this entity. Must be implemented by derived classes.
 
virtual void closeAllWindows ()=0
 Closes all windows managed by this controller. Must be implemented by derived classes.
 
void setAutoReloadOnSave (bool enabled)
 Sets whether the list window should auto-reload after save/delete.
 

Protected Member Functions

QString build_window_key (const QString &windowType, const QString &identifier) const
 Generates a unique key for tracking windows.
 
bool try_reuse_window (const QString &key)
 Tries to reuse an existing window if one exists for the key.
 
void bring_window_to_front (DetachableMdiSubWindow *window)
 Activates the specified window, handling detached state.
 
void track_window (const QString &key, DetachableMdiSubWindow *window)
 Registers a window for tracking.
 
void untrack_window (const QString &key)
 Unregisters a window from tracking.
 
void show_managed_window (DetachableMdiSubWindow *window, DetachableMdiSubWindow *referenceWindow=nullptr, QPoint offset=QPoint(30, 30))
 Shows a window in the MDI area, handling detach state.
 
void connect_dialog_close (DetailDialogBase *dialog, DetachableMdiSubWindow *window)
 Connects a dialog's closeRequested signal to the window's close slot.
 
void register_detachable_window (DetachableMdiSubWindow *window)
 Registers a detachable window and emits detachableWindowCreated signal.
 
virtual EntityListMdiWindowlistWindow () const
 Returns the list window for marking as stale on notifications.
 
virtual void reloadListWindow ()=0
 Reloads the list window. Must be implemented by derived classes.
 
void handleEntitySaved ()
 Called when an entity is saved.
 
void handleEntityDeleted ()
 Called when an entity is deleted.
 

Protected Attributes

QMainWindow * mainWindow_
 
QMdiArea * mdiArea_
 
ClientManagerclientManager_
 
QString username_
 
QMap< QString, DetachableMdiSubWindow * > managed_windows_
 Map of active windows indexed by unique key.
 
bool autoReloadOnSave_ = false
 Whether to auto-reload the list window after save/delete. Default: false.
 

Detailed Description

Abstract base class for entity controllers.

Entity controllers manage the lifecycle of windows related to specific data entities (like currencies, accounts, etc.). This base class provides common functionality for managing windows, tracking them for reuse, and handling the client connection.

Constructor & Destructor Documentation

◆ EntityController()

EntityController ( QMainWindow *  mainWindow,
QMdiArea *  mdiArea,
ClientManager clientManager,
const QString &  username,
std::string_view  eventName = {},
QObject *  parent = nullptr 
)

Constructs an entity controller.

Parameters
mainWindowParent main window.
mdiAreaMDI area for displaying windows.
clientManagerClient manager for network operations.
usernameCurrently logged in user.
eventNameEvent name to subscribe to for change notifications. Pass empty string_view to disable event subscription.
parentQObject parent.

Member Function Documentation

◆ showListWindow()

virtual void showListWindow ( )
pure virtual

◆ closeAllWindows()

virtual void closeAllWindows ( )
pure virtual

◆ setAutoReloadOnSave()

void setAutoReloadOnSave ( bool  enabled)

Sets whether the list window should auto-reload after save/delete.

Default is false (no auto-reload). This can be used to implement a user-configurable auto-reload preference in the future.

◆ detachableWindowCreated

void detachableWindowCreated ( DetachableMdiSubWindow window)
signal

Emitted when a detachable window is created by this controller.

MainWindow connects to this signal to track all detachable windows for the "Reattach All Windows" functionality.

Here is the caller graph for this function:

◆ build_window_key()

QString build_window_key ( const QString &  windowType,
const QString &  identifier 
) const
protected

Generates a unique key for tracking windows.

Parameters
windowTypeType of window (e.g., "details", "history").
identifierUnique ID of the entity (e.g., ISO code).
Returns
A string key for the window map.

◆ try_reuse_window()

bool try_reuse_window ( const QString &  key)
protected

Tries to reuse an existing window if one exists for the key.

Parameters
keyUnique window key.
Returns
true if window was found and activated, false otherwise.

◆ show_managed_window()

void show_managed_window ( DetachableMdiSubWindow window,
DetachableMdiSubWindow referenceWindow = nullptr,
QPoint  offset = QPoint(30, 30) 
)
protected

Shows a window in the MDI area, handling detach state.

This method adds the window to the MDI area, removes the maximize button, adjusts the size, and shows the window. If a reference window is provided and is detached, the new window will also be detached and positioned relative to the reference window.

Parameters
windowThe window to show.
referenceWindowOptional window to follow detach state from.
offsetPosition offset when detaching (default 30,30).

◆ connect_dialog_close()

void connect_dialog_close ( DetailDialogBase dialog,
DetachableMdiSubWindow window 
)
protected

Connects a dialog's closeRequested signal to the window's close slot.

Use this after creating a detail dialog to wire up decoupled window closing. The dialog can then call requestClose() instead of parentWidget()->close().

Parameters
dialogThe detail dialog.
windowThe container window to close when the dialog requests it.

◆ register_detachable_window()

void register_detachable_window ( DetachableMdiSubWindow window)
protected

Registers a detachable window and emits detachableWindowCreated signal.

Call this when creating a new detachable window. Also sets up the destroyed signal connection to automatically emit detachableWindowDestroyed.

Parameters
windowThe window to register.
Here is the caller graph for this function:

◆ listWindow()

virtual EntityListMdiWindow * listWindow ( ) const
protectedvirtual

Returns the list window for marking as stale on notifications.

Override in derived classes to return the list window pointer. This is used by the base class onNotificationReceived to call markAsStale().

Returns
Pointer to the list window, or nullptr if not available.

Reimplemented in CatalogController, DatasetBundleController, NatureDimensionController, OriginDimensionController, and TreatmentDimensionController.

◆ reloadListWindow()

virtual void reloadListWindow ( )
protectedpure virtual

◆ handleEntitySaved()

void handleEntitySaved ( )
protected

Called when an entity is saved.

If autoReloadOnSave_ is true, this will reload the list window. Call this from derived class signal handlers connected to entity saved signals.

◆ handleEntityDeleted()

void handleEntityDeleted ( )
protected

Called when an entity is deleted.

If autoReloadOnSave_ is true, this will reload the list window. Call this from derived class signal handlers connected to entity deleted signals.