File indexing completed on 2024-05-05 05:54:31

0001 /*
0002     SPDX-FileCopyrightText: 2014 Elvis Angelaccio <elvis.angelaccio@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef LAP_H
0008 #define LAP_H
0009 
0010 #include <QMetaType>
0011 #include <QString>
0012 #include <QTime>
0013 
0014 class QJsonObject;
0015 
0016 /**
0017  * @brief A Lap is a specific time instant.
0018  * This class is a wrapper for a QTime object and some strings, which are useful to describe it.
0019  */
0020 class Lap
0021 {
0022 
0023 public:
0024 
0025     explicit Lap(const QTime& lap = {0, 0});
0026 
0027     /**
0028      * The specific lap's time
0029      * @return The underlying lap's time object
0030      */
0031     QTime time() const;
0032 
0033     /**
0034      * Compute the difference with the given Lap.
0035      * @param lap A Lap object.
0036      * @return QTime difference if the given Lap is "greater", otherwise a zero QTime.
0037      */
0038     QTime timeTo(const Lap& lap) const;
0039 
0040     /**
0041      * Set the lap's relative time
0042      * @param rel The string to be set as relative time
0043      */
0044     void setRelativeTime(const QString& rel);
0045 
0046     /**
0047      * The relative lap time
0048      * @return String representation of the relative lap time
0049      */
0050     QString relativeTime() const;
0051 
0052     /**
0053      * Set the lap's absolute time
0054      * @param abs The string to be set as absolute lap time
0055      */
0056     void setAbsoluteTime(const QString& abs);
0057 
0058     /**
0059      * The absolute lap time
0060      * @return String representation of the absolute lap time
0061      */
0062     QString absoluteTime() const;
0063 
0064     /**
0065      * Set the lap's annotation
0066      * @param note The note to be set
0067      */
0068     void setNote(const QString& note);
0069 
0070     /**
0071      * The lap's annotation
0072      * @return The lap's annotation
0073      */
0074     QString note() const;
0075 
0076     /**
0077      * The underlying lap's raw data
0078      * @return Lap's raw data counter
0079      */
0080     int raw() const;
0081 
0082     /**
0083      * Serialize the lap on the given JSON object.
0084      * @param json A JSON object.
0085      */
0086     void write(QJsonObject& json) const;
0087 
0088     /**
0089      * Deserialize a lap from the given JSON object.
0090      * @param json A JSON object.
0091      * @return A deserialized lap.
0092      */
0093     static Lap fromJson(const QJsonObject& json);
0094 
0095     /**
0096      * Create a new Lap object from raw data
0097      * @param rawData The raw data counter of the new Lap
0098      * @return A new Lap object created from the given raw data
0099      */
0100     static Lap fromRawData(int rawData);
0101 
0102 private:
0103 
0104     QTime m_time;              /** The specific lap time */
0105     QString m_relativeTime;    /** String representation of the relative lap time, i.e. compared to another lap */
0106     QString m_absoluteTime;    /** String representation of the specific (absolute) lap time */
0107     QString m_note;            /** Custom lap annotation */
0108 };
0109 
0110 Q_DECLARE_METATYPE(Lap)
0111 
0112 #endif