wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
SceneItemRegistry.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
10#include <QHash>
11
12class ItemWithId;
13
24{
25public:
31
33 [[nodiscard]] ItemWithId *itemById(int id) const;
34
36 [[nodiscard]] bool contains(int id) const;
37
39 int lastId() const;
40
42 void setLastId(int newLastId);
43
45 int nextId();
46
48 void updateItemId(ItemWithId *item, int newId);
49
54 void forgetItemId(int id);
55
57 void registerItem(ItemWithId *item);
58
60 void unregisterItem(ItemWithId *item);
61
67 void forget(ItemWithId *item);
68
69private:
70 QHash<int, ItemWithId *> m_elementRegistry;
71 int m_lastId = 0;
72};
Base class providing a unique integer identifier for circuit items.
Definition ItemWithId.h:31
Owns the id↔item bookkeeping for a Scene: the id-to-item map and the monotonically increasing last-as...
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 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.