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:
@@ -3,7 +3,7 @@
|
||||
#include <QDateTime>
|
||||
|
||||
EmailListModel::EmailListModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
@@ -15,6 +15,12 @@ int EmailListModel::rowCount(const QModelIndex &parent) const
|
||||
return m_emails.size();
|
||||
}
|
||||
|
||||
int EmailListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return ColCount;
|
||||
}
|
||||
|
||||
QVariant EmailListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_emails.size())
|
||||
@@ -23,6 +29,17 @@ QVariant EmailListModel::data(const QModelIndex &index, int role) const
|
||||
const MailItem& item = m_emails.at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
switch (index.column()) {
|
||||
case ColSubject:
|
||||
return item.subject();
|
||||
case ColSender:
|
||||
return item.sender();
|
||||
case ColDate:
|
||||
return item.date();
|
||||
}
|
||||
break;
|
||||
case IdRole:
|
||||
return item.id();
|
||||
case SubjectRole:
|
||||
@@ -49,13 +66,29 @@ QVariant EmailListModel::data(const QModelIndex &index, int role) const
|
||||
QString sender = item.sender();
|
||||
if (sender.isEmpty())
|
||||
return QString();
|
||||
// Get first character, or first non-space character?
|
||||
// Simple: first character of the sender string
|
||||
return QString(sender.at(0)).toUpper();
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant EmailListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
switch (section) {
|
||||
case ColSubject:
|
||||
return tr("Asunto");
|
||||
case ColSender:
|
||||
return tr("De");
|
||||
case ColDate:
|
||||
return tr("Fecha");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> EmailListModel::roleNames() const
|
||||
|
||||
Reference in New Issue
Block a user