#ifndef MEMBERLISTMODEL_H #define MEMBERLISTMODEL_H #include #include #include #include #include #include class DbManager; struct MemberListItem { quint64 nodeId = 0; bool online = false; bool isSelf = false; QPixmap avatar; QString name; QString localNick; int rtt = -1; int natType = -1; }; class MemberListModel : public QAbstractListModel { Q_OBJECT public: static const int BATCH = 40; static const int MAX_CACHE = 120; explicit MemberListModel(DbManager* db, QObject* parent = nullptr); int rowCount(const QModelIndex& parent = QModelIndex()) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; void setChannel(const QString& channelId); void refresh(); void refreshRtt(); quint64 nodeIdAt(int row) const; private slots: void loadPendingBatch(); private: void scheduleBatch(int centerRow) const; void loadBatch(int from, int count); void evictDistant(int centerRow); QPixmap makeAvatar(QColor color, QChar letter) const; DbManager* m_db; QString m_channelId; int m_totalCount = 0; mutable QMap m_cache; mutable int m_pendingFrom = -1; mutable int m_pendingCount = 0; }; #endif