Skip to main content

SelectionContext

SelectionContext

Centralized selection and focus context for the application. More…

#include <SelectionContext.hpp>

Inherits from QObject

Public Signals

Name
void dataFocusChanged(SelectedDataKey const & data_key, QString const & data_type, SelectionSource const & source)
Emitted when data focus changes.
void widgetFocusChanged(EditorInstanceId const & instance_id)
Emitted when widget focus changes (keyboard shortcuts, etc.).
void timeFrameFocusChanged(QString const & time_key, SelectionSource const & source)
Emitted when TimeFrame focus changes.
void selectionChanged(SelectionSource const & source)
Emitted when data selection changes.
void entitySelectionChanged(SelectionSource const & source)
Emitted when entity selection changes.
void activeEditorChanged(EditorInstanceId const & instance_id)
Emitted when active editor changes.
void propertiesContextChanged()
Emitted when properties context changes.

Public Functions

Name
SelectionContext(QObject * parent =[nullptr])
Construct a new SelectionContext.
~SelectionContext() override =default
void setSelectedData(SelectedDataKey const & data_key, SelectionSource const & source)
Set the primary selected data key.
void addToSelection(SelectedDataKey const & data_key, SelectionSource const & source)
Add to the current selection (for multi-select).
void removeFromSelection(SelectedDataKey const & data_key, SelectionSource const & source)
Remove from current selection.
void clearSelection(SelectionSource const & source)
Clear all selections.
SelectedDataKey primarySelectedData() const
Get primary selected data key.
std::set< SelectedDataKey > allSelectedData() const
Get all selected data keys.
bool isSelected(SelectedDataKey const & data_key) const
Check if specific data is selected.
void setSelectedEntities(std::vector< int64_t > const & entity_ids, SelectionSource const & source)
Set selected entities within current data.
void addSelectedEntities(std::vector< int64_t > const & entity_ids, SelectionSource const & source)
Add entities to selection.
void clearEntitySelection(SelectionSource const & source)
Clear entity selection.
std::vector< int64_t > selectedEntities() const
Get selected entity IDs.
bool isEntitySelected(int64_t entity_id) const
Check if a specific entity is selected.
void setDataFocus(SelectedDataKey const & data_key, QString const & data_type, SelectionSource const & source)
Set the data focus without changing widget focus.
SelectedDataKey dataFocus() const
Get current data focus key.
QString dataFocusType() const
Get the type of the focused data.
void setTimeFrameFocus(QString const & time_key, SelectionSource const & source)
Set the focused TimeFrame key.
QString timeFrameFocus() const
Get the currently focused TimeFrame key.
void setActiveEditor(EditorInstanceId const & instance_id)
Set the currently active (focused) editor.
EditorInstanceId activeEditorId() const
Get the active editor instance ID.
PropertiesContext propertiesContext() const
Get current properties context.
void notifyInteraction(EditorInstanceId const & editor_instance_id)
Notify that an editor had meaningful user interaction.
void setSelectedDataType(QString const & data_type)
Set data type for properties context.
void registerAction(ContextAction action)
Register a context-aware action.
void removeAction(QString const & action_id)
Remove a previously registered action.
std::vector< ContextAction const * > applicableActions() const
Get all actions applicable to the current context.

Detailed Description

class SelectionContext;

Centralized selection and focus context for the application.

SelectionContext is a singleton-like object (owned by WorkspaceManager) that manages application-wide selection state. All widgets that need to know about or modify selection should interact with SelectionContext.

Key Concepts

Data Focus (Phase 1 Refactoring - Passive Awareness)

“Data Focus” represents what data the user is currently working with, separate from which widget has keyboard focus. When data focus changes, all “passively aware” widgets update their content accordingly.

Widget Focus

Which editor/widget has keyboard focus. This affects keyboard shortcuts but does NOT automatically change property panels.

Data Selection (Legacy)

One or more data objects (by key) can be selected. There is always a “primary” selection which is the most recently selected item.

Entity Selection

Within the currently selected data, specific entities can be selected. This is useful for line/mask/point data where each element has an EntityID.

Properties Context (Deprecated - Phase 6 removal)

Legacy mechanism for determining which properties panel to show. Being replaced by passive awareness pattern.

Usage Pattern


