wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
SceneItemRegistry Class Reference

Owns the id↔item bookkeeping for a Scene: the id-to-item map and the monotonically increasing last-assigned id. More...

#include <SceneItemRegistry.h>

Public Member Functions

bool contains (int id) const
 Returns true if an item is registered under id.
void forget (ItemWithId *item)
void forgetItemId (int id)
ItemWithId * itemById (int id) const
 Returns the item registered under id, or nullptr.
int lastId () const
 Returns the highest id assigned so far.
int nextId ()
 Returns a fresh, previously unused id.
void registerItem (ItemWithId *item)
 Registers item under its current id.
void setLastId (int newLastId)
 Raises the last-assigned id to newLastId (never lowers it).
void unregisterItem (ItemWithId *item)
 Removes item's mapping from the registry.
void updateItemId (ItemWithId *item, int newId)
 Pre-assigns newId to item before it is added (undo/redo restore path).
 ~SceneItemRegistry ()

Detailed Description

Owns the id↔item bookkeeping for a Scene: the id-to-item map and the monotonically increasing last-assigned id.

Extracted from Scene. Pure data structure with no back-reference to the scene; Scene forwards its itemById/nextId/register/… API here. Keeping the invariant (one id ↔ one live item) local makes the registry independently testable.

Definition at line 23 of file SceneItemRegistry.h.

Constructor & Destructor Documentation

◆ ~SceneItemRegistry()

SceneItemRegistry::~SceneItemRegistry ( )

Nulls the registry back-pointer on every item still mapped, so a later cascade-delete (e.g. Qt's ~QGraphicsScene teardown of remaining items, which runs after this registry – a Scene member – has already been destroyed) can't call back into a dangling SceneItemRegistry via ItemWithId's destructor.

Definition at line 89 of file SceneItemRegistry.cpp.

Member Function Documentation

◆ contains()

bool SceneItemRegistry::contains ( int id) const
nodiscard

Returns true if an item is registered under id.

Definition at line 17 of file SceneItemRegistry.cpp.

◆ forget()

void SceneItemRegistry::forget ( ItemWithId * item)

Removes item's mapping if it is still the one on file, identity-checked so a reused id that a new item has since claimed is never evicted. Called from ItemWithId's own destructor – this is the structural fix for the WIREDPANDA-HC stale-registry-entry bug family, working on ANY destruction path, not just the ones that happen to route through unregisterItem()/forgetItemId() explicitly.

Definition at line 77 of file SceneItemRegistry.cpp.

References ItemWithId::id().

◆ forgetItemId()

void SceneItemRegistry::forgetItemId ( int id)

Removes the mapping for id, clearing the mapped item's registry back-pointer if one is still found. Safe unconditionally: the RAII self-unregistration in ItemWithId's destructor guarantees this registry never holds an entry pointing at an already-destroyed item, so whatever is found here (if anything) is live.

Definition at line 45 of file SceneItemRegistry.cpp.

◆ itemById()

ItemWithId * SceneItemRegistry::itemById ( int id) const
nodiscard

Returns the item registered under id, or nullptr.

Definition at line 12 of file SceneItemRegistry.cpp.

◆ lastId()

int SceneItemRegistry::lastId ( ) const

Returns the highest id assigned so far.

Definition at line 22 of file SceneItemRegistry.cpp.

◆ nextId()

int SceneItemRegistry::nextId ( )

Returns a fresh, previously unused id.

Definition at line 32 of file SceneItemRegistry.cpp.

◆ registerItem()

void SceneItemRegistry::registerItem ( ItemWithId * item)

Registers item under its current id.

Definition at line 53 of file SceneItemRegistry.cpp.

References ItemWithId::id().

◆ setLastId()

void SceneItemRegistry::setLastId ( int newLastId)

Raises the last-assigned id to newLastId (never lowers it).

Definition at line 27 of file SceneItemRegistry.cpp.

Referenced by updateItemId().

◆ unregisterItem()

void SceneItemRegistry::unregisterItem ( ItemWithId * item)

Removes item's mapping from the registry.

Definition at line 66 of file SceneItemRegistry.cpp.

References ItemWithId::id().

◆ updateItemId()

void SceneItemRegistry::updateItemId ( ItemWithId * item,
int newId )

Pre-assigns newId to item before it is added (undo/redo restore path).

Definition at line 37 of file SceneItemRegistry.cpp.

References ItemWithId::setId(), and setLastId().


The documentation for this class was generated from the following files: