File indexing completed on 2024-05-19 16:51:55
0001 /* 0002 Copyright (C) 2015 by Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 0004 This file is part of Kronometer. 0005 0006 Kronometer is free software: you can redistribute it and/or modify 0007 it under the terms of the GNU General Public License as published by 0008 the Free Software Foundation, either version 2 of the License, or 0009 (at your option) any later version. 0010 0011 Kronometer is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with Kronometer. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef SESSION_H 0021 #define SESSION_H 0022 0023 #include "lap.h" 0024 0025 #include <QMetaType> 0026 #include <QVector> 0027 0028 /** 0029 * @brief A session represents a single Kronometer instance. 0030 * A session is made by a stopwatch time, a date timestamp and by zero or more laps. 0031 * An optional name and an optional note are also provided. 0032 */ 0033 class Session 0034 { 0035 0036 public: 0037 0038 explicit Session(int time = 0, const QDateTime& date = QDateTime::currentDateTime()); 0039 0040 /** 0041 * Set the session's name. 0042 * @param name The string to be set as name. 0043 */ 0044 void setName(const QString& name); 0045 0046 /** 0047 * Set the session's annotation. 0048 * @param note The note to be set. 0049 */ 0050 void setNote(const QString& note); 0051 0052 /** 0053 * Set the session's stopwatch (raw) time. 0054 * @param time The stopwatch raw time. 0055 */ 0056 void setTime(int time); 0057 0058 /** 0059 * Set the session's date (timestamp). 0060 * @param date The date to be set as timestamp. 0061 */ 0062 void setDate(const QDateTime& date); 0063 0064 /** 0065 * Set whether the session data is outdated. 0066 * @param isOutdated Whether the session is outdated. 0067 */ 0068 void setIsOutdated(bool isOutdated); 0069 0070 /** 0071 * @return The session name. 0072 */ 0073 QString name() const; 0074 0075 /** 0076 * @return The session note. 0077 */ 0078 QString note() const; 0079 0080 /** 0081 * @return The session stopwatch raw time. 0082 */ 0083 int time() const; 0084 0085 /** 0086 * @return The session date. 0087 */ 0088 QDateTime date() const; 0089 0090 /** 0091 * Whether the session data is outdated. 0092 * @return True if the session is outdated, false otherwise. 0093 */ 0094 bool isOutdated() const; 0095 0096 /** 0097 * @return The session laps. 0098 */ 0099 QVector<Lap> laps() const; 0100 0101 /** 0102 * Whether the session is empty. 0103 * @return True if the session is empty, false otherwise. 0104 */ 0105 bool isEmpty() const; 0106 0107 /** 0108 * Add a lap to the session. 0109 * @param lap The lap the be added. 0110 */ 0111 void addLap(const Lap& lap); 0112 0113 /** 0114 * Reset the stopwatch time and remove all the laps from the session. 0115 */ 0116 void clear(); 0117 0118 /** 0119 * Serialize the session on the given JSON object. 0120 * @param json A JSON object. 0121 */ 0122 void write(QJsonObject& json) const; 0123 0124 /** 0125 * Deserialize a session from the given JSON object. 0126 * @param json A JSON object. 0127 * @return A deserialized session. 0128 */ 0129 static Session fromJson(const QJsonObject& json); 0130 0131 bool operator==(const Session& right) const; 0132 bool operator!=(const Session& right) const; 0133 0134 private: 0135 0136 QString m_name; /** Session name. */ 0137 QString m_note; /** Custom session annotation. */ 0138 int m_time; /** Session stopwatch time. */ 0139 QDateTime m_date; /** Session date (timestamp of the last update). */ 0140 QVector<Lap> m_laps; /** Session laps. */ 0141 bool m_isOutdated = false; /** Whether the session data is outdated. */ 0142 }; 0143 0144 Q_DECLARE_METATYPE(Session) 0145 0146 #endif