// Modern pattern - connect to dataFocusChanged for passive awareness
connect(_selection_context, &SelectionContext::dataFocusChanged,
        this, [this](auto key, auto type, auto source) {
            onDataFocusChanged(key, type);
        });

// Legacy pattern - still supported
connect(_selection_context, &SelectionContext::selectionChanged,
        this, &MyWidget::onSelectionChanged);

// Making a selection
SelectionSource source{_state->getInstanceId(), "my_table"};
_selection_context->setSelectedData("data_key", source);

// Querying selection
if (_selection_context->isSelected("data_key")) {
    highlightData("data_key");
}

Public Signals Documentation

signal dataFocusChanged

void dataFocusChanged(
    SelectedDataKey const & data_key,
    QString const & data_type,
    SelectionSource const & source
)

Emitted when data focus changes.

Parameters:

  • data_key The focused data key
  • data_type The type of the focused data (e.g., “LineData”)
  • source Who made the focus change

This is the PRIMARY signal for passive awareness pattern. Widgets connect to this to update their content based on the currently focused data, regardless of whether they are visible.

signal widgetFocusChanged

void widgetFocusChanged(
    EditorInstanceId const & instance_id
)

Emitted when widget focus changes (keyboard shortcuts, etc.).

Parameters:

  • instance_id Instance ID of the newly focused widget

This does NOT automatically change properties - that’s user choice. Use this for keyboard shortcut routing and similar widget-focus needs.

signal timeFrameFocusChanged

void timeFrameFocusChanged(
    QString const & time_key,
    SelectionSource const & source
)

Emitted when TimeFrame focus changes.

Parameters:

  • time_key The focused TimeFrame key (empty if cleared)
  • source Who made the focus change

This is a separate signal from dataFocusChanged because TimeFrame keys live in a different namespace than data keys.

signal selectionChanged

void selectionChanged(
    SelectionSource const & source
)

Emitted when data selection changes.

Parameters:

  • source Who made the selection change

signal entitySelectionChanged

void entitySelectionChanged(
    SelectionSource const & source
)

Emitted when entity selection changes.

Parameters:

  • source Who made the selection change

signal activeEditorChanged

void activeEditorChanged(
    EditorInstanceId const & instance_id
)

Emitted when active editor changes.

Parameters:

  • instance_id Instance ID of the new active editor

Note: For passive awareness, prefer connecting to dataFocusChanged and/or widgetFocusChanged instead.

signal propertiesContextChanged

void propertiesContextChanged()

Emitted when properties context changes.

Deprecated:

This signal is deprecated and will be removed in Phase 6. Use dataFocusChanged for passive widget updates instead.

PropertiesHost listens to this to switch property panels.

Public Functions Documentation

function SelectionContext

explicit SelectionContext(
    QObject * parent =nullptr
)

Construct a new SelectionContext.

Parameters:

  • parent Parent QObject (typically WorkspaceManager)

function ~SelectionContext

~SelectionContext() override =default

function setSelectedData

void setSelectedData(
    SelectedDataKey const & data_key,
    SelectionSource const & source
)

Set the primary selected data key.

Parameters:

  • data_key Key in DataManager
  • source Who is making this selection

This replaces any existing selection with a single item.

function addToSelection

void addToSelection(
    SelectedDataKey const & data_key,
    SelectionSource const & source
)

Add to the current selection (for multi-select).

Parameters:

  • data_key Key to add to selection
  • source Who is making this selection

The first selected item remains the primary selection.

function removeFromSelection

void removeFromSelection(
    SelectedDataKey const & data_key,
    SelectionSource const & source
)

Remove from current selection.

Parameters:

  • data_key Key to remove from selection
  • source Who is making this change

If the removed item was primary, the next item becomes primary.

function clearSelection

void clearSelection(
    SelectionSource const & source
)

Clear all selections.

Parameters:

  • source Who is clearing the selection

function primarySelectedData

SelectedDataKey primarySelectedData() const

Get primary selected data key.

Return: Primary selection, or invalid SelectedDataKey if nothing selected

function allSelectedData

std::set< SelectedDataKey > allSelectedData() const

Get all selected data keys.

Return: Set of all selected data keys

function isSelected

bool isSelected(
    SelectedDataKey const & data_key
) const

Check if specific data is selected.

Parameters:

  • data_key Key to check

Return: true if data_key is in the current selection

function setSelectedEntities

