| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef MESSAGESMODELCACHE_H |
| 4 | #define MESSAGESMODELCACHE_H |
| 5 | |
| 6 | #include "core/message.h" |
| 7 | |
| 8 | #include <QModelIndex> |
| 9 | #include <QObject> |
| 10 | #include <QVariant> |
| 11 | |
| 12 | class MessagesModelCache : public QObject { |
| 13 | Q_OBJECT |
| 14 | |
| 15 | public: |
| 16 | explicit MessagesModelCache(QObject* parent = nullptr); |
| 17 | virtual ~MessagesModelCache() = default; |
| 18 | |
| 19 | bool containsData(int row_idx) const; |
| 20 | QSqlRecord record(int row_idx) const; |
| 21 | QVariant data(const QModelIndex& idx); |
| 22 | |
| 23 | void clear(); |
| 24 | void setData(const QModelIndex& index, const QVariant& value); |
| 25 | |
| 26 | private: |
| 27 | QHash<int, QSqlRecord> m_msgCache; |
| 28 | }; |
| 29 | |
| 30 | inline bool MessagesModelCache::containsData(int row_idx) const { |
| 31 | return m_msgCache.contains(row_idx); |
| 32 | } |
| 33 | |
| 34 | inline QSqlRecord MessagesModelCache::record(int row_idx) const { |
| 35 | return m_msgCache.value(row_idx); |
| 36 | } |
| 37 | |
| 38 | inline void MessagesModelCache::clear() { |
| 39 | m_msgCache.clear(); |
| 40 | } |
| 41 | |
| 42 | #endif // MESSAGESMODELCACHE_H |