Commit efed3313 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Expose add/removeObject on SensorContainer

This allows us to create SensorObjects in a separate context that does
not have access to a SensorContainer instance.
parent 0f79b18b
......@@ -54,15 +54,24 @@ SensorObject *SensorContainer::object(const QString &id) const
return m_sensorObjects.value(id);
}
void SensorContainer::addSubObject(SensorObject *object)
void SensorContainer::addObject(SensorObject *object)
{
const QString id = object->id();
Q_ASSERT(!m_sensorObjects.contains(id));
m_sensorObjects[id] = object;
emit objectAdded(object);
Q_EMIT objectAdded(object);
connect(object, &SensorObject::aboutToBeRemoved, this, [this, object]() {
m_sensorObjects.remove(object->id());
emit objectRemoved(object);
removeObject(object);
});
}
void SensorContainer::removeObject(SensorObject *object)
{
if (!m_sensorObjects.contains(object->id())) {
return;
}
m_sensorObjects.remove(object->id());
Q_EMIT objectRemoved(object);
}
......@@ -48,6 +48,24 @@ public:
QList<SensorObject *> objects();
SensorObject *object(const QString &id) const;
/**
* Add an object to the container.
*
* It will be exposed to clients as a subitem of this container.
*
* \param object The SensorObject to add.
*/
void addObject(SensorObject *object);
/**
* Remove an object from the container.
*
* It will no longer be available to clients.
*
* \param object The SensorObject to remove.
*/
void removeObject(SensorObject *object);
Q_SIGNALS:
/**
* Emitted when an object has been added
......@@ -60,12 +78,6 @@ Q_SIGNALS:
void objectRemoved(SensorObject *object);
private:
/**
* Called from sensorObject
* @internal
*/
void addSubObject(SensorObject *object);
QString m_id;
QString m_name;
QHash<QString, SensorObject *> m_sensorObjects;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment