mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
Move to id is size_t
This commit is contained in:
+10
-24
@@ -4,6 +4,7 @@ Simulator_base::Simulator_base(std::string name, std::chrono::milliseconds inter
|
||||
: QObject(parrent), m_name(name), m_timer(new QTimer(this)), m_interval(interval)
|
||||
{
|
||||
connect(m_timer, &QTimer::timeout, this, [this] { timer(); });
|
||||
m_UI_items.reserve(50);
|
||||
}
|
||||
|
||||
std::string Simulator_base::name() const
|
||||
@@ -12,29 +13,10 @@ std::string Simulator_base::name() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
bool Simulator_base::is_ui_id_unique(std::string id) const
|
||||
{
|
||||
// Check if the UI name is unique
|
||||
for (UI_item *item : m_UI_items)
|
||||
{
|
||||
if (item->id() == id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Simulator_base::add_UI_item(UI_item *item)
|
||||
{
|
||||
// Add a UI item to the simulator
|
||||
if (is_ui_id_unique(item->id()) == false)
|
||||
{
|
||||
throw std::runtime_error("UI item id " + item->id() + " is not unique");
|
||||
}
|
||||
connect(item, &UI_item::value_changed, this, [this] { emit sim_changed(); });
|
||||
m_UI_items_map[item->id()] = item;
|
||||
m_UI_items.push_back(item);
|
||||
}
|
||||
|
||||
@@ -43,18 +25,22 @@ json Simulator_base::get_UI_items() const
|
||||
// Get the UI items
|
||||
json items;
|
||||
items["name"] = m_name;
|
||||
for (UI_item *item : m_UI_items)
|
||||
for (size_t i = 0; i < m_UI_items.size(); i++)
|
||||
{
|
||||
items["UI_items"].push_back(item->to_json());
|
||||
items["UI_items"].push_back(m_UI_items[i]->to_json(i));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
UI_item *Simulator_base::get_UI_item(std::string id) const
|
||||
UI_item *Simulator_base::get_UI_item(size_t id) const
|
||||
{
|
||||
// Get a UI item by id
|
||||
return m_UI_items_map.at(id);
|
||||
// Get a UI item by id using the list
|
||||
if (id < m_UI_items.size())
|
||||
{
|
||||
return m_UI_items[id];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Simulator_base::run()
|
||||
|
||||
Reference in New Issue
Block a user