Warning, file /plasma/libksysguard/systemstats/SensorProperty.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 
0011 #include "SensorInfo.h"
0012 #include "systemstats_export.h"
0013 
0014 namespace KSysGuard
0015 {
0016 class SensorObject;
0017 
0018 /**
0019  * Represents a given value source with attached metadata
0020  * For example, current load for a given CPU core, or a disk capacity
0021  */
0022 class SYSTEMSTATS_EXPORT SensorProperty : public QObject
0023 {
0024     Q_OBJECT
0025 public:
0026     explicit SensorProperty(const QString &id, SensorObject *parent);
0027     explicit SensorProperty(const QString &id, const QString &name, SensorObject *parent);
0028 
0029     /**
0030      * Construct a SensorProperty.
0031      *
0032      * \param id The unique ID of this SensorProperty.
0033      * \param name The user-visible name of this SensorProperty.
0034      * \param initialValue The value that is used when no other value has been set.
0035      * \param parent The SensorObject that contains this SensorProperty.
0036      *
0037      * \note If initialValue is valid, the value of this SensorProperty will be
0038      * reset to initialValue when the last client unsubscribes from this
0039      * SensorProperty.
0040      */
0041     explicit SensorProperty(const QString &id, const QString &name, const QVariant &initalValue, SensorObject *parent);
0042 
0043     ~SensorProperty() override;
0044 
0045     SensorInfo info() const;
0046 
0047     /**
0048      * A computer readable ID of the property
0049      */
0050     QString id() const;
0051 
0052     /**
0053      * A deduced path based on the concatenated ID of ourselves + parent IDs
0054      */
0055     QString path() const;
0056     /**
0057      * A human reabable translated name of the property
0058      */
0059     void setName(const QString &name);
0060     void setShortName(const QString &name);
0061     void setPrefix(const QString &name);
0062 
0063     void setDescription(const QString &description);
0064     /**
0065      * Sets a hint describing the minimum value this value can be.
0066      * Values are not clipped, it is a hint for graphs.
0067      * When not relevant, leave unset
0068      */
0069     void setMin(qreal min);
0070     /**
0071      * Sets a hint describing the maximum value this value can be.
0072      * Values are not clipped, it is a hint for graphs.
0073      * When not relevant, leave unset
0074      */
0075     void setMax(qreal max);
0076     /**
0077      * Shorthand for setting the maximum value to that of another property
0078      * For example to mark the usedSpace of a disk to be the same as the disk capacity
0079      */
0080     void setMax(SensorProperty *other);
0081     void setUnit(KSysGuard::Unit unit);
0082     void setVariantType(QVariant::Type type);
0083 
0084     bool isSubscribed() const;
0085 
0086     /**
0087      * Called when a client requests to get continual updates from this property.
0088      */
0089     virtual void subscribe();
0090     /**
0091      * Called when a client disconnects or no longer wants updates for this property.
0092      */
0093     virtual void unsubscribe();
0094     /**
0095      * Returns the last value set for this property
0096      */
0097     virtual QVariant value() const;
0098     /**
0099      * Update the stored value for this property
0100      */
0101     void setValue(const QVariant &value);
0102 
0103     /**
0104      * Updates the value of this property if possible. The default implementation does nothing.
0105      */
0106     virtual void update()
0107     {
0108     }
0109 
0110 Q_SIGNALS:
0111     /**
0112      * Emitted when the value changes
0113      * Clients should emit this manually if they implement value() themselves
0114      */
0115     void valueChanged();
0116     /**
0117      * Emitted when the metadata of a sensor changes.
0118      * min/max etc.
0119      */
0120     void sensorInfoChanged();
0121     /**
0122      * Emitted when we have our first subscription, or all subscriptions are gone
0123      */
0124     void subscribedChanged(bool);
0125 
0126 private:
0127     class Private;
0128     const std::unique_ptr<Private> d;
0129 };
0130 
0131 } // namespace KSysGuard