- EmailListModel: QAbstractListModel with canFetchMore/fetchMore * Batch loading (default 50 emails per fetch) * Total count query for scrollbar * TotalCountChanged signal * Paginated DB queries: findAllPaginated, findByFolderIdPaginated * Count queries: countAll, countByFolderId - MailItemDao: new paginated methods * findAllPaginated(offset, limit, filters...) * findByFolderIdPaginated(folderId, offset, limit, filters...) * countAll(filters...), countByFolderId(folderId, filters...) - MailListView: scroll-triggered fetchMore * Connects verticalScrollBar valueChanged on both TreeView and ListView * Triggers fetchMore at 90% scroll threshold * onRowsInserted updates EmailTreeModel when new emails arrive * Works in both normal (tree) and compact (list) views
75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#ifndef EMAILLISTMODEL_H
|
|
#define EMAILLISTMODEL_H
|
|
|
|
#include <QAbstractTableModel>
|
|
#include <QHash>
|
|
#include <QByteArray>
|
|
#include "../db/dao/mailitemdao.h"
|
|
|
|
class EmailListModel : public QAbstractListModel
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit EmailListModel(QObject *parent = nullptr);
|
|
~EmailListModel() override = default;
|
|
|
|
enum EmailRoles {
|
|
IdRole = Qt::UserRole + 1,
|
|
SubjectRole,
|
|
SenderRole,
|
|
RecipientRole,
|
|
DateRole,
|
|
ReadRole,
|
|
FlaggedRole,
|
|
AttachmentsRole,
|
|
FileIdRole,
|
|
SizeRole,
|
|
MessageIdRole,
|
|
SenderInitialRole, // computed from sender
|
|
ThreadIdRole,
|
|
InReplyToRole,
|
|
ReferencesRole,
|
|
IsPinnedRole
|
|
};
|
|
|
|
// QAbstractListModel interface
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
bool canFetchMore(const QModelIndex &parent) const override;
|
|
void fetchMore(const QModelIndex &parent) override;
|
|
|
|
// Set the folderId to filter emails; -1 means all folders
|
|
void setFolderId(int folderId);
|
|
// Refresh the model from the database based on current folderId
|
|
void refresh();
|
|
// Set search filter on the model
|
|
void setSearchFilter(const QString &filter);
|
|
// Set filter flags
|
|
void setShowUnreadOnly(bool show);
|
|
void setShowFlaggedOnly(bool show);
|
|
void setShowHasAttachments(bool show);
|
|
// Set batch size for pagination
|
|
void setBatchSize(int size) { m_batchSize = size; }
|
|
|
|
// Get all emails currently in the model (after filtering)
|
|
const QVector<MailItem>& emails() const { return m_emails; }
|
|
|
|
// Total count of emails matching filters (including unloaded)
|
|
int totalCount() const { return m_totalCount; }
|
|
|
|
signals:
|
|
void totalCountChanged(int count);
|
|
|
|
private:
|
|
QVector<MailItem> m_emails;
|
|
int m_folderId{-1}; // -1 means all folders
|
|
QString m_searchFilter;
|
|
bool m_unreadOnly{false};
|
|
bool m_flaggedOnly{false};
|
|
bool m_hasAttachments{false};
|
|
int m_batchSize{50}; // emails per fetch
|
|
int m_loadedCount{0}; // how many emails currently loaded
|
|
int m_totalCount{0}; // total matching emails in DB
|
|
};
|
|
#endif // EMAILLISTMODEL_H
|