fix: EmailListModel as QAbstractTableModel for proper MailListView display

- Changed EmailListModel from QAbstractListModel to QAbstractTableModel
- Added columnCount() returning 3 columns (Subject, Sender, Date)
- Added headerData() for column headers (Asunto, De, Fecha)
- Modified data() to handle Qt::DisplayRole per column index
- Updated MailListView::setModel() to use column indices instead of role-based column hiding
- Added proper column resize modes (Stretch for Subject/Sender, ResizeToContents for Date)
- Default sort by Date column descending
This commit is contained in:
2026-08-19 09:43:03 +02:00
parent 2a7142be1e
commit 5fcedfa129
3 changed files with 58 additions and 33 deletions
+12 -4
View File
@@ -1,12 +1,12 @@
#ifndef EMAILLISTMODEL_H
#define EMAILLISTMODEL_H
#include <QAbstractListModel>
#include <QAbstractTableModel>
#include <QHash>
#include <QByteArray>
#include "../db/dao/mailitemdao.h"
class EmailListModel : public QAbstractListModel
class EmailListModel : public QAbstractTableModel
{
Q_OBJECT
public:
@@ -28,8 +28,18 @@ public:
SenderInitialRole // computed from sender
};
// Column indices (match role order for simplicity)
enum Columns {
ColSubject = 0,
ColSender = 1,
ColDate = 2,
ColCount = 3 // number of visible columns
};
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
// Set the folderId to filter emails; -1 means all folders
@@ -40,7 +50,5 @@ public:
private:
QVector<MailItem> m_emails;
int m_folderId{-1}; // -1 means all folders
// REMOVED: MailItemDao& m_mailItemDao; // Methods are static, no instance needed
};
#endif // EMAILLISTMODEL_H