File indexing completed on 2024-05-19 16:51:55
0001 /* 0002 Copyright (C) 2014 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 LAP_H 0021 #define LAP_H 0022 0023 #include <QMetaType> 0024 #include <QString> 0025 #include <QTime> 0026 0027 class QJsonObject; 0028 0029 /** 0030 * @brief A Lap is a specific time instant. 0031 * This class is a wrapper for a QTime object and some strings, which are useful to describe it. 0032 */ 0033 class Lap 0034 { 0035 0036 public: 0037 0038 explicit Lap(const QTime& lap = {0, 0}); 0039 0040 /** 0041 * The specific lap's time 0042 * @return The underlying lap's time object 0043 */ 0044 QTime time() const; 0045 0046 /** 0047 * Compute the difference with the given Lap. 0048 * @param lap A Lap object. 0049 * @return QTime difference if the given Lap is "greater", otherwise a zero QTime. 0050 */ 0051 QTime timeTo(const Lap& lap) const; 0052 0053 /** 0054 * Set the lap's relative time 0055 * @param rel The string to be set as relative time 0056 */ 0057 void setRelativeTime(const QString& rel); 0058 0059 /** 0060 * The relative lap time 0061 * @return String representation of the relative lap time 0062 */ 0063 QString relativeTime() const; 0064 0065 /** 0066 * Set the lap's absolute time 0067 * @param abs The string to be set as absolute lap time 0068 */ 0069 void setAbsoluteTime(const QString& abs); 0070 0071 /** 0072 * The absolute lap time 0073 * @return String representation of the absolute lap time 0074 */ 0075 QString absoluteTime() const; 0076 0077 /** 0078 * Set the lap's annotation 0079 * @param note The note to be set 0080 */ 0081 void setNote(const QString& note); 0082 0083 /** 0084 * The lap's annotation 0085 * @return The lap's annotation 0086 */ 0087 QString note() const; 0088 0089 /** 0090 * The underlying lap's raw data 0091 * @return Lap's raw data counter 0092 */ 0093 int raw() const; 0094 0095 /** 0096 * Serialize the lap on the given JSON object. 0097 * @param json A JSON object. 0098 */ 0099 void write(QJsonObject& json) const; 0100 0101 /** 0102 * Deserialize a lap from the given JSON object. 0103 * @param json A JSON object. 0104 * @return A deserialized lap. 0105 */ 0106 static Lap fromJson(const QJsonObject& json); 0107 0108 /** 0109 * Create a new Lap object from raw data 0110 * @param rawData The raw data counter of the new Lap 0111 * @return A new Lap object created from the given raw data 0112 */ 0113 static Lap fromRawData(int rawData); 0114 0115 private: 0116 0117 QTime m_time; /** The specific lap time */ 0118 QString m_relativeTime; /** String representation of the relative lap time, i.e. compared to another lap */ 0119 QString m_absoluteTime; /** String representation of the specific (absolute) lap time */ 0120 QString m_note; /** Custom lap annotation */ 0121 }; 0122 0123 Q_DECLARE_METATYPE(Lap) 0124 0125 #endif