File indexing completed on 2024-03-24 05:57:05
0001 /* 0002 SPDX-FileCopyrightText: 2006 Bram Schoenmakers <bramschoenmakers@kde.nl> 0003 SPDX-FileCopyrightText: 2006 Tom Albers <toma@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef RSISTATITEM_H 0009 #define RSISTATITEM_H 0010 0011 #include <QLabel> 0012 #include <QList> 0013 #include <QVariant> 0014 0015 #include "rsiglobals.h" 0016 0017 class QLabel; 0018 0019 /** 0020 * This class represents one statistic. 0021 * It consists of a value, a description and a list 0022 * of items which have this statistic as a dependency. 0023 * 0024 * @author Bram Schoenmakers <bramschoenmakers@kde.nl> 0025 */ 0026 class RSIStatItem 0027 { 0028 public: 0029 /** 0030 * Constructor. Pass a @p description along to give the 0031 * statistic a useful description. It will be visible in the 0032 * statistics widget. 0033 * @param description A i18n()'d text representing this statistic's meaning. 0034 * @param init The initial value of this statistic. Default value is an 0035 * integer zero. 0036 */ 0037 explicit RSIStatItem(const QString &description = QString(), const QVariant &init = QVariant(0)); 0038 0039 /** Default destructor. */ 0040 virtual ~RSIStatItem(); 0041 0042 /** Retrieve the item's description in QLabel format. */ 0043 QLabel *getDescription() const 0044 { 0045 return m_description; 0046 } 0047 0048 /** Retrieve the item's value in QVariant format. */ 0049 QVariant getValue() const 0050 { 0051 return m_value; 0052 } 0053 0054 /** 0055 * Sets the value of this item. 0056 * @param v The new value of this statistic item. 0057 * 0058 * @see QVariant documentation for supported types of values. 0059 */ 0060 void setValue(QVariant v) 0061 { 0062 m_value = v; 0063 } 0064 0065 /** 0066 * When other statistics depend on this statistic item, it should 0067 * be added to this list. When this statistic is updated, it will 0068 * iterate through the list of derived statistics and update them. 0069 */ 0070 void addDerivedItem(RSIStat stat); 0071 0072 /** 0073 * Returns the list of derived statistics. 0074 */ 0075 QList<RSIStat> getDerivedItems() const 0076 { 0077 return m_derived; 0078 } 0079 0080 /** 0081 * Resets current value to initial value, passed along with the 0082 * constructor. 0083 */ 0084 virtual void reset(); 0085 0086 // virtual void setActivity() {}; 0087 // virtual void setIdle() {}; 0088 0089 protected: 0090 QVariant m_value; 0091 QVariant m_init; 0092 0093 private: 0094 QLabel *m_description; 0095 0096 /** Contains a list of RSIStats which depend on *this* item. */ 0097 QList<RSIStat> m_derived; 0098 }; 0099 0100 /** 0101 * This is a more extended statistic item. 0102 * It uses a part of the bit array defined in RSIGlobals, which keeps track per 0103 * second when the user was active or idle (max. 24 hours). 0104 * The amount of time recorded by this item is specified with the size 0105 * attribute in the constructor. 0106 * 0107 * @author Bram Schoenmakers <bramschoenmakers@kde.nl> 0108 * @see RSIGlobals 0109 */ 0110 class RSIStatBitArrayItem : public RSIStatItem 0111 { 0112 public: 0113 /** 0114 * Constructor of a bit array item. 0115 * @param description A i18n()'d text representing this statistic's meaning. 0116 * @param init The initial value of this statistic. Default value is an 0117 * integer zero. 0118 * @param size The amount of time this item keeps track of in seconds. Default 0119 * it keeps track of 24 hours of usage. This value should be never higher than 0120 * 86400 seconds. 0121 */ 0122 explicit RSIStatBitArrayItem(const QString &description = QString(), const QVariant &init = QVariant(0), int size = 86400); 0123 0124 /** 0125 * Destructor. 0126 */ 0127 ~RSIStatBitArrayItem(); 0128 0129 /** 0130 * Resets the value of this item and the complete usage array 0131 * in RSIGlobals. 0132 */ 0133 void reset() override; 0134 0135 /** 0136 * Updates the value of this item when activity has occurred. 0137 */ 0138 void setActivity(); 0139 0140 /** 0141 * Updates the value of this item when the user was idle. 0142 */ 0143 void setIdle(); 0144 0145 private: 0146 int m_size; 0147 int m_counter; 0148 int m_begin; 0149 int m_end; 0150 }; 0151 0152 #endif