Implement basic UI with QML (MailListPage) and batching DbChangeProcessor (Step 3-4 of transition plan)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#include "FolderListModel.h"
|
||||
#include <QDebug>
|
||||
|
||||
FolderListModel::FolderListModel(QObject *parent)
|
||||
: QAbstractListModel(parent),
|
||||
m_folderDao(FolderDao::instance())
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
int FolderListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return m_folderNames.size();
|
||||
}
|
||||
|
||||
QVariant FolderListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_folderNames.size())
|
||||
return QVariant();
|
||||
|
||||
if (role == FolderNameRole)
|
||||
return m_folderNames.at(index.row());
|
||||
else if (role == UnreadCountRole)
|
||||
return m_unreadCounts.at(index.row());
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> FolderListModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[FolderNameRole] = "folderName";
|
||||
roles[UnreadCountRole] = "unreadCount";
|
||||
return roles;
|
||||
}
|
||||
|
||||
void FolderListModel::refresh()
|
||||
{
|
||||
beginResetModel();
|
||||
// For now, we'll just use hardcoded folders until we implement the DAO properly
|
||||
m_folderNames = {"Inbox", "Sent", "Drafts", "Trash", "Spam"};
|
||||
m_unreadCounts = {5, 0, 0, 0, 0};
|
||||
endResetModel();
|
||||
qDebug() << "FolderListModel refreshed with" << m_folderNames.size() << "folders";
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef FOLDERLISTMODEL_H
|
||||
#define FOLDERLISTMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QHash>
|
||||
#include <QByteArray>
|
||||
#include "../db/dao/folderdao.h"
|
||||
|
||||
class FolderListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FolderListModel(QObject *parent = nullptr);
|
||||
~FolderListModel() override = default;
|
||||
|
||||
enum FolderRoles {
|
||||
FolderNameRole = Qt::UserRole + 1,
|
||||
UnreadCountRole
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
// Optional: method to refresh the model from the database
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
QVector<QString> m_folderNames;
|
||||
QVector<int> m_unreadCounts;
|
||||
FolderDao& m_folderDao;
|
||||
};
|
||||
|
||||
#endif // FOLDERLISTMODEL_H
|
||||
Reference in New Issue
Block a user