Commit 9c73bad0 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Add an enabled property to SensorDataModel

Allows disabling updates for SensorDataModel, to preserve resources.
parent f63b52d0
......@@ -51,6 +51,7 @@ public:
bool usedByQml = false;
bool componentComplete = false;
bool loaded = false;
bool enabled = false;
private:
SensorDataModel *q;
......@@ -229,6 +230,29 @@ void SensorDataModel::setSensors(const QStringList &sensorIds)
Q_EMIT sensorsChanged();
}
bool SensorDataModel::enabled() const
{
return d->enabled;
}
void SensorDataModel::setEnabled(bool newEnabled)
{
if (newEnabled == d->enabled) {
return;
}
d->enabled = newEnabled;
if (d->enabled) {
SensorDaemonInterface::instance()->subscribe(d->sensorInfos.keys());
SensorDaemonInterface::instance()->requestMetaData(d->sensorInfos.keys());
} else {
SensorDaemonInterface::instance()->unsubscribe(d->sensorInfos.keys());
}
Q_EMIT enabledChanged();
}
void SensorDataModel::addSensor(const QString &sensorId)
{
d->addSensor(sensorId);
......@@ -289,16 +313,28 @@ void SensorDataModel::Private::removeSensor(const QString &id)
void SensorDataModel::onSensorAdded(const QString &sensorId)
{
if (!d->enabled) {
return;
}
d->addSensor(sensorId);
}
void SensorDataModel::onSensorRemoved(const QString &sensorId)
{
if (!d->enabled) {
return;
}
d->removeSensor(sensorId);
}
void SensorDataModel::onMetaDataChanged(const QString &sensorId, const SensorInfo &info)
{
if (!d->enabled) {
return;
}
auto column = d->sensors.indexOf(sensorId);
if (column == -1) {
return;
......@@ -325,7 +361,7 @@ void SensorDataModel::onMetaDataChanged(const QString &sensorId, const SensorInf
void SensorDataModel::onValueChanged(const QString &sensorId, const QVariant &value)
{
if (!d->sensorData.contains(sensorId)) {
if (!d->sensorData.contains(sensorId) || !d->enabled) {
return;
}
......
......@@ -54,6 +54,10 @@ class SENSORS_EXPORT SensorDataModel : public QAbstractTableModel, public QQmlPa
* The maximum value of all sensors' maximum property.
*/
Q_PROPERTY(qreal maximum READ maximum NOTIFY sensorMetaDataChanged)
/**
* Should this model be updated or not.
*/
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
public:
enum AdditionalRoles {
......@@ -86,6 +90,10 @@ public:
Q_SIGNAL void sensorsChanged() const;
Q_SIGNAL void sensorMetaDataChanged();
bool enabled() const;
void setEnabled(bool newEnabled);
Q_SIGNAL void enabledChanged();
qreal minimum() const;
qreal maximum() const;
......
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