Skip to main content

KeymapSystem::KeymapManager

KeymapSystem::KeymapManager

Central manager for keyboard shortcut registration, resolution, and dispatch. More…

#include <KeymapManager.hpp>

Inherits from QObject

Public Signals

Name
void bindingsChanged()
Emitted when any binding changes (override set/cleared, action registered/removed).
void activeTargetChanged(EditorLib::EditorTypeId type_id, EditorLib::EditorInstanceId instance_id)
Emitted when the active target for a type changes (cycling or explicit set).

Public Functions

Name
KeymapManager(QObject * parent =[nullptr])
~KeymapManager() override
bool eventFilter(QObject * obj, QEvent * event) override
Application-wide event filter for keyboard dispatch.
void setEditorRegistry(EditorRegistry * registry)
Set the editor registry used for focus tracking.
void setDataManager(std::shared_ptr< DataManager > dm)
Set application DataManager for command-sequence execution (mutation / navigation).
bool registerAction(KeyActionDescriptor const & descriptor)
Register an action descriptor.
bool registerCommandAction(QString const & action_id, QString const & display_name, QString const & category, KeyActionScope const & scope, QKeySequence const & default_binding, commands::CommandSequenceDescriptor sequence)
Register a shortcut that executes a CommandSequenceDescriptor (command architecture).
bool unregisterAction(QString const & action_id)
Unregister an action by ID.
std::vector< KeyActionDescriptor > allActions() const
Get all registered action descriptors.
std::optional< KeyActionDescriptor > action(QString const & action_id) const
Get a specific action descriptor by ID.
QKeySequence bindingFor(QString const & action_id) const
Get the effective binding for an action (override if set, otherwise default).
bool isActionEnabled(QString const & action_id) const
Check whether an action is enabled.
void setUserOverride(QString const & action_id, QKeySequence const & key)
Set a user override for an action’s key binding.
void clearUserOverride(QString const & action_id)
Clear a user override, reverting to the default binding.
void clearAllOverrides()
Clear all user overrides.
void setActionEnabled(QString const & action_id, bool enabled)
Set whether an action is enabled.
std::vector< KeyConflict > detectConflicts() const
Detect all binding conflicts (same key + same scope).
std::optional< QString > resolveKeyPress(QKeySequence const & key, EditorLib::EditorTypeId const & focused_type_id) const
Resolve a key press to an action ID given the current context.
void registerAdapter(KeyActionAdapter * adapter)
Register a KeyActionAdapter for dispatch routing.
bool dispatchAction(QString const & action_id, EditorLib::EditorTypeId const & target_type_id, EditorLib::EditorInstanceId const & target_instance_id ={}) const
Dispatch an action to the appropriate adapter.
void cycleActiveTarget(EditorLib::EditorTypeId const & type_id)
Cycle the active target to the next adapter of the given type.
void setActiveTarget(EditorLib::EditorTypeId const & type_id, EditorLib::EditorInstanceId const & instance_id)
Set the active target instance for a given editor type.
EditorLib::EditorInstanceId activeTarget(EditorLib::EditorTypeId const & type_id) const
Get the active target instance for a given editor type.
std::vector< EditorLib::EditorInstanceId > adapterInstancesForType(EditorLib::EditorTypeId const & type_id) const
Get all registered adapters for a given editor type.
std::vector< KeymapOverrideEntry > exportOverrides() const
Export all user overrides for persistence.
void importOverrides(std::vector< KeymapOverrideEntry > const & overrides)
Import user overrides (e.g. from AppPreferencesData on startup).

Detailed Description

class KeymapSystem::KeymapManager;

Central manager for keyboard shortcut registration, resolution, and dispatch.

Responsibilities:

  • Action registry: stores all KeyActionDescriptors
  • Override management: merges defaults with user customizations
  • Conflict detection: reports same key bound to multiple actions in the same scope
  • Scope resolution: resolves key presses using priority order (EditorFocused > AlwaysRouted > Global)
  • Adapter routing: dispatches actions to registered KeyActionAdapters

When installed as a QApplication event filter, it intercepts key events and dispatches them through the scope resolution pipeline. When focus is in a text-input widget (QLineEdit, QTextEdit, etc.), keybindings are not dispatched so normal typing is not interrupted.

Public Signals Documentation

signal bindingsChanged

void bindingsChanged()

Emitted when any binding changes (override set/cleared, action registered/removed).

signal activeTargetChanged

void activeTargetChanged(
    EditorLib::EditorTypeId type_id,
    EditorLib::EditorInstanceId instance_id
)

Emitted when the active target for a type changes (cycling or explicit set).

Public Functions Documentation

function KeymapManager

explicit KeymapManager(
    QObject * parent =nullptr
)

function ~KeymapManager

~KeymapManager() override

function eventFilter

bool eventFilter(
    QObject * obj,
    QEvent * event
) override

Application-wide event filter for keyboard dispatch.

Intercepts QEvent::KeyPress events and applies scope resolution. If focus is in a text-input widget, matched shortcuts are not dispatched. If no action matches, the event passes through to Qt.

function setEditorRegistry

void setEditorRegistry(
    EditorRegistry * registry
)

Set the editor registry used for focus tracking.

Parameters:

function setDataManager

void setDataManager(
    std::shared_ptr< DataManager > dm
)

Set application DataManager for command-sequence execution (mutation / navigation).

Parameters:

function registerAction

bool registerAction(
    KeyActionDescriptor const & descriptor
)

Register an action descriptor.

Parameters:

  • descriptor The action metadata to register

