Commit 50f09ede authored by David Redondo's avatar David Redondo 🏎 Committed by Arjen Hiemstra
Browse files

Use Formatter Units instead of having a copy of the enum

parent b96b18c4
......@@ -210,7 +210,7 @@ void AggregateSensor::delayedEmitDataChanged()
PercentageSensor::PercentageSensor(SensorObject *provider, const QString &id, const QString &name)
: SensorProperty(id, name, provider)
{
setUnit(KSysGuard::utils::UnitPercent);
setUnit(KSysGuard::UnitPercent);
setMax(100);
}
......
......@@ -9,7 +9,7 @@ set(ksgrdbackend_LIB_SRCS
add_library(ksgrdbackend ${ksgrdbackend_LIB_SRCS})
add_library(KSysGuard::StatsBackend ALIAS ksgrdbackend)
target_link_libraries(ksgrdbackend PUBLIC Qt5::Core Qt5::DBus)
target_link_libraries(ksgrdbackend PUBLIC Qt5::Core Qt5::DBus KSysGuard::Formatter)
set_target_properties(ksgrdbackend PROPERTIES
EXPORT_NAME SysGuardBackend
......
......@@ -142,7 +142,7 @@ void SensorProperty::setMax(SensorProperty *other)
});
}
void SensorProperty::setUnit(KSysGuard::utils::Unit unit)
void SensorProperty::setUnit(KSysGuard::Unit unit)
{
if (m_info.unit == unit) {
return;
......
......@@ -74,7 +74,7 @@ public:
* For example to mark the usedSpace of a disk to be the same as the disk capacity
*/
void setMax(SensorProperty *other);
void setUnit(KSysGuard::utils::Unit unit);
void setUnit(KSysGuard::Unit unit);
void setVariantType(QVariant::Type type);
bool isSubscribed() const;
......
......@@ -25,72 +25,7 @@
#include <QDBusArgument>
namespace KSysGuard
{
namespace utils
{
/**
* This enum type is used to specify metric prefixes.
*/
enum MetricPrefix {
MetricPrefixAutoAdjust = -1,
MetricPrefixUnity = 0,
MetricPrefixKilo,
MetricPrefixMega,
MetricPrefixGiga,
MetricPrefixTera,
MetricPrefixPeta,
MetricPrefixLast = MetricPrefixPeta
};
/**
* This enum types is used to specify units.
*/
enum Unit {
UnitInvalid = -1,
UnitNone = 0,
// Byte size units.
UnitByte = 100,
UnitKiloByte = MetricPrefixKilo + UnitByte,
UnitMegaByte = MetricPrefixMega + UnitByte,
UnitGigaByte = MetricPrefixGiga + UnitByte,
UnitTeraByte = MetricPrefixTera + UnitByte,
UnitPetaByte = MetricPrefixPeta + UnitByte,
// Data rate units.
UnitByteRate = 200,
UnitKiloByteRate = MetricPrefixKilo + UnitByteRate,
UnitMegaByteRate = MetricPrefixMega + UnitByteRate,
UnitGigaByteRate = MetricPrefixGiga + UnitByteRate,
UnitTeraByteRate = MetricPrefixTera + UnitByteRate,
UnitPetaByteRate = MetricPrefixPeta + UnitByteRate,
// Frequency.
UnitHertz = 300,
UnitKiloHertz = MetricPrefixKilo + UnitHertz,
UnitMegaHertz = MetricPrefixMega + UnitHertz,
UnitGigaHertz = MetricPrefixGiga + UnitHertz,
UnitTeraHertz = MetricPrefixTera + UnitHertz,
UnitPetaHertz = MetricPrefixPeta + UnitHertz,
// Time units.
UnitBootTimestamp = 400,
UnitSecond,
UnitTime,
// Misc units.
UnitCelsius = 500,
UnitDecibelMilliWatts,
UnitPercent,
UnitRate,
UnitRpm,
UnitVolt,
UnitWatt,
};
}
}
#include <ksysguard/formatter/Unit.h>
//Data that is static for the lifespan of the sensor
class SensorInfo
......@@ -101,7 +36,7 @@ public:
QString shortName;
QString description; // translated
QVariant::Type variantType = QVariant::Invalid;
KSysGuard::utils::Unit unit = KSysGuard::utils::UnitInvalid; //Both a format hint and implies data type (i.e double/string)
KSysGuard::Unit unit = KSysGuard::UnitInvalid; //Both a format hint and implies data type (i.e double/string)
qreal min = 0;
qreal max = 0;
};
......@@ -151,7 +86,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &argument, SensorInfo
argument >> t;
s.variantType = static_cast<QVariant::Type>(t);
argument >> t;
s.unit = static_cast<KSysGuard::utils::Unit>(t);
s.unit = static_cast<KSysGuard::Unit>(t);
argument >> s.min;
argument >> s.max;
argument.endStructure();
......
Supports Markdown
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