File indexing completed on 2024-04-28 16:54:24
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include <QAbstractListModel> 0009 #include <QRecursiveMutex> 0010 0011 class HistoryItem; 0012 0013 class HistoryModel : public QAbstractListModel 0014 { 0015 Q_OBJECT 0016 public: 0017 enum RoleType { 0018 HistoryItemConstPtrRole = Qt::UserRole, 0019 UuidRole, 0020 TypeRole, 0021 Base64UuidRole, 0022 TypeIntRole, 0023 }; 0024 Q_ENUM(RoleType) 0025 0026 explicit HistoryModel(QObject *parent = nullptr); 0027 ~HistoryModel() override; 0028 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0029 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0030 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 0031 QHash<int, QByteArray> roleNames() const override; 0032 bool remove(const QByteArray &uuid); 0033 0034 int maxSize() const; 0035 void setMaxSize(int size); 0036 0037 bool displayImages() const; 0038 void setDisplayImages(bool show); 0039 0040 void clear(); 0041 void moveToTop(const QByteArray &uuid); 0042 void moveTopToBack(); 0043 void moveBackToTop(); 0044 0045 QModelIndex indexOf(const QByteArray &uuid) const; 0046 QModelIndex indexOf(const HistoryItem *item) const; 0047 0048 void insert(QSharedPointer<HistoryItem> item); 0049 void clearAndBatchInsert(const QVector<QSharedPointer<HistoryItem>> &items); 0050 0051 QRecursiveMutex *mutex() 0052 { 0053 return &m_mutex; 0054 } 0055 0056 private: 0057 void moveToTop(int row); 0058 QList<QSharedPointer<HistoryItem>> m_items; 0059 int m_maxSize; 0060 bool m_displayImages; 0061 QRecursiveMutex m_mutex; 0062 }; 0063 0064 inline int HistoryModel::maxSize() const 0065 { 0066 return m_maxSize; 0067 } 0068 0069 inline bool HistoryModel::displayImages() const 0070 { 0071 return m_displayImages; 0072 } 0073 0074 inline void HistoryModel::setDisplayImages(bool show) 0075 { 0076 m_displayImages = show; 0077 }