Return: true if registered successfully, false if action_id already exists

Precondition:

  • descriptor.action_id must not be empty (enforcement: assert)
  • descriptor.scope.editor_type_id must be non-empty when scope.kind is AlwaysRouted or EditorFocused — an empty type_id is accepted silently but causes dispatchAction to match the wrong adapter class (enforcement: none)
  • descriptor.action_id must not already be registered; if it is, false is returned and the caller’s descriptor is silently ignored (enforcement: runtime_check)
  • descriptor.display_name should be non-empty for usable keybinding UI (enforcement: none)
  • descriptor.category should be non-empty for correct grouping in the keybinding editor (enforcement: none)

function registerCommandAction

bool registerCommandAction(
    QString const & action_id,
    QString const & display_name,
    QString const & category,
    KeyActionScope const & scope,
    QKeySequence const & default_binding,
    commands::CommandSequenceDescriptor sequence
)

Register a shortcut that executes a CommandSequenceDescriptor (command architecture).

Parameters:

  • sequence Serialized sequence; substitutions use ctx.runtime_variables (current_frame, current_time_key) populated from EditorRegistry via KeymapCommandBridge.

Return: true when registered (same duplicate rules as registerAction)

Precondition: When scope is AlwaysRouted or EditorFocused, scope.editor_type_id must be non-empty.

function unregisterAction

bool unregisterAction(
    QString const & action_id
)

Unregister an action by ID.

Parameters:

  • action_id The action to remove

Return: true if the action was found and removed

function allActions

std::vector< KeyActionDescriptor > allActions() const

Get all registered action descriptors.

function action

std::optional< KeyActionDescriptor > action(
    QString const & action_id
) const

Get a specific action descriptor by ID.

function bindingFor

QKeySequence bindingFor(
    QString const & action_id
) const

Get the effective binding for an action (override if set, otherwise default).

function isActionEnabled

bool isActionEnabled(
    QString const & action_id
) const

Check whether an action is enabled.

function setUserOverride

void setUserOverride(
    QString const & action_id,
    QKeySequence const & key
)

Set a user override for an action’s key binding.

Parameters:

  • action_id The action to override
  • key The new key sequence (empty to unbind)

function clearUserOverride

void clearUserOverride(
    QString const & action_id
)

Clear a user override, reverting to the default binding.

Parameters:

  • action_id The action to reset

function clearAllOverrides

void clearAllOverrides()

Clear all user overrides.

function setActionEnabled

void setActionEnabled(
    QString const & action_id,
    bool enabled
)

Set whether an action is enabled.

Parameters:

  • action_id The action to enable/disable
  • enabled Whether the action should be active

function detectConflicts

std::vector< KeyConflict > detectConflicts() const

Detect all binding conflicts (same key + same scope).

function resolveKeyPress

std::optional< QString > resolveKeyPress(
    QKeySequence const & key,
    EditorLib::EditorTypeId const & focused_type_id
) const

Resolve a key press to an action ID given the current context.

Parameters:

  • key The key sequence pressed
  • focused_type_id The editor type that currently has focus (may be empty)

Return: The action_id to dispatch, or std::nullopt if no match

Resolution order:

  1. EditorFocused actions for the focused editor type
  2. AlwaysRouted actions
  3. Global actions

function registerAdapter

void registerAdapter(
    KeyActionAdapter * adapter
)

Register a KeyActionAdapter for dispatch routing.

The adapter’s typeId() is used to route actions to the correct widget. Deregistration is automatic via QObject::destroyed.

function dispatchAction

bool dispatchAction(
    QString const & action_id,
    EditorLib::EditorTypeId const & target_type_id,
    EditorLib::EditorInstanceId const & target_instance_id ={}
) const

Dispatch an action to the appropriate adapter.

Parameters:

  • action_id The action to dispatch
  • target_type_id The editor type to route to
  • target_instance_id Optional specific instance (empty = first matching type)

Return: true if an adapter handled the action

function cycleActiveTarget

void cycleActiveTarget(
    EditorLib::EditorTypeId const & type_id
)

Cycle the active target to the next adapter of the given type.

Parameters:

  • type_id The editor type to cycle through

When multiple adapters of the same type are registered, AlwaysRouted actions dispatch to the “active target” for that type. This method advances the active target to the next adapter in registration order, wrapping around. If no active target is set, selects the first adapter.

Emits activeTargetChanged.

function setActiveTarget

void setActiveTarget(
    EditorLib::EditorTypeId const & type_id,
    EditorLib::EditorInstanceId const & instance_id
)

Set the active target instance for a given editor type.

Parameters:

  • type_id The editor type
  • instance_id The instance to make active (empty to clear)

Emits activeTargetChanged.

function activeTarget

EditorLib::EditorInstanceId activeTarget(
    EditorLib::EditorTypeId const & type_id
) const

Get the active target instance for a given editor type.

Parameters:

  • type_id The editor type to query

Return: The active instance ID, or invalid if none set

function adapterInstancesForType

std::vector< EditorLib::EditorInstanceId > adapterInstancesForType(
    EditorLib::EditorTypeId const & type_id
) const

Get all registered adapters for a given editor type.

Parameters:

  • type_id The editor type to query

Return: List of (instance_id, adapter) pairs

function exportOverrides

std::vector< KeymapOverrideEntry > exportOverrides() const

Export all user overrides for persistence.

function importOverrides

void importOverrides(
    std::vector< KeymapOverrideEntry > const & overrides
)

Import user overrides (e.g. from AppPreferencesData on startup).


Updated on 2026-11-13 at 20:25:42 +0000