LCOV - code coverage report
Current view: top level - src/models - NewsPosition.h (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 100.0 % 25 25
Test Date: 2026-03-23 10:19:47 Functions: 100.0 % 9 9

            Line data    Source code
       1              : #ifndef NEWSPOSITION_H
       2              : #define NEWSPOSITION_H
       3              : 
       4              : #include <QDateTime>
       5              : 
       6              : /*!
       7              :     \brief Represents a position in a news feed using (timestamp, id) tuple.
       8              : 
       9              :     This matches the in-memory data with the SQLite database ordering:
      10              :         ORDER BY timestamp ASC, id ASC
      11              : 
      12              :     Used for bookmark comparisons in Lisvel feeds where items may not appear
      13              :     in strictly chronological order.
      14              :  */
      15              : class NewsPosition
      16              : {
      17              : public:
      18           99 :     NewsPosition() : _id(-1), _timestamp() {}
      19         2619 :     NewsPosition(qint64 id, const QDateTime& timestamp) : _id(id), _timestamp(timestamp) {}
      20              : 
      21        89193 :     inline qint64 id() const { return _id; }
      22          118 :     inline const QDateTime& timestamp() const { return _timestamp; }
      23          121 :     inline bool isValid() const { return _id >= 0 && _timestamp.isValid(); }
      24              : 
      25              :     /*!
      26              :         \brief Compare positions.
      27              :         \return true if this position comes AFTER other in reading order.
      28              :      */
      29           23 :     inline bool isAfter(const NewsPosition& other) const
      30              :     {
      31           23 :         if (!isValid() || !other.isValid()) {
      32            8 :             return false;
      33           15 :         } else if (_timestamp > other._timestamp) {
      34            3 :             return true;
      35           12 :         } else if (_timestamp == other._timestamp) {
      36            6 :             return _id > other._id;
      37              :         }
      38              : 
      39            6 :         return false;
      40              :     }
      41              : 
      42              :     /*!
      43              :         \brief Compare positions.
      44              :         \return true if this position comes BEFORE other in reading order.
      45              :      */
      46           15 :     inline bool isBefore(const NewsPosition& other) const
      47              :     {
      48           15 :         if (!isValid() || !other.isValid()) {
      49            3 :             return false;
      50           12 :         } else if (_timestamp < other._timestamp) {
      51            3 :             return true;
      52            9 :         } else if (_timestamp == other._timestamp) {
      53            6 :             return _id < other._id;
      54              :         }
      55              : 
      56            3 :         return false;
      57              :     }
      58              : 
      59            8 :     inline bool operator==(const NewsPosition& other) const
      60              :     {
      61            8 :         return _id == other._id && _timestamp == other._timestamp;
      62              :     }
      63              : 
      64            4 :     inline bool operator!=(const NewsPosition& other) const
      65              :     {
      66            4 :         return !(*this == other);
      67              :     }
      68              : 
      69              : private:
      70              :     qint64 _id;
      71              :     QDateTime _timestamp;
      72              : };
      73              : 
      74              : #endif // NEWSPOSITION_H
        

Generated by: LCOV version 2.0-1