Commit 8a5fb2ce authored by Arjen Hiemstra's avatar Arjen Hiemstra

Add API to Sensor and models to query current update rate

This allows us to change things to read the update rate from sensors
rather than needing to hardcode this. Right now the value for Sensor and
SensorDataModel is hardcoded to 500ms, which matches the new update rate
of KSystemStats. However, this new API allows us to change this without
needing to update everything else in the future.
parent 359aa210
......@@ -139,6 +139,9 @@ QVariant ProcessDataModel::data(const QModelIndex &index, int role) const
case Unit: {
return attribute->unit();
}
case UpdateInterval: {
return d->m_updateInterval;
}
}
return QVariant();
}
......@@ -427,6 +430,9 @@ QVariant ProcessDataModel::headerData(int section, Qt::Orientation orientation,
case Maximum: {
return attribute->max();
}
case UpdateInterval: {
return d->m_updateInterval;
}
default:
break;
}
......
......@@ -87,6 +87,8 @@ public:
Name, /// The full name of this attribute
ShortName, /// A shorter name of this attribute, compressed for viewing
Unit, /// The unit associated with this attribute. Returned value is of the type KSysGuard::Unit
UpdateInterval, /// The amount of time in milliseconds between each update of the model.
};
Q_ENUM(AdditionalRoles)
......
......@@ -203,6 +203,12 @@ void Sensor::setEnabled(bool newEnabled)
Q_EMIT enabledChanged();
}
uint Sensor::updateInterval() const
{
//TODO: Make this dynamic once the backend supports that.
return BackendUpdateInterval;
}
void Sensor::classBegin()
{
d->usedByQml = true;
......
......@@ -108,6 +108,17 @@ class SENSORS_EXPORT Sensor : public QObject, public QQmlParserStatus
* is also enabled.
*/
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
/**
* The time in milliseconds between each update of the sensor.
*
* This is primarily intended to match sampling rate to the update rate of
* the sensor, like when used by KQuickCharts's HistorySource.
*
* \note Currently, the update rate of the backend is fixed and this method
* simply matches the value from the backend. Eventually the idea is
* that we can support per-sensor update rates.
*/
Q_PROPERTY(uint updateInterval READ updateInterval NOTIFY updateIntervalChanged)
public:
/**
......@@ -173,6 +184,9 @@ public:
void setEnabled(bool newEnabled);
Q_SIGNAL void enabledChanged();
uint updateInterval() const;
Q_SIGNAL void updateIntervalChanged();
void classBegin() override;
void componentComplete() override;
......
......@@ -130,6 +130,9 @@ QVariant SensorDataModel::data(const QModelIndex &index, int role) const
if (!d->sensorColors.empty()) {
return d->sensorColors.value(sensor);
}
case UpdateInterval:
//TODO: Make this dynamic once the backend supports it.
return BackendUpdateInterval;
default:
break;
}
......@@ -171,6 +174,9 @@ QVariant SensorDataModel::headerData(int section, Qt::Orientation orientation, i
return info.max;
case Type:
return info.variantType;
case UpdateInterval:
//TODO: Make this dynamic once the backend supports it.
return BackendUpdateInterval;
default:
break;
}
......
......@@ -81,6 +81,7 @@ public:
Value, ///< The value of the sensor.
FormattedValue, ///< A formatted string of the value of the sensor.
Color, ///< A color of the sensor, if sensorColors is set
UpdateInterval, ///< The time in milliseconds between each update of the sensor.
};
Q_ENUM(AdditionalRoles)
......
......@@ -28,6 +28,8 @@
namespace KSysGuard
{
constexpr uint BackendUpdateInterval = 500;
// Data that is static for the lifespan of the sensor
class SensorInfo
{
......
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