File indexing completed on 2024-05-05 05:54:31
0001 /* 0002 SPDX-FileCopyrightText: 2015 Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef SESSION_H 0008 #define SESSION_H 0009 0010 #include "lap.h" 0011 0012 #include <QMetaType> 0013 #include <QVector> 0014 0015 /** 0016 * @brief A session represents a single Kronometer instance. 0017 * A session is made by a stopwatch time, a date timestamp and by zero or more laps. 0018 * An optional name and an optional note are also provided. 0019 */ 0020 class Session 0021 { 0022 0023 public: 0024 0025 explicit Session(int time = 0, const QDateTime& date = QDateTime::currentDateTime()); 0026 0027 /** 0028 * Set the session's name. 0029 * @param name The string to be set as name. 0030 */ 0031 void setName(const QString& name); 0032 0033 /** 0034 * Set the session's annotation. 0035 * @param note The note to be set. 0036 */ 0037 void setNote(const QString& note); 0038 0039 /** 0040 * Set the session's stopwatch (raw) time. 0041 * @param time The stopwatch raw time. 0042 */ 0043 void setTime(int time); 0044 0045 /** 0046 * Set the session's date (timestamp). 0047 * @param date The date to be set as timestamp. 0048 */ 0049 void setDate(const QDateTime& date); 0050 0051 /** 0052 * Set whether the session data is outdated. 0053 * @param isOutdated Whether the session is outdated. 0054 */ 0055 void setIsOutdated(bool isOutdated); 0056 0057 /** 0058 * @return The session name. 0059 */ 0060 QString name() const; 0061 0062 /** 0063 * @return The session note. 0064 */ 0065 QString note() const; 0066 0067 /** 0068 * @return The session stopwatch raw time. 0069 */ 0070 int time() const; 0071 0072 /** 0073 * @return The session date. 0074 */ 0075 QDateTime date() const; 0076 0077 /** 0078 * Whether the session data is outdated. 0079 * @return True if the session is outdated, false otherwise. 0080 */ 0081 bool isOutdated() const; 0082 0083 /** 0084 * @return The session laps. 0085 */ 0086 QVector<Lap> laps() const; 0087 0088 /** 0089 * Whether the session is empty. 0090 * @return True if the session is empty, false otherwise. 0091 */ 0092 bool isEmpty() const; 0093 0094 /** 0095 * Add a lap to the session. 0096 * @param lap The lap the be added. 0097 */ 0098 void addLap(const Lap& lap); 0099 0100 /** 0101 * Reset the stopwatch time and remove all the laps from the session. 0102 */ 0103 void clear(); 0104 0105 /** 0106 * Serialize the session on the given JSON object. 0107 * @param json A JSON object. 0108 */ 0109 void write(QJsonObject& json) const; 0110 0111 /** 0112 * Deserialize a session from the given JSON object. 0113 * @param json A JSON object. 0114 * @return A deserialized session. 0115 */ 0116 static Session fromJson(const QJsonObject& json); 0117 0118 bool operator==(const Session& right) const; 0119 bool operator!=(const Session& right) const; 0120 0121 private: 0122 0123 QString m_name; /** Session name. */ 0124 QString m_note; /** Custom session annotation. */ 0125 int m_time; /** Session stopwatch time. */ 0126 QDateTime m_date; /** Session date (timestamp of the last update). */ 0127 QVector<Lap> m_laps; /** Session laps. */ 0128 bool m_isOutdated = false; /** Whether the session data is outdated. */ 0129 }; 0130 0131 Q_DECLARE_METATYPE(Session) 0132 0133 #endif