void setSelectedEntities(
    std::vector< int64_t > const & entity_ids,
    SelectionSource const & source
)

Set selected entities within current data.

Parameters:

  • entity_ids EntityIDs to select
  • source Who is making this selection

Entity selection is secondary to data selection. When data selection changes, entity selection is typically cleared.

function addSelectedEntities

void addSelectedEntities(
    std::vector< int64_t > const & entity_ids,
    SelectionSource const & source
)

Add entities to selection.

Parameters:

  • entity_ids EntityIDs to add
  • source Who is making this selection

function clearEntitySelection

void clearEntitySelection(
    SelectionSource const & source
)

Clear entity selection.

Parameters:

  • source Who is clearing

function selectedEntities

std::vector< int64_t > selectedEntities() const

Get selected entity IDs.

Return: Vector of selected EntityIDs

function isEntitySelected

bool isEntitySelected(
    int64_t entity_id
) const

Check if a specific entity is selected.

Parameters:

  • entity_id EntityID to check

Return: true if entity is selected

function setDataFocus

void setDataFocus(
    SelectedDataKey const & data_key,
    QString const & data_type,
    SelectionSource const & source
)

Set the data focus without changing widget focus.

Parameters:

  • data_key Key in DataManager
  • data_type Type of the data (e.g., “LineData”, “MaskData”)
  • source Who is making this selection

This is the primary mechanism for the “Passive Awareness” pattern. When data focus changes, all listening widgets should update their internal state and UI, regardless of whether they are currently visible.

This also updates the legacy selection API for backward compatibility.

function dataFocus

SelectedDataKey dataFocus() const

Get current data focus key.

Return: The focused data key, or invalid if nothing focused

function dataFocusType

QString dataFocusType() const

Get the type of the focused data.

Return: Type string (e.g., “LineData”, “MaskData”), or empty if nothing focused

function setTimeFrameFocus

void setTimeFrameFocus(
    QString const & time_key,
    SelectionSource const & source
)

Set the focused TimeFrame key.

Parameters:

TimeFrame objects are separate from data objects in DataManager. This provides a dedicated signal path so that TimeFrame keys are not confused with data keys.

Setting a timeframe focus clears the data focus and vice versa.

function timeFrameFocus

QString timeFrameFocus() const

Get the currently focused TimeFrame key.

Return: TimeFrame key, or empty string if none focused

function setActiveEditor

void setActiveEditor(
    EditorInstanceId const & instance_id
)

Set the currently active (focused) editor.

Parameters:

  • instance_id Instance ID of the active editor

Called when an editor gains focus. This affects:

  • Which editor receives keyboard shortcuts
  • Default target for actions

function activeEditorId

EditorInstanceId activeEditorId() const

Get the active editor instance ID.

Return: Instance ID, or invalid EditorInstanceId if none active

function propertiesContext

PropertiesContext propertiesContext() const

Get current properties context.

Return: Current PropertiesContext

Used by PropertiesHost to determine which properties panel to show.

function notifyInteraction

void notifyInteraction(
    EditorInstanceId const & editor_instance_id
)

Notify that an editor had meaningful user interaction.

Parameters:

  • editor_instance_id Instance ID of the interacted editor

“Meaningful” interaction includes:

  • Clicking on content (not just focus)
  • Modifying data
  • Using tools

This updates the properties context so the appropriate properties panel can be shown.

function setSelectedDataType

void setSelectedDataType(
    QString const & data_type
)

Set data type for properties context.

Parameters:

  • data_type Type string (e.g., “LineData”, “MaskData”)

Called when the selected data’s type is known, to help properties routing.

function registerAction

void registerAction(
    ContextAction action
)

Register a context-aware action.

Parameters:

  • action The action to register

Precondition:

  • action.action_id must not be empty
  • action.is_applicable must be callable
  • action.execute must be callable

Widgets call this at startup to advertise actions they can perform. Actions are evaluated against the current context when a consumer calls applicableActions().

function removeAction

void removeAction(
    QString const & action_id
)

Remove a previously registered action.

Parameters:

  • action_id The ID of the action to remove

function applicableActions

std::vector< ContextAction const * > applicableActions() const

Get all actions applicable to the current context.

Return: Vector of pointers to applicable ContextActions (non-owning)

Evaluates each registered action’s is_applicable predicate against the current SelectionContext state and returns those that pass.


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