14 return m_elementRegistry.value(
id,
nullptr);
19 return m_elementRegistry.contains(
id);
29 m_lastId = (std::max)(m_lastId, newLastId);
47 if (
auto *item = m_elementRegistry.value(
id,
nullptr)) {
48 item->setRegistry(
nullptr);
50 m_elementRegistry.remove(
id);
60 Q_ASSERT(!m_elementRegistry.contains(item->
id())
61 || m_elementRegistry.value(item->
id()) == item);
62 m_elementRegistry[item->
id()] = item;
63 item->setRegistry(
this);
71 m_elementRegistry.remove(item->
id());
72 item->setRegistry(
nullptr);
74 Q_ASSERT(!m_elementRegistry.contains(item->
id()));
84 if (m_elementRegistry.value(item->
id()) == item) {
85 m_elementRegistry.remove(item->
id());
91 for (
auto *item : std::as_const(m_elementRegistry)) {
92 item->setRegistry(
nullptr);
Defines ItemWithId, the base class for all uniquely identified circuit items.
SceneItemRegistry: maps stable integer IDs to the scene's identifiable items.
Base class providing a unique integer identifier for circuit items.
void setId(const int id)
Sets the identifier to id.
int id() const
Returns the unique integer identifier of this item, or -1 if unassigned.
void registerItem(ItemWithId *item)
Registers item under its current id.
int nextId()
Returns a fresh, previously unused id.
bool contains(int id) const
Returns true if an item is registered under id.
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).
int lastId() const
Returns the highest id assigned so far.
void forget(ItemWithId *item)
void forgetItemId(int id)
void setLastId(int newLastId)
Raises the last-assigned id to newLastId (never lowers it).
ItemWithId * itemById(int id) const
Returns the item registered under id, or nullptr.